]> Zhao Yanbai Git Server - minix.git/commitdiff
introducing libacpi 75/3375/2
authorrlfnb <rlfnb@rlfnb.de>
Thu, 8 Sep 2016 18:03:12 +0000 (20:03 +0200)
committerDavid van Moolenbroek <david@minix3.org>
Sat, 29 Oct 2016 15:08:10 +0000 (17:08 +0200)
Change-Id: I0808545fefaefc9a8fc8d1101bd85b676467fea0

distrib/sets/lists/minix-base/md.i386
distrib/sets/lists/minix-comp/mi
lib/Makefile
minix/drivers/bus/pci/Makefile
minix/drivers/bus/pci/pci.c
minix/include/minix/acpi.h
minix/lib/Makefile
minix/lib/libacpi/Makefile [new file with mode: 0644]
minix/lib/libacpi/acpi.c [new file with mode: 0644]

index 52aa190aabb8925b396335ba57c4b31fc09ba446..c3f049cc24a5200526cf10887b68cd0227465dae 100644 (file)
@@ -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
index e621bb447865e402295d8681efc1912dfc483fa0..16afb47d677837a7b273251f40a3076fd6afe9c4 100644 (file)
 ./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
index dec0fa079f79bf54c27af8d4977280c797a4cd57..bb090de1174d865be804acbcdf13de8902e22849 100644 (file)
@@ -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
index 71e63fc1eef3c6ecf585dd725f36d797c16d13fd..94c4dccfb4f72fded5495cb3f1fb117f35b2b28d 100644 (file)
@@ -18,6 +18,9 @@ CWARNFLAGS.clang=-Wno-unused
 DPADD+=        ${LIBCHARDRIVER}
 LDADD+=        -lchardriver
 
+DPADD+=        ${LIBACPI}
+LDADD+=        -lacpi
+
 WARNS= 3
 
 .include <minix.service.mk>
index ceb5d1d24a9b55f73419b108228767dec8a0e800..833e4615622e7409c97d281b5b1a4fc8efee91ae 100644 (file)
@@ -8,7 +8,6 @@ Created:        Jan 2000 by Philip Homburg <philip@cs.vu.nl>
 #include <minix/acpi.h>
 #include <minix/chardriver.h>
 #include <minix/driver.h>
-#include <minix/ds.h>
 #include <minix/param.h>
 #include <minix/rs.h>
 
@@ -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");
        }
 
index 618339d1fb39f6c5cee56535fcb70151cac4f762..98e447d2ab5527ef813fe1cf23fa80359d192daa 100644 (file)
@@ -1,15 +1,15 @@
 #include <sys/types.h>
 #include <minix/ipc.h>
 
-#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);
index c0325a2f0aaa4e84937aa010625386621197716e..ff80940505c4d6ba9d1ef9bf9fa7b9b125c016d3 100644 (file)
@@ -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 (file)
index 0000000..37c3285
--- /dev/null
@@ -0,0 +1,9 @@
+# Makefile for libacpi
+
+CPPFLAGS+= -D_MINIX_SYSTEM
+
+LIB = acpi
+
+SRCS = acpi.c
+
+.include <bsd.lib.mk>
diff --git a/minix/lib/libacpi/acpi.c b/minix/lib/libacpi/acpi.c
new file mode 100644 (file)
index 0000000..5675ee8
--- /dev/null
@@ -0,0 +1,85 @@
+#define _SYSTEM
+
+#include <errno.h>
+#include <string.h>
+
+#include <minix/acpi.h>
+#include <minix/com.h>
+#include <minix/ds.h>
+#include <minix/ipc.h>
+#include <minix/log.h>
+#include <minix/sysutil.h>
+
+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);
+}