ARM: Make GIC function that should only be called by GIC protected.
[gem5.git] / src / dev / pcidev.cc
index 9efee2835b1e4c4c248f292e06322f2afdb9b85b..a22612d185f780f79d885f2916aa47b019b03efd 100644 (file)
 #include <vector>
 
 #include "base/inifile.hh"
-#include "base/intmath.hh" // for isPowerOf2(
+#include "base/intmath.hh"
 #include "base/misc.hh"
-#include "base/str.hh" // for to_number
+#include "base/str.hh"
 #include "base/trace.hh"
+#include "debug/PCIDEV.hh"
+#include "dev/alpha/tsunamireg.h"
 #include "dev/pciconfigall.hh"
 #include "dev/pcidev.hh"
-#include "dev/alpha/tsunamireg.h"
 #include "mem/packet.hh"
 #include "mem/packet_access.hh"
-#include "params/PciConfigData.hh"
 #include "sim/byteswap.hh"
 #include "sim/core.hh"
 
@@ -57,10 +57,10 @@ using namespace std;
 
 PciDev::PciConfigPort::PciConfigPort(PciDev *dev, int busid, int devid,
         int funcid, Platform *p)
-    : SimpleTimingPort(dev->name() + "-pciconf"), device(dev), platform(p),
-      busId(busid), deviceId(devid), functionId(funcid)
+    : SimpleTimingPort(dev->name() + "-pciconf", dev), device(dev),
+      platform(p), busId(busid), deviceId(devid), functionId(funcid)
 {
-    configAddr = platform->calcConfigAddr(busId, deviceId, functionId);
+    configAddr = platform->calcPciConfigAddr(busId, deviceId, functionId);
 }
 
 
@@ -77,26 +77,74 @@ PciDev::PciConfigPort::getDeviceAddressRanges(AddrRangeList &resp,
                                               bool &snoop)
 {
     snoop = false;;
-    resp.push_back(RangeSize(configAddr, PCI_CONFIG_SIZE+1));
+    if (configAddr != ULL(-1))
+        resp.push_back(RangeSize(configAddr, PCI_CONFIG_SIZE+1));
 }
 
 
