From: rlfnb Date: Thu, 8 Sep 2016 18:03:12 +0000 (+0200) Subject: introducing libacpi X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=fee60e45e67240c6c98101a60bf7abc705899333;p=minix.git introducing libacpi Change-Id: I0808545fefaefc9a8fc8d1101bd85b676467fea0 --- diff --git a/distrib/sets/lists/minix-base/md.i386 b/distrib/sets/lists/minix-base/md.i386 index 52aa190aa..c3f049cc2 100644 --- a/distrib/sets/lists/minix-base/md.i386 +++ b/distrib/sets/lists/minix-base/md.i386 @@ -55,6 +55,8 @@ ./service/virtio_blk minix-base ./service/virtio_net minix-base ./service/vt6105 minix-base +./usr/lib/libacpi.a minix-base +./usr/lib/libacpi_pic.a minix-base ./usr/lib/libhgfs.a minix-base ./usr/lib/libhgfs_pic.a minix-base ./usr/lib/libm387.a minix-base diff --git a/distrib/sets/lists/minix-comp/mi b/distrib/sets/lists/minix-comp/mi index e621bb447..16afb47d6 100644 --- a/distrib/sets/lists/minix-comp/mi +++ b/distrib/sets/lists/minix-comp/mi @@ -1867,6 +1867,7 @@ ./usr/include/zlib.h minix-comp ./usr/lib minix-comp ./usr/lib/bc minix-comp +./usr/lib/bc/libacpi.a minix-comp bitcode ./usr/lib/bc/libarchive.a minix-comp bitcode ./usr/lib/bc/libasyn.a minix-comp bitcode ./usr/lib/bc/libaudiodriver.a minix-comp bitcode diff --git a/lib/Makefile b/lib/Makefile index dec0fa079..bb090de11 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -50,7 +50,8 @@ SUBDIR+= ../minix/lib/liblwip \ .endif .if (${MACHINE_ARCH} == "i386") -SUBDIR+= ../minix/lib/libhgfs \ +SUBDIR+= ../minix/lib/libacpi \ + ../minix/lib/libhgfs \ ../minix/lib/libvassert \ ../minix/lib/libvboxfs \ ../minix/lib/libvirtio diff --git a/minix/drivers/bus/pci/Makefile b/minix/drivers/bus/pci/Makefile index 71e63fc1e..94c4dccfb 100644 --- a/minix/drivers/bus/pci/Makefile +++ b/minix/drivers/bus/pci/Makefile @@ -18,6 +18,9 @@ CWARNFLAGS.clang=-Wno-unused DPADD+= ${LIBCHARDRIVER} LDADD+= -lchardriver +DPADD+= ${LIBACPI} +LDADD+= -lacpi + WARNS= 3 .include diff --git a/minix/drivers/bus/pci/pci.c b/minix/drivers/bus/pci/pci.c index ceb5d1d24..833e46156 100644 --- a/minix/drivers/bus/pci/pci.c +++ b/minix/drivers/bus/pci/pci.c @@ -8,7 +8,6 @@ Created: Jan 2000 by Philip Homburg #include #include #include -#include #include #include @@ -94,7 +93,6 @@ static struct pcidev static int nr_pcidev= 0; static struct machine machine; -static endpoint_t acpi_ep; /*===========================================================================* * helper functions for I/O * @@ -890,26 +888,6 @@ do_isabridge(int busind) return 0; } -/*===========================================================================* - * IRQ handling * - *===========================================================================*/ -static int -acpi_get_irq(unsigned bus, unsigned dev, unsigned pin) -{ - int err; - message m; - - ((struct acpi_get_irq_req *)&m)->hdr.request = ACPI_REQ_GET_IRQ; - ((struct acpi_get_irq_req *)&m)->bus = bus; - ((struct acpi_get_irq_req *)&m)->dev = dev; - ((struct acpi_get_irq_req *)&m)->pin = pin; - - if ((err = ipc_sendrec(acpi_ep, &m)) != OK) - panic("PCI: error %d while receiveing from ACPI\n", err); - - return ((struct acpi_get_irq_resp *)&m)->irq; -} - static int derive_irq(struct pcidev * dev, int pin) { @@ -1801,30 +1779,6 @@ complete_bridges(void) } } -/* - * tells acpi which two busses are connected by this bridge. The primary bus - * (pbnr) must be already known to acpi and it must map dev as the connection to - * the secondary (sbnr) bus - */ -static void -acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr) -{ - int err; - message m; - - ((struct acpi_map_bridge_req *)&m)->hdr.request = ACPI_REQ_MAP_BRIDGE; - ((struct acpi_map_bridge_req *)&m)->primary_bus = pbnr; - ((struct acpi_map_bridge_req *)&m)->secondary_bus = sbnr; - ((struct acpi_map_bridge_req *)&m)->device = dev; - - if ((err = ipc_sendrec(acpi_ep, &m)) != OK) - panic("PCI: error %d while receiveing from ACPI\n", err); - - if (((struct acpi_map_bridge_resp *)&m)->err != OK) - printf("PCI: acpi failed to map pci (%d) to pci (%d) bridge\n", - pbnr, sbnr); -} - static void do_pcibridge(int busind) { @@ -2148,7 +2102,7 @@ sef_cb_init(int type, sef_init_info_t *info) return ENODEV; } if (machine.apic_enabled && - ds_retrieve_label_endpt("acpi", &acpi_ep) != OK) { + acpi_init() != OK) { panic("PCI: Cannot use APIC mode without ACPI!\n"); } diff --git a/minix/include/minix/acpi.h b/minix/include/minix/acpi.h index 618339d1f..98e447d2a 100644 --- a/minix/include/minix/acpi.h +++ b/minix/include/minix/acpi.h @@ -1,15 +1,15 @@ #include #include -#define ACPI_REQ_GET_IRQ 1 -#define ACPI_REQ_MAP_BRIDGE 2 +#define ACPI_REQ_GET_IRQ 1 +#define ACPI_REQ_MAP_BRIDGE 2 struct acpi_request_hdr { endpoint_t m_source; /* message header */ u32_t request; }; -/* +/* * Message to request dev/pin translation to IRQ by acpi using the acpi routing * tables */ @@ -42,3 +42,7 @@ struct acpi_map_bridge_resp { int err; u32_t __padding[7]; }; + +int acpi_init(void); +int acpi_get_irq(unsigned bus, unsigned dev, unsigned pin); +void acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr); diff --git a/minix/lib/Makefile b/minix/lib/Makefile index c0325a2f0..ff8094050 100644 --- a/minix/lib/Makefile +++ b/minix/lib/Makefile @@ -32,6 +32,7 @@ SUBDIR+= libnetsock .endif .if (${MACHINE_ARCH} == "i386") +SUBDIR+= libacpi SUBDIR+= libhgfs SUBDIR+= libvassert SUBDIR+= libvboxfs diff --git a/minix/lib/libacpi/Makefile b/minix/lib/libacpi/Makefile new file mode 100644 index 000000000..37c328590 --- /dev/null +++ b/minix/lib/libacpi/Makefile @@ -0,0 +1,9 @@ +# Makefile for libacpi + +CPPFLAGS+= -D_MINIX_SYSTEM + +LIB = acpi + +SRCS = acpi.c + +.include diff --git a/minix/lib/libacpi/acpi.c b/minix/lib/libacpi/acpi.c new file mode 100644 index 000000000..5675ee8f4 --- /dev/null +++ b/minix/lib/libacpi/acpi.c @@ -0,0 +1,85 @@ +#define _SYSTEM + +#include +#include + +#include +#include +#include +#include +#include +#include + +static struct log log = +{ .name = "libacpi", .log_level = LEVEL_TRACE, .log_func = default_log }; + +static endpoint_t acpi_ep = NONE; + +int +acpi_init(void) +{ + int res; + res = ds_retrieve_label_endpt("acpi", &acpi_ep); + return res; +} + +/*===========================================================================* + * IRQ handling * + *===========================================================================*/ +int +acpi_get_irq(unsigned bus, unsigned dev, unsigned pin) +{ + int err; + message m; + + if (acpi_ep == NONE) { + err = acpi_init(); + if (OK != err) { + panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err); + } + else { + log_info(&log, "resolved acpi to endpoint: %d\n", acpi_ep); + } + } + + ((struct acpi_get_irq_req *)&m)->hdr.request = ACPI_REQ_GET_IRQ; + ((struct acpi_get_irq_req *)&m)->bus = bus; + ((struct acpi_get_irq_req *)&m)->dev = dev; + ((struct acpi_get_irq_req *)&m)->pin = pin; + + if ((err = ipc_sendrec(acpi_ep, &m)) != OK) + panic("libacpi: error %d while receiving from ACPI\n", err); + + return ((struct acpi_get_irq_resp *)&m)->irq; +} + +/* + * tells acpi which two busses are connected by this bridge. The primary bus + * (pbnr) must be already known to acpi and it must map dev as the connection to + * the secondary (sbnr) bus + */ +void +acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr) +{ + int err; + message m; + + if (acpi_ep == NONE) { + err = acpi_init(); + if (OK != err) { + panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err); + } + } + + ((struct acpi_map_bridge_req *)&m)->hdr.request = ACPI_REQ_MAP_BRIDGE; + ((struct acpi_map_bridge_req *)&m)->primary_bus = pbnr; + ((struct acpi_map_bridge_req *)&m)->secondary_bus = sbnr; + ((struct acpi_map_bridge_req *)&m)->device = dev; + + if ((err = ipc_sendrec(acpi_ep, &m)) != OK) + panic("libacpi: error %d while receiving from ACPI\n", err); + + if (((struct acpi_map_bridge_resp *)&m)->err != OK) + printf("libacpi: acpi failed to map pci (%d) to pci (%d) bridge\n", + pbnr, sbnr); +}