2 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
3 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000 BSDi
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/sys/dev/acpica/acpivar.h,v 1.71 2004/06/13 22:52:30 njl Exp $
29 * $DragonFly: src/sys/dev/acpica5/acpivar.h,v 1.16 2008/09/29 06:59:45 hasso Exp $
34 #include <sys/eventhandler.h>
35 #include <sys/sysctl.h>
36 #if __FreeBSD_version >= 500000
38 #include <sys/mutex.h>
46 struct callout acpi_sleep_timer;
47 struct resource *acpi_irq;
49 void *acpi_irq_handle;
53 int acpi_sleep_disabled;
55 struct sysctl_ctx_list acpi_sysctl_ctx;
56 struct sysctl_oid *acpi_sysctl_tree;
57 int acpi_power_button_sx;
58 int acpi_sleep_button_sx;
59 int acpi_lid_switch_sx;
66 int acpi_disable_on_poweroff;
69 bus_dma_tag_t acpi_waketag;
70 bus_dmamap_t acpi_wakemap;
71 vm_offset_t acpi_wakeaddr;
72 vm_paddr_t acpi_wakephys;
74 struct sysctl_ctx_list acpi_battery_sysctl_ctx;
75 struct sysctl_oid *acpi_battery_sysctl_tree;
80 ACPI_HANDLE ad_handle;
85 struct resource_list ad_rl;
88 struct acpi_prw_data {
89 ACPI_HANDLE gpe_handle;
95 /* Flags for each device defined in the AML namespace. */
96 #define ACPI_FLAG_WAKE_CAPABLE 0x1
97 #define ACPI_FLAG_WAKE_ENABLED 0x2
99 #if defined(__DragonFly__)
101 * In DragonFly, ACPI is protected by critical sections.
103 # define ACPI_LOCK crit_enter()
104 # define ACPI_UNLOCK crit_exit()
105 # define ACPI_ASSERTLOCK
106 # define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
107 # define ACPI_LOCK_DECL
108 # define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
109 #elif __FreeBSD_version < 500000
111 * In 4.x, ACPI is protected by splhigh().
113 # define ACPI_LOCK s = splhigh()
114 # define ACPI_UNLOCK splx(s)
115 # define ACPI_ASSERTLOCK
116 # define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
117 # define ACPI_LOCK_DECL int s
118 # define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
119 # define tc_init(a) init_timecounter(a)
123 # define ACPI_ASSERTLOCK
124 # define ACPI_LOCK_DECL
128 * ACPI CA does not define layers for non-ACPI CA drivers.
129 * We define some here within the range provided.
131 #define ACPI_AC_ADAPTER 0x00010000
132 #define ACPI_BATTERY 0x00020000
133 #define ACPI_BUS 0x00040000
134 #define ACPI_BUTTON 0x00080000
135 #define ACPI_EC 0x00100000
136 #define ACPI_FAN 0x00200000
137 #define ACPI_POWERRES 0x00400000
138 #define ACPI_PROCESSOR 0x00800000
139 #define ACPI_THERMAL 0x01000000
140 #define ACPI_TIMER 0x02000000
141 #define ACPI_OEM 0x04000000
144 * Constants for different interrupt models used with acpi_SetIntrModel().
146 #define ACPI_INTR_PIC 0
147 #define ACPI_INTR_APIC 1
148 #define ACPI_INTR_SAPIC 2
151 * Various features and capabilities for the acpi_get_features() method.
152 * In particular, these are used for the ACPI 3.0 _PDC and _OSC methods.
154 #define ACPI_CAP_PERF_MSRS (1 << 0) /* Intel SpeedStep PERF_CTL MSRs */
155 #define ACPI_CAP_C1_IO_HALT (1 << 1) /* Intel C1 "IO then halt" sequence */
156 #define ACPI_CAP_THR_MSRS (1 << 2) /* Intel OnDemand throttling MSRs */
157 #define ACPI_CAP_SMP_SAME (1 << 3) /* MP C1, Px, and Tx (all the same) */
158 #define ACPI_CAP_SMP_SAME_C3 (1 << 4) /* MP C2 and C3 (all the same) */
159 #define ACPI_CAP_SMP_DIFF_PX (1 << 5) /* MP Px (different, using _PSD) */
160 #define ACPI_CAP_SMP_DIFF_CX (1 << 6) /* MP Cx (different, using _CSD) */
161 #define ACPI_CAP_SMP_DIFF_TX (1 << 7) /* MP Tx (different, using _TSD) */
162 #define ACPI_CAP_SMP_C1_NATIVE (1 << 8) /* MP C1 support other than halt */
165 * Note that the low ivar values are reserved to provide
166 * interface compatibility with ISA drivers which can also
169 #define ACPI_IVAR_HANDLE 0x100
170 #define ACPI_IVAR_MAGIC 0x101
171 #define ACPI_IVAR_PRIVATE 0x102
174 * Accessor functions for our ivars. Default value for BUS_READ_IVAR is
175 * (type) 0. The <sys/bus.h> accessor functions don't check return values.
177 #define __ACPI_BUS_ACCESSOR(varp, var, ivarp, ivar, type) \
179 static __inline type varp ## _get_ ## var(device_t dev) \
182 BUS_READ_IVAR(device_get_parent(dev), dev, \
183 ivarp ## _IVAR_ ## ivar, &v); \
187 static __inline void varp ## _set_ ## var(device_t dev, type t) \
189 uintptr_t v = (uintptr_t) t; \
190 BUS_WRITE_IVAR(device_get_parent(dev), dev, \
191 ivarp ## _IVAR_ ## ivar, v); \
194 __ACPI_BUS_ACCESSOR(acpi, handle, ACPI, HANDLE, ACPI_HANDLE)
195 __ACPI_BUS_ACCESSOR(acpi, magic, ACPI, MAGIC, int)
196 __ACPI_BUS_ACCESSOR(acpi, private, ACPI, PRIVATE, void *)
198 void acpi_fake_objhandler(ACPI_HANDLE h, UINT32 fn, void *data);
199 static __inline device_t
200 acpi_get_device(ACPI_HANDLE handle)
203 AcpiGetData(handle, acpi_fake_objhandler, &dev);
204 return ((device_t)dev);
207 static __inline ACPI_OBJECT_TYPE
208 acpi_get_type(device_t dev)
213 if ((h = acpi_get_handle(dev)) == NULL)
214 return (ACPI_TYPE_NOT_FOUND);
215 if (AcpiGetType(h, &t) != AE_OK)
216 return (ACPI_TYPE_NOT_FOUND);
221 void acpi_EnterDebugger(void);
225 #include <sys/cons.h>
226 #define STEP(x) do {kprintf x, kprintf("\n"); cngetc();} while (0)
231 #define ACPI_VPRINT(dev, acpi_sc, x...) do { \
232 if (acpi_get_verbose(acpi_sc)) \
233 device_printf(dev, x); \
236 #define ACPI_DEVINFO_PRESENT(x) (((x) & 0x9) == 9)
237 BOOLEAN acpi_DeviceIsPresent(device_t dev);
238 BOOLEAN acpi_BatteryIsPresent(device_t dev);
239 BOOLEAN acpi_MatchHid(ACPI_HANDLE h, char *hid);
240 ACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path,
241 ACPI_HANDLE *result);
242 uint32_t acpi_TimerDelta(uint32_t end, uint32_t start);
243 ACPI_BUFFER *acpi_AllocBuffer(int size);
244 ACPI_STATUS acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp,
246 ACPI_STATUS acpi_GetInteger(ACPI_HANDLE handle, char *path,
248 ACPI_STATUS acpi_SetInteger(ACPI_HANDLE handle, char *path,
250 ACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj,
251 void (*func)(ACPI_OBJECT *comp, void *arg), void *arg);
252 ACPI_STATUS acpi_FindIndexedResource(ACPI_BUFFER *buf, int index,
253 ACPI_RESOURCE **resp);
254 ACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *buf,
256 ACPI_STATUS acpi_OverrideInterruptLevel(UINT32 InterruptNumber);
257 ACPI_STATUS acpi_SetIntrModel(int model);
258 ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state);
259 int acpi_wake_init(device_t dev, int type);
260 int acpi_wake_set_enable(device_t dev, int enable);
261 int acpi_wake_sleep_prep(device_t dev, int sstate);
262 int acpi_wake_run_prep(device_t dev);
263 ACPI_STATUS acpi_Startup(void);
264 ACPI_STATUS acpi_Enable(struct acpi_softc *sc);
265 ACPI_STATUS acpi_Disable(struct acpi_softc *sc);
266 void acpi_UserNotify(const char *subsystem, ACPI_HANDLE h,
268 struct resource *acpi_bus_alloc_gas(device_t dev, int *rid,
269 const ACPI_GENERIC_ADDRESS *gas, u_int flags);
271 struct acpi_parse_resource_set {
272 void (*set_init)(device_t dev, void *arg, void **context);
273 void (*set_done)(device_t dev, void *context);
274 void (*set_ioport)(device_t dev, void *context, uint32_t base,
276 void (*set_iorange)(device_t dev, void *context, uint32_t low,
277 uint32_t high, uint32_t length, uint32_t align);
278 void (*set_memory)(device_t dev, void *context, uint32_t base,
280 void (*set_memoryrange)(device_t dev, void *context, uint32_t low,
281 uint32_t high, uint32_t length, uint32_t align);
282 void (*set_irq)(device_t dev, void *context, u_int8_t *irq,
283 int count, int trig, int pol);
284 void (*set_ext_irq)(device_t dev, void *context, u_int32_t *irq,
285 int count, int trig, int pol);
286 void (*set_drq)(device_t dev, void *context, u_int8_t *drq,
288 void (*set_start_dependant)(device_t dev, void *context,
290 void (*set_end_dependant)(device_t dev, void *context);
293 extern struct acpi_parse_resource_set acpi_res_parse_set;
294 ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
295 struct acpi_parse_resource_set *set, void *arg);
296 extern struct rman acpi_rman_io, acpi_rman_mem;
297 struct resource_list_entry *acpi_sysres_find(int type, u_long addr);
299 /* ACPI event handling */
300 UINT32 acpi_event_power_button_sleep(void *context);
301 UINT32 acpi_event_power_button_wake(void *context);
302 UINT32 acpi_event_sleep_button_sleep(void *context);
303 UINT32 acpi_event_sleep_button_wake(void *context);
305 #define ACPI_EVENT_PRI_FIRST 0
306 #define ACPI_EVENT_PRI_DEFAULT 10000
307 #define ACPI_EVENT_PRI_LAST 20000
309 typedef void (*acpi_event_handler_t)(void *, int);
311 EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t);
312 EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t);
314 /* Device power control. */
315 ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state);
318 static __inline struct acpi_softc *
319 acpi_device_get_parent_softc(device_t child)
323 parent = device_get_parent(child);
326 return (device_get_softc(parent));
330 acpi_get_verbose(struct acpi_softc *sc)
333 return (sc->acpi_verbose);
337 char *acpi_name(ACPI_HANDLE handle);
338 int acpi_avoid(ACPI_HANDLE handle);
339 int acpi_disabled(char *subsys);
340 int acpi_enabled(char *subsys);
341 int acpi_machdep_init(device_t dev);
342 void acpi_install_wakeup_handler(struct acpi_softc *sc);
343 int acpi_sleep_machdep(struct acpi_softc *sc, int state);
345 /* Battery Abstraction. */
346 struct acpi_battinfo;
348 int acpi_battery_register(device_t dev);
349 int acpi_battery_remove(device_t dev);
350 int acpi_battery_get_units(void);
351 int acpi_battery_get_info_expire(void);
352 int acpi_battery_bst_valid(struct acpi_bst *bst);
353 int acpi_battery_bif_valid(struct acpi_bif *bif);
354 int acpi_battery_get_battinfo(device_t dev,
355 struct acpi_battinfo *info);
357 /* Embedded controller. */
358 void acpi_ec_ecdt_probe(device_t);
360 /* AC adapter interface. */
361 int acpi_acad_get_acline(int *);
363 /* Package manipulation convenience functions. */
364 #define _ACPI_PKG_VALID(pkg) \
365 ((pkg) != NULL && (pkg)->Type == ACPI_TYPE_PACKAGE)
366 #define ACPI_PKG_VALID(pkg, size) \
367 (_ACPI_PKG_VALID((pkg)) && (pkg)->Package.Count >= (size))
368 #define ACPI_PKG_VALID_EQ(pkg, size) \
369 (_ACPI_PKG_VALID((pkg)) && (pkg)->Package.Count == (size))
370 int acpi_PkgInt(ACPI_OBJECT *res, int idx, ACPI_INTEGER *dst);
371 int acpi_PkgInt32(ACPI_OBJECT *res, int idx, uint32_t *dst);
372 int acpi_PkgStr(ACPI_OBJECT *res, int idx, void *dst, size_t size);
373 int acpi_PkgGas(device_t dev, ACPI_OBJECT *res, int idx, int *rid,
374 struct resource **dst, u_int flags);
375 int acpi_PkgRawGas(ACPI_OBJECT *res, int idx,
376 ACPI_GENERIC_ADDRESS *gas);
377 ACPI_HANDLE acpi_GetReference(ACPI_HANDLE scope, ACPI_OBJECT *obj);
379 /* ACPI task kernel thread initialization. */
380 int acpi_task_thread_init(void);