]> Pileus Git - ~andy/linux/blob - drivers/staging/tidspbridge/include/dspbridge/drv.h
staging: ti dspbridge: make variables in prototypes match within functions definitions
[~andy/linux] / drivers / staging / tidspbridge / include / dspbridge / drv.h
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 <dspbridge/drvdefs.h>
27
28 #define DRV_ASSIGN     1
29 #define DRV_RELEASE    0
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 #define OMAP_DSP_GEM1_BASE 0x107F8000
41
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
46
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
51
52 #define OMAP_IVA2_PRM_BASE 0x48306000
53 #define OMAP_IVA2_PRM_SIZE 0x1000
54
55 #define OMAP_IVA2_CM_BASE 0x48004000
56 #define OMAP_IVA2_CM_SIZE 0x1000
57
58 #define OMAP_PER_CM_BASE 0x48005000
59 #define OMAP_PER_CM_SIZE 0x1000
60
61 #define OMAP_PER_PRM_BASE 0x48307000
62 #define OMAP_PER_PRM_SIZE 0x1000
63
64 #define OMAP_CORE_PRM_BASE 0x48306A00
65 #define OMAP_CORE_PRM_SIZE 0x1000
66
67 #define OMAP_SYSC_BASE 0x48002000
68 #define OMAP_SYSC_SIZE 0x1000
69
70 #define OMAP_DMMU_BASE 0x5D000000
71 #define OMAP_DMMU_SIZE 0x1000
72
73 #define OMAP_PRCM_VDD1_DOMAIN 1
74 #define OMAP_PRCM_VDD2_DOMAIN 2
75
76 /* GPP PROCESS CLEANUP Data structures */
77
78 /* New structure (member of process context) abstracts NODE resource info */
79 struct node_res_object {
80         void *hnode;
81         s32 node_allocated;     /* Node status */
82         s32 heap_allocated;     /* Heap status */
83         s32 streams_allocated;  /* Streams status */
84         struct node_res_object *next;
85 };
86
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 */
92         int num_pages;
93         /* number of elements returned from dma_map_sg */
94         int sg_num;
95         /* list of buffers used in this DMA action */
96         struct scatterlist *sg;
97 };
98
99 /* Used for DMM mapped memory accounting */
100 struct dmm_map_object {
101         struct list_head link;
102         u32 dsp_addr;
103         u32 mpu_addr;
104         u32 size;
105         u32 num_usr_pgs;
106         struct page **pages;
107         struct bridge_dma_map_info dma_info;
108 };
109
110 /* Used for DMM reserved memory accounting */
111 struct dmm_rsv_object {
112         struct list_head link;
113         u32 dsp_reserved_addr;
114 };
115
116 /* New structure (member of process context) abstracts DMM resource info */
117 struct dspheap_res_object {
118         s32 heap_allocated;     /* DMM status */
119         u32 ul_mpu_addr;
120         u32 ul_dsp_addr;
121         u32 ul_dsp_res_addr;
122         u32 heap_size;
123         void *hprocessor;
124         struct dspheap_res_object *next;
125 };
126
127 /* New structure (member of process context) abstracts stream resource info */
128 struct strm_res_object {
129         s32 stream_allocated;   /* Stream status */
130         void *hstream;
131         u32 num_bufs;
132         u32 dir;
133         struct strm_res_object *next;
134 };
135
136 /* Overall Bridge process resource usage state */
137 enum gpp_proc_res_state {
138         PROC_RES_ALLOCATED,
139         PROC_RES_FREED
140 };
141
142 /* Bridge Data */
143 struct drv_data {
144         char *base_img;
145         s32 shm_size;
146         int tc_wordswapon;
147         void *drv_object;
148         void *dev_object;
149         void *mgr_object;
150 };
151
152 /* Process Context */
153 struct process_context {
154         /* Process State */
155         enum gpp_proc_res_state res_state;
156
157         /* Handle to Processor */
158         void *hprocessor;
159
160         /* DSP Node resources */
161         struct node_res_object *node_list;
162         struct mutex node_mutex;
163
164         /* DMM mapped memory resources */
165         struct list_head dmm_map_list;
166         spinlock_t dmm_map_lock;
167
168         /* DMM reserved memory resources */
169         struct list_head dmm_rsv_list;
170         spinlock_t dmm_rsv_lock;
171
172         /* DSP Heap resources */
173         struct dspheap_res_object *pdspheap_list;
174
175         /* Stream resources */
176         struct strm_res_object *pstrm_list;
177         struct mutex strm_mutex;
178 };
179
180 /*
181  *  ======== drv_create ========
182  *  Purpose:
183  *      Creates the Driver Object. This is done during the driver loading.
184  *      There is only one Driver Object in the DSP/BIOS Bridge.
185  *  Parameters:
186  *      drv_obj:        Location to store created DRV Object handle.
187  *  Returns:
188  *      0:        Sucess
189  *      -ENOMEM:    Failed in Memory allocation
190  *      -EPERM:      General Failure
191  *  Requires:
192  *      DRV Initialized (refs > 0 )
193  *      drv_obj != NULL.
194  *  Ensures:
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
200  *  Details:
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.
206  */
207 extern int drv_create(struct drv_object **drv_obj);
208
209 /*
210  *  ======== drv_destroy ========
211  *  Purpose:
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.
215  *  Parameters:
216  *      driver_obj:     Handle to Driver object .
217  *  Returns:
218  *      0:        Success.
219  *      -EPERM:      Failed to destroy DRV Object
220  *  Requires:
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
225  *  Ensures:
226  *      0:        - DRV Object destroyed and hdrv_obj is not a valid
227  *                        DRV handle.
228  *                      - Registry is updated with "0" as the DRV Object.
229  */
230 extern int drv_destroy(struct drv_object *driver_obj);
231
232 /*
233  *  ======== drv_exit ========
234  *  Purpose:
235  *      Exit the DRV module, freeing any modules initialized in drv_init.
236  *  Parameters:
237  *  Returns:
238  *  Requires:
239  *  Ensures:
240  */
241 extern void drv_exit(void);
242
243 /*
244  *  ======== drv_get_first_dev_object ========
245  *  Purpose:
246  *      Returns the Ptr to the FirstDev Object in the List
247  *  Parameters:
248  *  Requires:
249  *      DRV Initialized
250  *  Returns:
251  *      dw_dev_object:  Ptr to the First Dev Object as a u32
252  *      0 if it fails to retrieve the First Dev Object
253  *  Ensures:
254  */
255 extern u32 drv_get_first_dev_object(void);
256
257 /*
258  *  ======== drv_get_first_dev_extension ========
259  *  Purpose:
260  *      Returns the Ptr to the First Device Extension in the List
261  *  Parameters:
262  *  Requires:
263  *      DRV Initialized
264  *  Returns:
265  *      dw_dev_extension:     Ptr to the First Device Extension as a u32
266  *      0:                  Failed to Get the Device Extension
267  *  Ensures:
268  */
269 extern u32 drv_get_first_dev_extension(void);
270
271 /*
272  *  ======== drv_get_dev_object ========
273  *  Purpose:
274  *      Given a index, returns a handle to DevObject from the list
275  *  Parameters:
276  *      hdrv_obj:     Handle to the Manager
277  *      device_obj:     Location to store the Dev Handle
278  *  Requires:
279  *      DRV Initialized
280  *      index >= 0
281  *      hdrv_obj is not NULL and Valid DRV Object
282  *      device_obj is not NULL
283  *      Device Object List not Empty
284  *  Returns:
285  *      0:        Success
286  *      -EPERM:      Failed to Get the Dev Object
287  *  Ensures:
288  *      0:        *device_obj != NULL
289  *      -EPERM:      *device_obj = NULL
290  */
291 extern int drv_get_dev_object(u32 index,
292                                      struct drv_object *hdrv_obj,
293                                      struct dev_object **device_obj);
294
295 /*
296  *  ======== drv_get_next_dev_object ========
297  *  Purpose:
298  *      Returns the Ptr to the Next Device Object from the the List
299  *  Parameters:
300  *      hdev_obj:     Handle to the Device Object
301  *  Requires:
302  *      DRV Initialized
303  *      hdev_obj != 0
304  *  Returns:
305  *      dw_dev_object:    Ptr to the Next Dev Object as a u32
306  *      0:              If it fail to get the next Dev Object.
307  *  Ensures:
308  */
309 extern u32 drv_get_next_dev_object(u32 hdev_obj);
310
311 /*
312  *  ======== drv_get_next_dev_extension ========
313  *  Purpose:
314  *      Returns the Ptr to the Next Device Extension from the the List
315  *  Parameters:
316  *      dev_extension:      Handle to the Device Extension
317  *  Requires:
318  *      DRV Initialized
319  *      dev_extension != 0.
320  *  Returns:
321  *      dw_dev_extension:     Ptr to the Next Dev Extension
322  *      0:                  If it fail to Get the next Dev Extension
323  *  Ensures:
324  */
325 extern u32 drv_get_next_dev_extension(u32 dev_extension);
326
327 /*
328  *  ======== drv_init ========
329  *  Purpose:
330  *      Initialize the DRV module.
331  *  Parameters:
332  *  Returns:
333  *      TRUE if success; FALSE otherwise.
334  *  Requires:
335  *  Ensures:
336  */
337 extern int drv_init(void);
338
339 /*
340  *  ======== drv_insert_dev_object ========
341  *  Purpose:
342  *      Insert a DeviceObject into the list of Driver object.
343  *  Parameters:
344  *      driver_obj:     Handle to DrvObject
345  *      hdev_obj:     Handle to DeviceObject to insert.
346  *  Returns:
347  *      0:        If successful.
348  *      -EPERM:      General Failure:
349  *  Requires:
350  *      hdrv_obj != NULL and Valid DRV Handle.
351  *      hdev_obj != NULL.
352  *  Ensures:
353  *      0:        Device Object is inserted and the List is not empty.
354  */
355 extern int drv_insert_dev_object(struct drv_object *driver_obj,
356                                         struct dev_object *hdev_obj);
357
358 /*
359  *  ======== drv_remove_dev_object ========
360  *  Purpose:
361  *      Search for and remove a Device object from the given list of Device Obj
362  *      objects.
363  *  Parameters:
364  *      driver_obj:     Handle to DrvObject
365  *      hdev_obj:     Handle to DevObject to Remove
366  *  Returns:
367  *      0:        Success.
368  *      -EPERM:      Unable to find dev_obj.
369  *  Requires:
370  *      hdrv_obj != NULL and a Valid DRV Handle.
371  *      hdev_obj != NULL.
372  *      List exists and is not empty.
373  *  Ensures:
374  *      List either does not exist (NULL), or is not empty if it does exist.
375  */
376 extern int drv_remove_dev_object(struct drv_object *driver_obj,
377                                         struct dev_object *hdev_obj);
378
379 /*
380  *  ======== drv_request_resources ========
381  *  Purpose:
382  *      Assigns the Resources or Releases them.
383  *  Parameters:
384  *      dw_context:          Path to the driver Registry Key.
385  *      dev_node_strg:     Ptr to dev_node String stored in the Device Ext.
386  *  Returns:
387  *      TRUE if success; FALSE otherwise.
388  *  Requires:
389  *  Ensures:
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.
395  */
396 extern int drv_request_resources(IN u32 dw_context,
397                                         OUT u32 *dev_node_strg);
398
399 /*
400  *  ======== drv_release_resources ========
401  *  Purpose:
402  *      Assigns the Resources or Releases them.
403  *  Parameters:
404  *      dw_context:      Path to the driver Registry Key.
405  *      hdrv_obj:     Handle to the Driver Object.
406  *  Returns:
407  *      TRUE if success; FALSE otherwise.
408  *  Requires:
409  *  Ensures:
410  *      The Resources are released based on Bus type.
411  *      Resource structure is deleted from the registry
412  */
413 extern int drv_release_resources(IN u32 dw_context,
414                                         struct drv_object *hdrv_obj);
415
416 /**
417  * drv_request_bridge_res_dsp() - Reserves shared memory for bridge.
418  * @phost_resources:  pointer to host resources.
419  */
420 int drv_request_bridge_res_dsp(void **phost_resources);
421
422 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
423 void bridge_recover_schedule(void);
424 #endif
425
426 /*
427  *  ======== mem_ext_phys_pool_init ========
428  *  Purpose:
429  *      Uses the physical memory chunk passed for internal consitent memory
430  *      allocations.
431  *      physical address based on the page frame address.
432  *  Parameters:
433  *      pool_phys_base  starting address of the physical memory pool.
434  *      pool_size      size of the physical memory pool.
435  *  Returns:
436  *      none.
437  *  Requires:
438  *      - MEM initialized.
439  *      - valid physical address for the base and size > 0
440  */
441 extern void mem_ext_phys_pool_init(IN u32 pool_phys_base, IN u32 pool_size);
442
443 /*
444  *  ======== mem_ext_phys_pool_release ========
445  */
446 extern void mem_ext_phys_pool_release(void);
447
448 /*  ======== mem_alloc_phys_mem ========
449  *  Purpose:
450  *      Allocate physically contiguous, uncached memory
451  *  Parameters:
452  *      byte_size:     Number of bytes to allocate.
453  *      align_mask:    Alignment Mask.
454  *      physical_address: Physical address of allocated memory.
455  *  Returns:
456  *      Pointer to a block of memory;
457  *      NULL if memory couldn't be allocated, or if byte_size == 0.
458  *  Requires:
459  *      MEM initialized.
460  *  Ensures:
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.
464  */
465 extern void *mem_alloc_phys_mem(IN u32 byte_size,
466                                 IN u32 align_mask, OUT u32 *physical_address);
467
468 /*
469  *  ======== mem_free_phys_mem ========
470  *  Purpose:
471  *      Free the given block of physically contiguous memory.
472  *  Parameters:
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().
478  *  Returns:
479  *  Requires:
480  *      MEM initialized.
481  *      virtual_address is a valid memory address returned by
482  *          mem_alloc_phys_mem()
483  *  Ensures:
484  *      virtual_address is no longer a valid pointer to memory.
485  */
486 extern void mem_free_phys_mem(void *virtual_address,
487                               u32 physical_address, u32 byte_size);
488
489 /*
490  *  ======== MEM_LINEAR_ADDRESS ========
491  *  Purpose:
492  *      Get the linear address corresponding to the given physical address.
493  *  Parameters:
494  *      phys_addr:  Physical address to be mapped.
495  *      byte_size:     Number of bytes in physical range to map.
496  *  Returns:
497  *      The corresponding linear address, or NULL if unsuccessful.
498  *  Requires:
499  *      MEM initialized.
500  *  Ensures:
501  *  Notes:
502  *      If valid linear address is returned, be sure to call
503  *      MEM_UNMAP_LINEAR_ADDRESS().
504  */
505 #define MEM_LINEAR_ADDRESS(phy_addr, byte_size) phy_addr
506
507 /*
508  *  ======== MEM_UNMAP_LINEAR_ADDRESS ========
509  *  Purpose:
510  *      Unmap the linear address mapped in MEM_LINEAR_ADDRESS.
511  *  Parameters:
512  *      base_addr: Ptr to mapped memory (as returned by MEM_LINEAR_ADDRESS()).
513  *  Returns:
514  *  Requires:
515  *      - MEM initialized.
516  *      - base_addr is a valid linear address mapped in MEM_LINEAR_ADDRESS.
517  *  Ensures:
518  *      - base_addr no longer points to a valid linear address.
519  */
520 #define MEM_UNMAP_LINEAR_ADDRESS(base_addr) {}
521
522 #endif /* DRV_ */