1 /* $NetBSD: acpivar.h,v 1.73 2011/08/01 11:25:59 jmcneill Exp $ */ 2 3 /* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 #ifndef _SYS_DEV_ACPI_ACPIVAR_H 39 #define _SYS_DEV_ACPI_ACPIVAR_H 40 41 /* 42 * This file defines the ACPI interface provided to the rest of the 43 * kernel, as well as the autoconfiguration structures for ACPI 44 * support. 45 */ 46 47 #include <sys/bus.h> 48 #include <dev/pci/pcivar.h> 49 #include <dev/isa/isavar.h> 50 51 #include <dev/acpi/acpica.h> 52 #include <dev/acpi/acpi_util.h> 53 54 #include <dev/sysmon/sysmonvar.h> 55 56 /* 57 * This structure is used to attach the ACPI "bus". 58 */ 59 struct acpibus_attach_args { 60 bus_space_tag_t aa_iot; /* PCI I/O space tag */ 61 bus_space_tag_t aa_memt; /* PCI MEM space tag */ 62 pci_chipset_tag_t aa_pc; /* PCI chipset */ 63 int aa_pciflags; /* PCI bus flags */ 64 isa_chipset_tag_t aa_ic; /* ISA chipset */ 65 }; 66 67 /* 68 * PCI information for ACPI device nodes that correspond to PCI devices. 69 * 70 * Remarks: 71 * 72 * ap_bus <= 255 73 * ap_device <= 31 74 * ap_function <= 7 or ap_function == 0xFFFF 75 * ap_downbus <= 255 76 * 77 * Validity of some fields depends on the value of ap_flags: 78 * 79 * ap_segment always valid 80 * ap_bus, ap_device, ap_function valid for PCI devices 81 * ap_downbus valid for PCI bridges 82 * 83 * The device and function numbers are encoded in the value returned by 84 * _ADR. A function number of 0xFFFF is used to refer to all the 85 * functions on a PCI device (ACPI 4.0a, p. 200). 86 */ 87 struct acpi_pci_info { 88 uint16_t ap_flags; /* Flags (cf. below) */ 89 uint16_t ap_segment; /* PCI segment group */ 90 uint16_t ap_bus; /* PCI bus */ 91 uint16_t ap_device; /* PCI device */ 92 uint16_t ap_function; /* PCI function */ 93 uint16_t ap_downbus; /* PCI bridge downstream bus */ 94 }; 95 96 /* 97 * Flags for PCI information. 98 */ 99 #define ACPI_PCI_INFO_DEVICE __BIT(0) /* PCI device */ 100 #define ACPI_PCI_INFO_BRIDGE __BIT(1) /* PCI bridge */ 101 102 /* 103 * An ACPI device node. 104 * 105 * Remarks: 106 * 107 * ad_device NULL if no device has attached to the node 108 * ad_root never NULL 109 * ad_parent only NULL if root of the tree ("\") 110 * ad_pciinfo NULL if not a PCI device 111 * ad_wakedev NULL if no wakeup capabilities 112 * ad_notify NULL if there is no notify handler 113 * ad_devinfo never NULL 114 * ad_handle never NULL 115 * 116 * Each ACPI device node is associated with its handle. The function 117 * acpi_match_node() can be used to get the node structure from a handle. 118 */ 119 struct acpi_devnode { 120 device_t ad_device; /* Device */ 121 device_t ad_root; /* Backpointer to acpi_softc */ 122 struct acpi_devnode *ad_parent; /* Backpointer to parent */ 123 struct acpi_pci_info *ad_pciinfo; /* PCI info */ 124 struct acpi_wakedev *ad_wakedev; /* Device wake */ 125 ACPI_NOTIFY_HANDLER ad_notify; /* Device notify */ 126 ACPI_DEVICE_INFO *ad_devinfo; /* Device info */ 127 ACPI_HANDLE ad_handle; /* Device handle */ 128 char ad_name[5]; /* Device name */ 129 uint32_t ad_flags; /* Device flags */ 130 uint32_t ad_type; /* Device type */ 131 int ad_state; /* Device power state */ 132 133 SIMPLEQ_ENTRY(acpi_devnode) ad_list; 134 SIMPLEQ_ENTRY(acpi_devnode) ad_child_list; 135 SIMPLEQ_HEAD(, acpi_devnode) ad_child_head; 136 }; 137 138 /* 139 * ACPI driver capabilities (ad_flags). 140 */ 141 #define ACPI_DEVICE_POWER __BIT(0) /* Support for D-states */ 142 #define ACPI_DEVICE_WAKEUP __BIT(1) /* Support for wake-up */ 143 #define ACPI_DEVICE_EJECT __BIT(2) /* Support for "ejection" */ 144 #define ACPI_DEVICE_DOCK __BIT(3) /* Support for docking */ 145 146 /* 147 * Software state of the ACPI subsystem. 148 */ 149 struct acpi_softc { 150 device_t sc_dev; /* base device info */ 151 device_t sc_apmbus; /* APM pseudo-bus */ 152 device_t sc_hpet; /* hpet(4) pseudo-bus */ 153 device_t sc_wdrt; /* acpiwdrt(4) pseudo-bus */ 154 155 struct acpi_devnode *sc_root; /* root of the device tree */ 156 157 bus_space_tag_t sc_iot; /* PCI I/O space tag */ 158 bus_space_tag_t sc_memt; /* PCI MEM space tag */ 159 pci_chipset_tag_t sc_pc; /* PCI chipset tag */ 160 int sc_pciflags; /* PCI bus flags */ 161 int sc_pci_bus; /* internal PCI fixup */ 162 isa_chipset_tag_t sc_ic; /* ISA chipset tag */ 163 164 void *sc_sdhook; /* shutdown hook */ 165 166 int sc_quirks; 167 int sc_sleepstate; 168 int sc_sleepstates; 169 170 struct sysmon_pswitch sc_smpsw_power; 171 struct sysmon_pswitch sc_smpsw_sleep; 172 173 SIMPLEQ_HEAD(, acpi_devnode) ad_head; 174 }; 175 176 /* 177 * acpi_attach_args: 178 * 179 * Used to attach a device instance to the acpi "bus". 180 */ 181 struct acpi_attach_args { 182 struct acpi_devnode *aa_node; /* ACPI device node */ 183 bus_space_tag_t aa_iot; /* PCI I/O space tag */ 184 bus_space_tag_t aa_memt; /* PCI MEM space tag */ 185 pci_chipset_tag_t aa_pc; /* PCI chipset tag */ 186 int aa_pciflags; /* PCI bus flags */ 187 isa_chipset_tag_t aa_ic; /* ISA chipset */ 188 }; 189 190 /* 191 * ACPI resources: 192 * 193 * acpi_io I/O ports 194 * acpi_iorange I/O port range 195 * acpi_mem memory region 196 * acpi_memrange memory range 197 * acpi_irq Interrupt Request 198 * acpi_drq DMA request 199 */ 200 struct acpi_io { 201 SIMPLEQ_ENTRY(acpi_io) ar_list; 202 int ar_index; 203 uint32_t ar_base; 204 uint32_t ar_length; 205 }; 206 207 struct acpi_iorange { 208 SIMPLEQ_ENTRY(acpi_iorange) ar_list; 209 int ar_index; 210 uint32_t ar_low; 211 uint32_t ar_high; 212 uint32_t ar_length; 213 uint32_t ar_align; 214 }; 215 216 struct acpi_mem { 217 SIMPLEQ_ENTRY(acpi_mem) ar_list; 218 int ar_index; 219 uint32_t ar_base; 220 uint32_t ar_length; 221 }; 222 223 struct acpi_memrange { 224 SIMPLEQ_ENTRY(acpi_memrange) ar_list; 225 int ar_index; 226 uint32_t ar_low; 227 uint32_t ar_high; 228 uint32_t ar_length; 229 uint32_t ar_align; 230 }; 231 232 struct acpi_irq { 233 SIMPLEQ_ENTRY(acpi_irq) ar_list; 234 int ar_index; 235 uint32_t ar_irq; 236 uint32_t ar_type; 237 }; 238 239 struct acpi_drq { 240 SIMPLEQ_ENTRY(acpi_drq) ar_list; 241 int ar_index; 242 uint32_t ar_drq; 243 }; 244 245 struct acpi_resources { 246 SIMPLEQ_HEAD(, acpi_io) ar_io; 247 int ar_nio; 248 249 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange; 250 int ar_niorange; 251 252 SIMPLEQ_HEAD(, acpi_mem) ar_mem; 253 int ar_nmem; 254 255 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange; 256 int ar_nmemrange; 257 258 SIMPLEQ_HEAD(, acpi_irq) ar_irq; 259 int ar_nirq; 260 261 SIMPLEQ_HEAD(, acpi_drq) ar_drq; 262 int ar_ndrq; 263 }; 264 265 /* 266 * acpi_resource_parse_ops: 267 * 268 * The client of ACPI resources specifies these operations 269 * when the resources are parsed. 270 */ 271 struct acpi_resource_parse_ops { 272 void (*init)(device_t, void *, void **); 273 void (*fini)(device_t, void *); 274 275 void (*ioport)(device_t, void *, uint32_t, uint32_t); 276 void (*iorange)(device_t, void *, uint32_t, uint32_t, 277 uint32_t, uint32_t); 278 279 void (*memory)(device_t, void *, uint32_t, uint32_t); 280 void (*memrange)(device_t, void *, uint32_t, uint32_t, 281 uint32_t, uint32_t); 282 283 void (*irq)(device_t, void *, uint32_t, uint32_t); 284 void (*drq)(device_t, void *, uint32_t); 285 286 void (*start_dep)(device_t, void *, int); 287 void (*end_dep)(device_t, void *); 288 }; 289 290 extern struct acpi_softc *acpi_softc; 291 extern int acpi_active; 292 293 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default; 294 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet; 295 296 int acpi_probe(void); 297 void acpi_disable(void); 298 int acpi_check(device_t, const char *); 299 300 int acpi_reset(void); 301 302 ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void); 303 304 bool acpi_register_notify(struct acpi_devnode *, 305 ACPI_NOTIFY_HANDLER); 306 void acpi_deregister_notify(struct acpi_devnode *); 307 308 ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *, 309 void *, const struct acpi_resource_parse_ops *); 310 void acpi_resource_print(device_t, struct acpi_resources *); 311 void acpi_resource_cleanup(struct acpi_resources *); 312 313 void * acpi_pci_link_devbyhandle(ACPI_HANDLE); 314 void acpi_pci_link_add_reference(void *, int, int, int, int); 315 int acpi_pci_link_route_interrupt(void *, int, int *, int *, int *); 316 char * acpi_pci_link_name(void *); 317 ACPI_HANDLE acpi_pci_link_handle(void *); 318 void acpi_pci_link_state(void); 319 void acpi_pci_link_resume(void); 320 321 struct acpi_io *acpi_res_io(struct acpi_resources *, int); 322 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int); 323 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int); 324 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int); 325 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int); 326 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int); 327 328 /* 329 * Sleep state transition. 330 */ 331 void acpi_enter_sleep_state(int); 332 333 /* 334 * MADT. 335 */ 336 #define ACPI_PLATFORM_INT_PMI 1 337 #define ACPI_PLATFORM_INT_INIT 2 338 #define ACPI_PLATFORM_INT_CERR 3 339 340 ACPI_STATUS acpi_madt_map(void); 341 void acpi_madt_unmap(void); 342 void acpi_madt_walk(ACPI_STATUS (*)(ACPI_SUBTABLE_HEADER *, 343 void *), void *); 344 345 /* 346 * Quirk handling. 347 */ 348 struct acpi_quirk { 349 const char *aq_tabletype; /* Type of table */ 350 const char *aq_oemid; /* "OemId" field */ 351 int aq_oemrev; /* "OemRev" field */ 352 int aq_cmpop; /* "OemRev" comparison */ 353 const char *aq_tabid; /* "TableId */ 354 int aq_quirks; /* The actual quirk */ 355 }; 356 357 #define ACPI_QUIRK_BROKEN 0x00000001 /* totally broken */ 358 #define ACPI_QUIRK_BADPCI 0x00000002 /* bad PCI hierarchy */ 359 #define ACPI_QUIRK_BADBBN 0x00000004 /* _BBN broken */ 360 #define ACPI_QUIRK_IRQ0 0x00000008 /* bad 0->2 irq override */ 361 #define ACPI_QUIRK_OLDBIOS 0x00000010 /* BIOS date blacklisted */ 362 363 int acpi_find_quirks(void); 364 int acpi_quirks_osi_add(const char *); 365 int acpi_quirks_osi_del(const char *); 366 367 #ifdef ACPI_DEBUG 368 void acpi_debug_init(void); 369 #endif 370 371 /* 372 * Misc routines with vectors updated by acpiverbose module. 373 */ 374 extern void (*acpi_print_verbose)(struct acpi_softc *); 375 extern void (*acpi_print_dev)(const char *); 376 377 void acpi_load_verbose(void); 378 extern int acpi_verbose_loaded; 379 380 #endif /* !_SYS_DEV_ACPI_ACPIVAR_H */ 381