mem: Fix guest corruption when caches handle uncacheable accesses
[gem5.git] / src / mem / bus.cc
index a0db6e52a227c87b8d154d93e583c5fdf55fa86c..a880eca8f2318d46aea270b91d47b2b1b7240c29 100644 (file)
@@ -161,7 +161,8 @@ BaseBus::calcPacketTiming(PacketPtr pkt)
 template <typename PortClass>
 BaseBus::Layer<PortClass>::Layer(BaseBus& _bus, const std::string& _name,
                                  Tick _clock) :
-    bus(_bus), _name(_name), state(IDLE), clock(_clock), drainEvent(NULL),
+    Drainable(),
+    bus(_bus), _name(_name), state(IDLE), clock(_clock), drainManager(NULL),
     releaseEvent(this)
 {
 }
@@ -266,12 +267,12 @@ BaseBus::Layer<PortClass>::releaseLayer()
         // busy, and in the latter case the bus may be released before
         // we see a retry from the destination
         retryWaiting();
-    } else if (drainEvent) {
-        DPRINTF(Drain, "Bus done draining, processing drain event\n");
+    } else if (drainManager) {
+        DPRINTF(Drain, "Bus done draining, signaling drain manager\n");
         //If we weren't able to drain before, do it now.
-        drainEvent->process();
+        drainManager->signalDrainDone();
         // Clear the drain event once we're done with it.
-        drainEvent = NULL;
+        drainManager = NULL;
     }
 }
 
@@ -356,7 +357,7 @@ BaseBus::findPort(Addr addr)
 
     // Check if this matches the default range
     if (useDefaultRange) {
-        if (defaultRange == addr) {
+        if (defaultRange.contains(addr)) {
             DPRINTF(BusAddrRanges, "  found addr %#llx on default\n",
                     addr);
             return defaultPortID;
@@ -377,6 +378,9 @@ BaseBus::findPort(Addr addr)
 void
 BaseBus::recvRangeChange(PortID master_port_id)
 {
+    DPRINTF(BusAddrRanges, "Received range change from slave port %s\n",
+            masterPorts[master_port_id]->getSlavePort().name());
+
     // remember that we got a range from this master port and thus the
     // connected slave module
     gotAddrRanges[master_port_id] = true;
@@ -390,15 +394,14 @@ BaseBus::recvRangeChange(PortID master_port_id)
         while (gotAllAddrRanges &&  r != gotAddrRanges.end()) {
             gotAllAddrRanges &= *r++;
         }
+        if (gotAllAddrRanges)
+            DPRINTF(BusAddrRanges, "Got address ranges from all slaves\n");
     }
 
     // note that we could get the range from the default port at any
     // point in time, and we cannot assume that the default range is
     // set before the other ones are, so we do additional checks once
     // all ranges are provided
-    DPRINTF(BusAddrRanges, "received RangeChange from slave port %s\n",
-            masterPorts[master_port_id]->getSlavePort().name());
-
     if (master_port_id == defaultPortID) {
         // only update if we are indeed checking ranges for the
         // default port since the port might not have a valid range
@@ -429,8 +432,8 @@ BaseBus::recvRangeChange(PortID master_port_id)
         AddrRangeList ranges = masterPorts[master_port_id]->getAddrRanges();
 
         for (AddrRangeConstIter r = ranges.begin(); r != ranges.end(); ++r) {
-            DPRINTF(BusAddrRanges, "Adding range %#llx : %#llx for id %d\n",
-                    r->start, r->end, master_port_id);
+            DPRINTF(BusAddrRanges, "Adding range %s for id %d\n",
+                    r->to_string(), master_port_id);
             if (portMap.insert(*r, master_port_id) == portMap.end()) {
                 PortID conflict_id = portMap.find(*r)->second;
                 fatal("%s has two ports with same range:\n\t%s\n\t%s\n",
@@ -465,9 +468,9 @@ BaseBus::recvRangeChange(PortID master_port_id)
                         // overlapping the default range
                         if (r->intersects(defaultRange) &&
                             !r->isSubset(defaultRange))
-                            fatal("Range %#llx : %#llx intersects the " \
+                            fatal("Range %s intersects the " \
                                   "default range of %s but is not a " \
-                                  "subset\n", r->start, r->end, name());
+                                  "subset\n", r->to_string(), name());
                     }
                 }
             }
@@ -491,23 +494,28 @@ BaseBus::getAddrRanges() const
     // of the connected devices
     assert(gotAllAddrRanges);
 
-    DPRINTF(BusAddrRanges, "received address range request, returning:\n");
+    // at the moment, this never happens, as there are no cycles in
+    // the range queries and no devices on the master side of a bus
+    // (CPU, cache, bridge etc) actually care about the ranges of the
+    // ports they are connected to
+
+    DPRINTF(BusAddrRanges, "Received address range request, returning:\n");
 
     // start out with the default range
     AddrRangeList ranges;
-    ranges.push_back(defaultRange);
-    DPRINTF(BusAddrRanges, "  -- %#llx : %#llx DEFAULT\n",
-            defaultRange.start, defaultRange.end);
+    if (useDefaultRange) {
+        ranges.push_back(defaultRange);
+        DPRINTF(BusAddrRanges, "  -- Default %s\n", defaultRange.to_string());
+    }
 
     // add any range that is not a subset of the default range
     for (PortMapConstIter p = portMap.begin(); p != portMap.end(); ++p) {
         if (useDefaultRange && p->first.isSubset(defaultRange)) {
-            DPRINTF(BusAddrRanges, "  -- %#llx : %#llx is a SUBSET\n",
-                    p->first.start, p->first.end);
+            DPRINTF(BusAddrRanges, "  -- %s is a subset of default\n",
+                    p->first.to_string());
         } else {
             ranges.push_back(p->first);
-            DPRINTF(BusAddrRanges, "  -- %#llx : %#llx\n",
-                    p->first.start, p->first.end);
+            DPRINTF(BusAddrRanges, "  -- %s\n", p->first.to_string());
         }
     }
 
@@ -522,14 +530,14 @@ BaseBus::deviceBlockSize() const
 
 template <typename PortClass>
 unsigned int
-BaseBus::Layer<PortClass>::drain(Event * de)
+BaseBus::Layer<PortClass>::drain(DrainManager *dm)
 {
     //We should check that we're not "doing" anything, and that noone is
     //waiting. We might be idle but have someone waiting if the device we
     //contacted for a retry didn't actually retry.
     if (!retryList.empty() || state != IDLE) {
         DPRINTF(Drain, "Bus not drained\n");
-        drainEvent = de;
+        drainManager = dm;
         return 1;
     }
     return 0;