Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
drv.h
Go to the documentation of this file.
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 */
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 */
74  /* direction of DMA in action, or DMA_NONE */
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 */
86  struct list_head link;
91  struct page **pages;
93 };
94 
95 /* Used for DMM reserved memory accounting */
97  struct list_head link;
99 };
100 
101 /* New structure (member of process context) abstracts stream resource info */
103  s32 stream_allocated; /* Stream status */
104  void *stream;
107  int id;
108 };
109 
110 /* Overall Bridge process resource usage state */
114 };
115 
116 /* Bridge Data */
117 struct drv_data {
118  char *base_img;
121  void *drv_object;
122  void *dev_object;
123  void *mgr_object;
124 };
125 
126 /* Process Context */
128  /* Process 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 */
140 
141  /* DMM reserved memory resources */
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_get_first_dev_object ========
203  * Purpose:
204  * Returns the Ptr to the FirstDev Object in the List
205  * Parameters:
206  * Requires:
207  * DRV Initialized
208  * Returns:
209  * dw_dev_object: Ptr to the First Dev Object as a u32
210  * 0 if it fails to retrieve the First Dev Object
211  * Ensures:
212  */
213 extern u32 drv_get_first_dev_object(void);
214 
215 /*
216  * ======== drv_get_first_dev_extension ========
217  * Purpose:
218  * Returns the Ptr to the First Device Extension in the List
219  * Parameters:
220  * Requires:
221  * DRV Initialized
222  * Returns:
223  * dw_dev_extension: Ptr to the First Device Extension as a u32
224  * 0: Failed to Get the Device Extension
225  * Ensures:
226  */
227 extern u32 drv_get_first_dev_extension(void);
228 
229 /*
230  * ======== drv_get_dev_object ========
231  * Purpose:
232  * Given a index, returns a handle to DevObject from the list
233  * Parameters:
234  * hdrv_obj: Handle to the Manager
235  * device_obj: Location to store the Dev Handle
236  * Requires:
237  * DRV Initialized
238  * index >= 0
239  * hdrv_obj is not NULL and Valid DRV Object
240  * device_obj is not NULL
241  * Device Object List not Empty
242  * Returns:
243  * 0: Success
244  * -EPERM: Failed to Get the Dev Object
245  * Ensures:
246  * 0: *device_obj != NULL
247  * -EPERM: *device_obj = NULL
248  */
249 extern int drv_get_dev_object(u32 index,
250  struct drv_object *hdrv_obj,
251  struct dev_object **device_obj);
252 
253 /*
254  * ======== drv_get_next_dev_object ========
255  * Purpose:
256  * Returns the Ptr to the Next Device Object from the the List
257  * Parameters:
258  * hdev_obj: Handle to the Device Object
259  * Requires:
260  * DRV Initialized
261  * hdev_obj != 0
262  * Returns:
263  * dw_dev_object: Ptr to the Next Dev Object as a u32
264  * 0: If it fail to get the next Dev Object.
265  * Ensures:
266  */
267 extern u32 drv_get_next_dev_object(u32 hdev_obj);
268 
269 /*
270  * ======== drv_get_next_dev_extension ========
271  * Purpose:
272  * Returns the Ptr to the Next Device Extension from the the List
273  * Parameters:
274  * dev_extension: Handle to the Device Extension
275  * Requires:
276  * DRV Initialized
277  * dev_extension != 0.
278  * Returns:
279  * dw_dev_extension: Ptr to the Next Dev Extension
280  * 0: If it fail to Get the next Dev Extension
281  * Ensures:
282  */
283 extern u32 drv_get_next_dev_extension(u32 dev_extension);
284 
285 /*
286  * ======== drv_insert_dev_object ========
287  * Purpose:
288  * Insert a DeviceObject into the list of Driver object.
289  * Parameters:
290  * driver_obj: Handle to DrvObject
291  * hdev_obj: Handle to DeviceObject to insert.
292  * Returns:
293  * 0: If successful.
294  * -EPERM: General Failure:
295  * Requires:
296  * hdrv_obj != NULL and Valid DRV Handle.
297  * hdev_obj != NULL.
298  * Ensures:
299  * 0: Device Object is inserted and the List is not empty.
300  */
301 extern int drv_insert_dev_object(struct drv_object *driver_obj,
302  struct dev_object *hdev_obj);
303 
304 /*
305  * ======== drv_remove_dev_object ========
306  * Purpose:
307  * Search for and remove a Device object from the given list of Device Obj
308  * objects.
309  * Parameters:
310  * driver_obj: Handle to DrvObject
311  * hdev_obj: Handle to DevObject to Remove
312  * Returns:
313  * 0: Success.
314  * -EPERM: Unable to find dev_obj.
315  * Requires:
316  * hdrv_obj != NULL and a Valid DRV Handle.
317  * hdev_obj != NULL.
318  * List exists and is not empty.
319  * Ensures:
320  * List either does not exist (NULL), or is not empty if it does exist.
321  */
322 extern int drv_remove_dev_object(struct drv_object *driver_obj,
323  struct dev_object *hdev_obj);
324 
325 /*
326  * ======== drv_request_resources ========
327  * Purpose:
328  * Assigns the Resources or Releases them.
329  * Parameters:
330  * dw_context: Path to the driver Registry Key.
331  * dev_node_strg: Ptr to dev_node String stored in the Device Ext.
332  * Returns:
333  * TRUE if success; FALSE otherwise.
334  * Requires:
335  * Ensures:
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.
341  */
342 extern int drv_request_resources(u32 dw_context,
343  u32 *dev_node_strg);
344 
345 /*
346  * ======== drv_release_resources ========
347  * Purpose:
348  * Assigns the Resources or Releases them.
349  * Parameters:
350  * dw_context: Path to the driver Registry Key.
351  * hdrv_obj: Handle to the Driver Object.
352  * Returns:
353  * TRUE if success; FALSE otherwise.
354  * Requires:
355  * Ensures:
356  * The Resources are released based on Bus type.
357  * Resource structure is deleted from the registry
358  */
359 extern int drv_release_resources(u32 dw_context,
360  struct drv_object *hdrv_obj);
361 
366 int drv_request_bridge_res_dsp(void **phost_resources);
367 
368 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
369 void bridge_recover_schedule(void);
370 #endif
371 
372 /*
373  * ======== mem_ext_phys_pool_init ========
374  * Purpose:
375  * Uses the physical memory chunk passed for internal consistent memory
376  * allocations.
377  * physical address based on the page frame address.
378  * Parameters:
379  * pool_phys_base starting address of the physical memory pool.
380  * pool_size size of the physical memory pool.
381  * Returns:
382  * none.
383  * Requires:
384  * - MEM initialized.
385  * - valid physical address for the base and size > 0
386  */
387 extern void mem_ext_phys_pool_init(u32 pool_phys_base, u32 pool_size);
388 
389 /*
390  * ======== mem_ext_phys_pool_release ========
391  */
392 extern void mem_ext_phys_pool_release(void);
393 
394 /* ======== mem_alloc_phys_mem ========
395  * Purpose:
396  * Allocate physically contiguous, uncached memory
397  * Parameters:
398  * byte_size: Number of bytes to allocate.
399  * align_mask: Alignment Mask.
400  * physical_address: Physical address of allocated memory.
401  * Returns:
402  * Pointer to a block of memory;
403  * NULL if memory couldn't be allocated, or if byte_size == 0.
404  * Requires:
405  * MEM initialized.
406  * Ensures:
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.
410  */
411 extern void *mem_alloc_phys_mem(u32 byte_size,
412  u32 align_mask, u32 *physical_address);
413 
414 /*
415  * ======== mem_free_phys_mem ========
416  * Purpose:
417  * Free the given block of physically contiguous memory.
418  * Parameters:
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().
424  * Returns:
425  * Requires:
426  * MEM initialized.
427  * virtual_address is a valid memory address returned by
428  * mem_alloc_phys_mem()
429  * Ensures:
430  * virtual_address is no longer a valid pointer to memory.
431  */
432 extern void mem_free_phys_mem(void *virtual_address,
433  u32 physical_address, u32 byte_size);
434 
435 /*
436  * ======== MEM_LINEAR_ADDRESS ========
437  * Purpose:
438  * Get the linear address corresponding to the given physical address.
439  * Parameters:
440  * phys_addr: Physical address to be mapped.
441  * byte_size: Number of bytes in physical range to map.
442  * Returns:
443  * The corresponding linear address, or NULL if unsuccessful.
444  * Requires:
445  * MEM initialized.
446  * Ensures:
447  * Notes:
448  * If valid linear address is returned, be sure to call
449  * MEM_UNMAP_LINEAR_ADDRESS().
450  */
451 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
452 
453 /*
454  * ======== MEM_UNMAP_LINEAR_ADDRESS ========
455  * Purpose:
456  * Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
457  * Parameters:
458  * base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
459  * Returns:
460  * Requires:
461  * - MEM initialized.
462  * - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
463  * Ensures:
464  * - base_addr no longer points to a valid linear address.
465  */
466 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}
467 
468 #endif /* DRV_ */