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
This commit is contained in:
Nate Lawson 2003-04-29 18:50:34 +00:00
parent 24b3046aac
commit 51773ddf47
8 changed files with 144 additions and 26 deletions

View File

@ -31,6 +31,7 @@
#include <bootstrap.h>
#include "acfreebsd.h"
#define ACPI_SYSTEM_XFACE
#include "actypes.h"
#include "actbl.h"

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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

View File

@ -10,29 +10,28 @@ KMOD= acpi
# ACPI CA sources
CFLAGS+= -I${.CURDIR}/../../contrib/dev/acpica
SRCS+= dsfield.c dsmethod.c dsmthdat.c dsobject.c dsopcode.c
SRCS+= dsutils.c dswexec.c dswload.c dswscope.c dswstate.c
SRCS+= evevent.c evmisc.c evregion.c evrgnini.c evsci.c
SRCS+= evxface.c evxfevnt.c evxfregn.c
SRCS+= exconfig.c exconvrt.c excreate.c exdump.c exfield.c
SRCS+= exfldio.c exmisc.c exmutex.c exnames.c exoparg1.c
SRCS+= exoparg2.c exoparg3.c exoparg6.c exprep.c exregion.c
SRCS+= exresnte.c exresolv.c exresop.c exstore.c exstoren.c
SRCS+= exstorob.c exsystem.c exutils.c
SRCS+= dsfield.c dsinit.c dsmethod.c dsmthdat.c
SRCS+= dsobject.c dsopcode.c dsutils.c dswexec.c dswload.c
SRCS+= dswscope.c dswstate.c evevent.c evgpe.c evgpeblk.c
SRCS+= evmisc.c evregion.c evrgnini.c evsci.c evxface.c
SRCS+= evxfevnt.c evxfregn.c exconfig.c exconvrt.c excreate.c
SRCS+= exdump.c exfield.c exfldio.c exmisc.c exmutex.c
SRCS+= exnames.c exoparg1.c exoparg2.c exoparg3.c exoparg6.c
SRCS+= exprep.c exregion.c exresnte.c exresolv.c exresop.c
SRCS+= exstore.c exstoren.c exstorob.c exsystem.c exutils.c
SRCS+= hwacpi.c hwgpe.c hwregs.c hwsleep.c hwtimer.c
SRCS+= nsaccess.c nsalloc.c nsdump.c nseval.c nsinit.c
SRCS+= nsload.c nsnames.c nsobject.c nssearch.c nsutils.c
SRCS+= nswalk.c nsxfeval.c nsxfname.c nsxfobj.c
SRCS+= psargs.c psfind.c psopcode.c psparse.c psscope.c
SRCS+= nsload.c nsnames.c nsobject.c nsparse.c nssearch.c
SRCS+= nsutils.c nswalk.c nsxfeval.c nsxfname.c nsxfobj.c
SRCS+= psargs.c psopcode.c psparse.c psscope.c
SRCS+= pstree.c psutils.c pswalk.c psxface.c
SRCS+= rsaddr.c rscalc.c rscreate.c rsdump.c rsio.c
SRCS+= rsirq.c rslist.c rsmemory.c rsmisc.c rsutils.c
SRCS+= rsxface.c
SRCS+= tbconvrt.c tbget.c tbgetall.c tbinstal.c tbrsdt.c
SRCS+= tbutils.c tbxface.c tbxfroot.c
SRCS+= utalloc.c utclib.c utcopy.c utdebug.c utdelete.c
SRCS+= uteval.c utglobal.c utinit.c utmath.c utmisc.c
SRCS+= utobject.c utxface.c
SRCS+= rsxface.c tbconvrt.c tbget.c tbgetall.c tbinstal.c
SRCS+= tbrsdt.c tbutils.c tbxface.c tbxfroot.c utalloc.c
SRCS+= utclib.c utcopy.c utdebug.c utdelete.c uteval.c
SRCS+= utglobal.c utinit.c utmath.c utmisc.c utobject.c
SRCS+= utxface.c
# OSD layer
SRCS+= acpi.c acpi_acad.c acpi_battery.c acpi_button.c acpi_cmbat.c acpi_cpu.c

View File

@ -38,8 +38,7 @@
#include <dev/acpica/acpiio.h>
#include <contrib/dev/acpica/acfreebsd.h>
#include <contrib/dev/acpica/actypes.h>
#include <contrib/dev/acpica/acpi.h>
#define ACPIDEV "/dev/acpi"