4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Implementation of Bridge Bridge driver device operations.
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <linux/types.h>
19 #include <linux/list.h>
21 /* ----------------------------------- Host OS */
22 #include <dspbridge/host_os.h>
24 /* ----------------------------------- DSP/BIOS Bridge */
25 #include <dspbridge/dbdefs.h>
27 /* ----------------------------------- Trace & Debug */
28 #include <dspbridge/dbc.h>
30 /* ----------------------------------- OS Adaptation Layer */
31 #include <dspbridge/ldr.h>
33 /* ----------------------------------- Platform Manager */
34 #include <dspbridge/cod.h>
35 #include <dspbridge/drv.h>
36 #include <dspbridge/proc.h>
37 #include <dspbridge/dmm.h>
39 /* ----------------------------------- Resource Manager */
40 #include <dspbridge/mgr.h>
41 #include <dspbridge/node.h>
43 /* ----------------------------------- Others */
44 #include <dspbridge/dspapi.h> /* DSP API version info. */
46 #include <dspbridge/chnl.h>
47 #include <dspbridge/io.h>
48 #include <dspbridge/msg.h>
49 #include <dspbridge/cmm.h>
50 #include <dspbridge/dspdeh.h>
52 /* ----------------------------------- This */
53 #include <dspbridge/dev.h>
55 /* ----------------------------------- Defines, Data Structures, Typedefs */
57 #define MAKEVERSION(major, minor) (major * 10 + minor)
58 #define BRD_API_VERSION MAKEVERSION(BRD_API_MAJOR_VERSION, \
59 BRD_API_MINOR_VERSION)
61 /* The Bridge device object: */
63 struct list_head link
; /* Link to next dev_object. */
64 u8 dev_type
; /* Device Type */
65 struct cfg_devnode
*dev_node_obj
; /* Platform specific dev id */
66 /* Bridge Context Handle */
67 struct bridge_dev_context
*hbridge_context
;
68 /* Function interface to Bridge driver. */
69 struct bridge_drv_interface bridge_interface
;
70 struct brd_object
*lock_owner
; /* Client with exclusive access. */
71 struct cod_manager
*cod_mgr
; /* Code manager handle. */
72 struct chnl_mgr
*hchnl_mgr
; /* Channel manager. */
73 struct deh_mgr
*hdeh_mgr
; /* DEH manager. */
74 struct msg_mgr
*hmsg_mgr
; /* Message manager. */
75 struct io_mgr
*hio_mgr
; /* IO manager (CHNL, msg_ctrl) */
76 struct cmm_object
*hcmm_mgr
; /* SM memory manager. */
77 struct dmm_object
*dmm_mgr
; /* Dynamic memory manager. */
78 struct ldr_module
*module_obj
; /* Bridge Module handle. */
79 u32 word_size
; /* DSP word size: quick access. */
80 struct drv_object
*hdrv_obj
; /* Driver Object */
81 struct list_head proc_list
; /* List of Processor attached to
83 struct node_mgr
*hnode_mgr
;
87 struct list_head link
;
88 char sz_string
[MAXREGPATHLENGTH
];
91 /* ----------------------------------- Globals */
92 static u32 refs
; /* Module reference count */
94 /* ----------------------------------- Function Prototypes */
95 static int fxn_not_implemented(int arg
, ...);
96 static int init_cod_mgr(struct dev_object
*dev_obj
);
97 static void store_interface_fxns(struct bridge_drv_interface
*drv_fxns
,
98 struct bridge_drv_interface
*intf_fxns
);
100 * ======== dev_brd_write_fxn ========
102 * Exported function to be used as the COD write function. This function
103 * is passed a handle to a DEV_hObject, then calls the
104 * device's bridge_brd_write() function.
106 u32
dev_brd_write_fxn(void *arb
, u32 dsp_add
, void *host_buf
,
107 u32 ul_num_bytes
, u32 mem_space
)
109 struct dev_object
*dev_obj
= (struct dev_object
*)arb
;
113 DBC_REQUIRE(refs
> 0);
114 DBC_REQUIRE(host_buf
!= NULL
); /* Required of BrdWrite(). */
116 /* Require of BrdWrite() */
117 DBC_ASSERT(dev_obj
->hbridge_context
!= NULL
);
118 status
= (*dev_obj
->bridge_interface
.pfn_brd_write
) (
119 dev_obj
->hbridge_context
, host_buf
,
120 dsp_add
, ul_num_bytes
, mem_space
);
121 /* Special case of getting the address only */
122 if (ul_num_bytes
== 0)
125 ul_written
= ul_num_bytes
;
132 * ======== dev_create_device ========
134 * Called by the operating system to load the PM Bridge Driver for a
137 int dev_create_device(struct dev_object
**device_obj
,
138 const char *driver_file_name
,
139 struct cfg_devnode
*dev_node_obj
)
141 struct cfg_hostres
*host_res
;
142 struct ldr_module
*module_obj
= NULL
;
143 struct bridge_drv_interface
*drv_fxns
= NULL
;
144 struct dev_object
*dev_obj
= NULL
;
145 struct chnl_mgrattrs mgr_attrs
;
146 struct io_attrs io_mgr_attrs
;
148 struct drv_object
*hdrv_obj
= NULL
;
149 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
151 DBC_REQUIRE(refs
> 0);
152 DBC_REQUIRE(device_obj
!= NULL
);
153 DBC_REQUIRE(driver_file_name
!= NULL
);
155 status
= drv_request_bridge_res_dsp((void *)&host_res
);
158 dev_dbg(bridge
, "%s: Failed to reserve bridge resources\n",
163 /* Get the Bridge driver interface functions */
164 bridge_drv_entry(&drv_fxns
, driver_file_name
);
166 /* Retrieve the Object handle from the driver data */
167 if (drv_datap
&& drv_datap
->drv_object
) {
168 hdrv_obj
= drv_datap
->drv_object
;
171 pr_err("%s: Failed to retrieve the object handle\n", __func__
);
174 /* Create the device object, and pass a handle to the Bridge driver for
177 DBC_ASSERT(drv_fxns
);
178 dev_obj
= kzalloc(sizeof(struct dev_object
), GFP_KERNEL
);
180 /* Fill out the rest of the Dev Object structure: */
181 dev_obj
->dev_node_obj
= dev_node_obj
;
182 dev_obj
->module_obj
= module_obj
;
183 dev_obj
->cod_mgr
= NULL
;
184 dev_obj
->hchnl_mgr
= NULL
;
185 dev_obj
->hdeh_mgr
= NULL
;
186 dev_obj
->lock_owner
= NULL
;
187 dev_obj
->word_size
= DSPWORDSIZE
;
188 dev_obj
->hdrv_obj
= hdrv_obj
;
189 dev_obj
->dev_type
= DSP_UNIT
;
190 /* Store this Bridge's interface functions, based on its
192 store_interface_fxns(drv_fxns
,
193 &dev_obj
->bridge_interface
);
195 /* Call fxn_dev_create() to get the Bridge's device
197 status
= (dev_obj
->bridge_interface
.pfn_dev_create
)
198 (&dev_obj
->hbridge_context
, dev_obj
,
200 /* Assert bridge_dev_create()'s ensure clause: */
202 || (dev_obj
->hbridge_context
!= NULL
));
207 /* Attempt to create the COD manager for this device: */
209 status
= init_cod_mgr(dev_obj
);
211 /* Attempt to create the channel manager for this device: */
213 mgr_attrs
.max_channels
= CHNL_MAXCHANNELS
;
214 io_mgr_attrs
.birq
= host_res
->birq_registers
;
215 io_mgr_attrs
.irq_shared
=
216 (host_res
->birq_attrib
& CFG_IRQSHARED
);
217 io_mgr_attrs
.word_size
= DSPWORDSIZE
;
218 mgr_attrs
.word_size
= DSPWORDSIZE
;
219 num_windows
= host_res
->num_mem_windows
;
221 /* Assume last memory window is for CHNL */
222 io_mgr_attrs
.shm_base
= host_res
->dw_mem_base
[1] +
223 host_res
->dw_offset_for_monitor
;
224 io_mgr_attrs
.usm_length
=
225 host_res
->dw_mem_length
[1] -
226 host_res
->dw_offset_for_monitor
;
228 io_mgr_attrs
.shm_base
= 0;
229 io_mgr_attrs
.usm_length
= 0;
230 pr_err("%s: No memory reserved for shared structures\n",
233 status
= chnl_create(&dev_obj
->hchnl_mgr
, dev_obj
, &mgr_attrs
);
234 if (status
== -ENOSYS
) {
235 /* It's OK for a device not to have a channel
239 /* Create CMM mgr even if Msg Mgr not impl. */
240 status
= cmm_create(&dev_obj
->hcmm_mgr
,
241 (struct dev_object
*)dev_obj
, NULL
);
242 /* Only create IO manager if we have a channel manager */
243 if (!status
&& dev_obj
->hchnl_mgr
) {
244 status
= io_create(&dev_obj
->hio_mgr
, dev_obj
,
247 /* Only create DEH manager if we have an IO manager */
249 /* Instantiate the DEH module */
250 status
= bridge_deh_create(&dev_obj
->hdeh_mgr
, dev_obj
);
252 /* Create DMM mgr . */
253 status
= dmm_create(&dev_obj
->dmm_mgr
,
254 (struct dev_object
*)dev_obj
, NULL
);
256 /* Add the new DEV_Object to the global list: */
258 status
= drv_insert_dev_object(hdrv_obj
, dev_obj
);
260 /* Create the Processor List */
262 INIT_LIST_HEAD(&dev_obj
->proc_list
);
264 /* If all went well, return a handle to the dev object;
265 * else, cleanup and return NULL in the OUT parameter. */
267 *device_obj
= dev_obj
;
270 if (dev_obj
->cod_mgr
)
271 cod_delete(dev_obj
->cod_mgr
);
272 if (dev_obj
->dmm_mgr
)
273 dmm_destroy(dev_obj
->dmm_mgr
);
280 DBC_ENSURE((!status
&& *device_obj
) || (status
&& !*device_obj
));
285 * ======== dev_create2 ========
287 * After successful loading of the image from api_init_complete2
288 * (PROC Auto_Start) or proc_load this fxn is called. This creates
289 * the Node Manager and updates the DEV Object.
291 int dev_create2(struct dev_object
*hdev_obj
)
294 struct dev_object
*dev_obj
= hdev_obj
;
296 DBC_REQUIRE(refs
> 0);
297 DBC_REQUIRE(hdev_obj
);
299 /* There can be only one Node Manager per DEV object */
300 DBC_ASSERT(!dev_obj
->hnode_mgr
);
301 status
= node_create_mgr(&dev_obj
->hnode_mgr
, hdev_obj
);
303 dev_obj
->hnode_mgr
= NULL
;
305 DBC_ENSURE((!status
&& dev_obj
->hnode_mgr
!= NULL
)
306 || (status
&& dev_obj
->hnode_mgr
== NULL
));
311 * ======== dev_destroy2 ========
313 * Destroys the Node manager for this device.
315 int dev_destroy2(struct dev_object
*hdev_obj
)
318 struct dev_object
*dev_obj
= hdev_obj
;
320 DBC_REQUIRE(refs
> 0);
321 DBC_REQUIRE(hdev_obj
);
323 if (dev_obj
->hnode_mgr
) {
324 if (node_delete_mgr(dev_obj
->hnode_mgr
))
327 dev_obj
->hnode_mgr
= NULL
;
331 DBC_ENSURE((!status
&& dev_obj
->hnode_mgr
== NULL
) || status
);
336 * ======== dev_destroy_device ========
338 * Destroys the channel manager for this device, if any, calls
339 * bridge_dev_destroy(), and then attempts to unload the Bridge module.
341 int dev_destroy_device(struct dev_object
*hdev_obj
)
344 struct dev_object
*dev_obj
= hdev_obj
;
346 DBC_REQUIRE(refs
> 0);
349 if (dev_obj
->cod_mgr
) {
350 cod_delete(dev_obj
->cod_mgr
);
351 dev_obj
->cod_mgr
= NULL
;
354 if (dev_obj
->hnode_mgr
) {
355 node_delete_mgr(dev_obj
->hnode_mgr
);
356 dev_obj
->hnode_mgr
= NULL
;
359 /* Free the io, channel, and message managers for this board: */
360 if (dev_obj
->hio_mgr
) {
361 io_destroy(dev_obj
->hio_mgr
);
362 dev_obj
->hio_mgr
= NULL
;
364 if (dev_obj
->hchnl_mgr
) {
365 chnl_destroy(dev_obj
->hchnl_mgr
);
366 dev_obj
->hchnl_mgr
= NULL
;
368 if (dev_obj
->hmsg_mgr
) {
369 msg_delete(dev_obj
->hmsg_mgr
);
370 dev_obj
->hmsg_mgr
= NULL
;
373 if (dev_obj
->hdeh_mgr
) {
374 /* Uninitialize DEH module. */
375 bridge_deh_destroy(dev_obj
->hdeh_mgr
);
376 dev_obj
->hdeh_mgr
= NULL
;
378 if (dev_obj
->hcmm_mgr
) {
379 cmm_destroy(dev_obj
->hcmm_mgr
, true);
380 dev_obj
->hcmm_mgr
= NULL
;
383 if (dev_obj
->dmm_mgr
) {
384 dmm_destroy(dev_obj
->dmm_mgr
);
385 dev_obj
->dmm_mgr
= NULL
;
388 /* Call the driver's bridge_dev_destroy() function: */
389 /* Require of DevDestroy */
390 if (dev_obj
->hbridge_context
) {
391 status
= (*dev_obj
->bridge_interface
.pfn_dev_destroy
)
392 (dev_obj
->hbridge_context
);
393 dev_obj
->hbridge_context
= NULL
;
397 /* Remove this DEV_Object from the global list: */
398 drv_remove_dev_object(dev_obj
->hdrv_obj
, dev_obj
);
399 /* Free The library * LDR_FreeModule
400 * (dev_obj->module_obj); */
401 /* Free this dev object: */
413 * ======== dev_get_chnl_mgr ========
415 * Retrieve the handle to the channel manager handle created for this
418 int dev_get_chnl_mgr(struct dev_object
*hdev_obj
,
419 struct chnl_mgr
**mgr
)
422 struct dev_object
*dev_obj
= hdev_obj
;
424 DBC_REQUIRE(refs
> 0);
425 DBC_REQUIRE(mgr
!= NULL
);
428 *mgr
= dev_obj
->hchnl_mgr
;
434 DBC_ENSURE(!status
|| (mgr
!= NULL
&& *mgr
== NULL
));
439 * ======== dev_get_cmm_mgr ========
441 * Retrieve the handle to the shared memory manager created for this
444 int dev_get_cmm_mgr(struct dev_object
*hdev_obj
,
445 struct cmm_object
**mgr
)
448 struct dev_object
*dev_obj
= hdev_obj
;
450 DBC_REQUIRE(refs
> 0);
451 DBC_REQUIRE(mgr
!= NULL
);
454 *mgr
= dev_obj
->hcmm_mgr
;
460 DBC_ENSURE(!status
|| (mgr
!= NULL
&& *mgr
== NULL
));
465 * ======== dev_get_dmm_mgr ========
467 * Retrieve the handle to the dynamic memory manager created for this
470 int dev_get_dmm_mgr(struct dev_object
*hdev_obj
,
471 struct dmm_object
**mgr
)
474 struct dev_object
*dev_obj
= hdev_obj
;
476 DBC_REQUIRE(refs
> 0);
477 DBC_REQUIRE(mgr
!= NULL
);
480 *mgr
= dev_obj
->dmm_mgr
;
486 DBC_ENSURE(!status
|| (mgr
!= NULL
&& *mgr
== NULL
));
491 * ======== dev_get_cod_mgr ========
493 * Retrieve the COD manager create for this device.
495 int dev_get_cod_mgr(struct dev_object
*hdev_obj
,
496 struct cod_manager
**cod_mgr
)
499 struct dev_object
*dev_obj
= hdev_obj
;
501 DBC_REQUIRE(refs
> 0);
502 DBC_REQUIRE(cod_mgr
!= NULL
);
505 *cod_mgr
= dev_obj
->cod_mgr
;
511 DBC_ENSURE(!status
|| (cod_mgr
!= NULL
&& *cod_mgr
== NULL
));
516 * ========= dev_get_deh_mgr ========
518 int dev_get_deh_mgr(struct dev_object
*hdev_obj
,
519 struct deh_mgr
**deh_manager
)
523 DBC_REQUIRE(refs
> 0);
524 DBC_REQUIRE(deh_manager
!= NULL
);
525 DBC_REQUIRE(hdev_obj
);
527 *deh_manager
= hdev_obj
->hdeh_mgr
;
536 * ======== dev_get_dev_node ========
538 * Retrieve the platform specific device ID for this device.
540 int dev_get_dev_node(struct dev_object
*hdev_obj
,
541 struct cfg_devnode
**dev_nde
)
544 struct dev_object
*dev_obj
= hdev_obj
;
546 DBC_REQUIRE(refs
> 0);
547 DBC_REQUIRE(dev_nde
!= NULL
);
550 *dev_nde
= dev_obj
->dev_node_obj
;
556 DBC_ENSURE(!status
|| (dev_nde
!= NULL
&& *dev_nde
== NULL
));
561 * ======== dev_get_first ========
563 * Retrieve the first Device Object handle from an internal linked list
564 * DEV_OBJECTs maintained by DEV.
566 struct dev_object
*dev_get_first(void)
568 struct dev_object
*dev_obj
= NULL
;
570 dev_obj
= (struct dev_object
*)drv_get_first_dev_object();
576 * ======== dev_get_intf_fxns ========
578 * Retrieve the Bridge interface function structure for the loaded driver.
581 int dev_get_intf_fxns(struct dev_object
*hdev_obj
,
582 struct bridge_drv_interface
**if_fxns
)
585 struct dev_object
*dev_obj
= hdev_obj
;
587 DBC_REQUIRE(refs
> 0);
588 DBC_REQUIRE(if_fxns
!= NULL
);
591 *if_fxns
= &dev_obj
->bridge_interface
;
597 DBC_ENSURE(!status
|| ((if_fxns
!= NULL
) && (*if_fxns
== NULL
)));
602 * ========= dev_get_io_mgr ========
604 int dev_get_io_mgr(struct dev_object
*hdev_obj
,
605 struct io_mgr
**io_man
)
609 DBC_REQUIRE(refs
> 0);
610 DBC_REQUIRE(io_man
!= NULL
);
611 DBC_REQUIRE(hdev_obj
);
614 *io_man
= hdev_obj
->hio_mgr
;
624 * ======== dev_get_next ========
626 * Retrieve the next Device Object handle from an internal linked list
627 * of DEV_OBJECTs maintained by DEV, after having previously called
628 * dev_get_first() and zero or more dev_get_next
630 struct dev_object
*dev_get_next(struct dev_object
*hdev_obj
)
632 struct dev_object
*next_dev_object
= NULL
;
635 next_dev_object
= (struct dev_object
*)
636 drv_get_next_dev_object((u32
) hdev_obj
);
639 return next_dev_object
;
643 * ========= dev_get_msg_mgr ========
645 void dev_get_msg_mgr(struct dev_object
*hdev_obj
, struct msg_mgr
**msg_man
)
647 DBC_REQUIRE(refs
> 0);
648 DBC_REQUIRE(msg_man
!= NULL
);
649 DBC_REQUIRE(hdev_obj
);
651 *msg_man
= hdev_obj
->hmsg_mgr
;
655 * ======== dev_get_node_manager ========
657 * Retrieve the Node Manager Handle
659 int dev_get_node_manager(struct dev_object
*hdev_obj
,
660 struct node_mgr
**node_man
)
663 struct dev_object
*dev_obj
= hdev_obj
;
665 DBC_REQUIRE(refs
> 0);
666 DBC_REQUIRE(node_man
!= NULL
);
669 *node_man
= dev_obj
->hnode_mgr
;
675 DBC_ENSURE(!status
|| (node_man
!= NULL
&& *node_man
== NULL
));
680 * ======== dev_get_symbol ========
682 int dev_get_symbol(struct dev_object
*hdev_obj
,
683 const char *str_sym
, u32
* pul_value
)
686 struct cod_manager
*cod_mgr
;
688 DBC_REQUIRE(refs
> 0);
689 DBC_REQUIRE(str_sym
!= NULL
&& pul_value
!= NULL
);
692 status
= dev_get_cod_mgr(hdev_obj
, &cod_mgr
);
694 status
= cod_get_sym_value(cod_mgr
, (char *)str_sym
,
704 * ======== dev_get_bridge_context ========
706 * Retrieve the Bridge Context handle, as returned by the
707 * bridge_dev_create fxn.
709 int dev_get_bridge_context(struct dev_object
*hdev_obj
,
710 struct bridge_dev_context
**phbridge_context
)
713 struct dev_object
*dev_obj
= hdev_obj
;
715 DBC_REQUIRE(refs
> 0);
716 DBC_REQUIRE(phbridge_context
!= NULL
);
719 *phbridge_context
= dev_obj
->hbridge_context
;
721 *phbridge_context
= NULL
;
725 DBC_ENSURE(!status
|| ((phbridge_context
!= NULL
) &&
726 (*phbridge_context
== NULL
)));
731 * ======== dev_exit ========
733 * Decrement reference count, and free resources when reference count is
738 DBC_REQUIRE(refs
> 0);
747 DBC_ENSURE(refs
>= 0);
751 * ======== dev_init ========
753 * Initialize DEV's private state, keeping a reference count on each call.
757 bool cmm_ret
, dmm_ret
, ret
= true;
759 DBC_REQUIRE(refs
>= 0);
762 cmm_ret
= cmm_init();
763 dmm_ret
= dmm_init();
765 ret
= cmm_ret
&& dmm_ret
;
780 DBC_ENSURE((ret
&& (refs
> 0)) || (!ret
&& (refs
>= 0)));
786 * ======== dev_notify_clients ========
788 * Notify all clients of this device of a change in device status.
790 int dev_notify_clients(struct dev_object
*hdev_obj
, u32 ret
)
792 struct dev_object
*dev_obj
= hdev_obj
;
793 struct list_head
*curr
;
796 * FIXME: this code needs struct proc_object to have a list_head
797 * at the begining. If not, this can go horribly wrong.
799 list_for_each(curr
, &dev_obj
->proc_list
)
800 proc_notify_clients((void *)curr
, (u32
) ret
);
806 * ======== dev_remove_device ========
808 int dev_remove_device(struct cfg_devnode
*dev_node_obj
)
810 struct dev_object
*hdev_obj
; /* handle to device object */
812 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
820 /* Retrieve the device object handle originaly stored with
823 /* check the device string and then store dev object */
824 if (!strcmp((char *)((struct drv_ext
*)dev_node_obj
)->sz_string
,
826 hdev_obj
= drv_datap
->dev_object
;
827 /* Destroy the device object. */
828 status
= dev_destroy_device(hdev_obj
);
835 pr_err("%s: Failed, status 0x%x\n", __func__
, status
);
841 * ======== dev_set_chnl_mgr ========
843 * Set the channel manager for this device.
845 int dev_set_chnl_mgr(struct dev_object
*hdev_obj
,
846 struct chnl_mgr
*hmgr
)
849 struct dev_object
*dev_obj
= hdev_obj
;
851 DBC_REQUIRE(refs
> 0);
854 dev_obj
->hchnl_mgr
= hmgr
;
858 DBC_ENSURE(status
|| (dev_obj
->hchnl_mgr
== hmgr
));
863 * ======== dev_set_msg_mgr ========
865 * Set the message manager for this device.
867 void dev_set_msg_mgr(struct dev_object
*hdev_obj
, struct msg_mgr
*hmgr
)
869 DBC_REQUIRE(refs
> 0);
870 DBC_REQUIRE(hdev_obj
);
872 hdev_obj
->hmsg_mgr
= hmgr
;
876 * ======== dev_start_device ========
878 * Initializes the new device with the BRIDGE environment.
880 int dev_start_device(struct cfg_devnode
*dev_node_obj
)
882 struct dev_object
*hdev_obj
= NULL
; /* handle to 'Bridge Device */
883 /* Bridge driver filename */
884 char bridge_file_name
[CFG_MAXSEARCHPATHLEN
] = "UMA";
886 struct mgr_object
*hmgr_obj
= NULL
;
887 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
889 DBC_REQUIRE(refs
> 0);
891 /* Given all resources, create a device object. */
892 status
= dev_create_device(&hdev_obj
, bridge_file_name
,
895 /* Store away the hdev_obj with the DEVNODE */
896 if (!drv_datap
|| !dev_node_obj
) {
898 pr_err("%s: Failed, status 0x%x\n", __func__
, status
);
899 } else if (!(strcmp((char *)dev_node_obj
, "TIOMAP1510"))) {
900 drv_datap
->dev_object
= (void *) hdev_obj
;
903 /* Create the Manager Object */
904 status
= mgr_create(&hmgr_obj
, dev_node_obj
);
905 if (status
&& !(strcmp((char *)dev_node_obj
,
907 /* Ensure the device extension is NULL */
908 drv_datap
->dev_object
= NULL
;
913 dev_destroy_device(hdev_obj
);
922 * ======== fxn_not_implemented ========
924 * Takes the place of a Bridge Null Function.
926 * Multiple, optional.
930 static int fxn_not_implemented(int arg
, ...)
936 * ======== init_cod_mgr ========
938 * Create a COD manager for this device.
940 * dev_obj: Pointer to device object created with
941 * dev_create_device()
944 * -EFAULT: Invalid hdev_obj.
946 * Should only be called once by dev_create_device() for a given DevObject.
949 static int init_cod_mgr(struct dev_object
*dev_obj
)
952 char *sz_dummy_file
= "dummy";
954 DBC_REQUIRE(refs
> 0);
955 DBC_REQUIRE(!dev_obj
|| (dev_obj
->cod_mgr
== NULL
));
957 status
= cod_create(&dev_obj
->cod_mgr
, sz_dummy_file
, NULL
);
963 * ======== dev_insert_proc_object ========
965 * Insert a ProcObject into the list maintained by DEV.
967 * p_proc_object: Ptr to ProcObject to insert.
968 * dev_obj: Ptr to Dev Object where the list is.
969 * already_attached: Ptr to return the bool
974 * hdev_obj is Valid handle
976 * already_attached != NULL
979 * 0 and List is not Empty.
981 int dev_insert_proc_object(struct dev_object
*hdev_obj
,
982 u32 proc_obj
, bool *already_attached
)
985 struct dev_object
*dev_obj
= (struct dev_object
*)hdev_obj
;
987 DBC_REQUIRE(refs
> 0);
988 DBC_REQUIRE(dev_obj
);
989 DBC_REQUIRE(proc_obj
!= 0);
990 DBC_REQUIRE(already_attached
!= NULL
);
991 if (!list_empty(&dev_obj
->proc_list
))
992 *already_attached
= true;
994 /* Add DevObject to tail. */
996 * FIXME: this code needs struct proc_object to have a list_head
997 * at the begining. If not, this can go horribly wrong.
999 list_add_tail((struct list_head
*)proc_obj
, &dev_obj
->proc_list
);
1001 DBC_ENSURE(!status
&& !list_empty(&dev_obj
->proc_list
));
1007 * ======== dev_remove_proc_object ========
1009 * Search for and remove a Proc object from the given list maintained
1012 * p_proc_object: Ptr to ProcObject to insert.
1013 * dev_obj Ptr to Dev Object where the list is.
1017 * List exists and is not empty
1019 * hdev_obj is a valid Dev handle.
1022 * List will be deleted when the DEV is destroyed.
1024 int dev_remove_proc_object(struct dev_object
*hdev_obj
, u32 proc_obj
)
1026 int status
= -EPERM
;
1027 struct list_head
*cur_elem
;
1028 struct dev_object
*dev_obj
= (struct dev_object
*)hdev_obj
;
1030 DBC_REQUIRE(dev_obj
);
1031 DBC_REQUIRE(proc_obj
!= 0);
1032 DBC_REQUIRE(!list_empty(&dev_obj
->proc_list
));
1034 /* Search list for dev_obj: */
1035 list_for_each(cur_elem
, &dev_obj
->proc_list
) {
1036 if ((u32
) cur_elem
== proc_obj
) {
1046 int dev_get_dev_type(struct dev_object
*device_obj
, u8
*dev_type
)
1049 struct dev_object
*dev_obj
= (struct dev_object
*)device_obj
;
1051 *dev_type
= dev_obj
->dev_type
;
1057 * ======== store_interface_fxns ========
1059 * Copy the Bridge's interface functions into the device object,
1060 * ensuring that fxn_not_implemented() is set for:
1062 * 1. All Bridge function pointers which are NULL; and
1063 * 2. All function slots in the struct dev_object structure which have no
1064 * corresponding slots in the the Bridge's interface, because the Bridge
1065 * is of an *older* version.
1067 * intf_fxns: Interface fxn Structure of the Bridge's Dev Object.
1068 * drv_fxns: Interface Fxns offered by the Bridge during DEV_Create().
1071 * Input pointers are valid.
1072 * Bridge driver is *not* written for a newer DSP API.
1074 * All function pointers in the dev object's fxn interface are not NULL.
1076 static void store_interface_fxns(struct bridge_drv_interface
*drv_fxns
,
1077 struct bridge_drv_interface
*intf_fxns
)
1081 /* Local helper macro: */
1082 #define STORE_FXN(cast, pfn) \
1083 (intf_fxns->pfn = ((drv_fxns->pfn != NULL) ? drv_fxns->pfn : \
1084 (cast)fxn_not_implemented))
1086 DBC_REQUIRE(intf_fxns
!= NULL
);
1087 DBC_REQUIRE(drv_fxns
!= NULL
);
1088 DBC_REQUIRE(MAKEVERSION(drv_fxns
->brd_api_major_version
,
1089 drv_fxns
->brd_api_minor_version
) <= BRD_API_VERSION
);
1090 bridge_version
= MAKEVERSION(drv_fxns
->brd_api_major_version
,
1091 drv_fxns
->brd_api_minor_version
);
1092 intf_fxns
->brd_api_major_version
= drv_fxns
->brd_api_major_version
;
1093 intf_fxns
->brd_api_minor_version
= drv_fxns
->brd_api_minor_version
;
1094 /* Install functions up to DSP API version .80 (first alpha): */
1095 if (bridge_version
> 0) {
1096 STORE_FXN(fxn_dev_create
, pfn_dev_create
);
1097 STORE_FXN(fxn_dev_destroy
, pfn_dev_destroy
);
1098 STORE_FXN(fxn_dev_ctrl
, pfn_dev_cntrl
);
1099 STORE_FXN(fxn_brd_monitor
, pfn_brd_monitor
);
1100 STORE_FXN(fxn_brd_start
, pfn_brd_start
);
1101 STORE_FXN(fxn_brd_stop
, pfn_brd_stop
);
1102 STORE_FXN(fxn_brd_status
, pfn_brd_status
);
1103 STORE_FXN(fxn_brd_read
, pfn_brd_read
);
1104 STORE_FXN(fxn_brd_write
, pfn_brd_write
);
1105 STORE_FXN(fxn_brd_setstate
, pfn_brd_set_state
);
1106 STORE_FXN(fxn_brd_memcopy
, pfn_brd_mem_copy
);
1107 STORE_FXN(fxn_brd_memwrite
, pfn_brd_mem_write
);
1108 STORE_FXN(fxn_brd_memmap
, pfn_brd_mem_map
);
1109 STORE_FXN(fxn_brd_memunmap
, pfn_brd_mem_un_map
);
1110 STORE_FXN(fxn_chnl_create
, pfn_chnl_create
);
1111 STORE_FXN(fxn_chnl_destroy
, pfn_chnl_destroy
);
1112 STORE_FXN(fxn_chnl_open
, pfn_chnl_open
);
1113 STORE_FXN(fxn_chnl_close
, pfn_chnl_close
);
1114 STORE_FXN(fxn_chnl_addioreq
, pfn_chnl_add_io_req
);
1115 STORE_FXN(fxn_chnl_getioc
, pfn_chnl_get_ioc
);
1116 STORE_FXN(fxn_chnl_cancelio
, pfn_chnl_cancel_io
);
1117 STORE_FXN(fxn_chnl_flushio
, pfn_chnl_flush_io
);
1118 STORE_FXN(fxn_chnl_getinfo
, pfn_chnl_get_info
);
1119 STORE_FXN(fxn_chnl_getmgrinfo
, pfn_chnl_get_mgr_info
);
1120 STORE_FXN(fxn_chnl_idle
, pfn_chnl_idle
);
1121 STORE_FXN(fxn_chnl_registernotify
, pfn_chnl_register_notify
);
1122 STORE_FXN(fxn_io_create
, pfn_io_create
);
1123 STORE_FXN(fxn_io_destroy
, pfn_io_destroy
);
1124 STORE_FXN(fxn_io_onloaded
, pfn_io_on_loaded
);
1125 STORE_FXN(fxn_io_getprocload
, pfn_io_get_proc_load
);
1126 STORE_FXN(fxn_msg_create
, pfn_msg_create
);
1127 STORE_FXN(fxn_msg_createqueue
, pfn_msg_create_queue
);
1128 STORE_FXN(fxn_msg_delete
, pfn_msg_delete
);
1129 STORE_FXN(fxn_msg_deletequeue
, pfn_msg_delete_queue
);
1130 STORE_FXN(fxn_msg_get
, pfn_msg_get
);
1131 STORE_FXN(fxn_msg_put
, pfn_msg_put
);
1132 STORE_FXN(fxn_msg_registernotify
, pfn_msg_register_notify
);
1133 STORE_FXN(fxn_msg_setqueueid
, pfn_msg_set_queue_id
);
1135 /* Add code for any additional functions in newerBridge versions here */
1136 /* Ensure postcondition: */
1137 DBC_ENSURE(intf_fxns
->pfn_dev_create
!= NULL
);
1138 DBC_ENSURE(intf_fxns
->pfn_dev_destroy
!= NULL
);
1139 DBC_ENSURE(intf_fxns
->pfn_dev_cntrl
!= NULL
);
1140 DBC_ENSURE(intf_fxns
->pfn_brd_monitor
!= NULL
);
1141 DBC_ENSURE(intf_fxns
->pfn_brd_start
!= NULL
);
1142 DBC_ENSURE(intf_fxns
->pfn_brd_stop
!= NULL
);
1143 DBC_ENSURE(intf_fxns
->pfn_brd_status
!= NULL
);
1144 DBC_ENSURE(intf_fxns
->pfn_brd_read
!= NULL
);
1145 DBC_ENSURE(intf_fxns
->pfn_brd_write
!= NULL
);
1146 DBC_ENSURE(intf_fxns
->pfn_chnl_create
!= NULL
);
1147 DBC_ENSURE(intf_fxns
->pfn_chnl_destroy
!= NULL
);
1148 DBC_ENSURE(intf_fxns
->pfn_chnl_open
!= NULL
);
1149 DBC_ENSURE(intf_fxns
->pfn_chnl_close
!= NULL
);
1150 DBC_ENSURE(intf_fxns
->pfn_chnl_add_io_req
!= NULL
);
1151 DBC_ENSURE(intf_fxns
->pfn_chnl_get_ioc
!= NULL
);
1152 DBC_ENSURE(intf_fxns
->pfn_chnl_cancel_io
!= NULL
);
1153 DBC_ENSURE(intf_fxns
->pfn_chnl_flush_io
!= NULL
);
1154 DBC_ENSURE(intf_fxns
->pfn_chnl_get_info
!= NULL
);
1155 DBC_ENSURE(intf_fxns
->pfn_chnl_get_mgr_info
!= NULL
);
1156 DBC_ENSURE(intf_fxns
->pfn_chnl_idle
!= NULL
);
1157 DBC_ENSURE(intf_fxns
->pfn_chnl_register_notify
!= NULL
);
1158 DBC_ENSURE(intf_fxns
->pfn_io_create
!= NULL
);
1159 DBC_ENSURE(intf_fxns
->pfn_io_destroy
!= NULL
);
1160 DBC_ENSURE(intf_fxns
->pfn_io_on_loaded
!= NULL
);
1161 DBC_ENSURE(intf_fxns
->pfn_io_get_proc_load
!= NULL
);
1162 DBC_ENSURE(intf_fxns
->pfn_msg_set_queue_id
!= NULL
);