misc: Replaced master/slave terminology
[gem5.git] / src / dev / x86 / i8259.cc
index b3d3a5aa24b4b517f59865dfe14a1b77176ac2c8..8ba1235a499010d49f807ce11b5496500c5d7b3c 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Gabe Black
  */
 
+#include "dev/x86/i8259.hh"
+
 #include "base/bitfield.hh"
+#include "base/trace.hh"
+#include "debug/I8259.hh"
 #include "dev/x86/i82094aa.hh"
-#include "dev/x86/i8259.hh"
 #include "mem/packet.hh"
 #include "mem/packet_access.hh"
 
-X86ISA::I8259::I8259(Params * p) : BasicPioDevice(p), IntDev(this),
-                    latency(p->pio_latency), output(p->output),
-                    mode(p->mode), slave(NULL),
-                    IRR(0), ISR(0), IMR(0),
-                    readIRR(true), initControlWord(0), autoEOI(false)
+X86ISA::I8259::I8259(Params * p)
+    : BasicPioDevice(p, 2),
+      latency(p->pio_latency),
+      mode(p->mode), slave(p->slave),
+      IRR(0), ISR(0), IMR(0),
+      readIRR(true), initControlWord(0), autoEOI(false)
 {
-    if (output) {
-        I8259 * master;
-        master = dynamic_cast<I8259 *>(output->getDevice());
-        if (master)
-            master->setSlave(this);
-        I82094AA * ioApic;
-        ioApic = dynamic_cast<I82094AA *>(output->getDevice());
-        if (ioApic)
-            ioApic->setExtIntPic(this);
+    for (int i = 0; i < p->port_output_connection_count; i++) {
+        output.push_back(new IntSourcePin<I8259>(
+                    csprintf("%s.output[%d]", name(), i), i, this));
     }
-    pioSize = 2;
+
+    int in_count = p->port_inputs_connection_count;
+    panic_if(in_count >= NumLines,
+            "I8259 only supports 8 inputs, but there are %d.", in_count);
+    for (int i = 0; i < in_count; i++) {
+        inputs.push_back(new IntSinkPin<I8259>(
+                    csprintf("%s.inputs[%d]", name(), i), i, this));
+    }
+
+    for (bool &state: pinStates)
+        state = false;
+}
+
+void
+X86ISA::I8259::init()
+{
+    BasicPioDevice::init();
+
+    for (auto *input: inputs)
+        pinStates[input->getId()] = input->state();
 }
 
 Tick
@@ -62,17 +77,18 @@ X86ISA::I8259::read(PacketPtr pkt)
       case 0x0:
         if (readIRR) {
             DPRINTF(I8259, "Reading IRR as %#x.\n", IRR);
-            pkt->set(IRR);
+            pkt->setLE(IRR);
         } else {
             DPRINTF(I8259, "Reading ISR as %#x.\n", ISR);
-            pkt->set(ISR);
+            pkt->setLE(ISR);
         }
         break;
       case 0x1:
         DPRINTF(I8259, "Reading IMR as %#x.\n", IMR);
-        pkt->set(IMR);
+        pkt->setLE(IMR);
         break;
     }
+    pkt->makeAtomicResponse();
     return latency;
 }
 
