summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2021-04-03 21:19:33 +1100
committerDamien Zammit <damien@zamaudio.com>2021-04-03 23:06:21 +1100
commit53fdd2f6649640ee981be45c727ec0e8e885fb96 (patch)
tree85a173615c346b4ea7989c46ea779ca4789af207
parent4f5eb7074e6ecbe8e53552a7f516923bfb75724e (diff)
acpi: Add new RPCsacpica-integrate
-rw-r--r--acpi/Makefile15
-rw-r--r--acpi/acpi-ops.c146
-rw-r--r--acpi/acpi.h6
-rw-r--r--acpi/main.c4
-rw-r--r--acpi/mig-mutate.h28
-rw-r--r--hurd/acpi.defs60
-rw-r--r--hurd/hurd_types.defs18
-rw-r--r--hurd/hurd_types.h1
8 files changed, 276 insertions, 2 deletions
diff --git a/acpi/Makefile b/acpi/Makefile
index 49c8ba9a..cc55a9f5 100644
--- a/acpi/Makefile
+++ b/acpi/Makefile
@@ -21,7 +21,9 @@ makemode = server
PORTDIR = $(srcdir)/port
SRCS = main.c netfs_impl.c acpi.c \
- acpifs.c ncache.c options.c func_files.c
+ acpifs.c ncache.c options.c func_files.c acpi-ops.c \
+ acpiServer.c
+
MIGSRCS =
OBJS = $(patsubst %.S,%.o,$(patsubst %.c,%.o, $(SRCS) $(MIGSRCS)))
@@ -33,3 +35,14 @@ target = acpi
include ../Makeconf
CFLAGS += -I$(PORTDIR)/include
+
+acpi-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
+
+# cpp doesn't automatically make dependencies for -imacros dependencies. argh.
+acpi_S.h acpiServer.c: mig-mutate.h
+ cat ../../hurd/acpi.defs \
+ | ${CC} -E -x c - -o - -imacros ../../acpi/mig-mutate.h \
+ | mig -cc cat - /dev/null -prefix S_ -subrprefix __ \
+ -user /dev/null \
+ -server acpiServer.c \
+ -sheader acpi_S.h
diff --git a/acpi/acpi-ops.c b/acpi/acpi-ops.c
new file mode 100644
index 00000000..d9795e87
--- /dev/null
+++ b/acpi/acpi-ops.c
@@ -0,0 +1,146 @@
+/*
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Implementation of ACPI operations */
+
+#include <acpi_S.h>
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+
+#include "libacpica/acpi_init.h"
+#include "acpifs.h"
+
+static error_t
+check_permissions (struct protid *master, int flags)
+{
+ struct node *node;
+ struct acpifs_dirent *e;
+
+ node = master->po->np;
+ e = node->nn->ln;
+
+ /* Check whether the user has permissions to access this node */
+ return entry_check_perms (master->user, e, flags);
+}
+
+static void
+acpi_enable(struct acpi_table *facp)
+{
+ int i;
+ uint8_t *ptr = (uint8_t *)&facp->data;
+
+ /* Grab value to write to SMI_CMD to enable ACPI */
+ uint8_t acpi_en = ptr[SMI_EN_OFFSET];
+ uint16_t smi_cmd = (uint16_t)ptr[SMI_CMD_OFFSET] | ((uint16_t)ptr[SMI_CMD_OFFSET+1] << 8);
+ uint16_t pm1a_ctl = (uint16_t)ptr[PM1A_CTL_OFFSET] | ((uint16_t)ptr[PM1A_CTL_OFFSET+1] << 8);
+
+ /* Get I/O permissions */
+ if (ioperm(smi_cmd, 2, 1))
+ {
+ fprintf(stderr, "EPERM on ioperm(smi_cmd)\n");
+ return;
+ }
+
+ if (ioperm(pm1a_ctl, 2, 1))
+ {
+ fprintf(stderr, "EPERM on ioperm(pm1a_ctl)\n");
+ return;
+ }
+
+ /* Enable ACPI */
+ outb(acpi_en, smi_cmd);
+ for (i = 0; i < 300; i++)
+ {
+ if ((inw(pm1a_ctl) & SCI_EN) == SCI_EN)
+ break;
+ }
+
+ /* Drop I/O permissions */
+ ioperm(smi_cmd, 2, 0);
+ ioperm(pm1a_ctl, 2, 0);
+}
+
+error_t
+S_acpi_sleep (struct protid *master, int sleep_state)
+{
+ error_t err;
+ struct acpifs_dirent *e;
+
+ if (!master)
+ return EOPNOTSUPP;
+
+ e = master->po->np->nn->ln;
+ if (strncmp (e->name, "FACP", 4))
+ /* This operation may only be addressed to the FADT table */
+ return EINVAL;
+
+ err = check_permissions (master, O_READ);
+ if (err)
+ return err;
+
+ /* Enable ACPI */
+ acpi_enable(e->acpitable);
+
+ /* Perform sleep */
+ acpi_enter_sleep(sleep_state);
+
+ /* Never reached */
+ return err;
+}
+
+error_t
+S_acpi_enable (struct protid *master)
+{
+ error_t err;
+ struct acpifs_dirent *e;
+
+ if (!master)
+ return EOPNOTSUPP;
+
+ e = master->po->np->nn->ln;
+ if (strncmp (e->name, "FACP", 4))
+ /* This operation may only be addressed to the FADT table */
+ return EINVAL;
+
+ err = check_permissions (master, O_READ);
+ if (err)
+ return err;
+
+ acpi_enable(e->acpitable);
+ return err;
+}
+
+error_t
+S_acpi_get_irq (struct protid *master, int bus, int dev, int func, int *irq)
+{
+ error_t err;
+
+ if (!master)
+ return EOPNOTSUPP;
+
+ err = check_permissions (master, O_READ);
+ if (err)
+ return err;
+
+ *irq = acpi_get_irq_number(bus, dev, func);
+ return err;
+}
diff --git a/acpi/acpi.h b/acpi/acpi.h
index 7c21a442..bb56ff76 100644
--- a/acpi/acpi.h
+++ b/acpi/acpi.h
@@ -29,6 +29,12 @@
#define ESCD 0xe0000U
#define RSDP_MAGIC (const unsigned char *)"RSD PTR "
#define ESCD_SIZE 0x20000U
+#define SLP_EN (0x1 << 13)
+#define SCI_EN 1
+#define SMI_CMD_OFFSET 12
+#define SMI_EN_OFFSET 16
+#define PM1A_CTL_OFFSET 28
+#define PM1B_CTL_OFFSET 32
struct rsdp_descr
{
diff --git a/acpi/main.c b/acpi/main.c
index 5b879e3f..90dc6580 100644
--- a/acpi/main.c
+++ b/acpi/main.c
@@ -26,6 +26,7 @@
#include <argp.h>
#include <hurd/netfs.h>
+#include "acpi_S.h"
#include "libnetfs/io_S.h"
#include "libnetfs/fs_S.h"
#include "libports/notify_S.h"
@@ -54,7 +55,8 @@ netfs_demuxer (mach_msg_header_t * inp, mach_msg_header_t * outp)
(routine = ports_notify_server_routine (inp)) ||
(routine = netfs_fsys_server_routine (inp)) ||
(routine = ports_interrupt_server_routine (inp)) ||
- (routine = netfs_ifsock_server_routine (inp)))
+ (routine = netfs_ifsock_server_routine (inp)) ||
+ (routine = S_acpi_server_routine (inp)))
{
(*routine) (inp, outp);
return TRUE;
diff --git a/acpi/mig-mutate.h b/acpi/mig-mutate.h
new file mode 100644
index 00000000..1ee33e5f
--- /dev/null
+++ b/acpi/mig-mutate.h
@@ -0,0 +1,28 @@
+/*
+ Copyright (C) 2017 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell, p/BSG.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Only CPP macro definitions should go in this file. */
+
+#define ACPI_IMPORTS \
+ import "../libnetfs/priv.h"; \
+
+#define ACPI_INTRAN protid_t begin_using_protid_port (acpi_t)
+#define ACPI_INTRAN_PAYLOAD protid_t begin_using_protid_payload
+#define ACPI_DESTRUCTOR end_using_protid_port (protid_t)
diff --git a/hurd/acpi.defs b/hurd/acpi.defs
new file mode 100644
index 00000000..5e9e4d90
--- /dev/null
+++ b/hurd/acpi.defs
@@ -0,0 +1,60 @@
+/* Definitions for acpi-specific calls
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+This file is part of the GNU Hurd.
+
+The GNU Hurd is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+The GNU Hurd is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the GNU Hurd; see the file COPYING. If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+subsystem acpi 41000;
+
+#include "../../hurd/hurd_types.defs"
+
+#ifdef ACPI_IMPORTS
+ACPI_IMPORTS
+#endif
+
+/* These RPCs only work on the FADT table entry */
+
+/*
+ * Enable ACPI mode of the machine
+ */
+routine acpi_enable(
+ master: acpi_t
+);
+
+/*
+ * Enter sleep state
+ *
+ * 3 = S3 (suspend)
+ * 5 = S5 (power off)
+ */
+routine acpi_sleep(
+ master: acpi_t;
+ sleep_state: int
+);
+
+/* This RPC works on any entry as it is not table specific */
+
+/*
+ * Get the irq for a particular PCI device
+ * based on its B/D/F
+ */
+routine acpi_get_irq(
+ master: acpi_t;
+ bus: int;
+ dev: int;
+ func: int;
+ out irq: int
+);
diff --git a/hurd/hurd_types.defs b/hurd/hurd_types.defs
index 88024045..5b9dd85a 100644
--- a/hurd/hurd_types.defs
+++ b/hurd/hurd_types.defs
@@ -332,6 +332,24 @@ destructor: SHUTDOWN_DESTRUCTOR
#endif
;
+/* ACPI */
+type acpi_t = mach_port_copy_send_t
+#ifdef ACPI_INTRAN
+intran: ACPI_INTRAN
+intranpayload: ACPI_INTRAN_PAYLOAD
+#else
+#ifdef HURD_DEFAULT_PAYLOAD_TO_PORT
+intranpayload: acpi_t HURD_DEFAULT_PAYLOAD_TO_PORT
+#endif
+#endif
+#ifdef ACPI_OUTTRAN
+outtran: ACPI_OUTTRAN
+#endif
+#ifdef ACPI_DESTRUCTOR
+destructor: ACPI_DESTRUCTOR
+#endif
+;
+
type proccoll_t = mach_port_copy_send_t;
type sreply_port_t = MACH_MSG_TYPE_MAKE_SEND_ONCE | polymorphic
diff --git a/hurd/hurd_types.h b/hurd/hurd_types.h
index f0521191..cdc01906 100644
--- a/hurd/hurd_types.h
+++ b/hurd/hurd_types.h
@@ -53,6 +53,7 @@ typedef mach_port_t proccoll_t;
typedef mach_port_t ctty_t;
typedef mach_port_t pci_t;
typedef mach_port_t shutdown_t;
+typedef mach_port_t acpi_t;
#include <errno.h> /* Defines `error_t'. */