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 3111793Sbrandon.potter@amd.com#include "dev/x86/cmos.hh" 3211793Sbrandon.potter@amd.com 338232Snate@binkert.org#include "debug/CMOS.hh" 345634Sgblack@eecs.umich.edu#include "dev/x86/intdev.hh" 355390SN/A#include "mem/packet_access.hh" 365390SN/A 375632Sgblack@eecs.umich.eduvoid 385632Sgblack@eecs.umich.eduX86ISA::Cmos::X86RTC::handleEvent() 395632Sgblack@eecs.umich.edu{ 4014290Sgabeblack@google.com for (auto *wire: intPin) { 4114290Sgabeblack@google.com wire->raise(); 4214290Sgabeblack@google.com //XXX This is a hack. 4314290Sgabeblack@google.com wire->lower(); 4414290Sgabeblack@google.com } 455632Sgblack@eecs.umich.edu} 465632Sgblack@eecs.umich.edu 475390SN/ATick 485390SN/AX86ISA::Cmos::read(PacketPtr pkt) 495390SN/A{ 505390SN/A assert(pkt->getSize() == 1); 515629Sgblack@eecs.umich.edu switch(pkt->getAddr() - pioAddr) 525390SN/A { 535390SN/A case 0x0: 5413229Sgabeblack@google.com pkt->setLE(address); 555390SN/A break; 565390SN/A case 0x1: 5713229Sgabeblack@google.com pkt->setLE(readRegister(address)); 585390SN/A break; 595390SN/A default: 605390SN/A panic("Read from undefined CMOS port.\n"); 615390SN/A } 625898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 635390SN/A return latency; 645390SN/A} 655390SN/A 665390SN/ATick 675390SN/AX86ISA::Cmos::write(PacketPtr pkt) 685390SN/A{ 695390SN/A assert(pkt->getSize() == 1); 705629Sgblack@eecs.umich.edu switch(pkt->getAddr() - pioAddr) 715390SN/A { 725390SN/A case 0x0: 7313229Sgabeblack@google.com address = pkt->getLE<uint8_t>(); 745390SN/A break; 755390SN/A case 0x1: 7613229Sgabeblack@google.com writeRegister(address, pkt->getLE<uint8_t>()); 775390SN/A break; 785390SN/A default: 795390SN/A panic("Write to undefined CMOS port.\n"); 805390SN/A } 815898Sgblack@eecs.umich.edu pkt->makeAtomicResponse(); 825390SN/A return latency; 835390SN/A} 845390SN/A 855390SN/Auint8_t 865390SN/AX86ISA::Cmos::readRegister(uint8_t reg) 875390SN/A{ 885390SN/A assert(reg < numRegs); 895629Sgblack@eecs.umich.edu uint8_t val; 905393SN/A if (reg <= 0xD) { 915629Sgblack@eecs.umich.edu val = rtc.readData(reg); 925629Sgblack@eecs.umich.edu DPRINTF(CMOS, 937799Sgblack@eecs.umich.edu "Reading CMOS RTC reg %x as %x.\n", reg, val); 945393SN/A } else { 955629Sgblack@eecs.umich.edu val = regs[reg]; 965629Sgblack@eecs.umich.edu DPRINTF(CMOS, 977799Sgblack@eecs.umich.edu "Reading non-volitile CMOS address %x as %x.\n", reg, val); 985390SN/A } 995629Sgblack@eecs.umich.edu return val; 1005390SN/A} 1015390SN/A 1025390SN/Avoid 1035390SN/AX86ISA::Cmos::writeRegister(uint8_t reg, uint8_t val) 1045390SN/A{ 1055390SN/A assert(reg < numRegs); 1065393SN/A if (reg <= 0xD) { 1075629Sgblack@eecs.umich.edu DPRINTF(CMOS, "Writing CMOS RTC reg %x with %x.\n", 1087799Sgblack@eecs.umich.edu reg, val); 1095393SN/A rtc.writeData(reg, val); 1105393SN/A } else { 1115629Sgblack@eecs.umich.edu DPRINTF(CMOS, "Writing non-volitile CMOS address %x with %x.\n", 1127799Sgblack@eecs.umich.edu reg, val); 1135629Sgblack@eecs.umich.edu regs[reg] = val; 1145390SN/A } 1155390SN/A} 1165629Sgblack@eecs.umich.edu 1177903Shestness@cs.utexas.eduvoid 11810631Scdirik@micron.comX86ISA::Cmos::startup() 11910631Scdirik@micron.com{ 12010631Scdirik@micron.com rtc.startup(); 12110631Scdirik@micron.com} 12210631Scdirik@micron.com 12310631Scdirik@micron.comvoid 12410905Sandreas.sandberg@arm.comX86ISA::Cmos::serialize(CheckpointOut &cp) const 1257903Shestness@cs.utexas.edu{ 1267903Shestness@cs.utexas.edu SERIALIZE_SCALAR(address); 1277903Shestness@cs.utexas.edu SERIALIZE_ARRAY(regs, numRegs); 1287903Shestness@cs.utexas.edu 1297903Shestness@cs.utexas.edu // Serialize the timer 13010905Sandreas.sandberg@arm.com rtc.serialize("rtc", cp); 1317903Shestness@cs.utexas.edu} 1327903Shestness@cs.utexas.edu 1337903Shestness@cs.utexas.eduvoid 13410905Sandreas.sandberg@arm.comX86ISA::Cmos::unserialize(CheckpointIn &cp) 1357903Shestness@cs.utexas.edu{ 1367903Shestness@cs.utexas.edu UNSERIALIZE_SCALAR(address); 1377903Shestness@cs.utexas.edu UNSERIALIZE_ARRAY(regs, numRegs); 1387903Shestness@cs.utexas.edu 1397903Shestness@cs.utexas.edu // Serialize the timer 14010905Sandreas.sandberg@arm.com rtc.unserialize("rtc", cp); 1417903Shestness@cs.utexas.edu} 1427903Shestness@cs.utexas.edu 1435629Sgblack@eecs.umich.eduX86ISA::Cmos * 1445629Sgblack@eecs.umich.eduCmosParams::create() 1455629Sgblack@eecs.umich.edu{ 1465629Sgblack@eecs.umich.edu return new X86ISA::Cmos(this); 1475629Sgblack@eecs.umich.edu} 148