1 /* $OpenBSD: acpivar.h,v 1.46 2009/02/19 21:02:05 marco Exp $ */ 2 /* 3 * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _DEV_ACPI_ACPIVAR_H_ 19 #define _DEV_ACPI_ACPIVAR_H_ 20 21 #define ACPI_TRAMPOLINE (NBPG*4) 22 23 #ifndef _ACPI_WAKECODE 24 25 #include <sys/timeout.h> 26 #include <sys/rwlock.h> 27 #include <machine/biosvar.h> 28 29 /* #define ACPI_DEBUG */ 30 #ifdef ACPI_DEBUG 31 extern int acpi_debug; 32 #define dprintf(x...) do { if (acpi_debug) printf(x); } while (0) 33 #define dnprintf(n,x...) do { if (acpi_debug > (n)) printf(x); } while (0) 34 #else 35 #define dprintf(x...) 36 #define dnprintf(n,x...) 37 #endif 38 39 /* #define ACPI_SLEEP_ENABLED */ 40 41 extern int acpi_hasprocfvs; 42 43 #define LAPIC_MAP_SIZE 256 44 extern u_int8_t acpi_lapic_flags[LAPIC_MAP_SIZE]; 45 46 struct klist; 47 struct acpiec_softc; 48 49 struct acpi_attach_args { 50 char *aaa_name; 51 bus_space_tag_t aaa_iot; 52 bus_space_tag_t aaa_memt; 53 void *aaa_table; 54 struct aml_node *aaa_node; 55 const char *aaa_dev; 56 }; 57 58 struct acpi_mem_map { 59 vaddr_t baseva; 60 u_int8_t *va; 61 size_t vsize; 62 paddr_t pa; 63 }; 64 65 struct acpi_q { 66 SIMPLEQ_ENTRY(acpi_q) q_next; 67 void *q_table; 68 u_int8_t q_data[0]; 69 }; 70 71 struct acpi_wakeq { 72 SIMPLEQ_ENTRY(acpi_wakeq) q_next; 73 struct aml_node *q_node; 74 struct aml_value *q_wakepkg; 75 int q_gpe; 76 int q_state; 77 }; 78 79 typedef SIMPLEQ_HEAD(, acpi_q) acpi_qhead_t; 80 typedef SIMPLEQ_HEAD(, acpi_wakeq) acpi_wakeqhead_t; 81 82 #define ACPIREG_PM1A_STS 0x00 83 #define ACPIREG_PM1A_EN 0x01 84 #define ACPIREG_PM1A_CNT 0x02 85 #define ACPIREG_PM1B_STS 0x03 86 #define ACPIREG_PM1B_EN 0x04 87 #define ACPIREG_PM1B_CNT 0x05 88 #define ACPIREG_PM2_CNT 0x06 89 #define ACPIREG_PM_TMR 0x07 90 #define ACPIREG_GPE0_STS 0x08 91 #define ACPIREG_GPE0_EN 0x09 92 #define ACPIREG_GPE1_STS 0x0A 93 #define ACPIREG_GPE1_EN 0x0B 94 #define ACPIREG_SMICMD 0x0C 95 #define ACPIREG_MAXREG 0x0D 96 97 /* Special registers */ 98 #define ACPIREG_PM1_STS 0x0E 99 #define ACPIREG_PM1_EN 0x0F 100 #define ACPIREG_PM1_CNT 0x10 101 #define ACPIREG_GPE_STS 0x11 102 #define ACPIREG_GPE_EN 0x12 103 104 struct acpi_parsestate { 105 u_int8_t *start; 106 u_int8_t *end; 107 u_int8_t *pos; 108 }; 109 110 struct acpi_reg_map { 111 bus_space_handle_t ioh; 112 int addr; 113 int size; 114 const char *name; 115 }; 116 117 struct acpi_thread { 118 struct acpi_softc *sc; 119 volatile int running; 120 }; 121 122 struct acpi_mutex { 123 struct rwlock amt_lock; 124 #define ACPI_MTX_MAXNAME 5 125 char amt_name[ACPI_MTX_MAXNAME + 3]; /* only 4 used */ 126 int amt_ref_count; 127 int amt_timeout; 128 int amt_synclevel; 129 }; 130 131 struct gpe_block { 132 int (*handler)(struct acpi_softc *, int, void *); 133 void *arg; 134 int active; 135 }; 136 137 struct acpi_ac { 138 struct acpiac_softc *aac_softc; 139 SLIST_ENTRY(acpi_ac) aac_link; 140 }; 141 142 SLIST_HEAD(acpi_ac_head, acpi_ac); 143 144 struct acpi_bat { 145 struct acpibat_softc *aba_softc; 146 SLIST_ENTRY(acpi_bat) aba_link; 147 }; 148 149 SLIST_HEAD(acpi_bat_head, acpi_bat); 150 151 struct acpi_softc { 152 struct device sc_dev; 153 154 bus_space_tag_t sc_iot; 155 bus_space_tag_t sc_memt; 156 #if 0 157 bus_space_tag_t sc_pcit; 158 bus_space_tag_t sc_smbust; 159 #endif 160 161 /* 162 * First-level ACPI tables 163 */ 164 struct acpi_fadt *sc_fadt; 165 acpi_qhead_t sc_tables; 166 acpi_wakeqhead_t sc_wakedevs; 167 168 /* 169 * Second-level information from FADT 170 */ 171 struct acpi_facs *sc_facs; /* Shared with firmware! */ 172 173 struct klist *sc_note; 174 struct acpi_reg_map sc_pmregs[ACPIREG_MAXREG]; 175 bus_space_handle_t sc_ioh_pm1a_evt; 176 177 void *sc_interrupt; 178 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS 179 void *sc_softih; 180 #else 181 struct timeout sc_timeout; 182 #endif 183 184 int sc_powerbtn; 185 int sc_sleepbtn; 186 187 struct { 188 int slp_typa; 189 int slp_typb; 190 } sc_sleeptype[6]; 191 int sc_maxgpe; 192 int sc_lastgpe; 193 194 struct gpe_block *gpe_table; 195 196 int sc_wakeup; 197 u_int32_t sc_gpe_sts; 198 u_int32_t sc_gpe_en; 199 struct acpi_thread *sc_thread; 200 201 struct aml_node *sc_tts; 202 struct aml_node *sc_pts; 203 struct aml_node *sc_bfs; 204 struct aml_node *sc_gts; 205 struct aml_node *sc_wak; 206 int sc_state; 207 struct acpiec_softc *sc_ec; /* XXX assume single EC */ 208 209 struct acpi_ac_head sc_ac; 210 struct acpi_bat_head sc_bat; 211 212 struct timeout sc_dev_timeout; 213 int sc_poll; 214 215 int sc_revision; 216 }; 217 218 #define GPE_NONE 0x00 219 #define GPE_LEVEL 0x01 220 #define GPE_EDGE 0x02 221 222 struct acpi_table { 223 int offset; 224 size_t size; 225 void *table; 226 }; 227 228 #define ACPI_IOC_GETFACS _IOR('A', 0, struct acpi_facs) 229 #define ACPI_IOC_GETTABLE _IOWR('A', 1, struct acpi_table) 230 #define ACPI_IOC_SETSLEEPSTATE _IOW('A', 2, int) 231 232 #define ACPI_EV_PWRBTN 0x0001 /* Power button was pushed */ 233 #define ACPI_EV_SLPBTN 0x0002 /* Sleep button was pushed */ 234 235 #define ACPI_EVENT_MASK 0x0003 236 237 #define ACPI_EVENT_COMPOSE(t,i) (((i) & 0x7fff) << 16 | ((t) & ACPI_EVENT_MASK)) 238 #define ACPI_EVENT_TYPE(e) ((e) & ACPI_EVENT_MASK) 239 #define ACPI_EVENT_INDEX(e) ((e) >> 16) 240 241 #if defined(_KERNEL) 242 struct acpi_gas; 243 int acpi_map_address(struct acpi_softc *, struct acpi_gas *, bus_addr_t, bus_size_t, 244 bus_space_handle_t *, bus_space_tag_t *); 245 246 int acpi_map(paddr_t, size_t, struct acpi_mem_map *); 247 void acpi_unmap(struct acpi_mem_map *); 248 int acpi_probe(struct device *, struct cfdata *, struct bios_attach_args *); 249 u_int acpi_checksum(const void *, size_t); 250 void acpi_attach_machdep(struct acpi_softc *); 251 int acpi_interrupt(void *); 252 void acpi_powerdown(void); 253 void acpi_reset(void); 254 void acpi_cpu_flush(struct acpi_softc *, int); 255 int acpi_sleep_state(struct acpi_softc *, int); 256 void acpi_resume(struct acpi_softc *); 257 int acpi_prepare_sleep_state(struct acpi_softc *, int); 258 int acpi_enter_sleep_state(struct acpi_softc *, int); 259 int acpi_sleep_machdep(struct acpi_softc *, int); 260 void acpi_sleep_walk(struct acpi_softc *, int); 261 262 263 #define ACPI_IOREAD 0 264 #define ACPI_IOWRITE 1 265 266 void acpi_delay(struct acpi_softc *, int64_t); 267 int acpi_gasio(struct acpi_softc *, int, int, uint64_t, int, int, void *); 268 269 int acpi_set_gpehandler(struct acpi_softc *, int, 270 int (*)(struct acpi_softc *, int, void *), void *, const char *); 271 void acpi_enable_gpe(struct acpi_softc *, u_int32_t); 272 273 int acpiec_intr(struct acpiec_softc *); 274 void acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *); 275 void acpiec_write(struct acpiec_softc *, u_int8_t, int, u_int8_t *); 276 void acpiec_handle_events(struct acpiec_softc *); 277 278 int acpi_read_pmreg(struct acpi_softc *, int, int); 279 void acpi_write_pmreg(struct acpi_softc *, int, int, int); 280 281 void acpi_poll(void *); 282 283 int acpi_matchhids(struct acpi_attach_args *, const char *[], const char *); 284 285 #endif 286 287 #endif /* !_ACPI_WAKECODE */ 288 #endif /* !_DEV_ACPI_ACPIVAR_H_ */ 289