gem5  v22.1.0.0
lupio_ipi.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 The Regents of the University of California
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 
29 #include "dev/lupio/lupio_ipi.hh"
30 
31 #include "cpu/base.hh"
32 #include "debug/LupioIPI.hh"
33 #include "mem/packet_access.hh"
34 #include "params/LupioIPI.hh"
35 
36 namespace gem5
37 {
38 
39 LupioIPI::LupioIPI(const Params &params) :
40  BasicPioDevice(params, params.pio_size),
41  system(params.system),
42  intType(params.int_type),
43  nThread(params.num_threads)
44 {
45  mask.resize(nThread, 0);
46  pending.resize(nThread, 0);
47 
48  DPRINTF(LupioIPI, "LupioIPI initalized--number of CPUs: %d\n", nThread);
49 }
50 
51 void
53 {
54  for (int cpu = 0; cpu < nThread; cpu++) {
55  auto tc = system->threads[cpu];
56 
57  if (mask[cpu] & pending[cpu]) {
58  tc->getCpuPtr()->postInterrupt(tc->threadId(), intType, 0);
59  } else {
60  tc->getCpuPtr()->clearInterrupt(tc->threadId(), intType, 0);
61  }
62  }
63 }
64 
65 uint64_t
66 LupioIPI::lupioIPIRead(uint8_t addr, int size)
67 {
68  uint32_t r = 0;
69 
70  int cpu = addr / LUPIO_IPI_MAX;
71  int reg = addr % LUPIO_IPI_MAX;
72 
73  switch (reg) {
74  case LUPIO_IPI_MASK:
75  r = mask[cpu];
76  DPRINTF(LupioIPI, "Read IPI_MASK[%d]: %#x\n", cpu, r);
77  break;
78  case LUPIO_IPI_PEND:
79  r = pending[cpu];
80  DPRINTF(LupioIPI, "Read IPI_PEND[%d]: %#x\n", cpu, r);
81  break;
82 
83  default:
84  panic("Unexpected read to LupioIPI device at address %#llx!",
85  addr);
86  break;
87  }
88 
89  return r;
90 }
91 
92 void
93 LupioIPI::lupioIPIWrite(uint8_t addr, uint64_t val64, int size)
94 {
95  uint32_t val = val64;
96 
97  int cpu = addr / LUPIO_IPI_MAX;
98  int reg = addr % LUPIO_IPI_MAX;
99 
100  switch (reg) {
101  case LUPIO_IPI_MASK:
102  mask[cpu] = val;
103  DPRINTF(LupioIPI, "Write IPI_MASK[%d]: %#x\n", cpu, mask[cpu]);
105  break;
106  case LUPIO_IPI_PEND:
107  pending[cpu] = val;
108  DPRINTF(LupioIPI, "Write IPI_PEND[%d]: %#x\n", cpu, pending[cpu]);
110  break;
111 
112  default:
113  panic("Unexpected write to LupioIPI device at address %#llx!",
114  addr);
115  break;
116  }
117 }
118 
119 Tick
121 {
122  Addr ipi_addr = pkt->getAddr() - pioAddr;
123 
125  "Read request - addr: %#x, size: %#x\n", ipi_addr, pkt->getSize());
126 
127  uint64_t read_val = lupioIPIRead(ipi_addr, pkt->getSize());
128  DPRINTF(LupioIPI, "Packet Read: %#x\n", read_val);
129  pkt->setUintX(read_val, byteOrder);
130  pkt->makeResponse();
131 
132  return pioDelay;
133 }
134 
135 Tick
137 {
138  Addr ipi_addr = pkt->getAddr() - pioAddr;
139 
140  DPRINTF(LupioIPI, "Write register %#x value %#x\n", ipi_addr,
141  pkt->getUintX(byteOrder));
142 
143  lupioIPIWrite(ipi_addr, pkt->getUintX(byteOrder), pkt->getSize());
144  DPRINTF(LupioIPI, "Packet Write Value: %d\n", pkt->getUintX(byteOrder));
145 
146  pkt->makeResponse();
147 
148  return pioDelay;
149 }
150 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
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
LupioIPI: An inter-processor interrupt virtual device.
Definition: lupio_ipi.hh:46
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: lupio_ipi.cc:136
System * system
Definition: lupio_ipi.hh:49
std::vector< uint32_t > pending
Definition: lupio_ipi.hh:68
Tick read(PacketPtr pkt) override
Implement BasicPioDevice virtual functions.
Definition: lupio_ipi.cc:120
std::vector< uint32_t > mask
Set of registers corresponding to each CPU for sending inter-processor interrupts.
Definition: lupio_ipi.hh:67
void lupioIPIWrite(const uint8_t addr, uint64_t val64, int size)
Function to write to the word register of the corresponding CPU and raise the IRQ.
Definition: lupio_ipi.cc:93
LupioIPI(const Params &params)
Definition: lupio_ipi.cc:39
void lupioIPIUpdateIRQ()
Function to post and clear interrupts.
Definition: lupio_ipi.cc:52
const ByteOrder byteOrder
Definition: lupio_ipi.hh:48
uint32_t nThread
Definition: lupio_ipi.hh:62
uint64_t lupioIPIRead(const uint8_t addr, int size)
Function to return the value in the word register of the corresponding CPU and lower the IRQ.
Definition: lupio_ipi.cc:66
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition: packet.cc:361
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
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition: packet.cc:352
PioDeviceParams Params
Definition: io_device.hh:134
Threads threads
Definition: system.hh:313
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 5 > r
Definition: pagetable.hh:60
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 15 > system
Definition: misc.hh:1004
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....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t Tick
Tick count type.
Definition: types.hh:58
int64 int_type
Definition: sc_nbdefs.hh:206

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