tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pci_mapreg_map and BAR from `Bus space tutorial'



On 6/10/20 4:30 PM, Radoslaw Kujawa wrote:

It is more likely that something mis-compiles now (I see a ton of warnings trying to build it now), or that there is a bug in implementation of test device emulation, that somehow went unnoticed back in 2012.

It seems that in 2018 cobalt port was switched to common MIPS bus space implementation. As a part of this implementation, it started to be more strict about verification of addresses used by device during bus_space_map.

I earlier wrote that gxemul does not emulate Cobalt firmware and that is true, however it seems that it does place PCI device at certain addresses (0x10110000) upon boot.

NetBSD attempts to reconfigure the device to use address 0x12000000. As a part of switch to common MIPS bus space, for cobalt, window 0x12000000-0x14000000 was dedicated to PCI memory BARs.

For reasons still not researched thoroughly, this reconfiguration fails, and the device stays at original address.

So when the pci_mapreg_map is called, a MIPS MI bus_space_map is executed. As a part of this, translation takes place, however sanity check in __BS(translate) throws EINVAL, due to device being outside of window range.

I've worked the problem around by placing the device in gxemul at an exact address expected by NetBSD:

[ 1.0000000] faa0 at pci0 dev 12 function 0: vendor fabc product 0001 (rev. 0x01)
[   1.0000000] faa0: registers at 0x12000000
[   1.0000000] faa0: just checking: 1 + 2 = 3

Please try the attached gxemul patch.

Best regards,
Radoslaw
diff --git a/gxemul-current/src/devices/bus_pci.cc b/gxemul-current/src/devices/bus_pci.cc
index ce64aa0..8e7827c 100644
--- a/gxemul-current/src/devices/bus_pci.cc
+++ b/gxemul-current/src/devices/bus_pci.cc
@@ -1436,6 +1436,7 @@ PCIINIT(ati_radeon_9200_2)
 PCIINIT(faa)
 {
        uint64_t port, memaddr;
+       memaddr = 0x12000000;
        char tmpstr[200];
 
        PCI_SET_DATA(PCI_ID_REG, PCI_ID_CODE(PCI_VENDOR_FAKECARDS,
@@ -1444,7 +1445,9 @@ PCIINIT(faa)
        PCI_SET_DATA(PCI_CLASS_REG, PCI_CLASS_CODE(PCI_CLASS_PROCESSOR,
            PCI_SUBCLASS_PROCESSOR_COPROC, 0) + 0x01);
 
-       allocate_device_space(pd, 0x0, 0x100, &port, &memaddr);
+       PCI_SET_DATA(0x10, memaddr);
+
+//     allocate_device_space(pd, 0x0, 0x100, &port, &memaddr);
 
        snprintf(tmpstr, sizeof(tmpstr), "faa addr=0x%llx "
            "pci_little_endian=1", (long long)memaddr);



Home | Main Index | Thread Index | Old Index