i8254.hh revision 10905:a6ca6831e775
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_I8254_HH__
32#define __DEV_X86_I8254_HH__
33
34#include "dev/intel_8254_timer.hh"
35#include "dev/io_device.hh"
36#include "params/I8254.hh"
37
38namespace X86ISA
39{
40
41class IntSourcePin;
42
43class I8254 : public BasicPioDevice
44{
45  protected:
46    Tick latency;
47    class X86Intel8254Timer : public Intel8254Timer
48    {
49      protected:
50        I8254 * parent;
51
52        void
53        counterInterrupt(unsigned int num)
54        {
55            parent->counterInterrupt(num);
56        }
57
58      public:
59        X86Intel8254Timer(const std::string &name, I8254 * _parent) :
60            Intel8254Timer(_parent, name), parent(_parent)
61        {}
62    };
63
64
65    X86Intel8254Timer pit;
66
67    IntSourcePin *intPin;
68
69    void counterInterrupt(unsigned int num);
70
71  public:
72    typedef I8254Params Params;
73
74    const Params *
75    params() const
76    {
77        return dynamic_cast<const Params *>(_params);
78    }
79
80    I8254(Params *p) : BasicPioDevice(p, 4), latency(p->pio_latency),
81            pit(p->name, this), intPin(p->int_pin)
82    {
83    }
84    Tick read(PacketPtr pkt);
85
86    Tick write(PacketPtr pkt);
87
88    bool
89    outputHigh(unsigned int num)
90    {
91        return pit.outputHigh(num);
92    }
93
94    uint8_t
95    readCounter(unsigned int num)
96    {
97        return pit.readCounter(num);
98    }
99
100    void
101    writeCounter(unsigned int num, const uint8_t data)
102    {
103        pit.writeCounter(num, data);
104    }
105
106    void
107    writeControl(uint8_t val)
108    {
109        pit.writeControl(val);
110    }
111
112    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
113    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
114
115    virtual void startup();
116
117};
118
119} // namespace X86ISA
120
121#endif //__DEV_X86_SOUTH_BRIDGE_I8254_HH__
122