1 /* $OpenBSD: acpivar.h,v 1.71 2011/04/15 17:34:51 oga 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 extern int acpi_hasprocfvs; 40 41 #define LAPIC_MAP_SIZE 256 42 extern u_int8_t acpi_lapic_flags[LAPIC_MAP_SIZE]; 43 44 struct klist; 45 struct acpiec_softc; 46 47 struct acpivideo_softc { 48 struct device sc_dev; 49 50 struct acpi_softc *sc_acpi; 51 struct aml_node *sc_devnode; 52 }; 53 54 struct acpi_attach_args { 55 char *aaa_name; 56 bus_space_tag_t aaa_iot; 57 bus_space_tag_t aaa_memt; 58 void *aaa_table; 59 struct aml_node *aaa_node; 60 const char *aaa_dev; 61 }; 62 63 struct acpi_mem_map { 64 vaddr_t baseva; 65 u_int8_t *va; 66 size_t vsize; 67 paddr_t pa; 68 }; 69 70 struct acpi_q { 71 SIMPLEQ_ENTRY(acpi_q) q_next; 72 int q_id; 73 void *q_table; 74 u_int8_t q_data[0]; 75 }; 76 77 struct acpi_taskq { 78 SIMPLEQ_ENTRY(acpi_taskq) next; 79 void (*handler)(void *, int); 80 void *arg0; 81 int arg1; 82 }; 83 84 struct acpi_wakeq { 85 SIMPLEQ_ENTRY(acpi_wakeq) q_next; 86 struct aml_node *q_node; 87 struct aml_value *q_wakepkg; 88 int q_gpe; 89 int q_state; 90 }; 91 92 typedef SIMPLEQ_HEAD(, acpi_q) acpi_qhead_t; 93 typedef SIMPLEQ_HEAD(, acpi_wakeq) acpi_wakeqhead_t; 94 95 #define ACPIREG_PM1A_STS 0x00 96 #define ACPIREG_PM1A_EN 0x01 97 #define ACPIREG_PM1A_CNT 0x02 98 #define ACPIREG_PM1B_STS 0x03 99 #define ACPIREG_PM1B_EN 0x04 100 #define ACPIREG_PM1B_CNT 0x05 101 #define ACPIREG_PM2_CNT 0x06 102 #define ACPIREG_PM_TMR 0x07 103 #define ACPIREG_GPE0_STS 0x08 104 #define ACPIREG_GPE0_EN 0x09 105 #define ACPIREG_GPE1_STS 0x0A 106 #define ACPIREG_GPE1_EN 0x0B 107 #define ACPIREG_SMICMD 0x0C 108 #define ACPIREG_MAXREG 0x0D 109 110 /* Special registers */ 111 #define ACPIREG_PM1_STS 0x0E 112 #define ACPIREG_PM1_EN 0x0F 113 #define ACPIREG_PM1_CNT 0x10 114 #define ACPIREG_GPE_STS 0x11 115 #define ACPIREG_GPE_EN 0x12 116 117 /* System status (_SST) codes */ 118 #define ACPI_SST_INDICATOR_OFF 0 119 #define ACPI_SST_WORKING 1 120 #define ACPI_SST_WAKING 2 121 #define ACPI_SST_SLEEPING 3 122 #define ACPI_SST_SLEEP_CONTEXT 4 123 124 struct acpi_parsestate { 125 u_int8_t *start; 126 u_int8_t *end; 127 u_int8_t *pos; 128 }; 129 130 struct acpi_reg_map { 131 bus_space_handle_t ioh; 132 int addr; 133 int size; 134 int access; 135 const char *name; 136 }; 137 138 struct acpi_thread { 139 struct acpi_softc *sc; 140 volatile int running; 141 }; 142 143 struct acpi_mutex { 144 struct rwlock amt_lock; 145 #define ACPI_MTX_MAXNAME 5 146 char amt_name[ACPI_MTX_MAXNAME + 3]; /* only 4 used */ 147 int amt_ref_count; 148 int amt_timeout; 149 int amt_synclevel; 150 }; 151 152 struct gpe_block { 153 int (*handler)(struct acpi_softc *, int, void *); 154 void *arg; 155 int active; 156 int edge; 157 }; 158 159 struct acpi_devlist { 160 struct aml_node *dev_node; 161 TAILQ_ENTRY(acpi_devlist) dev_link; 162 }; 163 164 TAILQ_HEAD(acpi_devlist_head, acpi_devlist); 165 166 struct acpi_ac { 167 struct acpiac_softc *aac_softc; 168 SLIST_ENTRY(acpi_ac) aac_link; 169 }; 170 171 SLIST_HEAD(acpi_ac_head, acpi_ac); 172 173 struct acpi_bat { 174 struct acpibat_softc *aba_softc; 175 SLIST_ENTRY(acpi_bat) aba_link; 176 }; 177 178 SLIST_HEAD(acpi_bat_head, acpi_bat); 179 180 struct acpi_softc { 181 struct device sc_dev; 182 183 bus_space_tag_t sc_iot; 184 bus_space_tag_t sc_memt; 185 #if 0 186 bus_space_tag_t sc_pcit; 187 bus_space_tag_t sc_smbust; 188 #endif 189 190 /* 191 * First-level ACPI tables 192 */ 193 struct acpi_fadt *sc_fadt; 194 acpi_qhead_t sc_tables; 195 acpi_wakeqhead_t sc_wakedevs; 196 197 /* 198 * Second-level information from FADT 199 */ 200 struct acpi_facs *sc_facs; /* Shared with firmware! */ 201 202 struct klist *sc_note; 203 struct acpi_reg_map sc_pmregs[ACPIREG_MAXREG]; 204 bus_space_handle_t sc_ioh_pm1a_evt; 205 206 void *sc_interrupt; 207 208 struct rwlock sc_lck; 209 210 struct { 211 int slp_typa; 212 int slp_typb; 213 } sc_sleeptype[6]; 214 int sc_maxgpe; 215 int sc_lastgpe; 216 217 struct gpe_block *gpe_table; 218 219 int sc_threadwaiting; 220 u_int32_t sc_gpe_sts; 221 u_int32_t sc_gpe_en; 222 struct acpi_thread *sc_thread; 223 224 struct aml_node *sc_tts; 225 struct aml_node *sc_pts; 226 struct aml_node *sc_bfs; 227 struct aml_node *sc_gts; 228 struct aml_node *sc_sst; 229 struct aml_node *sc_wak; 230 int sc_state; 231 struct acpiec_softc *sc_ec; /* XXX assume single EC */ 232 233 struct acpi_ac_head sc_ac; 234 struct acpi_bat_head sc_bat; 235 236 struct timeout sc_dev_timeout; 237 238 int sc_revision; 239 240 int sc_pse; /* passive cooling enabled */ 241 242 int sc_flags; 243 }; 244 245 extern struct acpi_softc *acpi_softc; 246 247 #define SCFLAG_OREAD 0x0000001 248 #define SCFLAG_OWRITE 0x0000002 249 #define SCFLAG_OPEN (SCFLAG_OREAD|SCFLAG_OWRITE) 250 251 #define GPE_NONE 0x00 252 #define GPE_LEVEL 0x01 253 #define GPE_EDGE 0x02 254 255 struct acpi_table { 256 int offset; 257 size_t size; 258 void *table; 259 }; 260 261 struct acpi_dev_rank { 262 struct device *dev; 263 int rank; 264 TAILQ_ENTRY(acpi_dev_rank) link; 265 }; 266 267 #define ACPI_IOC_GETFACS _IOR('A', 0, struct acpi_facs) 268 #define ACPI_IOC_GETTABLE _IOWR('A', 1, struct acpi_table) 269 #define ACPI_IOC_SETSLEEPSTATE _IOW('A', 2, int) 270 271 #if defined(_KERNEL) 272 struct acpi_gas; 273 int acpi_map_address(struct acpi_softc *, struct acpi_gas *, bus_addr_t, bus_size_t, 274 bus_space_handle_t *, bus_space_tag_t *); 275 276 int acpi_map(paddr_t, size_t, struct acpi_mem_map *); 277 void acpi_unmap(struct acpi_mem_map *); 278 int acpi_probe(struct device *, struct cfdata *, struct bios_attach_args *); 279 u_int acpi_checksum(const void *, size_t); 280 void acpi_attach_machdep(struct acpi_softc *); 281 int acpi_interrupt(void *); 282 void acpi_powerdown(void); 283 void acpi_reset(void); 284 void acpi_cpu_flush(struct acpi_softc *, int); 285 int acpi_sleep_state(struct acpi_softc *, int); 286 int acpi_prepare_sleep_state(struct acpi_softc *, int); 287 int acpi_enter_sleep_state(struct acpi_softc *, int); 288 int acpi_sleep_machdep(struct acpi_softc *, int); 289 void acpi_resume_machdep(void); 290 void acpi_sleep_walk(struct acpi_softc *, int); 291 292 293 #define ACPI_IOREAD 0 294 #define ACPI_IOWRITE 1 295 296 void acpi_wakeup(void *); 297 298 int acpi_gasio(struct acpi_softc *, int, int, uint64_t, int, int, void *); 299 300 int acpi_set_gpehandler(struct acpi_softc *, int, 301 int (*)(struct acpi_softc *, int, void *), void *, int); 302 void acpi_enable_gpe(struct acpi_softc *, u_int32_t); 303 304 int acpiec_intr(struct acpiec_softc *); 305 void acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *); 306 void acpiec_write(struct acpiec_softc *, u_int8_t, int, u_int8_t *); 307 void acpiec_handle_events(struct acpiec_softc *); 308 309 int acpi_read_pmreg(struct acpi_softc *, int, int); 310 void acpi_write_pmreg(struct acpi_softc *, int, int, int); 311 312 void acpi_poll(void *); 313 void acpi_sleep(int, char *); 314 315 int acpi_matchhids(struct acpi_attach_args *, const char *[], const char *); 316 317 int acpi_record_event(struct acpi_softc *, u_int); 318 319 void acpi_addtask(struct acpi_softc *, void (*)(void *, int), void *, int); 320 int acpi_dotask(struct acpi_softc *); 321 322 void acpi_powerdown_task(void *, int); 323 void acpi_sleep_task(void *, int); 324 325 #endif 326 327 #endif /* !_ACPI_WAKECODE */ 328 #endif /* !_DEV_ACPI_ACPIVAR_H_ */ 329