intdev.hh revision 5827:ac2c268bf4f1
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_INTDEV_HH__
32#define __DEV_X86_INTDEV_HH__
33
34#include <assert.h>
35#include <string>
36
37#include "arch/x86/x86_traits.hh"
38#include "mem/mem_object.hh"
39#include "mem/mport.hh"
40#include "sim/sim_object.hh"
41#include "params/X86IntSourcePin.hh"
42#include "params/X86IntSinkPin.hh"
43#include "params/X86IntLine.hh"
44
45namespace X86ISA {
46
47class IntDev
48{
49  protected:
50    class IntPort : public MessagePort
51    {
52        IntDev * device;
53        Tick latency;
54        Addr intAddr;
55      public:
56        IntPort(const std::string &_name, MemObject * _parent,
57                IntDev *dev, Tick _latency) :
58            MessagePort(_name, _parent), device(dev), latency(_latency)
59        {
60        }
61
62        void getDeviceAddressRanges(AddrRangeList &resp, bool &snoop)
63        {
64            snoop = false;
65            device->getIntAddrRange(resp);
66        }
67
68        Tick recvMessage(PacketPtr pkt)
69        {
70            return device->recvMessage(pkt);
71        }
72
73        void recvStatusChange(Status status)
74        {
75            if (status == RangeChange) {
76                sendStatusChange(Port::RangeChange);
77            }
78        }
79
80    };
81
82    IntPort * intPort;
83
84  public:
85    IntDev(MemObject * parent, Tick latency = 0)
86    {
87        if (parent != NULL) {
88            intPort = new IntPort(parent->name() + ".int_port",
89                    parent, this, latency);
90        } else {
91            intPort = NULL;
92        }
93    }
94
95    virtual ~IntDev()
96    {}
97
98    virtual void
99    signalInterrupt(int line)
100    {
101        panic("signalInterrupt not implemented.\n");
102    }
103
104    virtual void
105    raiseInterruptPin(int number)
106    {
107        panic("raiseInterruptPin not implemented.\n");
108    }
109
110    virtual void
111    lowerInterruptPin(int number)
112    {
113        panic("lowerInterruptPin not implemented.\n");
114    }
115
116    virtual Tick
117    recvMessage(PacketPtr pkt)
118    {
119        panic("recvMessage not implemented.\n");
120        return 0;
121    }
122
123    virtual void
124    getIntAddrRange(AddrRangeList &range_list)
125    {
126        panic("intAddrRange not implemented.\n");
127    }
128};
129
130class IntSinkPin : public SimObject
131{
132  public:
133    IntDev * device;
134    int number;
135
136    typedef X86IntSinkPinParams Params;
137
138    const Params *
139    params() const
140    {
141        return dynamic_cast<const Params *>(_params);
142    }
143
144    IntSinkPin(Params *p) : SimObject(p),
145            device(dynamic_cast<IntDev *>(p->device)), number(p->number)
146    {
147        assert(device);
148    }
149};
150
151class IntSourcePin : public SimObject
152{
153  protected:
154    std::vector<IntSinkPin *> sinks;
155
156  public:
157    typedef X86IntSourcePinParams Params;
158
159    const Params *
160    params() const
161    {
162        return dynamic_cast<const Params *>(_params);
163    }
164
165    void
166    addSink(IntSinkPin *sink)
167    {
168        sinks.push_back(sink);
169    }
170
171    void
172    raise()
173    {
174        for (int i = 0; i < sinks.size(); i++) {
175            const IntSinkPin &pin = *sinks[i];
176            pin.device->raiseInterruptPin(pin.number);
177        }
178    }
179
180    void
181    lower()
182    {
183        for (int i = 0; i < sinks.size(); i++) {
184            const IntSinkPin &pin = *sinks[i];
185            pin.device->lowerInterruptPin(pin.number);
186        }
187    }
188
189    IntSourcePin(Params *p) : SimObject(p)
190    {}
191};
192
193class IntLine : public SimObject
194{
195  protected:
196    IntSourcePin *source;
197    IntSinkPin *sink;
198
199  public:
200    typedef X86IntLineParams Params;
201
202    const Params *
203    params() const
204    {
205        return dynamic_cast<const Params *>(_params);
206    }
207
208    IntLine(Params *p) : SimObject(p), source(p->source), sink(p->sink)
209    {
210        source->addSink(sink);
211    }
212};
213
214}; // namespace X86ISA
215
216#endif //__DEV_X86_INTDEV_HH__
217