17c478bd9Sstevel@tonic-gate /* 28e56767dSsmall * CDDL HEADER START 38e56767dSsmall * 48e56767dSsmall * The contents of this file are subject to the terms of the 530082d0cSmyers * Common Development and Distribution License (the "License"). 630082d0cSmyers * You may not use this file except in compliance with the License. 78e56767dSsmall * 88e56767dSsmall * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 98e56767dSsmall * or http://www.opensolaris.org/os/licensing. 108e56767dSsmall * See the License for the specific language governing permissions 118e56767dSsmall * and limitations under the License. 128e56767dSsmall * 138e56767dSsmall * When distributing Covered Code, include this CDDL HEADER in each 148e56767dSsmall * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 158e56767dSsmall * If applicable, add the following below this CDDL HEADER, with the 168e56767dSsmall * fields enclosed by brackets "[]" replaced with your own identifying 178e56767dSsmall * information: Portions Copyright [yyyy] [name of copyright owner] 188e56767dSsmall * 198e56767dSsmall * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21450d6964Smyers 227c478bd9Sstevel@tonic-gate /* 235dff2f34Smyers * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 268e56767dSsmall /* 278e56767dSsmall * ACPI CA OSL for Solaris x86 288e56767dSsmall */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/psm.h> 367c478bd9Sstevel@tonic-gate #include <sys/pci_cfgspace.h> 377c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 385cff7825Smh #include <sys/sunndi.h> 397c478bd9Sstevel@tonic-gate #include <sys/pci.h> 407c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 417c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 427c478bd9Sstevel@tonic-gate #include <sys/strlog.h> 437c478bd9Sstevel@tonic-gate #include <sys/note.h> 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include <sys/acpi/acpi.h> 467c478bd9Sstevel@tonic-gate #include <sys/acpica.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #define MAX_DAT_FILE_SIZE (64*1024) 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* local functions */ 517c478bd9Sstevel@tonic-gate static int CompressEisaID(char *np); 527c478bd9Sstevel@tonic-gate 535cff7825Smh static void scan_d2a_map(void); 545cff7825Smh static void scan_d2a_subtree(dev_info_t *dip, ACPI_HANDLE acpiobj, int bus); 555cff7825Smh static void acpica_tag_devinfo(dev_info_t *dip, ACPI_HANDLE acpiobj); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static int acpica_query_bbn_problem(void); 587c478bd9Sstevel@tonic-gate static int acpica_find_pcibus(int busno, ACPI_HANDLE *rh); 597c478bd9Sstevel@tonic-gate static int acpica_eval_hid(ACPI_HANDLE dev, char *method, int *rint); 605cff7825Smh static ACPI_STATUS acpica_set_devinfo(ACPI_HANDLE, dev_info_t *); 615cff7825Smh static void acpica_devinfo_handler(ACPI_HANDLE, UINT32, void *); 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Event queue vars 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate int acpica_eventq_thread_count = 1; 677c478bd9Sstevel@tonic-gate int acpica_eventq_init = 0; 6827f7c583Smyers ddi_taskq_t *osl_eventq[OSL_EC_BURST_HANDLER+1]; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Note, if you change this path, you need to update 727c478bd9Sstevel@tonic-gate * /boot/grub/filelist.ramdisk and pkg SUNWckr/prototype_i386 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate static char *acpi_table_path = "/boot/acpi/tables/"; 757c478bd9Sstevel@tonic-gate 765cff7825Smh /* non-zero while scan_d2a_map() is working */ 775cff7825Smh static int scanning_d2a_map = 0; 785cff7825Smh static int d2a_done = 0; 797c478bd9Sstevel@tonic-gate 80859dcd3dSmyers /* set by acpi_poweroff() in PSMs */ 81859dcd3dSmyers int acpica_powering_off = 0; 82859dcd3dSmyers 835cff7825Smh /* CPU mapping data */ 845cff7825Smh struct cpu_map_item { 855cff7825Smh MADT_PROCESSOR_APIC *mpa; 865cff7825Smh ACPI_HANDLE obj; 875cff7825Smh }; 885cff7825Smh 895cff7825Smh static struct cpu_map_item **cpu_map = NULL; 905cff7825Smh static int cpu_map_count = 0; 915cff7825Smh static int cpu_map_built = 0; 925cff7825Smh 935cff7825Smh static int acpi_has_broken_bbn = -1; 945cff7825Smh 95*87bb58d6Smyers /* buffer for AcpiOsVprintf() */ 96*87bb58d6Smyers #define ACPI_OSL_PR_BUFLEN 1024 97*87bb58d6Smyers static char *acpi_osl_pr_buffer = NULL; 98*87bb58d6Smyers static int acpi_osl_pr_buflen; 99*87bb58d6Smyers 1005cff7825Smh #define D2A_DEBUG 1015cff7825Smh 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate static void 1067c478bd9Sstevel@tonic-gate discard_event_queues() 1077c478bd9Sstevel@tonic-gate { 10827f7c583Smyers int i; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * destroy event queues 1127c478bd9Sstevel@tonic-gate */ 11327f7c583Smyers for (i = OSL_GLOBAL_LOCK_HANDLER; i <= OSL_EC_BURST_HANDLER; i++) { 11427f7c583Smyers if (osl_eventq[i]) 11527f7c583Smyers ddi_taskq_destroy(osl_eventq[i]); 11627f7c583Smyers } 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate static ACPI_STATUS 1247c478bd9Sstevel@tonic-gate init_event_queues() 1257c478bd9Sstevel@tonic-gate { 12627f7c583Smyers char namebuf[32]; 12727f7c583Smyers int i, error = 0; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * Initialize event queues 1317c478bd9Sstevel@tonic-gate */ 1327c478bd9Sstevel@tonic-gate 13327f7c583Smyers for (i = OSL_GLOBAL_LOCK_HANDLER; i <= OSL_EC_BURST_HANDLER; i++) { 13427f7c583Smyers snprintf(namebuf, 32, "ACPI%d", i); 13527f7c583Smyers osl_eventq[i] = ddi_taskq_create(NULL, namebuf, 13627f7c583Smyers acpica_eventq_thread_count, TASKQ_DEFAULTPRI, 0); 13727f7c583Smyers if (osl_eventq[i] == NULL) 13827f7c583Smyers error++; 13927f7c583Smyers } 14027f7c583Smyers 14127f7c583Smyers if (error != 0) { 1427c478bd9Sstevel@tonic-gate discard_event_queues(); 1437c478bd9Sstevel@tonic-gate #ifdef DEBUG 1447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!acpica: could not initialize event queues"); 1457c478bd9Sstevel@tonic-gate #endif 1467c478bd9Sstevel@tonic-gate return (AE_ERROR); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate acpica_eventq_init = 1; 1507c478bd9Sstevel@tonic-gate return (AE_OK); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 154*87bb58d6Smyers * One-time initialization of OSL layer 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate ACPI_STATUS 1577c478bd9Sstevel@tonic-gate AcpiOsInitialize(void) 1587c478bd9Sstevel@tonic-gate { 159*87bb58d6Smyers /* 160*87bb58d6Smyers * Allocate buffer for AcpiOsVprintf() here to avoid 161*87bb58d6Smyers * kmem_alloc()/kmem_free() at high PIL 162*87bb58d6Smyers */ 163*87bb58d6Smyers acpi_osl_pr_buffer = kmem_alloc(ACPI_OSL_PR_BUFLEN, KM_SLEEP); 164*87bb58d6Smyers if (acpi_osl_pr_buffer != NULL) 165*87bb58d6Smyers acpi_osl_pr_buflen = ACPI_OSL_PR_BUFLEN; 166*87bb58d6Smyers 1677c478bd9Sstevel@tonic-gate return (AE_OK); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 171*87bb58d6Smyers * One-time shut-down of OSL layer 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate ACPI_STATUS 1747c478bd9Sstevel@tonic-gate AcpiOsTerminate(void) 1757c478bd9Sstevel@tonic-gate { 1767c478bd9Sstevel@tonic-gate 177*87bb58d6Smyers if (acpi_osl_pr_buffer != NULL) 178*87bb58d6Smyers kmem_free(acpi_osl_pr_buffer, acpi_osl_pr_buflen); 179*87bb58d6Smyers 1807c478bd9Sstevel@tonic-gate discard_event_queues(); 1817c478bd9Sstevel@tonic-gate return (AE_OK); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate ACPI_STATUS 1867c478bd9Sstevel@tonic-gate AcpiOsGetRootPointer(UINT32 Flags, ACPI_POINTER *Address) 1877c478bd9Sstevel@tonic-gate { 188f2be5148Sszhou uint_t acpi_root_tab; 189f2be5148Sszhou 190f2be5148Sszhou /* 191f2be5148Sszhou * For EFI firmware, the root pointer is defined in EFI systab. 192f2be5148Sszhou * The boot code process the table and put the physical address 193f2be5148Sszhou * in the acpi-root-tab property. 194f2be5148Sszhou */ 195f2be5148Sszhou acpi_root_tab = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(), 0, 196f2be5148Sszhou "acpi-root-tab", 0); 197f2be5148Sszhou if (acpi_root_tab != 0) { 198f2be5148Sszhou Address->PointerType = ACPI_PHYSICAL_POINTER; 199f2be5148Sszhou Address->Pointer.Physical = acpi_root_tab; 200f2be5148Sszhou return (AE_OK); 201f2be5148Sszhou } 2027c478bd9Sstevel@tonic-gate return (AcpiFindRootPointer(Flags, Address)); 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2067c478bd9Sstevel@tonic-gate ACPI_STATUS 2077c478bd9Sstevel@tonic-gate AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal, 2087c478bd9Sstevel@tonic-gate ACPI_STRING *NewVal) 2097c478bd9Sstevel@tonic-gate { 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate *NewVal = 0; 2127c478bd9Sstevel@tonic-gate return (AE_OK); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate static void 2167c478bd9Sstevel@tonic-gate acpica_strncpy(char *dest, const char *src, int len) 2177c478bd9Sstevel@tonic-gate { 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /*LINTED*/ 2207c478bd9Sstevel@tonic-gate while ((*dest++ = *src++) && (--len > 0)) 2217c478bd9Sstevel@tonic-gate /* copy the string */; 2227c478bd9Sstevel@tonic-gate *dest = '\0'; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate ACPI_STATUS 2267c478bd9Sstevel@tonic-gate AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable, 2277c478bd9Sstevel@tonic-gate ACPI_TABLE_HEADER **NewTable) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate char signature[5]; 2307c478bd9Sstevel@tonic-gate char oemid[7]; 2317c478bd9Sstevel@tonic-gate char oemtableid[9]; 2327c478bd9Sstevel@tonic-gate struct _buf *file; 2337c478bd9Sstevel@tonic-gate char *buf1, *buf2; 2347c478bd9Sstevel@tonic-gate int count; 2357c478bd9Sstevel@tonic-gate char acpi_table_loc[128]; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate acpica_strncpy(signature, ExistingTable->Signature, 4); 2387c478bd9Sstevel@tonic-gate acpica_strncpy(oemid, ExistingTable->OemId, 6); 2397c478bd9Sstevel@tonic-gate acpica_strncpy(oemtableid, ExistingTable->OemTableId, 8); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #ifdef DEBUG 2427c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!acpica: table [%s] v%d OEM ID [%s]" 2435dff2f34Smyers " OEM TABLE ID [%s] OEM rev %x", 2445dff2f34Smyers signature, ExistingTable->Revision, oemid, oemtableid, 2455dff2f34Smyers ExistingTable->OemRevision); 2467c478bd9Sstevel@tonic-gate #endif 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* File name format is "signature_oemid_oemtableid.dat" */ 2497c478bd9Sstevel@tonic-gate (void) strcpy(acpi_table_loc, acpi_table_path); 2507c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, signature); /* for example, DSDT */ 2517c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, "_"); 2527c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, oemid); /* for example, IntelR */ 2537c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, "_"); 2547c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, oemtableid); /* for example, AWRDACPI */ 2557c478bd9Sstevel@tonic-gate (void) strcat(acpi_table_loc, ".dat"); 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate file = kobj_open_file(acpi_table_loc); 2587c478bd9Sstevel@tonic-gate if (file == (struct _buf *)-1) { 2597c478bd9Sstevel@tonic-gate *NewTable = 0; 2607c478bd9Sstevel@tonic-gate return (AE_OK); 2617c478bd9Sstevel@tonic-gate } else { 2627c478bd9Sstevel@tonic-gate buf1 = (char *)kmem_alloc(MAX_DAT_FILE_SIZE, KM_SLEEP); 2637c478bd9Sstevel@tonic-gate count = kobj_read_file(file, buf1, MAX_DAT_FILE_SIZE-1, 0); 2647c478bd9Sstevel@tonic-gate if (count >= MAX_DAT_FILE_SIZE) { 2657c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!acpica: table %s file size too big", 2667c478bd9Sstevel@tonic-gate acpi_table_loc); 2677c478bd9Sstevel@tonic-gate *NewTable = 0; 2687c478bd9Sstevel@tonic-gate } else { 2697c478bd9Sstevel@tonic-gate buf2 = (char *)kmem_alloc(count, KM_SLEEP); 2707c478bd9Sstevel@tonic-gate (void) memcpy(buf2, buf1, count); 2717c478bd9Sstevel@tonic-gate *NewTable = (ACPI_TABLE_HEADER *)buf2; 2727c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!acpica: replacing table: %s", 2737c478bd9Sstevel@tonic-gate acpi_table_loc); 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate kobj_close_file(file); 2777c478bd9Sstevel@tonic-gate kmem_free(buf1, MAX_DAT_FILE_SIZE); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate return (AE_OK); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate 28330082d0cSmyers /* 28430082d0cSmyers * ACPI semaphore implementation 28530082d0cSmyers */ 28630082d0cSmyers typedef struct { 28730082d0cSmyers kmutex_t mutex; 28830082d0cSmyers kcondvar_t cv; 28930082d0cSmyers uint32_t available; 29030082d0cSmyers uint32_t initial; 29130082d0cSmyers uint32_t maximum; 29230082d0cSmyers } acpi_sema_t; 29330082d0cSmyers 29430082d0cSmyers /* 29530082d0cSmyers * 29630082d0cSmyers */ 29730082d0cSmyers void 29827f7c583Smyers acpi_sema_init(acpi_sema_t *sp, unsigned max, unsigned count) 29930082d0cSmyers { 30030082d0cSmyers mutex_init(&sp->mutex, NULL, MUTEX_DRIVER, NULL); 30130082d0cSmyers cv_init(&sp->cv, NULL, CV_DRIVER, NULL); 30230082d0cSmyers /* no need to enter mutex here at creation */ 30330082d0cSmyers sp->available = count; 30430082d0cSmyers sp->initial = count; 30530082d0cSmyers sp->maximum = max; 30630082d0cSmyers } 30730082d0cSmyers 30830082d0cSmyers /* 30930082d0cSmyers * 31030082d0cSmyers */ 31130082d0cSmyers void 31230082d0cSmyers acpi_sema_destroy(acpi_sema_t *sp) 31330082d0cSmyers { 31430082d0cSmyers 31530082d0cSmyers cv_destroy(&sp->cv); 31630082d0cSmyers mutex_destroy(&sp->mutex); 31730082d0cSmyers } 31830082d0cSmyers 31930082d0cSmyers /* 32030082d0cSmyers * 32130082d0cSmyers */ 32230082d0cSmyers ACPI_STATUS 32330082d0cSmyers acpi_sema_p(acpi_sema_t *sp, unsigned count, uint16_t wait_time) 32430082d0cSmyers { 32530082d0cSmyers ACPI_STATUS rv = AE_OK; 32630082d0cSmyers clock_t deadline; 32730082d0cSmyers 32830082d0cSmyers mutex_enter(&sp->mutex); 32930082d0cSmyers 33030082d0cSmyers if (sp->available >= count) { 33130082d0cSmyers /* 33230082d0cSmyers * Enough units available, no blocking 33330082d0cSmyers */ 33430082d0cSmyers sp->available -= count; 33530082d0cSmyers mutex_exit(&sp->mutex); 33630082d0cSmyers return (rv); 33730082d0cSmyers } else if (wait_time == 0) { 33830082d0cSmyers /* 33930082d0cSmyers * Not enough units available and timeout 34030082d0cSmyers * specifies no blocking 34130082d0cSmyers */ 34230082d0cSmyers rv = AE_TIME; 34330082d0cSmyers mutex_exit(&sp->mutex); 34430082d0cSmyers return (rv); 34530082d0cSmyers } 34630082d0cSmyers 34730082d0cSmyers /* 34830082d0cSmyers * Not enough units available and timeout specifies waiting 34930082d0cSmyers */ 35030082d0cSmyers if (wait_time != ACPI_WAIT_FOREVER) 35130082d0cSmyers deadline = ddi_get_lbolt() + 35230082d0cSmyers (clock_t)drv_usectohz(wait_time * 1000); 35330082d0cSmyers 35430082d0cSmyers do { 35530082d0cSmyers if (wait_time == ACPI_WAIT_FOREVER) 35630082d0cSmyers cv_wait(&sp->cv, &sp->mutex); 35730082d0cSmyers else if (cv_timedwait(&sp->cv, &sp->mutex, deadline) < 0) { 35830082d0cSmyers rv = AE_TIME; 35930082d0cSmyers break; 36030082d0cSmyers } 36130082d0cSmyers } while (sp->available < count); 36230082d0cSmyers 36330082d0cSmyers /* if we dropped out of the wait with AE_OK, we got the units */ 36430082d0cSmyers if (rv == AE_OK) 36530082d0cSmyers sp->available -= count; 36630082d0cSmyers 36730082d0cSmyers mutex_exit(&sp->mutex); 36830082d0cSmyers return (rv); 36930082d0cSmyers } 37030082d0cSmyers 37130082d0cSmyers /* 37230082d0cSmyers * 37330082d0cSmyers */ 37430082d0cSmyers void 37530082d0cSmyers acpi_sema_v(acpi_sema_t *sp, unsigned count) 37630082d0cSmyers { 37730082d0cSmyers mutex_enter(&sp->mutex); 37830082d0cSmyers sp->available += count; 37930082d0cSmyers cv_broadcast(&sp->cv); 38030082d0cSmyers mutex_exit(&sp->mutex); 38130082d0cSmyers } 38230082d0cSmyers 38330082d0cSmyers 3847c478bd9Sstevel@tonic-gate ACPI_STATUS 3857c478bd9Sstevel@tonic-gate AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, 3867c478bd9Sstevel@tonic-gate ACPI_HANDLE *OutHandle) 3877c478bd9Sstevel@tonic-gate { 38830082d0cSmyers acpi_sema_t *sp; 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate if ((OutHandle == NULL) || (InitialUnits > MaxUnits)) 3917c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 3927c478bd9Sstevel@tonic-gate 39330082d0cSmyers sp = (acpi_sema_t *)kmem_alloc(sizeof (acpi_sema_t), KM_SLEEP); 39427f7c583Smyers acpi_sema_init(sp, MaxUnits, InitialUnits); 39530082d0cSmyers *OutHandle = (ACPI_HANDLE)sp; 3967c478bd9Sstevel@tonic-gate return (AE_OK); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate ACPI_STATUS 4017c478bd9Sstevel@tonic-gate AcpiOsDeleteSemaphore(ACPI_HANDLE Handle) 4027c478bd9Sstevel@tonic-gate { 4037c478bd9Sstevel@tonic-gate 40430082d0cSmyers if (Handle == NULL) 40530082d0cSmyers return (AE_BAD_PARAMETER); 40630082d0cSmyers 40730082d0cSmyers acpi_sema_destroy((acpi_sema_t *)Handle); 40830082d0cSmyers kmem_free((void *)Handle, sizeof (acpi_sema_t)); 4097c478bd9Sstevel@tonic-gate return (AE_OK); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate ACPI_STATUS 4137c478bd9Sstevel@tonic-gate AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout) 4147c478bd9Sstevel@tonic-gate { 4157c478bd9Sstevel@tonic-gate 41630082d0cSmyers if ((Handle == NULL) || (Units < 1)) 41730082d0cSmyers return (AE_BAD_PARAMETER); 4187c478bd9Sstevel@tonic-gate 41930082d0cSmyers return (acpi_sema_p((acpi_sema_t *)Handle, Units, Timeout)); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate ACPI_STATUS 4237c478bd9Sstevel@tonic-gate AcpiOsSignalSemaphore(ACPI_HANDLE Handle, UINT32 Units) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate 42630082d0cSmyers if ((Handle == NULL) || (Units < 1)) 42730082d0cSmyers return (AE_BAD_PARAMETER); 42830082d0cSmyers 42930082d0cSmyers acpi_sema_v((acpi_sema_t *)Handle, Units); 4307c478bd9Sstevel@tonic-gate return (AE_OK); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate ACPI_STATUS 4347c478bd9Sstevel@tonic-gate AcpiOsCreateLock(ACPI_HANDLE *OutHandle) 4357c478bd9Sstevel@tonic-gate { 43630082d0cSmyers kmutex_t *mp; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate if (OutHandle == NULL) 4397c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 4407c478bd9Sstevel@tonic-gate 44130082d0cSmyers mp = (kmutex_t *)kmem_alloc(sizeof (kmutex_t), KM_SLEEP); 44230082d0cSmyers mutex_init(mp, NULL, MUTEX_DRIVER, NULL); 44330082d0cSmyers *OutHandle = (ACPI_HANDLE)mp; 4447c478bd9Sstevel@tonic-gate return (AE_OK); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate void 4487c478bd9Sstevel@tonic-gate AcpiOsDeleteLock(ACPI_HANDLE Handle) 4497c478bd9Sstevel@tonic-gate { 45030082d0cSmyers 45130082d0cSmyers if (Handle == NULL) 45230082d0cSmyers return; 45330082d0cSmyers 45430082d0cSmyers mutex_destroy((kmutex_t *)Handle); 45530082d0cSmyers kmem_free((void *)Handle, sizeof (kmutex_t)); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate 45830082d0cSmyers ACPI_NATIVE_UINT 459450d6964Smyers AcpiOsAcquireLock(ACPI_HANDLE Handle) 4607c478bd9Sstevel@tonic-gate { 46130082d0cSmyers 46230082d0cSmyers if (Handle == NULL) 46330082d0cSmyers return (AE_BAD_PARAMETER); 46430082d0cSmyers 46530082d0cSmyers mutex_enter((kmutex_t *)Handle); 46630082d0cSmyers return (AE_OK); 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate void 47030082d0cSmyers AcpiOsReleaseLock(ACPI_HANDLE Handle, ACPI_NATIVE_UINT Flags) 4717c478bd9Sstevel@tonic-gate { 472450d6964Smyers _NOTE(ARGUNUSED(Flags)) 4737c478bd9Sstevel@tonic-gate 47430082d0cSmyers if (Handle == NULL) 47530082d0cSmyers return; 47630082d0cSmyers 47730082d0cSmyers mutex_exit((kmutex_t *)Handle); 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate void * 4827c478bd9Sstevel@tonic-gate AcpiOsAllocate(ACPI_SIZE Size) 4837c478bd9Sstevel@tonic-gate { 4847c478bd9Sstevel@tonic-gate ACPI_SIZE *tmp_ptr; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate Size += sizeof (Size); 4877c478bd9Sstevel@tonic-gate tmp_ptr = (ACPI_SIZE *)kmem_zalloc(Size, KM_SLEEP); 4887c478bd9Sstevel@tonic-gate *tmp_ptr++ = Size; 48930082d0cSmyers return (tmp_ptr); 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate void 4937c478bd9Sstevel@tonic-gate AcpiOsFree(void *Memory) 4947c478bd9Sstevel@tonic-gate { 4957c478bd9Sstevel@tonic-gate ACPI_SIZE size, *tmp_ptr; 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate tmp_ptr = (ACPI_SIZE *)Memory; 4987c478bd9Sstevel@tonic-gate tmp_ptr -= 1; 4997c478bd9Sstevel@tonic-gate size = *tmp_ptr; 50030082d0cSmyers kmem_free(tmp_ptr, size); 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate ACPI_STATUS 5047c478bd9Sstevel@tonic-gate AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, 5057c478bd9Sstevel@tonic-gate ACPI_SIZE Size, void **LogicalAddress) 5067c478bd9Sstevel@tonic-gate { 5077c478bd9Sstevel@tonic-gate /* FUTUREWORK: test PhysicalAddress for > 32 bits */ 5087c478bd9Sstevel@tonic-gate *LogicalAddress = psm_map_new((paddr_t)PhysicalAddress, 5095dff2f34Smyers (size_t)Size, PSM_PROT_WRITE | PSM_PROT_READ); 51003335b7aSmyers 51103335b7aSmyers return (*LogicalAddress == NULL ? AE_NO_MEMORY : AE_OK); 5127c478bd9Sstevel@tonic-gate } 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate void 5157c478bd9Sstevel@tonic-gate AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Size) 5167c478bd9Sstevel@tonic-gate { 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate psm_unmap((caddr_t)LogicalAddress, (size_t)Size); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5227c478bd9Sstevel@tonic-gate ACPI_STATUS 5237c478bd9Sstevel@tonic-gate AcpiOsGetPhysicalAddress(void *LogicalAddress, 5247c478bd9Sstevel@tonic-gate ACPI_PHYSICAL_ADDRESS *PhysicalAddress) 5257c478bd9Sstevel@tonic-gate { 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* UNIMPLEMENTED: not invoked by ACPI CA code */ 52803335b7aSmyers return (AE_NOT_IMPLEMENTED); 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate ACPI_OSD_HANDLER acpi_isr; 5337c478bd9Sstevel@tonic-gate void *acpi_isr_context; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate uint_t 5367c478bd9Sstevel@tonic-gate acpi_wrapper_isr(char *arg) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(arg)) 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate int status; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate status = (*acpi_isr)(acpi_isr_context); 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate if (status == ACPI_INTERRUPT_HANDLED) { 5457c478bd9Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 5467c478bd9Sstevel@tonic-gate } else { 5477c478bd9Sstevel@tonic-gate return (DDI_INTR_UNCLAIMED); 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate 551186507a7Smyers static int acpi_intr_hooked = 0; 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate ACPI_STATUS 5547c478bd9Sstevel@tonic-gate AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, 5557c478bd9Sstevel@tonic-gate ACPI_OSD_HANDLER ServiceRoutine, 5567c478bd9Sstevel@tonic-gate void *Context) 5577c478bd9Sstevel@tonic-gate { 55827f7c583Smyers _NOTE(ARGUNUSED(InterruptNumber)) 55927f7c583Smyers 5607c478bd9Sstevel@tonic-gate int retval; 561450d6964Smyers int sci_vect; 562450d6964Smyers iflag_t sci_flags; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate acpi_isr = ServiceRoutine; 5657c478bd9Sstevel@tonic-gate acpi_isr_context = Context; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate /* 568450d6964Smyers * Get SCI (adjusted for PIC/APIC mode if necessary) 5697c478bd9Sstevel@tonic-gate */ 570450d6964Smyers if (acpica_get_sci(&sci_vect, &sci_flags) != AE_OK) { 571450d6964Smyers return (AE_ERROR); 572450d6964Smyers } 573450d6964Smyers 574450d6964Smyers #ifdef DEBUG 575450d6964Smyers cmn_err(CE_NOTE, "!acpica: attaching SCI %d", sci_vect); 576450d6964Smyers #endif 577450d6964Smyers 5787c478bd9Sstevel@tonic-gate retval = add_avintr(NULL, SCI_IPL, (avfunc)acpi_wrapper_isr, 5795dff2f34Smyers "ACPI SCI", sci_vect, NULL, NULL, NULL, NULL); 5807c478bd9Sstevel@tonic-gate if (retval) { 581186507a7Smyers acpi_intr_hooked = 1; 5827c478bd9Sstevel@tonic-gate return (AE_OK); 583186507a7Smyers } else 5847c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate ACPI_STATUS 5887c478bd9Sstevel@tonic-gate AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, 5897c478bd9Sstevel@tonic-gate ACPI_OSD_HANDLER ServiceRoutine) 5907c478bd9Sstevel@tonic-gate { 5917c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(ServiceRoutine)) 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate #ifdef DEBUG 5947c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!acpica: detaching SCI %d", InterruptNumber); 5957c478bd9Sstevel@tonic-gate #endif 596186507a7Smyers if (acpi_intr_hooked) { 5977c478bd9Sstevel@tonic-gate rem_avintr(NULL, LOCK_LEVEL - 1, (avfunc)acpi_wrapper_isr, 5985dff2f34Smyers InterruptNumber); 599186507a7Smyers acpi_intr_hooked = 0; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate return (AE_OK); 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate 60527f7c583Smyers ACPI_THREAD_ID 6067c478bd9Sstevel@tonic-gate AcpiOsGetThreadId(void) 6077c478bd9Sstevel@tonic-gate { 60827f7c583Smyers /* 60927f7c583Smyers * ACPI CA regards thread ID as an error, but it's valid 61027f7c583Smyers * on Solaris during kernel initialization. Thus, 1 is added 61127f7c583Smyers * to the kernel thread ID to avoid returning 0 61227f7c583Smyers */ 61327f7c583Smyers return (ddi_get_kt_did() + 1); 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate /* 6177c478bd9Sstevel@tonic-gate * 6187c478bd9Sstevel@tonic-gate */ 6197c478bd9Sstevel@tonic-gate ACPI_STATUS 62027f7c583Smyers AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function, 62127f7c583Smyers void *Context) 6227c478bd9Sstevel@tonic-gate { 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate if (!acpica_eventq_init) { 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * Create taskqs for event handling 6277c478bd9Sstevel@tonic-gate */ 6287c478bd9Sstevel@tonic-gate if (init_event_queues() != AE_OK) 6295dff2f34Smyers return (AE_ERROR); 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate 63227f7c583Smyers if (ddi_taskq_dispatch(osl_eventq[Type], Function, Context, 63327f7c583Smyers DDI_NOSLEEP) == DDI_FAILURE) { 6347c478bd9Sstevel@tonic-gate #ifdef DEBUG 6357c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!acpica: unable to dispatch event"); 6367c478bd9Sstevel@tonic-gate #endif 6377c478bd9Sstevel@tonic-gate return (AE_ERROR); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate return (AE_OK); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate void 6447c478bd9Sstevel@tonic-gate AcpiOsSleep(ACPI_INTEGER Milliseconds) 6457c478bd9Sstevel@tonic-gate { 6467c478bd9Sstevel@tonic-gate /* 6477c478bd9Sstevel@tonic-gate * During kernel startup, before the first 6487c478bd9Sstevel@tonic-gate * tick interrupt has taken place, we can't call 649859dcd3dSmyers * delay; very late in kernel shutdown, clock interrupts 650859dcd3dSmyers * are blocked, so delay doesn't work then either. 651859dcd3dSmyers * So we busy wait if lbolt == 0 (kernel startup) 652859dcd3dSmyers * or if psm_shutdown() has set acpi_powering_off to 653859dcd3dSmyers * a non-zero value. 6547c478bd9Sstevel@tonic-gate */ 655859dcd3dSmyers if ((ddi_get_lbolt() == 0) || acpica_powering_off) 6567c478bd9Sstevel@tonic-gate drv_usecwait(Milliseconds * 1000); 6577c478bd9Sstevel@tonic-gate else 6587c478bd9Sstevel@tonic-gate delay(drv_usectohz(Milliseconds * 1000)); 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate void 6627c478bd9Sstevel@tonic-gate AcpiOsStall(UINT32 Microseconds) 6637c478bd9Sstevel@tonic-gate { 6647c478bd9Sstevel@tonic-gate drv_usecwait(Microseconds); 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate /* 6697c478bd9Sstevel@tonic-gate * Implementation of "Windows 2001" compatible I/O permission map 6707c478bd9Sstevel@tonic-gate * 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate #define OSL_IO_NONE (0) 6737c478bd9Sstevel@tonic-gate #define OSL_IO_READ (1<<0) 6747c478bd9Sstevel@tonic-gate #define OSL_IO_WRITE (1<<1) 6757c478bd9Sstevel@tonic-gate #define OSL_IO_RW (OSL_IO_READ | OSL_IO_WRITE) 6767c478bd9Sstevel@tonic-gate #define OSL_IO_TERM (1<<2) 6777c478bd9Sstevel@tonic-gate #define OSL_IO_DEFAULT OSL_IO_RW 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate static struct io_perm { 6807c478bd9Sstevel@tonic-gate ACPI_IO_ADDRESS low; 6817c478bd9Sstevel@tonic-gate ACPI_IO_ADDRESS high; 6827c478bd9Sstevel@tonic-gate uint8_t perm; 6837c478bd9Sstevel@tonic-gate } osl_io_perm[] = { 6847c478bd9Sstevel@tonic-gate { 0xcf8, 0xd00, OSL_IO_NONE | OSL_IO_TERM } 6857c478bd9Sstevel@tonic-gate }; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* 6897c478bd9Sstevel@tonic-gate * 6907c478bd9Sstevel@tonic-gate */ 6917c478bd9Sstevel@tonic-gate static struct io_perm * 6927c478bd9Sstevel@tonic-gate osl_io_find_perm(ACPI_IO_ADDRESS addr) 6937c478bd9Sstevel@tonic-gate { 6947c478bd9Sstevel@tonic-gate struct io_perm *p; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate p = osl_io_perm; 6977c478bd9Sstevel@tonic-gate while (p != NULL) { 6987c478bd9Sstevel@tonic-gate if ((p->low <= addr) && (addr <= p->high)) 6997c478bd9Sstevel@tonic-gate break; 7007c478bd9Sstevel@tonic-gate p = (p->perm & OSL_IO_TERM) ? NULL : p+1; 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate return (p); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate ACPI_STATUS 7107c478bd9Sstevel@tonic-gate AcpiOsReadPort(ACPI_IO_ADDRESS Address, UINT32 *Value, UINT32 Width) 7117c478bd9Sstevel@tonic-gate { 7127c478bd9Sstevel@tonic-gate struct io_perm *p; 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate /* verify permission */ 7157c478bd9Sstevel@tonic-gate p = osl_io_find_perm(Address); 7167c478bd9Sstevel@tonic-gate if (p && (p->perm & OSL_IO_READ) == 0) { 7177c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsReadPort: %lx %u not permitted", 7185dff2f34Smyers (long)Address, Width); 7197c478bd9Sstevel@tonic-gate *Value = 0xffffffff; 7207c478bd9Sstevel@tonic-gate return (AE_ERROR); 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate switch (Width) { 7247c478bd9Sstevel@tonic-gate case 8: 7257c478bd9Sstevel@tonic-gate *Value = inb(Address); 7267c478bd9Sstevel@tonic-gate break; 7277c478bd9Sstevel@tonic-gate case 16: 7287c478bd9Sstevel@tonic-gate *Value = inw(Address); 7297c478bd9Sstevel@tonic-gate break; 7307c478bd9Sstevel@tonic-gate case 32: 7317c478bd9Sstevel@tonic-gate *Value = inl(Address); 7327c478bd9Sstevel@tonic-gate break; 7337c478bd9Sstevel@tonic-gate default: 7347c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsReadPort: %lx %u failed", 7355dff2f34Smyers (long)Address, Width); 7367c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 7377c478bd9Sstevel@tonic-gate } 7387c478bd9Sstevel@tonic-gate return (AE_OK); 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate ACPI_STATUS 7427c478bd9Sstevel@tonic-gate AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width) 7437c478bd9Sstevel@tonic-gate { 7447c478bd9Sstevel@tonic-gate struct io_perm *p; 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate /* verify permission */ 7477c478bd9Sstevel@tonic-gate p = osl_io_find_perm(Address); 7487c478bd9Sstevel@tonic-gate if (p && (p->perm & OSL_IO_WRITE) == 0) { 7497c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsWritePort: %lx %u not permitted", 7507c478bd9Sstevel@tonic-gate (long)Address, Width); 7517c478bd9Sstevel@tonic-gate return (AE_ERROR); 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate switch (Width) { 7557c478bd9Sstevel@tonic-gate case 8: 7567c478bd9Sstevel@tonic-gate outb(Address, Value); 7577c478bd9Sstevel@tonic-gate break; 7587c478bd9Sstevel@tonic-gate case 16: 7597c478bd9Sstevel@tonic-gate outw(Address, Value); 7607c478bd9Sstevel@tonic-gate break; 7617c478bd9Sstevel@tonic-gate case 32: 7627c478bd9Sstevel@tonic-gate outl(Address, Value); 7637c478bd9Sstevel@tonic-gate break; 7647c478bd9Sstevel@tonic-gate default: 7657c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsWritePort: %lx %u failed", 7667c478bd9Sstevel@tonic-gate (long)Address, Width); 7677c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate return (AE_OK); 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate /* 7747c478bd9Sstevel@tonic-gate * 7757c478bd9Sstevel@tonic-gate */ 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate #define OSL_RW(ptr, val, type, rw) \ 7787c478bd9Sstevel@tonic-gate { if (rw) *((type *)(ptr)) = *((type *) val); \ 7797c478bd9Sstevel@tonic-gate else *((type *) val) = *((type *)(ptr)); } 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate static void 7837c478bd9Sstevel@tonic-gate osl_rw_memory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, 7847c478bd9Sstevel@tonic-gate UINT32 Width, int write) 7857c478bd9Sstevel@tonic-gate { 7867c478bd9Sstevel@tonic-gate size_t maplen = Width / 8; 7877c478bd9Sstevel@tonic-gate caddr_t ptr; 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate ptr = psm_map_new((paddr_t)Address, maplen, 7907c478bd9Sstevel@tonic-gate PSM_PROT_WRITE | PSM_PROT_READ); 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate switch (maplen) { 7937c478bd9Sstevel@tonic-gate case 1: 7947c478bd9Sstevel@tonic-gate OSL_RW(ptr, Value, uint8_t, write); 7957c478bd9Sstevel@tonic-gate break; 7967c478bd9Sstevel@tonic-gate case 2: 7977c478bd9Sstevel@tonic-gate OSL_RW(ptr, Value, uint16_t, write); 7987c478bd9Sstevel@tonic-gate break; 7997c478bd9Sstevel@tonic-gate case 4: 8007c478bd9Sstevel@tonic-gate OSL_RW(ptr, Value, uint32_t, write); 8017c478bd9Sstevel@tonic-gate break; 8027c478bd9Sstevel@tonic-gate default: 8037c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!osl_rw_memory: invalid size %d", 8047c478bd9Sstevel@tonic-gate Width); 8057c478bd9Sstevel@tonic-gate break; 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate psm_unmap(ptr, maplen); 8097c478bd9Sstevel@tonic-gate } 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate ACPI_STATUS 8127c478bd9Sstevel@tonic-gate AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, 8137c478bd9Sstevel@tonic-gate UINT32 *Value, UINT32 Width) 8147c478bd9Sstevel@tonic-gate { 8157c478bd9Sstevel@tonic-gate osl_rw_memory(Address, Value, Width, 0); 8167c478bd9Sstevel@tonic-gate return (AE_OK); 8177c478bd9Sstevel@tonic-gate } 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate ACPI_STATUS 8207c478bd9Sstevel@tonic-gate AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, 8217c478bd9Sstevel@tonic-gate UINT32 Value, UINT32 Width) 8227c478bd9Sstevel@tonic-gate { 8237c478bd9Sstevel@tonic-gate osl_rw_memory(Address, &Value, Width, 1); 8247c478bd9Sstevel@tonic-gate return (AE_OK); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate ACPI_STATUS 8297c478bd9Sstevel@tonic-gate AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, 8307c478bd9Sstevel@tonic-gate void *Value, UINT32 Width) 8317c478bd9Sstevel@tonic-gate { 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate switch (Width) { 8347c478bd9Sstevel@tonic-gate case 8: 8357c478bd9Sstevel@tonic-gate *((UINT64 *)Value) = (UINT64)(*pci_getb_func) 8365dff2f34Smyers (PciId->Bus, PciId->Device, PciId->Function, Register); 8377c478bd9Sstevel@tonic-gate break; 8387c478bd9Sstevel@tonic-gate case 16: 8397c478bd9Sstevel@tonic-gate *((UINT64 *)Value) = (UINT64)(*pci_getw_func) 8405dff2f34Smyers (PciId->Bus, PciId->Device, PciId->Function, Register); 8417c478bd9Sstevel@tonic-gate break; 8427c478bd9Sstevel@tonic-gate case 32: 8437c478bd9Sstevel@tonic-gate *((UINT64 *)Value) = (UINT64)(*pci_getl_func) 8445dff2f34Smyers (PciId->Bus, PciId->Device, PciId->Function, Register); 8457c478bd9Sstevel@tonic-gate break; 8467c478bd9Sstevel@tonic-gate case 64: 8477c478bd9Sstevel@tonic-gate default: 8487c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsReadPciConfiguration: %x %u failed", 8497c478bd9Sstevel@tonic-gate Register, Width); 8507c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate return (AE_OK); 8537c478bd9Sstevel@tonic-gate } 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate /* 8567c478bd9Sstevel@tonic-gate * 8577c478bd9Sstevel@tonic-gate */ 8587c478bd9Sstevel@tonic-gate int acpica_write_pci_config_ok = 1; 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate ACPI_STATUS 8617c478bd9Sstevel@tonic-gate AcpiOsWritePciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, 8627c478bd9Sstevel@tonic-gate ACPI_INTEGER Value, UINT32 Width) 8637c478bd9Sstevel@tonic-gate { 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate if (!acpica_write_pci_config_ok) { 8667c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!write to PCI cfg %x/%x/%x %x" 8677c478bd9Sstevel@tonic-gate " %lx %d not permitted", PciId->Bus, PciId->Device, 8687c478bd9Sstevel@tonic-gate PciId->Function, Register, (long)Value, Width); 8697c478bd9Sstevel@tonic-gate return (AE_OK); 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate switch (Width) { 8737c478bd9Sstevel@tonic-gate case 8: 8747c478bd9Sstevel@tonic-gate (*pci_putb_func)(PciId->Bus, PciId->Device, PciId->Function, 8755dff2f34Smyers Register, (uint8_t)Value); 8767c478bd9Sstevel@tonic-gate break; 8777c478bd9Sstevel@tonic-gate case 16: 8787c478bd9Sstevel@tonic-gate (*pci_putw_func)(PciId->Bus, PciId->Device, PciId->Function, 8795dff2f34Smyers Register, (uint16_t)Value); 8807c478bd9Sstevel@tonic-gate break; 8817c478bd9Sstevel@tonic-gate case 32: 8827c478bd9Sstevel@tonic-gate (*pci_putl_func)(PciId->Bus, PciId->Device, PciId->Function, 8835dff2f34Smyers Register, (uint32_t)Value); 8847c478bd9Sstevel@tonic-gate break; 8857c478bd9Sstevel@tonic-gate case 64: 8867c478bd9Sstevel@tonic-gate default: 8877c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!AcpiOsWritePciConfiguration: %x %u failed", 8887c478bd9Sstevel@tonic-gate Register, Width); 8897c478bd9Sstevel@tonic-gate return (AE_BAD_PARAMETER); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate return (AE_OK); 8927c478bd9Sstevel@tonic-gate } 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate /* 8957c478bd9Sstevel@tonic-gate * Called with ACPI_HANDLEs for both a PCI Config Space 8967c478bd9Sstevel@tonic-gate * OpRegion and (what ACPI CA thinks is) the PCI device 89727f7c583Smyers * to which this ConfigSpace OpRegion belongs. Since 89827f7c583Smyers * ACPI CA depends on a valid _BBN object being present 89927f7c583Smyers * and this is not always true (one old x86 had broken _BBN), 90027f7c583Smyers * we go ahead and get the correct PCI bus number using the 90127f7c583Smyers * devinfo mapping (which compensates for broken _BBN). 9027c478bd9Sstevel@tonic-gate * 9037c478bd9Sstevel@tonic-gate * Default values for bus, segment, device and function are 9047c478bd9Sstevel@tonic-gate * all 0 when ACPI CA can't figure them out. 9057c478bd9Sstevel@tonic-gate * 90627f7c583Smyers * Some BIOSes implement _BBN() by reading PCI config space 9075dff2f34Smyers * on bus #0 - which means that we'll recurse when we attempt 90827f7c583Smyers * to create the devinfo-to-ACPI map. If Derive is called during 9095cff7825Smh * scan_d2a_map, we don't translate the bus # and return. 9105cff7825Smh * 9115cff7825Smh * We get the parent of the OpRegion, which must be a PCI 9125cff7825Smh * node, fetch the associated devinfo node and snag the 9135cff7825Smh * b/d/f from it. 9147c478bd9Sstevel@tonic-gate */ 9157c478bd9Sstevel@tonic-gate void 9167c478bd9Sstevel@tonic-gate AcpiOsDerivePciId(ACPI_HANDLE rhandle, ACPI_HANDLE chandle, 9177c478bd9Sstevel@tonic-gate ACPI_PCI_ID **PciId) 9187c478bd9Sstevel@tonic-gate { 9197c478bd9Sstevel@tonic-gate ACPI_HANDLE handle; 9205cff7825Smh dev_info_t *dip; 9215cff7825Smh int bus, device, func, devfn; 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate 92427f7c583Smyers /* 9255cff7825Smh * See above - avoid recursing during scanning_d2a_map. 92627f7c583Smyers */ 9275cff7825Smh if (scanning_d2a_map) 9287c478bd9Sstevel@tonic-gate return; 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate /* 9315cff7825Smh * Get the OpRegion's parent 9327c478bd9Sstevel@tonic-gate */ 9337c478bd9Sstevel@tonic-gate if (AcpiGetParent(chandle, &handle) != AE_OK) 9347c478bd9Sstevel@tonic-gate return; 9357c478bd9Sstevel@tonic-gate 9365cff7825Smh /* 9375cff7825Smh * If we've mapped the ACPI node to the devinfo 9385cff7825Smh * tree, use the devinfo reg property 9395cff7825Smh */ 9405cff7825Smh if (acpica_get_devinfo(handle, &dip) == AE_OK) { 9415cff7825Smh (void) acpica_get_bdf(dip, &bus, &device, &func); 9425cff7825Smh (*PciId)->Bus = bus; 9435cff7825Smh (*PciId)->Device = device; 9445cff7825Smh (*PciId)->Function = func; 9455cff7825Smh } else if (acpica_eval_int(handle, "_ADR", &devfn) == AE_OK) { 9465cff7825Smh /* no devinfo node - just confirm the d/f */ 9475cff7825Smh (*PciId)->Device = (devfn >> 16) & 0xFFFF; 9485cff7825Smh (*PciId)->Function = devfn & 0xFFFF; 9497c478bd9Sstevel@tonic-gate } 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate 95327f7c583Smyers /*ARGSUSED*/ 9547c478bd9Sstevel@tonic-gate BOOLEAN 9557c478bd9Sstevel@tonic-gate AcpiOsReadable(void *Pointer, ACPI_SIZE Length) 9567c478bd9Sstevel@tonic-gate { 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate /* Always says yes; all mapped memory assumed readable */ 9597c478bd9Sstevel@tonic-gate return (1); 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate 96227f7c583Smyers /*ARGSUSED*/ 9637c478bd9Sstevel@tonic-gate BOOLEAN 9647c478bd9Sstevel@tonic-gate AcpiOsWritable(void *Pointer, ACPI_SIZE Length) 9657c478bd9Sstevel@tonic-gate { 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate /* Always says yes; all mapped memory assumed writable */ 9687c478bd9Sstevel@tonic-gate return (1); 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate UINT64 9727c478bd9Sstevel@tonic-gate AcpiOsGetTimer(void) 9737c478bd9Sstevel@tonic-gate { 97427f7c583Smyers /* gethrtime() returns 1nS resolution; convert to 100nS granules */ 97527f7c583Smyers return ((gethrtime() + 50) / 100); 97627f7c583Smyers } 9777c478bd9Sstevel@tonic-gate 97827f7c583Smyers /*ARGSUSED*/ 97927f7c583Smyers ACPI_STATUS 98027f7c583Smyers AcpiOsValidateInterface(char *interface) 98127f7c583Smyers { 98227f7c583Smyers return (AE_SUPPORT); 98327f7c583Smyers } 9847c478bd9Sstevel@tonic-gate 98527f7c583Smyers /*ARGSUSED*/ 98627f7c583Smyers ACPI_STATUS 98727f7c583Smyers AcpiOsValidateAddress(UINT8 spaceid, ACPI_PHYSICAL_ADDRESS addr, 98827f7c583Smyers ACPI_SIZE length) 98927f7c583Smyers { 99027f7c583Smyers return (AE_OK); 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate ACPI_STATUS 9947c478bd9Sstevel@tonic-gate AcpiOsSignal(UINT32 Function, void *Info) 9957c478bd9Sstevel@tonic-gate { 9967c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(Function, Info)) 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate /* FUTUREWORK: debugger support */ 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!OsSignal unimplemented"); 10017c478bd9Sstevel@tonic-gate return (AE_OK); 10027c478bd9Sstevel@tonic-gate } 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate void ACPI_INTERNAL_VAR_XFACE 10057c478bd9Sstevel@tonic-gate AcpiOsPrintf(const char *Format, ...) 10067c478bd9Sstevel@tonic-gate { 10077c478bd9Sstevel@tonic-gate va_list ap; 1008186507a7Smyers 1009186507a7Smyers va_start(ap, Format); 1010186507a7Smyers AcpiOsVprintf(Format, ap); 1011186507a7Smyers va_end(ap); 1012186507a7Smyers } 1013186507a7Smyers 1014186507a7Smyers /* 1015186507a7Smyers * When != 0, sends output to console 1016186507a7Smyers * Patchable with kmdb or /etc/system. 1017186507a7Smyers */ 1018186507a7Smyers int acpica_console_out = 0; 1019186507a7Smyers 1020186507a7Smyers #define ACPICA_OUTBUF_LEN 160 1021186507a7Smyers char acpica_outbuf[ACPICA_OUTBUF_LEN]; 1022186507a7Smyers int acpica_outbuf_offset; 1023186507a7Smyers 1024186507a7Smyers /* 1025186507a7Smyers * 1026186507a7Smyers */ 1027186507a7Smyers static void 1028*87bb58d6Smyers acpica_pr_buf(char *buf) 1029186507a7Smyers { 1030186507a7Smyers char c, *bufp, *outp; 1031186507a7Smyers int out_remaining; 1032186507a7Smyers 1033186507a7Smyers /* 1034186507a7Smyers * copy the supplied buffer into the output buffer 1035186507a7Smyers * when we hit a '\n' or overflow the output buffer, 1036186507a7Smyers * output and reset the output buffer 1037186507a7Smyers */ 1038186507a7Smyers bufp = buf; 1039186507a7Smyers outp = acpica_outbuf + acpica_outbuf_offset; 1040186507a7Smyers out_remaining = ACPICA_OUTBUF_LEN - acpica_outbuf_offset - 1; 1041186507a7Smyers while (c = *bufp++) { 1042186507a7Smyers *outp++ = c; 1043186507a7Smyers if (c == '\n' || --out_remaining == 0) { 1044186507a7Smyers *outp = '\0'; 1045186507a7Smyers if (acpica_console_out) 1046186507a7Smyers printf(acpica_outbuf); 1047186507a7Smyers else 1048186507a7Smyers (void) strlog(0, 0, 0, 1049186507a7Smyers SL_CONSOLE | SL_NOTE | SL_LOGONLY, 1050186507a7Smyers acpica_outbuf); 1051186507a7Smyers acpica_outbuf_offset = 0; 1052186507a7Smyers outp = acpica_outbuf; 1053186507a7Smyers out_remaining = ACPICA_OUTBUF_LEN - 1; 1054186507a7Smyers } 1055186507a7Smyers } 1056186507a7Smyers 1057186507a7Smyers acpica_outbuf_offset = outp - acpica_outbuf; 1058186507a7Smyers } 1059186507a7Smyers 1060186507a7Smyers void 1061186507a7Smyers AcpiOsVprintf(const char *Format, va_list Args) 1062186507a7Smyers { 10637c478bd9Sstevel@tonic-gate 10647c478bd9Sstevel@tonic-gate /* 1065*87bb58d6Smyers * If AcpiOsInitialize() failed to allocate a string buffer, 1066*87bb58d6Smyers * resort to vprintf(). 10677c478bd9Sstevel@tonic-gate */ 1068*87bb58d6Smyers if (acpi_osl_pr_buffer == NULL) { 1069186507a7Smyers vprintf(Format, Args); 10707c478bd9Sstevel@tonic-gate return; 10717c478bd9Sstevel@tonic-gate } 1072*87bb58d6Smyers 1073*87bb58d6Smyers /* 1074*87bb58d6Smyers * It is possible that a very long debug output statement will 1075*87bb58d6Smyers * be truncated; this is silently ignored. 1076*87bb58d6Smyers */ 1077*87bb58d6Smyers (void) vsnprintf(acpi_osl_pr_buffer, acpi_osl_pr_buflen, Format, Args); 1078*87bb58d6Smyers acpica_pr_buf(acpi_osl_pr_buffer); 10797c478bd9Sstevel@tonic-gate } 10807c478bd9Sstevel@tonic-gate 10817c478bd9Sstevel@tonic-gate void 10827c478bd9Sstevel@tonic-gate AcpiOsRedirectOutput(void *Destination) 10837c478bd9Sstevel@tonic-gate { 10847c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(Destination)) 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate /* FUTUREWORK: debugger support */ 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate #ifdef DEBUG 10897c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!acpica: AcpiOsRedirectOutput called"); 10907c478bd9Sstevel@tonic-gate #endif 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate UINT32 10957c478bd9Sstevel@tonic-gate AcpiOsGetLine(char *Buffer) 10967c478bd9Sstevel@tonic-gate { 10977c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(Buffer)) 10987c478bd9Sstevel@tonic-gate 10997c478bd9Sstevel@tonic-gate /* FUTUREWORK: debugger support */ 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate return (0); 11027c478bd9Sstevel@tonic-gate } 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate /* 11087c478bd9Sstevel@tonic-gate * Device tree binding 11097c478bd9Sstevel@tonic-gate */ 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate static int 11127c478bd9Sstevel@tonic-gate acpica_find_pcibus(int busno, ACPI_HANDLE *rh) 11137c478bd9Sstevel@tonic-gate { 11147c478bd9Sstevel@tonic-gate ACPI_HANDLE sbobj, busobj; 11157c478bd9Sstevel@tonic-gate int hid, bbn; 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate /* initialize static flag by querying ACPI namespace for bug */ 11187c478bd9Sstevel@tonic-gate if (acpi_has_broken_bbn == -1) 11197c478bd9Sstevel@tonic-gate acpi_has_broken_bbn = acpica_query_bbn_problem(); 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate busobj = NULL; 11227c478bd9Sstevel@tonic-gate AcpiGetHandle(NULL, "\\_SB", &sbobj); 11237c478bd9Sstevel@tonic-gate while (AcpiGetNextObject(ACPI_TYPE_DEVICE, sbobj, busobj, 11247c478bd9Sstevel@tonic-gate &busobj) == AE_OK) { 11257c478bd9Sstevel@tonic-gate if (acpica_eval_hid(busobj, "_HID", &hid) == AE_OK && 11267c478bd9Sstevel@tonic-gate (hid == HID_PCI_BUS || hid == HID_PCI_EXPRESS_BUS)) { 11277c478bd9Sstevel@tonic-gate if (acpi_has_broken_bbn) { 11287c478bd9Sstevel@tonic-gate ACPI_BUFFER rb; 11297c478bd9Sstevel@tonic-gate rb.Pointer = NULL; 11307c478bd9Sstevel@tonic-gate rb.Length = ACPI_ALLOCATE_BUFFER; 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate /* Decree _BBN == n from PCI<n> */ 11337c478bd9Sstevel@tonic-gate if (AcpiGetName(busobj, ACPI_SINGLE_NAME, &rb) 11345dff2f34Smyers != AE_OK) { 11357c478bd9Sstevel@tonic-gate return (AE_ERROR); 11367c478bd9Sstevel@tonic-gate } 11377c478bd9Sstevel@tonic-gate bbn = ((char *)rb.Pointer)[3] - '0'; 11387c478bd9Sstevel@tonic-gate AcpiOsFree(rb.Pointer); 11397c478bd9Sstevel@tonic-gate if (bbn == busno || busno == 0) { 11407c478bd9Sstevel@tonic-gate *rh = busobj; 11417c478bd9Sstevel@tonic-gate return (AE_OK); 11427c478bd9Sstevel@tonic-gate } 11437c478bd9Sstevel@tonic-gate } else { 11447c478bd9Sstevel@tonic-gate if (acpica_eval_int(busobj, "_BBN", &bbn) == 11457c478bd9Sstevel@tonic-gate AE_OK) { 11467c478bd9Sstevel@tonic-gate if (bbn == busno) { 11477c478bd9Sstevel@tonic-gate *rh = busobj; 11487c478bd9Sstevel@tonic-gate return (AE_OK); 11497c478bd9Sstevel@tonic-gate } 11507c478bd9Sstevel@tonic-gate } else if (busno == 0) { 11517c478bd9Sstevel@tonic-gate *rh = busobj; 11527c478bd9Sstevel@tonic-gate return (AE_OK); 11537c478bd9Sstevel@tonic-gate } 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate } 11567c478bd9Sstevel@tonic-gate } 11577c478bd9Sstevel@tonic-gate return (AE_ERROR); 11587c478bd9Sstevel@tonic-gate } 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate /* 11627c478bd9Sstevel@tonic-gate * Look for ACPI problem where _BBN is zero for multiple PCI buses 11637c478bd9Sstevel@tonic-gate * This is a clear ACPI bug, but we have a workaround in acpica_find_pcibus() 11647c478bd9Sstevel@tonic-gate * below if it exists. 11657c478bd9Sstevel@tonic-gate */ 11667c478bd9Sstevel@tonic-gate static int 11677c478bd9Sstevel@tonic-gate acpica_query_bbn_problem(void) 11687c478bd9Sstevel@tonic-gate { 11697c478bd9Sstevel@tonic-gate ACPI_HANDLE sbobj, busobj; 11707c478bd9Sstevel@tonic-gate int hid, bbn; 11717c478bd9Sstevel@tonic-gate int zerobbncnt; 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate busobj = NULL; 11747c478bd9Sstevel@tonic-gate zerobbncnt = 0; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate AcpiGetHandle(NULL, "\\_SB", &sbobj); 11777c478bd9Sstevel@tonic-gate 11787c478bd9Sstevel@tonic-gate while (AcpiGetNextObject(ACPI_TYPE_DEVICE, sbobj, busobj, 11797c478bd9Sstevel@tonic-gate &busobj) == AE_OK) { 11807c478bd9Sstevel@tonic-gate if ((acpica_eval_hid(busobj, "_HID", &hid) == AE_OK) && 11817c478bd9Sstevel@tonic-gate (hid == HID_PCI_BUS || hid == HID_PCI_EXPRESS_BUS) && 11827c478bd9Sstevel@tonic-gate (acpica_eval_int(busobj, "_BBN", &bbn) == AE_OK)) { 11837c478bd9Sstevel@tonic-gate if (bbn == 0) { 11847c478bd9Sstevel@tonic-gate /* 11857c478bd9Sstevel@tonic-gate * If we find more than one bus with a 0 _BBN 11867c478bd9Sstevel@tonic-gate * we have the problem that BigBear's BIOS shows 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate if (++zerobbncnt > 1) 11897c478bd9Sstevel@tonic-gate return (1); 11907c478bd9Sstevel@tonic-gate } 11917c478bd9Sstevel@tonic-gate } 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate return (0); 11947c478bd9Sstevel@tonic-gate } 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate static const char hextab[] = "0123456789ABCDEF"; 11977c478bd9Sstevel@tonic-gate 11987c478bd9Sstevel@tonic-gate static int 11997c478bd9Sstevel@tonic-gate hexdig(int c) 12007c478bd9Sstevel@tonic-gate { 12017c478bd9Sstevel@tonic-gate /* 12027c478bd9Sstevel@tonic-gate * Get hex digit: 12037c478bd9Sstevel@tonic-gate * 12047c478bd9Sstevel@tonic-gate * Returns the 4-bit hex digit named by the input character. Returns 12057c478bd9Sstevel@tonic-gate * zero if the input character is not valid hex! 12067c478bd9Sstevel@tonic-gate */ 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate int x = ((c < 'a') || (c > 'z')) ? c : (c - ' '); 12097c478bd9Sstevel@tonic-gate int j = sizeof (hextab); 12107c478bd9Sstevel@tonic-gate 12115dff2f34Smyers while (--j && (x != hextab[j])) { 12125dff2f34Smyers } 12137c478bd9Sstevel@tonic-gate return (j); 12147c478bd9Sstevel@tonic-gate } 12157c478bd9Sstevel@tonic-gate 12167c478bd9Sstevel@tonic-gate static int 12177c478bd9Sstevel@tonic-gate CompressEisaID(char *np) 12187c478bd9Sstevel@tonic-gate { 12197c478bd9Sstevel@tonic-gate /* 12207c478bd9Sstevel@tonic-gate * Compress an EISA device name: 12217c478bd9Sstevel@tonic-gate * 12227c478bd9Sstevel@tonic-gate * This routine converts a 7-byte ASCII device name into the 4-byte 12237c478bd9Sstevel@tonic-gate * compressed form used by EISA (50 bytes of ROM to save 1 byte of 12247c478bd9Sstevel@tonic-gate * NV-RAM!) 12257c478bd9Sstevel@tonic-gate */ 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate union { char octets[4]; int retval; } myu; 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate myu.octets[0] = ((np[0] & 0x1F) << 2) + ((np[1] >> 3) & 0x03); 12307c478bd9Sstevel@tonic-gate myu.octets[1] = ((np[1] & 0x07) << 5) + (np[2] & 0x1F); 12317c478bd9Sstevel@tonic-gate myu.octets[2] = (hexdig(np[3]) << 4) + hexdig(np[4]); 12327c478bd9Sstevel@tonic-gate myu.octets[3] = (hexdig(np[5]) << 4) + hexdig(np[6]); 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate return (myu.retval); 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate 12375cff7825Smh ACPI_STATUS 12387c478bd9Sstevel@tonic-gate acpica_eval_int(ACPI_HANDLE dev, char *method, int *rint) 12397c478bd9Sstevel@tonic-gate { 12407c478bd9Sstevel@tonic-gate ACPI_STATUS status; 12417c478bd9Sstevel@tonic-gate ACPI_BUFFER rb; 12427c478bd9Sstevel@tonic-gate ACPI_OBJECT ro; 12437c478bd9Sstevel@tonic-gate 12447c478bd9Sstevel@tonic-gate rb.Pointer = &ro; 12457c478bd9Sstevel@tonic-gate rb.Length = sizeof (ro); 12467c478bd9Sstevel@tonic-gate if ((status = AcpiEvaluateObjectTyped(dev, method, NULL, &rb, 12475dff2f34Smyers ACPI_TYPE_INTEGER)) == AE_OK) 12487c478bd9Sstevel@tonic-gate *rint = ro.Integer.Value; 12497c478bd9Sstevel@tonic-gate 12507c478bd9Sstevel@tonic-gate return (status); 12517c478bd9Sstevel@tonic-gate } 12527c478bd9Sstevel@tonic-gate 12537c478bd9Sstevel@tonic-gate static int 12547c478bd9Sstevel@tonic-gate acpica_eval_hid(ACPI_HANDLE dev, char *method, int *rint) 12557c478bd9Sstevel@tonic-gate { 12567c478bd9Sstevel@tonic-gate ACPI_BUFFER rb; 12577c478bd9Sstevel@tonic-gate ACPI_OBJECT *rv; 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate rb.Pointer = NULL; 12607c478bd9Sstevel@tonic-gate rb.Length = ACPI_ALLOCATE_BUFFER; 12617c478bd9Sstevel@tonic-gate if (AcpiEvaluateObject(dev, method, NULL, &rb) == AE_OK) { 12627c478bd9Sstevel@tonic-gate rv = rb.Pointer; 12637c478bd9Sstevel@tonic-gate if (rv->Type == ACPI_TYPE_INTEGER) { 12647c478bd9Sstevel@tonic-gate *rint = rv->Integer.Value; 12657c478bd9Sstevel@tonic-gate AcpiOsFree(rv); 12667c478bd9Sstevel@tonic-gate return (AE_OK); 12677c478bd9Sstevel@tonic-gate } else if (rv->Type == ACPI_TYPE_STRING) { 12687c478bd9Sstevel@tonic-gate char *stringData; 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* Convert the string into an EISA ID */ 12717c478bd9Sstevel@tonic-gate if (rv->String.Pointer == NULL) { 12727c478bd9Sstevel@tonic-gate AcpiOsFree(rv); 12737c478bd9Sstevel@tonic-gate return (AE_ERROR); 12747c478bd9Sstevel@tonic-gate } 12757c478bd9Sstevel@tonic-gate 12767c478bd9Sstevel@tonic-gate stringData = rv->String.Pointer; 12777c478bd9Sstevel@tonic-gate 12787c478bd9Sstevel@tonic-gate /* 12797c478bd9Sstevel@tonic-gate * If the string is an EisaID, it must be 7 12807c478bd9Sstevel@tonic-gate * characters; if it's an ACPI ID, it will be 8 12817c478bd9Sstevel@tonic-gate * (and we don't care about ACPI ids here). 12827c478bd9Sstevel@tonic-gate */ 12837c478bd9Sstevel@tonic-gate if (strlen(stringData) != 7) { 12847c478bd9Sstevel@tonic-gate AcpiOsFree(rv); 12857c478bd9Sstevel@tonic-gate return (AE_ERROR); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate *rint = CompressEisaID(stringData); 12897c478bd9Sstevel@tonic-gate AcpiOsFree(rv); 12907c478bd9Sstevel@tonic-gate return (AE_OK); 12917c478bd9Sstevel@tonic-gate } else 12927c478bd9Sstevel@tonic-gate AcpiOsFree(rv); 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate return (AE_ERROR); 12957c478bd9Sstevel@tonic-gate } 12967c478bd9Sstevel@tonic-gate 12977c478bd9Sstevel@tonic-gate /* 12985cff7825Smh * Create linkage between devinfo nodes and ACPI nodes 12997c478bd9Sstevel@tonic-gate */ 13005cff7825Smh static void 13015cff7825Smh acpica_tag_devinfo(dev_info_t *dip, ACPI_HANDLE acpiobj) 13027c478bd9Sstevel@tonic-gate { 13035cff7825Smh ACPI_STATUS status; 13045cff7825Smh ACPI_BUFFER rb; 13057c478bd9Sstevel@tonic-gate 13065cff7825Smh /* 13075cff7825Smh * Tag the ACPI node with the dip 13085cff7825Smh */ 13095cff7825Smh status = acpica_set_devinfo(acpiobj, dip); 13105cff7825Smh ASSERT(status == AE_OK); 13117c478bd9Sstevel@tonic-gate 13125cff7825Smh /* 13135cff7825Smh * Tag the devinfo node with the ACPI name 13145cff7825Smh */ 13155cff7825Smh rb.Pointer = NULL; 13165cff7825Smh rb.Length = ACPI_ALLOCATE_BUFFER; 13175cff7825Smh if (AcpiGetName(acpiobj, ACPI_FULL_PATHNAME, &rb) == AE_OK) { 13185cff7825Smh (void) ndi_prop_update_string(DDI_DEV_T_NONE, dip, 13195cff7825Smh "acpi-namespace", (char *)rb.Pointer); 13205cff7825Smh AcpiOsFree(rb.Pointer); 13215cff7825Smh } else { 13225cff7825Smh cmn_err(CE_WARN, "acpica: could not get ACPI path!"); 13235cff7825Smh } 13247c478bd9Sstevel@tonic-gate } 13257c478bd9Sstevel@tonic-gate 13265cff7825Smh static void 13275cff7825Smh acpica_add_processor_to_map(UINT32 acpi_id, ACPI_HANDLE obj) 13287c478bd9Sstevel@tonic-gate { 13295cff7825Smh int cpu_id; 13307c478bd9Sstevel@tonic-gate 13315cff7825Smh /* 13325cff7825Smh * Special case: if we're a uppc system, there won't be 13335cff7825Smh * a CPU map yet. So we create one and use the passed-in 13345cff7825Smh * processor as CPU 0 13355cff7825Smh */ 13365cff7825Smh if (cpu_map == NULL) { 13375cff7825Smh cpu_map = kmem_zalloc(sizeof (cpu_map[0]) * NCPU, KM_SLEEP); 13385cff7825Smh cpu_map[0] = kmem_zalloc(sizeof (*cpu_map[0]), KM_SLEEP); 13395cff7825Smh cpu_map[0]->obj = obj; 13405cff7825Smh cpu_map_count = 1; 13415cff7825Smh return; 13425cff7825Smh } 13435cff7825Smh 13445cff7825Smh for (cpu_id = 0; cpu_id < NCPU; cpu_id++) { 13455cff7825Smh if (cpu_map[cpu_id] == NULL) 13465cff7825Smh continue; 13475cff7825Smh 13485cff7825Smh if (cpu_map[cpu_id]->mpa->ProcessorId == acpi_id) { 13495cff7825Smh cpu_map[cpu_id]->obj = obj; 13505cff7825Smh break; 13517c478bd9Sstevel@tonic-gate } 13525cff7825Smh } 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate /* 1357495256c0Smh * Return the ACPI device node matching the CPU dev_info node. 13587c478bd9Sstevel@tonic-gate */ 13595cff7825Smh ACPI_STATUS 13605cff7825Smh acpica_get_handle_cpu(dev_info_t *dip, ACPI_HANDLE *rh) 13617c478bd9Sstevel@tonic-gate { 13625cff7825Smh char *device_type_prop; 13635cff7825Smh int cpu_id; 13647c478bd9Sstevel@tonic-gate 13655cff7825Smh /* 13665cff7825Smh * if "device_type" != "cpu", error 13675cff7825Smh */ 1368495256c0Smh if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, 1369495256c0Smh "device_type", &device_type_prop) != DDI_PROP_SUCCESS) 1370495256c0Smh return (AE_ERROR); 1371495256c0Smh 1372495256c0Smh if (strcmp("cpu", device_type_prop) != 0) { 13735cff7825Smh ddi_prop_free(device_type_prop); 13745cff7825Smh return (AE_ERROR); 13755cff7825Smh } 13765cff7825Smh ddi_prop_free(device_type_prop); 13777c478bd9Sstevel@tonic-gate 13785cff7825Smh /* 13795cff7825Smh * if cpu_map itself is NULL, we're a uppc system and 13805cff7825Smh * acpica_build_processor_map() hasn't been called yet. 13815cff7825Smh * So call it here 13825cff7825Smh */ 13835cff7825Smh if (cpu_map == NULL) { 13845cff7825Smh (void) acpica_build_processor_map(); 13855cff7825Smh if (cpu_map == NULL) 13865cff7825Smh return (AE_ERROR); 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate 13895cff7825Smh /* 13905cff7825Smh * get 'reg' and get obj from cpu_map 13915cff7825Smh */ 13925cff7825Smh cpu_id = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 13935cff7825Smh "reg", -1); 13945cff7825Smh if ((cpu_id < 0) || (cpu_map[cpu_id] == NULL) || 13955cff7825Smh (cpu_map[cpu_id]->obj == NULL)) 13965cff7825Smh return (AE_ERROR); 13975cff7825Smh 13985cff7825Smh /* 13995cff7825Smh * tag devinfo and obj 14005cff7825Smh */ 14015cff7825Smh (void) acpica_tag_devinfo(dip, cpu_map[cpu_id]->obj); 14025cff7825Smh *rh = cpu_map[cpu_id]->obj; 14035cff7825Smh return (AE_OK); 14045cff7825Smh } 14055cff7825Smh 14065cff7825Smh /* 14075cff7825Smh * Determine if this object is a processor 14085cff7825Smh */ 14095cff7825Smh static ACPI_STATUS 14105cff7825Smh acpica_probe_processor(ACPI_HANDLE obj, UINT32 level, void *ctx, void **rv) 14115cff7825Smh { 14125cff7825Smh ACPI_STATUS status; 14135cff7825Smh ACPI_OBJECT_TYPE objtype; 14145cff7825Smh UINT32 acpi_id; 14155cff7825Smh ACPI_BUFFER rb; 14165cff7825Smh 14175cff7825Smh if (AcpiGetType(obj, &objtype) != AE_OK) 14185cff7825Smh return (AE_OK); 14195cff7825Smh 14205cff7825Smh if (objtype == ACPI_TYPE_PROCESSOR) { 14215cff7825Smh /* process a Processor */ 14227c478bd9Sstevel@tonic-gate rb.Pointer = NULL; 14237c478bd9Sstevel@tonic-gate rb.Length = ACPI_ALLOCATE_BUFFER; 14245cff7825Smh status = AcpiEvaluateObject(obj, NULL, NULL, &rb); 14255cff7825Smh if (status != AE_OK) { 14265cff7825Smh cmn_err(CE_WARN, "acpica: error probing Processor"); 14275cff7825Smh return (status); 14287c478bd9Sstevel@tonic-gate } 14295cff7825Smh ASSERT(((ACPI_OBJECT *)rb.Pointer)->Type == 14305cff7825Smh ACPI_TYPE_PROCESSOR); 14315cff7825Smh acpi_id = ((ACPI_OBJECT *)rb.Pointer)->Processor.ProcId; 14325cff7825Smh AcpiOsFree(rb.Pointer); 14335cff7825Smh } else if (objtype == ACPI_TYPE_DEVICE) { 14345cff7825Smh /* process a processor Device */ 14355cff7825Smh cmn_err(CE_WARN, "!acpica: probe found a processor Device\n"); 14365cff7825Smh cmn_err(CE_WARN, "!acpica: no support for processor Devices\n"); 14375cff7825Smh return (AE_OK); 14387c478bd9Sstevel@tonic-gate } 14395cff7825Smh 14405cff7825Smh acpica_add_processor_to_map(acpi_id, obj); 14415cff7825Smh return (AE_OK); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate 14445cff7825Smh 14457c478bd9Sstevel@tonic-gate static void 14465cff7825Smh scan_d2a_map(void) 14477c478bd9Sstevel@tonic-gate { 14487c478bd9Sstevel@tonic-gate dev_info_t *dip, *cdip; 14497c478bd9Sstevel@tonic-gate ACPI_HANDLE acpiobj; 14507c478bd9Sstevel@tonic-gate char *device_type_prop; 14517c478bd9Sstevel@tonic-gate int bus; 14527c478bd9Sstevel@tonic-gate static int map_error = 0; 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate if (map_error) 14557c478bd9Sstevel@tonic-gate return; 14567c478bd9Sstevel@tonic-gate 14575cff7825Smh scanning_d2a_map = 1; 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate /* 14607c478bd9Sstevel@tonic-gate * Find all child-of-root PCI buses, and find their corresponding 14617c478bd9Sstevel@tonic-gate * ACPI child-of-root PCI nodes. For each one, add to the 14627c478bd9Sstevel@tonic-gate * d2a table. 14637c478bd9Sstevel@tonic-gate */ 14647c478bd9Sstevel@tonic-gate 14657c478bd9Sstevel@tonic-gate for (dip = ddi_get_child(ddi_root_node()); 14667c478bd9Sstevel@tonic-gate dip != NULL; 14677c478bd9Sstevel@tonic-gate dip = ddi_get_next_sibling(dip)) { 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate /* prune non-PCI nodes */ 14707c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, 14717c478bd9Sstevel@tonic-gate "device_type", &device_type_prop) != DDI_PROP_SUCCESS) 14727c478bd9Sstevel@tonic-gate continue; 14737c478bd9Sstevel@tonic-gate 147470025d76Sjohnny if ((strcmp("pci", device_type_prop) != 0) && 147570025d76Sjohnny (strcmp("pciex", device_type_prop) != 0)) { 14767c478bd9Sstevel@tonic-gate ddi_prop_free(device_type_prop); 14777c478bd9Sstevel@tonic-gate continue; 14787c478bd9Sstevel@tonic-gate } 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate ddi_prop_free(device_type_prop); 14817c478bd9Sstevel@tonic-gate 14827c478bd9Sstevel@tonic-gate /* 14837c478bd9Sstevel@tonic-gate * To get bus number of dip, get first child and get its 14847c478bd9Sstevel@tonic-gate * bus number. If NULL, just continue, because we don't 14857c478bd9Sstevel@tonic-gate * care about bus nodes with no children anyway. 14867c478bd9Sstevel@tonic-gate */ 14877c478bd9Sstevel@tonic-gate if ((cdip = ddi_get_child(dip)) == NULL) 14887c478bd9Sstevel@tonic-gate continue; 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate if (acpica_get_bdf(cdip, &bus, NULL, NULL) < 0) { 14917c478bd9Sstevel@tonic-gate #ifdef D2ADEBUG 14927c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Can't get bus number of PCI child?"); 14937c478bd9Sstevel@tonic-gate #endif 14947c478bd9Sstevel@tonic-gate map_error = 1; 14955cff7825Smh scanning_d2a_map = 0; 14965cff7825Smh d2a_done = 1; 14977c478bd9Sstevel@tonic-gate return; 14987c478bd9Sstevel@tonic-gate } 14997c478bd9Sstevel@tonic-gate 15007c478bd9Sstevel@tonic-gate if (acpica_find_pcibus(bus, &acpiobj) == AE_ERROR) { 15017c478bd9Sstevel@tonic-gate #ifdef D2ADEBUG 15027c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "No ACPI bus obj for bus %d?\n", bus); 15037c478bd9Sstevel@tonic-gate #endif 15047c478bd9Sstevel@tonic-gate map_error = 1; 15057c478bd9Sstevel@tonic-gate continue; 15067c478bd9Sstevel@tonic-gate } 15077c478bd9Sstevel@tonic-gate 15085cff7825Smh acpica_tag_devinfo(dip, acpiobj); 15097c478bd9Sstevel@tonic-gate 15105cff7825Smh /* call recursively to enumerate subtrees */ 15115cff7825Smh scan_d2a_subtree(dip, acpiobj, bus); 15127c478bd9Sstevel@tonic-gate } 15135cff7825Smh 15145cff7825Smh scanning_d2a_map = 0; 15155cff7825Smh d2a_done = 1; 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate /* 15197c478bd9Sstevel@tonic-gate * For all acpi child devices of acpiobj, find their matching 15207c478bd9Sstevel@tonic-gate * dip under "dip" argument. (matching means "matches dev/fn"). 15217c478bd9Sstevel@tonic-gate * bus is assumed to already be a match from caller, and is 15227c478bd9Sstevel@tonic-gate * used here only to record in the d2a entry. Recurse if necessary. 15237c478bd9Sstevel@tonic-gate */ 15247c478bd9Sstevel@tonic-gate static void 15255cff7825Smh scan_d2a_subtree(dev_info_t *dip, ACPI_HANDLE acpiobj, int bus) 15267c478bd9Sstevel@tonic-gate { 15277c478bd9Sstevel@tonic-gate int acpi_devfn, hid; 15287c478bd9Sstevel@tonic-gate ACPI_HANDLE acld; 15297c478bd9Sstevel@tonic-gate dev_info_t *dcld; 15307c478bd9Sstevel@tonic-gate int dcld_b, dcld_d, dcld_f; 15317c478bd9Sstevel@tonic-gate int dev, func; 15325cff7825Smh char *device_type_prop; 15337c478bd9Sstevel@tonic-gate 15347c478bd9Sstevel@tonic-gate acld = NULL; 1535186507a7Smyers while (AcpiGetNextObject(ACPI_TYPE_DEVICE, acpiobj, acld, &acld) 15367c478bd9Sstevel@tonic-gate == AE_OK) { 15377c478bd9Sstevel@tonic-gate /* get the dev/func we're looking for in the devinfo tree */ 15387c478bd9Sstevel@tonic-gate if (acpica_eval_int(acld, "_ADR", &acpi_devfn) != AE_OK) 15397c478bd9Sstevel@tonic-gate continue; 15407c478bd9Sstevel@tonic-gate dev = (acpi_devfn >> 16) & 0xFFFF; 15417c478bd9Sstevel@tonic-gate func = acpi_devfn & 0xFFFF; 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate /* look through all the immediate children of dip */ 15447c478bd9Sstevel@tonic-gate for (dcld = ddi_get_child(dip); dcld != NULL; 15457c478bd9Sstevel@tonic-gate dcld = ddi_get_next_sibling(dcld)) { 15467c478bd9Sstevel@tonic-gate if (acpica_get_bdf(dcld, &dcld_b, &dcld_d, &dcld_f) < 0) 15477c478bd9Sstevel@tonic-gate continue; 15487c478bd9Sstevel@tonic-gate 15497c478bd9Sstevel@tonic-gate /* dev must match; function must match or wildcard */ 15507c478bd9Sstevel@tonic-gate if (dcld_d != dev || 15517c478bd9Sstevel@tonic-gate (func != 0xFFFF && func != dcld_f)) 15527c478bd9Sstevel@tonic-gate continue; 15537c478bd9Sstevel@tonic-gate bus = dcld_b; 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate /* found a match, record it */ 15565cff7825Smh acpica_tag_devinfo(dcld, acld); 15575cff7825Smh 15585cff7825Smh /* if we find a bridge, recurse from here */ 15595cff7825Smh if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dcld, 0, 15605cff7825Smh "device_type", &device_type_prop) == 15615cff7825Smh DDI_PROP_SUCCESS) { 15625cff7825Smh if ((strcmp("pci", device_type_prop) == 0) || 15635cff7825Smh (strcmp("pciex", device_type_prop) == 0)) 15645cff7825Smh scan_d2a_subtree(dcld, acld, bus); 15655cff7825Smh ddi_prop_free(device_type_prop); 15665cff7825Smh } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* done finding a match, so break now */ 15697c478bd9Sstevel@tonic-gate break; 15707c478bd9Sstevel@tonic-gate } 15718e56767dSsmall } 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate /* 15757c478bd9Sstevel@tonic-gate * Return bus/dev/fn for PCI dip (note: not the parent "pci" node). 15767c478bd9Sstevel@tonic-gate */ 15777c478bd9Sstevel@tonic-gate int 15787c478bd9Sstevel@tonic-gate acpica_get_bdf(dev_info_t *dip, int *bus, int *device, int *func) 15797c478bd9Sstevel@tonic-gate { 15807c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 15817c478bd9Sstevel@tonic-gate int len; 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 15847c478bd9Sstevel@tonic-gate "reg", (int **)&pci_rp, (uint_t *)&len) != DDI_SUCCESS) 15857c478bd9Sstevel@tonic-gate return (-1); 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate if (len < (sizeof (pci_regspec_t) / sizeof (int))) { 15887c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 15897c478bd9Sstevel@tonic-gate return (-1); 15907c478bd9Sstevel@tonic-gate } 15917c478bd9Sstevel@tonic-gate if (bus != NULL) 15927c478bd9Sstevel@tonic-gate *bus = (int)PCI_REG_BUS_G(pci_rp->pci_phys_hi); 15937c478bd9Sstevel@tonic-gate if (device != NULL) 15947c478bd9Sstevel@tonic-gate *device = (int)PCI_REG_DEV_G(pci_rp->pci_phys_hi); 15957c478bd9Sstevel@tonic-gate if (func != NULL) 15967c478bd9Sstevel@tonic-gate *func = (int)PCI_REG_FUNC_G(pci_rp->pci_phys_hi); 15977c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 15987c478bd9Sstevel@tonic-gate return (0); 15997c478bd9Sstevel@tonic-gate } 16005cff7825Smh 16015cff7825Smh /* 16025cff7825Smh * Return the ACPI device node matching this dev_info node, if it 16035cff7825Smh * exists in the ACPI tree. 16045cff7825Smh */ 16055cff7825Smh ACPI_STATUS 16065cff7825Smh acpica_get_handle(dev_info_t *dip, ACPI_HANDLE *rh) 16075cff7825Smh { 16085cff7825Smh ACPI_STATUS status; 16095cff7825Smh char *acpiname; 16105cff7825Smh 16115cff7825Smh if (!d2a_done) 16125cff7825Smh scan_d2a_map(); 16135cff7825Smh 16145cff7825Smh if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 16155cff7825Smh "acpi-namespace", &acpiname) != DDI_PROP_SUCCESS) { 16165cff7825Smh return (acpica_get_handle_cpu(dip, rh)); 16175cff7825Smh } 16185cff7825Smh 16195cff7825Smh status = AcpiGetHandle(NULL, acpiname, rh); 16205cff7825Smh ddi_prop_free((void *)acpiname); 16215cff7825Smh return (status); 16225cff7825Smh } 16235cff7825Smh 16245cff7825Smh 16255cff7825Smh 16265cff7825Smh /* 16275cff7825Smh * Manage OS data attachment to ACPI nodes 16285cff7825Smh */ 16295cff7825Smh 16305cff7825Smh /* 16315cff7825Smh * Return the (dev_info_t *) associated with the ACPI node. 16325cff7825Smh */ 16335cff7825Smh ACPI_STATUS 16345cff7825Smh acpica_get_devinfo(ACPI_HANDLE obj, dev_info_t **dipp) 16355cff7825Smh { 16365cff7825Smh ACPI_STATUS status; 16375cff7825Smh void *ptr; 16385cff7825Smh 16395cff7825Smh status = AcpiGetData(obj, acpica_devinfo_handler, &ptr); 16405cff7825Smh if (status == AE_OK) 16415cff7825Smh *dipp = (dev_info_t *)ptr; 16425cff7825Smh 16435cff7825Smh return (status); 16445cff7825Smh } 16455cff7825Smh 16465cff7825Smh /* 16475cff7825Smh * Set the dev_info_t associated with the ACPI node. 16485cff7825Smh */ 16495cff7825Smh static ACPI_STATUS 16505cff7825Smh acpica_set_devinfo(ACPI_HANDLE obj, dev_info_t *dip) 16515cff7825Smh { 16525cff7825Smh ACPI_STATUS status; 16535cff7825Smh 16545cff7825Smh status = AcpiAttachData(obj, acpica_devinfo_handler, (void *)dip); 16555cff7825Smh return (status); 16565cff7825Smh } 16575cff7825Smh 16585cff7825Smh 16595cff7825Smh /* 16605cff7825Smh * 16615cff7825Smh */ 16625cff7825Smh void 16635cff7825Smh acpica_devinfo_handler(ACPI_HANDLE obj, UINT32 func, void *data) 16645cff7825Smh { 16655cff7825Smh /* noop */ 16665cff7825Smh } 16675cff7825Smh 16685cff7825Smh 16695cff7825Smh /* 16705cff7825Smh * 16715cff7825Smh */ 16725cff7825Smh void 16735cff7825Smh acpica_map_cpu(processorid_t cpuid, MADT_PROCESSOR_APIC *mpa) 16745cff7825Smh { 16755cff7825Smh struct cpu_map_item *item; 16765cff7825Smh 16775cff7825Smh if (cpu_map == NULL) 16785cff7825Smh cpu_map = kmem_zalloc(sizeof (item) * NCPU, KM_SLEEP); 16795cff7825Smh 16805cff7825Smh item = kmem_zalloc(sizeof (*item), KM_SLEEP); 16815cff7825Smh item->mpa = mpa; 16825cff7825Smh item->obj = NULL; 16835cff7825Smh cpu_map[cpuid] = item; 16845cff7825Smh cpu_map_count++; 16855cff7825Smh } 16865cff7825Smh 16875cff7825Smh void 16885cff7825Smh acpica_build_processor_map() 16895cff7825Smh { 16905cff7825Smh ACPI_STATUS status; 16915cff7825Smh void *rv; 16925cff7825Smh 16935cff7825Smh /* 16945cff7825Smh * shouldn't be called more than once anyway 16955cff7825Smh */ 16965cff7825Smh if (cpu_map_built) 16975cff7825Smh return; 16985cff7825Smh 16995cff7825Smh /* 17005cff7825Smh * Look for Processor objects 17015cff7825Smh */ 17025cff7825Smh status = AcpiWalkNamespace(ACPI_TYPE_PROCESSOR, 17035cff7825Smh ACPI_ROOT_OBJECT, 17045cff7825Smh 4, 17055cff7825Smh acpica_probe_processor, 17065cff7825Smh NULL, 17075cff7825Smh &rv); 17085cff7825Smh ASSERT(status == AE_OK); 17095cff7825Smh 17105cff7825Smh /* 17115cff7825Smh * Look for processor Device objects 17125cff7825Smh */ 17135cff7825Smh status = AcpiGetDevices("ACPI0007", 17145cff7825Smh acpica_probe_processor, 17155cff7825Smh NULL, 17165cff7825Smh &rv); 17175cff7825Smh ASSERT(status == AE_OK); 17185cff7825Smh cpu_map_built = 1; 17195cff7825Smh } 1720