Kernel - Fixed freeze (I think)
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / main.c
1 /*
2  * Acess2 UDI Layer
3  */
4 #define DEBUG   0
5 #define VERSION ((0<<8)|1)
6 #include <acess.h>
7 #include <modules.h>
8 #include <udi.h>
9
10 // === PROTOTYPES ===
11  int    UDI_Install(char **Arguments);
12  int    UDI_DetectDriver(void *Base);
13  int    UDI_LoadDriver(void *Base);
14
15 // === GLOBALS ===
16 MODULE_DEFINE(0, VERSION, UDI, UDI_Install, NULL, NULL);
17 tModuleLoader   gUDI_Loader = {
18         NULL, "UDI", UDI_DetectDriver, UDI_LoadDriver, NULL
19 };
20
21 // === CODE ===
22 /**
23  * \fn int UDI_Install(char **Arguments)
24  * \brief Stub intialisation routine
25  */
26 int UDI_Install(char **Arguments)
27 {
28         Module_RegisterLoader( &gUDI_Loader );
29         return MODULE_ERR_OK;
30 }
31
32 /**
33  * \brief Detects if a driver should be loaded by the UDI subsystem
34  */
35 int UDI_DetectDriver(void *Base)
36 {
37         if( Binary_FindSymbol(Base, "udi_init_info", NULL) == 0) {
38                 return 0;
39         }
40         
41         return 1;
42 }
43
44 /**
45  * \fn int UDI_LoadDriver(void *Base)
46  */
47 int UDI_LoadDriver(void *Base)
48 {
49         udi_init_t      *info;
50         char    *udiprops = NULL;
51          int    udiprops_size = 0;
52          int    i;
53         // int  j;
54         
55         Log_Debug("UDI", "UDI_LoadDriver: (Base=%p)", Base);
56         
57         if( Binary_FindSymbol(Base, "udi_init_info", (Uint*)&info) == 0) {
58                 Binary_Unload(Base);
59                 return 0;
60         }
61         
62         if( Binary_FindSymbol(Base, "_udiprops", (Uint*)&udiprops) == 0 ) {
63                 Log_Warning("UDI", "_udiprops is not defined, this is usually bad");
64         }
65         else {
66                 Uint    udiprops_end = 0;
67                  int    i, j, nLines;
68                 char    **udipropsptrs;
69                 
70                 if( Binary_FindSymbol(Base, "_udiprops_end", (Uint*)&udiprops_end) == 0)
71                         Log_Warning("UDI", "_udiprops_end is not defined");
72                 Log_Debug("UDI", "udiprops_end = %p", udiprops_end);
73                 udiprops_size = udiprops_end - (Uint)udiprops;
74                 Log_Debug("UDI", "udiprops = %p, udiprops_size = 0x%x", udiprops, udiprops_size);
75                 
76                 Debug_HexDump("UDI_LoadDriver", udiprops, udiprops_size);
77                 
78                 nLines = 1;
79                 for( i = 0; i < udiprops_size; i++ )
80                 {
81                         if( udiprops[i] == '\0' )
82                                 nLines ++;
83                 }
84                 
85                 Log_Debug("UDI", "nLines = %i", nLines);
86                 
87                 udipropsptrs = malloc( sizeof(char*)*nLines );
88                 udipropsptrs[0] = udiprops;
89                 j = 0;
90                 for( i = 0; i < udiprops_size; i++ )
91                 {
92                         if( udiprops[i] == '\0' ) {
93                                 //Log_Debug("UDI", "udipropsptrs[%i] = '%s'", j, udipropsptrs[j]);
94                                 udipropsptrs[j++] = &udiprops[i+1];
95                         }
96                 }
97                 Log_Debug("UDI", "udipropsptrs[%i] = '%s'", j, udipropsptrs[j]);
98                 Log_Debug("UDI", "udiprops = \"%s\"", udiprops);
99         }
100         
101         
102         Log("primary_init_info = %p = {", info->primary_init_info);
103         {
104                 Log(" .mgmt_ops = %p = {", info->primary_init_info->mgmt_ops);
105                 Log("  .usage_ind_op: %p() - 0x%02x",
106                         info->primary_init_info->mgmt_ops->usage_ind_op,
107                         info->primary_init_info->mgmt_op_flags[0]
108                         );
109                 Log("  .enumerate_req_op: %p() - 0x%02x",
110                         info->primary_init_info->mgmt_ops->enumerate_req_op,
111                         info->primary_init_info->mgmt_op_flags[1]
112                         );
113                 Log("  .devmgmt_req_op: %p() - 0x%02x",
114                         info->primary_init_info->mgmt_ops->devmgmt_req_op,
115                         info->primary_init_info->mgmt_op_flags[2]
116                         );
117                 Log("  .final_cleanup_req_op: %p() - 0x%02x",
118                         info->primary_init_info->mgmt_ops->final_cleanup_req_op,
119                         info->primary_init_info->mgmt_op_flags[3]
120                         );
121                 Log(" }");
122                 Log(" .mgmt_scratch_requirement = 0x%x", info->primary_init_info->mgmt_scratch_requirement);
123                 Log(" .enumeration_attr_list_length = 0x%x", info->primary_init_info->enumeration_attr_list_length);
124                 Log(" .rdata_size = 0x%x", info->primary_init_info->rdata_size);
125                 Log(" .child_data_size = 0x%x", info->primary_init_info->child_data_size);
126                 Log(" .per_parent_paths = 0x%x", info->primary_init_info->per_parent_paths);
127         }
128         Log("}");
129         Log("secondary_init_list = %p", info->secondary_init_list);
130         Log("ops_init_list = %p", info->ops_init_list);
131         
132         for( i = 0; info->ops_init_list[i].ops_idx; i++ )
133         {
134                 Log("info->ops_init_list[%i] = {", i);
135                 Log(" .ops_idx = 0x%x", info->ops_init_list[i].ops_idx);
136                 Log(" .meta_idx = 0x%x", info->ops_init_list[i].meta_idx);
137                 Log(" .meta_ops_num = 0x%x", info->ops_init_list[i].meta_ops_num);
138                 Log(" .chan_context_size = 0x%x", info->ops_init_list[i].chan_context_size);
139                 Log(" .ops_vector = %p", info->ops_init_list[i].ops_vector);
140 //              Log(" .op_flags = %p", info->ops_init_list[i].op_flags);
141                 Log("}");
142         }
143         
144         return 0;
145 }

UCC git Repository :: git.ucc.asn.au