Home | History | Annotate | Line # | Download | only in acpi
acpivar.h revision 1.27
      1 /*	$NetBSD: acpivar.h,v 1.27 2006/09/23 17:04:26 fvdl 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 <machine/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 };
     87 
     88 /*
     89  * acpi_scope:
     90  *
     91  *	Description of an ACPI scope.
     92  */
     93 struct acpi_scope {
     94 	TAILQ_ENTRY(acpi_scope) as_list;
     95 	const char *as_name;		/* scope name */
     96 	/*
     97 	 * Device nodes we manage.
     98 	 */
     99 	TAILQ_HEAD(, acpi_devnode) as_devnodes;
    100 };
    101 
    102 /*
    103  * acpi_softc:
    104  *
    105  *	Software state of the ACPI subsystem.
    106  */
    107 struct acpi_softc {
    108 	struct device sc_dev;		/* base device info */
    109 	bus_space_tag_t sc_iot;		/* PCI I/O space tag */
    110 	bus_space_tag_t sc_memt;	/* PCI MEM space tag */
    111 	pci_chipset_tag_t sc_pc;	/* PCI chipset tag */
    112 	int sc_pciflags;		/* PCI bus flags */
    113 	int sc_pci_bus;			/* internal PCI fixup */
    114 	isa_chipset_tag_t sc_ic;	/* ISA chipset tag */
    115 
    116 	void *sc_sdhook;		/* shutdown hook */
    117 
    118 	/*
    119 	 * Power switch handlers for fixed-feature buttons.
    120 	 */
    121 	struct sysmon_pswitch sc_smpsw_power;
    122 	struct sysmon_pswitch sc_smpsw_sleep;
    123 
    124 	/*
    125 	 * Sleep state to transition to when a given
    126 	 * switch is activated.
    127 	 */
    128 	int sc_switch_sleep[ACPI_NSWITCHES];
    129 
    130 	int sc_sleepstate;		/* current sleep state */
    131 
    132 	int sc_quirks;
    133 
    134 	/*
    135 	 * Scopes we manage.
    136 	 */
    137 	TAILQ_HEAD(, acpi_scope) sc_scopes;
    138 };
    139 
    140 /*
    141  * acpi_attach_args:
    142  *
    143  *	Used to attach a device instance to the acpi "bus".
    144  */
    145 struct acpi_attach_args {
    146 	struct acpi_devnode *aa_node;	/* ACPI device node */
    147 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
    148 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
    149 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
    150 	int aa_pciflags;		/* PCI bus flags */
    151 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
    152 };
    153 
    154 /*
    155  * ACPI resources:
    156  *
    157  *	acpi_io		I/O ports
    158  *	acpi_iorange	I/O port range
    159  *	acpi_mem	memory region
    160  *	acpi_memrange	memory range
    161  *	acpi_irq	Interrupt Request
    162  *	acpi_drq	DMA request
    163  */
    164 
    165 struct acpi_io {
    166 	SIMPLEQ_ENTRY(acpi_io) ar_list;
    167 	int		ar_index;
    168 	uint32_t	ar_base;
    169 	uint32_t	ar_length;
    170 };
    171 
    172 struct acpi_iorange {
    173 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
    174 	int		ar_index;
    175 	uint32_t	ar_low;
    176 	uint32_t	ar_high;
    177 	uint32_t	ar_length;
    178 	uint32_t	ar_align;
    179 };
    180 
    181 struct acpi_mem {
    182 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
    183 	int		ar_index;
    184 	uint32_t	ar_base;
    185 	uint32_t	ar_length;
    186 };
    187 
    188 struct acpi_memrange {
    189 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
    190 	int		ar_index;
    191 	uint32_t	ar_low;
    192 	uint32_t	ar_high;
    193 	uint32_t	ar_length;
    194 	uint32_t	ar_align;
    195 };
    196 
    197 struct acpi_irq {
    198 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
    199 	int		ar_index;
    200 	uint32_t	ar_irq;
    201 	uint32_t	ar_type;
    202 };
    203 
    204 struct acpi_drq {
    205 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
    206 	int		ar_index;
    207 	uint32_t	ar_drq;
    208 };
    209 
    210 struct acpi_resources {
    211 	SIMPLEQ_HEAD(, acpi_io) ar_io;
    212 	int ar_nio;
    213 
    214 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
    215 	int ar_niorange;
    216 
    217 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
    218 	int ar_nmem;
    219 
    220 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
    221 	int ar_nmemrange;
    222 
    223 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
    224 	int ar_nirq;
    225 
    226 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
    227 	int ar_ndrq;
    228 };
    229 
    230 /*
    231  * acpi_resource_parse_ops:
    232  *
    233  *	The client of ACPI resources specifies these operations
    234  *	when the resources are parsed.
    235  */
    236 struct acpi_resource_parse_ops {
    237 	void	(*init)(struct device *, void *, void **);
    238 	void	(*fini)(struct device *, void *);
    239 
    240 	void	(*ioport)(struct device *, void *, uint32_t, uint32_t);
    241 	void	(*iorange)(struct device *, void *, uint32_t, uint32_t,
    242 		    uint32_t, uint32_t);
    243 
    244 	void	(*memory)(struct device *, void *, uint32_t, uint32_t);
    245 	void	(*memrange)(struct device *, void *, uint32_t, uint32_t,
    246 		    uint32_t, uint32_t);
    247 
    248 	void	(*irq)(struct device *, void *, uint32_t, uint32_t);
    249 	void	(*drq)(struct device *, void *, uint32_t);
    250 
    251 	void	(*start_dep)(struct device *, void *, int);
    252 	void	(*end_dep)(struct device *, void *);
    253 };
    254 
    255 extern struct acpi_softc *acpi_softc;
    256 extern int acpi_active;
    257 
    258 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
    259 
    260 int		acpi_probe(void);
    261 ACPI_STATUS	acpi_OsGetRootPointer(UINT32, ACPI_POINTER *);
    262 int		acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
    263 void		acpi_set_wake_gpe(ACPI_HANDLE);
    264 
    265 ACPI_STATUS	acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
    266 ACPI_STATUS	acpi_eval_string(ACPI_HANDLE, const char *, char **);
    267 ACPI_STATUS	acpi_eval_struct(ACPI_HANDLE, const char *, ACPI_BUFFER *);
    268 
    269 ACPI_STATUS	acpi_foreach_package_object(ACPI_OBJECT *,
    270 		    ACPI_STATUS (*)(ACPI_OBJECT *, void *), void *);
    271 ACPI_STATUS	acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
    272 		    ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
    273 const char*	acpi_name(ACPI_HANDLE);
    274 
    275 ACPI_STATUS	acpi_resource_parse(struct device *, ACPI_HANDLE, const char *,
    276 		    void *, const struct acpi_resource_parse_ops *);
    277 void		acpi_resource_print(struct device *, struct acpi_resources *);
    278 void		acpi_resource_cleanup(struct acpi_resources *);
    279 ACPI_STATUS	acpi_allocate_resources(ACPI_HANDLE);
    280 
    281 ACPI_STATUS	acpi_pwr_switch_consumer(ACPI_HANDLE, int);
    282 
    283 void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
    284 void		acpi_pci_link_add_reference(void *, int, int, int, int);
    285 int		acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
    286 char *		acpi_pci_link_name(void *);
    287 ACPI_HANDLE	acpi_pci_link_handle(void *);
    288 void		acpi_pci_link_state(void);
    289 
    290 
    291 
    292 
    293 #if defined(_KERNEL_OPT)
    294 #include "acpiec.h"
    295 
    296 #if NACPIEC > 0
    297 void		acpiec_early_attach(struct device *);
    298 #endif
    299 #else
    300 #define	NACPIEC	0
    301 #endif
    302 
    303 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
    304 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
    305 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
    306 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
    307 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
    308 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
    309 
    310 /*
    311  * power state transition
    312  */
    313 ACPI_STATUS	acpi_enter_sleep_state(struct acpi_softc *, int);
    314 
    315 /*
    316  * quirk handling
    317  */
    318 struct acpi_quirk {
    319 	uint32_t aq_tabletype;	/* what type of table (FADT, DSDT, etc) */
    320 	const char *aq_oemid;	/* compared against the table OemId */
    321 	int aq_oemrev;		/* compared against the table OemRev */
    322 	int aq_cmpop;		/* how to compare the oemrev number */
    323 	const char *aq_tabid;	/* compared against the table TableId */
    324 	int aq_quirks;		/* the actual quirks */
    325 };
    326 
    327 #define AQ_GT		0	/* > */
    328 #define AQ_LT		1	/* < */
    329 #define AQ_GTE		2	/* >= */
    330 #define AQ_LTE		3	/* <= */
    331 #define AQ_EQ		4	/* == */
    332 
    333 #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
    334 #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
    335 #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
    336 #define ACPI_QUIRK_IRQ0		0x00000008	/* bad 0->2 irq override */
    337 
    338 int acpi_find_quirks(void);
    339