gem5  v22.1.0.0
intpin.hh
Go to the documentation of this file.
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 namespace gem5
34 {
35 
36 class IntSourcePinBase;
37 
38 class IntSinkPinBase : public Port
39 {
40  protected:
42 
44 
45  int _number = 0;
46  bool _state = false;
47 
48  IntSinkPinBase(const std::string &_name, PortID _id, int num) :
49  Port(_name, _id), _number(num)
50  {}
51 
52  virtual void raiseOnDevice() = 0;
53  virtual void lowerOnDevice() = 0;
54 
55  void
56  raise()
57  {
58  _state = true;
59  raiseOnDevice();
60  }
61 
62  void
64  {
65  _state = false;
66  lowerOnDevice();
67  }
68 
69  public:
70  int number() { return _number; }
71  bool state() { return _state; }
72 
73  void bind(Port &peer) override;
74  void unbind() override;
75 };
76 
77 template <class Device>
78 class IntSinkPin : public IntSinkPinBase
79 {
80  private:
81  Device *device = nullptr;
82 
83  void raiseOnDevice() override { device->raiseInterruptPin(number()); }
84  void lowerOnDevice() override { device->lowerInterruptPin(number()); }
85 
86  public:
87  IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num) :
88  IntSinkPinBase(_name, _id, num), device(dev) {}
89  IntSinkPin(const std::string &_name, PortID _id, Device *dev) :
90  IntSinkPin(_name, _id, dev, _id) {}
91 };
92 
93 class IntSourcePinBase : public Port
94 {
95  private:
96  IntSinkPinBase *sink = nullptr;
97 
98  public:
99  IntSourcePinBase(const std::string &_name, PortID _id):
100  Port(_name, _id)
101  {}
102 
103  void raise() { sink->raise(); }
104  void lower() { sink->lower(); }
105 
106  void bind(Port &peer) override;
107  void unbind() override;
108 };
109 
110 template <class Device>
112 {
113  public:
114  IntSourcePin(const std::string &_name, PortID _id, Device *owner) :
115  IntSourcePinBase(_name, _id)
116  {}
117 };
118 
119 } // namespace gem5
120 
121 #endif //__DEV_INTPIN_HH__
void unbind() override
Dettach from a peer port.
Definition: intpin.cc:45
virtual void lowerOnDevice()=0
virtual void raiseOnDevice()=0
IntSourcePinBase * source
Definition: intpin.hh:43
void bind(Port &peer) override
Attach to a peer port.
Definition: intpin.cc:36
IntSinkPinBase(const std::string &_name, PortID _id, int num)
Definition: intpin.hh:48
friend IntSourcePinBase
Definition: intpin.hh:41
IntSinkPin(const std::string &_name, PortID _id, Device *dev)
Definition: intpin.hh:89
IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num)
Definition: intpin.hh:87
void raiseOnDevice() override
Definition: intpin.hh:83
Device * device
Definition: intpin.hh:81
void lowerOnDevice() override
Definition: intpin.hh:84
void unbind() override
Dettach from a peer port.
Definition: intpin.cc:61
IntSourcePinBase(const std::string &_name, PortID _id)
Definition: intpin.hh:99
void bind(Port &peer) override
Attach to a peer port.
Definition: intpin.cc:52
IntSinkPinBase * sink
Definition: intpin.hh:96
IntSourcePin(const std::string &_name, PortID _id, Device *owner)
Definition: intpin.hh:114
Ports are used to interface objects to each other.
Definition: port.hh:62
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
Port Object Declaration.

Generated on Wed Dec 21 2022 10:22:33 for gem5 by doxygen 1.9.1