2 * Copyright (c) 2011-2013 ARM Limited
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.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 * Definition of a bus object.
50 #include "base/misc.hh"
51 #include "base/trace.hh"
52 #include "debug/Bus.hh"
53 #include "debug/BusAddrRanges.hh"
54 #include "debug/NoncoherentBus.hh"
55 #include "mem/noncoherent_bus.hh"
57 NoncoherentBus::NoncoherentBus(const NoncoherentBusParams
*p
)
58 : BaseBus(p
), reqLayer(*this, ".reqLayer"),
59 respLayer(*this, ".respLayer")
61 // create the ports based on the size of the master and slave
62 // vector ports, and the presence of the default port, the ports
63 // are enumerated starting from zero
64 for (int i
= 0; i
< p
->port_master_connection_count
; ++i
) {
65 std::string portName
= csprintf("%s.master[%d]", name(), i
);
66 MasterPort
* bp
= new NoncoherentBusMasterPort(portName
, *this, i
);
67 masterPorts
.push_back(bp
);
70 // see if we have a default slave device connected and if so add
71 // our corresponding master port
72 if (p
->port_default_connection_count
) {
73 defaultPortID
= masterPorts
.size();
74 std::string portName
= name() + ".default";
75 MasterPort
* bp
= new NoncoherentBusMasterPort(portName
, *this,
77 masterPorts
.push_back(bp
);
80 // create the slave ports, once again starting at zero
81 for (int i
= 0; i
< p
->port_slave_connection_count
; ++i
) {
82 std::string portName
= csprintf("%s.slave[%d]", name(), i
);
83 SlavePort
* bp
= new NoncoherentBusSlavePort(portName
, *this, i
);
84 slavePorts
.push_back(bp
);
91 NoncoherentBus::recvTimingReq(PacketPtr pkt
, PortID slave_port_id
)
93 // determine the source port based on the id
94 SlavePort
*src_port
= slavePorts
[slave_port_id
];
96 // we should never see express snoops on a non-coherent bus
97 assert(!pkt
->isExpressSnoop());
99 // test if the bus should be considered occupied for the current
101 if (!reqLayer
.tryTiming(src_port
)) {
102 DPRINTF(NoncoherentBus
, "recvTimingReq: src %s %s 0x%x BUSY\n",
103 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
107 DPRINTF(NoncoherentBus
, "recvTimingReq: src %s %s 0x%x\n",
108 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
110 // set the source port for routing of the response
111 pkt
->setSrc(slave_port_id
);
113 calcPacketTiming(pkt
);
114 Tick packetFinishTime
= pkt
->busLastWordDelay
+ curTick();
116 // since it is a normal request, determine the destination
117 // based on the address and attempt to send the packet
118 bool success
= masterPorts
[findPort(pkt
->getAddr())]->sendTimingReq(pkt
);
121 // inhibited packets should never be forced to retry
122 assert(!pkt
->memInhibitAsserted());
124 DPRINTF(NoncoherentBus
, "recvTimingReq: src %s %s 0x%x RETRY\n",
125 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
127 // occupy until the header is sent
128 reqLayer
.failedTiming(src_port
, clockEdge(Cycles(headerCycles
)));
133 reqLayer
.succeededTiming(packetFinishTime
);
139 NoncoherentBus::recvTimingResp(PacketPtr pkt
, PortID master_port_id
)
141 // determine the source port based on the id
142 MasterPort
*src_port
= masterPorts
[master_port_id
];
144 // test if the bus should be considered occupied for the current
146 if (!respLayer
.tryTiming(src_port
)) {
147 DPRINTF(NoncoherentBus
, "recvTimingResp: src %s %s 0x%x BUSY\n",
148 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
152 DPRINTF(NoncoherentBus
, "recvTimingResp: src %s %s 0x%x\n",
153 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
155 calcPacketTiming(pkt
);
156 Tick packetFinishTime
= pkt
->busLastWordDelay
+ curTick();
158 // send the packet to the destination through one of our slave
159 // ports, as determined by the destination field
160 bool success M5_VAR_USED
= slavePorts
[pkt
->getDest()]->sendTimingResp(pkt
);
162 // currently it is illegal to block responses... can lead to
166 respLayer
.succeededTiming(packetFinishTime
);
172 NoncoherentBus::recvRetry()
174 // responses never block on forwarding them, so the retry will
175 // always be coming from a port to which we tried to forward a
177 reqLayer
.recvRetry();
181 NoncoherentBus::recvAtomic(PacketPtr pkt
, PortID slave_port_id
)
183 DPRINTF(NoncoherentBus
, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
184 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
187 // determine the destination port
188 PortID dest_id
= findPort(pkt
->getAddr());
190 // forward the request to the appropriate destination
191 Tick response_latency
= masterPorts
[dest_id
]->sendAtomic(pkt
);
193 // @todo: Not setting first-word time
194 pkt
->busLastWordDelay
= response_latency
;
195 return response_latency
;
199 NoncoherentBus::recvFunctional(PacketPtr pkt
, PortID slave_port_id
)
201 if (!pkt
->isPrint()) {
202 // don't do DPRINTFs on PrintReq as it clutters up the output
203 DPRINTF(NoncoherentBus
,
204 "recvFunctional: packet src %s addr 0x%x cmd %s\n",
205 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
209 // determine the destination port
210 PortID dest_id
= findPort(pkt
->getAddr());
212 // forward the request to the appropriate destination
213 masterPorts
[dest_id
]->sendFunctional(pkt
);
217 NoncoherentBus::drain(DrainManager
*dm
)
219 // sum up the individual layers
220 return reqLayer
.drain(dm
) + respLayer
.drain(dm
);
224 NoncoherentBusParams::create()
226 return new NoncoherentBus(this);