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_exit ========
204
* Exit the DRV module, freeing any modules initialized in drv_init.
210
extern void drv_exit(void);
213
* ======== drv_get_first_dev_object ========
215
* Returns the Ptr to the FirstDev Object in the List
220
* dw_dev_object: Ptr to the First Dev Object as a u32
221
* 0 if it fails to retrieve the First Dev Object
224
extern u32 drv_get_first_dev_object(void);
227
* ======== drv_get_first_dev_extension ========
229
* Returns the Ptr to the First Device Extension in the List
234
* dw_dev_extension: Ptr to the First Device Extension as a u32
235
* 0: Failed to Get the Device Extension
238
extern u32 drv_get_first_dev_extension(void);
241
* ======== drv_get_dev_object ========
243
* Given a index, returns a handle to DevObject from the list
245
* hdrv_obj: Handle to the Manager
246
* device_obj: Location to store the Dev Handle
250
* hdrv_obj is not NULL and Valid DRV Object
251
* device_obj is not NULL
252
* Device Object List not Empty
255
* -EPERM: Failed to Get the Dev Object
257
* 0: *device_obj != NULL
258
* -EPERM: *device_obj = NULL
260
extern int drv_get_dev_object(u32 index,
261
struct drv_object *hdrv_obj,
262
struct dev_object **device_obj);
265
* ======== drv_get_next_dev_object ========
267
* Returns the Ptr to the Next Device Object from the the List
269
* hdev_obj: Handle to the Device Object
274
* dw_dev_object: Ptr to the Next Dev Object as a u32
275
* 0: If it fail to get the next Dev Object.
278
extern u32 drv_get_next_dev_object(u32 hdev_obj);
281
* ======== drv_get_next_dev_extension ========
283
* Returns the Ptr to the Next Device Extension from the the List
285
* dev_extension: Handle to the Device Extension
288
* dev_extension != 0.
290
* dw_dev_extension: Ptr to the Next Dev Extension
291
* 0: If it fail to Get the next Dev Extension
294
extern u32 drv_get_next_dev_extension(u32 dev_extension);
297
* ======== drv_init ========
299
* Initialize the DRV module.
302
* TRUE if success; FALSE otherwise.
306
extern int drv_init(void);
309
* ======== drv_insert_dev_object ========
311
* Insert a DeviceObject into the list of Driver object.
313
* driver_obj: Handle to DrvObject
314
* hdev_obj: Handle to DeviceObject to insert.
317
* -EPERM: General Failure:
319
* hdrv_obj != NULL and Valid DRV Handle.
322
* 0: Device Object is inserted and the List is not empty.
324
extern int drv_insert_dev_object(struct drv_object *driver_obj,
325
struct dev_object *hdev_obj);
328
* ======== drv_remove_dev_object ========
330
* Search for and remove a Device object from the given list of Device Obj
333
* driver_obj: Handle to DrvObject
334
* hdev_obj: Handle to DevObject to Remove
337
* -EPERM: Unable to find dev_obj.
339
* hdrv_obj != NULL and a Valid DRV Handle.
341
* List exists and is not empty.
343
* List either does not exist (NULL), or is not empty if it does exist.
345
extern int drv_remove_dev_object(struct drv_object *driver_obj,
346
struct dev_object *hdev_obj);
349
* ======== drv_request_resources ========
351
* Assigns the Resources or Releases them.
353
* dw_context: Path to the driver Registry Key.
354
* dev_node_strg: Ptr to dev_node String stored in the Device Ext.
356
* TRUE if success; FALSE otherwise.
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.
365
extern int drv_request_resources(u32 dw_context,
369
* ======== drv_release_resources ========
371
* Assigns the Resources or Releases them.
373
* dw_context: Path to the driver Registry Key.
374
* hdrv_obj: Handle to the Driver Object.
376
* TRUE if success; FALSE otherwise.
379
* The Resources are released based on Bus type.
380
* Resource structure is deleted from the registry
382
extern int drv_release_resources(u32 dw_context,
383
struct drv_object *hdrv_obj);
386
* drv_request_bridge_res_dsp() - Reserves shared memory for bridge.
387
* @phost_resources: pointer to host resources.
389
int drv_request_bridge_res_dsp(void **phost_resources);
391
#ifdef CONFIG_TIDSPBRIDGE_RECOVERY
392
void bridge_recover_schedule(void);
396
* ======== mem_ext_phys_pool_init ========
398
* Uses the physical memory chunk passed for internal consistent memory
400
* physical address based on the page frame address.
402
* pool_phys_base starting address of the physical memory pool.
403
* pool_size size of the physical memory pool.
408
* - valid physical address for the base and size > 0
410
extern void mem_ext_phys_pool_init(u32 pool_phys_base, u32 pool_size);
413
* ======== mem_ext_phys_pool_release ========
415
extern void mem_ext_phys_pool_release(void);
417
/* ======== mem_alloc_phys_mem ========
419
* Allocate physically contiguous, uncached memory
421
* byte_size: Number of bytes to allocate.
422
* align_mask: Alignment Mask.
423
* physical_address: Physical address of allocated memory.
425
* Pointer to a block of memory;
426
* NULL if memory couldn't be allocated, or if byte_size == 0.
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.
434
extern void *mem_alloc_phys_mem(u32 byte_size,
435
u32 align_mask, u32 *physical_address);
438
* ======== mem_free_phys_mem ========
440
* Free the given block of physically contiguous memory.
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().
450
* virtual_address is a valid memory address returned by
451
* mem_alloc_phys_mem()
453
* virtual_address is no longer a valid pointer to memory.
455
extern void mem_free_phys_mem(void *virtual_address,
456
u32 physical_address, u32 byte_size);
459
* ======== MEM_LINEAR_ADDRESS ========
461
* Get the linear address corresponding to the given physical address.
463
* phys_addr: Physical address to be mapped.
464
* byte_size: Number of bytes in physical range to map.
466
* The corresponding linear address, or NULL if unsuccessful.
471
* If valid linear address is returned, be sure to call
472
* MEM_UNMAP_LINEAR_ADDRESS().
474
#define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
477
* ======== MEM_UNMAP_LINEAR_ADDRESS ========
479
* Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
481
* base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
485
* - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
487
* - base_addr no longer points to a valid linear address.
489
#define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}