The Pedigree Project  0.1
OpenPic.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_PPC_COMMON_PIC_H
21 #define KERNEL_MACHINE_PPC_COMMON_PIC_H
22 
23 #include "pedigree/kernel/machine/IrqManager.h"
24 #include "pedigree/kernel/processor/InterruptManager.h"
25 #include "pedigree/kernel/processor/MemoryMappedIo.h"
26 
30 // CPU registers - PPC implementation of OpenPIC does not need to implement the
31 // "this processor"
32 // registers at 0x0-0x1000, so we use the global ones at
33 // 0x20000.
34 #define OPENPIC_REG_TASK_PRIORITY 0x20080
35 #define OPENPIC_REG_ACK 0x200A0
36 #define OPENPIC_REG_EOI 0x200B0
37 
38 // Global registers.
39 #define OPENPIC_REG_FEATURE 0x01000
40 #define OPENPIC_REG_CONF0 0x01020
41 #define OPENPIC_FLAG_CONF0_P \
42  0x20000000 // 8259 passthrough DISABLE - 8259 passthrough is enabled by
43  // default, which basically turns off half of the PIC. It
44  // doesn't apply to us.
45 #define OPENPIC_REG_SPURIOUS 0x010E0
46 
47 // IRQ sources.
48 #define OPENPIC_SOURCE_START 0x10000
49 #define OPENPIC_SOURCE_END 0x20000
50 
51 #define OPENPIC_SOURCE_MASK 0x80000000
52 #define OPENPIC_SOURCE_ACT 0x40000000
53 #define OPENPIC_SOURCE_PRIORITY 0x00080000 // Default priority = 15 (highest)
54 
56 class OpenPic : public IrqManager, private InterruptHandler
57 {
58  public:
61  inline static OpenPic &instance()
62  {
63  return m_Instance;
64  }
65 
66  //
67  // IrqManager interface
68  //
69  virtual irq_id_t registerIsaIrqHandler(uint8_t irq, IrqHandler *handler);
70  virtual irq_id_t registerPciIrqHandler(IrqHandler *handler);
71  virtual void acknowledgeIrq(irq_id_t Id);
72  virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler);
73 
78 
79  private:
83  inline virtual ~OpenPic()
84  {
85  }
88  OpenPic(const OpenPic &);
91  OpenPic &operator=(const OpenPic &);
92 
93  void searchNode(class Device *pDev);
94 
95  //
96  // InterruptHandler interface
97  //
98  virtual void interrupt(size_t interruptNumber, InterruptState &state);
99 
100  void eoi(uint8_t irq);
101  void enable(uint8_t irq, bool enable);
102  void enableAll(bool enable);
103 
106 
109 
111  size_t m_nIrqs;
112 
115 
116  struct Feature
117  {
118  uint32_t reserved0 : 5;
119  uint32_t num_irq : 11;
120  uint32_t reserved1 : 3;
121  uint32_t num_cpu : 5;
122  uint32_t version : 8;
123  };
124 };
125 
128 #endif
OpenPic & operator=(const OpenPic &)
OpenPic() INITIALISATION_ONLY
Definition: OpenPic.cc:166
static OpenPic m_Instance
Definition: OpenPic.h:114
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
virtual void acknowledgeIrq(irq_id_t Id)
Definition: OpenPic.cc:49
Definition: Device.h:43
bool initialise() INITIALISATION_ONLY
Definition: OpenPic.cc:105
virtual void interrupt(size_t interruptNumber, InterruptState &state)
Definition: OpenPic.cc:172
IrqHandler * m_Handler[64]
Definition: OpenPic.h:108
IoBase * m_pPort
Definition: OpenPic.h:105
static OpenPic & instance()
Definition: OpenPic.h:61
Abstract base class for interrupt-handlers.
size_t m_nIrqs
Definition: OpenPic.h:111
virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler)
Definition: OpenPic.cc:57
virtual ~OpenPic()
Definition: OpenPic.h:83