-PciDev::PciDev(Params *p)
-    : DmaDevice(p), plat(p->platform), configData(p->configdata),
-      pioDelay(p->pio_latency), configDelay(p->config_latency),
-      configPort(NULL)
+PciDev::PciDev(const Params *p)
+    : DmaDevice(p), plat(p->platform), pioDelay(p->pio_latency),
+      configDelay(p->config_latency), configPort(NULL)
 {
-    // copy the config data from the PciConfigData object
-    if (configData) {
-        memcpy(config.data, configData->config.data, sizeof(config.data));
-        memcpy(BARSize, configData->BARSize, sizeof(BARSize));
-    } else
-        panic("NULL pointer to configuration data");
+    config.vendor = htole(p->VendorID);
+    config.device = htole(p->DeviceID);
+    config.command = htole(p->Command);
+    config.status = htole(p->Status);
+    config.revision = htole(p->Revision);
+    config.progIF = htole(p->ProgIF);
+    config.subClassCode = htole(p->SubClassCode);
+    config.classCode = htole(p->ClassCode);
+    config.cacheLineSize = htole(p->CacheLineSize);
+    config.latencyTimer = htole(p->LatencyTimer);
+    config.headerType = htole(p->HeaderType);
+    config.bist = htole(p->BIST);
+
+    config.baseAddr[0] = htole(p->BAR0);
+    config.baseAddr[1] = htole(p->BAR1);
+    config.baseAddr[2] = htole(p->BAR2);
+    config.baseAddr[3] = htole(p->BAR3);
+    config.baseAddr[4] = htole(p->BAR4);
+    config.baseAddr[5] = htole(p->BAR5);
+    config.cardbusCIS = htole(p->CardbusCIS);
+    config.subsystemVendorID = htole(p->SubsystemVendorID);
+    config.subsystemID = htole(p->SubsystemID);
+    config.expansionROM = htole(p->ExpansionROM);
+    config.reserved0 = 0;
+    config.reserved1 = 0;
+    config.interruptLine = htole(p->InterruptLine);
+    config.interruptPin = htole(p->InterruptPin);
+    config.minimumGrant = htole(p->MinimumGrant);
+    config.maximumLatency = htole(p->MaximumLatency);
+
+    BARSize[0] = p->BAR0Size;
+    BARSize[1] = p->BAR1Size;
+    BARSize[2] = p->BAR2Size;
+    BARSize[3] = p->BAR3Size;
+    BARSize[4] = p->BAR4Size;
+    BARSize[5] = p->BAR5Size;
+
+    legacyIO[0] = p->BAR0LegacyIO;
+    legacyIO[1] = p->BAR1LegacyIO;
+    legacyIO[2] = p->BAR2LegacyIO;
+    legacyIO[3] = p->BAR3LegacyIO;
+    legacyIO[4] = p->BAR4LegacyIO;
+    legacyIO[5] = p->BAR5LegacyIO;
 
-    memset(BARAddrs, 0, sizeof(BARAddrs));
+    for (int i = 0; i < 6; ++i) {
+        if (legacyIO[i]) {
+            BARAddrs[i] = platform->calcPciIOAddr(letoh(config.baseAddr[i]));
+            config.baseAddr[i] = 0;
+        } else {
+            BARAddrs[i] = 0;
+            uint32_t barsize = BARSize[i];
+            if (barsize != 0 && !isPowerOf2(barsize)) {
+                fatal("BAR %d size %d is not a power of 2\n", i, BARSize[i]);
+            }
+        }
+    }
 
     plat->registerPciDevice(0, p->pci_dev, p->pci_func,
-            letoh(configData->config.interruptLine));
+            letoh(config.interruptLine));
 }
 
 void
