1 /* $NetBSD: acpivar.h,v 1.53 2010/04/27 08:37:07 jruoho 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 * ACPI driver capabilities. 69 */ 70 #define ACPI_DEVICE_POWER __BIT(0) 71 #define ACPI_DEVICE_WAKEUP __BIT(1) 72 73 /* 74 * PCI information for ACPI device nodes that correspond to PCI devices. 75 */ 76 struct acpi_pci_info { 77 uint16_t ap_segment; /* PCI segment group */ 78 uint16_t ap_bus; /* PCI bus */ 79 uint16_t ap_device; /* PCI device */ 80 uint16_t ap_function; /* PCI function */ 81 bool ap_bridge; /* PCI bridge (PHB or PPB) */ 82 uint16_t ap_downbus; /* PCI bridge downstream bus */ 83 }; 84 85 /* 86 * An ACPI device node. 87 * 88 * Remarks: 89 * 90 * ad_device NULL if no device has attached to the node 91 * ad_root never NULL 92 * ad_parent only NULL if root of the tree ("\") 93 * ad_pciinfo NULL if not a PCI device 94 * ad_notify NULL if there is no notify handler 95 * ad_devinfo never NULL 96 * ad_handle never NULL 97 */ 98 struct acpi_devnode { 99 device_t ad_device; /* Device */ 100 device_t ad_root; /* Backpointer to acpi_softc */ 101 struct acpi_devnode *ad_parent; /* Backpointer to parent */ 102 struct acpi_pci_info *ad_pciinfo; /* PCI info */ 103 ACPI_NOTIFY_HANDLER ad_notify; /* Device notify */ 104 ACPI_DEVICE_INFO *ad_devinfo; /* Device info */ 105 ACPI_HANDLE ad_handle; /* Device handle */ 106 char ad_name[5]; /* Device name */ 107 uint32_t ad_flags; /* Device flags */ 108 uint32_t ad_type; /* Device type */ 109 int ad_state; /* Device power state */ 110 int ad_wake; /* Device wakeup */ 111 112 SIMPLEQ_ENTRY(acpi_devnode) ad_list; 113 SIMPLEQ_ENTRY(acpi_devnode) ad_child_list; 114 SIMPLEQ_HEAD(, acpi_devnode) ad_child_head; 115 }; 116 117 /* 118 * Software state of the ACPI subsystem. 119 */ 120 struct acpi_softc { 121 device_t sc_dev; /* base device info */ 122 device_t sc_apmbus; /* APM pseudo-bus */ 123 124 struct acpi_devnode *sc_root; /* root of the device tree */ 125 126 bus_space_tag_t sc_iot; /* PCI I/O space tag */ 127 bus_space_tag_t sc_memt; /* PCI MEM space tag */ 128 pci_chipset_tag_t sc_pc; /* PCI chipset tag */ 129 int sc_pciflags; /* PCI bus flags */ 130 int sc_pci_bus; /* internal PCI fixup */ 131 isa_chipset_tag_t sc_ic; /* ISA chipset tag */ 132 133 void *sc_sdhook; /* shutdown hook */ 134 135 int sc_quirks; 136 int sc_sleepstate; 137 int sc_sleepstates; 138 139 struct sysmon_pswitch sc_smpsw_power; 140 struct sysmon_pswitch sc_smpsw_sleep; 141 142 SIMPLEQ_HEAD(, acpi_devnode) ad_head; 143 }; 144 145 /* 146 * acpi_attach_args: 147 * 148 * Used to attach a device instance to the acpi "bus". 149 */ 150 struct acpi_attach_args { 151 struct acpi_devnode *aa_node; /* ACPI device node */ 152 bus_space_tag_t aa_iot; /* PCI I/O space tag */ 153 bus_space_tag_t aa_memt; /* PCI MEM space tag */ 154 pci_chipset_tag_t aa_pc; /* PCI chipset tag */ 155 int aa_pciflags; /* PCI bus flags */ 156 isa_chipset_tag_t aa_ic; /* ISA chipset */ 157 }; 158 159 /* 160 * ACPI resources: 161 * 162 * acpi_io I/O ports 163 * acpi_iorange I/O port range 164 * acpi_mem memory region 165 * acpi_memrange memory range 166 * acpi_irq Interrupt Request 167 * acpi_drq DMA request 168 */ 169 170 struct acpi_io { 171 SIMPLEQ_ENTRY(acpi_io) ar_list; 172 int ar_index; 173 uint32_t ar_base; 174 uint32_t ar_length; 175 }; 176 177 struct acpi_iorange { 178 SIMPLEQ_ENTRY(acpi_iorange) ar_list; 179 int ar_index; 180 uint32_t ar_low; 181 uint32_t ar_high; 182 uint32_t ar_length; 183 uint32_t ar_align; 184 }; 185 186 struct acpi_mem { 187 SIMPLEQ_ENTRY(acpi_mem) ar_list; 188 int ar_index; 189 uint32_t ar_base; 190 uint32_t ar_length; 191 }; 192 193 struct acpi_memrange { 194 SIMPLEQ_ENTRY(acpi_memrange) ar_list; 195 int ar_index; 196 uint32_t ar_low; 197 uint32_t ar_high; 198 uint32_t ar_length; 199 uint32_t ar_align; 200 }; 201 202 struct acpi_irq { 203 SIMPLEQ_ENTRY(acpi_irq) ar_list; 204 int ar_index; 205 uint32_t ar_irq; 206 uint32_t ar_type; 207 }; 208 209 struct acpi_drq { 210 SIMPLEQ_ENTRY(acpi_drq) ar_list; 211 int ar_index; 212 uint32_t ar_drq; 213 }; 214 215 struct acpi_resources { 216 SIMPLEQ_HEAD(, acpi_io) ar_io; 217 int ar_nio; 218 219 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange; 220 int ar_niorange; 221 222 SIMPLEQ_HEAD(, acpi_mem) ar_mem; 223 int ar_nmem; 224 225 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange; 226 int ar_nmemrange; 227 228 SIMPLEQ_HEAD(, acpi_irq) ar_irq; 229 int ar_nirq; 230 231 SIMPLEQ_HEAD(, acpi_drq) ar_drq; 232 int ar_ndrq; 233 }; 234 235 /* 236 * acpi_resource_parse_ops: 237 * 238 * The client of ACPI resources specifies these operations 239 * when the resources are parsed. 240 */ 241 struct acpi_resource_parse_ops { 242 void (*init)(device_t, void *, void **); 243 void (*fini)(device_t, void *); 244 245 void (*ioport)(device_t, void *, uint32_t, uint32_t); 246 void (*iorange)(device_t, void *, uint32_t, uint32_t, 247 uint32_t, uint32_t); 248 249 void (*memory)(device_t, void *, uint32_t, uint32_t); 250 void (*memrange)(device_t, void *, uint32_t, uint32_t, 251 uint32_t, uint32_t); 252 253 void (*irq)(device_t, void *, uint32_t, uint32_t); 254 void (*drq)(device_t, void *, uint32_t); 255 256 void (*start_dep)(device_t, void *, int); 257 void (*end_dep)(device_t, void *); 258 }; 259 260 extern struct acpi_softc *acpi_softc; 261 extern int acpi_active; 262 263 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default; 264 265 int acpi_probe(void); 266 int acpi_check(device_t, const char *); 267 268 ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void); 269 270 bool acpi_register_notify(struct acpi_devnode *, 271 ACPI_NOTIFY_HANDLER); 272 void acpi_deregister_notify(struct acpi_devnode *); 273 274 ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *, 275 void *, const struct acpi_resource_parse_ops *); 276 void acpi_resource_print(device_t, struct acpi_resources *); 277 void acpi_resource_cleanup(struct acpi_resources *); 278 279 void * acpi_pci_link_devbyhandle(ACPI_HANDLE); 280 void acpi_pci_link_add_reference(void *, int, int, int, int); 281 int acpi_pci_link_route_interrupt(void *, int, int *, int *, int *); 282 char * acpi_pci_link_name(void *); 283 ACPI_HANDLE acpi_pci_link_handle(void *); 284 void acpi_pci_link_state(void); 285 void acpi_pci_link_resume(void); 286 287 struct acpi_io *acpi_res_io(struct acpi_resources *, int); 288 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int); 289 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int); 290 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int); 291 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int); 292 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int); 293 294 /* 295 * Sleep state transition. 296 */ 297 void acpi_enter_sleep_state(struct acpi_softc *, int); 298 299 /* 300 * Quirk handling. 301 */ 302 struct acpi_quirk { 303 const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */ 304 const char *aq_oemid; /* compared against the table OemId */ 305 int aq_oemrev; /* compared against the table OemRev */ 306 int aq_cmpop; /* how to compare the oemrev number */ 307 const char *aq_tabid; /* compared against the table TableId */ 308 int aq_quirks; /* the actual quirks */ 309 }; 310 311 #define ACPI_QUIRK_BROKEN 0x00000001 /* totally broken */ 312 #define ACPI_QUIRK_BADPCI 0x00000002 /* bad PCI hierarchy */ 313 #define ACPI_QUIRK_BADBBN 0x00000004 /* _BBN broken */ 314 #define ACPI_QUIRK_IRQ0 0x00000008 /* bad 0->2 irq override */ 315 316 int acpi_find_quirks(void); 317 318 #ifdef ACPI_DEBUG 319 void acpi_debug_init(void); 320 #endif 321 322 #endif /* !_SYS_DEV_ACPI_ACPIVAR_H */ 323