From f602da2b72be9c948e694de0d89b1bc823b0f106 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 26 Jan 2006 15:06:59 +0000 Subject: [PATCH] * Turned the kernel platform support from a library into an object. * Moved the Open Firmware function platform_get_next_device() from the boot loader into the kernel (renamed to of_get_next_device()). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16101 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/platform/openfirmware/devices.h | 22 +++++ src/system/boot/platform/openfirmware/Jamfile | 3 +- .../platform/openfirmware/arch/ppc/cpu.cpp | 5 +- .../boot/platform/openfirmware/devices.cpp | 86 +---------------- .../boot/platform/openfirmware/devices.h | 22 ----- .../platform/openfirmware/real_time_clock.cpp | 5 +- src/system/kernel/Jamfile | 4 +- src/system/kernel/platform/bios_ia32/Jamfile | 2 +- .../kernel/platform/openfirmware/Jamfile | 3 +- .../openfirmware/openfirmware_devices.cpp | 92 +++++++++++++++++++ 10 files changed, 127 insertions(+), 117 deletions(-) create mode 100644 headers/private/kernel/platform/openfirmware/devices.h delete mode 100644 src/system/boot/platform/openfirmware/devices.h create mode 100644 src/system/kernel/platform/openfirmware/openfirmware_devices.cpp diff --git a/headers/private/kernel/platform/openfirmware/devices.h b/headers/private/kernel/platform/openfirmware/devices.h new file mode 100644 index 0000000000..9a3a4c8e85 --- /dev/null +++ b/headers/private/kernel/platform/openfirmware/devices.h @@ -0,0 +1,22 @@ +/* + * Copyright 2005-2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#ifndef _KERNEL_OPEN_FIRMWARE_DEVICES_H +#define _KERNEL_OPEN_FIRMWARE_DEVICES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +status_t of_get_next_device(int *_cookie, int root, const char *type, + char *path, size_t pathSize); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* _KERNEL_OPEN_FIRMWARE_DEVICES_H */ diff --git a/src/system/boot/platform/openfirmware/Jamfile b/src/system/boot/platform/openfirmware/Jamfile index a5ae2e9d52..0204ec863e 100644 --- a/src/system/boot/platform/openfirmware/Jamfile +++ b/src/system/boot/platform/openfirmware/Jamfile @@ -17,6 +17,7 @@ KernelMergeObject boot_platform_openfirmware.o : video.cpp openfirmware.c + openfirmware_devices.cpp # generic text_menu.cpp @@ -26,7 +27,7 @@ KernelMergeObject boot_platform_openfirmware.o : SEARCH on [ FGristFiles text_menu.cpp ] = [ FDirName $(HAIKU_TOP) src system boot platform generic ] ; -SEARCH on [ FGristFiles openfirmware.c ] +SEARCH on [ FGristFiles openfirmware.c openfirmware_devices.cpp ] = [ FDirName $(HAIKU_TOP) src system kernel platform openfirmware ] ; SubInclude HAIKU_TOP src system boot platform openfirmware arch ; diff --git a/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp b/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp index bbe753e83b..800de3f153 100644 --- a/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp +++ b/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp @@ -12,10 +12,9 @@ #include #include #include +#include #include -#include "devices.h" - #define TRACE_CPU #ifdef TRACE_CPU # define TRACE(x) dprintf x @@ -37,7 +36,7 @@ boot_arch_cpu_init(void) char cpuPath[256]; int cookie = 0; int cpuCount = 0; - while (platform_get_next_device(&cookie, cpus, "cpu", cpuPath, + while (of_get_next_device(&cookie, cpus, "cpu", cpuPath, sizeof(cpuPath)) == B_OK) { TRACE(("found CPU: %s\n", cpuPath)); diff --git a/src/system/boot/platform/openfirmware/devices.cpp b/src/system/boot/platform/openfirmware/devices.cpp index 0f2e9d34ea..5f32598dde 100644 --- a/src/system/boot/platform/openfirmware/devices.cpp +++ b/src/system/boot/platform/openfirmware/devices.cpp @@ -3,7 +3,6 @@ * Distributed under the terms of the MIT License. */ -#include "devices.h" #include "Handle.h" #include "machine.h" @@ -13,6 +12,7 @@ #include #include #include +#include #include #include @@ -22,88 +22,6 @@ char sBootPath[192]; -/** Gets all device types of the specified type by doing a - * depth-first search of the OpenFirmware device tree. - * If a root != 0 is given, the function only traverses the subtree spanned - * by the root (inclusively). Otherwise the whole device tree is searched. - * - * The cookie has to be initialized to zero. - */ - -status_t -platform_get_next_device(int *_cookie, int root, const char *type, char *path, - size_t pathSize) -{ - int node = *_cookie; - - while (true) { - int next; - - if (node == 0) { - // node is NULL, meaning that this is the initial function call. - // If a root was supplied, we take that, otherwise the device tree - // root. - if (root != 0) - node = root; - else - node = of_peer(0); - - if (node == OF_FAILED) - return B_ERROR; - if (node == 0) - return B_ENTRY_NOT_FOUND; - - // We want to visit the root first. - next = node; - } else - next = of_child(node); - - if (next == OF_FAILED) - return B_ERROR; - - if (next == 0) { - // no child node found - next = of_peer(node); - if (next == OF_FAILED) - return B_ERROR; - - while (next == 0) { - // no peer node found, we are using the device - // tree itself as our search stack - - next = of_parent(node); - if (next == OF_FAILED) - return B_ERROR; - - if (next == root || next == 0) { - // We have searched the whole device tree - return B_ENTRY_NOT_FOUND; - } - - // look into the next tree - node = next; - next = of_peer(node); - } - } - - *_cookie = node = next; - - char nodeType[16]; - int length; - if (of_getprop(node, "device_type", nodeType, sizeof(nodeType)) == OF_FAILED - || strcmp(nodeType, type) - || (length = of_package_to_path(node, path, pathSize - 1)) == OF_FAILED) - continue; - - path[length] = '\0'; - return B_OK; - } -} - - -// #pragma mark - - - status_t platform_get_boot_device(struct stage2_args *args, Node **_device) { @@ -229,7 +147,7 @@ platform_add_block_devices(stage2_args *args, NodeList *devicesList) int cookie = 0; char path[256]; status_t status; - while ((status = platform_get_next_device(&cookie, 0, "block", path, + while ((status = of_get_next_device(&cookie, 0, "block", path, sizeof(path))) == B_OK) { if (!strcmp(path, sBootPath)) { // don't add the boot device twice diff --git a/src/system/boot/platform/openfirmware/devices.h b/src/system/boot/platform/openfirmware/devices.h deleted file mode 100644 index b080324e65..0000000000 --- a/src/system/boot/platform/openfirmware/devices.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2005, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#ifndef OPENFIRMWARE_DEVICES_H -#define OPENFIRMWARE_DEVICES_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -status_t platform_get_next_device(int *_cookie, int root, const char *type, - char *path, size_t pathSize); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* OPENFIRMWARE_DEVICES_H */ diff --git a/src/system/boot/platform/openfirmware/real_time_clock.cpp b/src/system/boot/platform/openfirmware/real_time_clock.cpp index 957d73008b..64c858cc3f 100644 --- a/src/system/boot/platform/openfirmware/real_time_clock.cpp +++ b/src/system/boot/platform/openfirmware/real_time_clock.cpp @@ -9,16 +9,15 @@ #include #include +#include #include -#include "devices.h" - status_t init_real_time_clock(void) { // find RTC int rtcCookie = 0; - if (platform_get_next_device(&rtcCookie, 0, "rtc", + if (of_get_next_device(&rtcCookie, 0, "rtc", gKernelArgs.platform_args.rtc_path, sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) { printf("init_real_time_clock(): Found no RTC device!"); diff --git a/src/system/kernel/Jamfile b/src/system/kernel/Jamfile index a8a3904a9e..f7f05bc631 100644 --- a/src/system/kernel/Jamfile +++ b/src/system/kernel/Jamfile @@ -63,7 +63,7 @@ KernelLd kernel_$(TARGET_ARCH) : kernel_debug.o lib$(TARGET_ARCH).a - lib$(TARGET_BOOT_PLATFORM).a + kernel_platform_$(TARGET_BOOT_PLATFORM).o linkhack.so @@ -92,7 +92,7 @@ KernelLd kernel.so : kernel_debug.o lib$(TARGET_ARCH).a - lib$(TARGET_BOOT_PLATFORM).a + kernel_platform_$(TARGET_BOOT_PLATFORM).o linkhack.so diff --git a/src/system/kernel/platform/bios_ia32/Jamfile b/src/system/kernel/platform/bios_ia32/Jamfile index 497fe79acb..becc0e4fc8 100644 --- a/src/system/kernel/platform/bios_ia32/Jamfile +++ b/src/system/kernel/platform/bios_ia32/Jamfile @@ -3,6 +3,6 @@ SubDir HAIKU_TOP src system kernel platform bios_ia32 ; SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ; SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ; -KernelStaticLibrary libbios_ia32.a : +KernelMergeObject kernel_platform_bios_ia32.o : platform.cpp ; diff --git a/src/system/kernel/platform/openfirmware/Jamfile b/src/system/kernel/platform/openfirmware/Jamfile index 62a9614f9b..c594a2b8b4 100644 --- a/src/system/kernel/platform/openfirmware/Jamfile +++ b/src/system/kernel/platform/openfirmware/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src system kernel platform openfirmware ; SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ; SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ; -KernelStaticLibrary libopenfirmware.a : +KernelMergeObject kernel_platform_openfirmware.o : openfirmware.c + openfirmware_devices.cpp ; diff --git a/src/system/kernel/platform/openfirmware/openfirmware_devices.cpp b/src/system/kernel/platform/openfirmware/openfirmware_devices.cpp new file mode 100644 index 0000000000..35348d6406 --- /dev/null +++ b/src/system/kernel/platform/openfirmware/openfirmware_devices.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include + +#include + + +/** Gets all device types of the specified type by doing a + * depth-first search of the OpenFirmware device tree. + * If a root != 0 is given, the function only traverses the subtree spanned + * by the root (inclusively). Otherwise the whole device tree is searched. + * + * The cookie has to be initialized to zero. + */ +status_t +of_get_next_device(int *_cookie, int root, const char *type, char *path, + size_t pathSize) +{ + int node = *_cookie; + + while (true) { + int next; + + if (node == 0) { + // node is NULL, meaning that this is the initial function call. + // If a root was supplied, we take that, otherwise the device tree + // root. + if (root != 0) + node = root; + else + node = of_peer(0); + + if (node == OF_FAILED) + return B_ERROR; + if (node == 0) + return B_ENTRY_NOT_FOUND; + + // We want to visit the root first. + next = node; + } else + next = of_child(node); + + if (next == OF_FAILED) + return B_ERROR; + + if (next == 0) { + // no child node found + next = of_peer(node); + if (next == OF_FAILED) + return B_ERROR; + + while (next == 0) { + // no peer node found, we are using the device + // tree itself as our search stack + + next = of_parent(node); + if (next == OF_FAILED) + return B_ERROR; + + if (next == root || next == 0) { + // We have searched the whole device tree + return B_ENTRY_NOT_FOUND; + } + + // look into the next tree + node = next; + next = of_peer(node); + } + } + + *_cookie = node = next; + + char nodeType[16]; + int length; + if (of_getprop(node, "device_type", nodeType, sizeof(nodeType)) + == OF_FAILED + || strcmp(nodeType, type) + || (length = of_package_to_path(node, path, pathSize - 1)) + == OF_FAILED) { + continue; + } + + path[length] = '\0'; + return B_OK; + } +} +