summaryrefslogtreecommitdiffstats
path: root/sys/dev/acpica
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2003-04-29 18:50:34 +0000
committernjl <njl@FreeBSD.org>2003-04-29 18:50:34 +0000
commit32b2682952c56d1802d387c87c361a5b0e28ae05 (patch)
tree65beb1553eb37160f7d2c71eddc0083cb96d1c32 /sys/dev/acpica
parentac2712d2c827e8b00cf0d1ec14e773ee4ff49eee (diff)
downloadFreeBSD-src-32b2682952c56d1802d387c87c361a5b0e28ae05.zip
FreeBSD-src-32b2682952c56d1802d387c87c361a5b0e28ae05.tar.gz
Support functions for the new ACPI import.
* AcpiOsDerivePciId(): finds a bus number, given the slot/func and the acpi parse tree. * AcpiOsPredefinedOverride(): use the sysctl hw.acpi.os_name to override the value for _OS. Ideas from: takawata, jhb Reviewed by: takawata, marcel Tested on: i386, ia64
Diffstat (limited to 'sys/dev/acpica')
-rw-r--r--sys/dev/acpica/Osd/OsdDebug.c8
-rw-r--r--sys/dev/acpica/Osd/OsdHardware.c96
-rw-r--r--sys/dev/acpica/Osd/OsdStream.c4
-rw-r--r--sys/dev/acpica/Osd/OsdTable.c20
-rw-r--r--sys/dev/acpica/acpivar.h3
5 files changed, 125 insertions, 6 deletions
diff --git a/sys/dev/acpica/Osd/OsdDebug.c b/sys/dev/acpica/Osd/OsdDebug.c
index 1651d25..3df9e45 100644
--- a/sys/dev/acpica/Osd/OsdDebug.c
+++ b/sys/dev/acpica/Osd/OsdDebug.c
@@ -50,7 +50,7 @@
#include <dev/acpica/acpivar.h>
UINT32
-AcpiOsGetLine(NATIVE_CHAR *Buffer)
+AcpiOsGetLine(char *Buffer)
{
#ifdef DDB
char *cp;
@@ -67,7 +67,7 @@ AcpiOsGetLine(NATIVE_CHAR *Buffer)
}
void
-AcpiOsDbgAssert(void *FailedAssertion, void *FileName, UINT32 LineNumber, NATIVE_CHAR *Message)
+AcpiOsDbgAssert(void *FailedAssertion, void *FileName, UINT32 LineNumber, char *Message)
{
printf("ACPI: %s:%d - %s\n", (char *)FileName, LineNumber, Message);
printf("ACPI: assertion %s\n", (char *)FailedAssertion);
@@ -79,7 +79,7 @@ AcpiOsSignal (
void *Info)
{
ACPI_SIGNAL_FATAL_INFO *fatal;
- NATIVE_CHAR *message;
+ char *message;
switch(Function) {
case ACPI_SIGNAL_FATAL:
@@ -90,7 +90,7 @@ AcpiOsSignal (
break;
case ACPI_SIGNAL_BREAKPOINT:
- message = (NATIVE_CHAR *)Info;
+ message = (char *)Info;
Debugger(message);
break;
diff --git a/sys/dev/acpica/Osd/OsdHardware.c b/sys/dev/acpica/Osd/OsdHardware.c
index 5897157..9eeae49 100644
--- a/sys/dev/acpica/Osd/OsdHardware.c
+++ b/sys/dev/acpica/Osd/OsdHardware.c
@@ -36,6 +36,7 @@
#include <machine/bus_pio.h>
#include <machine/bus.h>
#include <machine/pci_cfgreg.h>
+#include <dev/pci/pcireg.h>
/*
* ACPICA's rather gung-ho approach to hardware resource ownership is a little
@@ -155,3 +156,98 @@ AcpiOsWritePciConfiguration (
return(AE_OK);
}
+
+/* XXX should use acpivar.h but too many include dependencies */
+extern ACPI_STATUS acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int
+ *number);
+
+/*
+ * Depth-first recursive case for finding the bus, given the slot/function.
+ */
+static int
+acpi_bus_number(ACPI_HANDLE root, ACPI_HANDLE curr, ACPI_PCI_ID *PciId)
+{
+ ACPI_HANDLE parent;
+ ACPI_OBJECT_TYPE type;
+ UINT32 adr;
+ int bus, slot, func, class, subclass, header;
+
+ /* Try to get the _BBN object of the root, otherwise assume it is 0 */
+ bus = 0;
+ if (root == curr) {
+ if (ACPI_FAILURE(acpi_EvaluateInteger(root, "_BBN", &bus)))
+ printf("acpi_bus_number: root bus has no _BBN, assuming 0\n");
+ return (bus);
+ }
+ if (ACPI_FAILURE(AcpiGetParent(curr, &parent)))
+ return (bus);
+
+ /* First, recurse up the tree until we find the host bus */
+ bus = acpi_bus_number(root, parent, PciId);
+
+ /* Validate parent bus device type */
+ if (ACPI_FAILURE(AcpiGetType(parent, &type)) || type != ACPI_TYPE_DEVICE) {
+ printf("acpi_bus_number: not a device, type %d\n", type);
+ return (bus);
+ }
+ /* Get the parent's slot and function */
+ if (ACPI_FAILURE(acpi_EvaluateInteger(parent, "_ADR", &adr))) {
+ printf("acpi_bus_number: can't get _ADR\n");
+ return (bus);
+ }
+ slot = ACPI_HIWORD(adr);
+ func = ACPI_LOWORD(adr);
+
+ /* Is this a PCI-PCI or Cardbus-PCI bridge? */
+ class = pci_cfgregread(bus, slot, func, PCIR_CLASS, 1);
+ if (class != PCIC_BRIDGE)
+ return (bus);
+ subclass = pci_cfgregread(bus, slot, func, PCIR_SUBCLASS, 1);
+ /* Find the header type, masking off the multifunction bit */
+ header = pci_cfgregread(bus, slot, func, PCIR_HEADERTYPE, 1) & 0x7f;
+ if (header == 1 && subclass == PCIS_BRIDGE_PCI)
+ bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_1, 1);
+ if (header == 2 && subclass == PCIS_BRIDGE_CARDBUS)
+ bus = pci_cfgregread(bus, slot, func, PCIR_SECBUS_2, 1);
+ return (bus);
+}
+
+/*
+ * Find the bus number for a device
+ *
+ * rhandle: handle for the root bus
+ * chandle: handle for the device
+ * PciId: pointer to device slot and function, we fill out bus
+ */
+void
+AcpiOsDerivePciId (
+ ACPI_HANDLE rhandle,
+ ACPI_HANDLE chandle,
+ ACPI_PCI_ID **PciId)
+{
+ ACPI_HANDLE parent;
+ int bus;
+
+ if (pci_cfgregopen() == 0)
+ panic("AcpiOsDerivePciId unable to initialize pci bus");
+
+ /* Try to read _BBN for bus number if we're at the root */
+ bus = 0;
+ if (rhandle == chandle) {
+ if (ACPI_FAILURE(acpi_EvaluateInteger(rhandle, "_BBN", &bus)))
+ printf("AcpiOsDerivePciId: root bus has no _BBN, assuming 0\n");
+ }
+ /*
+ * Get the parent handle and call the recursive case. It is not
+ * clear why we seem to be getting a chandle that points to a child
+ * of the desired slot/function but passing in the parent handle
+ * here works.
+ */
+ if (ACPI_SUCCESS(AcpiGetParent(chandle, &parent)))
+ bus = acpi_bus_number(rhandle, parent, *PciId);
+ (*PciId)->Bus = bus;
+ if (bootverbose) {
+ printf("AcpiOsDerivePciId: bus %d dev %d func %d\n",
+ (*PciId)->Bus, (*PciId)->Device, (*PciId)->Function);
+ }
+}
diff --git a/sys/dev/acpica/Osd/OsdStream.c b/sys/dev/acpica/Osd/OsdStream.c
index 31778d6..7c9acde 100644
--- a/sys/dev/acpica/Osd/OsdStream.c
+++ b/sys/dev/acpica/Osd/OsdStream.c
@@ -34,7 +34,7 @@
#include "acpi.h"
void
-AcpiOsPrintf (const NATIVE_CHAR *Format, ...)
+AcpiOsPrintf (const char *Format, ...)
{
va_list ap;
@@ -44,7 +44,7 @@ AcpiOsPrintf (const NATIVE_CHAR *Format, ...)
}
void
-AcpiOsVprintf (const NATIVE_CHAR *Format, va_list Args)
+AcpiOsVprintf (const char *Format, va_list Args)
{
vprintf(Format, Args);
}
diff --git a/sys/dev/acpica/Osd/OsdTable.c b/sys/dev/acpica/Osd/OsdTable.c
index 58c01cd..f24c5ea 100644
--- a/sys/dev/acpica/Osd/OsdTable.c
+++ b/sys/dev/acpica/Osd/OsdTable.c
@@ -38,6 +38,26 @@
#undef _COMPONENT
#define _COMPONENT ACPI_TABLES
+static char acpi_os_name[128];
+
+ACPI_STATUS
+AcpiOsPredefinedOverride (
+ const ACPI_PREDEFINED_NAMES *InitVal,
+ ACPI_STRING *NewVal)
+{
+ if (InitVal == NULL || NewVal == NULL)
+ return(AE_BAD_PARAMETER);
+
+ *NewVal = NULL;
+ if (strncmp(InitVal->Name, "_OS_", 4) == 0 &&
+ getenv_string("hw.acpi.os_name", acpi_os_name, sizeof(acpi_os_name))) {
+ printf("ACPI: Overriding _OS definition with \"%s\"\n", acpi_os_name);
+ *NewVal = acpi_os_name;
+ }
+
+ return(AE_OK);
+}
+
ACPI_STATUS
AcpiOsTableOverride (
ACPI_TABLE_HEADER *ExistingTable,
diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h
index e31862a..12a5a68 100644
--- a/sys/dev/acpica/acpivar.h
+++ b/sys/dev/acpica/acpivar.h
@@ -141,6 +141,8 @@ extern struct mtx acpi_mutex;
#define ACPI_INTR_APIC 1
#define ACPI_INTR_SAPIC 2
+/* XXX this is no longer referenced anywhere, remove? */
+#if 0
/*
* This is a cheap and nasty way to get around the horrid counted list
* argument format that AcpiEvalateObject uses.
@@ -168,6 +170,7 @@ acpi_AllocObjectList(int nobj)
l->count = nobj;
return(l);
}
+#endif /* unused */
/*
* Note that the low ivar values are reserved to provide
OpenPOWER on IntegriCloud