167761Smsmith/*- 267761Smsmith * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 367761Smsmith * Copyright (c) 2000 Michael Smith <msmith@freebsd.org> 467761Smsmith * Copyright (c) 2000 BSDi 567761Smsmith * All rights reserved. 667761Smsmith * 767761Smsmith * Redistribution and use in source and binary forms, with or without 867761Smsmith * modification, are permitted provided that the following conditions 967761Smsmith * are met: 1067761Smsmith * 1. Redistributions of source code must retain the above copyright 1167761Smsmith * notice, this list of conditions and the following disclaimer. 1267761Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1367761Smsmith * notice, this list of conditions and the following disclaimer in the 1467761Smsmith * documentation and/or other materials provided with the distribution. 1567761Smsmith * 1667761Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1767761Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1867761Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1967761Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2067761Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2167761Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2267761Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2367761Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2467761Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2567761Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2667761Smsmith * SUCH DAMAGE. 2767761Smsmith * 28143002Sobrien * $FreeBSD$ 2967761Smsmith */ 3067761Smsmith 31142753Snjl#ifndef _ACPIVAR_H_ 32142753Snjl#define _ACPIVAR_H_ 33142753Snjl 34142984Snjl#ifdef _KERNEL 35142984Snjl 36131283Snjl#include "acpi_if.h" 3767761Smsmith#include "bus_if.h" 3867761Smsmith#include <sys/eventhandler.h> 39153171Snjl#include <sys/ktr.h> 40105280Sjhb#include <sys/lock.h> 41105280Sjhb#include <sys/mutex.h> 42170976Snjl#include <sys/selinfo.h> 43133611Snjl#include <sys/sx.h> 44153171Snjl#include <sys/sysctl.h> 4567761Smsmith 4680028Stakawata#include <machine/bus.h> 4780028Stakawata#include <machine/resource.h> 4880028Stakawata 49170976Snjlstruct apm_clone_data; 5067761Smsmithstruct acpi_softc { 5167761Smsmith device_t acpi_dev; 52160824Snjl struct cdev *acpi_dev_t; 5367761Smsmith 5467761Smsmith int acpi_enabled; 5567761Smsmith int acpi_sstate; 5687566Siwasaki int acpi_sleep_disabled; 57216674Sjhb int acpi_resources_reserved; 5867761Smsmith 5971001Sjhb struct sysctl_ctx_list acpi_sysctl_ctx; 6071001Sjhb struct sysctl_oid *acpi_sysctl_tree; 6167761Smsmith int acpi_power_button_sx; 6267761Smsmith int acpi_sleep_button_sx; 6367761Smsmith int acpi_lid_switch_sx; 6478662Siwasaki 6585556Siwasaki int acpi_standby_sx; 6685556Siwasaki int acpi_suspend_sx; 6785556Siwasaki 68102402Siwasaki int acpi_sleep_delay; 6986133Siwasaki int acpi_s4bios; 70159543Snjl int acpi_do_disable; 7185699Siwasaki int acpi_verbose; 72160824Snjl int acpi_handle_reboot; 7385699Siwasaki 7480028Stakawata bus_dma_tag_t acpi_waketag; 7580028Stakawata bus_dmamap_t acpi_wakemap; 7680028Stakawata vm_offset_t acpi_wakeaddr; 77112581Sjake vm_paddr_t acpi_wakephys; 78170976Snjl 79170976Snjl int acpi_next_sstate; /* Next suspend Sx state. */ 80170976Snjl struct apm_clone_data *acpi_clone; /* Pseudo-dev for devd(8). */ 81170976Snjl STAILQ_HEAD(,apm_clone_data) apm_cdevs; /* All apm/apmctl/acpi cdevs. */ 82170976Snjl struct callout susp_force_to; /* Force suspend if no acks. */ 8367761Smsmith}; 8467761Smsmith 8567761Smsmithstruct acpi_device { 8667761Smsmith /* ACPI ivars */ 8767761Smsmith ACPI_HANDLE ad_handle; 8867761Smsmith void *ad_private; 89131341Snjl int ad_flags; 9067761Smsmith 91128225Snjl /* Resources */ 9267761Smsmith struct resource_list ad_rl; 93129783Snjl}; 9478994Smsmith 95170976Snjl/* Track device (/dev/{apm,apmctl} and /dev/acpi) notification status. */ 96170976Snjlstruct apm_clone_data { 97170976Snjl STAILQ_ENTRY(apm_clone_data) entries; 98170976Snjl struct cdev *cdev; 99170976Snjl int flags; 100170976Snjl#define ACPI_EVF_NONE 0 /* /dev/apm semantics */ 101170976Snjl#define ACPI_EVF_DEVD 1 /* /dev/acpi is handled via devd(8) */ 102170976Snjl#define ACPI_EVF_WRITE 2 /* Device instance is opened writable. */ 103170976Snjl int notify_status; 104170976Snjl#define APM_EV_NONE 0 /* Device not yet aware of pending sleep. */ 105170976Snjl#define APM_EV_NOTIFIED 1 /* Device saw next sleep state. */ 106170976Snjl#define APM_EV_ACKED 2 /* Device agreed sleep can occur. */ 107170976Snjl struct acpi_softc *acpi_sc; 108170976Snjl struct selinfo sel_read; 109170976Snjl}; 110170976Snjl 111131341Snjl#define ACPI_PRW_MAX_POWERRES 8 112131341Snjl 113129783Snjlstruct acpi_prw_data { 114129806Snjl ACPI_HANDLE gpe_handle; 115129806Snjl int gpe_bit; 116129806Snjl int lowest_wake; 117131341Snjl ACPI_OBJECT power_res[ACPI_PRW_MAX_POWERRES]; 118131341Snjl int power_res_count; 11967761Smsmith}; 12067761Smsmith 121129783Snjl/* Flags for each device defined in the AML namespace. */ 122131341Snjl#define ACPI_FLAG_WAKE_ENABLED 0x1 123129783Snjl 124135574Sjhb/* Macros for extracting parts of a PCI address from an _ADR value. */ 125135574Sjhb#define ACPI_ADR_PCI_SLOT(adr) (((adr) & 0xffff0000) >> 16) 126135574Sjhb#define ACPI_ADR_PCI_FUNC(adr) ((adr) & 0xffff) 127135574Sjhb 12867761Smsmith/* 129133611Snjl * Entry points to ACPI from above are global functions defined in this 130133611Snjl * file, sysctls, and I/O on the control device. Entry points from below 131133611Snjl * are interrupts (the SCI), notifies, task queue threads, and the thermal 132133611Snjl * zone polling thread. 133133611Snjl * 134133611Snjl * ACPI tables and global shared data are protected by a global lock 135133611Snjl * (acpi_mutex). 136133611Snjl * 137133611Snjl * Each ACPI device can have its own driver-specific mutex for protecting 138133611Snjl * shared access to local data. The ACPI_LOCK macros handle mutexes. 139133611Snjl * 140133611Snjl * Drivers that need to serialize access to functions (e.g., to route 141133611Snjl * interrupts, get/set control paths, etc.) should use the sx lock macros 142133611Snjl * (ACPI_SERIAL). 143133611Snjl * 144133611Snjl * ACPI-CA handles its own locking and should not be called with locks held. 145133611Snjl * 146133611Snjl * The most complicated path is: 147133611Snjl * GPE -> EC runs _Qxx -> _Qxx reads EC space -> GPE 148105280Sjhb */ 149133611Snjlextern struct mtx acpi_mutex; 150133611Snjl#define ACPI_LOCK(sys) mtx_lock(&sys##_mutex) 151133611Snjl#define ACPI_UNLOCK(sys) mtx_unlock(&sys##_mutex) 152133611Snjl#define ACPI_LOCK_ASSERT(sys) mtx_assert(&sys##_mutex, MA_OWNED); 153133611Snjl#define ACPI_LOCK_DECL(sys, name) \ 154133611Snjl static struct mtx sys##_mutex; \ 155133611Snjl MTX_SYSINIT(sys##_mutex, &sys##_mutex, name, MTX_DEF) 156133611Snjl#define ACPI_SERIAL_BEGIN(sys) sx_xlock(&sys##_sxlock) 157133611Snjl#define ACPI_SERIAL_END(sys) sx_xunlock(&sys##_sxlock) 158133611Snjl#define ACPI_SERIAL_ASSERT(sys) sx_assert(&sys##_sxlock, SX_XLOCKED); 159133611Snjl#define ACPI_SERIAL_DECL(sys, name) \ 160133611Snjl static struct sx sys##_sxlock; \ 161133611Snjl SX_SYSINIT(sys##_sxlock, &sys##_sxlock, name) 16278994Smsmith 16378994Smsmith/* 16491127Smsmith * ACPI CA does not define layers for non-ACPI CA drivers. 16591127Smsmith * We define some here within the range provided. 16691127Smsmith */ 167126517Snjl#define ACPI_AC_ADAPTER 0x00010000 168126517Snjl#define ACPI_BATTERY 0x00020000 169126517Snjl#define ACPI_BUS 0x00040000 170126517Snjl#define ACPI_BUTTON 0x00080000 171126517Snjl#define ACPI_EC 0x00100000 172126517Snjl#define ACPI_FAN 0x00200000 173126517Snjl#define ACPI_POWERRES 0x00400000 174125526Sphilip#define ACPI_PROCESSOR 0x00800000 175125526Sphilip#define ACPI_THERMAL 0x01000000 176126517Snjl#define ACPI_TIMER 0x02000000 177138825Snjl#define ACPI_OEM 0x04000000 17891127Smsmith 17991127Smsmith/* 180103015Sjhb * Constants for different interrupt models used with acpi_SetIntrModel(). 181103015Sjhb */ 182103015Sjhb#define ACPI_INTR_PIC 0 183103015Sjhb#define ACPI_INTR_APIC 1 184103015Sjhb#define ACPI_INTR_SAPIC 2 185103015Sjhb 186142257Sjhb/* 187144629Snjl * Various features and capabilities for the acpi_get_features() method. 188144629Snjl * In particular, these are used for the ACPI 3.0 _PDC and _OSC methods. 189219037Sjkim * See the Intel document titled "Intel Processor Vendor-Specific ACPI", 190219037Sjkim * number 302223-005. 191144629Snjl */ 192219037Sjkim#define ACPI_CAP_PERF_MSRS (1 << 0) /* Intel SpeedStep PERF_CTL MSRs */ 193219037Sjkim#define ACPI_CAP_C1_IO_HALT (1 << 1) /* Intel C1 "IO then halt" sequence */ 194219037Sjkim#define ACPI_CAP_THR_MSRS (1 << 2) /* Intel OnDemand throttling MSRs */ 195219037Sjkim#define ACPI_CAP_SMP_SAME (1 << 3) /* MP C1, Px, and Tx (all the same) */ 196219037Sjkim#define ACPI_CAP_SMP_SAME_C3 (1 << 4) /* MP C2 and C3 (all the same) */ 197219037Sjkim#define ACPI_CAP_SMP_DIFF_PX (1 << 5) /* MP Px (different, using _PSD) */ 198219037Sjkim#define ACPI_CAP_SMP_DIFF_CX (1 << 6) /* MP Cx (different, using _CSD) */ 199219037Sjkim#define ACPI_CAP_SMP_DIFF_TX (1 << 7) /* MP Tx (different, using _TSD) */ 200219037Sjkim#define ACPI_CAP_SMP_C1_NATIVE (1 << 8) /* MP C1 support other than halt */ 201219037Sjkim#define ACPI_CAP_SMP_C3_NATIVE (1 << 9) /* MP C2 and C3 support */ 202219037Sjkim#define ACPI_CAP_PX_HW_COORD (1 << 11) /* Intel P-state HW coordination */ 203144629Snjl 204144629Snjl/* 205142257Sjhb * Quirk flags. 206142257Sjhb * 207142257Sjhb * ACPI_Q_BROKEN: Disables all ACPI support. 208142257Sjhb * ACPI_Q_TIMER: Disables support for the ACPI timer. 209142257Sjhb * ACPI_Q_MADT_IRQ0: Specifies that ISA IRQ 0 is wired up to pin 0 of the 210142257Sjhb * first APIC and that the MADT should force that by ignoring the PC-AT 211142257Sjhb * compatible flag and ignoring overrides that redirect IRQ 0 to pin 2. 212142257Sjhb */ 213136270Snjlextern int acpi_quirks; 214131312Snjl#define ACPI_Q_OK 0 215142257Sjhb#define ACPI_Q_BROKEN (1 << 0) 216142257Sjhb#define ACPI_Q_TIMER (1 << 1) 217142257Sjhb#define ACPI_Q_MADT_IRQ0 (1 << 2) 218131312Snjl 219103015Sjhb/* 22082535Smsmith * Note that the low ivar values are reserved to provide 22182535Smsmith * interface compatibility with ISA drivers which can also 22282535Smsmith * attach to ACPI. 22382535Smsmith */ 22467761Smsmith#define ACPI_IVAR_HANDLE 0x100 225199016Savg#define ACPI_IVAR_UNUSED 0x101 /* Unused/reserved. */ 22667761Smsmith#define ACPI_IVAR_PRIVATE 0x102 227131341Snjl#define ACPI_IVAR_FLAGS 0x103 22867761Smsmith 229129783Snjl/* 230129783Snjl * Accessor functions for our ivars. Default value for BUS_READ_IVAR is 231129783Snjl * (type) 0. The <sys/bus.h> accessor functions don't check return values. 232129783Snjl */ 233129783Snjl#define __ACPI_BUS_ACCESSOR(varp, var, ivarp, ivar, type) \ 234129783Snjl \ 235129783Snjlstatic __inline type varp ## _get_ ## var(device_t dev) \ 236129783Snjl{ \ 237129783Snjl uintptr_t v = 0; \ 238129783Snjl BUS_READ_IVAR(device_get_parent(dev), dev, \ 239129783Snjl ivarp ## _IVAR_ ## ivar, &v); \ 240129783Snjl return ((type) v); \ 241129783Snjl} \ 242129783Snjl \ 243129783Snjlstatic __inline void varp ## _set_ ## var(device_t dev, type t) \ 244129783Snjl{ \ 245129783Snjl uintptr_t v = (uintptr_t) t; \ 246129783Snjl BUS_WRITE_IVAR(device_get_parent(dev), dev, \ 247129783Snjl ivarp ## _IVAR_ ## ivar, v); \ 248129594Snjl} 249129594Snjl 250129783Snjl__ACPI_BUS_ACCESSOR(acpi, handle, ACPI, HANDLE, ACPI_HANDLE) 251129783Snjl__ACPI_BUS_ACCESSOR(acpi, private, ACPI, PRIVATE, void *) 252131341Snjl__ACPI_BUS_ACCESSOR(acpi, flags, ACPI, FLAGS, int) 253129594Snjl 254197105Sjkimvoid acpi_fake_objhandler(ACPI_HANDLE h, void *data); 255130417Snjlstatic __inline device_t 256130417Snjlacpi_get_device(ACPI_HANDLE handle) 257130417Snjl{ 258130417Snjl void *dev = NULL; 259130417Snjl AcpiGetData(handle, acpi_fake_objhandler, &dev); 260130417Snjl return ((device_t)dev); 261130417Snjl} 262130417Snjl 263127700Snjlstatic __inline ACPI_OBJECT_TYPE 264127700Snjlacpi_get_type(device_t dev) 265127700Snjl{ 266127700Snjl ACPI_HANDLE h; 267127700Snjl ACPI_OBJECT_TYPE t; 268127700Snjl 269127700Snjl if ((h = acpi_get_handle(dev)) == NULL) 270127700Snjl return (ACPI_TYPE_NOT_FOUND); 271127700Snjl if (AcpiGetType(h, &t) != AE_OK) 272127700Snjl return (ACPI_TYPE_NOT_FOUND); 273127700Snjl return (t); 274127700Snjl} 275127700Snjl 276220338Sjkim/* Find the difference between two PM tick counts. */ 277220338Sjkimstatic __inline uint32_t 278220338Sjkimacpi_TimerDelta(uint32_t end, uint32_t start) 279220338Sjkim{ 280220338Sjkim 281220338Sjkim if (end < start && (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER) == 0) 282220338Sjkim end |= 0x01000000; 283220338Sjkim return (end - start); 284220338Sjkim} 285220338Sjkim 286102553Siwasaki#ifdef ACPI_DEBUGGER 287129806Snjlvoid acpi_EnterDebugger(void); 28867761Smsmith#endif 28967761Smsmith 29077432Smsmith#ifdef ACPI_DEBUG 29177432Smsmith#include <sys/cons.h> 29277432Smsmith#define STEP(x) do {printf x, printf("\n"); cngetc();} while (0) 29377432Smsmith#else 29477432Smsmith#define STEP(x) 29577432Smsmith#endif 29677432Smsmith 297119529Snjl#define ACPI_VPRINT(dev, acpi_sc, x...) do { \ 298119529Snjl if (acpi_get_verbose(acpi_sc)) \ 299119529Snjl device_printf(dev, x); \ 30086552Siwasaki} while (0) 30186552Siwasaki 302133188Snjl/* Values for the device _STA (status) method. */ 303133188Snjl#define ACPI_STA_PRESENT (1 << 0) 304133188Snjl#define ACPI_STA_ENABLED (1 << 1) 305133188Snjl#define ACPI_STA_SHOW_IN_UI (1 << 2) 306133188Snjl#define ACPI_STA_FUNCTIONAL (1 << 3) 307133188Snjl#define ACPI_STA_BATT_PRESENT (1 << 4) 308133188Snjl 309133188Snjl#define ACPI_DEVINFO_PRESENT(x, flags) \ 310133188Snjl (((x) & (flags)) == (flags)) 311133188Snjl#define ACPI_DEVICE_PRESENT(x) \ 312133188Snjl ACPI_DEVINFO_PRESENT(x, ACPI_STA_PRESENT | ACPI_STA_FUNCTIONAL) 313133188Snjl#define ACPI_BATTERY_PRESENT(x) \ 314133188Snjl ACPI_DEVINFO_PRESENT(x, ACPI_STA_PRESENT | ACPI_STA_FUNCTIONAL | \ 315133188Snjl ACPI_STA_BATT_PRESENT) 316133188Snjl 317197439Sjhb/* Callback function type for walking subtables within a table. */ 318197439Sjhbtypedef void acpi_subtable_handler(ACPI_SUBTABLE_HEADER *, void *); 319197439Sjhb 320129806SnjlBOOLEAN acpi_DeviceIsPresent(device_t dev); 321129806SnjlBOOLEAN acpi_BatteryIsPresent(device_t dev); 322129806SnjlACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path, 323129806Snjl ACPI_HANDLE *result); 324129806SnjlACPI_BUFFER *acpi_AllocBuffer(int size); 325129806SnjlACPI_STATUS acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp, 326129806Snjl UINT32 *number); 327129806SnjlACPI_STATUS acpi_GetInteger(ACPI_HANDLE handle, char *path, 328129806Snjl UINT32 *number); 329129806SnjlACPI_STATUS acpi_SetInteger(ACPI_HANDLE handle, char *path, 330129806Snjl UINT32 number); 331129806SnjlACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj, 332129806Snjl void (*func)(ACPI_OBJECT *comp, void *arg), void *arg); 333129806SnjlACPI_STATUS acpi_FindIndexedResource(ACPI_BUFFER *buf, int index, 334129806Snjl ACPI_RESOURCE **resp); 335129806SnjlACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *buf, 336129806Snjl ACPI_RESOURCE *res); 337129806SnjlACPI_STATUS acpi_OverrideInterruptLevel(UINT32 InterruptNumber); 338129806SnjlACPI_STATUS acpi_SetIntrModel(int model); 339170976Snjlint acpi_ReqSleepState(struct acpi_softc *sc, int state); 340170976Snjlint acpi_AckSleepState(struct apm_clone_data *clone, int error); 341129806SnjlACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state); 342129783Snjlint acpi_wake_set_enable(device_t dev, int enable); 343131341Snjlint acpi_parse_prw(ACPI_HANDLE h, struct acpi_prw_data *prw); 344129806SnjlACPI_STATUS acpi_Startup(void); 345129806Snjlvoid acpi_UserNotify(const char *subsystem, ACPI_HANDLE h, 346129806Snjl uint8_t notify); 347141371Snjlint acpi_bus_alloc_gas(device_t dev, int *type, int *rid, 348165875Snjl ACPI_GENERIC_ADDRESS *gas, struct resource **res, 349165875Snjl u_int flags); 350197439Sjhbvoid acpi_walk_subtables(void *first, void *end, 351197439Sjhb acpi_subtable_handler *handler, void *arg); 352208436SmavBOOLEAN acpi_MatchHid(ACPI_HANDLE h, const char *hid); 35367761Smsmith 35467761Smsmithstruct acpi_parse_resource_set { 355127679Snjl void (*set_init)(device_t dev, void *arg, void **context); 356119529Snjl void (*set_done)(device_t dev, void *context); 357223370Sjhb void (*set_ioport)(device_t dev, void *context, uint64_t base, 358223370Sjhb uint64_t length); 359223370Sjhb void (*set_iorange)(device_t dev, void *context, uint64_t low, 360223370Sjhb uint64_t high, uint64_t length, uint64_t align); 361223370Sjhb void (*set_memory)(device_t dev, void *context, uint64_t base, 362223370Sjhb uint64_t length); 363223370Sjhb void (*set_memoryrange)(device_t dev, void *context, uint64_t low, 364223370Sjhb uint64_t high, uint64_t length, uint64_t align); 365223370Sjhb void (*set_irq)(device_t dev, void *context, uint8_t *irq, 366129806Snjl int count, int trig, int pol); 367223370Sjhb void (*set_ext_irq)(device_t dev, void *context, uint32_t *irq, 368151948Sjkim int count, int trig, int pol); 369223370Sjhb void (*set_drq)(device_t dev, void *context, uint8_t *drq, 370129806Snjl int count); 371151948Sjkim void (*set_start_dependent)(device_t dev, void *context, 372129806Snjl int preference); 373151948Sjkim void (*set_end_dependent)(device_t dev, void *context); 37467761Smsmith}; 37567761Smsmith 376129806Snjlextern struct acpi_parse_resource_set acpi_res_parse_set; 377130981Sjhb 378177157Sjhbint acpi_identify(void); 379130981Sjhbvoid acpi_config_intr(device_t dev, ACPI_RESOURCE *res); 380130981SjhbACPI_STATUS acpi_lookup_irq_resource(device_t dev, int rid, 381130981Sjhb struct resource *res, ACPI_RESOURCE *acpi_res); 382129806SnjlACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, 383129806Snjl struct acpi_parse_resource_set *set, void *arg); 384227397Sjhbstruct resource *acpi_alloc_sysres(device_t child, int type, int *rid, 385227397Sjhb u_long start, u_long end, u_long count, u_int flags); 38667761Smsmith 387119529Snjl/* ACPI event handling */ 388129806SnjlUINT32 acpi_event_power_button_sleep(void *context); 389129806SnjlUINT32 acpi_event_power_button_wake(void *context); 390129806SnjlUINT32 acpi_event_sleep_button_sleep(void *context); 391129806SnjlUINT32 acpi_event_sleep_button_wake(void *context); 39267761Smsmith 39367761Smsmith#define ACPI_EVENT_PRI_FIRST 0 39467761Smsmith#define ACPI_EVENT_PRI_DEFAULT 10000 39567761Smsmith#define ACPI_EVENT_PRI_LAST 20000 39667761Smsmith 39792739Salfredtypedef void (*acpi_event_handler_t)(void *, int); 39867761Smsmith 39967761SmsmithEVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t); 40067761SmsmithEVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t); 40167761Smsmith 402119529Snjl/* Device power control. */ 403131341SnjlACPI_STATUS acpi_pwr_wake_enable(ACPI_HANDLE consumer, int enable); 404129806SnjlACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state); 405211430Sjhbint acpi_device_pwr_for_sleep(device_t bus, device_t dev, 406211430Sjhb int *dstate); 40778915Smsmith 408215072Sjkim/* APM emulation */ 409215097Sjkimvoid acpi_apm_init(struct acpi_softc *); 410215072Sjkim 411119529Snjl/* Misc. */ 41267761Smsmithstatic __inline struct acpi_softc * 41367761Smsmithacpi_device_get_parent_softc(device_t child) 41467761Smsmith{ 41567761Smsmith device_t parent; 41667761Smsmith 41767761Smsmith parent = device_get_parent(child); 418119529Snjl if (parent == NULL) 419119529Snjl return (NULL); 420119529Snjl return (device_get_softc(parent)); 42167761Smsmith} 42267761Smsmith 42385699Siwasakistatic __inline int 42485699Siwasakiacpi_get_verbose(struct acpi_softc *sc) 42585699Siwasaki{ 42685699Siwasaki if (sc) 427119529Snjl return (sc->acpi_verbose); 428119529Snjl return (0); 42985699Siwasaki} 43085699Siwasaki 431129806Snjlchar *acpi_name(ACPI_HANDLE handle); 432129806Snjlint acpi_avoid(ACPI_HANDLE handle); 433129806Snjlint acpi_disabled(char *subsys); 434129806Snjlint acpi_machdep_init(device_t dev); 435129806Snjlvoid acpi_install_wakeup_handler(struct acpi_softc *sc); 436129806Snjlint acpi_sleep_machdep(struct acpi_softc *sc, int state); 437247881Savgint acpi_wakeup_machdep(struct acpi_softc *sc, int state, 438247881Savg int sleep_result, int intr_enabled); 439131312Snjlint acpi_table_quirks(int *quirks); 440131312Snjlint acpi_machdep_quirks(int *quirks); 44180028Stakawata 442119529Snjl/* Battery Abstraction. */ 44378662Siwasakistruct acpi_battinfo; 44478662Siwasaki 445148352Snjlint acpi_battery_register(device_t dev); 446148352Snjlint acpi_battery_remove(device_t dev); 447129806Snjlint acpi_battery_get_units(void); 448129806Snjlint acpi_battery_get_info_expire(void); 449148352Snjlint acpi_battery_bst_valid(struct acpi_bst *bst); 450148352Snjlint acpi_battery_bif_valid(struct acpi_bif *bif); 451148352Snjlint acpi_battery_get_battinfo(device_t dev, 452148352Snjl struct acpi_battinfo *info); 45385556Siwasaki 454119529Snjl/* Embedded controller. */ 455129806Snjlvoid acpi_ec_ecdt_probe(device_t); 456117795Snjl 457119529Snjl/* AC adapter interface. */ 458129806Snjlint acpi_acad_get_acline(int *); 45985556Siwasaki 460122765Snjl/* Package manipulation convenience functions. */ 461122765Snjl#define ACPI_PKG_VALID(pkg, size) \ 462122765Snjl ((pkg) != NULL && (pkg)->Type == ACPI_TYPE_PACKAGE && \ 463122765Snjl (pkg)->Package.Count >= (size)) 464202771Sjkimint acpi_PkgInt(ACPI_OBJECT *res, int idx, UINT64 *dst); 465123776Snjlint acpi_PkgInt32(ACPI_OBJECT *res, int idx, uint32_t *dst); 466123776Snjlint acpi_PkgStr(ACPI_OBJECT *res, int idx, void *dst, size_t size); 467141371Snjlint acpi_PkgGas(device_t dev, ACPI_OBJECT *res, int idx, int *type, 468165875Snjl int *rid, struct resource **dst, u_int flags); 469128046SnjlACPI_HANDLE acpi_GetReference(ACPI_HANDLE scope, ACPI_OBJECT *obj); 470122765Snjl 471172489Snjl/* 472172489Snjl * Base level for BUS_ADD_CHILD. Special devices are added at orders less 473172489Snjl * than this, and normal devices at or above this level. This keeps the 474172489Snjl * probe order sorted so that things like sysresource are available before 475172489Snjl * their children need them. 476172489Snjl */ 477232086Sjkim#define ACPI_DEV_BASE_ORDER 100 478172489Snjl 479193963Sjkim/* Default maximum number of tasks to enqueue. */ 480193963Sjkim#ifndef ACPI_MAX_TASKS 481265663Ssmh#define ACPI_MAX_TASKS MAX(32, MAXCPU * 4) 482193963Sjkim#endif 483193963Sjkim 484145352Snjl/* Default number of task queue threads to start. */ 485167814Sjkim#ifndef ACPI_MAX_THREADS 486145352Snjl#define ACPI_MAX_THREADS 3 487167814Sjkim#endif 488106255Siwasaki 489153171Snjl/* Use the device logging level for ktr(4). */ 490153171Snjl#define KTR_ACPI KTR_DEV 491153171Snjl 492237822SjhbSYSCTL_DECL(_debug_acpi); 493237822Sjhb 494142984Snjl#endif /* _KERNEL */ 495142753Snjl#endif /* !_ACPIVAR_H_ */ 496