The Pedigree Project  0.1
mach_pc/Pic.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_PIC_H
21 #define KERNEL_MACHINE_X86_COMMON_PIC_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/machine/IrqManager.h"
26 #include "pedigree/kernel/machine/types.h"
27 #include "pedigree/kernel/processor/InterruptHandler.h"
28 #include "pedigree/kernel/processor/IoPort.h"
29 #include "pedigree/kernel/processor/state_forward.h"
30 #include "pedigree/kernel/processor/types.h"
31 #include "pedigree/kernel/utilities/List.h"
32 #include "pedigree/kernel/utilities/new"
33 
34 class Device;
35 class IrqHandler;
36 
41 class Pic : public IrqManager, private InterruptHandler
42 {
43  public:
46  inline static Pic &instance()
47  {
48  return m_Instance;
49  }
50 
51  //
52  // IrqManager interface
53  //
54  virtual irq_id_t
55  registerIsaIrqHandler(uint8_t irq, IrqHandler *handler, bool bEdge = false);
56  virtual irq_id_t
57  registerPciIrqHandler(IrqHandler *handler, Device *pDevice);
58  virtual void acknowledgeIrq(irq_id_t Id);
59  virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler);
60 
65 
67  virtual void tick();
68 
70  virtual bool control(uint8_t irq, ControlCode code, size_t argument);
71 
72  private:
76  inline virtual ~Pic()
77  {
78  }
81  Pic(const Pic &);
84  Pic &operator=(const Pic &);
85 
86  //
87  // InterruptHandler interface
88  //
89  virtual void interrupt(size_t interruptNumber, InterruptState &state);
90 
91  void eoi(uint8_t irq);
92  void enable(uint8_t irq, bool enable);
93  void enableAll(bool enable);
94 
96  bool spurious(size_t irq);
97 
102 
106  bool m_HandlerEdge[16];
108  size_t m_IrqCount[16];
110  bool m_MitigatedIrqs[16];
115 
118 
120  static Pic m_Instance;
121 };
122 
125 #endif
IoPort m_MasterPort
Definition: mach_pc/Pic.h:101
virtual irq_id_t registerPciIrqHandler(IrqHandler *handler, Device *pDevice)
Definition: mach_pc/Pic.cc:86
uint8_t m_InterruptMask
Definition: mach_pc/Pic.h:114
virtual void tick()
Definition: mach_pc/Pic.cc:41
virtual void acknowledgeIrq(irq_id_t Id)
Definition: mach_pc/Pic.cc:103
size_t m_IrqCount[16]
Definition: mach_pc/Pic.h:108
static Pic & instance()
Definition: mach_pc/Pic.h:46
Pic & operator=(const Pic &)
virtual bool control(uint8_t irq, ControlCode code, size_t argument)
Definition: mach_pc/Pic.cc:45
Definition: Device.h:43
IoPort m_SlavePort
Definition: mach_pc/Pic.h:99
virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler)
Definition: mach_pc/Pic.cc:111
List< IrqHandler * > m_Handler[16]
Definition: mach_pc/Pic.h:104
bool m_HandlerEdge[16]
Definition: mach_pc/Pic.h:106
I/O port range.
Definition: IoPort.h:34
virtual ~Pic()
Definition: mach_pc/Pic.h:76
static Pic m_Instance
Definition: mach_pc/Pic.h:120
bool m_MitigatedIrqs[16]
Definition: mach_pc/Pic.h:110
bool spurious(size_t irq)
Definition: mach_pc/Pic.cc:182
Pic() INITIALISATION_ONLY
Definition: mach_pc/Pic.cc:171
virtual void interrupt(size_t interruptNumber, InterruptState &state)
Definition: mach_pc/Pic.cc:204
Abstract base class for interrupt-handlers.
virtual irq_id_t registerIsaIrqHandler(uint8_t irq, IrqHandler *handler, bool bEdge=false)
Definition: mach_pc/Pic.cc:72
bool initialise() INITIALISATION_ONLY
Definition: mach_pc/Pic.cc:131
size_t m_MitigationThreshold[16]
Definition: mach_pc/Pic.h:112
Spinlock m_Lock
Definition: mach_pc/Pic.h:117