xref: /freebsd/usr.sbin/acpi/acpidump/acpidump.h (revision 2357939bc239bd5334a169b62313806178dd8f30)
1 /*-
2  * Copyright (c) 1999 Doug Rabson
3  * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *	$FreeBSD$
28  */
29 
30 #ifndef _ACPIDUMP_H_
31 #define _ACPIDUMP_H_
32 
33 /* Generic Address structure */
34 struct ACPIgas {
35 	u_int8_t	address_space_id;
36 #define ACPI_GAS_MEMORY		0
37 #define ACPI_GAS_IO		1
38 #define ACPI_GAS_PCI		2
39 #define ACPI_GAS_EMBEDDED	3
40 #define ACPI_GAS_SMBUS		4
41 #define ACPI_GAS_FIXED		0x7f
42 	u_int8_t	bit_width;
43 	u_int8_t	bit_offset;
44 	u_int8_t	_reserved;
45 	u_int64_t	address;
46 } __packed;
47 
48 /* Root System Description Pointer */
49 struct ACPIrsdp {
50 	u_char		signature[8];
51 	u_char		sum;
52 	u_char		oem[6];
53 	u_char		revision;
54 	u_int32_t	rsdt_addr;
55 	u_int32_t	length;
56 	u_int64_t	xsdt_addr;
57 	u_char		xsum;
58 	u_char		_reserved_[3];
59 } __packed;
60 
61 /* System Description Table */
62 struct ACPIsdt {
63 	u_char		signature[4];
64 	u_int32_t	len;
65 	u_char		rev;
66 	u_char		check;
67 	u_char		oemid[6];
68 	u_char		oemtblid[8];
69 	u_int32_t	oemrev;
70 	u_char		creator[4];
71 	u_int32_t	crerev;
72 #define SIZEOF_SDT_HDR 36	/* struct size except body */
73 	u_int32_t	body[1];/* This member should be casted */
74 } __packed;
75 
76 /* Fixed ACPI Description Table (body) */
77 struct FADTbody {
78 	u_int32_t	facs_ptr;
79 	u_int32_t	dsdt_ptr;
80 	u_int8_t	int_model;
81 #define ACPI_FADT_INTMODEL_PIC	0	/* Standard PC-AT PIC */
82 #define ACPI_FADT_INTMODEL_APIC	1	/* Multiple APIC */
83 	u_int8_t	pm_profile;
84 	u_int16_t	sci_int;
85 	u_int32_t	smi_cmd;
86 	u_int8_t	acpi_enable;
87 	u_int8_t	acpi_disable;
88 	u_int8_t	s4biosreq;
89 	u_int8_t	pstate_cnt;
90 	u_int32_t	pm1a_evt_blk;
91 	u_int32_t	pm1b_evt_blk;
92 	u_int32_t	pm1a_cnt_blk;
93 	u_int32_t	pm1b_cnt_blk;
94 	u_int32_t	pm2_cnt_blk;
95 	u_int32_t	pm_tmr_blk;
96 	u_int32_t	gpe0_blk;
97 	u_int32_t	gpe1_blk;
98 	u_int8_t	pm1_evt_len;
99 	u_int8_t	pm1_cnt_len;
100 	u_int8_t	pm2_cnt_len;
101 	u_int8_t	pm_tmr_len;
102 	u_int8_t	gpe0_len;
103 	u_int8_t	gpe1_len;
104 	u_int8_t	gpe1_base;
105 	u_int8_t	cst_cnt;
106 	u_int16_t	p_lvl2_lat;
107 	u_int16_t	p_lvl3_lat;
108 	u_int16_t	flush_size;
109 	u_int16_t	flush_stride;
110 	u_int8_t	duty_off;
111 	u_int8_t	duty_width;
112 	u_int8_t	day_alrm;
113 	u_int8_t	mon_alrm;
114 	u_int8_t	century;
115 	u_int16_t	iapc_boot_arch;
116 #define FADT_FLAG_LEGACY_DEV	1	/* System has legacy devices */
117 #define FADT_FLAG_8042		2	/* 8042 keyboard controller */
118 	u_char		reserved4[1];
119 	u_int32_t	flags;
120 #define FADT_FLAG_WBINVD	1	/* WBINVD is correctly supported */
121 #define FADT_FLAG_WBINVD_FLUSH	2	/* WBINVD flushes caches */
122 #define FADT_FLAG_PROC_C1	4	/* C1 power state supported */
123 #define FADT_FLAG_P_LVL2_UP	8	/* C2 power state works on SMP */
124 #define FADT_FLAG_PWR_BUTTON	16	/* Power button uses control method */
125 #define FADT_FLAG_SLP_BUTTON	32	/* Sleep button uses control method */
126 #define FADT_FLAG_FIX_RTC	64	/* RTC wakeup not supported */
127 #define FADT_FLAG_RTC_S4	128	/* RTC can wakeup from S4 state */
128 #define FADT_FLAG_TMR_VAL_EXT	256	/* TMR_VAL is 32bit */
129 #define FADT_FLAG_DCK_CAP	512	/* Can support docking */
130 #define FADT_FLAG_RESET_REG	1024	/* Supports RESET_REG */
131 #define FADT_FLAG_SEALED_CASE	2048	/* Case cannot be opened */
132 #define FADT_FLAG_HEADLESS	4096	/* No monitor */
133 #define FADT_FLAG_CPU_SW_SLP	8192	/* Supports CPU software sleep */
134 	struct ACPIgas	reset_reg;
135 	u_int8_t	reset_value;
136 	u_int8_t	reserved5[3];
137 	u_int64_t	x_facs_ptr;
138 	u_int64_t	x_dsdt_ptr;
139 	struct ACPIgas	x_pm1a_evt_blk;
140 	struct ACPIgas	x_pm1b_evt_blk;
141 	struct ACPIgas	x_pm1a_cnt_blk;
142 	struct ACPIgas	x_pm1b_cnt_blk;
143 	struct ACPIgas	x_pm2_cnt_blk;
144 	struct ACPIgas	x_pm_tmr_blk;
145 	struct ACPIgas	x_gpe0_blk;
146 	struct ACPIgas	x_gpe1_blk;
147 } __packed;
148 
149 /* Firmware ACPI Control Structure */
150 struct FACSbody {
151 	u_char		signature[4];
152 	u_int32_t	len;
153 	u_int32_t	hw_sig;
154 	/*
155 	 * NOTE This should be filled with physical address below 1MB!!
156 	 * sigh....
157 	 */
158 	u_int32_t	firm_wake_vec;
159 	u_int32_t	global_lock;
160 #define FACS_FLAG_LOCK_PENDING	1	/* 5.2.6.1 Global Lock */
161 #define FACS_FLAG_LOCK_OWNED	2
162 	u_int32_t	flags;
163 #define FACS_FLAG_S4BIOS_F	1	/* Supports S4BIOS_SEQ */
164 	u_int64_t	x_firm_wake_vec;
165 	u_int8_t	version;
166 	char		reserved[31];
167 } __packed;
168 
169 struct MADT_local_apic {
170 	u_char		cpu_id;
171 	u_char		apic_id;
172 	u_int32_t	flags;
173 #define	ACPI_MADT_APIC_LOCAL_FLAG_ENABLED	1
174 } __packed;
175 
176 struct MADT_io_apic {
177 	u_char		apic_id;
178 	u_char		reserved;
179 	u_int32_t	apic_addr;
180 	u_int32_t	int_base;
181 } __packed;
182 
183 struct MADT_int_override {
184 	u_char		bus;
185 	u_char		source;
186 	u_int32_t	intr;
187 	u_int16_t	mps_flags;
188 #define	MPS_INT_FLAG_POLARITY_MASK	0x3
189 #define	MPS_INT_FLAG_POLARITY_CONFORM	0x0
190 #define	MPS_INT_FLAG_POLARITY_HIGH	0x1
191 #define	MPS_INT_FLAG_POLARITY_LOW	0x3
192 #define	MPS_INT_FLAG_TRIGGER_MASK	0xc
193 #define	MPS_INT_FLAG_TRIGGER_CONFORM	0x0
194 #define	MPS_INT_FLAG_TRIGGER_EDGE	0x4
195 #define	MPS_INT_FLAG_TRIGGER_LEVEL	0xc
196 } __packed;
197 
198 struct MADT_nmi {
199 	u_int16_t	mps_flags;
200 	u_int32_t	intr;
201 } __packed;
202 
203 struct MADT_local_nmi {
204 	u_char		cpu_id;
205 	u_int16_t	mps_flags;
206 	u_char		lintpin;
207 } __packed;
208 
209 struct MADT_local_apic_override {
210 	u_char		reserved[2];
211 	u_int64_t	apic_addr;
212 } __packed;
213 
214 struct MADT_io_sapic {
215 	u_char		apic_id;
216 	u_char		reserved;
217 	u_int32_t	int_base;
218 	u_int64_t	apic_addr;
219 } __packed;
220 
221 struct MADT_local_sapic {
222 	u_char		cpu_id;
223 	u_char		apic_id;
224 	u_char		apic_eid;
225 	u_char		reserved[3];
226 	u_int32_t	flags;
227 } __packed;
228 
229 struct MADT_int_src {
230 	u_int16_t	mps_flags;
231 	u_char		type;
232 #define	ACPI_MADT_APIC_INT_SOURCE_PMI	1
233 #define	ACPI_MADT_APIC_INT_SOURCE_INIT	2
234 #define	ACPI_MADT_APIC_INT_SOURCE_CPEI	3	/* Corrected Platform Error */
235 	u_char		cpu_id;
236 	u_char		cpu_eid;
237 	u_char		sapic_vector;
238 	u_int32_t	intr;
239 	u_char		reserved[4];
240 } __packed;
241 
242 struct MADT_APIC {
243 	u_char		type;
244 #define	ACPI_MADT_APIC_TYPE_LOCAL_APIC	0
245 #define	ACPI_MADT_APIC_TYPE_IO_APIC	1
246 #define	ACPI_MADT_APIC_TYPE_INT_OVERRIDE 2
247 #define	ACPI_MADT_APIC_TYPE_NMI		3
248 #define	ACPI_MADT_APIC_TYPE_LOCAL_NMI	4
249 #define	ACPI_MADT_APIC_TYPE_LOCAL_OVERRIDE 5
250 #define	ACPI_MADT_APIC_TYPE_IO_SAPIC	6
251 #define	ACPI_MADT_APIC_TYPE_LOCAL_SAPIC	7
252 #define	ACPI_MADT_APIC_TYPE_INT_SRC	8
253 	u_char		len;
254 	union {
255 		struct MADT_local_apic local_apic;
256 		struct MADT_io_apic io_apic;
257 		struct MADT_int_override int_override;
258 		struct MADT_nmi nmi;
259 		struct MADT_local_nmi local_nmi;
260 		struct MADT_local_apic_override local_apic_override;
261 		struct MADT_io_sapic io_sapic;
262 		struct MADT_local_sapic local_sapic;
263 		struct MADT_int_src int_src;
264 	} body;
265 } __packed;
266 
267 struct MADTbody {
268 	u_int32_t	lapic_addr;
269 	u_int32_t	flags;
270 #define	ACPI_APIC_FLAG_PCAT_COMPAT 1	/* System has dual-8259 setup. */
271 	u_char		body[1];
272 } __packed;
273 
274 struct HPETbody {
275 	u_int32_t	block_hwrev:8,
276 			block_comparitors:5,
277 			block_counter_size:1,
278 			:1,
279 			block_legacy_capable:1,
280 			block_pcivendor:16;
281 	u_int32_t	base_addr;
282 	u_int64_t	reserved1;
283 	u_int8_t	hpet_number;
284 	u_int16_t	clock_tick __packed;
285 } __packed;
286 
287 /* Embedded Controller Description Table */
288 struct ECDTbody {
289 	struct ACPIgas	ec_control;	/* Control register */
290 	struct ACPIgas	ec_data;	/* Data register */
291 	uint32_t	uid;		/* Same value as _UID in namespace */
292 	uint8_t		gpe_bit;	/* GPE bit for the EC */
293 	u_char		ec_id[1];	/* Variable length name string */
294 } __packed;
295 
296 /* Find and map the RSD PTR structure and return it for parsing */
297 struct ACPIsdt  *sdt_load_devmem(void);
298 
299 /*
300  * Load the DSDT from a previous save file.  Note that other tables are
301  * not saved (i.e. FADT)
302  */
303 struct ACPIsdt  *dsdt_load_file(char *);
304 
305 /* Save the DSDT to a file */
306 void		 dsdt_save_file(char *, struct ACPIsdt *);
307 
308 /* Print out as many fixed tables as possible, given the RSD PTR */
309 void		 sdt_print_all(struct ACPIsdt *);
310 
311 /* Disassemble the AML in the DSDT */
312 void		 aml_disassemble(struct ACPIsdt *);
313 
314 /* Routines for accessing tables in physical memory */
315 struct ACPIrsdp	*acpi_find_rsd_ptr(void);
316 void		*acpi_map_physical(vm_offset_t, size_t);
317 struct ACPIsdt	*sdt_from_rsdt(struct ACPIsdt *, const char *);
318 struct ACPIsdt	*dsdt_from_fadt(struct FADTbody *);
319 int		 acpi_checksum(void *, size_t);
320 
321 /* Command line flags */
322 extern int	dflag;
323 extern int	tflag;
324 extern int	vflag;
325 
326 #endif	/* !_ACPIDUMP_H_ */
327