@@ -181,8 +229,10 @@ PciDev::writeConfig(PacketPtr pkt)
         switch (offset) {
           case PCI0_INTERRUPT_LINE:
             config.interruptLine = pkt->get<uint8_t>();
+            break;
           case PCI_CACHE_LINE_SIZE:
             config.cacheLineSize = pkt->get<uint8_t>();
+            break;
           case PCI_LATENCY_TIMER:
             config.latencyTimer = pkt->get<uint8_t>();
             break;
@@ -205,8 +255,10 @@ PciDev::writeConfig(PacketPtr pkt)
         switch (offset) {
           case PCI_COMMAND:
             config.command = pkt->get<uint8_t>();
+            break;
           case PCI_STATUS:
             config.status = pkt->get<uint8_t>();
+            break;
           case PCI_CACHE_LINE_SIZE:
             config.cacheLineSize = pkt->get<uint8_t>();
             break;
@@ -229,30 +281,32 @@ PciDev::writeConfig(PacketPtr pkt)
             {
                 int barnum = BAR_NUMBER(offset);
 
-                // convert BAR values to host endianness
-                uint32_t he_old_bar = letoh(config.baseAddr[barnum]);
-                uint32_t he_new_bar = letoh(pkt->get<uint32_t>());
-
-                uint32_t bar_mask =
-                    BAR_IO_SPACE(he_old_bar) ? BAR_IO_MASK : BAR_MEM_MASK;
-
-                // Writing 0xffffffff to a BAR tells the card to set the
-                // value of the bar to a bitmask indicating the size of
-                // memory it needs
-                if (he_new_bar == 0xffffffff) {
-                    he_new_bar = ~(BARSize[barnum] - 1);
-                } else {
-                    // does it mean something special to write 0 to a BAR?
-                    he_new_bar &= ~bar_mask;
-                    if (he_new_bar) {
-                        Addr space_base = BAR_IO_SPACE(he_old_bar) ?
-                            TSUNAMI_PCI0_IO : TSUNAMI_PCI0_MEMORY;
-                        BARAddrs[barnum] = he_new_bar + space_base;
-                        pioPort->sendStatusChange(Port::RangeChange);
+                if (!legacyIO[barnum]) {
+                    // convert BAR values to host endianness
+                    uint32_t he_old_bar = letoh(config.baseAddr[barnum]);
+                    uint32_t he_new_bar = letoh(pkt->get<uint32_t>());
+
+                    uint32_t bar_mask =
+                        BAR_IO_SPACE(he_old_bar) ? BAR_IO_MASK : BAR_MEM_MASK;
+
+                    // Writing 0xffffffff to a BAR tells the card to set the
+                    // value of the bar to a bitmask indicating the size of
+                    // memory it needs
+                    if (he_new_bar == 0xffffffff) {
+                        he_new_bar = ~(BARSize[barnum] - 1);
+                    } else {
+                        // does it mean something special to write 0 to a BAR?
+                        he_new_bar &= ~bar_mask;
+                        if (he_new_bar) {
+                            BARAddrs[barnum] = BAR_IO_SPACE(he_old_bar) ?
+                                platform->calcPciIOAddr(he_new_bar) :
+                                platform->calcPciMemAddr(he_new_bar);
+                            pioPort->sendStatusChange(Port::RangeChange);
+                        }
                     }
+                    config.baseAddr[barnum] = htole((he_new_bar & ~bar_mask) |
+                                                    (he_old_bar & bar_mask));
                 }
-                config.baseAddr[barnum] = htole((he_new_bar & ~bar_mask) |
-                                                (he_old_bar & bar_mask));
             }
             break;
 
@@ -304,53 +358,3 @@ PciDev::unserialize(Checkpoint *cp, const std::string &section)
 
 }
 
-PciConfigData *
-PciConfigDataParams::create()
-{
-    PciConfigData *data = new PciConfigData(name);
-
-    data->config.vendor = htole(VendorID);
-    data->config.device = htole(DeviceID);
-    data->config.command = htole(Command);
-    data->config.status = htole(Status);
-    data->config.revision = htole(Revision);
-    data->config.progIF = htole(ProgIF);
-    data->config.subClassCode = htole(SubClassCode);
-    data->config.classCode = htole(ClassCode);
-    data->config.cacheLineSize = htole(CacheLineSize);
-    data->config.latencyTimer = htole(LatencyTimer);
-    data->config.headerType = htole(HeaderType);
-    data->config.bist = htole(BIST);
-
-    data->config.baseAddr[0] = htole(BAR0);
-    data->config.baseAddr[1] = htole(BAR1);
-    data->config.baseAddr[2] = htole(BAR2);
-    data->config.baseAddr[3] = htole(BAR3);
-    data->config.baseAddr[4] = htole(BAR4);
-    data->config.baseAddr[5] = htole(BAR5);
-    data->config.cardbusCIS = htole(CardbusCIS);
-    data->config.subsystemVendorID = htole(SubsystemVendorID);
-    data->config.subsystemID = htole(SubsystemID);
-    data->config.expansionROM = htole(ExpansionROM);
-    data->config.interruptLine = htole(InterruptLine);
-    data->config.interruptPin = htole(InterruptPin);
-    data->config.minimumGrant = htole(MinimumGrant);
-    data->config.maximumLatency = htole(MaximumLatency);
-
-    data->BARSize[0] = BAR0Size;
-    data->BARSize[1] = BAR1Size;
-    data->BARSize[2] = BAR2Size;
-    data->BARSize[3] = BAR3Size;
-    data->BARSize[4] = BAR4Size;
-    data->BARSize[5] = BAR5Size;
-
-    for (int i = 0; i < 6; ++i) {
-        uint32_t barsize = data->BARSize[i];
-        if (barsize != 0 && !isPowerOf2(barsize)) {
-            fatal("%s: BAR %d size %d is not a power of 2\n",
-                  name, i, data->BARSize[i]);
-        }
-    }
-
-    return data;
-}