dev-arm: Add VRAM to VExpress_GEM5_Base
[gem5.git] / src / dev / intpin.hh
1 /*
2 * Copyright 2019 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef __DEV_INTPIN_HH__
29 #define __DEV_INTPIN_HH__
30
31 #include "sim/port.hh"
32
33 class IntSourcePinBase;
34
35 class IntSinkPinBase : public Port
36 {
37 protected:
38 friend IntSourcePinBase;
39
40 IntSourcePinBase *source = nullptr;
41
42 int _number = 0;
43 bool _state = false;
44
45 IntSinkPinBase(const std::string &_name, PortID _id, int num) :
46 Port(_name, _id), _number(num)
47 {}
48
49 virtual void raiseOnDevice() = 0;
50 virtual void lowerOnDevice() = 0;
51
52 void
53 raise()
54 {
55 _state = true;
56 raiseOnDevice();
57 }
58
59 void
60 lower()
61 {
62 _state = false;
63 lowerOnDevice();
64 }
65
66 public:
67 int number() { return _number; }
68 bool state() { return _state; }
69
70 void bind(Port &peer) override;
71 void unbind() override;
72 };
73
74 template <class Device>
75 class IntSinkPin : public IntSinkPinBase
76 {
77 private:
78 Device *device = nullptr;
79
80 void raiseOnDevice() override { device->raiseInterruptPin(number()); }
81 void lowerOnDevice() override { device->lowerInterruptPin(number()); }
82
83 public:
84 IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num) :
85 IntSinkPinBase(_name, _id, num), device(dev) {}
86 IntSinkPin(const std::string &_name, PortID _id, Device *dev) :
87 IntSinkPin(_name, _id, dev, _id) {}
88 };
89
90 class IntSourcePinBase : public Port
91 {
92 private:
93 IntSinkPinBase *sink = nullptr;
94 bool _state = false;
95
96 public:
97 IntSourcePinBase(const std::string &_name, PortID _id, bool def_state) :
98 Port(_name, _id), _state(def_state)
99 {}
100
101 void raise() { sink->raise(); }
102 void lower() { sink->lower(); }
103
104 void bind(Port &peer) override;
105 void unbind() override;
106 };
107
108 template <class Device>
109 class IntSourcePin : public IntSourcePinBase
110 {
111 public:
112 IntSourcePin(const std::string &_name, PortID _id, Device *owner,
113 bool def_state=false) :
114 IntSourcePinBase(_name, _id, def_state)
115 {}
116 };
117
118 #endif //__DEV_INTPIN_HH__