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 *
| 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 *
|
28 * $FreeBSD: head/sys/dev/acpica/acpivar.h 78662 2001-06-23 10:38:25Z iwasaki $
| 28 * $FreeBSD: head/sys/dev/acpica/acpivar.h 78915 2001-06-28 06:17:16Z msmith $
|
29 */ 30 31#include "bus_if.h" 32#include <sys/eventhandler.h> 33#include <sys/sysctl.h> 34 35extern devclass_t acpi_devclass; 36 37struct acpi_softc { 38 device_t acpi_dev; 39 dev_t acpi_dev_t; 40 41 struct resource *acpi_irq; 42 int acpi_irq_rid; 43 void *acpi_irq_handle; 44 45 int acpi_enabled; 46 int acpi_sstate; 47 48 struct sysctl_ctx_list acpi_sysctl_ctx; 49 struct sysctl_oid *acpi_sysctl_tree; 50#define ACPI_POWER_BUTTON_DEFAULT_SX ACPI_STATE_S5; 51#define ACPI_SLEEP_BUTTON_DEFAULT_SX ACPI_STATE_S1; 52#define ACPI_LID_SWITCH_DEFAULT_SX ACPI_STATE_S1; 53 int acpi_power_button_sx; 54 int acpi_sleep_button_sx; 55 int acpi_lid_switch_sx; 56 57 struct sysctl_ctx_list acpi_battery_sysctl_ctx; 58 struct sysctl_oid *acpi_battery_sysctl_tree; 59}; 60 61struct acpi_device { 62 /* ACPI ivars */ 63 ACPI_HANDLE ad_handle; 64 int ad_magic; 65 void *ad_private; 66 67 /* resources */ 68 struct resource_list ad_rl; 69}; 70 71/* 72 * This is a cheap and nasty way to get around the horrid counted list 73 * argument format that AcpiEvalateMethod uses. 74 */ 75#define ACPI_OBJECTLIST_MAX 16 76struct acpi_object_list { 77 UINT32 count; 78 ACPI_OBJECT *pointer[ACPI_OBJECTLIST_MAX]; 79 ACPI_OBJECT object[ACPI_OBJECTLIST_MAX]; 80}; 81 82static __inline struct acpi_object_list * 83acpi_AllocObjectList(int nobj) { 84 struct acpi_object_list *l; 85 int i; 86 87 if (nobj > ACPI_OBJECTLIST_MAX) 88 return(NULL); 89 if ((l = AcpiOsAllocate(sizeof(*l))) == NULL) 90 return(NULL); 91 bzero(l, sizeof(*l)); 92 for (i = 0; i < ACPI_OBJECTLIST_MAX; i++) 93 l->pointer[i] = &l->object[i]; 94 l->count = nobj; 95 return(l); 96} 97 98#define ACPI_IVAR_HANDLE 0x100 99#define ACPI_IVAR_MAGIC 0x101 100#define ACPI_IVAR_PRIVATE 0x102 101 102static __inline ACPI_HANDLE 103acpi_get_handle(device_t dev) { 104 ACPI_HANDLE h; 105 106 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t *)&h)) 107 return(NULL); 108 return(h); 109} 110 111static __inline int 112acpi_set_handle(device_t dev, ACPI_HANDLE h) { 113 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t)h)); 114} 115 116static __inline int 117acpi_get_magic(device_t dev) { 118 int m; 119 120 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t *)&m)) 121 return(0); 122 return(m); 123} 124 125static __inline int 126acpi_set_magic(device_t dev, int m) { 127 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t)m)); 128} 129 130static __inline void * 131acpi_get_private(device_t dev) { 132 void *p; 133 134 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t *)&p)) 135 return(NULL); 136 return(p); 137} 138 139static __inline int 140acpi_set_private(device_t dev, void *p) { 141 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t)p)); 142} 143 144static __inline ACPI_OBJECT_TYPE 145acpi_get_type(device_t dev) { 146 ACPI_HANDLE h; 147 ACPI_OBJECT_TYPE t; 148 149 if ((h = acpi_get_handle(dev)) == NULL) 150 return(ACPI_TYPE_NOT_FOUND); 151 if (AcpiGetType(h, &t) != AE_OK) 152 return(ACPI_TYPE_NOT_FOUND); 153 return(t); 154} 155 156#ifdef ENABLE_DEBUGGER 157extern void acpi_EnterDebugger(void); 158#endif 159 160#ifdef ACPI_DEBUG 161#include <sys/cons.h> 162#define STEP(x) do {printf x, printf("\n"); cngetc();} while (0) 163#else 164#define STEP(x) 165#endif 166
| 29 */ 30 31#include "bus_if.h" 32#include <sys/eventhandler.h> 33#include <sys/sysctl.h> 34 35extern devclass_t acpi_devclass; 36 37struct acpi_softc { 38 device_t acpi_dev; 39 dev_t acpi_dev_t; 40 41 struct resource *acpi_irq; 42 int acpi_irq_rid; 43 void *acpi_irq_handle; 44 45 int acpi_enabled; 46 int acpi_sstate; 47 48 struct sysctl_ctx_list acpi_sysctl_ctx; 49 struct sysctl_oid *acpi_sysctl_tree; 50#define ACPI_POWER_BUTTON_DEFAULT_SX ACPI_STATE_S5; 51#define ACPI_SLEEP_BUTTON_DEFAULT_SX ACPI_STATE_S1; 52#define ACPI_LID_SWITCH_DEFAULT_SX ACPI_STATE_S1; 53 int acpi_power_button_sx; 54 int acpi_sleep_button_sx; 55 int acpi_lid_switch_sx; 56 57 struct sysctl_ctx_list acpi_battery_sysctl_ctx; 58 struct sysctl_oid *acpi_battery_sysctl_tree; 59}; 60 61struct acpi_device { 62 /* ACPI ivars */ 63 ACPI_HANDLE ad_handle; 64 int ad_magic; 65 void *ad_private; 66 67 /* resources */ 68 struct resource_list ad_rl; 69}; 70 71/* 72 * This is a cheap and nasty way to get around the horrid counted list 73 * argument format that AcpiEvalateMethod uses. 74 */ 75#define ACPI_OBJECTLIST_MAX 16 76struct acpi_object_list { 77 UINT32 count; 78 ACPI_OBJECT *pointer[ACPI_OBJECTLIST_MAX]; 79 ACPI_OBJECT object[ACPI_OBJECTLIST_MAX]; 80}; 81 82static __inline struct acpi_object_list * 83acpi_AllocObjectList(int nobj) { 84 struct acpi_object_list *l; 85 int i; 86 87 if (nobj > ACPI_OBJECTLIST_MAX) 88 return(NULL); 89 if ((l = AcpiOsAllocate(sizeof(*l))) == NULL) 90 return(NULL); 91 bzero(l, sizeof(*l)); 92 for (i = 0; i < ACPI_OBJECTLIST_MAX; i++) 93 l->pointer[i] = &l->object[i]; 94 l->count = nobj; 95 return(l); 96} 97 98#define ACPI_IVAR_HANDLE 0x100 99#define ACPI_IVAR_MAGIC 0x101 100#define ACPI_IVAR_PRIVATE 0x102 101 102static __inline ACPI_HANDLE 103acpi_get_handle(device_t dev) { 104 ACPI_HANDLE h; 105 106 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t *)&h)) 107 return(NULL); 108 return(h); 109} 110 111static __inline int 112acpi_set_handle(device_t dev, ACPI_HANDLE h) { 113 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t)h)); 114} 115 116static __inline int 117acpi_get_magic(device_t dev) { 118 int m; 119 120 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t *)&m)) 121 return(0); 122 return(m); 123} 124 125static __inline int 126acpi_set_magic(device_t dev, int m) { 127 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t)m)); 128} 129 130static __inline void * 131acpi_get_private(device_t dev) { 132 void *p; 133 134 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t *)&p)) 135 return(NULL); 136 return(p); 137} 138 139static __inline int 140acpi_set_private(device_t dev, void *p) { 141 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t)p)); 142} 143 144static __inline ACPI_OBJECT_TYPE 145acpi_get_type(device_t dev) { 146 ACPI_HANDLE h; 147 ACPI_OBJECT_TYPE t; 148 149 if ((h = acpi_get_handle(dev)) == NULL) 150 return(ACPI_TYPE_NOT_FOUND); 151 if (AcpiGetType(h, &t) != AE_OK) 152 return(ACPI_TYPE_NOT_FOUND); 153 return(t); 154} 155 156#ifdef ENABLE_DEBUGGER 157extern void acpi_EnterDebugger(void); 158#endif 159 160#ifdef ACPI_DEBUG 161#include <sys/cons.h> 162#define STEP(x) do {printf x, printf("\n"); cngetc();} while (0) 163#else 164#define STEP(x) 165#endif 166
|
| 167extern BOOLEAN acpi_DeviceIsPresent(device_t dev);
|
167extern BOOLEAN acpi_MatchHid(device_t dev, char *hid);
| 168extern BOOLEAN acpi_MatchHid(device_t dev, char *hid);
|
| 169extern ACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path, ACPI_HANDLE *result); 170extern ACPI_BUFFER *acpi_AllocBuffer(int size);
|
168extern ACPI_STATUS acpi_GetIntoBuffer(ACPI_HANDLE handle, 169 ACPI_STATUS (*func)(ACPI_HANDLE, ACPI_BUFFER *), 170 ACPI_BUFFER *buf);
| 171extern ACPI_STATUS acpi_GetIntoBuffer(ACPI_HANDLE handle, 172 ACPI_STATUS (*func)(ACPI_HANDLE, ACPI_BUFFER *), 173 ACPI_BUFFER *buf);
|
171extern ACPI_BUFFER *acpi_AllocBuffer(int size);
| 174extern ACPI_STATUS acpi_EvaluateIntoBuffer(ACPI_HANDLE object, ACPI_STRING pathname, 175 ACPI_OBJECT_LIST *params, ACPI_BUFFER *buf); 176extern ACPI_STATUS acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number); 177extern ACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj, 178 void (* func)(ACPI_OBJECT *comp, void *arg), 179 void *arg); 180
|
172extern ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state); 173extern ACPI_STATUS acpi_Enable(struct acpi_softc *sc); 174extern ACPI_STATUS acpi_Disable(struct acpi_softc *sc);
| 181extern ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state); 182extern ACPI_STATUS acpi_Enable(struct acpi_softc *sc); 183extern ACPI_STATUS acpi_Disable(struct acpi_softc *sc);
|
175extern BOOLEAN acpi_DeviceIsPresent(device_t dev); 176extern ACPI_STATUS acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number);
| |
177 178struct acpi_parse_resource_set { 179 void (* set_init)(device_t dev, void **context); 180 void (* set_done)(device_t dev, void *context); 181 void (* set_ioport)(device_t dev, void *context, u_int32_t base, u_int32_t length); 182 void (* set_iorange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 183 u_int32_t length, u_int32_t align); 184 void (* set_memory)(device_t dev, void *context, u_int32_t base, u_int32_t length); 185 void (* set_memoryrange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 186 u_int32_t length, u_int32_t align); 187 void (* set_irq)(device_t dev, void *context, u_int32_t irq); 188 void (* set_drq)(device_t dev, void *context, u_int32_t drq); 189 void (* set_start_dependant)(device_t dev, void *context, int preference); 190 void (* set_end_dependant)(device_t dev, void *context); 191}; 192 193extern struct acpi_parse_resource_set acpi_res_parse_set; 194extern ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, 195 struct acpi_parse_resource_set *set); 196 197/* XXX this is ugly */ 198extern char *acpi_strerror(ACPI_STATUS excep); 199 200/* 201 * ACPI event handling 202 */ 203extern UINT32 acpi_eventhandler_power_button_for_sleep(void *context); 204extern UINT32 acpi_eventhandler_power_button_for_wakeup(void *context); 205extern UINT32 acpi_eventhandler_sleep_button_for_sleep(void *context); 206extern UINT32 acpi_eventhandler_sleep_button_for_wakeup(void *context); 207 208#define ACPI_EVENT_PRI_FIRST 0 209#define ACPI_EVENT_PRI_DEFAULT 10000 210#define ACPI_EVENT_PRI_LAST 20000 211 212typedef void (*acpi_event_handler_t) __P((void *, int)); 213 214EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t); 215EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t); 216
| 184 185struct acpi_parse_resource_set { 186 void (* set_init)(device_t dev, void **context); 187 void (* set_done)(device_t dev, void *context); 188 void (* set_ioport)(device_t dev, void *context, u_int32_t base, u_int32_t length); 189 void (* set_iorange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 190 u_int32_t length, u_int32_t align); 191 void (* set_memory)(device_t dev, void *context, u_int32_t base, u_int32_t length); 192 void (* set_memoryrange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 193 u_int32_t length, u_int32_t align); 194 void (* set_irq)(device_t dev, void *context, u_int32_t irq); 195 void (* set_drq)(device_t dev, void *context, u_int32_t drq); 196 void (* set_start_dependant)(device_t dev, void *context, int preference); 197 void (* set_end_dependant)(device_t dev, void *context); 198}; 199 200extern struct acpi_parse_resource_set acpi_res_parse_set; 201extern ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, 202 struct acpi_parse_resource_set *set); 203 204/* XXX this is ugly */ 205extern char *acpi_strerror(ACPI_STATUS excep); 206 207/* 208 * ACPI event handling 209 */ 210extern UINT32 acpi_eventhandler_power_button_for_sleep(void *context); 211extern UINT32 acpi_eventhandler_power_button_for_wakeup(void *context); 212extern UINT32 acpi_eventhandler_sleep_button_for_sleep(void *context); 213extern UINT32 acpi_eventhandler_sleep_button_for_wakeup(void *context); 214 215#define ACPI_EVENT_PRI_FIRST 0 216#define ACPI_EVENT_PRI_DEFAULT 10000 217#define ACPI_EVENT_PRI_LAST 20000 218 219typedef void (*acpi_event_handler_t) __P((void *, int)); 220 221EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t); 222EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t); 223
|
| 224/* 225 * Device power control. 226 */ 227extern ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state); 228
|
217/* 218 * Misc. 219 */ 220static __inline struct acpi_softc * 221acpi_device_get_parent_softc(device_t child) 222{ 223 device_t parent; 224 225 parent = device_get_parent(child); 226 if (parent == NULL) { 227 return(NULL); 228 } 229 return(device_get_softc(parent)); 230} 231 232extern char *acpi_name(ACPI_HANDLE handle); 233extern int acpi_avoid(ACPI_HANDLE handle); 234extern int acpi_disabled(char *subsys); 235 236/* 237 * Battery Abstruction and Generalized Power Management interface. 238 */ 239struct acpi_battinfo; 240 241extern int acpi_battery_register(int, int); 242extern int acpi_acad_get_acline(void); 243extern int acpi_cmbat_get_battinfo(int, struct acpi_battinfo *); 244
| 229/* 230 * Misc. 231 */ 232static __inline struct acpi_softc * 233acpi_device_get_parent_softc(device_t child) 234{ 235 device_t parent; 236 237 parent = device_get_parent(child); 238 if (parent == NULL) { 239 return(NULL); 240 } 241 return(device_get_softc(parent)); 242} 243 244extern char *acpi_name(ACPI_HANDLE handle); 245extern int acpi_avoid(ACPI_HANDLE handle); 246extern int acpi_disabled(char *subsys); 247 248/* 249 * Battery Abstruction and Generalized Power Management interface. 250 */ 251struct acpi_battinfo; 252 253extern int acpi_battery_register(int, int); 254extern int acpi_acad_get_acline(void); 255extern int acpi_cmbat_get_battinfo(int, struct acpi_battinfo *); 256
|