4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * DRV Resource allocation module. Driver Object gets Created
7 * at the time of Loading. It holds the List of Device Objects
10 * Copyright (C) 2005-2006 Texas Instruments, Inc.
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.
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.
24 #include <dspbridge/devdefs.h>
26 #include <dspbridge/drvdefs.h>
31 /* Provide the DSP Internal memory windows that can be accessed from L3 address
34 #define OMAP_GEM_BASE 0x107F8000
35 #define OMAP_DSP_SIZE 0x00720000
37 /* MEM1 is L2 RAM + L2 Cache space */
38 #define OMAP_DSP_MEM1_BASE 0x5C7F8000
39 #define OMAP_DSP_MEM1_SIZE 0x18000
40 #define OMAP_DSP_GEM1_BASE 0x107F8000
42 /* MEM2 is L1P RAM/CACHE space */
43 #define OMAP_DSP_MEM2_BASE 0x5CE00000
44 #define OMAP_DSP_MEM2_SIZE 0x8000
45 #define OMAP_DSP_GEM2_BASE 0x10E00000
47 /* MEM3 is L1D RAM/CACHE space */
48 #define OMAP_DSP_MEM3_BASE 0x5CF04000
49 #define OMAP_DSP_MEM3_SIZE 0x14000
50 #define OMAP_DSP_GEM3_BASE 0x10F04000
52 #define OMAP_IVA2_PRM_BASE 0x48306000
53 #define OMAP_IVA2_PRM_SIZE 0x1000
55 #define OMAP_IVA2_CM_BASE 0x48004000
56 #define OMAP_IVA2_CM_SIZE 0x1000
58 #define OMAP_PER_CM_BASE 0x48005000
59 #define OMAP_PER_CM_SIZE 0x1000
61 #define OMAP_PER_PRM_BASE 0x48307000
62 #define OMAP_PER_PRM_SIZE 0x1000
64 #define OMAP_CORE_PRM_BASE 0x48306A00
65 #define OMAP_CORE_PRM_SIZE 0x1000
67 #define OMAP_SYSC_BASE 0x48002000
68 #define OMAP_SYSC_SIZE 0x1000
70 #define OMAP_DMMU_BASE 0x5D000000
71 #define OMAP_DMMU_SIZE 0x1000
73 #define OMAP_PRCM_VDD1_DOMAIN 1
74 #define OMAP_PRCM_VDD2_DOMAIN 2
76 /* GPP PROCESS CLEANUP Data structures */
78 /* New structure (member of process context) abstracts NODE resource info */
79 struct node_res_object {
81 s32 node_allocated; /* Node status */
82 s32 heap_allocated; /* Heap status */
83 s32 streams_allocated; /* Streams status */
84 struct node_res_object *next;
87 /* used to cache dma mapping information */
88 struct bridge_dma_map_info {
89 /* direction of DMA in action, or DMA_NONE */
90 enum dma_data_direction dir;
91 /* number of elements requested by us */
93 /* number of elements returned from dma_map_sg */
95 /* list of buffers used in this DMA action */
96 struct scatterlist *sg;
99 /* Used for DMM mapped memory accounting */
100 struct dmm_map_object {
101 struct list_head link;
107 struct bridge_dma_map_info dma_info;
110 /* Used for DMM reserved memory accounting */
111 struct dmm_rsv_object {
112 struct list_head link;
113 u32 dsp_reserved_addr;
116 /* New structure (member of process context) abstracts DMM resource info */
117 struct dspheap_res_object {
118 s32 heap_allocated; /* DMM status */
124 struct dspheap_res_object *next;
127 /* New structure (member of process context) abstracts stream resource info */
128 struct strm_res_object {
129 s32 stream_allocated; /* Stream status */
133 struct strm_res_object *next;
136 /* Overall Bridge process resource usage state */
137 enum gpp_proc_res_state {
152 /* Process Context */
153 struct process_context {
155 enum gpp_proc_res_state res_state;
157 /* Handle to Processor */
160 /* DSP Node resources */
161 struct node_res_object *node_list;
162 struct mutex node_mutex;
164 /* DMM mapped memory resources */
165 struct list_head dmm_map_list;
166 spinlock_t dmm_map_lock;
168 /* DMM reserved memory resources */
169 struct list_head dmm_rsv_list;
170 spinlock_t dmm_rsv_lock;
172 /* DSP Heap resources */
173 struct dspheap_res_object *pdspheap_list;
175 /* Stream resources */
176 struct strm_res_object *pstrm_list;
177 struct mutex strm_mutex;
181 * ======== drv_create ========
183 * Creates the Driver Object. This is done during the driver loading.
184 * There is only one Driver Object in the DSP/BIOS Bridge.
186 * drv_obj: Location to store created DRV Object handle.
189 * -ENOMEM: Failed in Memory allocation
190 * -EPERM: General Failure
192 * DRV Initialized (refs > 0 )
195 * 0: - *drv_obj is a valid DRV interface to the device.
196 * - List of DevObject Created and Initialized.
197 * - List of dev_node String created and intialized.
198 * - Registry is updated with the DRV Object.
199 * !0: DRV Object not created
201 * There is one Driver Object for the Driver representing
202 * the driver itself. It contains the list of device
203 * Objects and the list of Device Extensions in the system.
204 * Also it can hold other neccessary
205 * information in its storage area.
207 extern int drv_create(struct drv_object **drv_obj);
210 * ======== drv_destroy ========
212 * destroys the Dev Object list, DrvExt list
213 * and destroy the DRV object
214 * Called upon driver unLoading.or unsuccesful loading of the driver.
216 * driver_obj: Handle to Driver object .
219 * -EPERM: Failed to destroy DRV Object
221 * DRV Initialized (cRegs > 0 )
222 * hdrv_obj is not NULL and a valid DRV handle .
223 * List of DevObject is Empty.
224 * List of DrvExt is Empty
226 * 0: - DRV Object destroyed and hdrv_obj is not a valid
228 * - Registry is updated with "0" as the DRV Object.
230 extern int drv_destroy(struct drv_object *driver_obj);
233 * ======== drv_exit ========
235 * Exit the DRV module, freeing any modules initialized in drv_init.
241 extern void drv_exit(void);
244 * ======== drv_get_first_dev_object ========
246 * Returns the Ptr to the FirstDev Object in the List
251 * dw_dev_object: Ptr to the First Dev Object as a u32
252 * 0 if it fails to retrieve the First Dev Object
255 extern u32 drv_get_first_dev_object(void);
258 * ======== drv_get_first_dev_extension ========
260 * Returns the Ptr to the First Device Extension in the List
265 * dw_dev_extension: Ptr to the First Device Extension as a u32
266 * 0: Failed to Get the Device Extension
269 extern u32 drv_get_first_dev_extension(void);
272 * ======== drv_get_dev_object ========
274 * Given a index, returns a handle to DevObject from the list
276 * hdrv_obj: Handle to the Manager
277 * device_obj: Location to store the Dev Handle
281 * hdrv_obj is not NULL and Valid DRV Object
282 * device_obj is not NULL
283 * Device Object List not Empty
286 * -EPERM: Failed to Get the Dev Object
288 * 0: *device_obj != NULL
289 * -EPERM: *device_obj = NULL
291 extern int drv_get_dev_object(u32 index,
292 struct drv_object *hdrv_obj,
293 struct dev_object **device_obj);
296 * ======== drv_get_next_dev_object ========
298 * Returns the Ptr to the Next Device Object from the the List
300 * hdev_obj: Handle to the Device Object
305 * dw_dev_object: Ptr to the Next Dev Object as a u32
306 * 0: If it fail to get the next Dev Object.
309 extern u32 drv_get_next_dev_object(u32 hdev_obj);
312 * ======== drv_get_next_dev_extension ========
314 * Returns the Ptr to the Next Device Extension from the the List
316 * dev_extension: Handle to the Device Extension
319 * dev_extension != 0.
321 * dw_dev_extension: Ptr to the Next Dev Extension
322 * 0: If it fail to Get the next Dev Extension
325 extern u32 drv_get_next_dev_extension(u32 dev_extension);
328 * ======== drv_init ========
330 * Initialize the DRV module.
333 * TRUE if success; FALSE otherwise.
337 extern int drv_init(void);
340 * ======== drv_insert_dev_object ========
342 * Insert a DeviceObject into the list of Driver object.
344 * driver_obj: Handle to DrvObject
345 * hdev_obj: Handle to DeviceObject to insert.
348 * -EPERM: General Failure:
350 * hdrv_obj != NULL and Valid DRV Handle.
353 * 0: Device Object is inserted and the List is not empty.
355 extern int drv_insert_dev_object(struct drv_object *driver_obj,
356 struct dev_object *hdev_obj);
359 * ======== drv_remove_dev_object ========
361 * Search for and remove a Device object from the given list of Device Obj
364 * driver_obj: Handle to DrvObject
365 * hdev_obj: Handle to DevObject to Remove
368 * -EPERM: Unable to find dev_obj.
370 * hdrv_obj != NULL and a Valid DRV Handle.
372 * List exists and is not empty.
374 * List either does not exist (NULL), or is not empty if it does exist.
376 extern int drv_remove_dev_object(struct drv_object *driver_obj,
377 struct dev_object *hdev_obj);
380 * ======== drv_request_resources ========
382 * Assigns the Resources or Releases them.
384 * dw_context: Path to the driver Registry Key.
385 * dev_node_strg: Ptr to dev_node String stored in the Device Ext.
387 * TRUE if success; FALSE otherwise.
390 * The Resources are assigned based on Bus type.
391 * The hardware is initialized. Resource information is
392 * gathered from the Registry(ISA, PCMCIA)or scanned(PCI)
393 * Resource structure is stored in the registry which will be
394 * later used by the CFG module.
396 extern int drv_request_resources(IN u32 dw_context,
397 OUT u32 *dev_node_strg);
400 * ======== drv_release_resources ========
402 * Assigns the Resources or Releases them.
404 * dw_context: Path to the driver Registry Key.
405 * hdrv_obj: Handle to the Driver Object.
407 * TRUE if success; FALSE otherwise.
410 * The Resources are released based on Bus type.
411 * Resource structure is deleted from the registry
413 extern int drv_release_resources(IN u32 dw_context,
414 struct drv_object *hdrv_obj);
417 * drv_request_bridge_res_dsp() - Reserves shared memory for bridge.
418 * @phost_resources: pointer to host resources.
420 int drv_request_bridge_res_dsp(void **phost_resources);
422 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
423 void bridge_recover_schedule(void);
427 * ======== mem_ext_phys_pool_init ========
429 * Uses the physical memory chunk passed for internal consitent memory
431 * physical address based on the page frame address.
433 * pool_phys_base starting address of the physical memory pool.
434 * pool_size size of the physical memory pool.
439 * - valid physical address for the base and size > 0
441 extern void mem_ext_phys_pool_init(IN u32 pool_phys_base, IN u32 pool_size);
444 * ======== mem_ext_phys_pool_release ========
446 extern void mem_ext_phys_pool_release(void);
448 /* ======== mem_alloc_phys_mem ========
450 * Allocate physically contiguous, uncached memory
452 * byte_size: Number of bytes to allocate.
453 * align_mask: Alignment Mask.
454 * physical_address: Physical address of allocated memory.
456 * Pointer to a block of memory;
457 * NULL if memory couldn't be allocated, or if byte_size == 0.
461 * The returned pointer, if not NULL, points to a valid memory block of
462 * the size requested. Returned physical address refers to physical
463 * location of memory.
465 extern void *mem_alloc_phys_mem(IN u32 byte_size,
466 IN u32 align_mask, OUT u32 *physical_address);
469 * ======== mem_free_phys_mem ========
471 * Free the given block of physically contiguous memory.
473 * virtual_address: Pointer to virtual memory region allocated
474 * by mem_alloc_phys_mem().
475 * physical_address: Pointer to physical memory region allocated
476 * by mem_alloc_phys_mem().
477 * byte_size: Size of the memory region allocated by mem_alloc_phys_mem().
481 * virtual_address is a valid memory address returned by
482 * mem_alloc_phys_mem()
484 * virtual_address is no longer a valid pointer to memory.
486 extern void mem_free_phys_mem(void *virtual_address,
487 u32 physical_address, u32 byte_size);
490 * ======== MEM_LINEAR_ADDRESS ========
492 * Get the linear address corresponding to the given physical address.
494 * phys_addr: Physical address to be mapped.
495 * byte_size: Number of bytes in physical range to map.
497 * The corresponding linear address, or NULL if unsuccessful.
502 * If valid linear address is returned, be sure to call
503 * MEM_UNMAP_LINEAR_ADDRESS().
505 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
508 * ======== MEM_UNMAP_LINEAR_ADDRESS ========
510 * Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
512 * base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
516 * - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
518 * - base_addr no longer points to a valid linear address.
520 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}