gem5  v22.1.0.0
example.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 
29 
30 #include <algorithm>
31 
32 #include "base/logging.hh"
33 
34 namespace gem5
35 {
36 namespace fastmodel
37 {
38 
39 ResetControllerExample::CorePins::CorePins(const std::string &module_name)
40  : reset(module_name + ".reset", 0, this),
41  halt(module_name + ".halt", 0, this)
42 {}
43 
45  const std::string &module_name, Iris::BaseCPU *c, CorePins *p)
46  : RegisterBankLE(module_name, 0), cpu(c), pins(p),
47  nsrvbar(module_name + ".nsrvbar"),
48  rvbar(module_name + ".rvbar"),
49  reset(module_name + ".reset"),
50  halt(module_name + ".halt")
51 {
52  panic_if(cpu == nullptr, "ResetControllerExample needs a target cpu.");
53  nsrvbar.writer(
54  [this] (auto &reg, auto val)
55  {
56  cpu->setResetAddr(val, false);
57  });
58  rvbar.writer(
59  [this] (auto &reg, auto val)
60  {
61  cpu->setResetAddr(val, true);
62  });
63  reset.writer(
64  [this] (auto &reg, auto val)
65  {
67  "%s is not connected.", pins->reset.name());
68 
69  if (val)
70  pins->reset.raise();
71  else
72  pins->reset.lower();
73  });
74  halt.writer(
75  [this] (auto &reg, auto val)
76  {
78  "%s is not connected.", pins->halt.name());
79 
80  if (val)
81  pins->halt.raise();
82  else
83  pins->halt.lower();
84  });
85 
86  addRegisters({
87  nsrvbar,
88  rvbar,
89  reset,
90  halt,
91  });
92 }
93 
95  : BasicPioDevice(p, 0x20),
96  pins(p.name + ".pins"),
97  registers(p.name + ".registers", p.cpu, &pins)
98 {}
99 
100 Tick
102 {
103  pkt->makeResponse();
104  auto data = pkt->getPtr<uint8_t>();
105  auto size = pkt->getSize();
106  std::fill(data, data + size, 0);
107  return pioDelay;
108 }
109 
110 Tick
112 {
113  pkt->makeResponse();
114  size_t size = pkt->getSize();
115  if (size != 4 && size != 8) {
116  pkt->setBadAddress();
117  } else {
118  auto addr = pkt->getAddr() - pioAddr;
119  registers.write(addr, pkt->getPtr<void>(), size);
120  }
121  return pioDelay;
122 }
123 
124 Port &
125 ResetControllerExample::getPort(const std::string &if_name, PortID idx)
126 {
127  if (if_name == "reset")
128  return pins.reset;
129  else if (if_name == "halt")
130  return pins.halt;
131 
132  return BasicPioDevice::getPort(if_name, idx);
133 }
134 
135 } // namespace fastmodel
136 } // namespace gem5
const char data[]
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:157
virtual void setResetAddr(Addr addr, bool secure=false)
Definition: cpu.hh:91
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
void setBadAddress()
Definition: packet.hh:784
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1212
Addr getAddr() const
Definition: packet.hh:805
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1059
unsigned getSize() const
Definition: packet.hh:815
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: io_device.cc:67
Ports are used to interface objects to each other.
Definition: port.hh:62
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:133
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:111
void addRegisters(std::initializer_list< std::reference_wrapper< RegisterBase >> regs)
Definition: reg_bank.hh:809
virtual void write(Addr addr, const void *buf, Addr bytes)
Definition: reg_bank.hh:884
Registers(const std::string &, Iris::BaseCPU *, CorePins *)
Definition: example.cc:44
Port & getPort(const std::string &, PortID=InvalidPortID) override
Get a port with a given name and index.
Definition: example.cc:125
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: example.cc:111
FastModelResetControllerExampleParams Params
Definition: example.hh:77
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: example.cc:101
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 26 > halt
Definition: dt_constants.hh:47
Bitfield< 2 > c
Definition: pagetable.hh:63
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
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
uint64_t Tick
Tick count type.
Definition: types.hh:58

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