Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src acpi: add character device for accessing ACPI tables
details: https://anonhg.NetBSD.org/src/rev/67e774791822
branches: trunk
changeset: 957637:67e774791822
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Dec 06 02:57:29 2020 +0000
description:
acpi: add character device for accessing ACPI tables
The /dev/acpi character device gives an aperture into physical memory
that allows only read access to known ACPI tables: RSDP, XSDT/RSDT, and
the root tables. Adapt acpidump(8) to use this interface by default,
falling back to the old /dev/mem method if it is not available or if
ACPIDUMP_USE_DEVMEM=1 is set in the environment. The user visible benefit
of this change is that "options INSECURE" is no longer required to
dump ACPI tables.
diffstat:
etc/MAKEDEV.tmpl | 6 +-
etc/etc.aarch64/MAKEDEV.conf | 3 +-
etc/etc.amd64/MAKEDEV.conf | 3 +-
etc/etc.i386/MAKEDEV.conf | 3 +-
etc/etc.ia64/MAKEDEV.conf | 3 +-
share/man/man4/acpi.4 | 8 +-
sys/conf/majors | 3 +-
sys/dev/acpi/acpi_dev.c | 220 ++++++++++++++++++++++++++++++++
sys/dev/acpi/files.acpi | 3 +-
usr.sbin/acpitools/acpidump/acpi_user.c | 61 +++++++-
usr.sbin/acpitools/acpidump/acpidump.8 | 10 +-
usr.sbin/acpitools/acpidump/acpidump.c | 10 +-
12 files changed, 304 insertions(+), 29 deletions(-)
diffs (truncated from 564 to 300 lines):
diff -r 8c9773366aad -r 67e774791822 etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl Sun Dec 06 02:26:33 2020 +0000
+++ b/etc/MAKEDEV.tmpl Sun Dec 06 02:57:29 2020 +0000
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: MAKEDEV.tmpl,v 1.221 2020/07/26 15:47:27 jdolecek Exp $
+# $NetBSD: MAKEDEV.tmpl,v 1.222 2020/12/06 02:57:29 jmcneill Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -2243,6 +2243,10 @@
mkdev ttyXMM${unit}1 c %wwanc_chr% $(($unit * 65536 + 4))
;;
+acpi)
+ mkdev acpi c %acpi_chr% 0
+ ;;
+
midevend)
%MI_DEVICES_END%
local)
diff -r 8c9773366aad -r 67e774791822 etc/etc.aarch64/MAKEDEV.conf
--- a/etc/etc.aarch64/MAKEDEV.conf Sun Dec 06 02:26:33 2020 +0000
+++ b/etc/etc.aarch64/MAKEDEV.conf Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.7 2018/12/15 01:02:58 jmcneill Exp $
+# $NetBSD: MAKEDEV.conf,v 1.8 2020/12/06 02:57:30 jmcneill Exp $
all_md)
makedev wscons fd0 fd1 wd0 wd1 wd2 wd3 sd0 sd1 sd2 sd3
@@ -20,6 +20,7 @@
makedev spiflash0
makedev bpf
makedev openfirm
+ makedev acpi
;;
ramdisk|floppy)
diff -r 8c9773366aad -r 67e774791822 etc/etc.amd64/MAKEDEV.conf
--- a/etc/etc.amd64/MAKEDEV.conf Sun Dec 06 02:26:33 2020 +0000
+++ b/etc/etc.amd64/MAKEDEV.conf Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.31 2020/08/03 04:32:13 nia Exp $
+# $NetBSD: MAKEDEV.conf,v 1.32 2020/12/06 02:57:30 jmcneill Exp $
# As of 2003-04-17, the "init" case must not create more than 890 entries.
all_md)
@@ -45,6 +45,7 @@
makedev kttcp
makedev bio
makedev xmm0
+ makedev acpi
;;
xen)
diff -r 8c9773366aad -r 67e774791822 etc/etc.i386/MAKEDEV.conf
--- a/etc/etc.i386/MAKEDEV.conf Sun Dec 06 02:26:33 2020 +0000
+++ b/etc/etc.i386/MAKEDEV.conf Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.32 2020/08/03 04:32:13 nia Exp $
+# $NetBSD: MAKEDEV.conf,v 1.33 2020/12/06 02:57:30 jmcneill Exp $
# As of 2005-03-15, the "init" case must not create more than 1024 entries.
all_md)
@@ -49,6 +49,7 @@
makedev io
makedev bio
makedev cfs
+ makedev acpi
;;
xen)
diff -r 8c9773366aad -r 67e774791822 etc/etc.ia64/MAKEDEV.conf
--- a/etc/etc.ia64/MAKEDEV.conf Sun Dec 06 02:26:33 2020 +0000
+++ b/etc/etc.ia64/MAKEDEV.conf Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: MAKEDEV.conf,v 1.4 2020/04/05 14:09:18 jdolecek Exp $
+# $NetBSD: MAKEDEV.conf,v 1.5 2020/12/06 02:57:30 jmcneill Exp $
# As of 2005-03-15, the "init" case must not create more than 1024 entries.
all_md)
@@ -43,4 +43,5 @@
makedev io
makedev bio
makedev cfs
+ makedev acpi
;;
diff -r 8c9773366aad -r 67e774791822 share/man/man4/acpi.4
--- a/share/man/man4/acpi.4 Sun Dec 06 02:26:33 2020 +0000
+++ b/share/man/man4/acpi.4 Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: acpi.4,v 1.86 2018/03/04 02:10:26 pgoyette Exp $
+.\" $NetBSD: acpi.4,v 1.87 2020/12/06 02:57:30 jmcneill Exp $
.\"
.\" Copyright (c) 2002, 2004, 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -24,7 +24,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd March 4, 2018
+.Dd December 5, 2020
.Dt ACPI 4
.Os
.Sh NAME
@@ -491,6 +491,10 @@
.Ic hw.acpi.debug.object
is set to 1, the message stored to the debug object
is printed every time the method is called by the interpreter.
+.Sh FILES
+.Bl -tag -width /dev/acpi
+.It Pa /dev/acpi
+.El
.Sh SEE ALSO
.Xr ioapic 4 ,
.Xr acpidump 8 ,
diff -r 8c9773366aad -r 67e774791822 sys/conf/majors
--- a/sys/conf/majors Sun Dec 06 02:26:33 2020 +0000
+++ b/sys/conf/majors Sun Dec 06 02:57:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.96 2020/08/28 14:58:25 riastradh Exp $
+# $NetBSD: majors,v 1.97 2020/12/06 02:57:30 jmcneill Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -90,3 +90,4 @@
device-major vio9p char 356 vio9p
device-major fault char 357 fault
device-major wwanc char 358 wwanc
+device-major acpi char 359 acpi
diff -r 8c9773366aad -r 67e774791822 sys/dev/acpi/acpi_dev.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_dev.c Sun Dec 06 02:57:29 2020 +0000
@@ -0,0 +1,220 @@
+/* $NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/mman.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#define _COMPONENT ACPI_BUS_COMPONENT
+ACPI_MODULE_NAME ("acpi_dev")
+
+static dev_type_read(acpi_read);
+
+const struct cdevsw acpi_cdevsw = {
+ .d_open = nullopen,
+ .d_close = nullclose,
+ .d_read = acpi_read,
+ .d_write = nowrite,
+ .d_ioctl = noioctl,
+ .d_stop = nostop,
+ .d_tty = notty,
+ .d_poll = nopoll,
+ .d_mmap = nommap,
+ .d_kqfilter = nokqfilter,
+ .d_discard = nodiscard,
+ .d_flag = D_OTHER | D_MPSAFE,
+};
+
+/*
+ * acpi_find_table_rsdp --
+ *
+ * Returns true if the RSDP table is found and overlaps the specified
+ * physical address. The table's physical start address and length
+ * are placed in 'paddr' and 'plen' when found.
+ *
+ */
+static bool
+acpi_find_table_rsdp(ACPI_PHYSICAL_ADDRESS pa,
+ ACPI_PHYSICAL_ADDRESS *paddr, uint32_t *plen)
+{
+ ACPI_PHYSICAL_ADDRESS table_pa;
+
+ table_pa = AcpiOsGetRootPointer();
+ if (table_pa == 0) {
+ return false;
+ }
+ if (pa >= table_pa && pa < table_pa + sizeof(ACPI_TABLE_RSDP)) {
+ *paddr = table_pa;
+ *plen = sizeof(ACPI_TABLE_RSDP);
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * acpi_find_table_sdt --
+ *
+ * Returns true if the XSDT/RSDT table is found and overlaps the
+ * specified physical address. The table's physical start address
+ * and length are placed in 'paddr' and 'plen' when found.
+ *
+ */
+static bool
+acpi_find_table_sdt(ACPI_PHYSICAL_ADDRESS pa,
+ ACPI_PHYSICAL_ADDRESS *paddr, uint32_t *plen)
+{
+ ACPI_PHYSICAL_ADDRESS table_pa;
+ ACPI_TABLE_RSDP *rsdp;
+ ACPI_TABLE_HEADER *thdr;
+ uint32_t table_len;
+
+ table_pa = AcpiOsGetRootPointer();
+ KASSERT(table_pa != 0);
+
+ /*
+ * Find the XSDT/RSDT using the RSDP.
+ */
+ rsdp = AcpiOsMapMemory(table_pa, sizeof(ACPI_TABLE_RSDP));
+ if (rsdp == NULL) {
+ return false;
+ }
+ if (rsdp->Revision > 1 && rsdp->XsdtPhysicalAddress) {
+ table_pa = rsdp->XsdtPhysicalAddress;
+ } else {
+ table_pa = rsdp->RsdtPhysicalAddress;
+ }
+ AcpiOsUnmapMemory(rsdp, sizeof(ACPI_TABLE_RSDP));
+ if (table_pa == 0) {
+ return false;
+ }
+
+ /*
+ * Map the XSDT/RSDT and check access.
+ */
+ thdr = AcpiOsMapMemory(table_pa, sizeof(ACPI_TABLE_HEADER));
+ if (thdr == NULL) {
+ return false;
+ }
+ table_len = thdr->Length;
+ AcpiOsUnmapMemory(thdr, sizeof(ACPI_TABLE_HEADER));
+ if (pa >= table_pa && pa < table_pa + table_len) {
+ *paddr = table_pa;
+ *plen = table_len;
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * acpi_find_table --
+ *
+ * Find an ACPI table that overlaps the specified physical address.
+ * Returns true if the table is found and places the table start
+ * address into 'paddr' and the length into 'plen'.
+ *
+ */
+static bool
+acpi_find_table(ACPI_PHYSICAL_ADDRESS pa,
+ ACPI_PHYSICAL_ADDRESS *paddr, uint32_t *plen)
+{
+ ACPI_TABLE_DESC *tdesc;
+ bool found_table;
+ uint32_t i;
+
+ /* Check for RSDP access. */
+ if (acpi_find_table_rsdp(pa, paddr, plen)) {
+ return true;
+ }
+
+ /* Check for XSDT/RSDT access. */
+ if (acpi_find_table_sdt(pa, paddr, plen)) {
+ return true;
+ }
+
Home |
Main Index |
Thread Index |
Old Index