Debian Codegraph @

i386/i386at/acpi_parse_apic.h

raw
1 /* acpi_parse_apic.h - ACPI-MADT table parser. Header file
2 Copyright (C) 2018 Juan Bosco Garcia
3 Copyright (C) 2019 2020 Almudena Garcia Jurado-Centurion
4 Written by Juan Bosco Garcia and Almudena Garcia Jurado-Centurion
5
6 This file is part of Min_SMP.
7
8 Min_SMP is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 Min_SMP is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
21
22 #ifndef __ACPI_H__
23 #define __ACPI_H__
24
25 #include <stdint.h>
26
27 enum ACPI_RETURN {
28 ACPI_BAD_CHECKSUM = -1,
29 ACPI_BAD_ALIGN = -2,
30 ACPI_NO_RSDP = -3,
31 ACPI_NO_RSDT = -4,
32 ACPI_BAD_SIGNATURE = -5,
33 ACPI_NO_APIC = -6,
34 ACPI_NO_LAPIC = -7,
35 ACPI_APIC_FAILURE = -8,
36 ACPI_FIT_FAILURE = -9,
37 ACPI_SUCCESS = 0,
38 };
39
40 #define ACPI_RSDP_ALIGN 16
41 #define ACPI_RSDP_SIG "RSD PTR "
42
43 struct acpi_rsdp {
44 uint8_t signature[8];
45 uint8_t checksum;
46 uint8_t oem_id[6];
47 uint8_t revision;
48 uint32_t rsdt_addr;
49 } __attribute__((__packed__));
50
51 struct acpi_rsdp2 {
52 struct acpi_rsdp v1;
53 uint32_t length;
54 uint64_t xsdt_addr;
55 uint8_t checksum;
56 uint8_t reserved[3];
57 } __attribute__((__packed__));
58
59 /*
60 * RSDT Entry Header
61 *
62 * Header which stores the descriptors of tables pointed from RDSP's Entry Field
63 * Includes the signature of the table, to identify each table.
64 *
65 * In MADT, the signature is 'APIC'.
66 */
67 struct acpi_dhdr {
68 uint8_t signature[4];
69 uint32_t length;
70 uint8_t revision;
71 uint8_t checksum;
72 uint8_t oem_id[6];
73 uint8_t oem_table_id[8];
74 uint32_t oem_revision;
75 uint8_t creator_id[4];
76 uint32_t creator_revision;
77 } __attribute__((__packed__));
78
79
80 #define ACPI_RSDT_SIG "RSDT"
81
82 struct acpi_rsdt {
83 struct acpi_dhdr header;
84 uint32_t entry[0];
85 } __attribute__((__packed__));
86
87 #define ACPI_XSDT_SIG "XSDT"
88
89 struct acpi_xsdt {
90 struct acpi_dhdr header;
91 uint64_t entry[0];
92 } __attribute__((__packed__));
93
94 struct acpi_address {
95 uint8_t is_io;
96 uint8_t reg_width;
97 uint8_t reg_offset;
98 uint8_t reserved;
99 uint64_t addr64;
100 } __attribute__((__packed__));
101
102 /* APIC table signature. */
103 #define ACPI_APIC_SIG "APIC"
104
105 /* Types value for MADT entries: Local APIC, IOAPIC and IRQ Override. */
106 enum ACPI_APIC_ENTRY_TYPE {
107 ACPI_APIC_ENTRY_LAPIC = 0,
108 ACPI_APIC_ENTRY_IOAPIC = 1,
109 ACPI_APIC_ENTRY_IRQ_OVERRIDE = 2,
110 ACPI_APIC_ENTRY_NONMASK_IRQ = 4
111 };
112
113 /*
114 * APIC descriptor header
115 * Define the type of the structure (Local APIC, I/O APIC or others).
116 * Type: Local APIC (0), I/O APIC (1).
117 */
118 struct acpi_apic_dhdr {
119 uint8_t type;
120 uint8_t length;
121 } __attribute__((__packed__));
122
123
124 /*
125 * Multiple APIC Description Table (MADT)
126 *
127 * Describes the APIC structures which exist in the machine.
128 * Includes the common address where Local APIC is mapped in main memory.
129 *
130 * Entry field stores the descriptors of APIC structures.
131 */
132 struct acpi_apic {
133 struct acpi_dhdr header; /* Header, which stores the descriptor for RDST's Entry field. */
134 uint32_t lapic_addr; /* Local Interrupt Controller Address. */
135 uint32_t flags;
136 struct acpi_apic_dhdr entry[0]; /* Interrupt Controller Structure */
137 } __attribute__((__packed__));
138
139 /*
140 * Processor Local APIC Structure
141 *
142 * Stores information about APIC ID, flags and ACPI Processor UID
143 */
144
145 struct acpi_apic_lapic {
146 struct acpi_apic_dhdr header;
147 uint8_t processor_id; /* ACPI Processor UID */
148 uint8_t apic_id;
149 uint32_t flags;
150 } __attribute__((__packed__));
151
152 #define ACPI_LAPIC_FLAG_ENABLED (1 << 0)
153 #define ACPI_LAPIC_FLAG_CAPABLE (1 << 1)
154
155 /*
156 * I/O APIC Structure
157 *
158 * Stores information about APIC ID, and I/O APIC tables
159 */
160
161 struct acpi_apic_ioapic {
162 struct acpi_apic_dhdr header;
163 uint8_t apic_id;
164 uint8_t reserved;
165 uint32_t addr;
166 uint32_t gsi_base;
167 } __attribute__((__packed__));
168
169 /*
170 * IRQ Override structure
171 *
172 * Stores information about IRQ override, with busses and IRQ.
173 */
174
175 struct acpi_apic_irq_override {
176 struct acpi_apic_dhdr header;
177 uint8_t bus;
178 uint8_t irq;
179 uint32_t gsi;
180 uint16_t flags;
181 } __attribute__((__packed__));
182
183
184 #define ACPI_HPET_SIG "HPET"
185
186 /*
187 * HPET High Precision Event Timer structure
188 */
189 struct acpi_hpet {
190 struct acpi_dhdr header;
191 uint32_t id;
192 struct acpi_address address;
193 uint8_t sequence;
194 uint16_t minimum_tick;
195 uint8_t flags;
196 } __attribute__((__packed__));
197
198 int acpi_apic_init(void);
199 void acpi_print_info(phys_addr_t rsdp, void *rsdt, int acpi_rsdt_n);
200
201 extern unsigned lapic_addr;
202
203 #endif /* __ACPI_H__ */