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