FreeNOS
IntelCoreServer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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/User.h>
19 #include <FreeNOS/API.h>
20 #include <Factory.h>
21 #include <Log.h>
22 #include "IntelCoreServer.h"
23 
25 {
26  return new IntelCoreServer();
27 }
28 
30  : CoreServer()
31  , m_mp(m_apic)
32 {
33 }
34 
36 {
38 
39  if (r != API::Success)
40  {
41  ERROR("failed to register IPI vector: "
42  "ProcessCtl(WatchIRQ) returned: " << (uint)r);
43  return IOError;
44  }
45 
46  return CoreServer::initialize();
47 }
48 
50 {
51  // Signal the core to boot
52  if (m_mp.boot(info) != IntelMP::Success)
53  {
54  ERROR("failed to boot core" << coreId);
55  return Core::BootError;
56  }
57 
58  NOTICE("core" << coreId << " started");
59  return Core::Success;
60 }
61 
63 {
64  m_mp.initialize();
65 
68  {
69  NOTICE("using ACPI as CoreManager");
70  m_cores = &m_acpi;
71  }
72  else if (m_mp.discover() == IntelMP::Success)
73  {
74  NOTICE("using MPTable as CoreManager");
75  m_cores = &m_mp;
76  }
77  else
78  {
79  ERROR("no CoreManager found (ACPI or MPTable)");
80  return Core::NotFound;
81  }
82 
83  return Core::Success;
84 }
85 
87 {
88  // Wait for IPI which will wake us
90  ProcessCtl(SELF, EnterSleep, 0, 0);
91 }
92 
94 {
95  // Send IPI to ensure the slave wakes up for the message
97  {
98  ERROR("failed to send IPI to core" << coreId);
99  return Core::IOError;
100  }
101 
102  return Core::Success;
103 }
API::Result
Result
Enumeration of generic kernel API result codes.
Definition: API.h:68
IntelCoreServer
Represents a single Core in a Central Processing Unit (CPU).
Definition: IntelCoreServer.h:42
IntelCoreServer::waitIPI
virtual void waitIPI() const
Wait for Inter-Processor-Interrupt.
Definition: IntelCoreServer.cpp:86
NOTICE
#define NOTICE(msg)
Output a notice message.
Definition: Log.h:75
IntelMP::discover
virtual Result discover()
Discover processors.
Definition: IntelMP.cpp:56
Core::IOError
@ IOError
Definition: Core.h:55
EnableIRQ
@ EnableIRQ
Definition: ProcessCtl.h:44
Core::BootError
@ BootError
Definition: Core.h:52
WatchIRQ
@ WatchIRQ
Definition: ProcessCtl.h:43
Core::NotFound
@ NotFound
Definition: Core.h:51
IntelCoreServer::m_mp
IntelMP m_mp
Definition: IntelCoreServer.h:97
CoreServer::initialize
virtual Result initialize()
Initialize the server.
Definition: CoreServer.cpp:260
IntelAPIC::sendIPI
IntController::Result sendIPI(uint coreId, uint vector)
Send Intercore-Processor-Interrupt.
Definition: IntelAPIC.cpp:237
IntelCoreServer::m_apic
IntelAPIC m_apic
Definition: IntelCoreServer.h:96
IntController::Success
@ Success
Definition: IntController.h:44
IntelMP::boot
virtual Result boot(CoreInfo *info)
Boot a processor.
Definition: IntelMP.cpp:90
ProcessCtl
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition: ProcessCtl.h:93
IntelACPI::initialize
virtual Result initialize()
Initialize the ACPI.
Definition: IntelACPI.cpp:27
IntelCoreServer::m_acpi
IntelACPI m_acpi
Definition: IntelCoreServer.h:98
Log.h
IntelACPI::discover
virtual Result discover()
Discover processors.
Definition: IntelACPI.cpp:97
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
SELF
#define SELF
Definition: ProcessID.h:35
CoreServer
Represents a single Core in a Central Processing Unit (CPU).
Definition: CoreServer.h:49
ChannelServer< CoreServer, CoreMessage >::Result
Result
Result codes.
Definition: ChannelServer.h:99
ChannelServer< CoreServer, CoreMessage >::IOError
@ IOError
Definition: ChannelServer.h:104
IntelCoreServer::discoverCores
virtual Core::Result discoverCores()
Discover processor cores.
Definition: IntelCoreServer.cpp:62
CoreServer::m_cores
CoreManager * m_cores
Definition: CoreServer.h:240
IntelMP::initialize
virtual Result initialize()
Perform initialization.
Definition: IntelMP.cpp:30
AbstractFactory::create
static T * create()
Abstract function to create an instance of T.
IntelCoreServer::sendIPI
virtual Core::Result sendIPI(uint coreId)
Send Inter-Processor-Interrupt.
Definition: IntelCoreServer.cpp:93
EnterSleep
@ EnterSleep
Definition: ProcessCtl.h:51
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
Core::Result
Result
Result code for Actions.
Definition: Core.h:47
IntelCoreServer.h
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
CoreManager::Success
@ Success
Definition: CoreManager.h:47
IntelCoreServer::initialize
virtual Result initialize()
Initialize the server.
Definition: IntelCoreServer.cpp:35
API::Success
@ Success
Definition: API.h:70
IntelCoreServer::IPIVector
static const uint IPIVector
Inter-Processor-Interrupt vector number.
Definition: IntelCoreServer.h:47
IntelCoreServer::IntelCoreServer
IntelCoreServer()
Class constructor function.
Definition: IntelCoreServer.cpp:29
Core::Success
@ Success
Definition: Core.h:49
Factory.h
coreId
u8 coreId
Definition: IntelACPI.h:64
IntelCoreServer::bootCore
virtual Core::Result bootCore(uint coreId, CoreInfo *info)
Boot a processor core.
Definition: IntelCoreServer.cpp:49