4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Implementation of Manager interface to the device object at the
7 * driver level. This queries the NDB data base and retrieves the
8 * data about Node and Processor.
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.
21 #include <linux/types.h>
23 /* ----------------------------------- Host OS */
24 #include <dspbridge/host_os.h>
26 /* ----------------------------------- DSP/BIOS Bridge */
27 #include <dspbridge/dbdefs.h>
29 /* ----------------------------------- Trace & Debug */
30 #include <dspbridge/dbc.h>
32 /* ----------------------------------- OS Adaptation Layer */
33 #include <dspbridge/sync.h>
35 /* ----------------------------------- Others */
36 #include <dspbridge/dbdcd.h>
37 #include <dspbridge/drv.h>
38 #include <dspbridge/dev.h>
40 /* ----------------------------------- This */
41 #include <dspbridge/mgr.h>
43 /* ----------------------------------- Defines, Data Structures, Typedefs */
47 struct dcd_manager
*dcd_mgr
; /* Proc/Node data manager */
50 /* ----------------------------------- Globals */
54 * ========= mgr_create =========
56 * MGR Object gets created only once during driver Loading.
58 int mgr_create(struct mgr_object
**mgr_obj
,
59 struct cfg_devnode
*dev_node_obj
)
62 struct mgr_object
*pmgr_obj
= NULL
;
63 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
65 DBC_REQUIRE(mgr_obj
!= NULL
);
66 DBC_REQUIRE(refs
> 0);
68 pmgr_obj
= kzalloc(sizeof(struct mgr_object
), GFP_KERNEL
);
70 status
= dcd_create_manager(ZLDLLNAME
, &pmgr_obj
->dcd_mgr
);
72 /* If succeeded store the handle in the MGR Object */
74 drv_datap
->mgr_object
= (void *)pmgr_obj
;
77 pr_err("%s: Failed to store MGR object\n",
84 dcd_destroy_manager(pmgr_obj
->dcd_mgr
);
88 /* failed to Create DCD Manager */
95 DBC_ENSURE(status
|| pmgr_obj
);
100 * ========= mgr_destroy =========
101 * This function is invoked during bridge driver unloading.Frees MGR object.
103 int mgr_destroy(struct mgr_object
*hmgr_obj
)
106 struct mgr_object
*pmgr_obj
= (struct mgr_object
*)hmgr_obj
;
107 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
109 DBC_REQUIRE(refs
> 0);
110 DBC_REQUIRE(hmgr_obj
);
113 if (hmgr_obj
->dcd_mgr
)
114 dcd_destroy_manager(hmgr_obj
->dcd_mgr
);
117 /* Update the driver data with NULL for MGR Object */
119 drv_datap
->mgr_object
= NULL
;
122 pr_err("%s: Failed to store MGR object\n", __func__
);
129 * ======== mgr_enum_node_info ========
130 * Enumerate and get configuration information about nodes configured
131 * in the node database.
133 int mgr_enum_node_info(u32 node_id
, struct dsp_ndbprops
*pndb_props
,
134 u32 undb_props_size
, u32
*pu_num_nodes
)
137 struct dsp_uuid node_uuid
;
139 struct dcd_genericobj gen_obj
;
140 struct mgr_object
*pmgr_obj
= NULL
;
141 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
143 DBC_REQUIRE(pndb_props
!= NULL
);
144 DBC_REQUIRE(pu_num_nodes
!= NULL
);
145 DBC_REQUIRE(undb_props_size
>= sizeof(struct dsp_ndbprops
));
146 DBC_REQUIRE(refs
> 0);
149 /* Get the Manager Object from the driver data */
150 if (!drv_datap
|| !drv_datap
->mgr_object
) {
151 pr_err("%s: Failed to retrieve the object handle\n", __func__
);
154 pmgr_obj
= drv_datap
->mgr_object
;
156 DBC_ASSERT(pmgr_obj
);
157 /* Forever loop till we hit failed or no more items in the
158 * Enumeration. We will exit the loop other than 0; */
160 status
= dcd_enumerate_object(node_index
++, DSP_DCDNODETYPE
,
164 *pu_num_nodes
= node_index
;
165 if (node_id
== (node_index
- 1)) {
166 status
= dcd_get_object_def(pmgr_obj
->dcd_mgr
,
167 &node_uuid
, DSP_DCDNODETYPE
, &gen_obj
);
170 /* Get the Obj def */
171 *pndb_props
= gen_obj
.obj_data
.node_obj
.ndb_props
;
175 /* the last status is not 0, but neither an error */
183 * ======== mgr_enum_processor_info ========
184 * Enumerate and get configuration information about available
187 int mgr_enum_processor_info(u32 processor_id
,
188 struct dsp_processorinfo
*
189 processor_info
, u32 processor_info_size
,
195 struct dsp_uuid temp_uuid
;
198 struct dcd_genericobj gen_obj
;
199 struct mgr_object
*pmgr_obj
= NULL
;
200 struct mgr_processorextinfo
*ext_info
;
201 struct dev_object
*hdev_obj
;
202 struct drv_object
*hdrv_obj
;
204 struct cfg_devnode
*dev_node
;
205 struct drv_data
*drv_datap
= dev_get_drvdata(bridge
);
206 bool proc_detect
= false;
208 DBC_REQUIRE(processor_info
!= NULL
);
209 DBC_REQUIRE(pu_num_procs
!= NULL
);
210 DBC_REQUIRE(processor_info_size
>= sizeof(struct dsp_processorinfo
));
211 DBC_REQUIRE(refs
> 0);
215 /* Retrieve the Object handle from the driver data */
216 if (!drv_datap
|| !drv_datap
->drv_object
) {
218 pr_err("%s: Failed to retrieve the object handle\n", __func__
);
220 hdrv_obj
= drv_datap
->drv_object
;
224 status
= drv_get_dev_object(processor_id
, hdrv_obj
, &hdev_obj
);
226 status
= dev_get_dev_type(hdev_obj
, (u8
*) &dev_type
);
227 status
= dev_get_dev_node(hdev_obj
, &dev_node
);
228 if (dev_type
!= DSP_UNIT
)
232 processor_info
->processor_type
= DSPTYPE64
;
238 /* Get The Manager Object from the driver data */
239 if (drv_datap
&& drv_datap
->mgr_object
) {
240 pmgr_obj
= drv_datap
->mgr_object
;
242 dev_dbg(bridge
, "%s: Failed to get MGR Object\n", __func__
);
245 DBC_ASSERT(pmgr_obj
);
246 /* Forever loop till we hit no more items in the
247 * Enumeration. We will exit the loop other than 0; */
248 while (status1
== 0) {
249 status1
= dcd_enumerate_object(temp_index
++,
250 DSP_DCDPROCESSORTYPE
,
256 /* Get the Object properties to find the Device/Processor
258 if (proc_detect
!= false)
261 status2
= dcd_get_object_def(pmgr_obj
->dcd_mgr
,
262 (struct dsp_uuid
*)&temp_uuid
,
263 DSP_DCDPROCESSORTYPE
, &gen_obj
);
265 /* Get the Obj def */
266 if (processor_info_size
<
267 sizeof(struct mgr_processorextinfo
)) {
268 *processor_info
= gen_obj
.obj_data
.proc_info
;
271 ext_info
= (struct mgr_processorextinfo
*)
273 *ext_info
= gen_obj
.obj_data
.ext_proc_obj
;
275 dev_dbg(bridge
, "%s: Got proctype from DCD %x\n",
276 __func__
, processor_info
->processor_type
);
277 /* See if we got the needed processor */
278 if (dev_type
== DSP_UNIT
) {
279 if (processor_info
->processor_type
==
282 } else if (dev_type
== IVA_UNIT
) {
283 if (processor_info
->processor_type
==
287 /* User applciatiuons aonly check for chip type, so
288 * this clumsy overwrite */
289 processor_info
->processor_type
= DSPTYPE64
;
291 dev_dbg(bridge
, "%s: Failed to get DCD processor info "
292 "%x\n", __func__
, status2
);
296 *pu_num_procs
= proc_index
;
297 if (proc_detect
== false) {
298 dev_dbg(bridge
, "%s: Failed to get proc info from DCD, so use "
299 "CFG registry\n", __func__
);
300 processor_info
->processor_type
= DSPTYPE64
;
307 * ======== mgr_exit ========
308 * Decrement reference count, and free resources when reference count is
313 DBC_REQUIRE(refs
> 0);
318 DBC_ENSURE(refs
>= 0);
322 * ======== mgr_get_dcd_handle ========
323 * Retrieves the MGR handle. Accessor Function.
325 int mgr_get_dcd_handle(struct mgr_object
*mgr_handle
,
329 struct mgr_object
*pmgr_obj
= (struct mgr_object
*)mgr_handle
;
331 DBC_REQUIRE(refs
> 0);
332 DBC_REQUIRE(dcd_handle
!= NULL
);
334 *dcd_handle
= (u32
) NULL
;
336 *dcd_handle
= (u32
) pmgr_obj
->dcd_mgr
;
339 DBC_ENSURE((!status
&& *dcd_handle
!= (u32
) NULL
) ||
340 (status
&& *dcd_handle
== (u32
) NULL
));
346 * ======== mgr_init ========
347 * Initialize MGR's private state, keeping a reference count on each call.
352 bool init_dcd
= false;
354 DBC_REQUIRE(refs
>= 0);
357 init_dcd
= dcd_init(); /* DCD Module */
366 DBC_ENSURE((ret
&& (refs
> 0)) || (!ret
&& (refs
>= 0)));
372 * ======== mgr_wait_for_bridge_events ========
373 * Block on any Bridge event(s)
375 int mgr_wait_for_bridge_events(struct dsp_notification
**anotifications
,
376 u32 count
, u32
*pu_index
,
380 struct sync_object
*sync_events
[MAX_EVENTS
];
383 DBC_REQUIRE(count
< MAX_EVENTS
);
385 for (i
= 0; i
< count
; i
++)
386 sync_events
[i
] = anotifications
[i
]->handle
;
388 status
= sync_wait_on_multiple_events(sync_events
, count
, utimeout
,