15390SN/A/* 25452SN/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 315629Sgblack@eecs.umich.edu#ifndef __DEV_X86_CMOS_HH__ 325629Sgblack@eecs.umich.edu#define __DEV_X86_CMOS_HH__ 335390SN/A 3414290Sgabeblack@google.com#include "dev/intpin.hh" 355629Sgblack@eecs.umich.edu#include "dev/io_device.hh" 365393SN/A#include "dev/mc146818.hh" 375629Sgblack@eecs.umich.edu#include "params/Cmos.hh" 385390SN/A 395390SN/Anamespace X86ISA 405390SN/A{ 415390SN/A 425629Sgblack@eecs.umich.educlass Cmos : public BasicPioDevice 435390SN/A{ 445390SN/A protected: 455629Sgblack@eecs.umich.edu Tick latency; 465629Sgblack@eecs.umich.edu 475390SN/A uint8_t address; 485390SN/A 495390SN/A static const int numRegs = 128; 505390SN/A 515390SN/A uint8_t regs[numRegs]; 525390SN/A 535390SN/A uint8_t readRegister(uint8_t reg); 545390SN/A void writeRegister(uint8_t reg, uint8_t val); 555390SN/A 565393SN/A class X86RTC : public MC146818 575393SN/A { 585393SN/A public: 5914291Sgabeblack@google.com std::vector<IntSourcePin<X86RTC> *> intPin; 6014290Sgabeblack@google.com 615611SN/A X86RTC(EventManager *em, const std::string &n, const struct tm time, 6214290Sgabeblack@google.com bool bcd, Tick frequency, int int_pin_count) : 6314290Sgabeblack@google.com MC146818(em, n, time, bcd, frequency) 645393SN/A { 6514290Sgabeblack@google.com for (int i = 0; i < int_pin_count; i++) { 6614291Sgabeblack@google.com intPin.push_back(new IntSourcePin<X86RTC>( 6714290Sgabeblack@google.com csprintf("%s.int_pin[%d]", n, i), i, this)); 6814290Sgabeblack@google.com } 695393SN/A } 705393SN/A protected: 715632Sgblack@eecs.umich.edu void handleEvent(); 725393SN/A } rtc; 735393SN/A 745390SN/A public: 755629Sgblack@eecs.umich.edu typedef CmosParams Params; 765390SN/A 779808Sstever@gmail.com Cmos(const Params *p) : BasicPioDevice(p, 2), latency(p->pio_latency), 7814290Sgabeblack@google.com rtc(this, name() + ".rtc", p->time, true, ULL(5000000000), 7914290Sgabeblack@google.com p->port_int_pin_connection_count) 805390SN/A { 815390SN/A memset(regs, 0, numRegs * sizeof(uint8_t)); 825390SN/A address = 0; 835390SN/A } 845390SN/A 8514290Sgabeblack@google.com Port & 8614290Sgabeblack@google.com getPort(const std::string &if_name, PortID idx=InvalidPortID) override 8714290Sgabeblack@google.com { 8814290Sgabeblack@google.com if (if_name == "int_pin") 8914290Sgabeblack@google.com return *rtc.intPin.at(idx); 9014290Sgabeblack@google.com else 9114290Sgabeblack@google.com return BasicPioDevice::getPort(if_name, idx); 9214290Sgabeblack@google.com } 9314290Sgabeblack@google.com 9411175Sandreas.hansson@arm.com Tick read(PacketPtr pkt) override; 955390SN/A 9611175Sandreas.hansson@arm.com Tick write(PacketPtr pkt) override; 977903Shestness@cs.utexas.edu 9811175Sandreas.hansson@arm.com void startup() override; 997903Shestness@cs.utexas.edu 10011168Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 10111168Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override; 1025390SN/A}; 1035390SN/A 1047811Ssteve.reinhardt@amd.com} // namespace X86ISA 1055390SN/A 1065629Sgblack@eecs.umich.edu#endif //__DEV_X86_CMOS_HH__ 107