From 2e298fb603e8e07fba4ef1580f42ecc9690c2975 Mon Sep 17 00:00:00 2001 From: Bryan Varner Date: Wed, 22 Feb 2006 13:36:08 +0000 Subject: [PATCH] Enabled acpi bus_manager build targets, R5 and haiku targets. R5 also has acpi_loader as a disk driver (so it's loaded early at boot). acpi ns dumper will dump your acpi namespace device tree. It's handy. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16497 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuImage | 4 +- src/add-ons/kernel/drivers/disk/Jamfile | 1 + .../kernel/drivers/disk/acpi_loader/Jamfile | 15 + .../drivers/disk/acpi_loader/acpi_loader.c | 56 ++++ src/add-ons/kernel/drivers/power/Jamfile | 1 + .../kernel/drivers/power/acpi_ns_dump/Jamfile | 16 ++ .../drivers/power/acpi_ns_dump/acpi_ns_dump.c | 257 ++++++++++++++++++ 7 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 src/add-ons/kernel/drivers/disk/acpi_loader/Jamfile create mode 100644 src/add-ons/kernel/drivers/disk/acpi_loader/acpi_loader.c create mode 100644 src/add-ons/kernel/drivers/power/acpi_ns_dump/Jamfile create mode 100644 src/add-ons/kernel/drivers/power/acpi_ns_dump/acpi_ns_dump.c diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 1d2814c941..fb2e814ca6 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -71,7 +71,8 @@ BEOS_ADD_ONS_DRIVERS_NET = ipro1000 rtl8139 rtl8169 sis900 via-rhine wb840 net_stack_driver # bcm440x bcm570x (only available with GPLd add-ons) ; -BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager ; +BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button $(X86_ONLY)acpi_ns_dump ; +BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager $(X86_ONLY)acpi ; BEOS_ADD_ONS_FILESYSTEMS = bfs ; @@ -102,6 +103,7 @@ AddDriversToHaikuImage graphics : $(BEOS_ADD_ONS_DRIVERS_GRAPHICS) ; AddDriversToHaikuImage input : ps2_hid ; AddDriversToHaikuImage misc : config ; AddDriversToHaikuImage net : $(BEOS_ADD_ONS_DRIVERS_NET) ; +AddDriversToHaikuImage power : $(BEOS_ADD_ONS_DRIVERS_ACPI) ; # kernel AddFilesToHaikuImage beos system : kernel_$(TARGET_ARCH) ; diff --git a/src/add-ons/kernel/drivers/disk/Jamfile b/src/add-ons/kernel/drivers/disk/Jamfile index f3afdf897d..7d0492e3d5 100644 --- a/src/add-ons/kernel/drivers/disk/Jamfile +++ b/src/add-ons/kernel/drivers/disk/Jamfile @@ -1,3 +1,4 @@ SubDir HAIKU_TOP src add-ons kernel drivers disk ; SubInclude HAIKU_TOP src add-ons kernel drivers disk scsi ; +SubInclude HAIKU_TOP src add-ons kernel drivers disk acpi_loader ; diff --git a/src/add-ons/kernel/drivers/disk/acpi_loader/Jamfile b/src/add-ons/kernel/drivers/disk/acpi_loader/Jamfile new file mode 100644 index 0000000000..0141a451d6 --- /dev/null +++ b/src/add-ons/kernel/drivers/disk/acpi_loader/Jamfile @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src add-ons kernel drivers disk acpi_loader ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +if $(TARGET_PLATFORM) != haiku { + # Needed for . Unfortunately we also get the other headers there, + # that we don't really want. + UsePublicHeaders drivers ; +} + +KernelAddon acpi_loader : kernel drivers bin : + acpi_loader.c + ; + +Depends acpi_loader : acpi ; diff --git a/src/add-ons/kernel/drivers/disk/acpi_loader/acpi_loader.c b/src/add-ons/kernel/drivers/disk/acpi_loader/acpi_loader.c new file mode 100644 index 0000000000..d03a0d04c4 --- /dev/null +++ b/src/add-ons/kernel/drivers/disk/acpi_loader/acpi_loader.c @@ -0,0 +1,56 @@ +/* + * R5 ACPI Loader. This needs to happen as soon as possible in the boot process + * so we have to break convention and place it here. + */ + +#include +#include +#include + +#include + +acpi_module_info *acpi; + +status_t +init_hardware (void) +{ + return B_OK; +} + +status_t +init_driver (void) +{ + return get_module(B_ACPI_MODULE_NAME, (module_info**)&acpi); +} + +void +uninit_driver (void) +{ + put_module(B_ACPI_MODULE_NAME); +} + +static const char *acpi_loader_name[] = { + NULL +}; + +device_hooks acpi_loader_hooks = { + NULL, /* open */ + NULL, /* close */ + NULL, /* free */ + NULL, /* control */ + NULL, /* read */ + NULL, /* write */ + NULL, NULL, NULL, NULL +}; + +const char** +publish_devices() +{ + return acpi_loader_name; +} + +device_hooks* +find_device(const char* name) +{ + return &acpi_loader_hooks; +} diff --git a/src/add-ons/kernel/drivers/power/Jamfile b/src/add-ons/kernel/drivers/power/Jamfile index 76f6642d72..8fd0ef4b8b 100644 --- a/src/add-ons/kernel/drivers/power/Jamfile +++ b/src/add-ons/kernel/drivers/power/Jamfile @@ -1,3 +1,4 @@ SubDir HAIKU_TOP src add-ons kernel drivers power ; SubInclude HAIKU_TOP src add-ons kernel drivers power acpi_button ; +SubInclude HAIKU_TOP src add-ons kernel drivers power acpi_ns_dump ; \ No newline at end of file diff --git a/src/add-ons/kernel/drivers/power/acpi_ns_dump/Jamfile b/src/add-ons/kernel/drivers/power/acpi_ns_dump/Jamfile new file mode 100644 index 0000000000..09f4cfc51f --- /dev/null +++ b/src/add-ons/kernel/drivers/power/acpi_ns_dump/Jamfile @@ -0,0 +1,16 @@ +SubDir HAIKU_TOP src add-ons kernel drivers power acpi_ns_dump ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +if $(TARGET_PLATFORM) != haiku { + # Needed for . Unfortunately we also get the other headers there, + # that we don't really want. + UsePublicHeaders drivers ; +} + +KernelAddon acpi_ns_dump : kernel drivers bin : + acpi_ns_dump.c + ; + +Depends acpi_ns_dump : acpi ; + diff --git a/src/add-ons/kernel/drivers/power/acpi_ns_dump/acpi_ns_dump.c b/src/add-ons/kernel/drivers/power/acpi_ns_dump/acpi_ns_dump.c new file mode 100644 index 0000000000..4021e6e35b --- /dev/null +++ b/src/add-ons/kernel/drivers/power/acpi_ns_dump/acpi_ns_dump.c @@ -0,0 +1,257 @@ +/* ++++++++++ + ACPI namespace dump. + Nothing special here, just tree enumeration and type identification. ++++++ */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +acpi_module_info *acpi; + +/* ---------- + init_hardware - called once the first time the driver is loaded +----- */ +status_t +init_hardware (void) +{ + return B_OK; +} + + +/* ---------- + init_driver - optional function - called every time the driver + is loaded. +----- */ +status_t +init_driver (void) +{ + dprintf("acpi_ns_dump: init_driver\n"); + return get_module(B_ACPI_MODULE_NAME,(module_info **)&acpi); +} + + +/* ---------- + uninit_driver - optional function - called every time the driver + is unloaded +----- */ +void +uninit_driver (void) +{ + dprintf("acpi_ns_dump: uninit_driver\n"); + put_module(B_ACPI_MODULE_NAME); +} + +void dump_acpi_namespace(char *root, void *buf, size_t* num_bytes, int indenting) { + char result[255]; + char output[255]; + char tabs[255]; + char hid[9]; + int i, depth; + uint32 type; + void *counter = NULL; + + hid[8] = '\0'; + tabs[0] = '\0'; + + for (i = 0; i < indenting; i++) { + sprintf(tabs, "%s| ", tabs); + } + sprintf(tabs, "%s|--- ", tabs); + depth = sizeof(char) * 5 * indenting + sizeof(char); // index into result where the device name will be. + + while (acpi->get_next_entry(ACPI_TYPE_ANY, root, result, 255, &counter) == B_OK) { + type = acpi->get_object_type(result); + sprintf(output, "%s%s", tabs, result + depth); + switch(type) { + case ACPI_TYPE_ANY: + break; + case ACPI_TYPE_INTEGER: + sprintf(output, "%s INTEGER", output); + break; + case ACPI_TYPE_STRING: + sprintf(output, "%s STRING", output); + break; + case ACPI_TYPE_BUFFER: + sprintf(output, "%s BUFFER", output); + break; + case ACPI_TYPE_PACKAGE: + sprintf(output, "%s PACKAGE", output); + break; + case ACPI_TYPE_FIELD_UNIT: + sprintf(output, "%s FIELD UNIT", output); + break; + case ACPI_TYPE_DEVICE: + acpi->get_device_hid(result, hid); + sprintf(output, "%s DEVICE (%s)", output, hid); + break; + case ACPI_TYPE_EVENT: + sprintf(output, "%s EVENT", output); + break; + case ACPI_TYPE_METHOD: + sprintf(output, "%s METHOD", output); + break; + case ACPI_TYPE_MUTEX: + sprintf(output, "%s MUTEX", output); + break; + case ACPI_TYPE_REGION: + sprintf(output, "%s REGION", output); + break; + case ACPI_TYPE_POWER: + sprintf(output, "%s POWER", output); + break; + case ACPI_TYPE_PROCESSOR: + sprintf(output, "%s PROCESSOR", output); + break; + case ACPI_TYPE_THERMAL: + sprintf(output, "%s THERMAL", output); + break; + case ACPI_TYPE_BUFFER_FIELD: + sprintf(output, "%s BUFFER_FIELD", output); + break; + } + sprintf(output, "%s\n", output); + + sprintf((buf + *num_bytes), "%s", output); + *num_bytes += strlen(output); + + dump_acpi_namespace(result, buf, num_bytes, indenting + 1); + } +} + + +/* ---------- + my_device_open - handle open() calls +----- */ + +static status_t +my_device_open (const char *name, uint32 flags, void** cookie) +{ + dprintf("\nacpi_ns_dump: device_open\n"); + *cookie = NULL; + + return B_OK; +} + + +/* ---------- + my_device_read - handle read() calls +----- */ +static status_t +my_device_read (void* cookie, off_t position, void *buf, size_t* num_bytes) +{ + size_t bytes = 0; + + if (position > 0) { + *num_bytes = 0; + } else { + dump_acpi_namespace("\\", buf, &bytes, 0); + *num_bytes = bytes; + dprintf("num_bytes %lu\n", *num_bytes); + } + + return B_OK; +} + + +/* ---------- + my_device_write - handle write() calls +----- */ + +static status_t +my_device_write (void* cookie, off_t position, const void* buffer, size_t* num_bytes) +{ + dprintf("acpi_ns_dump: device_write\n"); + *num_bytes = 0; /* tell caller nothing was written */ + return B_IO_ERROR; +} + + +/* ---------- + my_device_control - handle ioctl calls +----- */ + +static status_t +my_device_control (void* cookie, uint32 op, void* arg, size_t len) +{ + dprintf("acpi_nd_dump: device_control\n"); + return B_BAD_VALUE; +} + + +/* ---------- + my_device_close - handle close() calls +----- */ + +static status_t +my_device_close (void* cookie) +{ + dprintf("acpi_ns_dump: device_close\n"); + return B_OK; +} + + +/* ----- + my_device_free - called after the last device is closed, and after + all i/o is complete. +----- */ +static status_t +my_device_free (void* cookie) +{ + dprintf("acpi_ns_dump: device_free\n"); + + return B_OK; +} + + +/* ----- + null-terminated array of device names supported by this driver +----- */ + +static const char *my_device_name[] = { + "power/namespace", + NULL +}; + +/* ----- + function pointers for the device hooks entry points +----- */ + +device_hooks my_device_hooks = { + my_device_open, /* -> open entry point */ + my_device_close, /* -> close entry point */ + my_device_free, /* -> free cookie */ + my_device_control, /* -> control entry point */ + my_device_read, /* -> read entry point */ + my_device_write /* -> write entry point */ +}; + +/* ---------- + publish_devices - return a null-terminated array of devices + supported by this driver. +----- */ + +const char** +publish_devices() +{ + dprintf("acpi_ns_driver: publish_devices\n"); + return my_device_name; +} + +/* ---------- + find_device - return ptr to device hooks structure for a + given device name +----- */ + +device_hooks* +find_device(const char* name) +{ + dprintf("acpi_ns_driver: find_device(%s)\n", name); + return &my_device_hooks; +}