4 * Created on: Oct 12, 2008
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
)
31 of_node_t
*node
, *root
= NULL
;
33 D(bug("[OF] OpenKey('%s')\n", Key
));
37 D(bug("[OF] Key must have absolute path\n"));
41 root
= LIBBASE
->of_Root
;
46 for (i
=0; i
< 63; i
++)
48 if (*Key
== '/' || *Key
== 0)
56 D(bug("[OF] looking for child '%s'\n", ptrbuf
));
58 ForeachNode(&root
->on_children
, node
)
60 if (!strcmp(node
->on_name
, ptrbuf
))
74 AROS_LH1I(void, OF_CloseKey
,
75 AROS_LHA(void *, Key
, A0
),
76 struct OpenFirmwareBase
*, OpenFirmwareBase
, 2, Openfirmware
)
83 AROS_LH2I(void *, OF_GetChild
,
84 AROS_LHA(void *, Key
, A0
),
85 AROS_LHA(void *, Prev
, A1
),
86 struct OpenFirmwareBase
*, OpenFirmwareBase
, 3, Openfirmware
)
90 of_node_t
*node
= (of_node_t
*)Key
;
91 of_node_t
*last
= (of_node_t
*)Prev
;
96 return GetHead(&node
->on_children
);
101 AROS_LH2I(void *, OF_FindProperty
,
102 AROS_LHA(void *, Key
, A0
),
103 AROS_LHA(char *, name
, A1
),
104 struct OpenFirmwareBase
*, OpenFirmwareBase
, 4, Openfirmware
)
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
))
125 AROS_LH2I(void *, OF_GetProperty
,
126 AROS_LHA(void *, Key
, A0
),
127 AROS_LHA(void *, Prev
, A1
),
128 struct OpenFirmwareBase
*, OpenFirmwareBase
, 5, Openfirmware
)
132 of_node_t
*node
= (of_node_t
*)Key
;
133 of_property_t
*last
= (of_property_t
*)Prev
;
136 return GetSucc(last
);
138 return GetHead(&node
->on_properties
);
143 AROS_LH1I(uint32_t, OF_GetPropLen
,
144 AROS_LHA(void *, Key
, A0
),
145 struct OpenFirmwareBase
*, OpenFirmwareBase
, 6, Openfirmware
)
149 of_property_t
*prop
= (of_property_t
*)Key
;
152 return prop
->op_length
;
159 AROS_LH1I(char *, OF_GetPropName
,
160 AROS_LHA(void *, Key
, A0
),
161 struct OpenFirmwareBase
*, OpenFirmwareBase
, 8, Openfirmware
)
165 of_property_t
*prop
= (of_property_t
*)Key
;
168 return prop
->op_name
;
175 AROS_LH1I(void *, OF_GetPropValue
,
176 AROS_LHA(void *, Key
, A0
),
177 struct OpenFirmwareBase
*, OpenFirmwareBase
, 7, Openfirmware
)
181 of_property_t
*prop
= (of_property_t
*)Key
;
184 return prop
->op_value
;
192 static int OF_Init(LIBBASETYPEPTR LIBBASE
)
194 void *KernelBase
= OpenResource("kernel.resource");
196 D(bug("[OF] OpenFirmware_Init\n"));
200 struct TagItem
*tags
= KrnGetBootInfo();
205 D(bug("[OF] BootInto @ %08x\n", tags
));
207 oftree
= GetTagData(KRN_OpenFirmwareTree
, 0, tags
);
211 D(bug("[OF] OpenFirmware root at %08x\n", oftree
));
212 LIBBASE
->of_Root
= (of_node_t
*)oftree
;
216 D(else bug("[OF] No OpenFirmware tree passed from bootloader\n"));
218 D(else bug("[OF] No BootInfo found\n"));
224 ADD2INITLIB(OF_Init
, 0)