osl.c revision 450d696485d078017a0c7d3eef7384ee79c9f467
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* ACPI CA OSL for Solaris x86
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/pci_cfgspace.h>
extern int (*psm_translate_irq)(dev_info_t *, int);
#define D2A_INITLEN 20
static int d2a_len = 0;
static int d2a_valid = 0;
static int acpi_has_broken_bbn = -1;
/* local functions */
static int CompressEisaID(char *np);
static void create_d2a_map(void);
static int acpica_query_bbn_problem(void);
/*
* Event queue vars
*/
int acpica_eventq_thread_count = 1;
int acpica_eventq_init = 0;
/*
* Note, if you change this path, you need to update
* /boot/grub/filelist.ramdisk and pkg SUNWckr/prototype_i386
*/
static char *acpi_table_path = "/boot/acpi/tables/";
/* non-zero while create_d2a_map() is working */
static int creating_d2a_map = 0;
/*
*
*/
static void
{
/*
* destroy event queues
*/
if (eventq_gpe)
if (eventq_high)
if (eventq_low)
if (eventq_medium)
}
/*
*
*/
static ACPI_STATUS
{
/*
* Initialize event queues
* FUTUREWORK: taskq priorities currently the same
*/
#ifdef DEBUG
#endif
return (AE_ERROR);
}
acpica_eventq_init = 1;
return (AE_OK);
}
/*
*
*/
AcpiOsInitialize(void)
{
return (AE_OK);
}
/*
*
*/
AcpiOsTerminate(void)
{
return (AE_OK);
}
{
}
/*ARGSUSED*/
{
*NewVal = 0;
return (AE_OK);
}
static void
{
/*LINTED*/
/* copy the string */;
*dest = '\0';
}
{
char signature[5];
char oemid[7];
char oemtableid[9];
int count;
char acpi_table_loc[128];
#ifdef DEBUG
" OEM TABLE ID [%s] OEM rev %x",
#endif
/* File name format is "signature_oemid_oemtableid.dat" */
*NewTable = 0;
return (AE_OK);
} else {
if (count >= MAX_DAT_FILE_SIZE) {
*NewTable = 0;
} else {
}
}
return (AE_OK);
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
{
return (AE_OK);
}
{
do {
/* going to block */
if (timeout_ticks > 0) {
delay(1);
if (Timeout != 0xffff)
continue;
} else
break;
} else {
p_count++;
if (--Units == 0)
return (AE_OK); /* normal exit */
}
} while (timeout_ticks > 0);
while (p_count > 0)
return (AE_TIME);
}
{
while (Units > 0) {
Units -= 1;
}
return (AE_OK);
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
void
{
}
{
return (0);
}
void
{
}
void *
{
return ((void *)tmp_ptr);
}
void
AcpiOsFree(void *Memory)
{
tmp_ptr -= 1;
}
{
/* FUTUREWORK: test PhysicalAddress for > 32 bits */
return (AE_OK);
}
void
{
}
/*ARGSUSED*/
{
/* UNIMPLEMENTED: not invoked by ACPI CA code */
return (AE_OK);
}
void *acpi_isr_context;
acpi_wrapper_isr(char *arg)
{
int status;
if (status == ACPI_INTERRUPT_HANDLED) {
return (DDI_INTR_CLAIMED);
} else {
return (DDI_INTR_UNCLAIMED);
}
}
int intr_hooked = 0;
void *Context)
{
int retval;
int sci_vect;
/*
*/
return (AE_ERROR);
}
#ifdef DEBUG
#endif
if (retval) {
intr_hooked = 1;
return (AE_OK);
} else {
return (AE_BAD_PARAMETER);
}
}
{
#ifdef DEBUG
#endif
if (intr_hooked) {
intr_hooked = 0;
}
return (AE_OK);
}
AcpiOsGetThreadId(void)
{
/* FUTUREWORK: give back a real thread id */
thread_id = ddi_get_kt_did();
}
/*
*
*/
void *Context)
{
ddi_taskq_t *q;
if (!acpica_eventq_init) {
/*
* Create taskqs for event handling
*/
if (init_event_queues() != AE_OK)
return (AE_ERROR);
}
switch (Priority) {
case OSD_PRIORITY_GPE:
q = eventq_gpe;
break;
case OSD_PRIORITY_HIGH:
q = eventq_high;
break;
case OSD_PRIORITY_MED:
q = eventq_medium;
break;
case OSD_PRIORITY_LO:
q = eventq_low;
break;
default:
q = NULL;
break;
}
if (q == NULL) {
#ifdef DEBUG
#endif
return (AE_ERROR);
}
DDI_FAILURE) {
#ifdef DEBUG
#endif
return (AE_ERROR);
}
return (AE_OK);
}
void
{
/*
* During kernel startup, before the first
* tick interrupt has taken place, we can't call
* delay. So we busy wait if lbolt == 0.
*/
if (ddi_get_lbolt() == 0)
else
}
void
{
}
/*
* Implementation of "Windows 2001" compatible I/O permission map
*
*/
#define OSL_IO_NONE (0)
#define OSL_IO_READ (1<<0)
#define OSL_IO_DEFAULT OSL_IO_RW
static struct io_perm {
} osl_io_perm[] = {
};
/*
*
*/
static struct io_perm *
{
struct io_perm *p;
p = osl_io_perm;
while (p != NULL) {
break;
}
return (p);
}
/*
*
*/
{
struct io_perm *p;
/* verify permission */
p = osl_io_find_perm(Address);
if (p && (p->perm & OSL_IO_READ) == 0) {
*Value = 0xffffffff;
return (AE_ERROR);
}
switch (Width) {
case 8:
break;
case 16:
break;
case 32:
break;
default:
return (AE_BAD_PARAMETER);
}
return (AE_OK);
}
{
struct io_perm *p;
/* verify permission */
p = osl_io_find_perm(Address);
if (p && (p->perm & OSL_IO_WRITE) == 0) {
return (AE_ERROR);
}
switch (Width) {
case 8:
break;
case 16:
break;
case 32:
break;
default:
return (AE_BAD_PARAMETER);
}
return (AE_OK);
}
/*
*
*/
static void
{
switch (maplen) {
case 1:
break;
case 2:
break;
case 4:
break;
default:
Width);
break;
}
}
{
return (AE_OK);
}
{
return (AE_OK);
}
{
switch (Width) {
case 8:
break;
case 16:
break;
case 32:
break;
case 64:
default:
return (AE_BAD_PARAMETER);
}
return (AE_OK);
}
/*
*
*/
int acpica_write_pci_config_ok = 1;
{
if (!acpica_write_pci_config_ok) {
return (AE_OK);
}
switch (Width) {
case 8:
break;
case 16:
break;
case 32:
break;
case 64:
default:
return (AE_BAD_PARAMETER);
}
return (AE_OK);
}
/*
* This took me a while to figure out, and thus warrants
* detailed explanation lest I forget it.
*
* Called with ACPI_HANDLEs for both a PCI Config Space
* OpRegion and (what ACPI CA thinks is) the PCI device
* to which this ConfigSpace OpRegion belongs. Problems
* with this are:
* - ACPI CA currently only thinks "PNP0A03" is a PCI bridge;
* and doesn't recognize "PNP0A08" which is a PCI Express bridge
* (in which case the root handle may be higher in the ACPI
* namespace than it should, including a non-PCI device)
*
* - ACPI CA depends on a valid _BBN object being present
* and this is known to not always be true
*
* Default values for bus, segment, device and function are
* all 0 when ACPI CA can't figure them out.
*
* This is further complicated by BIOSes that implement
* _BBN() by reading PCI config space - it means that we'll
* recurse when we attempt to create the devinfo-to-ACPI
* map. If Derive is called during create_d2a_map, we simply
* can't help and return. It seems this ends up doing the right
* thing, at least on the LX50 which gets base bus numbers other
* than 0 from PCI Config space on bus 0.
*
*/
void
ACPI_PCI_ID **PciId)
{
int devfn;
/* See above - avoid recursing during create_d2a_map */
/* doesn't matter if multi-threaded here, either */
if (creating_d2a_map)
return;
/*
* We start with the parent node of the OpRegion
* and ascend, looking for a matching dip2acpi
* node; once located, we use the bus from the d2a
* method on the ACPI node.
* If we encounter any kind of failure, we just
* return, possibly after updating the bus value
* This is probably always better than nothing.
*/
return;
}
break;
}
break;
}
}
{
/* Always says yes; all mapped memory assumed readable */
return (1);
}
{
/* Always says yes; all mapped memory assumed writable */
return (1);
}
AcpiOsGetTimer(void)
{
/* New ACPI 3.0 Timer() support */
/* FUTUREWORK: need to integrate with PSM? */
return (0);
}
{
/* FUTUREWORK: debugger support */
return (AE_OK);
}
AcpiOsPrintf(const char *Format, ...)
{
int buflen;
char *buf;
/*
* Try to be nice and emit the message via strlog().
* Unfortunately, vstrlog() doesn't define the format
* string as const char, so we allocate a local buffer
* use vsnprintf().
*
* If we fail to allocate a string buffer, we resort
* to printf().
*/
return;
}
}
void
{
}
void
AcpiOsRedirectOutput(void *Destination)
{
/* FUTUREWORK: debugger support */
#ifdef DEBUG
#endif
}
AcpiOsGetLine(char *Buffer)
{
/* FUTUREWORK: debugger support */
return (0);
}
/*
* Device tree binding
*/
static int
{
/* initialize static flag by querying ACPI namespace for bug */
if (acpi_has_broken_bbn == -1)
if (acpi_has_broken_bbn) {
/* Decree _BBN == n from PCI<n> */
!= AE_OK) {
return (AE_ERROR);
}
return (AE_OK);
}
} else {
AE_OK) {
return (AE_OK);
}
} else if (busno == 0) {
return (AE_OK);
}
}
}
}
return (AE_ERROR);
}
/*
* Look for ACPI problem where _BBN is zero for multiple PCI buses
* This is a clear ACPI bug, but we have a workaround in acpica_find_pcibus()
* below if it exists.
*/
static int
acpica_query_bbn_problem(void)
{
int zerobbncnt;
zerobbncnt = 0;
if (bbn == 0) {
/*
* If we find more than one bus with a 0 _BBN
* we have the problem that BigBear's BIOS shows
*/
if (++zerobbncnt > 1)
return (1);
}
}
}
return (0);
}
static const char hextab[] = "0123456789ABCDEF";
static int
hexdig(int c)
{
/*
* Get hex digit:
*
* Returns the 4-bit hex digit named by the input character. Returns
* zero if the input character is not valid hex!
*/
int x = ((c < 'a') || (c > 'z')) ? c : (c - ' ');
int j = sizeof (hextab);
while (--j && (x != hextab[j]));
return (j);
}
static int
CompressEisaID(char *np)
{
/*
* Compress an EISA device name:
*
* This routine converts a 7-byte ASCII device name into the 4-byte
* compressed form used by EISA (50 bytes of ROM to save 1 byte of
* NV-RAM!)
*/
}
int
{
ACPI_TYPE_INTEGER)) == AE_OK)
return (status);
}
static int
{
AcpiOsFree(rv);
return (AE_OK);
char *stringData;
/* Convert the string into an EISA ID */
AcpiOsFree(rv);
return (AE_ERROR);
}
/*
* If the string is an EisaID, it must be 7
* characters; if it's an ACPI ID, it will be 8
* (and we don't care about ACPI ids here).
*/
AcpiOsFree(rv);
return (AE_ERROR);
}
AcpiOsFree(rv);
return (AE_OK);
} else
AcpiOsFree(rv);
}
return (AE_ERROR);
}
/*
* Return the d2a node matching this ACPI_HANDLE, if one exists
*/
int
{
int i;
if (d2a_len == 0)
return (AE_OK);
}
return (AE_ERROR);
}
/*
* Return the ACPI device node matching this dev_info node, if it
* exists in the ACPI tree.
*/
int
{
int i;
if (d2a_len == 0)
return (AE_OK);
}
return (AE_ERROR);
}
/*
* Create a table mapping PCI dips to ACPI objects
*/
static void
{
int newsize;
/* initially, or re-, allocate array */
if (d2a_len != 0) {
/* realloc: copy data, free old */
}
}
#ifdef D2ADEBUG
{
char pathname[60];
}
}
#endif
}
static void
create_d2a_map(void)
{
char *device_type_prop;
int bus;
static int map_error = 0;
if (map_error)
return;
creating_d2a_map = 1;
/*
* Find all child-of-root PCI buses, and find their corresponding
* ACPI child-of-root PCI nodes. For each one, add to the
* d2a table.
*/
/* prune non-PCI nodes */
continue;
continue;
}
/*
* To get bus number of dip, get first child and get its
* bus number. If NULL, just continue, because we don't
* care about bus nodes with no children anyway.
*/
continue;
#ifdef D2ADEBUG
#endif
map_error = 1;
creating_d2a_map = 0;
return;
}
#ifdef D2ADEBUG
#endif
map_error = 1;
continue;
}
/*
* map this node, with illegal device and fn numbers
* (since, as a PCI root node, it exists on the system
* bus
*/
/* call recursive function to enumerate subtrees */
}
creating_d2a_map = 0;
}
/*
* For all acpi child devices of acpiobj, find their matching
* bus is assumed to already be a match from caller, and is
* used here only to record in the d2a entry. Recurse if necessary.
*/
static void
{
int acpi_devfn, hid;
== AE_OK) {
/*
* Skip ACPI devices that are obviously not PCI, i.e.,
* that have a _HID that is *not* the PCI HID
*/
continue;
continue;
/* look through all the immediate children of dip */
continue;
/* dev must match; function must match or wildcard */
continue;
/* found a match, record it */
/* recurse from here to pick up child trees */
/* done finding a match, so break now */
break;
}
}
}
/*
*/
int
{
int len;
return (-1);
if (len < (sizeof (pci_regspec_t) / sizeof (int))) {
return (-1);
}
return (0);
}