summaryrefslogtreecommitdiff
path: root/i386/i386at/acpi_parse_apic.h
blob: 97a59a2e6d7658d9e7420d53350ceece91ae0ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* acpi_parse_apic.h - ACPI-MADT table parser. Header file
   Copyright (C) 2018 Juan Bosco Garcia
   Copyright (C) 2019 2020 Almudena Garcia Jurado-Centurion
   Written by Juan Bosco Garcia and Almudena Garcia Jurado-Centurion

   This file is part of Min_SMP.

   Min_SMP is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   Min_SMP is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */

#ifndef __ACPI_H__
#define __ACPI_H__

#include <include/stdint.h>

enum ACPI_RETURN {
    ACPI_BAD_CHECKSUM = -1,
    ACPI_BAD_ALIGN = -2,
    ACPI_NO_RSDP = -3,
    ACPI_NO_RSDT = -4,
    ACPI_BAD_SIGNATURE = -5,
    ACPI_NO_APIC = -6,
    ACPI_NO_LAPIC = -7,
    ACPI_APIC_FAILURE = -8,
    ACPI_FIT_FAILURE = -9,
    ACPI_SUCCESS = 0,
};

#define ACPI_RSDP_ALIGN 16
#define ACPI_RSDP_SIG "RSD PTR "

struct acpi_rsdp {
    uint8_t  	signature[8];
    uint8_t  	checksum;
    uint8_t  	oem_id[6];
    uint8_t  	revision[1];
    uint32_t 	rsdt_addr;
} __attribute__((__packed__));


/*
 * RSDT Entry Header
 *
 * Header which stores the descriptors of tables pointed from RDSP's Entry Field
 * Includes the signature of the table, to identify each table.
 *
 * In MADT, the signature is 'APIC'.
 */
struct acpi_dhdr {
    uint8_t		signature[4];
    uint32_t	length;
    uint8_t  	revision;
    uint8_t  	checksum;
    uint8_t  	oem_id[6];
    uint8_t  	oem_table_id[8];
    uint32_t 	oem_revision;
    uint8_t  	creator_id[4];
    uint32_t 	creator_revision;
} __attribute__((__packed__));


#define ACPI_RSDT_SIG "RSDT"

struct acpi_rsdt {
    struct acpi_dhdr 	header;
    uint32_t 			entry[0];
} __attribute__((__packed__));

/* APIC table signature. */
#define ACPI_APIC_SIG "APIC"

/* Types value for MADT entries: Local APIC, IOAPIC and IRQ Override. */
enum ACPI_APIC_ENTRY_TYPE {
    ACPI_APIC_ENTRY_LAPIC = 0,
    ACPI_APIC_ENTRY_IOAPIC = 1,
    ACPI_APIC_ENTRY_IRQ_OVERRIDE  = 2,
    ACPI_APIC_ENTRY_NONMASK_IRQ = 4
};

/*
 * APIC descriptor header
 * Define the type of the structure (Local APIC, I/O APIC or others).
 * Type: Local APIC (0), I/O APIC (1).
 */
struct acpi_apic_dhdr {
    uint8_t 	type;
    uint8_t 	length;
} __attribute__((__packed__));


/*
 * Multiple APIC Description Table (MADT)
 *
 * Describes the APIC structures which exist in the machine.
 * Includes the common address where Local APIC is mapped in main memory.
 *
 * Entry field stores the descriptors of APIC structures.
 */
struct acpi_apic {
    struct   	acpi_dhdr header;       /* Header, which stores the descriptor for RDST's Entry field. */
    uint32_t 	lapic_addr;             /* Local Interrupt Controller Address. */
    uint32_t 	flags;
    struct acpi_apic_dhdr entry[0];     /* Interrupt Controller Structure */
} __attribute__((__packed__));

/*
 * Processor Local APIC Structure
 *
 * Stores information about APIC ID, flags and ACPI Processor UID
 */

struct acpi_apic_lapic {
    struct      acpi_apic_dhdr header;
    uint8_t     processor_id;           /* ACPI Processor UID */
    uint8_t     apic_id;
    uint32_t    flags;
} __attribute__((__packed__));


/*
 * I/O APIC Structure
 *
 * Stores information about APIC ID, and I/O APIC tables
 */

struct acpi_apic_ioapic {
    struct      acpi_apic_dhdr header;
    uint8_t     apic_id;
    uint8_t     reserved;
    uint32_t    addr;
    uint32_t    gsi_base;
} __attribute__((__packed__));

/*
 * IRQ Override structure
 *
 * Stores information about IRQ override, with busses and IRQ.
 */

struct acpi_apic_irq_override {
    struct acpi_apic_dhdr header;
    uint8_t     bus;
    uint8_t     irq;
    uint32_t    gsi;
    uint16_t    flags;
} __attribute__((__packed__));

int acpi_apic_init(void);
void acpi_print_info(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, int acpi_rsdt_n);


#endif /* __ACPI_H__ */