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 *
|
65 struct sysctl_ctx_list acpi_battery_sysctl_ctx; 66 struct sysctl_oid *acpi_battery_sysctl_tree; 67}; 68 69struct acpi_device { 70 /* ACPI ivars */ 71 ACPI_HANDLE ad_handle; 72 int ad_magic; 73 void *ad_private; 74 75 /* resources */ 76 struct resource_list ad_rl; 77 78}; 79 80/* 81 * The ACPI subsystem lives under a single mutex. You *must* 82 * acquire this mutex before calling any of the acpi_ or Acpi* functions. 83 * 84 * XXX the ACPI_MSLEEP macro should go away once locking is resolved 85 */ 86extern struct mtx acpi_mutex; 87#if 0 88# define ACPI_LOCK mtx_lock(&acpi_mutex) 89# define ACPI_UNLOCK mtx_unlock(&acpi_mutex) 90# define ACPI_ASSERTLOCK mtx_assert(&acpi_mutex, MA_OWNED) 91# define ACPI_MSLEEP(a, b, c, d, e) msleep(a, b, c, d, e) 92#else 93# define ACPI_LOCK 94# define ACPI_UNLOCK 95# define ACPI_ASSERTLOCK 96# define ACPI_MSLEEP(a, b, c, d, e) tsleep(a, c, d, e) 97#endif 98 99/* 100 * This is a cheap and nasty way to get around the horrid counted list 101 * argument format that AcpiEvalateObject uses. 102 */ 103#define ACPI_OBJECTLIST_MAX 16 104struct acpi_object_list { 105 UINT32 count; 106 ACPI_OBJECT *pointer[ACPI_OBJECTLIST_MAX]; 107 ACPI_OBJECT object[ACPI_OBJECTLIST_MAX]; 108}; 109 110static __inline struct acpi_object_list * 111acpi_AllocObjectList(int nobj) { 112 struct acpi_object_list *l; 113 int i; 114 115 if (nobj > ACPI_OBJECTLIST_MAX) 116 return(NULL); 117 if ((l = AcpiOsAllocate(sizeof(*l))) == NULL) 118 return(NULL); 119 bzero(l, sizeof(*l)); 120 for (i = 0; i < ACPI_OBJECTLIST_MAX; i++) 121 l->pointer[i] = &l->object[i]; 122 l->count = nobj; 123 return(l); 124} 125 126#define ACPI_IVAR_HANDLE 0x100 127#define ACPI_IVAR_MAGIC 0x101 128#define ACPI_IVAR_PRIVATE 0x102 129 130static __inline ACPI_HANDLE 131acpi_get_handle(device_t dev) { 132 ACPI_HANDLE h; 133 134 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t *)&h)) 135 return(NULL); 136 return(h); 137} 138 139static __inline int 140acpi_set_handle(device_t dev, ACPI_HANDLE h) { 141 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_HANDLE, (uintptr_t)h)); 142} 143 144static __inline int 145acpi_get_magic(device_t dev) { 146 int m; 147 148 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t *)&m)) 149 return(0); 150 return(m); 151} 152 153static __inline int 154acpi_set_magic(device_t dev, int m) { 155 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_MAGIC, (uintptr_t)m)); 156} 157 158static __inline void * 159acpi_get_private(device_t dev) { 160 void *p; 161 162 if (BUS_READ_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t *)&p)) 163 return(NULL); 164 return(p); 165} 166 167static __inline int 168acpi_set_private(device_t dev, void *p) { 169 return(BUS_WRITE_IVAR(device_get_parent(dev), dev, ACPI_IVAR_PRIVATE, (uintptr_t)p)); 170} 171 172static __inline ACPI_OBJECT_TYPE 173acpi_get_type(device_t dev) { 174 ACPI_HANDLE h; 175 ACPI_OBJECT_TYPE t; 176 177 if ((h = acpi_get_handle(dev)) == NULL) 178 return(ACPI_TYPE_NOT_FOUND); 179 if (AcpiGetType(h, &t) != AE_OK) 180 return(ACPI_TYPE_NOT_FOUND); 181 return(t); 182} 183 184#ifdef ENABLE_DEBUGGER 185extern void acpi_EnterDebugger(void); 186#endif 187 188#ifdef ACPI_DEBUG 189#include <sys/cons.h> 190#define STEP(x) do {printf x, printf("\n"); cngetc();} while (0) 191#else 192#define STEP(x) 193#endif 194 195extern BOOLEAN acpi_DeviceIsPresent(device_t dev); 196extern BOOLEAN acpi_MatchHid(device_t dev, char *hid); 197extern ACPI_STATUS acpi_GetHandleInScope(ACPI_HANDLE parent, char *path, ACPI_HANDLE *result); 198extern ACPI_BUFFER *acpi_AllocBuffer(int size); 199extern ACPI_STATUS acpi_GetIntoBuffer(ACPI_HANDLE handle, 200 ACPI_STATUS (*func)(ACPI_HANDLE, ACPI_BUFFER *), 201 ACPI_BUFFER *buf); 202extern ACPI_STATUS acpi_GetTableIntoBuffer(ACPI_TABLE_TYPE table, UINT32 instance, ACPI_BUFFER *buf); 203extern ACPI_STATUS acpi_EvaluateIntoBuffer(ACPI_HANDLE object, ACPI_STRING pathname, 204 ACPI_OBJECT_LIST *params, ACPI_BUFFER *buf); 205extern ACPI_STATUS acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number); 206extern ACPI_STATUS acpi_ForeachPackageObject(ACPI_OBJECT *obj, 207 void (* func)(ACPI_OBJECT *comp, void *arg), 208 void *arg); 209extern ACPI_STATUS acpi_FindIndexedResource(ACPI_RESOURCE *resbuf, int index, ACPI_RESOURCE **resp); 210 211extern ACPI_STATUS acpi_SetSleepState(struct acpi_softc *sc, int state); 212extern ACPI_STATUS acpi_Enable(struct acpi_softc *sc); 213extern ACPI_STATUS acpi_Disable(struct acpi_softc *sc); 214 215struct acpi_parse_resource_set { 216 void (* set_init)(device_t dev, void **context); 217 void (* set_done)(device_t dev, void *context); 218 void (* set_ioport)(device_t dev, void *context, u_int32_t base, u_int32_t length); 219 void (* set_iorange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 220 u_int32_t length, u_int32_t align); 221 void (* set_memory)(device_t dev, void *context, u_int32_t base, u_int32_t length); 222 void (* set_memoryrange)(device_t dev, void *context, u_int32_t low, u_int32_t high, 223 u_int32_t length, u_int32_t align); 224 void (* set_irq)(device_t dev, void *context, u_int32_t irq); 225 void (* set_drq)(device_t dev, void *context, u_int32_t drq); 226 void (* set_start_dependant)(device_t dev, void *context, int preference); 227 void (* set_end_dependant)(device_t dev, void *context); 228}; 229 230extern struct acpi_parse_resource_set acpi_res_parse_set; 231extern ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, 232 struct acpi_parse_resource_set *set); 233 234/* XXX this is ugly */ 235extern char *acpi_strerror(ACPI_STATUS excep); 236 237/* 238 * ACPI event handling 239 */ 240extern UINT32 acpi_eventhandler_power_button_for_sleep(void *context); 241extern UINT32 acpi_eventhandler_power_button_for_wakeup(void *context); 242extern UINT32 acpi_eventhandler_sleep_button_for_sleep(void *context); 243extern UINT32 acpi_eventhandler_sleep_button_for_wakeup(void *context); 244 245#define ACPI_EVENT_PRI_FIRST 0 246#define ACPI_EVENT_PRI_DEFAULT 10000 247#define ACPI_EVENT_PRI_LAST 20000 248 249typedef void (*acpi_event_handler_t) __P((void *, int)); 250 251EVENTHANDLER_DECLARE(acpi_sleep_event, acpi_event_handler_t); 252EVENTHANDLER_DECLARE(acpi_wakeup_event, acpi_event_handler_t); 253 254/* 255 * Device power control. 256 */ 257extern ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state); 258 259/* 260 * Misc. 261 */ 262static __inline struct acpi_softc * 263acpi_device_get_parent_softc(device_t child) 264{ 265 device_t parent; 266 267 parent = device_get_parent(child); 268 if (parent == NULL) { 269 return(NULL); 270 } 271 return(device_get_softc(parent)); 272} 273 274extern char *acpi_name(ACPI_HANDLE handle); 275extern int acpi_avoid(ACPI_HANDLE handle); 276extern int acpi_disabled(char *subsys); 277
|