adopt previous changes. (NicJA)
[AROS.git] / rom / openfirmware / of_init.c
bloba678f85492e1052d2d1165035047a77761b50ab5
1 /*
2 Copyright � 2008-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
8 #include <inttypes.h>
9 #include <aros/kernel.h>
10 #include <aros/symbolsets.h>
11 #include <aros/debug.h>
12 #include <exec/nodes.h>
13 #include <exec/lists.h>
14 #include <utility/tagitem.h>
15 #include <proto/kernel.h>
16 #include <proto/utility.h>
18 #include "of_intern.h"
19 #include LC_LIBDEFS_FILE
21 int my_strcmp(const char *s1, const char *s2)
23 if (s1 && s2)
25 while (*s1 && *s2) {
26 if (*s1 != *s2)
27 break;
28 s1++;
29 s2++;
31 return *s1 - *s2;
33 else return -1;
36 AROS_LH1(void *, OF_OpenKey,
37 AROS_LHA(char *, Key, A0),
38 struct OpenFirmwareBase *, OpenFirmwareBase, 1, Openfirmware)
40 AROS_LIBFUNC_INIT
42 char ptrbuf[64];
43 int i;
44 of_node_t *node, *root = NULL;
46 D(bug("[OF] OpenKey('%s')\n", Key));
48 if (*Key != '/')
50 D(bug("[OF] Key must have absolute path\n"));
52 else
54 root = LIBBASE->of_Root;
56 while(*Key)
58 Key++;
59 for (i=0; i < 63; i++)
61 if (*Key == '/' || *Key == 0)
62 break;
63 ptrbuf[i] = *Key;
64 Key++;
67 ptrbuf[i] = 0;
69 D(bug("[OF] looking for child '%s'\n", ptrbuf));
71 ForeachNode(&root->on_children, node)
73 if (!my_strcmp(node->on_name, ptrbuf))
75 root = node;
76 break;
82 return root;
84 AROS_LIBFUNC_EXIT
87 AROS_LH1I(void, OF_CloseKey,
88 AROS_LHA(void *, Key, A0),
89 struct OpenFirmwareBase *, OpenFirmwareBase, 2, Openfirmware)
91 AROS_LIBFUNC_INIT
93 AROS_LIBFUNC_EXIT
96 AROS_LH2I(void *, OF_GetChild,
97 AROS_LHA(void *, Key, A0),
98 AROS_LHA(void *, Prev, A1),
99 struct OpenFirmwareBase *, OpenFirmwareBase, 3, Openfirmware)
101 AROS_LIBFUNC_INIT
103 of_node_t *node = (of_node_t *)Key;
104 of_node_t *last = (of_node_t *)Prev;
106 if (last)
107 return GetSucc(last);
108 else
109 return GetHead(&node->on_children);
111 AROS_LIBFUNC_EXIT
114 AROS_LH2I(void *, OF_FindProperty,
115 AROS_LHA(void *, Key, A0),
116 AROS_LHA(char *, name, A1),
117 struct OpenFirmwareBase *, OpenFirmwareBase, 4, Openfirmware)
119 AROS_LIBFUNC_INIT
121 of_node_t *node = (of_node_t *)Key;
122 of_property_t *p, *prop = NULL;
124 ForeachNode(&node->on_properties, p)
126 if (!my_strcmp(p->op_name, name))
128 prop = p;
129 break;
133 return prop;
135 AROS_LIBFUNC_EXIT
138 AROS_LH2I(void *, OF_GetProperty,
139 AROS_LHA(void *, Key, A0),
140 AROS_LHA(void *, Prev, A1),
141 struct OpenFirmwareBase *, OpenFirmwareBase, 5, Openfirmware)
143 AROS_LIBFUNC_INIT
145 of_node_t *node = (of_node_t *)Key;
146 of_property_t *last = (of_property_t *)Prev;
148 if (last)
149 return GetSucc(last);
150 else
151 return GetHead(&node->on_properties);
153 AROS_LIBFUNC_EXIT
156 AROS_LH1I(uint32_t, OF_GetPropLen,
157 AROS_LHA(void *, Key, A0),
158 struct OpenFirmwareBase *, OpenFirmwareBase, 6, Openfirmware)
160 AROS_LIBFUNC_INIT
162 of_property_t *prop = (of_property_t *)Key;
164 if (prop)
165 return prop->op_length;
166 else
167 return 0;
169 AROS_LIBFUNC_EXIT
172 AROS_LH1I(char *, OF_GetPropName,
173 AROS_LHA(void *, Key, A0),
174 struct OpenFirmwareBase *, OpenFirmwareBase, 8, Openfirmware)
176 AROS_LIBFUNC_INIT
178 of_property_t *prop = (of_property_t *)Key;
180 if (prop)
181 return prop->op_name;
182 else
183 return "(null)";
185 AROS_LIBFUNC_EXIT
188 AROS_LH1I(void *, OF_GetPropValue,
189 AROS_LHA(void *, Key, A0),
190 struct OpenFirmwareBase *, OpenFirmwareBase, 7, Openfirmware)
192 AROS_LIBFUNC_INIT
194 of_property_t *prop = (of_property_t *)Key;
196 if (prop)
197 return prop->op_value;
198 else
199 return NULL;
201 AROS_LIBFUNC_EXIT
205 static int OF_Init(LIBBASETYPEPTR LIBBASE)
207 void *KernelBase = OpenResource("kernel.resource");
209 D(bug("[OF] OpenFirmware_Init\n"));
211 if (KernelBase)
213 struct TagItem *tags = KrnGetBootInfo();
215 if (tags)
217 intptr_t oftree;
218 D(bug("[OF] BootInto @ %08x\n", tags));
220 oftree = GetTagData(KRN_OpenFirmwareTree, 0, tags);
222 if (oftree)
224 D(bug("[OF] OpenFirmware root at %08x\n", oftree));
225 LIBBASE->of_Root = (of_node_t *)oftree;
227 return TRUE;
229 D(else bug("[OF] No OpenFirmware tree passed from bootloader\n"));
231 D(else bug("[OF] No BootInfo found\n"));
234 return FALSE;
237 ADD2INITLIB(OF_Init, 0)