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