15390SN/A/*
25443SN/A * Copyright (c) 2008 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
3111793Sbrandon.potter@amd.com#include "dev/x86/i8254.hh"
3211793Sbrandon.potter@amd.com
338232Snate@binkert.org#include "debug/I8254.hh"
345642Sgblack@eecs.umich.edu#include "dev/x86/intdev.hh"
355636Sgblack@eecs.umich.edu#include "mem/packet.hh"
365390SN/A#include "mem/packet_access.hh"
375390SN/A
385642Sgblack@eecs.umich.eduvoid
395642Sgblack@eecs.umich.eduX86ISA::I8254::counterInterrupt(unsigned int num)
405642Sgblack@eecs.umich.edu{
415642Sgblack@eecs.umich.edu    DPRINTF(I8254, "Interrupt from counter %d.\n", num);
425827Sgblack@eecs.umich.edu    if (num == 0) {
4314290Sgabeblack@google.com        for (auto *wire: intPin) {
4414290Sgabeblack@google.com            wire->raise();
4514290Sgabeblack@google.com            //XXX This is a hack.
4614290Sgabeblack@google.com            wire->lower();
4714290Sgabeblack@google.com        }
485827Sgblack@eecs.umich.edu    }
495642Sgblack@eecs.umich.edu}
505642Sgblack@eecs.umich.edu
515390SN/ATick
525390SN/AX86ISA::I8254::read(PacketPtr pkt)
535390SN/A{
545390SN/A    assert(pkt->getSize() == 1);
555636Sgblack@eecs.umich.edu    Addr offset = pkt->getAddr() - pioAddr;
565636Sgblack@eecs.umich.edu    if (offset < 3) {
5713229Sgabeblack@google.com        pkt->setLE(pit.readCounter(offset));
585636Sgblack@eecs.umich.edu    } else if (offset == 3) {
5913229Sgabeblack@google.com        pkt->setLE(uint8_t(-1));
605636Sgblack@eecs.umich.edu    } else {
615390SN/A        panic("Read from undefined i8254 register.\n");
625390SN/A    }
635898Sgblack@eecs.umich.edu    pkt->makeAtomicResponse();
645443SN/A    return latency;
655390SN/A}
665390SN/A
675390SN/ATick
685390SN/AX86ISA::I8254::write(PacketPtr pkt)
695390SN/A{
705390SN/A    assert(pkt->getSize() == 1);
715636Sgblack@eecs.umich.edu    Addr offset = pkt->getAddr() - pioAddr;
725636Sgblack@eecs.umich.edu    if (offset < 3) {
7313229Sgabeblack@google.com        pit.writeCounter(offset, pkt->getLE<uint8_t>());
745636Sgblack@eecs.umich.edu    } else if (offset == 3) {
7513229Sgabeblack@google.com        pit.writeControl(pkt->getLE<uint8_t>());
765636Sgblack@eecs.umich.edu    } else {
775390SN/A        panic("Write to undefined i8254 register.\n");
785390SN/A    }
795898Sgblack@eecs.umich.edu    pkt->makeAtomicResponse();
805443SN/A    return latency;
815390SN/A}
825636Sgblack@eecs.umich.edu
837903Shestness@cs.utexas.eduvoid
8410905Sandreas.sandberg@arm.comX86ISA::I8254::serialize(CheckpointOut &cp) const
857903Shestness@cs.utexas.edu{
8610905Sandreas.sandberg@arm.com    pit.serialize("pit", cp);
877903Shestness@cs.utexas.edu}
887903Shestness@cs.utexas.edu
897903Shestness@cs.utexas.eduvoid
9010905Sandreas.sandberg@arm.comX86ISA::I8254::unserialize(CheckpointIn &cp)
917903Shestness@cs.utexas.edu{
9210905Sandreas.sandberg@arm.com    pit.unserialize("pit", cp);
937903Shestness@cs.utexas.edu}
947903Shestness@cs.utexas.edu
9510642Scdirik@micron.comvoid
9610642Scdirik@micron.comX86ISA::I8254::startup()
9710642Scdirik@micron.com{
9810642Scdirik@micron.com    pit.startup();
9910642Scdirik@micron.com}
10010642Scdirik@micron.com
1015636Sgblack@eecs.umich.eduX86ISA::I8254 *
1025636Sgblack@eecs.umich.eduI8254Params::create()
1035636Sgblack@eecs.umich.edu{
1045636Sgblack@eecs.umich.edu    return new X86ISA::I8254(this);
1055636Sgblack@eecs.umich.edu}
106