1 /* 2 * drv.h 3 * 4 * DSP-BIOS Bridge driver support functions for TI OMAP processors. 5 * 6 * DRV Resource allocation module. Driver Object gets Created 7 * at the time of Loading. It holds the List of Device Objects 8 * in the system. 9 * 10 * Copyright (C) 2005-2006 Texas Instruments, Inc. 11 * 12 * This package is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License version 2 as 14 * published by the Free Software Foundation. 15 * 16 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21 #ifndef DRV_ 22 #define DRV_ 23 24 #include <dspbridge/devdefs.h> 25 26 #include <linux/idr.h> 27 28 /* Bridge Driver Object */ 29 struct drv_object; 30 31 /* Provide the DSP Internal memory windows that can be accessed from L3 address 32 * space */ 33 34 #define OMAP_GEM_BASE 0x107F8000 35 #define OMAP_DSP_SIZE 0x00720000 36 37 /* MEM1 is L2 RAM + L2 Cache space */ 38 #define OMAP_DSP_MEM1_BASE 0x5C7F8000 39 #define OMAP_DSP_MEM1_SIZE 0x18000 40 41 /* MEM2 is L1P RAM/CACHE space */ 42 #define OMAP_DSP_MEM2_BASE 0x5CE00000 43 #define OMAP_DSP_MEM2_SIZE 0x8000 44 45 /* MEM3 is L1D RAM/CACHE space */ 46 #define OMAP_DSP_MEM3_BASE 0x5CF04000 47 #define OMAP_DSP_MEM3_SIZE 0x14000 48 49 #define OMAP_PER_CM_BASE 0x48005000 50 #define OMAP_PER_CM_SIZE 0x1000 51 52 #define OMAP_PER_PRM_BASE 0x48307000 53 #define OMAP_PER_PRM_SIZE 0x1000 54 55 #define OMAP_CORE_PRM_BASE 0x48306A00 56 #define OMAP_CORE_PRM_SIZE 0x1000 57 58 #define OMAP_DMMU_BASE 0x5D000000 59 #define OMAP_DMMU_SIZE 0x1000 60 61 /* GPP PROCESS CLEANUP Data structures */ 62 63 /* New structure (member of process context) abstracts NODE resource info */ 64 struct node_res_object { 65 void *node; 66 s32 node_allocated; /* Node status */ 67 s32 heap_allocated; /* Heap status */ 68 s32 streams_allocated; /* Streams status */ 69 int id; 70 }; 71 72 /* used to cache dma mapping information */ 73 struct bridge_dma_map_info { 74 /* direction of DMA in action, or DMA_NONE */ 75 enum dma_data_direction dir; 76 /* number of elements requested by us */ 77 int num_pages; 78 /* number of elements returned from dma_map_sg */ 79 int sg_num; 80 /* list of buffers used in this DMA action */ 81 struct scatterlist *sg; 82 }; 83 84 /* Used for DMM mapped memory accounting */ 85 struct dmm_map_object { 86 struct list_head link; 87 u32 dsp_addr; 88 u32 mpu_addr; 89 u32 size; 90 u32 num_usr_pgs; 91 struct page **pages; 92 struct bridge_dma_map_info dma_info; 93 }; 94 95 /* Used for DMM reserved memory accounting */ 96 struct dmm_rsv_object { 97 struct list_head link; 98 u32 dsp_reserved_addr; 99 }; 100 101 /* New structure (member of process context) abstracts stream resource info */ 102 struct strm_res_object { 103 s32 stream_allocated; /* Stream status */ 104 void *stream; 105 u32 num_bufs; 106 u32 dir; 107 int id; 108 }; 109 110 /* Overall Bridge process resource usage state */ 111 enum gpp_proc_res_state { 112 PROC_RES_ALLOCATED, 113 PROC_RES_FREED 114 }; 115 116 /* Bridge Data */ 117 struct drv_data { 118 char *base_img; 119 s32 shm_size; 120 int tc_wordswapon; 121 void *drv_object; 122 void *dev_object; 123 void *mgr_object; 124 }; 125 126 /* Process Context */ 127 struct process_context { 128 /* Process State */ 129 enum gpp_proc_res_state res_state; 130 131 /* Handle to Processor */ 132 void *processor; 133 134 /* DSP Node resources */ 135 struct idr *node_id; 136 137 /* DMM mapped memory resources */ 138 struct list_head dmm_map_list; 139 spinlock_t dmm_map_lock; 140 141 /* DMM reserved memory resources */ 142 struct list_head dmm_rsv_list; 143 spinlock_t dmm_rsv_lock; 144 145 /* Stream resources */ 146 struct idr *stream_id; 147 }; 148 149 /* 150 * ======== drv_create ======== 151 * Purpose: 152 * Creates the Driver Object. This is done during the driver loading. 153 * There is only one Driver Object in the DSP/BIOS Bridge. 154 * Parameters: 155 * drv_obj: Location to store created DRV Object handle. 156 * Returns: 157 * 0: Success 158 * -ENOMEM: Failed in Memory allocation 159 * -EPERM: General Failure 160 * Requires: 161 * DRV Initialized (refs > 0 ) 162 * drv_obj != NULL. 163 * Ensures: 164 * 0: - *drv_obj is a valid DRV interface to the device. 165 * - List of DevObject Created and Initialized. 166 * - List of dev_node String created and initialized. 167 * - Registry is updated with the DRV Object. 168 * !0: DRV Object not created 169 * Details: 170 * There is one Driver Object for the Driver representing 171 * the driver itself. It contains the list of device 172 * Objects and the list of Device Extensions in the system. 173 * Also it can hold other necessary 174 * information in its storage area. 175 */ 176 extern int drv_create(struct drv_object **drv_obj); 177 178 /* 179 * ======== drv_destroy ======== 180 * Purpose: 181 * destroys the Dev Object list, DrvExt list 182 * and destroy the DRV object 183 * Called upon driver unLoading.or unsuccessful loading of the driver. 184 * Parameters: 185 * driver_obj: Handle to Driver object . 186 * Returns: 187 * 0: Success. 188 * -EPERM: Failed to destroy DRV Object 189 * Requires: 190 * DRV Initialized (cRegs > 0 ) 191 * hdrv_obj is not NULL and a valid DRV handle . 192 * List of DevObject is Empty. 193 * List of DrvExt is Empty 194 * Ensures: 195 * 0: - DRV Object destroyed and hdrv_obj is not a valid 196 * DRV handle. 197 * - Registry is updated with "0" as the DRV Object. 198 */ 199 extern int drv_destroy(struct drv_object *driver_obj); 200 201 /* 202 * ======== drv_exit ======== 203 * Purpose: 204 * Exit the DRV module, freeing any modules initialized in drv_init. 205 * Parameters: 206 * Returns: 207 * Requires: 208 * Ensures: 209 */ 210 extern void drv_exit(void); 211 212 /* 213 * ======== drv_get_first_dev_object ======== 214 * Purpose: 215 * Returns the Ptr to the FirstDev Object in the List 216 * Parameters: 217 * Requires: 218 * DRV Initialized 219 * Returns: 220 * dw_dev_object: Ptr to the First Dev Object as a u32 221 * 0 if it fails to retrieve the First Dev Object 222 * Ensures: 223 */ 224 extern u32 drv_get_first_dev_object(void); 225 226 /* 227 * ======== drv_get_first_dev_extension ======== 228 * Purpose: 229 * Returns the Ptr to the First Device Extension in the List 230 * Parameters: 231 * Requires: 232 * DRV Initialized 233 * Returns: 234 * dw_dev_extension: Ptr to the First Device Extension as a u32 235 * 0: Failed to Get the Device Extension 236 * Ensures: 237 */ 238 extern u32 drv_get_first_dev_extension(void); 239 240 /* 241 * ======== drv_get_dev_object ======== 242 * Purpose: 243 * Given a index, returns a handle to DevObject from the list 244 * Parameters: 245 * hdrv_obj: Handle to the Manager 246 * device_obj: Location to store the Dev Handle 247 * Requires: 248 * DRV Initialized 249 * index >= 0 250 * hdrv_obj is not NULL and Valid DRV Object 251 * device_obj is not NULL 252 * Device Object List not Empty 253 * Returns: 254 * 0: Success 255 * -EPERM: Failed to Get the Dev Object 256 * Ensures: 257 * 0: *device_obj != NULL 258 * -EPERM: *device_obj = NULL 259 */ 260 extern int drv_get_dev_object(u32 index, 261 struct drv_object *hdrv_obj, 262 struct dev_object **device_obj); 263 264 /* 265 * ======== drv_get_next_dev_object ======== 266 * Purpose: 267 * Returns the Ptr to the Next Device Object from the the List 268 * Parameters: 269 * hdev_obj: Handle to the Device Object 270 * Requires: 271 * DRV Initialized 272 * hdev_obj != 0 273 * Returns: 274 * dw_dev_object: Ptr to the Next Dev Object as a u32 275 * 0: If it fail to get the next Dev Object. 276 * Ensures: 277 */ 278 extern u32 drv_get_next_dev_object(u32 hdev_obj); 279 280 /* 281 * ======== drv_get_next_dev_extension ======== 282 * Purpose: 283 * Returns the Ptr to the Next Device Extension from the the List 284 * Parameters: 285 * dev_extension: Handle to the Device Extension 286 * Requires: 287 * DRV Initialized 288 * dev_extension != 0. 289 * Returns: 290 * dw_dev_extension: Ptr to the Next Dev Extension 291 * 0: If it fail to Get the next Dev Extension 292 * Ensures: 293 */ 294 extern u32 drv_get_next_dev_extension(u32 dev_extension); 295 296 /* 297 * ======== drv_init ======== 298 * Purpose: 299 * Initialize the DRV module. 300 * Parameters: 301 * Returns: 302 * TRUE if success; FALSE otherwise. 303 * Requires: 304 * Ensures: 305 */ 306 extern int drv_init(void); 307 308 /* 309 * ======== drv_insert_dev_object ======== 310 * Purpose: 311 * Insert a DeviceObject into the list of Driver object. 312 * Parameters: 313 * driver_obj: Handle to DrvObject 314 * hdev_obj: Handle to DeviceObject to insert. 315 * Returns: 316 * 0: If successful. 317 * -EPERM: General Failure: 318 * Requires: 319 * hdrv_obj != NULL and Valid DRV Handle. 320 * hdev_obj != NULL. 321 * Ensures: 322 * 0: Device Object is inserted and the List is not empty. 323 */ 324 extern int drv_insert_dev_object(struct drv_object *driver_obj, 325 struct dev_object *hdev_obj); 326 327 /* 328 * ======== drv_remove_dev_object ======== 329 * Purpose: 330 * Search for and remove a Device object from the given list of Device Obj 331 * objects. 332 * Parameters: 333 * driver_obj: Handle to DrvObject 334 * hdev_obj: Handle to DevObject to Remove 335 * Returns: 336 * 0: Success. 337 * -EPERM: Unable to find dev_obj. 338 * Requires: 339 * hdrv_obj != NULL and a Valid DRV Handle. 340 * hdev_obj != NULL. 341 * List exists and is not empty. 342 * Ensures: 343 * List either does not exist (NULL), or is not empty if it does exist. 344 */ 345 extern int drv_remove_dev_object(struct drv_object *driver_obj, 346 struct dev_object *hdev_obj); 347 348 /* 349 * ======== drv_request_resources ======== 350 * Purpose: 351 * Assigns the Resources or Releases them. 352 * Parameters: 353 * dw_context: Path to the driver Registry Key. 354 * dev_node_strg: Ptr to dev_node String stored in the Device Ext. 355 * Returns: 356 * TRUE if success; FALSE otherwise. 357 * Requires: 358 * Ensures: 359 * The Resources are assigned based on Bus type. 360 * The hardware is initialized. Resource information is 361 * gathered from the Registry(ISA, PCMCIA)or scanned(PCI) 362 * Resource structure is stored in the registry which will be 363 * later used by the CFG module. 364 */ 365 extern int drv_request_resources(u32 dw_context, 366 u32 *dev_node_strg); 367 368 /* 369 * ======== drv_release_resources ======== 370 * Purpose: 371 * Assigns the Resources or Releases them. 372 * Parameters: 373 * dw_context: Path to the driver Registry Key. 374 * hdrv_obj: Handle to the Driver Object. 375 * Returns: 376 * TRUE if success; FALSE otherwise. 377 * Requires: 378 * Ensures: 379 * The Resources are released based on Bus type. 380 * Resource structure is deleted from the registry 381 */ 382 extern int drv_release_resources(u32 dw_context, 383 struct drv_object *hdrv_obj); 384 385 /** 386 * drv_request_bridge_res_dsp() - Reserves shared memory for bridge. 387 * @phost_resources: pointer to host resources. 388 */ 389 int drv_request_bridge_res_dsp(void **phost_resources); 390 391 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY 392 void bridge_recover_schedule(void); 393 #endif 394 395 /* 396 * ======== mem_ext_phys_pool_init ======== 397 * Purpose: 398 * Uses the physical memory chunk passed for internal consistent memory 399 * allocations. 400 * physical address based on the page frame address. 401 * Parameters: 402 * pool_phys_base starting address of the physical memory pool. 403 * pool_size size of the physical memory pool. 404 * Returns: 405 * none. 406 * Requires: 407 * - MEM initialized. 408 * - valid physical address for the base and size > 0 409 */ 410 extern void mem_ext_phys_pool_init(u32 pool_phys_base, u32 pool_size); 411 412 /* 413 * ======== mem_ext_phys_pool_release ======== 414 */ 415 extern void mem_ext_phys_pool_release(void); 416 417 /* ======== mem_alloc_phys_mem ======== 418 * Purpose: 419 * Allocate physically contiguous, uncached memory 420 * Parameters: 421 * byte_size: Number of bytes to allocate. 422 * align_mask: Alignment Mask. 423 * physical_address: Physical address of allocated memory. 424 * Returns: 425 * Pointer to a block of memory; 426 * NULL if memory couldn't be allocated, or if byte_size == 0. 427 * Requires: 428 * MEM initialized. 429 * Ensures: 430 * The returned pointer, if not NULL, points to a valid memory block of 431 * the size requested. Returned physical address refers to physical 432 * location of memory. 433 */ 434 extern void *mem_alloc_phys_mem(u32 byte_size, 435 u32 align_mask, u32 *physical_address); 436 437 /* 438 * ======== mem_free_phys_mem ======== 439 * Purpose: 440 * Free the given block of physically contiguous memory. 441 * Parameters: 442 * virtual_address: Pointer to virtual memory region allocated 443 * by mem_alloc_phys_mem(). 444 * physical_address: Pointer to physical memory region allocated 445 * by mem_alloc_phys_mem(). 446 * byte_size: Size of the memory region allocated by mem_alloc_phys_mem(). 447 * Returns: 448 * Requires: 449 * MEM initialized. 450 * virtual_address is a valid memory address returned by 451 * mem_alloc_phys_mem() 452 * Ensures: 453 * virtual_address is no longer a valid pointer to memory. 454 */ 455 extern void mem_free_phys_mem(void *virtual_address, 456 u32 physical_address, u32 byte_size); 457 458 /* 459 * ======== MEM_LINEAR_ADDRESS ======== 460 * Purpose: 461 * Get the linear address corresponding to the given physical address. 462 * Parameters: 463 * phys_addr: Physical address to be mapped. 464 * byte_size: Number of bytes in physical range to map. 465 * Returns: 466 * The corresponding linear address, or NULL if unsuccessful. 467 * Requires: 468 * MEM initialized. 469 * Ensures: 470 * Notes: 471 * If valid linear address is returned, be sure to call 472 * MEM_UNMAP_LINEAR_ADDRESS(). 473 */ 474 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr 475 476 /* 477 * ======== MEM_UNMAP_LINEAR_ADDRESS ======== 478 * Purpose: 479 * Unmap the linear address mapped in MEM_LINEAR_ADDRESS. 480 * Parameters: 481 * base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()). 482 * Returns: 483 * Requires: 484 * - MEM initialized. 485 * - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS. 486 * Ensures: 487 * - base_addr no longer points to a valid linear address. 488 */ 489 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {} 490 491 #endif /* DRV_ */ 492