The Pedigree Project  0.1
Smp.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_MACHINE_X86_COMMON_SMP_H
21 #define KERNEL_MACHINE_X86_COMMON_SMP_H
22 
23 #if defined(SMP)
24 
25 #include "../../core/processor/x86_common/Multiprocessor.h"
26 #include "pedigree/kernel/compiler.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/Vector.h"
29 #include "pedigree/kernel/utilities/new"
30 
37 class Smp
38 {
39  public:
41  inline static Smp &instance()
42  {
43  return m_Instance;
44  }
45 
48  void initialise() INITIALISATION_ONLY;
50  inline bool valid() const
51  {
52  return m_bValid;
53  }
54 
55 #if defined(APIC)
56 
58  inline uint64_t getLocalApicAddress() const
59  {
60  return m_LocalApicAddress;
61  }
65  getIoApicList() const
66  {
67  return m_IoApics;
68  }
69 #if defined(MULTIPROCESSOR)
71  getProcessorList() const
72  {
73  return m_Processors;
74  }
75 #endif
76 #endif
77 
78  private:
80  Smp() INITIALISATION_ONLY;
83  Smp(const Smp &);
86  Smp &operator=(const Smp &);
88  inline ~Smp()
89  {
90  }
91 
94  struct FloatingPointer
95  {
96  uint32_t signature;
97  uint32_t physicalAddress;
98  uint8_t length;
99  uint8_t revision;
100  uint8_t checksum;
101  uint8_t features[5];
102  } PACKED;
103 
106  struct ConfigTableHeader
107  {
108  uint32_t signature;
109  uint16_t baseTableLength;
110  uint8_t revision;
111  uint8_t checksum;
112  char oem[8];
113  char product[12];
114  uint32_t oemTable;
115  uint16_t oemTableSize;
116  uint16_t entryCount;
117  uint32_t localApicAddress;
118  uint16_t extendedTableLength;
119  uint8_t extendedChecksum;
120  uint8_t reserved;
121  } PACKED;
122 
124  struct Processor
125  {
126  uint8_t entryType;
127  uint8_t localApicId;
128  uint8_t localApicVersion;
129  uint8_t flags;
130  uint32_t signature;
131  uint32_t featureFlags;
132  uint32_t res0;
133  uint32_t res1;
134  } PACKED;
135 
137  struct Bus
138  {
139  uint8_t entryType;
140  uint8_t busId;
141  char name[6];
142  } PACKED;
143 
145  struct IoApic
146  {
147  uint8_t entryType;
148  uint8_t id;
149  uint8_t version;
150  uint8_t flags;
151  uint32_t address;
152  } PACKED;
153 
154  struct IoInterruptAssignment
155  {
156  uint8_t entryType;
157  uint8_t type;
158  uint16_t flags;
159  uint8_t busId;
160  uint8_t busIrq;
161  uint8_t ioApicId;
162  uint8_t ioApicIntn;
163  } PACKED;
164 
165  struct LocalInterruptAssignment
166  {
167  uint8_t entryType;
168  uint8_t type;
169  uint16_t flags;
170  uint8_t busId;
171  uint8_t busIrq;
172  uint8_t localApicId;
173  uint8_t localApicIntn;
174  } PACKED;
175 
178  bool find() INITIALISATION_ONLY;
183  FloatingPointer *find(void *pMemory, size_t sMemory) INITIALISATION_ONLY;
187  bool checksum(const FloatingPointer *pFloatingPointer) INITIALISATION_ONLY;
191  bool checksum(const ConfigTableHeader *pConfigTable) INITIALISATION_ONLY;
192 
194  bool m_bValid;
196  FloatingPointer *m_pFloatingPointer;
198  ConfigTableHeader *m_pConfigTable;
199 
200 #if defined(APIC)
201 
202  bool m_bPICMode;
204  uint64_t m_LocalApicAddress;
207 
208 #if defined(MULTIPROCESSOR)
209 
211 #endif
212 #endif
213 
215  static Smp m_Instance;
216 };
217 
220 #endif
221 
222 #endif
A vector / dynamic array.
Definition: Bus.h:31
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
The exception was caused by a hardware task switch.
Definition: Processor.h:80