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