Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / dev / acpica5 / acpivar.h
CommitLineData
5ed44076
MD
1/*-
2 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
3 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000 BSDi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
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
26 * SUCH DAMAGE.
27 *
49e48b8a 28 * $FreeBSD: src/sys/dev/acpica/acpivar.h,v 1.69 2004/05/28 07:15:55 njl Exp $
b13267a5 29 * $DragonFly: src/sys/dev/acpica5/acpivar.h,v 1.8 2006/09/10 01:26:33 dillon Exp $
5ed44076
MD
30 */
31
32#include "bus_if.h"
33#include <sys/eventhandler.h>
34#include <sys/sysctl.h>
35#if __FreeBSD_version >= 500000
36#include <sys/lock.h>
37#include <sys/mutex.h>
38#endif
39
40#include <machine/bus.h>
41#include <machine/resource.h>
42
43struct acpi_softc {
44 device_t acpi_dev;
b13267a5 45 cdev_t acpi_dev_t;
5ed44076 46
edf6eb70 47 struct callout acpi_sleep_timer;
5ed44076
MD
48 struct resource *acpi_irq;
49 int acpi_irq_rid;
50 void *acpi_irq_handle;
51
52 int acpi_enabled;
53 int acpi_sstate;
54 int acpi_sleep_disabled;
55
56 struct sysctl_ctx_list acpi_sysctl_ctx;
57 struct sysctl_oid *acpi_sysctl_tree;
5ed44076
MD
58 int acpi_power_button_sx;
59 int acpi_sleep_button_sx;
60 int acpi_lid_switch_sx;
61
62 int acpi_standby_sx;
63 int acpi_suspend_sx;
64
65 int acpi_sleep_delay;
66 int acpi_s4bios;
67 int acpi_disable_on_poweroff;
5ed44076
MD
68 int acpi_verbose;
69
70 bus_dma_tag_t acpi_waketag;
71 bus_dmamap_t acpi_wakemap;
72 vm_offset_t acpi_wakeaddr;
73 vm_paddr_t acpi_wakephys;
74
75 struct sysctl_ctx_list acpi_battery_sysctl_ctx;
76 struct sysctl_oid *acpi_battery_sysctl_tree;
77};
78
79struct acpi_device {
80 /* ACPI ivars */
81 ACPI_HANDLE ad_handle;
82 int ad_magic;
83 void *ad_private;
84
f9d8cd12 85 /* Resources */
5ed44076 86 struct resource_list ad_rl;
49e48b8a 87};
5ed44076 88
49e48b8a
MD
89struct acpi_prw_data {
90 ACPI_HANDLE gpe_handle;
91 int gpe_bit;
92 int lowest_wake;
93 void *power_res;
5ed44076
MD
94};
95
49e48b8a
MD
96/* Flags for each device defined in the AML namespace. */
97#define ACPI_FLAG_WAKE_CAPABLE 0x1
98#define ACPI_FLAG_WAKE_ENABLED 0x2
99
5ed44076
MD
100#if defined(__DragonFly__)
101/*
1a5f156c 102 * In DragonFly, ACPI is protected by critical sections.
5ed44076 103 */
1a5f156c
SS
104# define ACPI_LOCK crit_enter()
105# define ACPI_UNLOCK crit_exit()
5ed44076
MD
106# define ACPI_ASSERTLOCK
107# define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
1a5f156c 108# define ACPI_LOCK_DECL
5ed44076
MD
109# define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
110#elif __FreeBSD_version < 500000
111/*
112 * In 4.x, ACPI is protected by splhigh().
113 */
114# define ACPI_LOCK s = splhigh()
115# define ACPI_UNLOCK splx(s)
116# define ACPI_ASSERTLOCK
117# define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e)
118# define ACPI_LOCK_DECL int s
119# define kthread_create(a, b, c, d, e, f) kthread_create(a, b, c, f)
120# define tc_init(a) init_timecounter(a)
121#else
122# define ACPI_LOCK
123# define ACPI_UNLOCK
124# define ACPI_ASSERTLOCK
125# define ACPI_LOCK_DECL
126#endif
127
128/*
129 * ACPI CA does not define layers for non-ACPI CA drivers.
130 * We define some here within the range provided.
131 */
f9d8cd12
MD
132#define ACPI_AC_ADAPTER 0x00010000
133#define ACPI_BATTERY 0x00020000
134#define ACPI_BUS 0x00040000
135#define ACPI_BUTTON 0x00080000
136#define ACPI_EC 0x00100000
137#define ACPI_FAN 0x00200000
138#define ACPI_POWERRES 0x00400000
5ed44076
MD
139#define ACPI_PROCESSOR 0x00800000
140#define ACPI_THERMAL 0x01000000
f9d8cd12
MD
141#define ACPI_TIMER 0x02000000
142#define ACPI_ASUS 0x04000000
5ed44076
MD
143
144/*
145 * Constants for different interrupt models used with acpi_SetIntrModel().
146 */
147#define ACPI_INTR_PIC 0
148#define ACPI_INTR_APIC 1
149#define ACPI_INTR_SAPIC 2
150
151/*
152 * Note that the low ivar values are reserved to provide
153 * interface compatibility with ISA drivers which can also
154 * attach to ACPI.
155 */
156#define ACPI_IVAR_HANDLE 0x100
157#define ACPI_IVAR_MAGIC 0x101
158#define ACPI_IVAR_PRIVATE 0x102
159
49e48b8a
MD
160/*
161 * Accessor functions for our ivars. Default value for BUS_READ_IVAR is
162 * (type) 0. The <sys/bus.h> accessor functions don't check return values.
163 */
164#define __ACPI_BUS_ACCESSOR(varp, var, ivarp, ivar, type) \
165 \
166static __inline type varp ## _get_ ## var(device_t dev) \
167{ \
168 uintptr_t v = 0; \
169 BUS_READ_IVAR(device_get_parent(dev), dev, \
170 ivarp ## _IVAR_ ## ivar, &v); \
171 return ((type) v); \
172} \
173 \
174static __inline void varp ## _set_ ## var(device_t dev, type t) \
175{ \
176 uintptr_t v = (uintptr_t) t; \
177 BUS_WRITE_IVAR(device_get_parent(dev), dev, \
178 ivarp ## _IVAR_ ## ivar, v); \
f9d8cd12
MD
179}
180
49e48b8a
MD
181__ACPI_BUS_ACCESSOR(acpi, handle, ACPI, HANDLE, ACPI_HANDLE)
182__ACPI_BUS_ACCESSOR(acpi, magic, ACPI, MAGIC, int)
183__ACPI_BUS_ACCESSOR(acpi, private, ACPI, PRIVATE, void *)
f9d8cd12
MD
184
185static __inline ACPI_OBJECT_TYPE
186acpi_get_type(device_t dev)
187{
188 ACPI_HANDLE h;
189 ACPI_OBJECT_TYPE t;
190
191 if ((h = acpi_get_handle(dev)) == NULL)
192 return (ACPI_TYPE_NOT_FOUND);
193 if (AcpiGetType(h, &t) != AE_OK)
194 return (ACPI_TYPE_NOT_FOUND);
195 return (t);
196}
5ed44076
MD
197
198#ifdef ACPI_DEBUGGER
49e48b8a 199void acpi_EnterDebugger(void);
5ed44076
MD
200#endif
201
202#ifdef ACPI_DEBUG
203#include <sys/cons.h>
204#define STEP(x) do {printf x, printf("\n"); cngetc();} while (0)
205#else
206#define STEP(x)
207#endif
208
209#define ACPI_VPRINT(dev, acpi_sc, x...) do { \
210 if (acpi_get_verbose(acpi_sc)) \
211 device_printf(dev, x); \
212} while (0)
213
214#define ACPI_DEVINFO_PRESENT(x) (((x) & 0x9) == 9)
49e48b8a
MD
215BOOLEAN acpi_DeviceIsPresent(device_t dev);
216BOOLEAN acpi_BatteryIsPresent(device_t dev);
217BOOLEAN acpi_MatchHid(device_t dev, char *hid);
218ACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path,
219 ACPI_HANDLE *result);
220uint32_t acpi_TimerDelta(uint32_t end, uint32_t start);
221ACPI_BUFFER *acpi_AllocBuffer(int size);
222ACPI_STATUS acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp,
223 UINT32 *number);
224ACPI_STATUS acpi_GetInteger(ACPI_HANDLE handle, char *path,
225 UINT32 *number);
226ACPI_STATUS acpi_SetInteger(ACPI_HANDLE handle, char *path,
227 UINT32 number);
228ACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj,
229 void (*func)(ACPI_OBJECT *comp, void *arg), void *arg);
230ACPI_STATUS acpi_FindIndexedResource(ACPI_BUFFER *buf, int index,
231 ACPI_RESOURCE **resp);
232ACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *buf,
233 ACPI_RESOURCE *res);
234ACPI_STATUS acpi_OverrideInterruptLevel(UINT32 InterruptNumber);
235ACPI_STATUS acpi_SetIntrModel(int model);
236ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state);
237int acpi_wake_init(device_t dev, int type);
238int acpi_wake_set_enable(device_t dev, int enable);
239int acpi_wake_sleep_prep(device_t dev, int sstate);
240int acpi_wake_run_prep(device_t dev);
241ACPI_STATUS acpi_Startup(void);
242ACPI_STATUS acpi_Enable(struct acpi_softc *sc);
243ACPI_STATUS acpi_Disable(struct acpi_softc *sc);
244void acpi_UserNotify(const char *subsystem, ACPI_HANDLE h,
245 uint8_t notify);
246struct resource *acpi_bus_alloc_gas(device_t dev, int *rid,
247 ACPI_GENERIC_ADDRESS *gas);
5ed44076
MD
248
249struct acpi_parse_resource_set {
f9d8cd12 250 void (*set_init)(device_t dev, void *arg, void **context);
5ed44076 251 void (*set_done)(device_t dev, void *context);
49e48b8a
MD
252 void (*set_ioport)(device_t dev, void *context, uint32_t base,
253 uint32_t length);
254 void (*set_iorange)(device_t dev, void *context, uint32_t low,
255 uint32_t high, uint32_t length, uint32_t align);
256 void (*set_memory)(device_t dev, void *context, uint32_t base,
257 uint32_t length);
258 void (*set_memoryrange)(device_t dev, void *context, uint32_t low,
259 uint32_t high, uint32_t length, uint32_t align);
5ed44076 260 void (*set_irq)(device_t dev, void *context, u_int32_t *irq,
49e48b8a 261 int count, int trig, int pol);
5ed44076 262 void (*set_drq)(device_t dev, void *context, u_int32_t *drq,
49e48b8a 263 int count);
5ed44076 264 void (*set_start_dependant)(device_t dev, void *context,
49e48b8a 265 int preference);
5ed44076
MD
266 void (*set_end_dependant)(device_t dev, void *context);
267};
268
49e48b8a
MD
269extern struct acpi_parse_resource_set acpi_res_parse_set;
270ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
271 struct acpi_parse_resource_set *set, void *arg);
5ed44076
MD
272
273/* ACPI event handling */
49e48b8a
MD
274UINT32 acpi_event_power_button_sleep(void *context);
275UINT32 acpi_event_power_button_wake(void *context);
276UINT32 acpi_event_sleep_button_sleep(void *context);
277UINT32 acpi_event_sleep_button_wake(void *context);
5ed44076
MD
278
279#define ACPI_EVENT_PRI_FIRST 0
280#define ACPI_EVENT_PRI_DEFAULT 10000
281#define ACPI_EVENT_PRI_LAST 20000
282
283typedef void (*acpi_event_handler_t)(void *, int);
284
285EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t);
286EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t);
287
288/* Device power control. */
49e48b8a 289ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state);
5ed44076
MD
290
291/* Misc. */
292static __inline struct acpi_softc *
293acpi_device_get_parent_softc(device_t child)
294{
295 device_t parent;
296
297 parent = device_get_parent(child);
298 if (parent == NULL)
299 return (NULL);
300 return (device_get_softc(parent));
301}
302
303static __inline int
304acpi_get_verbose(struct acpi_softc *sc)
305{
306 if (sc)
307 return (sc->acpi_verbose);
308 return (0);
309}
310
49e48b8a
MD
311char *acpi_name(ACPI_HANDLE handle);
312int acpi_avoid(ACPI_HANDLE handle);
313int acpi_disabled(char *subsys);
2df6e324 314int acpi_enabled(char *subsys);
49e48b8a
MD
315int acpi_machdep_init(device_t dev);
316void acpi_install_wakeup_handler(struct acpi_softc *sc);
317int acpi_sleep_machdep(struct acpi_softc *sc, int state);
5ed44076
MD
318
319/* Battery Abstraction. */
320struct acpi_battinfo;
321struct acpi_battdesc;
322
49e48b8a
MD
323int acpi_battery_register(int, int);
324int acpi_battery_get_battinfo(int, struct acpi_battinfo *);
325int acpi_battery_get_units(void);
326int acpi_battery_get_info_expire(void);
327int acpi_battery_get_battdesc(int, struct acpi_battdesc *);
5ed44076 328
49e48b8a 329int acpi_cmbat_get_battinfo(int, struct acpi_battinfo *);
5ed44076
MD
330
331/* Embedded controller. */
49e48b8a 332void acpi_ec_ecdt_probe(device_t);
5ed44076
MD
333
334/* AC adapter interface. */
49e48b8a 335int acpi_acad_get_acline(int *);
5ed44076
MD
336
337/* Package manipulation convenience functions. */
338#define ACPI_PKG_VALID(pkg, size) \
339 ((pkg) != NULL && (pkg)->Type == ACPI_TYPE_PACKAGE && \
340 (pkg)->Package.Count >= (size))
341int acpi_PkgInt(ACPI_OBJECT *res, int idx, ACPI_INTEGER *dst);
342int acpi_PkgInt32(ACPI_OBJECT *res, int idx, uint32_t *dst);
343int acpi_PkgStr(ACPI_OBJECT *res, int idx, void *dst, size_t size);
344int acpi_PkgGas(device_t dev, ACPI_OBJECT *res, int idx, int *rid,
345 struct resource **dst);
f9d8cd12 346ACPI_HANDLE acpi_GetReference(ACPI_HANDLE scope, ACPI_OBJECT *obj);
5ed44076 347
5ed44076 348/* ACPI task kernel thread initialization. */
49e48b8a 349int acpi_task_thread_init(void);