BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / bus_managers / pci / arch / ppc / openfirmware / pci_openfirmware.cpp
blobaae13305323424cd1ddc941ac126daa8ff5c9cd8
1 /*
2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "pci_openfirmware.h"
8 #include <stdlib.h>
9 #include <string.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,
25 NULL,
29 status_t
30 ppc_openfirmware_pci_controller_init(void)
32 char path[256];
33 int cookie = 0;
34 while (of_get_next_device(&cookie, 0, "pci", path, sizeof(path))
35 == B_OK) {
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",
41 compatible);
42 if (error != B_OK) {
43 dprintf("ppc_openfirmware_pci_controller_init: Failed to get "
44 "\"compatible\" property for pci device: %s\n", path);
45 continue;
48 // probe
49 for (int i = 0; sProbeFunctions[i]; i++) {
50 error = sProbeFunctions[i](deviceNode, compatible);
51 if (error == B_OK)
52 break;
56 return B_OK;
60 // #pragma mark - support functions
63 char *
64 StringArrayPropertyValue::NextElement(int &cookie) const
66 if (cookie >= length)
67 return NULL;
69 char *result = value + cookie;
70 cookie += strnlen(result, length - cookie) + 1;
71 return result;
75 bool
76 StringArrayPropertyValue::ContainsElement(const char *value) const
78 int cookie = 0;
79 while (char *checkValue = NextElement(cookie)) {
80 if (strcmp(checkValue, value) == 0)
81 return true;
84 return false;
88 status_t
89 openfirmware_get_property(int package, const char *propertyName,
90 PropertyValue &value)
92 value.length = of_getproplen(package, propertyName);
93 if (value.length < 0)
94 return B_ENTRY_NOT_FOUND;
96 value.value = (char*)malloc(value.length);
97 if (!value.value)
98 return B_NO_MEMORY;
100 if (of_getprop(package, propertyName, value.value, value.length)
101 == OF_FAILED) {
102 return B_ERROR;
105 return B_OK;