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.54 2004/02/19 18:20:03 njl Exp $
29 * $DragonFly: src/sys/dev/acpica5/acpivar.h,v 1.1 2004/02/21 06:48:08 dillon Exp $
33 #include <sys/eventhandler.h>
34 #include <sys/sysctl.h>
35 #if __FreeBSD_version >= 500000
37 #include <sys/mutex.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
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 #define ACPI_POWER_BUTTON_DEFAULT_SX ACPI_STATE_S5;
58 #define ACPI_SLEEP_BUTTON_DEFAULT_SX ACPI_STATE_S1;
59 #define ACPI_LID_SWITCH_DEFAULT_SX ACPI_STATE_S1;
60 int acpi_power_button_sx;
61 int acpi_sleep_button_sx;
62 int acpi_lid_switch_sx;
69 int acpi_disable_on_poweroff;
73 bus_dma_tag_t acpi_waketag;
74 bus_dmamap_t acpi_wakemap;
75 vm_offset_t acpi_wakeaddr;
76 vm_paddr_t acpi_wakephys;
78 struct sysctl_ctx_list acpi_battery_sysctl_ctx;
79 struct sysctl_oid *acpi_battery_sysctl_tree;
84 ACPI_HANDLE ad_handle;
89 struct resource_list ad_rl;
93 #if defined(__DragonFly__)
95 * In 4.x, ACPI is protected by splhigh().
97 # define ACPI_LOCK s = splhigh()
98 # define ACPI_UNLOCK splx(s)
99 # define ACPI_ASSERTLOCK
100 # define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
101 # define ACPI_LOCK_DECL int s
102 # define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
103 #elif __FreeBSD_version < 500000
105 * In 4.x, ACPI is protected by splhigh().
107 # define ACPI_LOCK s = splhigh()
108 # define ACPI_UNLOCK splx(s)
109 # define ACPI_ASSERTLOCK
110 # define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
111 # define ACPI_LOCK_DECL int s
112 # define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
113 # define tc_init(a) init_timecounter(a)
117 # define ACPI_ASSERTLOCK
118 # define ACPI_LOCK_DECL
122 * ACPI CA does not define layers for non-ACPI CA drivers.
123 * We define some here within the range provided.
125 #define ACPI_BUS 0x00010000
126 #define ACPI_SYSTEM 0x00020000
127 #define ACPI_POWER 0x00040000
128 #define ACPI_EC 0x00080000
129 #define ACPI_AC_ADAPTER 0x00100000
130 #define ACPI_BATTERY 0x00200000
131 #define ACPI_BUTTON 0x00400000
132 #define ACPI_PROCESSOR 0x00800000
133 #define ACPI_THERMAL 0x01000000
134 #define ACPI_FAN 0x02000000
135 #define ACPI_TOSHIBA 0x04000000
138 * Constants for different interrupt models used with acpi_SetIntrModel().
140 #define ACPI_INTR_PIC 0
141 #define ACPI_INTR_APIC 1
142 #define ACPI_INTR_SAPIC 2
145 * Note that the low ivar values are reserved to provide
146 * interface compatibility with ISA drivers which can also
149 #define ACPI_IVAR_HANDLE 0x100
150 #define ACPI_IVAR_MAGIC 0x101
151 #define ACPI_IVAR_PRIVATE 0x102
153 extern ACPI_HANDLE acpi_get_handle(device_t dev);
154 extern int acpi_set_handle(device_t dev, ACPI_HANDLE h);
155 extern int acpi_get_magic(device_t dev);
156 extern int acpi_set_magic(device_t dev, int m);
157 extern void * acpi_get_private(device_t dev);
158 extern int acpi_set_private(device_t dev, void *p);
159 extern ACPI_OBJECT_TYPE acpi_get_type(device_t dev);
160 struct resource * acpi_bus_alloc_gas(device_t dev, int *rid,
161 ACPI_GENERIC_ADDRESS *gas);
164 extern void acpi_EnterDebugger(void);
168 #include <sys/cons.h>
169 #define STEP(x) do {printf x, printf("\n"); cngetc();} while (0)
174 #define ACPI_VPRINT(dev, acpi_sc, x...) do { \
175 if (acpi_get_verbose(acpi_sc)) \
176 device_printf(dev, x); \
179 #define ACPI_DEVINFO_PRESENT(x) (((x) & 0x9) == 9)
180 extern BOOLEAN acpi_DeviceIsPresent(device_t dev);
181 extern BOOLEAN acpi_BatteryIsPresent(device_t dev);
182 extern BOOLEAN acpi_MatchHid(device_t dev, char *hid);
183 extern ACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path,
184 ACPI_HANDLE *result);
185 extern ACPI_BUFFER *acpi_AllocBuffer(int size);
186 extern ACPI_STATUS acpi_EvaluateInteger(ACPI_HANDLE handle, char *path,
188 extern ACPI_STATUS acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp,
190 extern ACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj,
191 void (*func)(ACPI_OBJECT *comp, void *arg),
193 extern ACPI_STATUS acpi_FindIndexedResource(ACPI_BUFFER *buf, int index,
194 ACPI_RESOURCE **resp);
195 extern ACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *buf,
197 extern ACPI_STATUS acpi_OverrideInterruptLevel(UINT32 InterruptNumber);
198 extern ACPI_STATUS acpi_SetIntrModel(int model);
199 extern ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state);
200 extern ACPI_STATUS acpi_Startup(void);
201 extern ACPI_STATUS acpi_Enable(struct acpi_softc *sc);
202 extern ACPI_STATUS acpi_Disable(struct acpi_softc *sc);
203 extern void acpi_UserNotify(const char *subsystem, ACPI_HANDLE h,
206 struct acpi_parse_resource_set {
207 void (*set_init)(device_t dev, void **context);
208 void (*set_done)(device_t dev, void *context);
209 void (*set_ioport)(device_t dev, void *context, u_int32_t base,
211 void (*set_iorange)(device_t dev, void *context,
212 u_int32_t low, u_int32_t high,
213 u_int32_t length, u_int32_t align);
214 void (*set_memory)(device_t dev, void *context, u_int32_t base,
216 void (*set_memoryrange)(device_t dev, void *context, u_int32_t low,
217 u_int32_t high, u_int32_t length,
219 void (*set_irq)(device_t dev, void *context, u_int32_t *irq,
220 int count, int trig, int pol);
221 void (*set_drq)(device_t dev, void *context, u_int32_t *drq,
223 void (*set_start_dependant)(device_t dev, void *context,
225 void (*set_end_dependant)(device_t dev, void *context);
228 extern struct acpi_parse_resource_set acpi_res_parse_set;
229 extern ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
230 struct acpi_parse_resource_set *set);
232 /* ACPI event handling */
233 extern UINT32 acpi_event_power_button_sleep(void *context);
234 extern UINT32 acpi_event_power_button_wake(void *context);
235 extern UINT32 acpi_event_sleep_button_sleep(void *context);
236 extern UINT32 acpi_event_sleep_button_wake(void *context);
238 #define ACPI_EVENT_PRI_FIRST 0
239 #define ACPI_EVENT_PRI_DEFAULT 10000
240 #define ACPI_EVENT_PRI_LAST 20000
242 typedef void (*acpi_event_handler_t)(void *, int);
244 EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t);
245 EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t);
247 /* Device power control. */
248 extern ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer,
252 static __inline struct acpi_softc *
253 acpi_device_get_parent_softc(device_t child)
257 parent = device_get_parent(child);
260 return (device_get_softc(parent));
264 acpi_get_verbose(struct acpi_softc *sc)
267 return (sc->acpi_verbose);
271 extern char *acpi_name(ACPI_HANDLE handle);
272 extern int acpi_avoid(ACPI_HANDLE handle);
273 extern int acpi_disabled(char *subsys);
274 extern void acpi_device_enable_wake_capability(ACPI_HANDLE h, int enable);
275 extern void acpi_device_enable_wake_event(ACPI_HANDLE h);
276 extern int acpi_machdep_init(device_t dev);
277 extern void acpi_install_wakeup_handler(struct acpi_softc *sc);
278 extern int acpi_sleep_machdep(struct acpi_softc *sc, int state);
280 /* Battery Abstraction. */
281 struct acpi_battinfo;
282 struct acpi_battdesc;
284 extern int acpi_battery_register(int, int);
285 extern int acpi_battery_get_battinfo(int, struct acpi_battinfo *);
286 extern int acpi_battery_get_units(void);
287 extern int acpi_battery_get_info_expire(void);
288 extern int acpi_battery_get_battdesc(int, struct acpi_battdesc *);
290 extern int acpi_cmbat_get_battinfo(int, struct acpi_battinfo *);
292 /* Embedded controller. */
293 extern void acpi_ec_ecdt_probe(device_t);
295 /* AC adapter interface. */
296 extern int acpi_acad_get_acline(int *);
298 /* Package manipulation convenience functions. */
299 #define ACPI_PKG_VALID(pkg, size) \
300 ((pkg) != NULL && (pkg)->Type == ACPI_TYPE_PACKAGE && \
301 (pkg)->Package.Count >= (size))
302 int acpi_PkgInt(ACPI_OBJECT *res, int idx, ACPI_INTEGER *dst);
303 int acpi_PkgInt32(ACPI_OBJECT *res, int idx, uint32_t *dst);
304 int acpi_PkgStr(ACPI_OBJECT *res, int idx, void *dst, size_t size);
305 int acpi_PkgGas(device_t dev, ACPI_OBJECT *res, int idx, int *rid,
306 struct resource **dst);
308 #if __FreeBSD_version >= 500000
309 #ifndef ACPI_MAX_THREADS
310 #define ACPI_MAX_THREADS 3
312 #if ACPI_MAX_THREADS > 0
313 #define ACPI_USE_THREADS
317 #ifdef ACPI_USE_THREADS
318 /* ACPI task kernel thread initialization. */
319 extern int acpi_task_thread_init(void);