Remove building with NOCRYPTO option
[minix.git] / minix / lib / libacpi / acpi.c
blob5675ee8f425b250c0c1a96929159a7a5160fe9d1
1 #define _SYSTEM
3 #include <errno.h>
4 #include <string.h>
6 #include <minix/acpi.h>
7 #include <minix/com.h>
8 #include <minix/ds.h>
9 #include <minix/ipc.h>
10 #include <minix/log.h>
11 #include <minix/sysutil.h>
13 static struct log log =
14 { .name = "libacpi", .log_level = LEVEL_TRACE, .log_func = default_log };
16 static endpoint_t acpi_ep = NONE;
18 int
19 acpi_init(void)
21 int res;
22 res = ds_retrieve_label_endpt("acpi", &acpi_ep);
23 return res;
26 /*===========================================================================*
27 * IRQ handling *
28 *===========================================================================*/
29 int
30 acpi_get_irq(unsigned bus, unsigned dev, unsigned pin)
32 int err;
33 message m;
35 if (acpi_ep == NONE) {
36 err = acpi_init();
37 if (OK != err) {
38 panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err);
40 else {
41 log_info(&log, "resolved acpi to endpoint: %d\n", acpi_ep);
45 ((struct acpi_get_irq_req *)&m)->hdr.request = ACPI_REQ_GET_IRQ;
46 ((struct acpi_get_irq_req *)&m)->bus = bus;
47 ((struct acpi_get_irq_req *)&m)->dev = dev;
48 ((struct acpi_get_irq_req *)&m)->pin = pin;
50 if ((err = ipc_sendrec(acpi_ep, &m)) != OK)
51 panic("libacpi: error %d while receiving from ACPI\n", err);
53 return ((struct acpi_get_irq_resp *)&m)->irq;
57 * tells acpi which two busses are connected by this bridge. The primary bus
58 * (pbnr) must be already known to acpi and it must map dev as the connection to
59 * the secondary (sbnr) bus
61 void
62 acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr)
64 int err;
65 message m;
67 if (acpi_ep == NONE) {
68 err = acpi_init();
69 if (OK != err) {
70 panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err);
74 ((struct acpi_map_bridge_req *)&m)->hdr.request = ACPI_REQ_MAP_BRIDGE;
75 ((struct acpi_map_bridge_req *)&m)->primary_bus = pbnr;
76 ((struct acpi_map_bridge_req *)&m)->secondary_bus = sbnr;
77 ((struct acpi_map_bridge_req *)&m)->device = dev;
79 if ((err = ipc_sendrec(acpi_ep, &m)) != OK)
80 panic("libacpi: error %d while receiving from ACPI\n", err);
82 if (((struct acpi_map_bridge_resp *)&m)->err != OK)
83 printf("libacpi: acpi failed to map pci (%d) to pci (%d) bridge\n",
84 pbnr, sbnr);