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>
27 #include <linux/idr.h>
32 /* Provide the DSP Internal memory windows that can be accessed from L3 address
35 #define OMAP_GEM_BASE 0x107F8000
36 #define OMAP_DSP_SIZE 0x00720000
38 /* MEM1 is L2 RAM + L2 Cache space */
39 #define OMAP_DSP_MEM1_BASE 0x5C7F8000
40 #define OMAP_DSP_MEM1_SIZE 0x18000
41 #define OMAP_DSP_GEM1_BASE 0x107F8000
43 /* MEM2 is L1P RAM/CACHE space */
44 #define OMAP_DSP_MEM2_BASE 0x5CE00000
45 #define OMAP_DSP_MEM2_SIZE 0x8000
46 #define OMAP_DSP_GEM2_BASE 0x10E00000
48 /* MEM3 is L1D RAM/CACHE space */
49 #define OMAP_DSP_MEM3_BASE 0x5CF04000
50 #define OMAP_DSP_MEM3_SIZE 0x14000
51 #define OMAP_DSP_GEM3_BASE 0x10F04000
53 #define OMAP_IVA2_PRM_BASE 0x48306000
54 #define OMAP_IVA2_PRM_SIZE 0x1000
56 #define OMAP_IVA2_CM_BASE 0x48004000
57 #define OMAP_IVA2_CM_SIZE 0x1000
59 #define OMAP_PER_CM_BASE 0x48005000
60 #define OMAP_PER_CM_SIZE 0x1000
62 #define OMAP_PER_PRM_BASE 0x48307000
63 #define OMAP_PER_PRM_SIZE 0x1000
65 #define OMAP_CORE_PRM_BASE 0x48306A00
66 #define OMAP_CORE_PRM_SIZE 0x1000
68 #define OMAP_SYSC_BASE 0x48002000
69 #define OMAP_SYSC_SIZE 0x1000
71 #define OMAP_DMMU_BASE 0x5D000000
72 #define OMAP_DMMU_SIZE 0x1000
74 #define OMAP_PRCM_VDD1_DOMAIN 1
75 #define OMAP_PRCM_VDD2_DOMAIN 2
77 /* GPP PROCESS CLEANUP Data structures */
79 /* New structure (member of process context) abstracts NODE resource info */
80 struct node_res_object {
82 s32 node_allocated; /* Node status */
83 s32 heap_allocated; /* Heap status */
84 s32 streams_allocated; /* Streams status */
88 /* used to cache dma mapping information */
89 struct bridge_dma_map_info {
90 /* direction of DMA in action, or DMA_NONE */
91 enum dma_data_direction dir;
92 /* number of elements requested by us */
94 /* number of elements returned from dma_map_sg */
96 /* list of buffers used in this DMA action */
97 struct scatterlist *sg;
100 /* Used for DMM mapped memory accounting */
101 struct dmm_map_object {
102 struct list_head link;
108 struct bridge_dma_map_info dma_info;
111 /* Used for DMM reserved memory accounting */
112 struct dmm_rsv_object {
113 struct list_head link;
114 u32 dsp_reserved_addr;
117 /* New structure (member of process context) abstracts DMM resource info */
118 struct dspheap_res_object {
119 s32 heap_allocated; /* DMM status */
125 struct dspheap_res_object *next;
128 /* New structure (member of process context) abstracts stream resource info */
129 struct strm_res_object {
130 s32 stream_allocated; /* Stream status */
137 /* Overall Bridge process resource usage state */
138 enum gpp_proc_res_state {
153 /* Process Context */
154 struct process_context {
156 enum gpp_proc_res_state res_state;
158 /* Handle to Processor */
161 /* DSP Node resources */
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 idr *stream_id;
180 * ======== drv_create ========
182 * Creates the Driver Object. This is done during the driver loading.
183 * There is only one Driver Object in the DSP/BIOS Bridge.
185 * drv_obj: Location to store created DRV Object handle.
188 * -ENOMEM: Failed in Memory allocation
189 * -EPERM: General Failure
191 * DRV Initialized (refs > 0 )
194 * 0: - *drv_obj is a valid DRV interface to the device.
195 * - List of DevObject Created and Initialized.
196 * - List of dev_node String created and initialized.
197 * - Registry is updated with the DRV Object.
198 * !0: DRV Object not created
200 * There is one Driver Object for the Driver representing
201 * the driver itself. It contains the list of device
202 * Objects and the list of Device Extensions in the system.
203 * Also it can hold other neccessary
204 * information in its storage area.
206 extern int drv_create(struct drv_object **drv_obj);
209 * ======== drv_destroy ========
211 * destroys the Dev Object list, DrvExt list
212 * and destroy the DRV object
213 * Called upon driver unLoading.or unsuccesful loading of the driver.
215 * driver_obj: Handle to Driver object .
218 * -EPERM: Failed to destroy DRV Object
220 * DRV Initialized (cRegs > 0 )
221 * hdrv_obj is not NULL and a valid DRV handle .
222 * List of DevObject is Empty.
223 * List of DrvExt is Empty
225 * 0: - DRV Object destroyed and hdrv_obj is not a valid
227 * - Registry is updated with "0" as the DRV Object.
229 extern int drv_destroy(struct drv_object *driver_obj);
232 * ======== drv_exit ========
234 * Exit the DRV module, freeing any modules initialized in drv_init.
240 extern void drv_exit(void);
243 * ======== drv_get_first_dev_object ========
245 * Returns the Ptr to the FirstDev Object in the List
250 * dw_dev_object: Ptr to the First Dev Object as a u32
251 * 0 if it fails to retrieve the First Dev Object
254 extern u32 drv_get_first_dev_object(void);
257 * ======== drv_get_first_dev_extension ========
259 * Returns the Ptr to the First Device Extension in the List
264 * dw_dev_extension: Ptr to the First Device Extension as a u32
265 * 0: Failed to Get the Device Extension
268 extern u32 drv_get_first_dev_extension(void);
271 * ======== drv_get_dev_object ========
273 * Given a index, returns a handle to DevObject from the list
275 * hdrv_obj: Handle to the Manager
276 * device_obj: Location to store the Dev Handle
280 * hdrv_obj is not NULL and Valid DRV Object
281 * device_obj is not NULL
282 * Device Object List not Empty
285 * -EPERM: Failed to Get the Dev Object
287 * 0: *device_obj != NULL
288 * -EPERM: *device_obj = NULL
290 extern int drv_get_dev_object(u32 index,
291 struct drv_object *hdrv_obj,
292 struct dev_object **device_obj);
295 * ======== drv_get_next_dev_object ========
297 * Returns the Ptr to the Next Device Object from the the List
299 * hdev_obj: Handle to the Device Object
304 * dw_dev_object: Ptr to the Next Dev Object as a u32
305 * 0: If it fail to get the next Dev Object.
308 extern u32 drv_get_next_dev_object(u32 hdev_obj);
311 * ======== drv_get_next_dev_extension ========
313 * Returns the Ptr to the Next Device Extension from the the List
315 * dev_extension: Handle to the Device Extension
318 * dev_extension != 0.
320 * dw_dev_extension: Ptr to the Next Dev Extension
321 * 0: If it fail to Get the next Dev Extension
324 extern u32 drv_get_next_dev_extension(u32 dev_extension);
327 * ======== drv_init ========
329 * Initialize the DRV module.
332 * TRUE if success; FALSE otherwise.
336 extern int drv_init(void);
339 * ======== drv_insert_dev_object ========
341 * Insert a DeviceObject into the list of Driver object.
343 * driver_obj: Handle to DrvObject
344 * hdev_obj: Handle to DeviceObject to insert.
347 * -EPERM: General Failure:
349 * hdrv_obj != NULL and Valid DRV Handle.
352 * 0: Device Object is inserted and the List is not empty.
354 extern int drv_insert_dev_object(struct drv_object *driver_obj,
355 struct dev_object *hdev_obj);
358 * ======== drv_remove_dev_object ========
360 * Search for and remove a Device object from the given list of Device Obj
363 * driver_obj: Handle to DrvObject
364 * hdev_obj: Handle to DevObject to Remove
367 * -EPERM: Unable to find dev_obj.
369 * hdrv_obj != NULL and a Valid DRV Handle.
371 * List exists and is not empty.
373 * List either does not exist (NULL), or is not empty if it does exist.
375 extern int drv_remove_dev_object(struct drv_object *driver_obj,
376 struct dev_object *hdev_obj);
379 * ======== drv_request_resources ========
381 * Assigns the Resources or Releases them.
383 * dw_context: Path to the driver Registry Key.
384 * dev_node_strg: Ptr to dev_node String stored in the Device Ext.
386 * TRUE if success; FALSE otherwise.
389 * The Resources are assigned based on Bus type.
390 * The hardware is initialized. Resource information is
391 * gathered from the Registry(ISA, PCMCIA)or scanned(PCI)
392 * Resource structure is stored in the registry which will be
393 * later used by the CFG module.
395 extern int drv_request_resources(u32 dw_context,
399 * ======== drv_release_resources ========
401 * Assigns the Resources or Releases them.
403 * dw_context: Path to the driver Registry Key.
404 * hdrv_obj: Handle to the Driver Object.
406 * TRUE if success; FALSE otherwise.
409 * The Resources are released based on Bus type.
410 * Resource structure is deleted from the registry
412 extern int drv_release_resources(u32 dw_context,
413 struct drv_object *hdrv_obj);
416 * drv_request_bridge_res_dsp() - Reserves shared memory for bridge.
417 * @phost_resources: pointer to host resources.
419 int drv_request_bridge_res_dsp(void **phost_resources);
421 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
422 void bridge_recover_schedule(void);
426 * ======== mem_ext_phys_pool_init ========
428 * Uses the physical memory chunk passed for internal consitent memory
430 * physical address based on the page frame address.
432 * pool_phys_base starting address of the physical memory pool.
433 * pool_size size of the physical memory pool.
438 * - valid physical address for the base and size > 0
440 extern void mem_ext_phys_pool_init(u32 pool_phys_base, u32 pool_size);
443 * ======== mem_ext_phys_pool_release ========
445 extern void mem_ext_phys_pool_release(void);
447 /* ======== mem_alloc_phys_mem ========
449 * Allocate physically contiguous, uncached memory
451 * byte_size: Number of bytes to allocate.
452 * align_mask: Alignment Mask.
453 * physical_address: Physical address of allocated memory.
455 * Pointer to a block of memory;
456 * NULL if memory couldn't be allocated, or if byte_size == 0.
460 * The returned pointer, if not NULL, points to a valid memory block of
461 * the size requested. Returned physical address refers to physical
462 * location of memory.
464 extern void *mem_alloc_phys_mem(u32 byte_size,
465 u32 align_mask, u32 *physical_address);
468 * ======== mem_free_phys_mem ========
470 * Free the given block of physically contiguous memory.
472 * virtual_address: Pointer to virtual memory region allocated
473 * by mem_alloc_phys_mem().
474 * physical_address: Pointer to physical memory region allocated
475 * by mem_alloc_phys_mem().
476 * byte_size: Size of the memory region allocated by mem_alloc_phys_mem().
480 * virtual_address is a valid memory address returned by
481 * mem_alloc_phys_mem()
483 * virtual_address is no longer a valid pointer to memory.
485 extern void mem_free_phys_mem(void *virtual_address,
486 u32 physical_address, u32 byte_size);
489 * ======== MEM_LINEAR_ADDRESS ========
491 * Get the linear address corresponding to the given physical address.
493 * phys_addr: Physical address to be mapped.
494 * byte_size: Number of bytes in physical range to map.
496 * The corresponding linear address, or NULL if unsuccessful.
501 * If valid linear address is returned, be sure to call
502 * MEM_UNMAP_LINEAR_ADDRESS().
504 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
507 * ======== MEM_UNMAP_LINEAR_ADDRESS ========
509 * Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
511 * base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
515 * - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
517 * - base_addr no longer points to a valid linear address.
519 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}