intdev.hh revision 5651:7f0c8006c3d7
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/X86IntPin.hh"
42
43namespace X86ISA {
44
45class IntDev
46{
47  protected:
48    class IntPort : public MessagePort
49    {
50        IntDev * device;
51        Tick latency;
52        Addr intAddr;
53      public:
54        IntPort(const std::string &_name, MemObject * _parent,
55                IntDev *dev, Tick _latency) :
56            MessagePort(_name, _parent), device(dev), latency(_latency)
57        {
58        }
59
60        void getDeviceAddressRanges(AddrRangeList &resp, bool &snoop)
61        {
62            snoop = false;
63            device->getIntAddrRange(resp);
64        }
65
66        Tick recvMessage(PacketPtr pkt)
67        {
68            return device->recvMessage(pkt);
69        }
70
71        void recvStatusChange(Status status)
72        {
73            if (status == RangeChange) {
74                sendStatusChange(Port::RangeChange);
75            }
76        }
77
78    };
79
80    IntPort * intPort;
81
82  public:
83    IntDev(MemObject * parent, Tick latency = 0)
84    {
85        if (parent != NULL) {
86            intPort = new IntPort(parent->name() + ".int_port",
87                    parent, this, latency);
88        } else {
89            intPort = NULL;
90        }
91    }
92
93    virtual ~IntDev()
94    {}
95
96    virtual void
97    signalInterrupt(int line)
98    {
99        panic("signalInterrupt not implemented.\n");
100    }
101
102    virtual Tick
103    recvMessage(PacketPtr pkt)
104    {
105        panic("recvMessage not implemented.\n");
106        return 0;
107    }
108
109    virtual void
110    getIntAddrRange(AddrRangeList &range_list)
111    {
112        panic("intAddrRange not implemented.\n");
113    }
114};
115
116class IntPin : public SimObject
117{
118  protected:
119    IntDev * device;
120    int line;
121
122  public:
123    typedef X86IntPinParams Params;
124
125    const Params *
126    params() const
127    {
128        return dynamic_cast<const Params *>(_params);
129    }
130
131    IntPin(Params *p) : SimObject(p),
132            device(dynamic_cast<IntDev *>(p->device)), line(p->line)
133    {
134        assert(device);
135    }
136
137    void
138    signalInterrupt()
139    {
140        device->signalInterrupt(line);
141    }
142};
143
144}; // namespace X86ISA
145
146#endif //__DEV_X86_INTDEV_HH__
147