[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH libacpica] Allow read/write to pci config
From: |
Damien Zammit |
Subject: |
[PATCH libacpica] Allow read/write to pci config |
Date: |
Sun, 25 Jun 2023 01:36:34 +0000 |
This allows hurd's acpi translator to read/write pci config.
Note that hurd needs to be changed to link acpi translator
with libpciaccess once this patch is merged.
Also, the boot order needs to be pci-arbiter then acpi.
TESTED: on qemu with a rump patch to enable acpi it boots via rumpdisk.
On a T500 laptop acpi crashes at boot.
---
debian/patches/acgnu.diff | 13 +++---
debian/patches/acpi-init-files.diff | 66 +++++++++++++++++++++++++++--
debian/patches/add-makefile.diff | 4 +-
3 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/debian/patches/acgnu.diff b/debian/patches/acgnu.diff
index fc59992..6fdb440 100644
--- a/debian/patches/acgnu.diff
+++ b/debian/patches/acgnu.diff
@@ -163,7 +163,7 @@ Add acgnu.h and acgnuex.h
+#endif /* __ACGNU_H__ */
--- /dev/null
+++ b/include/acpi/platform/acgnuex.h
-@@ -0,0 +1,256 @@
+@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
+
+#ifndef __ACGNUEX_H__
@@ -181,6 +181,8 @@ Add acgnu.h and acgnuex.h
+acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void);
+acpi_status acpi_os_terminate(void);
+void acpi_os_printf(const char *format, ...);
++struct pci_device;
++struct pci_device *lookup_pci_dev(struct acpi_pci_id *pci_id);
+
+static inline void *acpi_os_allocate(acpi_size size)
+{
@@ -232,6 +234,7 @@ Add acgnu.h and acgnuex.h
+#include <stdarg.h>
+#include <limits.h>
+#include <hurd.h>
++#include <pciaccess.h>
+
+#define ACPI_MAX_TABLES 128
+
@@ -405,16 +408,16 @@ Add acgnu.h and acgnuex.h
+acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
+ u64 *value, u32 width)
+{
-+ acpi_os_printf("ACPI: Tried to read pci config\n");
-+ return 1;
++ pci_device_cfg_read(lookup_pci_dev(pci_id), (void *)value, reg, width,
NULL);
++ return 0;
+}
+
+static inline acpi_status
+acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
+ u64 value, u32 width)
+{
-+ acpi_os_printf("ACPI: Tried to write pci config\n");
-+ return 1;
++ pci_device_cfg_write(lookup_pci_dev(pci_id), (const void *)&value, reg,
width, NULL);
++ return 0;
+}
+
+#endif /* __KERNEL__ */
diff --git a/debian/patches/acpi-init-files.diff
b/debian/patches/acpi-init-files.diff
index b83eafd..2fead2b 100644
--- a/debian/patches/acpi-init-files.diff
+++ b/debian/patches/acpi-init-files.diff
@@ -1,6 +1,6 @@
--- /dev/null
+++ b/acpi_init.c
-@@ -0,0 +1,510 @@
+@@ -0,0 +1,570 @@
+// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
+#include <acpi/acpi.h>
+
@@ -24,14 +24,22 @@
+
+#include <device/device.h>
+#include <hurd.h>
++#include <pciaccess.h>
+
+#define ACPI_MAX_TABLES 128
+
++#define PCI_CFG1_START 0xcf8
++#define PCI_CFG1_END 0xcff
++
+extern acpi_status acpi_hw_legacy_sleep(u8 sleep_state);
+
+// Lets keep the ACPI tables in this module
+static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES];
+
++#define NUMDEVS 32
++static struct pci_device *pci_devices[NUMDEVS];
++static int numdevs = -1;
++
+struct slots {
+ uint8_t bus;
+ uint16_t dev;
@@ -40,6 +48,43 @@
+ struct slots *next;
+};
+
++static void
++pci_init(void)
++{
++ int i = 0;
++ struct pci_device_iterator *dev_iter;
++ struct pci_device *pci_dev;
++
++ pci_system_init ();
++
++ dev_iter = pci_slot_match_iterator_create (NULL);
++ while (((pci_dev = pci_device_next (dev_iter)) != NULL)
++ && (i < NUMDEVS))
++ {
++ pci_device_probe(pci_dev);
++ pci_devices[i++] = pci_dev;
++ }
++ numdevs = i;
++}
++
++struct pci_device *
++lookup_pci_dev(struct acpi_pci_id *pci_id)
++{
++ int i;
++
++ for (i = 0; i < numdevs; i++)
++ {
++ if ((pci_devices[i]->bus == pci_id->bus)
++ && (pci_devices[i]->dev == pci_id->device)
++ && (pci_devices[i]->func == pci_id->function))
++ {
++ return pci_devices[i];
++ }
++ }
++ acpi_os_printf("Can't find pci dev %d:%02x.%d\n", pci_id->bus,
pci_id->device, pci_id->function);
++ return NULL;
++}
++
+void
+acpi_ds_dump_method_stack(acpi_status status, ...)
+// struct acpi_walk_state *walk_state, union acpi_parse_object *op)
@@ -224,11 +269,26 @@
+acpi_status
+acpi_os_initialize(void)
+{
-+ if (ioperm(0, 0x10000, 1))
++ /* Avoid giving ioperm to the PCI cfg registers
++ * since GNU/Hurd controls these
++ */
++
++ /* 0-0xcf7 */
++ if (ioperm(0, PCI_CFG1_START, 1))
+ {
-+ acpi_os_printf("EPERM on ioperm\n");
++ acpi_os_printf("EPERM on ioperm 1\n");
+ return AE_ERROR;
+ }
++
++ /* 0xd00-0xffff */
++ if (ioperm(PCI_CFG1_END+1, 0x10000 - (PCI_CFG1_END+1), 1))
++ {
++ acpi_os_printf("EPERM on ioperm 2\n");
++ return AE_ERROR;
++ }
++
++ pci_init();
++
+ return AE_OK;
+}
+
diff --git a/debian/patches/add-makefile.diff b/debian/patches/add-makefile.diff
index da2edc3..a78d8d0 100644
--- a/debian/patches/add-makefile.diff
+++ b/debian/patches/add-makefile.diff
@@ -1,6 +1,6 @@
--- /dev/null
+++ b/Makefile
-@@ -0,0 +1,216 @@
+@@ -0,0 +1,218 @@
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This is free software; you can redistribute it and/or modify
@@ -37,6 +37,8 @@
+PREFIX ?= /usr/local
+libdir ?= $(PREFIX)/lib
+
++LDLIBS = -lpciaccess
++
+SRCS = global_state.c \
+ acpi_init.c \
+ $(BASE)/dsargs.c \
--
2.40.1
- [PATCH libacpica] Allow read/write to pci config,
Damien Zammit <=