FreeNOS
IntelAPIC.h
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 #ifndef __LIBARCH_INTEL_APIC_H
19 #define __LIBARCH_INTEL_APIC_H
20 
21 #include <Types.h>
22 #include <BitOperations.h>
23 #include <IntController.h>
24 #include <Timer.h>
25 #include "IntelIO.h"
26 
28 class MemoryContext;
29 class IntelPIT;
30 
45 class IntelAPIC : public IntController, public Timer
46 {
47  using Timer::start;
48 
49  public:
50 
52  static const uint IOBase = 0xfee00000;
53 
55  static const uint TimerVector = 48;
56 
57  private:
58 
62  enum Registers
63  {
64  Identifier = 0x20,
65  Version = 0x30,
66  TaskPriority = 0x80,
71  InService = 0x100,
72  TriggerMode = 0x180,
73  IntRequest = 0x200,
74  ErrorStatus = 0x280,
75  IntCommand1 = 0x300,
76  IntCommand2 = 0x310,
77  Timer = 0x320,
78  ThermalSensor = 0x330,
79  PerfCounters = 0x340,
80  LocalInt0 = 0x350,
81  LocalInt1 = 0x360,
82  Error = 0x370,
83  InitialCount = 0x380,
84  CurrentCount = 0x390,
85  DivideConfig = 0x3e0
86  };
87 
92  {
93  APICEnable = 0x100
94  };
95 
100  {
102  };
103 
108  {
109  TimerMasked = (1 << 16),
110  PeriodicMode = (1 << 17)
111  };
112 
113  public:
114 
118  IntelAPIC();
119 
125  IntelIO & getIO();
126 
132  uint getCounter() const;
133 
139  virtual Timer::Result initialize();
140 
147  virtual Timer::Result wait(u32 microseconds) const;
148 
156 
164  Timer::Result start(uint initialCounter, uint hertz);
165 
175  virtual Timer::Result start();
176 
182  virtual Timer::Result stop();
183 
190  virtual IntController::Result enable(uint irq);
191 
198  virtual IntController::Result disable(uint irq);
199 
210  virtual IntController::Result clear(uint irq);
211 
220 
230 
231  private:
232 
235 
238 };
239 
246 #endif /* __LIBARCH_INTEL_APIC_H */
IntelAPIC::TaskPriority
@ TaskPriority
Definition: IntelAPIC.h:66
IntelAPIC::ProcessorPriority
@ ProcessorPriority
Definition: IntelAPIC.h:68
IntelPIT
Intel 8254 Programmable Interrupt Timer (PIT).
Definition: IntelPIT.h:40
IntelAPIC::IntelAPIC
IntelAPIC()
Constructor.
Definition: IntelAPIC.cpp:36
IntController
Interrupt controller interface.
Definition: IntController.h:35
IntelIO.h
IntelAPIC::getCounter
uint getCounter() const
Get timer initial counter.
Definition: IntelAPIC.cpp:50
IntelAPIC::TimerFlags
TimerFlags
Timer Register flags.
Definition: IntelAPIC.h:107
MemoryContext
Virtual memory abstract interface.
Definition: MemoryContext.h:42
IntelAPIC::ErrorStatus
@ ErrorStatus
Definition: IntelAPIC.h:74
Timer::start
virtual Result start()
Start the timer.
Definition: Timer.cpp:64
Types.h
IntelAPIC::clear
virtual IntController::Result clear(uint irq)
Clear hardware interrupt (IRQ).
Definition: IntelAPIC.cpp:189
IntelAPIC::CurrentCount
@ CurrentCount
Definition: IntelAPIC.h:84
IntelAPIC::InService
@ InService
Definition: IntelAPIC.h:71
IntelAPIC::InitialCount
@ InitialCount
Definition: IntelAPIC.h:83
IntelAPIC::stop
virtual Timer::Result stop()
Stop the APIC timer.
Definition: IntelAPIC.cpp:156
IntelAPIC::sendIPI
IntController::Result sendIPI(uint coreId, uint vector)
Send Intercore-Processor-Interrupt.
Definition: IntelAPIC.cpp:237
IntelAPIC::start
virtual Timer::Result start()
(Re)start the APIC timer.
Definition: IntelAPIC.cpp:149
IntelAPIC::Divide16
@ Divide16
Definition: IntelAPIC.h:101
IntelAPIC::disable
virtual IntController::Result disable(uint irq)
Disable hardware interrupt (IRQ).
Definition: IntelAPIC.cpp:184
Address
unsigned long Address
A memory address.
Definition: Types.h:131
IntelAPIC::ThermalSensor
@ ThermalSensor
Definition: IntelAPIC.h:78
BitOperations.h
IntelAPIC::IOBase
static const uint IOBase
APIC memory mapped I/O register base offset (physical address).
Definition: IntelAPIC.h:52
IntelAPIC::PerfCounters
@ PerfCounters
Definition: IntelAPIC.h:79
Timer
Represents a configurable timer device.
Definition: Timer.h:35
IntelAPIC::TimerMasked
@ TimerMasked
Definition: IntelAPIC.h:109
IntelAPIC::APICEnable
@ APICEnable
Definition: IntelAPIC.h:93
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
IntelAPIC::TriggerMode
@ TriggerMode
Definition: IntelAPIC.h:72
IntelAPIC::PeriodicMode
@ PeriodicMode
Definition: IntelAPIC.h:110
Timer.h
IntelAPIC::enable
virtual IntController::Result enable(uint irq)
Enable hardware interrupt (IRQ).
Definition: IntelAPIC.cpp:179
IntelAPIC::IntCommand2
@ IntCommand2
Definition: IntelAPIC.h:76
IntelAPIC::ArbitrationPriority
@ ArbitrationPriority
Definition: IntelAPIC.h:67
Error
slong Error
Error code defined in Error.h.
Definition: Types.h:159
IntelAPIC::m_io
IntelIO m_io
I/O object.
Definition: IntelAPIC.h:234
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
IntelAPIC::SpuriousIntVecFlags
SpuriousIntVecFlags
Spurious Interrupt Vector Register flags.
Definition: IntelAPIC.h:91
IntelAPIC::SpuriousIntVec
@ SpuriousIntVec
Definition: IntelAPIC.h:70
IntelAPIC::LocalInt0
@ LocalInt0
Definition: IntelAPIC.h:80
IntelAPIC::DivideConfigFlags
DivideConfigFlags
Timer Divide Configuration Register flags.
Definition: IntelAPIC.h:99
IntelAPIC::EndOfInterrupt
@ EndOfInterrupt
Definition: IntelAPIC.h:69
Timer::Result
Result
Result codes.
Definition: Timer.h:52
IntelAPIC::Identifier
@ Identifier
Definition: IntelAPIC.h:64
IntelAPIC::wait
virtual Timer::Result wait(u32 microseconds) const
Busy wait a number of microseconds.
Definition: IntelAPIC.cpp:93
IntController.h
IntelAPIC
Intel Advanced Programmable Interrupt Controller (APIC)
Definition: IntelAPIC.h:45
IntelIO
Intel I/O functions.
Definition: IntelIO.h:38
IntelAPIC::LocalInt1
@ LocalInt1
Definition: IntelAPIC.h:81
IntelAPIC::Registers
Registers
Hardware registers.
Definition: IntelAPIC.h:62
IntelAPIC::sendStartupIPI
IntController::Result sendStartupIPI(uint cpuId, Address addr)
Send startup Intercore-Processor-Interrupt.
Definition: IntelAPIC.cpp:195
coreId
u8 coreId
Definition: IntelACPI.h:64
IntelAPIC::Version
@ Version
Definition: IntelAPIC.h:65
IntelAPIC::IntCommand1
@ IntCommand1
Definition: IntelAPIC.h:75
IntelAPIC::IntRequest
@ IntRequest
Definition: IntelAPIC.h:73
IntController::Result
Result
Result codes.
Definition: IntController.h:42
IntelAPIC::initialize
virtual Timer::Result initialize()
Initialize the APIC.
Definition: IntelAPIC.cpp:162
IntelAPIC::getIO
IntelIO & getIO()
Get I/O object.
Definition: IntelAPIC.cpp:45
IntelAPIC::m_initialCounter
uint m_initialCounter
Saved initial counter value for APIC timer.
Definition: IntelAPIC.h:237
IntelAPIC::TimerVector
static const uint TimerVector
APIC timer interrupt vector is fixed at 48.
Definition: IntelAPIC.h:55
IntelAPIC::DivideConfig
@ DivideConfig
Definition: IntelAPIC.h:85