cmos.hh revision 14291:722551795497
1/*
2 * Copyright (c) 2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 */
30
31#ifndef __DEV_X86_CMOS_HH__
32#define __DEV_X86_CMOS_HH__
33
34#include "dev/intpin.hh"
35#include "dev/io_device.hh"
36#include "dev/mc146818.hh"
37#include "params/Cmos.hh"
38
39namespace X86ISA
40{
41
42class Cmos : public BasicPioDevice
43{
44  protected:
45    Tick latency;
46
47    uint8_t address;
48
49    static const int numRegs = 128;
50
51    uint8_t regs[numRegs];
52
53    uint8_t readRegister(uint8_t reg);
54    void writeRegister(uint8_t reg, uint8_t val);
55
56    class X86RTC : public MC146818
57    {
58      public:
59        std::vector<IntSourcePin<X86RTC> *> intPin;
60
61        X86RTC(EventManager *em, const std::string &n, const struct tm time,
62                bool bcd, Tick frequency, int int_pin_count) :
63            MC146818(em, n, time, bcd, frequency)
64        {
65            for (int i = 0; i < int_pin_count; i++) {
66                intPin.push_back(new IntSourcePin<X86RTC>(
67                            csprintf("%s.int_pin[%d]", n, i), i, this));
68            }
69        }
70      protected:
71        void handleEvent();
72    } rtc;
73
74  public:
75    typedef CmosParams Params;
76
77    Cmos(const Params *p) : BasicPioDevice(p, 2), latency(p->pio_latency),
78        rtc(this, name() + ".rtc", p->time, true, ULL(5000000000),
79                p->port_int_pin_connection_count)
80    {
81        memset(regs, 0, numRegs * sizeof(uint8_t));
82        address = 0;
83    }
84
85    Port &
86    getPort(const std::string &if_name, PortID idx=InvalidPortID) override
87    {
88        if (if_name == "int_pin")
89            return *rtc.intPin.at(idx);
90        else
91            return BasicPioDevice::getPort(if_name, idx);
92    }
93
94    Tick read(PacketPtr pkt) override;
95
96    Tick write(PacketPtr pkt) override;
97
98    void startup() override;
99
100    void serialize(CheckpointOut &cp) const override;
101    void unserialize(CheckpointIn &cp) override;
102};
103
104} // namespace X86ISA
105
106#endif //__DEV_X86_CMOS_HH__
107