@@ -80,7 +96,7 @@ Tick
 X86ISA::I8259::write(PacketPtr pkt)
 {
     assert(pkt->getSize() == 1);
-    uint8_t val = pkt->get<uint8_t>();
+    uint8_t val = pkt->getLE<uint8_t>();
     switch (pkt->getAddr() - pioAddr) {
       case 0x0:
         if (bits(val, 4)) {
@@ -175,7 +191,8 @@ X86ISA::I8259::write(PacketPtr pkt)
           case 0x2:
             DPRINTF(I8259, "Received initialization command word 3.\n");
             if (mode == Enums::I8259Master) {
-                DPRINTF(I8259, "Slaves attached to IRQs:%s%s%s%s%s%s%s%s\n",
+                DPRINTF(I8259, "Responders attached to "
+                        "IRQs:%s%s%s%s%s%s%s%s\n",
                         bits(val, 0) ? " 0" : "",
                         bits(val, 1) ? " 1" : "",
                         bits(val, 2) ? " 2" : "",
@@ -186,7 +203,7 @@ X86ISA::I8259::write(PacketPtr pkt)
                         bits(val, 7) ? " 7" : "");
                 cascadeBits = val;
             } else {
-                DPRINTF(I8259, "Slave ID is %d.\n", val & mask(3));
+                DPRINTF(I8259, "Responder ID is %d.\n", val & mask(3));
                 cascadeBits = val & mask(3);
             }
             if (expectICW4)
@@ -218,6 +235,7 @@ X86ISA::I8259::write(PacketPtr pkt)
         }
         break;
     }
+    pkt->makeAtomicResponse();
     return latency;
 }
 
@@ -235,9 +253,13 @@ void
 X86ISA::I8259::requestInterrupt(int line)
 {
     if (bits(ISR, 7, line) == 0) {
-        if (output) {
+        if (!output.empty()) {
             DPRINTF(I8259, "Propogating interrupt.\n");
-            output->signalInterrupt();
+            for (auto *wire: output) {
+                wire->raise();
+                //XXX This is a hack.
+                wire->lower();
+            }
         } else {
             warn("Received interrupt but didn't have "
                     "anyone to tell about it.\n");
@@ -248,7 +270,7 @@ X86ISA::I8259::requestInterrupt(int line)
 void
 X86ISA::I8259::signalInterrupt(int line)
 {
-    DPRINTF(I8259, "Interrupt raised on line %d.\n", line);
+    DPRINTF(I8259, "Interrupt requested for line %d.\n", line);
     if (line >= NumLines)
         fatal("Line number %d doesn't exist. The max is %d.\n",
                 line, NumLines - 1);
@@ -260,14 +282,36 @@ X86ISA::I8259::signalInterrupt(int line)
     }
 }
 
+void
+X86ISA::I8259::raiseInterruptPin(int number)
+{
+    DPRINTF(I8259, "Interrupt signal raised for pin %d.\n", number);
+    if (number >= NumLines)
+        fatal("Line number %d doesn't exist. The max is %d.\n",
+                number, NumLines - 1);
+    if (!pinStates[number])
+        signalInterrupt(number);
+    pinStates[number] = true;
+}
+
+void
+X86ISA::I8259::lowerInterruptPin(int number)
+{
+    DPRINTF(I8259, "Interrupt signal lowered for pin %d.\n", number);
+    if (number >= NumLines)
+        fatal("Line number %d doesn't exist. The max is %d.\n",
+                number, NumLines - 1);
+    pinStates[number] = false;
+}
+
 int
 X86ISA::I8259::getVector()
 {
     /*
-     * This code only handles one slave. Since that's how the PC platform
+     * This code only handles one responder. Since that's how the PC platform
      * always uses the 8259 PIC, there shouldn't be any need for more. If
-     * there -is- a need for more for some reason, "slave" can become a
-     * vector of slaves.
+     * there -is- a need for more for some reason, "responder" can become a
+     * vector of responders.
      */
     int line = findMsbSet(IRR);
     IRR &= ~(1 << line);
@@ -278,13 +322,49 @@ X86ISA::I8259::getVector()
         ISR |= 1 << line;
     }
     if (slave && bits(cascadeBits, line)) {
-        DPRINTF(I8259, "Interrupt was from slave who will "
+        DPRINTF(I8259, "Interrupt was from responder who will "
                 "provide the vector.\n");
         return slave->getVector();
     }
     return line | vectorOffset;
 }
 
+void
+X86ISA::I8259::serialize(CheckpointOut &cp) const
+{
+    SERIALIZE_ARRAY(pinStates, NumLines);
+    SERIALIZE_ENUM(mode);
+    SERIALIZE_SCALAR(IRR);
+    SERIALIZE_SCALAR(ISR);
+    SERIALIZE_SCALAR(IMR);
+    SERIALIZE_SCALAR(vectorOffset);
+    SERIALIZE_SCALAR(cascadeMode);
+    SERIALIZE_SCALAR(cascadeBits);
+    SERIALIZE_SCALAR(edgeTriggered);
+    SERIALIZE_SCALAR(readIRR);
+    SERIALIZE_SCALAR(expectICW4);
+    SERIALIZE_SCALAR(initControlWord);
+    SERIALIZE_SCALAR(autoEOI);
+}
+
+void
+X86ISA::I8259::unserialize(CheckpointIn &cp)
+{
+    UNSERIALIZE_ARRAY(pinStates, NumLines);
+    UNSERIALIZE_ENUM(mode);
+    UNSERIALIZE_SCALAR(IRR);
+    UNSERIALIZE_SCALAR(ISR);
+    UNSERIALIZE_SCALAR(IMR);
+    UNSERIALIZE_SCALAR(vectorOffset);
+    UNSERIALIZE_SCALAR(cascadeMode);
+    UNSERIALIZE_SCALAR(cascadeBits);
+    UNSERIALIZE_SCALAR(edgeTriggered);
+    UNSERIALIZE_SCALAR(readIRR);
+    UNSERIALIZE_SCALAR(expectICW4);
+    UNSERIALIZE_SCALAR(initControlWord);
+    UNSERIALIZE_SCALAR(autoEOI);
+}
+
 X86ISA::I8259 *
 I8259Params::create()
 {