15390SN/A/*
25390SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
35390SN/A * All rights reserved.
45390SN/A *
55390SN/A * Redistribution and use in source and binary forms, with or without
65390SN/A * modification, are permitted provided that the following conditions are
75390SN/A * met: redistributions of source code must retain the above copyright
85390SN/A * notice, this list of conditions and the following disclaimer;
95390SN/A * redistributions in binary form must reproduce the above copyright
105390SN/A * notice, this list of conditions and the following disclaimer in the
115390SN/A * documentation and/or other materials provided with the distribution;
125390SN/A * neither the name of the copyright holders nor the names of its
135390SN/A * contributors may be used to endorse or promote products derived from
145390SN/A * this software without specific prior written permission.
155390SN/A *
165390SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175390SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185390SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195390SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205390SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215390SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225390SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235390SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245390SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255390SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265390SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275390SN/A *
285390SN/A * Authors: Gabe Black
295390SN/A */
305390SN/A
315630Sgblack@eecs.umich.edu#ifndef __DEV_X86_I8259_HH__
325630Sgblack@eecs.umich.edu#define __DEV_X86_I8259_HH__
335390SN/A
3414290Sgabeblack@google.com#include "dev/intpin.hh"
355630Sgblack@eecs.umich.edu#include "dev/io_device.hh"
368229Snate@binkert.org#include "enums/X86I8259CascadeMode.hh"
375630Sgblack@eecs.umich.edu#include "params/I8259.hh"
385390SN/A
395390SN/Anamespace X86ISA
405390SN/A{
415390SN/A
4214290Sgabeblack@google.comclass I8259 : public BasicPioDevice
435390SN/A{
445630Sgblack@eecs.umich.edu  protected:
455657Sgblack@eecs.umich.edu    static const int NumLines = 8;
465827Sgblack@eecs.umich.edu    bool pinStates[NumLines];
475657Sgblack@eecs.umich.edu
4814290Sgabeblack@google.com    void init() override;
4914290Sgabeblack@google.com
505630Sgblack@eecs.umich.edu    Tick latency;
5114291Sgabeblack@google.com    std::vector<IntSourcePin<I8259> *> output;
5214291Sgabeblack@google.com    std::vector<IntSinkPin<I8259> *> inputs;
535634Sgblack@eecs.umich.edu    Enums::X86I8259CascadeMode mode;
545657Sgblack@eecs.umich.edu    I8259 * slave;
555630Sgblack@eecs.umich.edu
565631Sgblack@eecs.umich.edu    // Interrupt Request Register
575631Sgblack@eecs.umich.edu    uint8_t IRR;
585631Sgblack@eecs.umich.edu    // In Service Register
595631Sgblack@eecs.umich.edu    uint8_t ISR;
605631Sgblack@eecs.umich.edu    // Interrupt Mask Register
615631Sgblack@eecs.umich.edu    uint8_t IMR;
625631Sgblack@eecs.umich.edu
635656Sgblack@eecs.umich.edu    // The higher order bits of the vector to return
645656Sgblack@eecs.umich.edu    uint8_t vectorOffset;
655656Sgblack@eecs.umich.edu
665632Sgblack@eecs.umich.edu    bool cascadeMode;
675632Sgblack@eecs.umich.edu    // A bit vector of lines with slaves attached, or the slave id, depending
685632Sgblack@eecs.umich.edu    // on if this is a master or slave PIC.
695632Sgblack@eecs.umich.edu    uint8_t cascadeBits;
705632Sgblack@eecs.umich.edu
715631Sgblack@eecs.umich.edu    bool edgeTriggered;
725632Sgblack@eecs.umich.edu    bool readIRR;
735632Sgblack@eecs.umich.edu
745632Sgblack@eecs.umich.edu    // State machine information for reading in initialization control words.
755631Sgblack@eecs.umich.edu    bool expectICW4;
765631Sgblack@eecs.umich.edu    int initControlWord;
775631Sgblack@eecs.umich.edu
785688Sgblack@eecs.umich.edu    // Whether or not the PIC is in auto EOI mode.
795688Sgblack@eecs.umich.edu    bool autoEOI;
805688Sgblack@eecs.umich.edu
815686Sgblack@eecs.umich.edu    void requestInterrupt(int line);
825686Sgblack@eecs.umich.edu    void handleEOI(int line);
835686Sgblack@eecs.umich.edu
845390SN/A  public:
855630Sgblack@eecs.umich.edu    typedef I8259Params Params;
865390SN/A
875630Sgblack@eecs.umich.edu    const Params *
885630Sgblack@eecs.umich.edu    params() const
895630Sgblack@eecs.umich.edu    {
905630Sgblack@eecs.umich.edu        return dynamic_cast<const Params *>(_params);
915630Sgblack@eecs.umich.edu    }
925630Sgblack@eecs.umich.edu
935657Sgblack@eecs.umich.edu    I8259(Params * p);
945657Sgblack@eecs.umich.edu
9514290Sgabeblack@google.com    Port &
9614290Sgabeblack@google.com    getPort(const std::string &if_name, PortID idx=InvalidPortID) override
9714290Sgabeblack@google.com    {
9814290Sgabeblack@google.com        if (if_name == "inputs")
9914290Sgabeblack@google.com            return *inputs.at(idx);
10014290Sgabeblack@google.com        else if (if_name == "output")
10114290Sgabeblack@google.com            return *output.at(idx);
10214290Sgabeblack@google.com        else
10314290Sgabeblack@google.com            return BasicPioDevice::getPort(if_name, idx);
10414290Sgabeblack@google.com    }
10514290Sgabeblack@google.com
10611175Sandreas.hansson@arm.com    Tick read(PacketPtr pkt) override;
10711175Sandreas.hansson@arm.com    Tick write(PacketPtr pkt) override;
1085632Sgblack@eecs.umich.edu
1096073Sgblack@eecs.umich.edu    void
1106073Sgblack@eecs.umich.edu    maskAll()
1116073Sgblack@eecs.umich.edu    {
1126073Sgblack@eecs.umich.edu        IMR = 0xFF;
1136073Sgblack@eecs.umich.edu    }
1146073Sgblack@eecs.umich.edu
1156073Sgblack@eecs.umich.edu    void
1166073Sgblack@eecs.umich.edu    unmaskAll()
1176073Sgblack@eecs.umich.edu    {
1186073Sgblack@eecs.umich.edu        IMR = 0x00;
1196073Sgblack@eecs.umich.edu    }
1206073Sgblack@eecs.umich.edu
12114290Sgabeblack@google.com    void signalInterrupt(int line);
12214290Sgabeblack@google.com    void raiseInterruptPin(int number);
12314290Sgabeblack@google.com    void lowerInterruptPin(int number);
1245657Sgblack@eecs.umich.edu    int getVector();
1257903Shestness@cs.utexas.edu
12611168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
12711168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
1285390SN/A};
1295390SN/A
1307811Ssteve.reinhardt@amd.com} // namespace X86ISA
1315390SN/A
1325630Sgblack@eecs.umich.edu#endif //__DEV_X86_I8259_HH__
133