Home | History | Annotate | Line # | Download | only in acpi
acpivar.h revision 1.32
      1 /*	$NetBSD: acpivar.h,v 1.32 2008/03/27 02:51:26 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 /*
     39  * This file defines the ACPI interface provided to the rest of the
     40  * kernel, as well as the autoconfiguration structures for ACPI
     41  * support.
     42  */
     43 
     44 #include <sys/bus.h>
     45 #include <dev/pci/pcivar.h>
     46 #include <dev/isa/isavar.h>
     47 
     48 #include <dev/acpi/acpica.h>
     49 
     50 #include <dev/sysmon/sysmonvar.h>
     51 
     52 /*
     53  * acpibus_attach_args:
     54  *
     55  *	This structure is used to attach the ACPI "bus".
     56  */
     57 struct acpibus_attach_args {
     58 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
     59 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
     60 	pci_chipset_tag_t aa_pc;	/* PCI chipset */
     61 	int aa_pciflags;		/* PCI bus flags */
     62 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
     63 };
     64 
     65 /*
     66  * Types of switches that ACPI understands.
     67  */
     68 #define	ACPI_SWITCH_POWERBUTTON		0
     69 #define	ACPI_SWITCH_SLEEPBUTTON		1
     70 #define	ACPI_SWITCH_LID			2
     71 #define	ACPI_NSWITCHES			3
     72 
     73 /*
     74  * acpi_devnode:
     75  *
     76  *	An ACPI device node.
     77  */
     78 struct acpi_devnode {
     79 	TAILQ_ENTRY(acpi_devnode) ad_list;
     80 	ACPI_HANDLE	ad_handle;	/* our ACPI handle */
     81 	u_int32_t	ad_level;	/* ACPI level */
     82 	u_int32_t	ad_type;	/* ACPI object type */
     83 	ACPI_DEVICE_INFO *ad_devinfo;	/* our ACPI device info */
     84 	struct acpi_scope *ad_scope;	/* backpointer to scope */
     85 	struct device	*ad_device;	/* pointer to configured device */
     86 	char		ad_name[5];	/* Human-readable device name */
     87 };
     88 
     89 /*
     90  * acpi_scope:
     91  *
     92  *	Description of an ACPI scope.
     93  */
     94 struct acpi_scope {
     95 	TAILQ_ENTRY(acpi_scope) as_list;
     96 	const char *as_name;		/* scope name */
     97 	/*
     98 	 * Device nodes we manage.
     99 	 */
    100 	TAILQ_HEAD(, acpi_devnode) as_devnodes;
    101 };
    102 
    103 /*
    104  * acpi_softc:
    105  *
    106  *	Software state of the ACPI subsystem.
    107  */
    108 struct acpi_softc {
    109 	device_t sc_dev;		/* base device info */
    110 	bus_space_tag_t sc_iot;		/* PCI I/O space tag */
    111 	bus_space_tag_t sc_memt;	/* PCI MEM space tag */
    112 	pci_chipset_tag_t sc_pc;	/* PCI chipset tag */
    113 	int sc_pciflags;		/* PCI bus flags */
    114 	int sc_pci_bus;			/* internal PCI fixup */
    115 	isa_chipset_tag_t sc_ic;	/* ISA chipset tag */
    116 
    117 	void *sc_sdhook;		/* shutdown hook */
    118 
    119 	/*
    120 	 * Power switch handlers for fixed-feature buttons.
    121 	 */
    122 	struct sysmon_pswitch sc_smpsw_power;
    123 	struct sysmon_pswitch sc_smpsw_sleep;
    124 
    125 	/*
    126 	 * Sleep state to transition to when a given
    127 	 * switch is activated.
    128 	 */
    129 	int sc_switch_sleep[ACPI_NSWITCHES];
    130 
    131 	int sc_sleepstate;		/* current sleep state */
    132 
    133 	int sc_quirks;
    134 
    135 	/*
    136 	 * Scopes we manage.
    137 	 */
    138 	TAILQ_HEAD(, acpi_scope) sc_scopes;
    139 };
    140 
    141 /*
    142  * acpi_attach_args:
    143  *
    144  *	Used to attach a device instance to the acpi "bus".
    145  */
    146 struct acpi_attach_args {
    147 	struct acpi_devnode *aa_node;	/* ACPI device node */
    148 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
    149 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
    150 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
    151 	int aa_pciflags;		/* PCI bus flags */
    152 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
    153 };
    154 
    155 /*
    156  * ACPI resources:
    157  *
    158  *	acpi_io		I/O ports
    159  *	acpi_iorange	I/O port range
    160  *	acpi_mem	memory region
    161  *	acpi_memrange	memory range
    162  *	acpi_irq	Interrupt Request
    163  *	acpi_drq	DMA request
    164  */
    165 
    166 struct acpi_io {
    167 	SIMPLEQ_ENTRY(acpi_io) ar_list;
    168 	int		ar_index;
    169 	uint32_t	ar_base;
    170 	uint32_t	ar_length;
    171 };
    172 
    173 struct acpi_iorange {
    174 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
    175 	int		ar_index;
    176 	uint32_t	ar_low;
    177 	uint32_t	ar_high;
    178 	uint32_t	ar_length;
    179 	uint32_t	ar_align;
    180 };
    181 
    182 struct acpi_mem {
    183 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
    184 	int		ar_index;
    185 	uint32_t	ar_base;
    186 	uint32_t	ar_length;
    187 };
    188 
    189 struct acpi_memrange {
    190 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
    191 	int		ar_index;
    192 	uint32_t	ar_low;
    193 	uint32_t	ar_high;
    194 	uint32_t	ar_length;
    195 	uint32_t	ar_align;
    196 };
    197 
    198 struct acpi_irq {
    199 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
    200 	int		ar_index;
    201 	uint32_t	ar_irq;
    202 	uint32_t	ar_type;
    203 };
    204 
    205 struct acpi_drq {
    206 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
    207 	int		ar_index;
    208 	uint32_t	ar_drq;
    209 };
    210 
    211 struct acpi_resources {
    212 	SIMPLEQ_HEAD(, acpi_io) ar_io;
    213 	int ar_nio;
    214 
    215 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
    216 	int ar_niorange;
    217 
    218 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
    219 	int ar_nmem;
    220 
    221 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
    222 	int ar_nmemrange;
    223 
    224 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
    225 	int ar_nirq;
    226 
    227 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
    228 	int ar_ndrq;
    229 };
    230 
    231 /*
    232  * acpi_resource_parse_ops:
    233  *
    234  *	The client of ACPI resources specifies these operations
    235  *	when the resources are parsed.
    236  */
    237 struct acpi_resource_parse_ops {
    238 	void	(*init)(struct device *, void *, void **);
    239 	void	(*fini)(struct device *, void *);
    240 
    241 	void	(*ioport)(struct device *, void *, uint32_t, uint32_t);
    242 	void	(*iorange)(struct device *, void *, uint32_t, uint32_t,
    243 		    uint32_t, uint32_t);
    244 
    245 	void	(*memory)(struct device *, void *, uint32_t, uint32_t);
    246 	void	(*memrange)(struct device *, void *, uint32_t, uint32_t,
    247 		    uint32_t, uint32_t);
    248 
    249 	void	(*irq)(struct device *, void *, uint32_t, uint32_t);
    250 	void	(*drq)(struct device *, void *, uint32_t);
    251 
    252 	void	(*start_dep)(struct device *, void *, int);
    253 	void	(*end_dep)(struct device *, void *);
    254 };
    255 
    256 extern struct acpi_softc *acpi_softc;
    257 extern int acpi_active;
    258 
    259 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
    260 
    261 int		acpi_check(device_t, const char *);
    262 int		acpi_probe(void);
    263 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);
    264 int		acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
    265 void		acpi_set_wake_gpe(ACPI_HANDLE);
    266 
    267 ACPI_STATUS	acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
    268 ACPI_STATUS	acpi_eval_string(ACPI_HANDLE, const char *, char **);
    269 ACPI_STATUS	acpi_eval_struct(ACPI_HANDLE, const char *, ACPI_BUFFER *);
    270 
    271 ACPI_STATUS	acpi_foreach_package_object(ACPI_OBJECT *,
    272 		    ACPI_STATUS (*)(ACPI_OBJECT *, void *), void *);
    273 ACPI_STATUS	acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
    274 		    ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
    275 const char*	acpi_name(ACPI_HANDLE);
    276 
    277 ACPI_STATUS	acpi_resource_parse(struct device *, ACPI_HANDLE, const char *,
    278 		    void *, const struct acpi_resource_parse_ops *);
    279 void		acpi_resource_print(struct device *, struct acpi_resources *);
    280 void		acpi_resource_cleanup(struct acpi_resources *);
    281 ACPI_STATUS	acpi_allocate_resources(ACPI_HANDLE);
    282 
    283 ACPI_STATUS	acpi_pwr_switch_consumer(ACPI_HANDLE, int);
    284 
    285 void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
    286 void		acpi_pci_link_add_reference(void *, int, int, int, int);
    287 int		acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
    288 char *		acpi_pci_link_name(void *);
    289 ACPI_HANDLE	acpi_pci_link_handle(void *);
    290 void		acpi_pci_link_state(void);
    291 
    292 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
    293 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
    294 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
    295 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
    296 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
    297 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
    298 
    299 /*
    300  * power state transition
    301  */
    302 ACPI_STATUS	acpi_enter_sleep_state(struct acpi_softc *, int);
    303 
    304 /*
    305  * quirk handling
    306  */
    307 struct acpi_quirk {
    308 	const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */
    309 	const char *aq_oemid;	/* compared against the table OemId */
    310 	int aq_oemrev;		/* compared against the table OemRev */
    311 	int aq_cmpop;		/* how to compare the oemrev number */
    312 	const char *aq_tabid;	/* compared against the table TableId */
    313 	int aq_quirks;		/* the actual quirks */
    314 };
    315 
    316 #define AQ_GT		0	/* > */
    317 #define AQ_LT		1	/* < */
    318 #define AQ_GTE		2	/* >= */
    319 #define AQ_LTE		3	/* <= */
    320 #define AQ_EQ		4	/* == */
    321 
    322 #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
    323 #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
    324 #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
    325 #define ACPI_QUIRK_IRQ0		0x00000008	/* bad 0->2 irq override */
    326 
    327 int acpi_find_quirks(void);
    328