osl.c revision 137e2f25e10005c56c157f22e407cc6ef70a6d39
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* ACPI CA OSL for Solaris x86
*/
#include <sys/pci_cfgspace.h>
/* local functions */
static int CompressEisaID(char *np);
static void scan_d2a_map(void);
static int acpica_query_bbn_problem(void);
/*
* Event queue vars
*/
int acpica_eventq_init = 0;
/*
* Priorities relative to minclsyspri that each taskq
* run at; OSL_NOTIFY_HANDLER needs to run at a higher
* priority than OSL_GPE_HANDLER. There's an implicit
* assumption that no priority here results in exceeding
* maxclsyspri.
* Note: these initializations need to match the order of
* ACPI_EXECUTE_TYPE.
*/
0, /* OSL_GLOBAL_LOCK_HANDLER */
2, /* OSL_NOTIFY_HANDLER */
0, /* OSL_GPE_HANDLER */
0, /* OSL_DEBUGGER_THREAD */
0, /* OSL_EC_POLL_HANDLER */
0 /* OSL_EC_BURST_HANDLER */
};
/*
* 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 scan_d2a_map() is working */
static int scanning_d2a_map = 0;
static int d2a_done = 0;
/* set by acpi_poweroff() in PSMs and appm_ioctl() in acpippm for S3 */
int acpica_use_safe_delay = 0;
/* CPU mapping data */
struct cpu_map_item {
};
static int cpu_map_count = 0;
static int cpu_map_built = 0;
static int acpi_has_broken_bbn = -1;
/* buffer for AcpiOsVprintf() */
#define ACPI_OSL_PR_BUFLEN 1024
static char *acpi_osl_pr_buffer = NULL;
static int acpi_osl_pr_buflen;
#define D2A_DEBUG
/*
*
*/
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
*/
/* Always allocate only 1 thread per queue to force FIFO execution */
for (i = OSL_GLOBAL_LOCK_HANDLER; i <= OSL_EC_BURST_HANDLER; i++) {
osl_eventq_pri_delta[i] + minclsyspri, 0);
if (osl_eventq[i] == NULL)
error++;
}
if (error != 0) {
#ifdef DEBUG
#endif
return (AE_ERROR);
}
acpica_eventq_init = 1;
return (AE_OK);
}
/*
* One-time initialization of OSL layer
*/
AcpiOsInitialize(void)
{
/*
* Allocate buffer for AcpiOsVprintf() here to avoid
* kmem_alloc()/kmem_free() at high PIL
*/
if (acpi_osl_pr_buffer != NULL)
return (AE_OK);
}
/*
* One-time shut-down of OSL layer
*/
AcpiOsTerminate(void)
{
if (acpi_osl_pr_buffer != NULL)
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", NULL);
return (Address);
}
/*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 (0);
}
void
{
}
void *
{
return (tmp_ptr);
}
void
AcpiOsFree(void *Memory)
{
tmp_ptr -= 1;
}
void *
{
/* 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
* are blocked, so delay doesn't work then either.
* So we busy wait if lbolt == 0 (kernel startup)
* or if acpica_use_safe_delay has been set to a
* non-zero value.
*/
if ((ddi_get_lbolt() == 0) || acpica_use_safe_delay)
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
* on bus #0 - which means that we'll recurse when we attempt
* to create the devinfo-to-ACPI map. If Derive is called during
* scan_d2a_map, we don't translate the bus # and return.
*
* We get the parent of the OpRegion, which must be a PCI
* node, fetch the associated devinfo node and snag the
* b/d/f from it.
*/
void
ACPI_PCI_ID **PciId)
{
/*
* See above - avoid recursing during scanning_d2a_map.
*/
if (scanning_d2a_map)
return;
/*
* Get the OpRegion's parent
*/
return;
/*
* If we've mapped the ACPI node to the devinfo
* tree, use the devinfo reg property
*/
/* no devinfo node - just confirm the d/f */
}
}
/*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
acpica_pr_buf(char *buf)
{
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
{
/*
* If AcpiOsInitialize() failed to allocate a string buffer,
* resort to vprintf().
*/
if (acpi_osl_pr_buffer == NULL) {
return;
}
/*
* It is possible that a very long debug output statement will
* be truncated; this is silently ignored.
*/
}
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!)
*/
}
{
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);
}
/*
* Create linkage between devinfo nodes and ACPI nodes
*/
static void
{
/*
* Tag the ACPI node with the dip
*/
/*
* Tag the devinfo node with the ACPI name
*/
} else {
}
}
static void
{
int cpu_id;
/*
* Special case: if we're a uppc system, there won't be
* a CPU map yet. So we create one and use the passed-in
* processor as CPU 0
*/
cpu_map_count = 1;
return;
}
continue;
break;
}
}
}
/*
* Return the ACPI device node matching the CPU dev_info node.
*/
{
char *device_type_prop;
int cpu_id;
/*
* if "device_type" != "cpu", error
*/
return (AE_ERROR);
return (AE_ERROR);
}
/*
* if cpu_map itself is NULL, we're a uppc system and
* acpica_build_processor_map() hasn't been called yet.
* So call it here
*/
(void) acpica_build_processor_map();
return (AE_ERROR);
}
/*
* get 'reg' and get obj from cpu_map
*/
"reg", -1);
return (AE_ERROR);
/*
* tag devinfo and obj
*/
return (AE_OK);
}
/*
* Convert CPU device _UID strings into unique integers
* ACPI 3.0 spec 6.1.9 permits _UID to be either
* an arbitrary string or numeric value. ACPI CA converts
* numeric types to a string, providing a consistent API,
* but it can not be assumed that _UID is always numeric.
* Keep a private list of CPU _UIDs and convert them to
* an integer representation.
*/
struct acpica_cpu_uid {
struct acpica_cpu_uid *next;
char *uid;
};
static UINT32
acpica_cpu_uid_str_to_uint(char *uidstr)
{
UINT32 n;
n = 0;
break;
n++;
}
/*
* failed to find a matching element; create it here
*/
/* allocate new list element as current one */
sizeof (struct acpica_cpu_uid), KM_SLEEP);
/* allocate storage for the device ID string */
KM_SLEEP);
}
/*
* 'n' correctly contains the index for either
* a new element or an existing element
*/
return (n);
}
/*
* Determine if this object is a processor
*/
static ACPI_STATUS
{
return (AE_OK);
if (objtype == ACPI_TYPE_PROCESSOR) {
/* process a Processor */
return (status);
}
} else if (objtype == ACPI_TYPE_DEVICE) {
/* process a processor Device */
"acpica: error probing Processor Device\n");
return (status);
}
}
return (AE_OK);
}
static void
scan_d2a_map(void)
{
char *device_type_prop;
int bus;
static int map_error = 0;
if (map_error)
return;
scanning_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;
scanning_d2a_map = 0;
d2a_done = 1;
return;
}
#ifdef D2ADEBUG
#endif
map_error = 1;
continue;
}
/* call recursively to enumerate subtrees */
}
scanning_d2a_map = 0;
d2a_done = 1;
}
/*
* 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;
char *device_type_prop;
== AE_OK) {
continue;
/* look through all the immediate children of dip */
continue;
/* dev must match; function must match or wildcard */
continue;
/* found a match, record it */
/* if we find a bridge, recurse from here */
"device_type", &device_type_prop) ==
}
/* 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);
}
/*
* Return the ACPI device node matching this dev_info node, if it
* exists in the ACPI tree.
*/
{
char *acpiname;
if (!d2a_done)
scan_d2a_map();
}
ddi_prop_free((void *)acpiname);
return (status);
}
/*
* Manage OS data attachment to ACPI nodes
*/
/*
* Return the (dev_info_t *) associated with the ACPI node.
*/
{
void *ptr;
return (status);
}
/*
* Set the dev_info_t associated with the ACPI node.
*/
static ACPI_STATUS
{
return (status);
}
/*
*
*/
void
{
/* noop */
}
/*
*
*/
void
{
struct cpu_map_item *item;
}
void
{
void *rv;
/*
* shouldn't be called more than once anyway
*/
if (cpu_map_built)
return;
/*
* Look for Processor objects
*/
4,
NULL,
&rv);
/*
* Look for processor Device objects
*/
NULL,
&rv);
cpu_map_built = 1;
}