* 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
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005-2006, Ingo Weinhold <[email protected]>.
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _KERNEL_OPEN_FIRMWARE_DEVICES_H
|
||||||
|
#define _KERNEL_OPEN_FIRMWARE_DEVICES_H
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#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 */
|
||||||
@@ -17,6 +17,7 @@ KernelMergeObject boot_platform_openfirmware.o :
|
|||||||
video.cpp
|
video.cpp
|
||||||
|
|
||||||
openfirmware.c
|
openfirmware.c
|
||||||
|
openfirmware_devices.cpp
|
||||||
|
|
||||||
# generic
|
# generic
|
||||||
text_menu.cpp
|
text_menu.cpp
|
||||||
@@ -26,7 +27,7 @@ KernelMergeObject boot_platform_openfirmware.o :
|
|||||||
|
|
||||||
SEARCH on [ FGristFiles text_menu.cpp ]
|
SEARCH on [ FGristFiles text_menu.cpp ]
|
||||||
= [ FDirName $(HAIKU_TOP) src system boot platform generic ] ;
|
= [ 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 ] ;
|
= [ FDirName $(HAIKU_TOP) src system kernel platform openfirmware ] ;
|
||||||
|
|
||||||
SubInclude HAIKU_TOP src system boot platform openfirmware arch ;
|
SubInclude HAIKU_TOP src system boot platform openfirmware arch ;
|
||||||
|
|||||||
@@ -12,10 +12,9 @@
|
|||||||
#include <boot/kernel_args.h>
|
#include <boot/kernel_args.h>
|
||||||
#include <boot/stage2.h>
|
#include <boot/stage2.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
#include <platform/openfirmware/devices.h>
|
||||||
#include <platform/openfirmware/openfirmware.h>
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
|
|
||||||
#include "devices.h"
|
|
||||||
|
|
||||||
#define TRACE_CPU
|
#define TRACE_CPU
|
||||||
#ifdef TRACE_CPU
|
#ifdef TRACE_CPU
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x) dprintf x
|
||||||
@@ -37,7 +36,7 @@ boot_arch_cpu_init(void)
|
|||||||
char cpuPath[256];
|
char cpuPath[256];
|
||||||
int cookie = 0;
|
int cookie = 0;
|
||||||
int cpuCount = 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) {
|
sizeof(cpuPath)) == B_OK) {
|
||||||
TRACE(("found CPU: %s\n", cpuPath));
|
TRACE(("found CPU: %s\n", cpuPath));
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "devices.h"
|
|
||||||
#include "Handle.h"
|
#include "Handle.h"
|
||||||
#include "machine.h"
|
#include "machine.h"
|
||||||
|
|
||||||
@@ -13,6 +12,7 @@
|
|||||||
#include <boot/stage2.h>
|
#include <boot/stage2.h>
|
||||||
#include <boot/net/NetStack.h>
|
#include <boot/net/NetStack.h>
|
||||||
#include <boot/net/RemoteDisk.h>
|
#include <boot/net/RemoteDisk.h>
|
||||||
|
#include <platform/openfirmware/devices.h>
|
||||||
#include <platform/openfirmware/openfirmware.h>
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
@@ -22,88 +22,6 @@
|
|||||||
char sBootPath[192];
|
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
|
status_t
|
||||||
platform_get_boot_device(struct stage2_args *args, Node **_device)
|
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;
|
int cookie = 0;
|
||||||
char path[256];
|
char path[256];
|
||||||
status_t status;
|
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) {
|
sizeof(path))) == B_OK) {
|
||||||
if (!strcmp(path, sBootPath)) {
|
if (!strcmp(path, sBootPath)) {
|
||||||
// don't add the boot device twice
|
// don't add the boot device twice
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2005, Ingo Weinhold <[email protected]>.
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OPENFIRMWARE_DEVICES_H
|
|
||||||
#define OPENFIRMWARE_DEVICES_H
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
|
||||||
|
|
||||||
#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 */
|
|
||||||
@@ -9,16 +9,15 @@
|
|||||||
|
|
||||||
#include <boot/kernel_args.h>
|
#include <boot/kernel_args.h>
|
||||||
#include <boot/stage2.h>
|
#include <boot/stage2.h>
|
||||||
|
#include <platform/openfirmware/devices.h>
|
||||||
#include <platform/openfirmware/openfirmware.h>
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
|
|
||||||
#include "devices.h"
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
init_real_time_clock(void)
|
init_real_time_clock(void)
|
||||||
{
|
{
|
||||||
// find RTC
|
// find RTC
|
||||||
int rtcCookie = 0;
|
int rtcCookie = 0;
|
||||||
if (platform_get_next_device(&rtcCookie, 0, "rtc",
|
if (of_get_next_device(&rtcCookie, 0, "rtc",
|
||||||
gKernelArgs.platform_args.rtc_path,
|
gKernelArgs.platform_args.rtc_path,
|
||||||
sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) {
|
sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) {
|
||||||
printf("init_real_time_clock(): Found no RTC device!");
|
printf("init_real_time_clock(): Found no RTC device!");
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ KernelLd kernel_$(TARGET_ARCH) :
|
|||||||
kernel_debug.o
|
kernel_debug.o
|
||||||
|
|
||||||
lib$(TARGET_ARCH).a
|
lib$(TARGET_ARCH).a
|
||||||
lib$(TARGET_BOOT_PLATFORM).a
|
kernel_platform_$(TARGET_BOOT_PLATFORM).o
|
||||||
|
|
||||||
linkhack.so
|
linkhack.so
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ KernelLd kernel.so :
|
|||||||
kernel_debug.o
|
kernel_debug.o
|
||||||
|
|
||||||
lib$(TARGET_ARCH).a
|
lib$(TARGET_ARCH).a
|
||||||
lib$(TARGET_BOOT_PLATFORM).a
|
kernel_platform_$(TARGET_BOOT_PLATFORM).o
|
||||||
|
|
||||||
linkhack.so
|
linkhack.so
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ SubDir HAIKU_TOP src system kernel platform bios_ia32 ;
|
|||||||
SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||||
SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||||
|
|
||||||
KernelStaticLibrary libbios_ia32.a :
|
KernelMergeObject kernel_platform_bios_ia32.o :
|
||||||
platform.cpp
|
platform.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src system kernel platform openfirmware ;
|
|||||||
SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
SubDirCcFlags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||||
SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ;
|
||||||
|
|
||||||
KernelStaticLibrary libopenfirmware.a :
|
KernelMergeObject kernel_platform_openfirmware.o :
|
||||||
openfirmware.c
|
openfirmware.c
|
||||||
|
openfirmware_devices.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2005, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <platform/openfirmware/devices.h>
|
||||||
|
#include <platform/openfirmware/openfirmware.h>
|
||||||
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/** 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user