Home | History | Annotate | Line # | Download | only in acpi
      1 /*	$NetBSD: acpivar.h,v 1.93 2024/12/18 21:19:52 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 	bus_dma_tag_t		 aa_dmat;	/* PCI DMA tag */
     66 	bus_dma_tag_t		 aa_dmat64;	/* PCI 64bit DMA tag */
     67 };
     68 
     69 /*
     70  * PCI information for ACPI device nodes that correspond to PCI devices.
     71  *
     72  * Remarks:
     73  *
     74  *	ap_bus		<= 255
     75  *	ap_device	<= 31
     76  *	ap_function	<= 7		or	ap_function == 0xFFFF
     77  *	ap_downbus	<= 255
     78  *
     79  * Validity of some fields depends on the value of ap_flags:
     80  *
     81  *	ap_segment				always valid
     82  *	ap_bus, ap_device, ap_function		valid for PCI devices
     83  *	ap_downbus				valid for PCI bridges
     84  *
     85  * The device and function numbers are encoded in the value returned by
     86  * _ADR.  A function number of 0xFFFF is used to refer to all the
     87  * functions on a PCI device (ACPI 4.0a, p. 200).
     88  */
     89 struct acpi_pci_info {
     90 	pci_chipset_tag_t	 ap_pc;		/* PCI chipset tag */
     91 	uint16_t		 ap_flags;	/* Flags (cf. below) */
     92 	uint16_t		 ap_segment;	/* PCI segment group */
     93 	uint16_t		 ap_bus;	/* PCI bus */
     94 	uint16_t		 ap_device;	/* PCI device */
     95 	uint16_t		 ap_function;	/* PCI function */
     96 	uint16_t		 ap_downbus;	/* PCI bridge downstream bus */
     97 };
     98 
     99 /*
    100  * Flags for PCI information.
    101  */
    102 #define ACPI_PCI_INFO_DEVICE	__BIT(0)	/* PCI device */
    103 #define ACPI_PCI_INFO_BRIDGE	__BIT(1)	/* PCI bridge */
    104 
    105 /* Represents a device node dependency. */
    106 struct acpi_devnodedep {
    107 	SIMPLEQ_ENTRY(acpi_devnodedep)	 dd_list;
    108 	struct acpi_devnode		*dd_node;
    109 };
    110 
    111 /*
    112  * An ACPI device node.
    113  *
    114  * Remarks:
    115  *
    116  *	ad_device	NULL if no device has attached to the node
    117  *	ad_root		never NULL
    118  *	ad_parent	only NULL if root of the tree ("\")
    119  *	ad_pciinfo	NULL if not a PCI device
    120  *	ad_wakedev	NULL if no wakeup capabilities
    121  *	ad_notify	NULL if there is no notify handler
    122  *	ad_devinfo	never NULL
    123  *	ad_handle	never NULL
    124  *
    125  * Each ACPI device node is associated with its handle. The function
    126  * acpi_match_node() can be used to get the node structure from a handle.
    127  */
    128 struct acpi_devnode {
    129 	device_t		 ad_device;	/* Device */
    130 	device_t		 ad_root;	/* Backpointer to acpi_softc */
    131 	struct acpi_devnode	*ad_parent;	/* Backpointer to parent */
    132 	struct acpi_pci_info	*ad_pciinfo;	/* PCI info */
    133 	struct acpi_wakedev	*ad_wakedev;	/* Device wake */
    134 	ACPI_NOTIFY_HANDLER	 ad_notify;	/* Device notify */
    135 	ACPI_DEVICE_INFO	*ad_devinfo;	/* Device info */
    136 	ACPI_HANDLE		 ad_handle;	/* Device handle */
    137 	char			 ad_name[5];	/* Device name */
    138 	uint32_t		 ad_flags;	/* Device flags */
    139 	uint32_t		 ad_type;	/* Device type */
    140 	int			 ad_state;	/* Device power state */
    141 	bus_dma_tag_t		 ad_dmat;	/* Bus DMA tag for device */
    142 	bus_dma_tag_t		 ad_dmat64;	/* Bus DMA tag for device (64-bit) */
    143 
    144 	device_t		ad_gpiodev;	/* GPIO controller device */
    145 	int			(*ad_gpio_translate)(void *, ACPI_RESOURCE_GPIO *, void **);
    146 	void			*ad_gpio_priv;	/* private data for translate */
    147 
    148 	SIMPLEQ_ENTRY(acpi_devnode)	ad_list;
    149 	SIMPLEQ_ENTRY(acpi_devnode)	ad_child_list;
    150 	SIMPLEQ_HEAD(, acpi_devnode)	ad_child_head;
    151 	SIMPLEQ_HEAD(, acpi_devnodedep)	ad_deps;
    152 
    153 	bool			ad_scanned;	/* private: acpi_rescan state */
    154 };
    155 
    156 /*
    157  * ACPI driver capabilities (ad_flags).
    158  */
    159 #define ACPI_DEVICE_POWER	__BIT(0)	/* Support for D-states  */
    160 #define ACPI_DEVICE_WAKEUP	__BIT(1)	/* Support for wake-up */
    161 #define ACPI_DEVICE_EJECT	__BIT(2)	/* Support for "ejection" */
    162 #define ACPI_DEVICE_DOCK	__BIT(3)	/* Support for docking */
    163 
    164 /*
    165  * Software state of the ACPI subsystem.
    166  */
    167 struct acpi_softc {
    168 	device_t		 sc_dev;	/* base device info */
    169 	device_t		 sc_apmbus;	/* APM pseudo-bus */
    170 	device_t		 sc_hpet;	/* hpet(4) pseudo-bus */
    171 	device_t		 sc_wdrt;	/* acpiwdrt(4) pseudo-bus */
    172 
    173 	struct acpi_devnode	*sc_root;	/* root of the device tree */
    174 
    175 	bus_space_tag_t		 sc_iot;	/* PCI I/O space tag */
    176 	bus_space_tag_t		 sc_memt;	/* PCI MEM space tag */
    177 	int			 sc_pciflags;	/* PCI bus flags */
    178 	int			 sc_pci_bus;	/* internal PCI fixup */
    179 	isa_chipset_tag_t	 sc_ic;		/* ISA chipset tag */
    180 	bus_dma_tag_t		 sc_dmat;	/* PCI DMA tag */
    181 	bus_dma_tag_t		 sc_dmat64;	/* PCI 64bit DMA tag */
    182 
    183 	void			*sc_sdhook;	/* shutdown hook */
    184 
    185 	int			 sc_quirks;
    186 	int			 sc_sleepstate;
    187 	int			 sc_sleepstates;
    188 
    189 	struct sysmon_pswitch	 sc_smpsw_power;
    190 	struct sysmon_pswitch	 sc_smpsw_sleep;
    191 
    192 	SIMPLEQ_HEAD(, acpi_devnode)	sc_head;
    193 
    194 	/*
    195 	 * Move this section to the other pseudo-bus child pointers
    196 	 * after pullup -- putting it here avoids potential ABI
    197 	 * compatibility issues with kernel modules.
    198 	 */
    199 	device_t		 sc_apei;	/* apei(4) pseudo-bus */
    200 };
    201 
    202 /*
    203  * acpi_attach_args:
    204  *
    205  *	Used to attach a device instance to the acpi "bus".
    206  */
    207 struct acpi_attach_args {
    208 	struct acpi_devnode *aa_node;	/* ACPI device node */
    209 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
    210 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
    211 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
    212 	int aa_pciflags;		/* PCI bus flags */
    213 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
    214 	bus_dma_tag_t aa_dmat;		/* PCI DMA tag */
    215 	bus_dma_tag_t aa_dmat64;	/* PCI 64bit DMA tag */
    216 };
    217 
    218 /* ACPI driver matching scores. */
    219 #define	ACPI_MATCHSCORE_HID		100	/* matched _HID */
    220 #define	ACPI_MATCHSCORE_CID_MAX		49
    221 #define	ACPI_MATCHSCORE_CID		10	/* matched _CID or _DSD
    222 						 * "compatible"
    223 						 */
    224 #define	ACPI_MATCHSCORE_CLS		1	/* matched _CLS */
    225 
    226 /*
    227  * ACPI resources:
    228  *
    229  *	acpi_io		I/O ports
    230  *	acpi_iorange	I/O port range
    231  *	acpi_mem	memory region
    232  *	acpi_memrange	memory range
    233  *	acpi_irq	Interrupt Request
    234  *	acpi_drq	DMA request
    235  */
    236 struct acpi_io {
    237 	SIMPLEQ_ENTRY(acpi_io) ar_list;
    238 	int		ar_index;
    239 	uint32_t	ar_base;
    240 	uint32_t	ar_length;
    241 };
    242 
    243 struct acpi_iorange {
    244 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
    245 	int		ar_index;
    246 	uint32_t	ar_low;
    247 	uint32_t	ar_high;
    248 	uint32_t	ar_length;
    249 	uint32_t	ar_align;
    250 };
    251 
    252 struct acpi_mem {
    253 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
    254 	int		ar_index;
    255 	bus_addr_t	ar_base;
    256 	bus_size_t	ar_length;
    257 	bus_addr_t	ar_xbase;	/* translated base address */
    258 };
    259 
    260 struct acpi_memrange {
    261 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
    262 	int		ar_index;
    263 	bus_addr_t	ar_low;
    264 	bus_addr_t	ar_high;
    265 	bus_size_t	ar_length;
    266 	bus_size_t	ar_align;
    267 };
    268 
    269 struct acpi_irq {
    270 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
    271 	int		ar_index;
    272 	uint32_t	ar_irq;
    273 	uint32_t	ar_type;
    274 };
    275 
    276 struct acpi_drq {
    277 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
    278 	int		ar_index;
    279 	uint32_t	ar_drq;
    280 };
    281 
    282 struct acpi_resources {
    283 	SIMPLEQ_HEAD(, acpi_io) ar_io;
    284 	int ar_nio;
    285 
    286 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
    287 	int ar_niorange;
    288 
    289 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
    290 	int ar_nmem;
    291 
    292 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
    293 	int ar_nmemrange;
    294 
    295 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
    296 	int ar_nirq;
    297 
    298 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
    299 	int ar_ndrq;
    300 };
    301 
    302 /*
    303  * acpi_resource_parse_ops:
    304  *
    305  *	The client of ACPI resources specifies these operations
    306  *	when the resources are parsed.
    307  */
    308 struct acpi_resource_parse_ops {
    309 	void	(*init)(device_t, void *, void **);
    310 	void	(*fini)(device_t, void *);
    311 
    312 	void	(*ioport)(device_t, void *, uint32_t, uint32_t);
    313 	void	(*iorange)(device_t, void *, uint32_t, uint32_t,
    314 		    uint32_t, uint32_t);
    315 
    316 	void	(*memory)(device_t, void *, uint64_t, uint64_t, uint64_t);
    317 	void	(*memrange)(device_t, void *, uint64_t, uint64_t,
    318 		    uint64_t, uint64_t);
    319 
    320 	void	(*irq)(device_t, void *, uint32_t, uint32_t);
    321 	void	(*drq)(device_t, void *, uint32_t);
    322 
    323 	void	(*start_dep)(device_t, void *, int);
    324 	void	(*end_dep)(device_t, void *);
    325 };
    326 
    327 extern struct acpi_softc *acpi_softc;
    328 extern int acpi_active;
    329 
    330 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
    331 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet;
    332 
    333 int		acpi_probe(void);
    334 void		acpi_disable(void);
    335 int		acpi_check(device_t, const char *);
    336 
    337 int		acpi_compatible_match(const struct acpi_attach_args *,
    338 		    const struct device_compatible_entry *);
    339 const struct device_compatible_entry *
    340 		acpi_compatible_lookup(const struct acpi_attach_args *,
    341 		    const struct device_compatible_entry *);
    342 
    343 bool    	acpi_device_present(ACPI_HANDLE);
    344 
    345 int		acpi_reset(void);
    346 
    347 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);
    348 
    349 bool		acpi_register_notify(struct acpi_devnode *,
    350 				     ACPI_NOTIFY_HANDLER);
    351 void		acpi_deregister_notify(struct acpi_devnode *);
    352 
    353 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
    354 		    void *, const struct acpi_resource_parse_ops *);
    355 ACPI_STATUS	acpi_resource_parse_any(device_t, ACPI_HANDLE, const char *,
    356 		    void *, const struct acpi_resource_parse_ops *);
    357 void		acpi_resource_print(device_t, struct acpi_resources *);
    358 void		acpi_resource_cleanup(struct acpi_resources *);
    359 
    360 void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
    361 void		acpi_pci_link_add_reference(void *, pci_chipset_tag_t, int,
    362 		    int, int, int);
    363 int		acpi_pci_link_route_interrupt(void *, pci_chipset_tag_t, int,
    364 		    int *, int *, int *);
    365 char *		acpi_pci_link_name(void *);
    366 ACPI_HANDLE	acpi_pci_link_handle(void *);
    367 void		acpi_pci_link_state(void);
    368 void		acpi_pci_link_resume(void);
    369 
    370 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
    371 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
    372 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
    373 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
    374 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
    375 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
    376 
    377 /*
    378  * Sleep state transition.
    379  */
    380 void			acpi_enter_sleep_state(int);
    381 
    382 /*
    383  * MADT.
    384  */
    385 #define ACPI_PLATFORM_INT_PMI	1
    386 #define ACPI_PLATFORM_INT_INIT	2
    387 #define ACPI_PLATFORM_INT_CERR	3
    388 
    389 ACPI_STATUS		acpi_madt_map(void);
    390 void			acpi_madt_unmap(void);
    391 void			acpi_madt_walk(ACPI_STATUS (*)(ACPI_SUBTABLE_HEADER *,
    392 				       void *), void *);
    393 
    394 /*
    395  * GTDT.
    396  */
    397 ACPI_STATUS		acpi_gtdt_map(void);
    398 void			acpi_gtdt_unmap(void);
    399 void			acpi_gtdt_walk(ACPI_STATUS (*)(ACPI_GTDT_HEADER *,
    400 				       void *), void *);
    401 
    402 /*
    403  * Quirk handling.
    404  */
    405 struct acpi_quirk {
    406 	const char	*aq_tabletype;		/* Type of table */
    407 	const char	*aq_oemid;		/* "OemId" field */
    408 	int		 aq_oemrev;		/* "OemRev" field */
    409 	int		 aq_cmpop;		/* "OemRev" comparison */
    410 	const char	*aq_tabid;		/* "TableId */
    411 	int		 aq_quirks;		/* The actual quirk */
    412 };
    413 
    414 #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
    415 #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
    416 #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
    417 #define ACPI_QUIRK_IRQ0		0x00000008	/* bad 0->2 irq override */
    418 #define ACPI_QUIRK_OLDBIOS	0x00000010	/* BIOS date blacklisted */
    419 
    420 int	acpi_find_quirks(void);
    421 
    422 #ifdef ACPI_DEBUG
    423 void	acpi_debug_init(void);
    424 #endif
    425 
    426 bus_dma_tag_t	acpi_get_dma_tag(struct acpi_softc *, struct acpi_devnode *);
    427 bus_dma_tag_t	acpi_get_dma64_tag(struct acpi_softc *, struct acpi_devnode *);
    428 pci_chipset_tag_t acpi_get_pci_chipset_tag(struct acpi_softc *, int, int);
    429 
    430 /*
    431  * Misc routines with vectors updated by acpiverbose module.
    432  */
    433 extern void	(*acpi_print_verbose)(struct acpi_softc *);
    434 extern void	(*acpi_print_dev)(const char *);
    435 
    436 void		acpi_load_verbose(void);
    437 extern int	acpi_verbose_loaded;
    438 
    439 #endif	/* !_SYS_DEV_ACPI_ACPIVAR_H */
    440