Fix detection path (Info tool)
[AROS.git] / rom / openfirmware / of_init.c
blob12a92039cedde85ca4426f665d1aa9772cee4704
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 AROS_LH1(void *, OF_OpenKey,
22 AROS_LHA(char *, Key, A0),
23 struct OpenFirmwareBase *, OpenFirmwareBase, 1, Openfirmware)
25 AROS_LIBFUNC_INIT
27 char ptrbuf[64];
28 int i;
29 of_node_t *node, *root = NULL;
31 D(bug("[OF] OpenKey('%s')\n", Key));
33 if (*Key != '/')
35 D(bug("[OF] Key must have absolute path\n"));
37 else
39 root = LIBBASE->of_Root;
41 while(*Key)
43 Key++;
44 for (i=0; i < 63; i++)
46 if (*Key == '/' || *Key == 0)
47 break;
48 ptrbuf[i] = *Key;
49 Key++;
52 ptrbuf[i] = 0;
54 D(bug("[OF] looking for child '%s'\n", ptrbuf));
56 ForeachNode(&root->on_children, node)
58 if (!strcmp(node->on_name, ptrbuf))
60 root = node;
61 break;
67 return root;
69 AROS_LIBFUNC_EXIT
72 AROS_LH1I(void, OF_CloseKey,
73 AROS_LHA(void *, Key, A0),
74 struct OpenFirmwareBase *, OpenFirmwareBase, 2, Openfirmware)
76 AROS_LIBFUNC_INIT
78 AROS_LIBFUNC_EXIT
81 AROS_LH2I(void *, OF_GetChild,
82 AROS_LHA(void *, Key, A0),
83 AROS_LHA(void *, Prev, A1),
84 struct OpenFirmwareBase *, OpenFirmwareBase, 3, Openfirmware)
86 AROS_LIBFUNC_INIT
88 of_node_t *node = (of_node_t *)Key;
89 of_node_t *last = (of_node_t *)Prev;
91 if (last)
92 return GetSucc(last);
93 else
94 return GetHead(&node->on_children);
96 AROS_LIBFUNC_EXIT
99 AROS_LH2I(void *, OF_FindProperty,
100 AROS_LHA(void *, Key, A0),
101 AROS_LHA(char *, name, A1),
102 struct OpenFirmwareBase *, OpenFirmwareBase, 4, Openfirmware)
104 AROS_LIBFUNC_INIT
106 of_node_t *node = (of_node_t *)Key;
107 of_property_t *p, *prop = NULL;
109 ForeachNode(&node->on_properties, p)
111 if (!strcmp(p->op_name, name))
113 prop = p;
114 break;
118 return prop;
120 AROS_LIBFUNC_EXIT
123 AROS_LH2I(void *, OF_GetProperty,
124 AROS_LHA(void *, Key, A0),
125 AROS_LHA(void *, Prev, A1),
126 struct OpenFirmwareBase *, OpenFirmwareBase, 5, Openfirmware)
128 AROS_LIBFUNC_INIT
130 of_node_t *node = (of_node_t *)Key;
131 of_property_t *last = (of_property_t *)Prev;
133 if (last)
134 return GetSucc(last);
135 else
136 return GetHead(&node->on_properties);
138 AROS_LIBFUNC_EXIT
141 AROS_LH1I(uint32_t, OF_GetPropLen,
142 AROS_LHA(void *, Key, A0),
143 struct OpenFirmwareBase *, OpenFirmwareBase, 6, Openfirmware)
145 AROS_LIBFUNC_INIT
147 of_property_t *prop = (of_property_t *)Key;
149 if (prop)
150 return prop->op_length;
151 else
152 return 0;
154 AROS_LIBFUNC_EXIT
157 AROS_LH1I(char *, OF_GetPropName,
158 AROS_LHA(void *, Key, A0),
159 struct OpenFirmwareBase *, OpenFirmwareBase, 8, Openfirmware)
161 AROS_LIBFUNC_INIT
163 of_property_t *prop = (of_property_t *)Key;
165 if (prop)
166 return prop->op_name;
167 else
168 return "(null)";
170 AROS_LIBFUNC_EXIT
173 AROS_LH1I(void *, OF_GetPropValue,
174 AROS_LHA(void *, Key, A0),
175 struct OpenFirmwareBase *, OpenFirmwareBase, 7, Openfirmware)
177 AROS_LIBFUNC_INIT
179 of_property_t *prop = (of_property_t *)Key;
181 if (prop)
182 return prop->op_value;
183 else
184 return NULL;
186 AROS_LIBFUNC_EXIT
190 static int OF_Init(LIBBASETYPEPTR LIBBASE)
192 void *KernelBase = OpenResource("kernel.resource");
194 D(bug("[OF] OpenFirmware_Init\n"));
196 if (KernelBase)
198 struct TagItem *tags = KrnGetBootInfo();
200 if (tags)
202 intptr_t oftree;
203 D(bug("[OF] BootInto @ %08x\n", tags));
205 oftree = GetTagData(KRN_OpenFirmwareTree, 0, tags);
207 if (oftree)
209 D(bug("[OF] OpenFirmware root at %08x\n", oftree));
210 LIBBASE->of_Root = (of_node_t *)oftree;
212 return TRUE;
214 D(else bug("[OF] No OpenFirmware tree passed from bootloader\n"));
216 D(else bug("[OF] No BootInfo found\n"));
219 return FALSE;
222 ADD2INITLIB(OF_Init, 0)