2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "pci_openfirmware.h"
11 #include <KernelExport.h>
13 #include <platform/openfirmware/devices.h>
14 #include <platform/openfirmware/openfirmware.h>
15 #include <platform/openfirmware/pci.h>
17 #include "pci_openfirmware_priv.h"
20 typedef status_t (*probeFunction
)(int, const StringArrayPropertyValue
&);
22 static const probeFunction sProbeFunctions
[] = {
23 ppc_openfirmware_probe_uninorth
,
24 ppc_openfirmware_probe_grackle
,
30 ppc_openfirmware_pci_controller_init(void)
34 while (of_get_next_device(&cookie
, 0, "pci", path
, sizeof(path
))
36 dprintf("ppc_openfirmware_pci_controller_init(): pci device node: %s\n", path
);
37 // get the device node and the "compatible" property
38 int deviceNode
= of_finddevice(path
);
39 StringArrayPropertyValue compatible
;
40 status_t error
= openfirmware_get_property(deviceNode
, "compatible",
43 dprintf("ppc_openfirmware_pci_controller_init: Failed to get "
44 "\"compatible\" property for pci device: %s\n", path
);
49 for (int i
= 0; sProbeFunctions
[i
]; i
++) {
50 error
= sProbeFunctions
[i
](deviceNode
, compatible
);
60 // #pragma mark - support functions
64 StringArrayPropertyValue::NextElement(int &cookie
) const
69 char *result
= value
+ cookie
;
70 cookie
+= strnlen(result
, length
- cookie
) + 1;
76 StringArrayPropertyValue::ContainsElement(const char *value
) const
79 while (char *checkValue
= NextElement(cookie
)) {
80 if (strcmp(checkValue
, value
) == 0)
89 openfirmware_get_property(int package
, const char *propertyName
,
92 value
.length
= of_getproplen(package
, propertyName
);
94 return B_ENTRY_NOT_FOUND
;
96 value
.value
= (char*)malloc(value
.length
);
100 if (of_getprop(package
, propertyName
, value
.value
, value
.length
)