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 
23 {
25 }
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 &&
39  rsd1->signature[1] == RootSystemSignature2)
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 {
68  MultipleAPICTableEntry *entry = &madt->entry[0];
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:
79  proc = (MultipleAPICTableProc *) entry;
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 
119  scanAPIC((MultipleAPICTable *) hdr);
120 
121  io.unmap();
122  }
123  }
124  else if (hdr->signature == ExtendedSystemTableSignature)
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 
140  scanAPIC((MultipleAPICTable *) hdr);
141 
142  io.unmap();
143  }
144  }
145  return Success;
146 }
147 
149 {
150  return IOError;
151 }
IntelACPI::RootSystemTable::entry
u32 entry[]
Definition: IntelACPI.h:113
IntelACPI::SystemDescriptorHeader::signature
u32 signature
Definition: IntelACPI.h:95
IntelACPI::MultipleAPICTable
Multiple APIC Description Table (MADT).
Definition: IntelACPI.h:152
IntelACPI::ExtendedSystemTable::entry
u64 entry[]
Definition: IntelACPI.h:123
IntelACPI::RootSystemDescriptor1
Root System Description Pointer (ACPI v1.0).
Definition: IntelACPI.h:67
CoreManager::NotFound
@ NotFound
Definition: CoreManager.h:49
IntelACPI::RootSystemTableSignature
static const u32 RootSystemTableSignature
Signature for the Root System Descriptor Table (RSDT).
Definition: IntelACPI.h:56
IO::unmap
Result unmap()
Unmap I/O address space.
Definition: IO.cpp:70
CoreManager::m_cores
List< uint > m_cores
List of core ids found.
Definition: CoreManager.h:91
NOTICE
#define NOTICE(msg)
Output a notice message.
Definition: Log.h:75
List::clear
virtual void clear()
Clears the entire List.
Definition: List.h:232
IntelACPI::m_rootIO
IntelIO m_rootIO
Root/Extended SDT table I/O object.
Definition: IntelACPI.h:213
IntelACPI::RootSystemSignature2
static const uint RootSystemSignature2
Signature to detect a valid RootSystemDescriptor (part 2).
Definition: IntelACPI.h:53
IO::map
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
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
IntelACPI::MultipleAPICTableSignature
static const u32 MultipleAPICTableSignature
Signature for the Multiple APIC Descriptor Table (MADT).
Definition: IntelACPI.h:62
IntelACPI::RootSystemDescriptor1::signature
u32 signature[2]
Definition: IntelACPI.h:69
Address
unsigned long Address
A memory address.
Definition: Types.h:131
IntelACPI::RootSystemTable
Root System Descriptor Table (RSDT)
Definition: IntelACPI.h:110
IntelACPI::RSDSize
static const uint RSDSize
Size of the memory region for searching the RootSystemDescriptor.
Definition: IntelACPI.h:47
IntelACPI::RootSystemDescriptor1::revision
u8 revision
Definition: IntelACPI.h:72
IntelACPI::boot
virtual Result boot(CoreInfo *info)
Boot a processor.
Definition: IntelACPI.cpp:148
IntelACPI::initialize
virtual Result initialize()
Initialize the ACPI.
Definition: IntelACPI.cpp:27
IntelACPI::scanAPIC
Result scanAPIC(MultipleAPICTable *madt)
Scan for cores in the APIC tables.
Definition: IntelACPI.cpp:66
IntelACPI::SystemDescriptorHeader::length
u32 length
Definition: IntelACPI.h:96
Log.h
IntelACPI::discover
virtual Result discover()
Discover processors.
Definition: IntelACPI.cpp:97
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
IntelACPI::RootSystemSignature1
static const uint RootSystemSignature1
Signature to detect a valid RootSystemDescriptor (part 1).
Definition: IntelACPI.h:50
IntelACPI::MultipleAPICTableProc::apicId
u8 apicId
Definition: IntelACPI.h:144
u64
unsigned long long u64
Unsigned 64-bit number.
Definition: Types.h:50
IntelACPI.h
IntelACPI::MultipleAPICTable::header
SystemDescriptorHeader header
Definition: IntelACPI.h:154
IntelACPI::IntelACPI
IntelACPI()
Constructor.
Definition: IntelACPI.cpp:22
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
IntelACPI::ExtendedSystemTable::header
SystemDescriptorHeader header
Definition: IntelACPI.h:122
IntelACPI::MultipleAPICTableProc
Multiple APIC Description Table (MADT) processor entry.
Definition: IntelACPI.h:140
List::append
void append(T t)
Insert an item at the end of the list.
Definition: List.h:139
IntelACPI::RootSystemTable::header
SystemDescriptorHeader header
Definition: IntelACPI.h:112
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
IntelACPI::RootSystemDescriptor2::xsdtAddress
u64 xsdtAddress
Definition: IntelACPI.h:84
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
IntelACPI::SystemDescriptorHeader
System Descriptor Header (ACPI v3.0)
Definition: IntelACPI.h:93
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
IntelACPI::ExtendedSystemTableSignature
static const u32 ExtendedSystemTableSignature
Signature for the Extended System Descriptor Table (XSDT).
Definition: IntelACPI.h:59
IntelACPI::RootSystemDescriptor1::rsdtAddress
u32 rsdtAddress
Definition: IntelACPI.h:73
IntelACPI::RSDBase
static const uint RSDBase
Memory base address for searching the RootSystemDescriptor.
Definition: IntelACPI.h:44
CoreManager::IOError
@ IOError
Definition: CoreManager.h:48
entry
u32 entry[]
Definition: IntelACPI.h:64
CoreManager::Success
@ Success
Definition: CoreManager.h:47
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
IO::getBase
Address getBase() const
Get memory I/O base offset.
Definition: IO.cpp:28
IntelACPI::RootSystemDescriptor2
Root System Description Pointer (ACPI v2.0)
Definition: IntelACPI.h:80
IntelIO
Intel I/O functions.
Definition: IntelIO.h:38
IntelACPI::MultipleAPICTable::entry
MultipleAPICTableEntry entry[]
Definition: IntelACPI.h:157
IntelACPI::ExtendedSystemTable
Extended System Descriptor Table (XSDT)
Definition: IntelACPI.h:120
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
IntelACPI::MultipleAPICTableEntry
Multiple APIC Description Table (MADT) entry.
Definition: IntelACPI.h:130
IntelACPI::m_bios
IntelIO m_bios
I/O object for searching the RootSystemDescriptor.
Definition: IntelACPI.h:210
CoreManager::Result
Result
Result codes.
Definition: CoreManager.h:45