4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * This file contains the implementation of the DSP/BIOS Bridge
7 * Configuration Database (DCD).
10 * The fxn dcd_get_objects can apply a callback fxn to each DCD object
11 * that is located in a specified COFF file. At the moment,
12 * dcd_auto_register, dcd_auto_unregister, and NLDR module all use
15 * Copyright (C) 2005-2006 Texas Instruments, Inc.
17 * This package is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
21 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
23 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #include <linux/types.h>
27 /* ----------------------------------- Host OS */
28 #include <dspbridge/host_os.h>
30 /* ----------------------------------- DSP/BIOS Bridge */
31 #include <dspbridge/dbdefs.h>
33 /* ----------------------------------- Platform Manager */
34 #include <dspbridge/cod.h>
36 /* ----------------------------------- Others */
37 #include <dspbridge/uuidutil.h>
39 /* ----------------------------------- This */
40 #include <dspbridge/dbdcd.h>
42 /* ----------------------------------- Global defines. */
43 #define MAX_INT2CHAR_LENGTH 16 /* Max int2char len of 32 bit int */
45 /* Name of section containing dependent libraries */
46 #define DEPLIBSECT ".dspbridge_deplibs"
48 /* DCD specific structures. */
50 struct cod_manager
*cod_mgr
; /* Handle to COD manager object. */
53 /* Pointer to the registry support key */
54 static struct list_head reg_key_list
;
55 static DEFINE_SPINLOCK(dbdcd_lock
);
57 /* Global reference variables. */
61 /* Helper function prototypes. */
62 static s32
atoi(char *psz_buf
);
63 static int get_attrs_from_buf(char *psz_buf
, u32 ul_buf_size
,
64 enum dsp_dcdobjtype obj_type
,
65 struct dcd_genericobj
*gen_obj
);
66 static void compress_buf(char *psz_buf
, u32 ul_buf_size
, s32 char_size
);
67 static char dsp_char2_gpp_char(char *word
, s32 dsp_char_size
);
68 static int get_dep_lib_info(struct dcd_manager
*hdcd_mgr
,
69 struct dsp_uuid
*uuid_obj
,
72 struct dsp_uuid
*dep_lib_uuids
,
73 bool *prstnt_dep_libs
,
74 enum nldr_phase phase
);
77 * ======== dcd_auto_register ========
79 * Parses the supplied image and resigsters with DCD.
81 int dcd_auto_register(struct dcd_manager
*hdcd_mgr
,
87 status
= dcd_get_objects(hdcd_mgr
, sz_coff_path
,
88 (dcd_registerfxn
) dcd_register_object
,
89 (void *)sz_coff_path
);
97 * ======== dcd_auto_unregister ========
99 * Parses the supplied DSP image and unresiters from DCD.
101 int dcd_auto_unregister(struct dcd_manager
*hdcd_mgr
,
107 status
= dcd_get_objects(hdcd_mgr
, sz_coff_path
,
108 (dcd_registerfxn
) dcd_register_object
,
117 * ======== dcd_create_manager ========
119 * Creates DCD manager.
121 int dcd_create_manager(char *sz_zl_dll_name
,
122 struct dcd_manager
**dcd_mgr
)
124 struct cod_manager
*cod_mgr
; /* COD manager handle */
125 struct dcd_manager
*dcd_mgr_obj
= NULL
; /* DCD Manager pointer */
128 status
= cod_create(&cod_mgr
, sz_zl_dll_name
);
132 /* Create a DCD object. */
133 dcd_mgr_obj
= kzalloc(sizeof(struct dcd_manager
), GFP_KERNEL
);
134 if (dcd_mgr_obj
!= NULL
) {
135 /* Fill out the object. */
136 dcd_mgr_obj
->cod_mgr
= cod_mgr
;
138 /* Return handle to this DCD interface. */
139 *dcd_mgr
= dcd_mgr_obj
;
144 * If allocation of DcdManager object failed, delete the
155 * ======== dcd_destroy_manager ========
157 * Frees DCD Manager object.
159 int dcd_destroy_manager(struct dcd_manager
*hdcd_mgr
)
161 struct dcd_manager
*dcd_mgr_obj
= hdcd_mgr
;
162 int status
= -EFAULT
;
165 /* Delete the COD manager. */
166 cod_delete(dcd_mgr_obj
->cod_mgr
);
168 /* Deallocate a DCD manager object. */
178 * ======== dcd_enumerate_object ========
180 * Enumerates objects in the DCD.
182 int dcd_enumerate_object(s32 index
, enum dsp_dcdobjtype obj_type
,
183 struct dsp_uuid
*uuid_obj
)
186 char sz_reg_key
[DCD_MAXPATHLENGTH
];
187 char sz_value
[DCD_MAXPATHLENGTH
];
188 struct dsp_uuid dsp_uuid_obj
;
189 char sz_obj_type
[MAX_INT2CHAR_LENGTH
]; /* str. rep. of obj_type. */
191 struct dcd_key_elem
*dcd_key
;
194 if ((index
!= 0) && (enum_refs
== 0)) {
196 * If an enumeration is being performed on an index greater
197 * than zero, then the current enum_refs must have been
198 * incremented to greater than zero.
203 * Pre-determine final key length. It's length of DCD_REGKEY +
204 * "_\0" + length of sz_obj_type string + terminating NULL.
206 dw_key_len
= strlen(DCD_REGKEY
) + 1 + sizeof(sz_obj_type
) + 1;
208 /* Create proper REG key; concatenate DCD_REGKEY with
210 strncpy(sz_reg_key
, DCD_REGKEY
, strlen(DCD_REGKEY
) + 1);
211 if ((strlen(sz_reg_key
) + strlen("_\0")) <
213 strncat(sz_reg_key
, "_\0", 2);
218 /* This snprintf is guaranteed not to exceed max size of an
220 status
= snprintf(sz_obj_type
, MAX_INT2CHAR_LENGTH
, "%d",
227 if ((strlen(sz_reg_key
) + strlen(sz_obj_type
)) <
229 strncat(sz_reg_key
, sz_obj_type
,
230 strlen(sz_obj_type
) + 1);
237 len
= strlen(sz_reg_key
);
238 spin_lock(&dbdcd_lock
);
239 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
240 if (!strncmp(dcd_key
->name
, sz_reg_key
, len
)
242 strncpy(sz_value
, &dcd_key
->name
[len
],
243 strlen(&dcd_key
->name
[len
]) + 1);
247 spin_unlock(&dbdcd_lock
);
249 if (&dcd_key
->link
== ®_key_list
)
254 /* Create UUID value using string retrieved from
256 uuid_uuid_from_string(sz_value
, &dsp_uuid_obj
);
258 *uuid_obj
= dsp_uuid_obj
;
260 /* Increment enum_refs to update reference count. */
264 } else if (status
== -ENODATA
) {
265 /* At the end of enumeration. Reset enum_refs. */
269 * TODO: Revisit, this is not an error case but code
270 * expects non-zero value.
282 * ======== dcd_exit ========
284 * Discontinue usage of the DCD module.
288 struct dcd_key_elem
*rv
, *rv_tmp
;
292 list_for_each_entry_safe(rv
, rv_tmp
, ®_key_list
, link
) {
302 * ======== dcd_get_dep_libs ========
304 int dcd_get_dep_libs(struct dcd_manager
*hdcd_mgr
,
305 struct dsp_uuid
*uuid_obj
,
306 u16 num_libs
, struct dsp_uuid
*dep_lib_uuids
,
307 bool *prstnt_dep_libs
,
308 enum nldr_phase phase
)
313 get_dep_lib_info(hdcd_mgr
, uuid_obj
, &num_libs
, NULL
, dep_lib_uuids
,
314 prstnt_dep_libs
, phase
);
320 * ======== dcd_get_num_dep_libs ========
322 int dcd_get_num_dep_libs(struct dcd_manager
*hdcd_mgr
,
323 struct dsp_uuid
*uuid_obj
,
324 u16
*num_libs
, u16
*num_pers_libs
,
325 enum nldr_phase phase
)
329 status
= get_dep_lib_info(hdcd_mgr
, uuid_obj
, num_libs
, num_pers_libs
,
336 * ======== dcd_get_object_def ========
338 * Retrieves the properties of a node or processor based on the UUID and
341 int dcd_get_object_def(struct dcd_manager
*hdcd_mgr
,
342 struct dsp_uuid
*obj_uuid
,
343 enum dsp_dcdobjtype obj_type
,
344 struct dcd_genericobj
*obj_def
)
346 struct dcd_manager
*dcd_mgr_obj
= hdcd_mgr
; /* ptr to DCD mgr */
347 struct cod_libraryobj
*lib
= NULL
;
349 u32 ul_addr
= 0; /* Used by cod_get_section */
350 u32 ul_len
= 0; /* Used by cod_get_section */
351 u32 dw_buf_size
; /* Used by REG functions */
352 char sz_reg_key
[DCD_MAXPATHLENGTH
];
353 char *sz_uuid
; /*[MAXUUIDLEN]; */
354 struct dcd_key_elem
*dcd_key
= NULL
;
355 char sz_sect_name
[MAXUUIDLEN
+ 2]; /* ".[UUID]\0" */
357 u32 dw_key_len
; /* Len of REG key. */
358 char sz_obj_type
[MAX_INT2CHAR_LENGTH
]; /* str. rep. of obj_type. */
360 sz_uuid
= kzalloc(MAXUUIDLEN
, GFP_KERNEL
);
371 /* Pre-determine final key length. It's length of DCD_REGKEY +
372 * "_\0" + length of sz_obj_type string + terminating NULL */
373 dw_key_len
= strlen(DCD_REGKEY
) + 1 + sizeof(sz_obj_type
) + 1;
375 /* Create proper REG key; concatenate DCD_REGKEY with obj_type. */
376 strncpy(sz_reg_key
, DCD_REGKEY
, strlen(DCD_REGKEY
) + 1);
378 if ((strlen(sz_reg_key
) + strlen("_\0")) < DCD_MAXPATHLENGTH
)
379 strncat(sz_reg_key
, "_\0", 2);
383 status
= snprintf(sz_obj_type
, MAX_INT2CHAR_LENGTH
, "%d", obj_type
);
389 if ((strlen(sz_reg_key
) + strlen(sz_obj_type
)) <
391 strncat(sz_reg_key
, sz_obj_type
,
392 strlen(sz_obj_type
) + 1);
397 /* Create UUID value to set in registry. */
398 uuid_uuid_to_string(obj_uuid
, sz_uuid
, MAXUUIDLEN
);
400 if ((strlen(sz_reg_key
) + MAXUUIDLEN
) < DCD_MAXPATHLENGTH
)
401 strncat(sz_reg_key
, sz_uuid
, MAXUUIDLEN
);
405 /* Retrieve paths from the registry based on struct dsp_uuid */
406 dw_buf_size
= DCD_MAXPATHLENGTH
;
409 spin_lock(&dbdcd_lock
);
410 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
411 if (!strncmp(dcd_key
->name
, sz_reg_key
,
412 strlen(sz_reg_key
) + 1))
415 spin_unlock(&dbdcd_lock
);
416 if (&dcd_key
->link
== ®_key_list
) {
423 /* Open COFF file. */
424 status
= cod_open(dcd_mgr_obj
->cod_mgr
, dcd_key
->path
,
431 /* Ensure sz_uuid + 1 is not greater than sizeof sz_sect_name. */
433 /* Create section name based on node UUID. A period is
434 * pre-pended to the UUID string to form the section name.
435 * I.e. ".24BC8D90_BB45_11d4_B756_006008BDB66F" */
436 strncpy(sz_sect_name
, ".", 2);
437 strncat(sz_sect_name
, sz_uuid
, strlen(sz_uuid
));
439 /* Get section information. */
440 status
= cod_get_section(lib
, sz_sect_name
, &ul_addr
, &ul_len
);
446 /* Allocate zeroed buffer. */
447 psz_coff_buf
= kzalloc(ul_len
+ 4, GFP_KERNEL
);
448 if (psz_coff_buf
== NULL
) {
453 if (strstr(dcd_key
->path
, "iva") == NULL
) {
454 /* Locate section by objectID and read its content. */
456 cod_read_section(lib
, sz_sect_name
, psz_coff_buf
, ul_len
);
459 cod_read_section(lib
, sz_sect_name
, psz_coff_buf
, ul_len
);
460 dev_dbg(bridge
, "%s: Skipped Byte swap for IVA!!\n", __func__
);
463 status
= cod_read_section(lib
, sz_sect_name
, psz_coff_buf
, ul_len
);
466 /* Compres DSP buffer to conform to PC format. */
467 if (strstr(dcd_key
->path
, "iva") == NULL
) {
468 compress_buf(psz_coff_buf
, ul_len
, DSPWORDSIZE
);
470 compress_buf(psz_coff_buf
, ul_len
, 1);
471 dev_dbg(bridge
, "%s: Compressing IVA COFF buffer by 1 "
472 "for IVA!!\n", __func__
);
475 /* Parse the content of the COFF buffer. */
477 get_attrs_from_buf(psz_coff_buf
, ul_len
, obj_type
, obj_def
);
484 /* Free the previously allocated dynamic buffer. */
496 * ======== dcd_get_objects ========
498 int dcd_get_objects(struct dcd_manager
*hdcd_mgr
,
499 char *sz_coff_path
, dcd_registerfxn register_fxn
,
502 struct dcd_manager
*dcd_mgr_obj
= hdcd_mgr
;
506 struct cod_libraryobj
*lib
= NULL
;
507 u32 ul_addr
= 0; /* Used by cod_get_section */
508 u32 ul_len
= 0; /* Used by cod_get_section */
511 struct dsp_uuid dsp_uuid_obj
;
519 /* Open DSP coff file, don't load symbols. */
520 status
= cod_open(dcd_mgr_obj
->cod_mgr
, sz_coff_path
, COD_NOLOAD
, &lib
);
526 /* Get DCD_RESIGER_SECTION section information. */
527 status
= cod_get_section(lib
, DCD_REGISTER_SECTION
, &ul_addr
, &ul_len
);
528 if (status
|| !(ul_len
> 0)) {
533 /* Allocate zeroed buffer. */
534 psz_coff_buf
= kzalloc(ul_len
+ 4, GFP_KERNEL
);
535 if (psz_coff_buf
== NULL
) {
540 if (strstr(sz_coff_path
, "iva") == NULL
) {
541 /* Locate section by objectID and read its content. */
542 status
= cod_read_section(lib
, DCD_REGISTER_SECTION
,
543 psz_coff_buf
, ul_len
);
545 dev_dbg(bridge
, "%s: Skipped Byte swap for IVA!!\n", __func__
);
546 status
= cod_read_section(lib
, DCD_REGISTER_SECTION
,
547 psz_coff_buf
, ul_len
);
551 cod_read_section(lib
, DCD_REGISTER_SECTION
, psz_coff_buf
, ul_len
);
554 /* Compress DSP buffer to conform to PC format. */
555 if (strstr(sz_coff_path
, "iva") == NULL
) {
556 compress_buf(psz_coff_buf
, ul_len
, DSPWORDSIZE
);
558 compress_buf(psz_coff_buf
, ul_len
, 1);
559 dev_dbg(bridge
, "%s: Compress COFF buffer with 1 word "
560 "for IVA!!\n", __func__
);
563 /* Read from buffer and register object in buffer. */
564 psz_cur
= psz_coff_buf
;
565 while ((token
= strsep(&psz_cur
, seps
)) && *token
!= '\0') {
566 /* Retrieve UUID string. */
567 uuid_uuid_from_string(token
, &dsp_uuid_obj
);
569 /* Retrieve object type */
570 token
= strsep(&psz_cur
, seps
);
572 /* Retrieve object type */
573 object_type
= atoi(token
);
576 * Apply register_fxn to the found DCD object.
577 * Possible actions include:
579 * 1) Register found DCD object.
580 * 2) Unregister found DCD object (when handle == NULL)
581 * 3) Add overlay node.
584 register_fxn(&dsp_uuid_obj
, object_type
, handle
);
586 /* if error occurs, break from while loop. */
594 /* Free the previously allocated dynamic buffer. */
605 * ======== dcd_get_library_name ========
607 * Retrieves the library name for the given UUID.
610 int dcd_get_library_name(struct dcd_manager
*hdcd_mgr
,
611 struct dsp_uuid
*uuid_obj
,
614 enum nldr_phase phase
, bool *phase_split
)
616 char sz_reg_key
[DCD_MAXPATHLENGTH
];
617 char sz_uuid
[MAXUUIDLEN
];
618 u32 dw_key_len
; /* Len of REG key. */
619 char sz_obj_type
[MAX_INT2CHAR_LENGTH
]; /* str. rep. of obj_type. */
621 struct dcd_key_elem
*dcd_key
= NULL
;
623 dev_dbg(bridge
, "%s: hdcd_mgr %p, uuid_obj %p, str_lib_name %p,"
624 " buff_size %p\n", __func__
, hdcd_mgr
, uuid_obj
, str_lib_name
,
628 * Pre-determine final key length. It's length of DCD_REGKEY +
629 * "_\0" + length of sz_obj_type string + terminating NULL.
631 dw_key_len
= strlen(DCD_REGKEY
) + 1 + sizeof(sz_obj_type
) + 1;
633 /* Create proper REG key; concatenate DCD_REGKEY with obj_type. */
634 strncpy(sz_reg_key
, DCD_REGKEY
, strlen(DCD_REGKEY
) + 1);
635 if ((strlen(sz_reg_key
) + strlen("_\0")) < DCD_MAXPATHLENGTH
)
636 strncat(sz_reg_key
, "_\0", 2);
642 /* create phase type */
643 sprintf(sz_obj_type
, "%d", DSP_DCDCREATELIBTYPE
);
646 /* execute phase type */
647 sprintf(sz_obj_type
, "%d", DSP_DCDEXECUTELIBTYPE
);
650 /* delete phase type */
651 sprintf(sz_obj_type
, "%d", DSP_DCDDELETELIBTYPE
);
654 /* known to be a dependent library */
655 sprintf(sz_obj_type
, "%d", DSP_DCDLIBRARYTYPE
);
661 if ((strlen(sz_reg_key
) + strlen(sz_obj_type
)) <
663 strncat(sz_reg_key
, sz_obj_type
,
664 strlen(sz_obj_type
) + 1);
668 /* Create UUID value to find match in registry. */
669 uuid_uuid_to_string(uuid_obj
, sz_uuid
, MAXUUIDLEN
);
670 if ((strlen(sz_reg_key
) + MAXUUIDLEN
) < DCD_MAXPATHLENGTH
)
671 strncat(sz_reg_key
, sz_uuid
, MAXUUIDLEN
);
676 spin_lock(&dbdcd_lock
);
677 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
678 /* See if the name matches. */
679 if (!strncmp(dcd_key
->name
, sz_reg_key
,
680 strlen(sz_reg_key
) + 1))
683 spin_unlock(&dbdcd_lock
);
686 if (&dcd_key
->link
== ®_key_list
)
689 /* If can't find, phases might be registered as generic LIBRARYTYPE */
690 if (status
&& phase
!= NLDR_NOPHASE
) {
692 *phase_split
= false;
694 strncpy(sz_reg_key
, DCD_REGKEY
, strlen(DCD_REGKEY
) + 1);
695 if ((strlen(sz_reg_key
) + strlen("_\0")) <
697 strncat(sz_reg_key
, "_\0", 2);
701 sprintf(sz_obj_type
, "%d", DSP_DCDLIBRARYTYPE
);
702 if ((strlen(sz_reg_key
) + strlen(sz_obj_type
))
703 < DCD_MAXPATHLENGTH
) {
704 strncat(sz_reg_key
, sz_obj_type
,
705 strlen(sz_obj_type
) + 1);
709 uuid_uuid_to_string(uuid_obj
, sz_uuid
, MAXUUIDLEN
);
710 if ((strlen(sz_reg_key
) + MAXUUIDLEN
) < DCD_MAXPATHLENGTH
)
711 strncat(sz_reg_key
, sz_uuid
, MAXUUIDLEN
);
715 spin_lock(&dbdcd_lock
);
716 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
717 /* See if the name matches. */
718 if (!strncmp(dcd_key
->name
, sz_reg_key
,
719 strlen(sz_reg_key
) + 1))
722 spin_unlock(&dbdcd_lock
);
724 status
= (&dcd_key
->link
!= ®_key_list
) ?
729 memcpy(str_lib_name
, dcd_key
->path
, strlen(dcd_key
->path
) + 1);
734 * ======== dcd_init ========
736 * Initialize the DCD module.
743 INIT_LIST_HEAD(®_key_list
);
752 * ======== dcd_register_object ========
754 * Registers a node or a processor with the DCD.
755 * If psz_path_name == NULL, unregister the specified DCD object.
757 int dcd_register_object(struct dsp_uuid
*uuid_obj
,
758 enum dsp_dcdobjtype obj_type
,
762 char sz_reg_key
[DCD_MAXPATHLENGTH
];
763 char sz_uuid
[MAXUUIDLEN
+ 1];
764 u32 dw_path_size
= 0;
765 u32 dw_key_len
; /* Len of REG key. */
766 char sz_obj_type
[MAX_INT2CHAR_LENGTH
]; /* str. rep. of obj_type. */
767 struct dcd_key_elem
*dcd_key
= NULL
;
769 dev_dbg(bridge
, "%s: object UUID %p, obj_type %d, szPathName %s\n",
770 __func__
, uuid_obj
, obj_type
, psz_path_name
);
773 * Pre-determine final key length. It's length of DCD_REGKEY +
774 * "_\0" + length of sz_obj_type string + terminating NULL.
776 dw_key_len
= strlen(DCD_REGKEY
) + 1 + sizeof(sz_obj_type
) + 1;
778 /* Create proper REG key; concatenate DCD_REGKEY with obj_type. */
779 strncpy(sz_reg_key
, DCD_REGKEY
, strlen(DCD_REGKEY
) + 1);
780 if ((strlen(sz_reg_key
) + strlen("_\0")) < DCD_MAXPATHLENGTH
)
781 strncat(sz_reg_key
, "_\0", 2);
787 status
= snprintf(sz_obj_type
, MAX_INT2CHAR_LENGTH
, "%d", obj_type
);
792 if ((strlen(sz_reg_key
) + strlen(sz_obj_type
)) <
794 strncat(sz_reg_key
, sz_obj_type
,
795 strlen(sz_obj_type
) + 1);
799 /* Create UUID value to set in registry. */
800 uuid_uuid_to_string(uuid_obj
, sz_uuid
, MAXUUIDLEN
);
801 if ((strlen(sz_reg_key
) + MAXUUIDLEN
) < DCD_MAXPATHLENGTH
)
802 strncat(sz_reg_key
, sz_uuid
, MAXUUIDLEN
);
811 * If psz_path_name != NULL, perform registration, otherwise,
812 * perform unregistration.
816 dw_path_size
= strlen(psz_path_name
) + 1;
817 spin_lock(&dbdcd_lock
);
818 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
819 /* See if the name matches. */
820 if (!strncmp(dcd_key
->name
, sz_reg_key
,
821 strlen(sz_reg_key
) + 1))
824 spin_unlock(&dbdcd_lock
);
825 if (&dcd_key
->link
== ®_key_list
) {
827 * Add new reg value (UUID+obj_type)
828 * with COFF path info
831 dcd_key
= kmalloc(sizeof(struct dcd_key_elem
),
838 dcd_key
->path
= kmalloc(strlen(sz_reg_key
) + 1,
841 if (!dcd_key
->path
) {
847 strncpy(dcd_key
->name
, sz_reg_key
,
848 strlen(sz_reg_key
) + 1);
849 strncpy(dcd_key
->path
, psz_path_name
,
851 spin_lock(&dbdcd_lock
);
852 list_add_tail(&dcd_key
->link
, ®_key_list
);
853 spin_unlock(&dbdcd_lock
);
855 /* Make sure the new data is the same. */
856 if (strncmp(dcd_key
->path
, psz_path_name
,
858 /* The caller needs a different data size! */
859 kfree(dcd_key
->path
);
860 dcd_key
->path
= kmalloc(dw_path_size
,
862 if (dcd_key
->path
== NULL
) {
868 /* We have a match! Copy out the data. */
869 memcpy(dcd_key
->path
, psz_path_name
, dw_path_size
);
871 dev_dbg(bridge
, "%s: psz_path_name=%s, dw_path_size=%d\n",
872 __func__
, psz_path_name
, dw_path_size
);
874 /* Deregister an existing object */
875 spin_lock(&dbdcd_lock
);
876 list_for_each_entry(dcd_key
, ®_key_list
, link
) {
877 if (!strncmp(dcd_key
->name
, sz_reg_key
,
878 strlen(sz_reg_key
) + 1)) {
879 list_del(&dcd_key
->link
);
880 kfree(dcd_key
->path
);
885 spin_unlock(&dbdcd_lock
);
886 if (&dcd_key
->link
== ®_key_list
)
892 * Because the node database has been updated through a
893 * successful object registration/de-registration operation,
894 * we need to reset the object enumeration counter to allow
895 * current enumerations to reflect this update in the node
905 * ======== dcd_unregister_object ========
906 * Call DCD_Register object with psz_path_name set to NULL to
907 * perform actual object de-registration.
909 int dcd_unregister_object(struct dsp_uuid
*uuid_obj
,
910 enum dsp_dcdobjtype obj_type
)
915 * When dcd_register_object is called with NULL as pathname,
916 * it indicates an unregister object operation.
918 status
= dcd_register_object(uuid_obj
, obj_type
, NULL
);
924 **********************************************************************
925 * DCD Helper Functions
926 **********************************************************************
930 * ======== atoi ========
932 * This function converts strings in decimal or hex format to integers.
934 static s32
atoi(char *psz_buf
)
939 while (isspace(*pch
))
942 if (*pch
== '-' || *pch
== '+') {
945 } else if (*pch
&& tolower(pch
[strlen(pch
) - 1]) == 'h') {
949 return simple_strtoul(pch
, NULL
, base
);
953 * ======== get_attrs_from_buf ========
955 * Parse the content of a buffer filled with DSP-side data and
956 * retrieve an object's attributes from it. IMPORTANT: Assume the
957 * buffer has been converted from DSP format to GPP format.
959 static int get_attrs_from_buf(char *psz_buf
, u32 ul_buf_size
,
960 enum dsp_dcdobjtype obj_type
,
961 struct dcd_genericobj
*gen_obj
)
974 case DSP_DCDNODETYPE
:
976 * Parse COFF sect buffer to retrieve individual tokens used
977 * to fill in object attrs.
980 token
= strsep(&psz_cur
, seps
);
983 gen_obj
->obj_data
.node_obj
.ndb_props
.cb_struct
=
985 token
= strsep(&psz_cur
, seps
);
987 /* dsp_uuid ui_node_id */
988 uuid_uuid_from_string(token
,
989 &gen_obj
->obj_data
.node_obj
.ndb_props
.
991 token
= strsep(&psz_cur
, seps
);
994 token_len
= strlen(token
);
995 if (token_len
> DSP_MAXNAMELEN
- 1)
996 token_len
= DSP_MAXNAMELEN
- 1;
998 strncpy(gen_obj
->obj_data
.node_obj
.ndb_props
.ac_name
,
1000 gen_obj
->obj_data
.node_obj
.ndb_props
.ac_name
[token_len
] = '\0';
1001 token
= strsep(&psz_cur
, seps
);
1003 gen_obj
->obj_data
.node_obj
.ndb_props
.ntype
= atoi(token
);
1004 token
= strsep(&psz_cur
, seps
);
1005 /* u32 cache_on_gpp */
1006 gen_obj
->obj_data
.node_obj
.ndb_props
.cache_on_gpp
= atoi(token
);
1007 token
= strsep(&psz_cur
, seps
);
1008 /* dsp_resourcereqmts dsp_resource_reqmts */
1009 gen_obj
->obj_data
.node_obj
.ndb_props
.dsp_resource_reqmts
.
1010 cb_struct
= (u32
) atoi(token
);
1011 token
= strsep(&psz_cur
, seps
);
1013 gen_obj
->obj_data
.node_obj
.ndb_props
.
1014 dsp_resource_reqmts
.static_data_size
= atoi(token
);
1015 token
= strsep(&psz_cur
, seps
);
1016 gen_obj
->obj_data
.node_obj
.ndb_props
.
1017 dsp_resource_reqmts
.global_data_size
= atoi(token
);
1018 token
= strsep(&psz_cur
, seps
);
1019 gen_obj
->obj_data
.node_obj
.ndb_props
.
1020 dsp_resource_reqmts
.program_mem_size
= atoi(token
);
1021 token
= strsep(&psz_cur
, seps
);
1022 gen_obj
->obj_data
.node_obj
.ndb_props
.
1023 dsp_resource_reqmts
.wc_execution_time
= atoi(token
);
1024 token
= strsep(&psz_cur
, seps
);
1025 gen_obj
->obj_data
.node_obj
.ndb_props
.
1026 dsp_resource_reqmts
.wc_period
= atoi(token
);
1027 token
= strsep(&psz_cur
, seps
);
1029 gen_obj
->obj_data
.node_obj
.ndb_props
.
1030 dsp_resource_reqmts
.wc_deadline
= atoi(token
);
1031 token
= strsep(&psz_cur
, seps
);
1033 gen_obj
->obj_data
.node_obj
.ndb_props
.
1034 dsp_resource_reqmts
.avg_exection_time
= atoi(token
);
1035 token
= strsep(&psz_cur
, seps
);
1037 gen_obj
->obj_data
.node_obj
.ndb_props
.
1038 dsp_resource_reqmts
.minimum_period
= atoi(token
);
1039 token
= strsep(&psz_cur
, seps
);
1042 gen_obj
->obj_data
.node_obj
.ndb_props
.prio
= atoi(token
);
1043 token
= strsep(&psz_cur
, seps
);
1045 /* u32 stack_size */
1046 gen_obj
->obj_data
.node_obj
.ndb_props
.stack_size
= atoi(token
);
1047 token
= strsep(&psz_cur
, seps
);
1049 /* u32 sys_stack_size */
1050 gen_obj
->obj_data
.node_obj
.ndb_props
.sys_stack_size
=
1052 token
= strsep(&psz_cur
, seps
);
1055 gen_obj
->obj_data
.node_obj
.ndb_props
.stack_seg
= atoi(token
);
1056 token
= strsep(&psz_cur
, seps
);
1058 /* u32 message_depth */
1059 gen_obj
->obj_data
.node_obj
.ndb_props
.message_depth
=
1061 token
= strsep(&psz_cur
, seps
);
1063 /* u32 num_input_streams */
1064 gen_obj
->obj_data
.node_obj
.ndb_props
.num_input_streams
=
1066 token
= strsep(&psz_cur
, seps
);
1068 /* u32 num_output_streams */
1069 gen_obj
->obj_data
.node_obj
.ndb_props
.num_output_streams
=
1071 token
= strsep(&psz_cur
, seps
);
1074 gen_obj
->obj_data
.node_obj
.ndb_props
.timeout
= atoi(token
);
1075 token
= strsep(&psz_cur
, seps
);
1077 /* char *str_create_phase_fxn */
1078 token_len
= strlen(token
);
1079 gen_obj
->obj_data
.node_obj
.str_create_phase_fxn
=
1080 kzalloc(token_len
+ 1, GFP_KERNEL
);
1081 strncpy(gen_obj
->obj_data
.node_obj
.str_create_phase_fxn
,
1083 gen_obj
->obj_data
.node_obj
.str_create_phase_fxn
[token_len
] =
1085 token
= strsep(&psz_cur
, seps
);
1087 /* char *str_execute_phase_fxn */
1088 token_len
= strlen(token
);
1089 gen_obj
->obj_data
.node_obj
.str_execute_phase_fxn
=
1090 kzalloc(token_len
+ 1, GFP_KERNEL
);
1091 strncpy(gen_obj
->obj_data
.node_obj
.str_execute_phase_fxn
,
1093 gen_obj
->obj_data
.node_obj
.str_execute_phase_fxn
[token_len
] =
1095 token
= strsep(&psz_cur
, seps
);
1097 /* char *str_delete_phase_fxn */
1098 token_len
= strlen(token
);
1099 gen_obj
->obj_data
.node_obj
.str_delete_phase_fxn
=
1100 kzalloc(token_len
+ 1, GFP_KERNEL
);
1101 strncpy(gen_obj
->obj_data
.node_obj
.str_delete_phase_fxn
,
1103 gen_obj
->obj_data
.node_obj
.str_delete_phase_fxn
[token_len
] =
1105 token
= strsep(&psz_cur
, seps
);
1107 /* Segment id for message buffers */
1108 gen_obj
->obj_data
.node_obj
.msg_segid
= atoi(token
);
1109 token
= strsep(&psz_cur
, seps
);
1111 /* Message notification type */
1112 gen_obj
->obj_data
.node_obj
.msg_notify_type
= atoi(token
);
1113 token
= strsep(&psz_cur
, seps
);
1115 /* char *str_i_alg_name */
1117 token_len
= strlen(token
);
1118 gen_obj
->obj_data
.node_obj
.str_i_alg_name
=
1119 kzalloc(token_len
+ 1, GFP_KERNEL
);
1120 strncpy(gen_obj
->obj_data
.node_obj
.str_i_alg_name
,
1122 gen_obj
->obj_data
.node_obj
.str_i_alg_name
[token_len
] =
1124 token
= strsep(&psz_cur
, seps
);
1127 /* Load type (static, dynamic, or overlay) */
1129 gen_obj
->obj_data
.node_obj
.load_type
= atoi(token
);
1130 token
= strsep(&psz_cur
, seps
);
1133 /* Dynamic load data requirements */
1135 gen_obj
->obj_data
.node_obj
.data_mem_seg_mask
=
1137 token
= strsep(&psz_cur
, seps
);
1140 /* Dynamic load code requirements */
1142 gen_obj
->obj_data
.node_obj
.code_mem_seg_mask
=
1144 token
= strsep(&psz_cur
, seps
);
1147 /* Extract node profiles into node properties */
1150 gen_obj
->obj_data
.node_obj
.ndb_props
.count_profiles
=
1154 gen_obj
->obj_data
.node_obj
.
1155 ndb_props
.count_profiles
; i
++) {
1156 token
= strsep(&psz_cur
, seps
);
1158 /* Heap Size for the node */
1159 gen_obj
->obj_data
.node_obj
.
1160 ndb_props
.node_profiles
[i
].
1161 heap_size
= atoi(token
);
1165 token
= strsep(&psz_cur
, seps
);
1167 gen_obj
->obj_data
.node_obj
.ndb_props
.stack_seg_name
=
1173 case DSP_DCDPROCESSORTYPE
:
1175 * Parse COFF sect buffer to retrieve individual tokens used
1176 * to fill in object attrs.
1179 token
= strsep(&psz_cur
, seps
);
1181 gen_obj
->obj_data
.proc_info
.cb_struct
= atoi(token
);
1182 token
= strsep(&psz_cur
, seps
);
1184 gen_obj
->obj_data
.proc_info
.processor_family
= atoi(token
);
1185 token
= strsep(&psz_cur
, seps
);
1187 gen_obj
->obj_data
.proc_info
.processor_type
= atoi(token
);
1188 token
= strsep(&psz_cur
, seps
);
1190 gen_obj
->obj_data
.proc_info
.clock_rate
= atoi(token
);
1191 token
= strsep(&psz_cur
, seps
);
1193 gen_obj
->obj_data
.proc_info
.internal_mem_size
= atoi(token
);
1194 token
= strsep(&psz_cur
, seps
);
1196 gen_obj
->obj_data
.proc_info
.external_mem_size
= atoi(token
);
1197 token
= strsep(&psz_cur
, seps
);
1199 gen_obj
->obj_data
.proc_info
.processor_id
= atoi(token
);
1200 token
= strsep(&psz_cur
, seps
);
1202 gen_obj
->obj_data
.proc_info
.ty_running_rtos
= atoi(token
);
1203 token
= strsep(&psz_cur
, seps
);
1205 gen_obj
->obj_data
.proc_info
.node_min_priority
= atoi(token
);
1206 token
= strsep(&psz_cur
, seps
);
1208 gen_obj
->obj_data
.proc_info
.node_max_priority
= atoi(token
);
1211 /* Proc object may contain additional(extended) attributes. */
1212 /* attr must match proc.hxx */
1213 for (entry_id
= 0; entry_id
< 7; entry_id
++) {
1214 token
= strsep(&psz_cur
, seps
);
1215 gen_obj
->obj_data
.ext_proc_obj
.ty_tlb
[entry_id
].
1216 gpp_phys
= atoi(token
);
1218 token
= strsep(&psz_cur
, seps
);
1219 gen_obj
->obj_data
.ext_proc_obj
.ty_tlb
[entry_id
].
1220 dsp_virt
= atoi(token
);
1235 * ======== CompressBuffer ========
1237 * Compress the DSP buffer, if necessary, to conform to PC format.
1239 static void compress_buf(char *psz_buf
, u32 ul_buf_size
, s32 char_size
)
1249 for (q
= psz_buf
; q
< (psz_buf
+ ul_buf_size
);) {
1250 ch
= dsp_char2_gpp_char(q
, char_size
);
1253 ch
= dsp_char2_gpp_char(q
, char_size
);
1282 /* NULL out remainder of buffer. */
1288 * ======== dsp_char2_gpp_char ========
1290 * Convert DSP char to host GPP char in a portable manner
1292 static char dsp_char2_gpp_char(char *word
, s32 dsp_char_size
)
1298 for (ch_src
= word
, i
= dsp_char_size
; i
> 0; i
--)
1305 * ======== get_dep_lib_info ========
1307 static int get_dep_lib_info(struct dcd_manager
*hdcd_mgr
,
1308 struct dsp_uuid
*uuid_obj
,
1311 struct dsp_uuid
*dep_lib_uuids
,
1312 bool *prstnt_dep_libs
,
1313 enum nldr_phase phase
)
1315 struct dcd_manager
*dcd_mgr_obj
= hdcd_mgr
;
1316 char *psz_coff_buf
= NULL
;
1318 char *psz_file_name
= NULL
;
1319 struct cod_libraryobj
*lib
= NULL
;
1320 u32 ul_addr
= 0; /* Used by cod_get_section */
1321 u32 ul_len
= 0; /* Used by cod_get_section */
1322 u32 dw_data_size
= COD_MAXPATHLENGTH
;
1325 bool get_uuids
= (dep_lib_uuids
!= NULL
);
1329 /* Initialize to 0 dependent libraries, if only counting number of
1330 * dependent libraries */
1336 /* Allocate a buffer for file name */
1337 psz_file_name
= kzalloc(dw_data_size
, GFP_KERNEL
);
1338 if (psz_file_name
== NULL
) {
1341 /* Get the name of the library */
1342 status
= dcd_get_library_name(hdcd_mgr
, uuid_obj
, psz_file_name
,
1343 &dw_data_size
, phase
, NULL
);
1346 /* Open the library */
1348 status
= cod_open(dcd_mgr_obj
->cod_mgr
, psz_file_name
,
1352 /* Get dependent library section information. */
1353 status
= cod_get_section(lib
, DEPLIBSECT
, &ul_addr
, &ul_len
);
1356 /* Ok, no dependent libraries */
1362 if (status
|| !(ul_len
> 0))
1365 /* Allocate zeroed buffer. */
1366 psz_coff_buf
= kzalloc(ul_len
+ 4, GFP_KERNEL
);
1367 if (psz_coff_buf
== NULL
)
1370 /* Read section contents. */
1371 status
= cod_read_section(lib
, DEPLIBSECT
, psz_coff_buf
, ul_len
);
1375 /* Compress and format DSP buffer to conform to PC format. */
1376 compress_buf(psz_coff_buf
, ul_len
, DSPWORDSIZE
);
1378 /* Read from buffer */
1379 psz_cur
= psz_coff_buf
;
1380 while ((token
= strsep(&psz_cur
, seps
)) && *token
!= '\0') {
1382 if (dep_libs
>= *num_libs
) {
1383 /* Gone beyond the limit */
1386 /* Retrieve UUID string. */
1387 uuid_uuid_from_string(token
,
1390 /* Is this library persistent? */
1391 token
= strsep(&psz_cur
, seps
);
1392 prstnt_dep_libs
[dep_libs
] = atoi(token
);
1396 /* Advanc to next token */
1397 token
= strsep(&psz_cur
, seps
);
1401 /* Just counting number of dependent libraries */
1409 /* Free previously allocated dynamic buffers. */
1410 kfree(psz_file_name
);
1412 kfree(psz_coff_buf
);