Deleted Added
sdiff udiff text old ( 13756:12aa26df8c2f ) new ( 13877:a4ac726b549d )
full compact
1/*
2 * Copyright (c) 2018 Metempsy Technology Consulting
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 * Authors: Jairo Balart
29 */
30
31#include "dev/arm/gic_v3.hh"
32
33#include "cpu/intr_control.hh"
34#include "debug/GIC.hh"
35#include "debug/Interrupt.hh"
36#include "dev/arm/gic_v3_cpu_interface.hh"
37#include "dev/arm/gic_v3_distributor.hh"
38#include "dev/arm/gic_v3_redistributor.hh"
39#include "dev/platform.hh"
40#include "mem/packet.hh"
41#include "mem/packet_access.hh"
42
43Gicv3::Gicv3(const Params * p)
44 : BaseGic(p)
45{
46}
47
48void
49Gicv3::init()
50{
51 distRange = RangeSize(params()->dist_addr,
52 Gicv3Distributor::ADDR_RANGE_SIZE - 1);
53 redistRange = RangeSize(params()->redist_addr,
54 Gicv3Redistributor::ADDR_RANGE_SIZE * sys->numContexts() - 1);
55 addrRanges = {distRange, redistRange};
56 BaseGic::init();
57 distributor = new Gicv3Distributor(this, params()->it_lines);
58 redistributors.resize(sys->numContexts(), nullptr);
59 cpuInterfaces.resize(sys->numContexts(), nullptr);
60
61 for (int i = 0; i < sys->numContexts(); i++) {
62 redistributors[i] = new Gicv3Redistributor(this, i);
63 cpuInterfaces[i] = new Gicv3CPUInterface(this, i);
64 }
65
66 distributor->init();
67
68 for (int i = 0; i < sys->numContexts(); i++) {
69 redistributors[i]->init();
70 cpuInterfaces[i]->init();
71 }
72}
73
74void
75Gicv3::initState()
76{
77 distributor->initState();
78
79 for (int i = 0; i < sys->numContexts(); i++) {
80 redistributors[i]->initState();
81 cpuInterfaces[i]->initState();
82 }
83}
84
85Tick
86Gicv3::read(PacketPtr pkt)
87{
88 const Addr addr = pkt->getAddr();
89 const size_t size = pkt->getSize();
90 bool is_secure_access = pkt->isSecure();
91 uint64_t resp = 0;
92 Tick delay = 0;
93
94 if (distRange.contains(addr)) {
95 const Addr daddr = addr - distRange.start();
96 panic_if(!distributor, "Distributor is null!");
97 resp = distributor->read(daddr, size, is_secure_access);
98 delay = params()->dist_pio_delay;
99 DPRINTF(GIC, "Gicv3::read(): (distributor) context_id %d register %#x "
100 "size %d is_secure_access %d (value %#x)\n",
101 pkt->req->contextId(), daddr, size, is_secure_access, resp);
102 } else if (redistRange.contains(addr)) {
103 Addr daddr = addr - redistRange.start();
104 uint32_t redistributor_id =
105 daddr / Gicv3Redistributor::ADDR_RANGE_SIZE;
106 daddr = daddr % Gicv3Redistributor::ADDR_RANGE_SIZE;
107 panic_if(redistributor_id >= redistributors.size(),
108 "Invalid redistributor_id!");
109 panic_if(!redistributors[redistributor_id], "Redistributor is null!");
110 resp = redistributors[redistributor_id]->read(daddr, size,
111 is_secure_access);
112 delay = params()->redist_pio_delay;
113 DPRINTF(GIC, "Gicv3::read(): (redistributor %d) context_id %d "
114 "register %#x size %d is_secure_access %d (value %#x)\n",
115 redistributor_id, pkt->req->contextId(), daddr, size,
116 is_secure_access, resp);
117 } else {
118 panic("Gicv3::read(): unknown address %#x\n", addr);
119 }
120
121 pkt->setUintX(resp, LittleEndianByteOrder);
122 pkt->makeAtomicResponse();
123 return delay;
124}
125
126Tick
127Gicv3::write(PacketPtr pkt)
128{
129 const size_t size = pkt->getSize();
130 uint64_t data = pkt->getUintX(LittleEndianByteOrder);
131 const Addr addr = pkt->getAddr();
132 bool is_secure_access = pkt->isSecure();
133 Tick delay = 0;
134
135 if (distRange.contains(addr)) {
136 const Addr daddr = addr - distRange.start();
137 panic_if(!distributor, "Distributor is null!");
138 DPRINTF(GIC, "Gicv3::write(): (distributor) context_id %d "
139 "register %#x size %d is_secure_access %d value %#x\n",
140 pkt->req->contextId(), daddr, size, is_secure_access, data);
141 distributor->write(daddr, data, size, is_secure_access);
142 delay = params()->dist_pio_delay;
143 } else if (redistRange.contains(addr)) {
144 Addr daddr = addr - redistRange.start();
145 uint32_t redistributor_id =
146 daddr / Gicv3Redistributor::ADDR_RANGE_SIZE;
147 daddr = daddr % Gicv3Redistributor::ADDR_RANGE_SIZE;
148 panic_if(redistributor_id >= redistributors.size(),
149 "Invalid redistributor_id!");
150 panic_if(!redistributors[redistributor_id], "Redistributor is null!");
151 DPRINTF(GIC, "Gicv3::write(): (redistributor %d) context_id %d "
152 "register %#x size %d is_secure_access %d value %#x\n",
153 redistributor_id, pkt->req->contextId(), daddr, size,
154 is_secure_access, data);
155 redistributors[redistributor_id]->write(daddr, data, size,
156 is_secure_access);
157 delay = params()->redist_pio_delay;
158 } else {
159 panic("Gicv3::write(): unknown address %#x\n", addr);
160 }
161
162 pkt->makeAtomicResponse();
163 return delay;
164}
165
166void
167Gicv3::sendInt(uint32_t int_id)
168{
169 panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!");
170 panic_if(int_id >= Gicv3::INTID_SECURE, "Invalid SPI!");
171 DPRINTF(Interrupt, "Gicv3::sendInt(): received SPI %d\n", int_id);
172 distributor->sendInt(int_id);
173}
174
175void
176Gicv3::clearInt(uint32_t number)
177{
178 distributor->deassertSPI(number);
179}
180
181void
182Gicv3::sendPPInt(uint32_t int_id, uint32_t cpu)
183{
184 panic_if(cpu >= redistributors.size(), "Invalid cpuID sending PPI!");
185 panic_if(int_id < Gicv3::SGI_MAX, "Invalid PPI!");
186 panic_if(int_id >= Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid PPI!");
187 DPRINTF(Interrupt, "Gicv3::sendPPInt(): received PPI %d cpuTarget %#x\n",
188 int_id, cpu);
189 redistributors[cpu]->sendPPInt(int_id);
190}
191
192void
193Gicv3::clearPPInt(uint32_t num, uint32_t cpu)
194{
195}
196
197void
198Gicv3::postInt(uint32_t cpu, ArmISA::InterruptTypes int_type)
199{
200 platform->intrctrl->post(cpu, int_type, 0);
201}
202
203void
204Gicv3::deassertInt(uint32_t cpu, ArmISA::InterruptTypes int_type)
205{
206 platform->intrctrl->clear(cpu, int_type, 0);
207}
208
209Gicv3Redistributor *
210Gicv3::getRedistributorByAffinity(uint32_t affinity) const
211{
212 for (auto & redistributor : redistributors) {
213 if (redistributor->getAffinity() == affinity) {
214 return redistributor;
215 }
216 }
217
218 return nullptr;
219}
220
221void
222Gicv3::serialize(CheckpointOut & cp) const
223{
224 distributor->serializeSection(cp, "distributor");
225
226 for (uint32_t redistributor_id = 0;
227 redistributor_id < redistributors.size(); redistributor_id++)
228 redistributors[redistributor_id]->serializeSection(cp,
229 csprintf("redistributors.%i", redistributor_id));
230
231 for (uint32_t cpu_interface_id = 0;
232 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++)
233 cpuInterfaces[cpu_interface_id]->serializeSection(cp,
234 csprintf("cpuInterface.%i", cpu_interface_id));
235}
236
237void
238Gicv3::unserialize(CheckpointIn & cp)
239{
240 getSystem()->setGIC(this);
241
242 distributor->unserializeSection(cp, "distributor");
243
244 for (uint32_t redistributor_id = 0;
245 redistributor_id < redistributors.size(); redistributor_id++)
246 redistributors[redistributor_id]->unserializeSection(cp,
247 csprintf("redistributors.%i", redistributor_id));
248
249 for (uint32_t cpu_interface_id = 0;
250 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++)
251 cpuInterfaces[cpu_interface_id]->unserializeSection(cp,
252 csprintf("cpuInterface.%i", cpu_interface_id));
253}
254
255Gicv3 *
256Gicv3Params::create()
257{
258 return new Gicv3(this);
259}