2 Copyright � 2008-2014, The AROS Development Team. All rights reserved.
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
)
36 AROS_LH1(void *, OF_OpenKey
,
37 AROS_LHA(char *, Key
, A0
),
38 struct OpenFirmwareBase
*, OpenFirmwareBase
, 1, Openfirmware
)
44 of_node_t
*node
, *root
= NULL
;
46 D(bug("[OF] OpenKey('%s')\n", Key
));
50 D(bug("[OF] Key must have absolute path\n"));
54 root
= LIBBASE
->of_Root
;
59 for (i
=0; i
< 63; i
++)
61 if (*Key
== '/' || *Key
== 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
))
87 AROS_LH1I(void, OF_CloseKey
,
88 AROS_LHA(void *, Key
, A0
),
89 struct OpenFirmwareBase
*, OpenFirmwareBase
, 2, Openfirmware
)
96 AROS_LH2I(void *, OF_GetChild
,
97 AROS_LHA(void *, Key
, A0
),
98 AROS_LHA(void *, Prev
, A1
),
99 struct OpenFirmwareBase
*, OpenFirmwareBase
, 3, Openfirmware
)
103 of_node_t
*node
= (of_node_t
*)Key
;
104 of_node_t
*last
= (of_node_t
*)Prev
;
107 return GetSucc(last
);
109 return GetHead(&node
->on_children
);
114 AROS_LH2I(void *, OF_FindProperty
,
115 AROS_LHA(void *, Key
, A0
),
116 AROS_LHA(char *, name
, A1
),
117 struct OpenFirmwareBase
*, OpenFirmwareBase
, 4, Openfirmware
)
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
))
138 AROS_LH2I(void *, OF_GetProperty
,
139 AROS_LHA(void *, Key
, A0
),
140 AROS_LHA(void *, Prev
, A1
),
141 struct OpenFirmwareBase
*, OpenFirmwareBase
, 5, Openfirmware
)
145 of_node_t
*node
= (of_node_t
*)Key
;
146 of_property_t
*last
= (of_property_t
*)Prev
;
149 return GetSucc(last
);
151 return GetHead(&node
->on_properties
);
156 AROS_LH1I(uint32_t, OF_GetPropLen
,
157 AROS_LHA(void *, Key
, A0
),
158 struct OpenFirmwareBase
*, OpenFirmwareBase
, 6, Openfirmware
)
162 of_property_t
*prop
= (of_property_t
*)Key
;
165 return prop
->op_length
;
172 AROS_LH1I(char *, OF_GetPropName
,
173 AROS_LHA(void *, Key
, A0
),
174 struct OpenFirmwareBase
*, OpenFirmwareBase
, 8, Openfirmware
)
178 of_property_t
*prop
= (of_property_t
*)Key
;
181 return prop
->op_name
;
188 AROS_LH1I(void *, OF_GetPropValue
,
189 AROS_LHA(void *, Key
, A0
),
190 struct OpenFirmwareBase
*, OpenFirmwareBase
, 7, Openfirmware
)
194 of_property_t
*prop
= (of_property_t
*)Key
;
197 return prop
->op_value
;
205 static int OF_Init(LIBBASETYPEPTR LIBBASE
)
207 void *KernelBase
= OpenResource("kernel.resource");
209 D(bug("[OF] OpenFirmware_Init\n"));
213 struct TagItem
*tags
= KrnGetBootInfo();
218 D(bug("[OF] BootInto @ %08x\n", tags
));
220 oftree
= GetTagData(KRN_OpenFirmwareTree
, 0, tags
);
224 D(bug("[OF] OpenFirmware root at %08x\n", oftree
));
225 LIBBASE
->of_Root
= (of_node_t
*)oftree
;
229 D(else bug("[OF] No OpenFirmware tree passed from bootloader\n"));
231 D(else bug("[OF] No BootInfo found\n"));
237 ADD2INITLIB(OF_Init
, 0)