The Pedigree Project  0.1
LocalApic.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_LOCAL_APIC_H
21 #define KERNEL_MACHINE_X86_COMMON_LOCAL_APIC_H
22 
23 #if defined(APIC)
24 
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/machine/SchedulerTimer.h"
27 #include "pedigree/kernel/processor/InterruptHandler.h"
28 #include "pedigree/kernel/processor/MemoryMappedIo.h"
29 #include "pedigree/kernel/processor/Processor.h"
30 #include "pedigree/kernel/processor/ProcessorInformation.h"
31 #include "pedigree/kernel/processor/state_forward.h"
32 #include "pedigree/kernel/processor/types.h"
33 #include "pedigree/kernel/utilities/Tree.h"
34 #include "pedigree/kernel/utilities/new"
35 
36 class TimerHandler;
37 
38 #define IPI_HALT_VECTOR 0xFB
39 #define ERROR_VECTOR 0xFC
40 #define SPURIOUS_VECTOR 0xFD
41 #define TIMER_VECTOR 0xFE
42 
48 class LocalApic : public SchedulerTimer, private InterruptHandler
49 {
50  public:
52  inline LocalApic()
53  : m_IoSpace("Local APIC"), m_Handlers(), m_BusFrequency(0)
54  {
55  }
57  inline virtual ~LocalApic()
58  {
59  }
60 
66  bool initialise(uint64_t physicalAddress) INITIALISATION_ONLY;
71  bool initialiseProcessor() INITIALISATION_ONLY;
72 
74  enum
75  {
76  deliveryModeFixed = 0,
77  deliveryModeLowestPriority = 1,
78  deliveryModeSmi = 2,
79  deliveryModeNmi = 4,
80  deliveryModeInit = 5,
81  deliveryModeStartup = 6,
82  deliveryModeExtInt = 7
83  };
84 
90  void interProcessorInterrupt(
91  uint8_t destinationApicId, uint8_t vector, size_t deliveryMode,
92  bool bAssert, bool bLevelTriggered);
93 
97  void interProcessorInterruptAllExcludingThis(
98  uint8_t vector, size_t deliveryMode);
99 
102  uint8_t getId();
103 
104  //
105  // SchedulerTimer interface
106  //
107  virtual bool registerHandler(TimerHandler *handler)
108  {
109  // insert() won't insert if the key is already present.
110  m_Handlers.insert(Processor::id(), handler);
111  return false;
112  }
113 
114  void ack();
115 
116  private:
119  LocalApic(const LocalApic &);
122  LocalApic &operator=(const LocalApic &);
123 
128  bool check(uint64_t physicalAddress) INITIALISATION_ONLY;
129 
130  //
131  // InterruptHandler interface
132  //
133  virtual void interrupt(size_t nInterruptNumber, InterruptState &state);
134 
136  MemoryMappedIo m_IoSpace;
137 
140 
142  size_t m_BusFrequency;
143 };
144 
147 #endif
148 
149 #endif
Memory mapped I/O range.
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
SchedulerTimer & operator=(const SchedulerTimer &)
virtual void interrupt(size_t nInterruptNumber, InterruptState &state)=0
A key/value dictionary.
Definition: Tree.h:33
static ProcessorId id()
Definition: Processor.cc:40
Abstract base class for interrupt-handlers.