gem5  v22.1.0.0
mhu.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "dev/arm/css/mhu.hh"
39 
40 #include "debug/MHU.hh"
41 #include "dev/arm/base_gic.hh"
42 #include "dev/arm/css/scp.hh"
43 #include "mem/packet_access.hh"
44 #include "params/Ap2ScpDoorbell.hh"
45 #include "params/MHU.hh"
46 #include "params/Scp2ApDoorbell.hh"
47 
48 namespace gem5
49 {
50 
51 Scp2ApDoorbell::Scp2ApDoorbell(const Scp2ApDoorbellParams &p)
52  : MhuDoorbell(p), interrupt(p.interrupt->get())
53 {}
54 
55 Ap2ScpDoorbell::Ap2ScpDoorbell(const Ap2ScpDoorbellParams &p)
56  : MhuDoorbell(p)
57 {}
58 
59 MHU::MHU(const MHUParams &p)
60  : BasicPioDevice(p, p.pio_size),
61  scpLow(p.lowp_scp2ap),
62  scpHigh(p.highp_scp2ap),
63  scpSec(p.sec_scp2ap),
64  apLow(p.lowp_ap2scp),
65  apHigh(p.highp_ap2scp),
66  apSec(p.sec_ap2scp),
67  pid{ 0x98, 0xb0, 0x1b, 0x0, 0x4 },
68  compid{ 0x0d, 0xf0, 0x05, 0xb1 },
69  scfg(0)
70 {
71  apLow->setScp(p.scp);
72  apHigh->setScp(p.scp);
73  apSec->setScp(p.scp);
74 }
75 
78 {
79  return AddrRangeList({ RangeSize(pioAddr, pioSize) });
80 }
81 
82 Tick
84 {
85  const Addr addr = pkt->getAddr() - pioAddr;
86  const bool secure = pkt->isSecure();
87 
88  uint32_t value = read32(addr, secure);
89 
90  DPRINTF(MHU, "Reading %#x at address: %#x\n", value, addr);
91 
92  pkt->setUintX(value, ByteOrder::little);
93  pkt->makeAtomicResponse();
94  return pioDelay;
95 }
96 
97 uint32_t
98 MHU::read32(const Addr addr, bool secure_access)
99 {
100  switch (addr) {
101  case SCP_INTR_L_STAT:
102  return scpLow->channel;
103  case SCP_INTR_H_STAT:
104  return scpHigh->channel;
105  case CPU_INTR_L_STAT:
106  return apLow->channel;
107  case CPU_INTR_H_STAT:
108  return apHigh->channel;
109  case SCP_INTR_S_STAT:
110  if (secure_access) {
111  return scpSec->channel;
112  } else {
113  if (!bits(scfg, 0))
114  scpSec->set(SVI_INT);
115  return 0;
116  }
117  case CPU_INTR_S_STAT:
118  if (secure_access) {
119  return apSec->channel;
120  } else {
121  if (!bits(scfg, 0))
122  scpSec->set(SVI_INT);
123  return 0;
124  }
125  case MHU_SCFG:
126  return scfg;
127  case PID4:
128  return pid[4];
129  case PID0:
130  return pid[0];
131  case PID1:
132  return pid[1];
133  case PID2:
134  return pid[2];
135  case PID3:
136  return pid[3];
137  case COMPID0:
138  return compid[0];
139  case COMPID1:
140  return compid[1];
141  case COMPID2:
142  return compid[2];
143  case COMPID3:
144  return compid[3];
145  default:
146  panic("Invalid register read at address: %#x\n", addr);
147  }
148 }
149 
150 Tick
152 {
153  const Addr addr = pkt->getAddr() - pioAddr;
154 
155  assert(pkt->getSize() == sizeof(uint32_t));
156  const uint32_t value = pkt->getLE<uint32_t>();
157 
158  DPRINTF(MHU, "Writing %#x at address: %#x\n", value, addr);
159 
160  switch (addr) {
161  case SCP_INTR_L_SET:
162  scpLow->set(value);
163  break;
164  case SCP_INTR_L_CLEAR:
165  scpLow->clear(value);
166  break;
167  case SCP_INTR_H_SET:
168  scpHigh->set(value);
169  break;
170  case SCP_INTR_H_CLEAR:
171  scpHigh->clear(value);
172  break;
173  case CPU_INTR_L_SET:
174  apLow->set(value);
175  break;
176  case CPU_INTR_L_CLEAR:
177  apLow->clear(value);
178  break;
179  case CPU_INTR_H_SET:
180  apHigh->set(value);
181  break;
182  case CPU_INTR_H_CLEAR:
183  apHigh->clear(value);
184  break;
185  case SCP_INTR_S_SET:
186  scpSec->set(value);
187  break;
188  case SCP_INTR_S_CLEAR:
189  scpSec->clear(value);
190  break;
191  case CPU_INTR_S_SET:
192  apSec->set(value);
193  break;
194  case CPU_INTR_S_CLEAR:
195  apSec->clear(value);
196  break;
197  case MHU_SCFG:
198  scfg = value;
199  break;
200  default:
201  panic("Invalid register write at address: %#x\n", addr);
202  }
203 
204  pkt->makeAtomicResponse();
205  return pioDelay;
206 }
207 
208 void
209 MhuDoorbell::update(uint32_t new_val)
210 {
211  const bool int_old = channel != 0;
212  const bool int_new = new_val != 0;
213 
214  channel = new_val;
215  if (int_old && !int_new) {
216  clearInterrupt();
217  } else if (!int_old && int_new) {
218  raiseInterrupt();
219  }
220 }
221 
222 void
224 {
225  interrupt->raise();
226 }
227 
228 void
230 {
231  interrupt->clear();
232 }
233 
234 void
236 {
237  scp->raiseInterrupt(this);
238 }
239 
240 void
242 {
243  scp->clearInterrupt(this);
244 }
245 
246 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Base class for ARM GIC implementations.
void clearInterrupt() override
Definition: mhu.cc:241
void setScp(Scp *_scp)
Definition: mhu.hh:92
void raiseInterrupt() override
Definition: mhu.cc:235
Ap2ScpDoorbell(const Ap2ScpDoorbellParams &p)
Definition: mhu.cc:55
virtual void clear()=0
Clear a signalled interrupt.
virtual void raise()=0
Signal an interrupt.
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
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:154
Message Handling Unit.
Definition: mhu.hh:103
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mhu.cc:151
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mhu.cc:83
uint32_t compid[4]
Definition: mhu.hh:167
Scp2ApDoorbell * scpHigh
Definition: mhu.hh:158
static const uint32_t SVI_INT
Definition: mhu.hh:146
Ap2ScpDoorbell * apLow
Definition: mhu.hh:161
Scp2ApDoorbell * scpSec
Definition: mhu.hh:159
uint32_t scfg
Definition: mhu.hh:169
@ COMPID0
Definition: mhu.hh:138
@ SCP_INTR_H_SET
Definition: mhu.hh:112
@ SCP_INTR_S_SET
Definition: mhu.hh:124
@ PID1
Definition: mhu.hh:134
@ CPU_INTR_H_SET
Definition: mhu.hh:120
@ SCP_INTR_S_CLEAR
Definition: mhu.hh:125
@ SCP_INTR_S_STAT
Definition: mhu.hh:123
@ SCP_INTR_H_CLEAR
Definition: mhu.hh:113
@ PID0
Definition: mhu.hh:133
@ CPU_INTR_L_SET
Definition: mhu.hh:117
@ PID4
Definition: mhu.hh:132
@ CPU_INTR_S_SET
Definition: mhu.hh:127
@ CPU_INTR_L_STAT
From Application Processor to SCP.
Definition: mhu.hh:116
@ CPU_INTR_H_CLEAR
Definition: mhu.hh:121
@ SCP_INTR_H_STAT
Definition: mhu.hh:111
@ SCP_INTR_L_SET
Definition: mhu.hh:109
@ CPU_INTR_S_CLEAR
Definition: mhu.hh:128
@ CPU_INTR_H_STAT
Definition: mhu.hh:119
@ CPU_INTR_L_CLEAR
Definition: mhu.hh:118
@ CPU_INTR_S_STAT
Definition: mhu.hh:126
@ PID2
Definition: mhu.hh:135
@ COMPID1
Definition: mhu.hh:139
@ MHU_SCFG
Definition: mhu.hh:130
@ SCP_INTR_L_STAT
From SCP to Application Processor.
Definition: mhu.hh:108
@ PID3
Definition: mhu.hh:136
@ SCP_INTR_L_CLEAR
Definition: mhu.hh:110
@ COMPID3
Definition: mhu.hh:141
@ COMPID2
Definition: mhu.hh:140
uint32_t read32(const Addr addr, bool secure_access)
Definition: mhu.cc:98
Ap2ScpDoorbell * apHigh
Definition: mhu.hh:162
Ap2ScpDoorbell * apSec
Definition: mhu.hh:163
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: mhu.cc:77
MHU(const MHUParams &p)
Definition: mhu.cc:59
Scp2ApDoorbell * scpLow
Definition: mhu.hh:157
uint32_t pid[5]
Definition: mhu.hh:166
virtual void raiseInterrupt()=0
void update(uint32_t new_val)
Definition: mhu.cc:209
void set(uint32_t val)
Definition: mhu.hh:63
void clear(uint32_t val)
Definition: mhu.hh:64
virtual void clearInterrupt()=0
uint32_t channel
Definition: mhu.hh:72
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
bool isSecure() const
Definition: packet.hh:834
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
unsigned getSize() const
Definition: packet.hh:815
void makeAtomicResponse()
Definition: packet.hh:1071
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
void raiseInterrupt() override
Definition: mhu.cc:223
Scp2ApDoorbell(const Scp2ApDoorbellParams &p)
Definition: mhu.cc:51
ArmInterruptPin * interrupt
Definition: mhu.hh:84
void clearInterrupt() override
Definition: mhu.cc:229
virtual void raiseInterrupt(const Doorbell *doorbell)=0
virtual void clearInterrupt(const Doorbell *doorbell)=0
AddrRange RangeSize(Addr start, Addr size)
Definition: addr_range.hh:815
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition: addr_range.hh:57
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 54 > p
Definition: pagetable.hh:70
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

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