FreeNOS
IntelACPI.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/System.h>
19#include <Log.h>
20#include "IntelACPI.h"
21
26
28{
31 Address addr = m_bios.getBase();
32
33 // Look for the Multiprocessor configuration
34 for (uint i = 0; i < RSDSize - sizeof(Address); i += sizeof(Address))
35 {
36 rsd1 = (RootSystemDescriptor1 *)(addr + i);
37
38 if (rsd1->signature[0] == RootSystemSignature1 &&
40 {
41 // Found ACPI
42 DEBUG("found ACPI RootSys at " << (void *) rsd1);
43 DEBUG("ACPI v" << (rsd1->revision + 1) << ".0");
44 break;
45 }
46 }
47
48 // Check if the ACPI tables are found
49 if (!rsd1)
50 return NotFound;
51
52 if (rsd1->revision == 0)
53 {
55 NOTICE("RootSystemTable found");
56 }
57 else
58 {
59 rsd2 = (RootSystemDescriptor2 *) rsd1;
61 NOTICE("ExtendedSystemTable found");
62 }
63 return Success;
64}
65
67{
70 Size j = 0, madt_length = madt->header.length - sizeof(MultipleAPICTable);
71
72 // Search for APIC entries
73 while (j < madt_length)
74 {
75 entry = (MultipleAPICTableEntry *) (((u8 *)(&madt->entry[0])) + j);
76 switch (entry->type)
77 {
78 case 0:
80 DEBUG("APIC for core" << proc->apicId);
81 m_cores.append(proc->apicId);
82 break;
83
84 case 1:
85 DEBUG("I/O APIC");
86 break;
87
88 case 2:
89 DEBUG("IRQ source override");
90 break;
91 }
92 j += entry->length;
93 }
94 return Success;
95}
96
98{
100 m_cores.clear();
101
102 // Detect the Root/ExtendedSystemTable
104 {
105 RootSystemTable *rst = (RootSystemTable *) hdr;
106 Size num = (rst->header.length - sizeof(RootSystemTable)) / sizeof(u32);
107
108 DEBUG("found " << num << " SDT entries");
109 for (uint i = 0; i < num; i++)
110 {
111 IntelIO io;
112
113 io.map(rst->entry[i], PAGESIZE);
114 hdr = (SystemDescriptorHeader *) io.getBase();
115
116 DEBUG("entry " << i << " : " << (void *) hdr->signature);
117
120
121 io.unmap();
122 }
123 }
125 {
127 Size num = (xst->header.length - sizeof(ExtendedSystemTable)) / sizeof(u64);
128
129 DEBUG("found " << num << " SDT entries");
130 for (uint i = 0; i < num; i++)
131 {
132 IntelIO io;
133
134 io.map(xst->entry[i], PAGESIZE);
135 hdr = (SystemDescriptorHeader *) io.getBase();
136
137 DEBUG("entry " << i << " : " << (void *) hdr->signature);
138
141
142 io.unmap();
143 }
144 }
145 return Success;
146}
147
u32 entry[]
Definition IntelACPI.h:1
List< uint > m_cores
List of core ids found.
Definition CoreManager.h:91
Result
Result codes.
Definition CoreManager.h:46
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition IO.cpp:38
Address getBase() const
Get memory I/O base offset.
Definition IO.cpp:28
Result unmap()
Unmap I/O address space.
Definition IO.cpp:70
static const uint RSDSize
Size of the memory region for searching the RootSystemDescriptor.
Definition IntelACPI.h:47
static const u32 RootSystemTableSignature
Signature for the Root System Descriptor Table (RSDT).
Definition IntelACPI.h:56
static const uint RSDBase
Memory base address for searching the RootSystemDescriptor.
Definition IntelACPI.h:44
Result scanAPIC(MultipleAPICTable *madt)
Scan for cores in the APIC tables.
Definition IntelACPI.cpp:66
virtual Result initialize()
Initialize the ACPI.
Definition IntelACPI.cpp:27
IntelIO m_bios
I/O object for searching the RootSystemDescriptor.
Definition IntelACPI.h:210
static const u32 ExtendedSystemTableSignature
Signature for the Extended System Descriptor Table (XSDT).
Definition IntelACPI.h:59
virtual Result discover()
Discover processors.
Definition IntelACPI.cpp:97
virtual Result boot(CoreInfo *info)
Boot a processor.
static const u32 MultipleAPICTableSignature
Signature for the Multiple APIC Descriptor Table (MADT).
Definition IntelACPI.h:62
IntelIO m_rootIO
Root/Extended SDT table I/O object.
Definition IntelACPI.h:213
static const uint RootSystemSignature2
Signature to detect a valid RootSystemDescriptor (part 2).
Definition IntelACPI.h:53
static const uint RootSystemSignature1
Signature to detect a valid RootSystemDescriptor (part 1).
Definition IntelACPI.h:50
IntelACPI()
Constructor.
Definition IntelACPI.cpp:22
Intel I/O functions.
Definition IntelIO.h:39
void append(T t)
Insert an item at the end of the list.
Definition List.h:139
virtual void clear()
Clears the entire List.
Definition List.h:232
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
#define NOTICE(msg)
Output a notice message.
Definition Log.h:75
unsigned int uint
Unsigned integer number.
Definition Types.h:44
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Per-Core information structure.
Definition CoreInfo.h:61
Extended System Descriptor Table (XSDT)
Definition IntelACPI.h:121
SystemDescriptorHeader header
Definition IntelACPI.h:122
Multiple APIC Description Table (MADT) entry.
Definition IntelACPI.h:131
Multiple APIC Description Table (MADT) processor entry.
Definition IntelACPI.h:141
Multiple APIC Description Table (MADT).
Definition IntelACPI.h:153
SystemDescriptorHeader header
Definition IntelACPI.h:154
MultipleAPICTableEntry entry[]
Definition IntelACPI.h:157
Root System Description Pointer (ACPI v1.0).
Definition IntelACPI.h:68
Root System Description Pointer (ACPI v2.0)
Definition IntelACPI.h:81
Root System Descriptor Table (RSDT)
Definition IntelACPI.h:111
SystemDescriptorHeader header
Definition IntelACPI.h:112
System Descriptor Header (ACPI v3.0)
Definition IntelACPI.h:94