- HD_SCSICMD: assume there is no sense-data buffer if no AUTOSENSE
[AROS.git] / rom / openfirmware / of_init.c
bloba113fb15d5eaf9470e13fb1a6f039cb2e2777d3b
1 /*
2 * of_init.c
4 * Created on: Oct 12, 2008
5 * Author: misc
6 */
8 #define DEBUG 1
10 #include <inttypes.h>
11 #include <aros/kernel.h>
12 #include <aros/symbolsets.h>
13 #include <aros/debug.h>
14 #include <exec/nodes.h>
15 #include <exec/lists.h>
16 #include <utility/tagitem.h>
17 #include <proto/kernel.h>
18 #include <proto/utility.h>
20 #include "of_intern.h"
21 #include LC_LIBDEFS_FILE
23 AROS_LH1(void *, OF_OpenKey,
24 AROS_LHA(char *, Key, A0),
25 struct OpenFirmwareBase *, OpenFirmwareBase, 1, Openfirmware)
27 AROS_LIBFUNC_INIT
29 char ptrbuf[64];
30 int i;
31 of_node_t *node, *root = NULL;
33 D(bug("[OF] OpenKey('%s')\n", Key));
35 if (*Key != '/')
37 D(bug("[OF] Key must have absolute path\n"));
39 else
41 root = LIBBASE->of_Root;
43 while(*Key)
45 Key++;
46 for (i=0; i < 63; i++)
48 if (*Key == '/' || *Key == 0)
49 break;
50 ptrbuf[i] = *Key;
51 Key++;
54 ptrbuf[i] = 0;
56 D(bug("[OF] looking for child '%s'\n", ptrbuf));
58 ForeachNode(&root->on_children, node)
60 if (!strcmp(node->on_name, ptrbuf))
62 root = node;
63 break;
69 return root;
71 AROS_LIBFUNC_EXIT
74 AROS_LH1I(void, OF_CloseKey,
75 AROS_LHA(void *, Key, A0),
76 struct OpenFirmwareBase *, OpenFirmwareBase, 2, Openfirmware)
78 AROS_LIBFUNC_INIT
80 AROS_LIBFUNC_EXIT
83 AROS_LH2I(void *, OF_GetChild,
84 AROS_LHA(void *, Key, A0),
85 AROS_LHA(void *, Prev, A1),
86 struct OpenFirmwareBase *, OpenFirmwareBase, 3, Openfirmware)
88 AROS_LIBFUNC_INIT
90 of_node_t *node = (of_node_t *)Key;
91 of_node_t *last = (of_node_t *)Prev;
93 if (last)
94 return GetSucc(last);
95 else
96 return GetHead(&node->on_children);
98 AROS_LIBFUNC_EXIT
101 AROS_LH2I(void *, OF_FindProperty,
102 AROS_LHA(void *, Key, A0),
103 AROS_LHA(char *, name, A1),
104 struct OpenFirmwareBase *, OpenFirmwareBase, 4, Openfirmware)
106 AROS_LIBFUNC_INIT
108 of_node_t *node = (of_node_t *)Key;
109 of_property_t *p, *prop = NULL;
111 ForeachNode(&node->on_properties, p)
113 if (!strcmp(p->op_name, name))
115 prop = p;
116 break;
120 return prop;
122 AROS_LIBFUNC_EXIT
125 AROS_LH2I(void *, OF_GetProperty,
126 AROS_LHA(void *, Key, A0),
127 AROS_LHA(void *, Prev, A1),
128 struct OpenFirmwareBase *, OpenFirmwareBase, 5, Openfirmware)
130 AROS_LIBFUNC_INIT
132 of_node_t *node = (of_node_t *)Key;
133 of_property_t *last = (of_property_t *)Prev;
135 if (last)
136 return GetSucc(last);
137 else
138 return GetHead(&node->on_properties);
140 AROS_LIBFUNC_EXIT
143 AROS_LH1I(uint32_t, OF_GetPropLen,
144 AROS_LHA(void *, Key, A0),
145 struct OpenFirmwareBase *, OpenFirmwareBase, 6, Openfirmware)
147 AROS_LIBFUNC_INIT
149 of_property_t *prop = (of_property_t *)Key;
151 if (prop)
152 return prop->op_length;
153 else
154 return 0;
156 AROS_LIBFUNC_EXIT
159 AROS_LH1I(char *, OF_GetPropName,
160 AROS_LHA(void *, Key, A0),
161 struct OpenFirmwareBase *, OpenFirmwareBase, 8, Openfirmware)
163 AROS_LIBFUNC_INIT
165 of_property_t *prop = (of_property_t *)Key;
167 if (prop)
168 return prop->op_name;
169 else
170 return "(null)";
172 AROS_LIBFUNC_EXIT
175 AROS_LH1I(void *, OF_GetPropValue,
176 AROS_LHA(void *, Key, A0),
177 struct OpenFirmwareBase *, OpenFirmwareBase, 7, Openfirmware)
179 AROS_LIBFUNC_INIT
181 of_property_t *prop = (of_property_t *)Key;
183 if (prop)
184 return prop->op_value;
185 else
186 return NULL;
188 AROS_LIBFUNC_EXIT
192 static int OF_Init(LIBBASETYPEPTR LIBBASE)
194 void *KernelBase = OpenResource("kernel.resource");
196 D(bug("[OF] OpenFirmware_Init\n"));
198 if (KernelBase)
200 struct TagItem *tags = KrnGetBootInfo();
202 if (tags)
204 intptr_t oftree;
205 D(bug("[OF] BootInto @ %08x\n", tags));
207 oftree = GetTagData(KRN_OpenFirmwareTree, 0, tags);
209 if (oftree)
211 D(bug("[OF] OpenFirmware root at %08x\n", oftree));
212 LIBBASE->of_Root = (of_node_t *)oftree;
214 return TRUE;
216 D(else bug("[OF] No OpenFirmware tree passed from bootloader\n"));
218 D(else bug("[OF] No BootInfo found\n"));
221 return FALSE;
224 ADD2INITLIB(OF_Init, 0)