osl.c revision f2be51489e45daeb2c91d227fa1691c74cc3ea97
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 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;
/* set by acpi_poweroff() in PSMs */
int acpica_powering_off = 0;
/*
*
*/
static void
{
int i;
/*
* destroy event queues
*/
for (i = OSL_GLOBAL_LOCK_HANDLER; i <= OSL_EC_BURST_HANDLER; i++) {
if (osl_eventq[i])
}
}
/*
*
*/
static ACPI_STATUS
{
char namebuf[32];
int i, error = 0;
/*
* Initialize event queues
*/
for (i = OSL_GLOBAL_LOCK_HANDLER; i <= OSL_EC_BURST_HANDLER; i++) {
if (osl_eventq[i] == NULL)
error++;
}
if (error != 0) {
#ifdef DEBUG
#endif
return (AE_ERROR);
}
acpica_eventq_init = 1;
return (AE_OK);
}
/*
*
*/
AcpiOsInitialize(void)
{
return (AE_OK);
}
/*
*
*/
AcpiOsTerminate(void)
{
return (AE_OK);
}
{
/*
* For EFI firmware, the root pointer is defined in EFI systab.
* The boot code process the table and put the physical address
* in the acpi-root-tab property.
*/
"acpi-root-tab", 0);
if (acpi_root_tab != 0) {
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);
}
/*
* ACPI semaphore implementation
*/
typedef struct {
} acpi_sema_t;
/*
*
*/
void
{
/* no need to enter mutex here at creation */
}
/*
*
*/
void
{
}
/*
*
*/
{
/*
* Enough units available, no blocking
*/
return (rv);
} else if (wait_time == 0) {
/*
* Not enough units available and timeout
* specifies no blocking
*/
return (rv);
}
/*
* Not enough units available and timeout specifies waiting
*/
if (wait_time != ACPI_WAIT_FOREVER)
deadline = ddi_get_lbolt() +
do {
if (wait_time == ACPI_WAIT_FOREVER)
break;
}
/* if we dropped out of the wait with AE_OK, we got the units */
return (rv);
}
/*
*
*/
void
{
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
{
return (AE_BAD_PARAMETER);
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
void
{
return;
}
{
return (AE_BAD_PARAMETER);
return (AE_OK);
}
void
{
return;
}
void *
{
return (tmp_ptr);
}
void
AcpiOsFree(void *Memory)
{
tmp_ptr -= 1;
}
{
/* FUTUREWORK: test PhysicalAddress for > 32 bits */
}
void
{
}
/*ARGSUSED*/
{
/* UNIMPLEMENTED: not invoked by ACPI CA code */
return (AE_NOT_IMPLEMENTED);
}
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);
}
}
static int acpi_intr_hooked = 0;
void *Context)
{
int retval;
int sci_vect;
/*
*/
return (AE_ERROR);
}
#ifdef DEBUG
#endif
if (retval) {
acpi_intr_hooked = 1;
return (AE_OK);
} else
return (AE_BAD_PARAMETER);
}
{
#ifdef DEBUG
#endif
if (acpi_intr_hooked) {
acpi_intr_hooked = 0;
}
return (AE_OK);
}
AcpiOsGetThreadId(void)
{
/*
* ACPI CA regards thread ID as an error, but it's valid
* on Solaris during kernel initialization. Thus, 1 is added
* to the kernel thread ID to avoid returning 0
*/
return (ddi_get_kt_did() + 1);
}
/*
*
*/
void *Context)
{
if (!acpica_eventq_init) {
/*
* Create taskqs for event handling
*/
if (init_event_queues() != AE_OK)
return (AE_ERROR);
}
DDI_NOSLEEP) == 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; very late in kernel shutdown, clock interrupts
* are blocked, so delay doesn't work then either.
* So we busy wait if lbolt == 0 (kernel startup)
* or if psm_shutdown() has set acpi_powering_off to
* a non-zero value.
*/
if ((ddi_get_lbolt() == 0) || acpica_powering_off)
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);
}
/*
* 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. Since
* ACPI CA depends on a valid _BBN object being present
* and this is not always true (one old x86 had broken _BBN),
* we go ahead and get the correct PCI bus number using the
* devinfo mapping (which compensates for broken _BBN).
*
* Default values for bus, segment, device and function are
* all 0 when ACPI CA can't figure them out.
*
* Some BIOSes implement _BBN() by reading PCI config space
* one bus #0 - which means that we'll recurse when we attempt
* to create the devinfo-to-ACPI map. If Derive is called during
* create_d2a_map or with bus #0, we don't translate the bus # and
* return.
*/
void
ACPI_PCI_ID **PciId)
{
int devfn;
/*
* See above - avoid recursing during create_d2a_map,
* and never translate bus# 0.
*/
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;
}
}
/*ARGSUSED*/
{
/* Always says yes; all mapped memory assumed readable */
return (1);
}
/*ARGSUSED*/
{
/* Always says yes; all mapped memory assumed writable */
return (1);
}
AcpiOsGetTimer(void)
{
/* gethrtime() returns 1nS resolution; convert to 100nS granules */
}
/*ARGSUSED*/
AcpiOsValidateInterface(char *interface)
{
return (AE_SUPPORT);
}
/*ARGSUSED*/
{
return (AE_OK);
}
{
/* FUTUREWORK: debugger support */
return (AE_OK);
}
AcpiOsPrintf(const char *Format, ...)
{
}
/*
* When != 0, sends output to console
*/
int acpica_console_out = 0;
#define ACPICA_OUTBUF_LEN 160
char acpica_outbuf[ACPICA_OUTBUF_LEN];
int acpica_outbuf_offset;
/*
*
*/
static void
{
int out_remaining;
/*
* copy the supplied buffer into the output buffer
* when we hit a '\n' or overflow the output buffer,
* output and reset the output buffer
*/
while (c = *bufp++) {
*outp++ = c;
if (c == '\n' || --out_remaining == 0) {
*outp = '\0';
if (acpica_console_out)
else
(void) strlog(0, 0, 0,
acpica_outbuf_offset = 0;
}
}
}
void
{
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
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);
}