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