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 <linux/idr.h>
28 /* Bridge Driver Object */
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
41 /* MEM2 is L1P RAM/CACHE space */
42 #define OMAP_DSP_MEM2_BASE 0x5CE00000
43 #define OMAP_DSP_MEM2_SIZE 0x8000
45 /* MEM3 is L1D RAM/CACHE space */
46 #define OMAP_DSP_MEM3_BASE 0x5CF04000
47 #define OMAP_DSP_MEM3_SIZE 0x14000
49 #define OMAP_PER_CM_BASE 0x48005000
50 #define OMAP_PER_CM_SIZE 0x1000
52 #define OMAP_PER_PRM_BASE 0x48307000
53 #define OMAP_PER_PRM_SIZE 0x1000
55 #define OMAP_CORE_PRM_BASE 0x48306A00
56 #define OMAP_CORE_PRM_SIZE 0x1000
58 #define OMAP_DMMU_BASE 0x5D000000
59 #define OMAP_DMMU_SIZE 0x1000
61 /* GPP PROCESS CLEANUP Data structures */
63 /* New structure (member of process context) abstracts NODE resource info */
64 struct node_res_object {
66 s32 node_allocated; /* Node status */
67 s32 heap_allocated; /* Heap status */
68 s32 streams_allocated; /* Streams status */
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 */
78 /* number of elements returned from dma_map_sg */
80 /* list of buffers used in this DMA action */
81 struct scatterlist *sg;
84 /* Used for DMM mapped memory accounting */
85 struct dmm_map_object {
86 struct list_head link;
92 struct bridge_dma_map_info dma_info;
95 /* Used for DMM reserved memory accounting */
96 struct dmm_rsv_object {
97 struct list_head link;
98 u32 dsp_reserved_addr;
101 /* New structure (member of process context) abstracts stream resource info */
102 struct strm_res_object {
103 s32 stream_allocated; /* Stream status */
110 /* Overall Bridge process resource usage state */
111 enum gpp_proc_res_state {
126 /* Process Context */
127 struct process_context {
129 enum gpp_proc_res_state res_state;
131 /* Handle to Processor */
134 /* DSP Node resources */
137 /* DMM mapped memory resources */
138 struct list_head dmm_map_list;
139 spinlock_t dmm_map_lock;
141 /* DMM reserved memory resources */
142 struct list_head dmm_rsv_list;
143 spinlock_t dmm_rsv_lock;
145 /* Stream resources */
146 struct idr *stream_id;
150 * ======== drv_create ========
152 * Creates the Driver Object. This is done during the driver loading.
153 * There is only one Driver Object in the DSP/BIOS Bridge.
155 * drv_obj: Location to store created DRV Object handle.
158 * -ENOMEM: Failed in Memory allocation
159 * -EPERM: General Failure
161 * DRV Initialized (refs > 0 )
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
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.
176 extern int drv_create(struct drv_object **drv_obj);
179 * ======== drv_destroy ========
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.
185 * driver_obj: Handle to Driver object .
188 * -EPERM: Failed to destroy DRV Object
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
195 * 0: - DRV Object destroyed and hdrv_obj is not a valid
197 * - Registry is updated with "0" as the DRV Object.
199 extern int drv_destroy(struct drv_object *driver_obj);
202 * ======== drv_get_first_dev_object ========
204 * Returns the Ptr to the FirstDev Object in the List
209 * dw_dev_object: Ptr to the First Dev Object as a u32
210 * 0 if it fails to retrieve the First Dev Object
213 extern u32 drv_get_first_dev_object(void);
216 * ======== drv_get_first_dev_extension ========
218 * Returns the Ptr to the First Device Extension in the List
223 * dw_dev_extension: Ptr to the First Device Extension as a u32
224 * 0: Failed to Get the Device Extension
227 extern u32 drv_get_first_dev_extension(void);
230 * ======== drv_get_dev_object ========
232 * Given a index, returns a handle to DevObject from the list
234 * hdrv_obj: Handle to the Manager
235 * device_obj: Location to store the Dev Handle
239 * hdrv_obj is not NULL and Valid DRV Object
240 * device_obj is not NULL
241 * Device Object List not Empty
244 * -EPERM: Failed to Get the Dev Object
246 * 0: *device_obj != NULL
247 * -EPERM: *device_obj = NULL
249 extern int drv_get_dev_object(u32 index,
250 struct drv_object *hdrv_obj,
251 struct dev_object **device_obj);
254 * ======== drv_get_next_dev_object ========
256 * Returns the Ptr to the Next Device Object from the the List
258 * hdev_obj: Handle to the Device Object
263 * dw_dev_object: Ptr to the Next Dev Object as a u32
264 * 0: If it fail to get the next Dev Object.
267 extern u32 drv_get_next_dev_object(u32 hdev_obj);
270 * ======== drv_get_next_dev_extension ========
272 * Returns the Ptr to the Next Device Extension from the the List
274 * dev_extension: Handle to the Device Extension
277 * dev_extension != 0.
279 * dw_dev_extension: Ptr to the Next Dev Extension
280 * 0: If it fail to Get the next Dev Extension
283 extern u32 drv_get_next_dev_extension(u32 dev_extension);
286 * ======== drv_insert_dev_object ========
288 * Insert a DeviceObject into the list of Driver object.
290 * driver_obj: Handle to DrvObject
291 * hdev_obj: Handle to DeviceObject to insert.
294 * -EPERM: General Failure:
296 * hdrv_obj != NULL and Valid DRV Handle.
299 * 0: Device Object is inserted and the List is not empty.
301 extern int drv_insert_dev_object(struct drv_object *driver_obj,
302 struct dev_object *hdev_obj);
305 * ======== drv_remove_dev_object ========
307 * Search for and remove a Device object from the given list of Device Obj
310 * driver_obj: Handle to DrvObject
311 * hdev_obj: Handle to DevObject to Remove
314 * -EPERM: Unable to find dev_obj.
316 * hdrv_obj != NULL and a Valid DRV Handle.
318 * List exists and is not empty.
320 * List either does not exist (NULL), or is not empty if it does exist.
322 extern int drv_remove_dev_object(struct drv_object *driver_obj,
323 struct dev_object *hdev_obj);
326 * ======== drv_request_resources ========
328 * Assigns the Resources or Releases them.
330 * dw_context: Path to the driver Registry Key.
331 * dev_node_strg: Ptr to dev_node String stored in the Device Ext.
333 * TRUE if success; FALSE otherwise.
336 * The Resources are assigned based on Bus type.
337 * The hardware is initialized. Resource information is
338 * gathered from the Registry(ISA, PCMCIA)or scanned(PCI)
339 * Resource structure is stored in the registry which will be
340 * later used by the CFG module.
342 extern int drv_request_resources(u32 dw_context,
346 * ======== drv_release_resources ========
348 * Assigns the Resources or Releases them.
350 * dw_context: Path to the driver Registry Key.
351 * hdrv_obj: Handle to the Driver Object.
353 * TRUE if success; FALSE otherwise.
356 * The Resources are released based on Bus type.
357 * Resource structure is deleted from the registry
359 extern int drv_release_resources(u32 dw_context,
360 struct drv_object *hdrv_obj);
363 * drv_request_bridge_res_dsp() - Reserves shared memory for bridge.
364 * @phost_resources: pointer to host resources.
366 int drv_request_bridge_res_dsp(void **phost_resources);
368 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
369 void bridge_recover_schedule(void);
373 * ======== mem_ext_phys_pool_init ========
375 * Uses the physical memory chunk passed for internal consistent memory
377 * physical address based on the page frame address.
379 * pool_phys_base starting address of the physical memory pool.
380 * pool_size size of the physical memory pool.
385 * - valid physical address for the base and size > 0
387 extern void mem_ext_phys_pool_init(u32 pool_phys_base, u32 pool_size);
390 * ======== mem_ext_phys_pool_release ========
392 extern void mem_ext_phys_pool_release(void);
394 /* ======== mem_alloc_phys_mem ========
396 * Allocate physically contiguous, uncached memory
398 * byte_size: Number of bytes to allocate.
399 * align_mask: Alignment Mask.
400 * physical_address: Physical address of allocated memory.
402 * Pointer to a block of memory;
403 * NULL if memory couldn't be allocated, or if byte_size == 0.
407 * The returned pointer, if not NULL, points to a valid memory block of
408 * the size requested. Returned physical address refers to physical
409 * location of memory.
411 extern void *mem_alloc_phys_mem(u32 byte_size,
412 u32 align_mask, u32 *physical_address);
415 * ======== mem_free_phys_mem ========
417 * Free the given block of physically contiguous memory.
419 * virtual_address: Pointer to virtual memory region allocated
420 * by mem_alloc_phys_mem().
421 * physical_address: Pointer to physical memory region allocated
422 * by mem_alloc_phys_mem().
423 * byte_size: Size of the memory region allocated by mem_alloc_phys_mem().
427 * virtual_address is a valid memory address returned by
428 * mem_alloc_phys_mem()
430 * virtual_address is no longer a valid pointer to memory.
432 extern void mem_free_phys_mem(void *virtual_address,
433 u32 physical_address, u32 byte_size);
436 * ======== MEM_LINEAR_ADDRESS ========
438 * Get the linear address corresponding to the given physical address.
440 * phys_addr: Physical address to be mapped.
441 * byte_size: Number of bytes in physical range to map.
443 * The corresponding linear address, or NULL if unsuccessful.
448 * If valid linear address is returned, be sure to call
449 * MEM_UNMAP_LINEAR_ADDRESS().
451 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
454 * ======== MEM_UNMAP_LINEAR_ADDRESS ========
456 * Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
458 * base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
462 * - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
464 * - base_addr no longer points to a valid linear address.
466 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}