On 20/07/2019 18:38, BALATON Zoltan wrote:
Or maybe not because it looks correct for BARs as above at the top of this message. So why does this function ignore the pci-addr.hi which is the only non-0 in this call or should it try to map config space of the card for ba=0?
This pci_decode_pci_addr() function looks suspicious:
https://github.com/openbios/openbios/blob/master/drivers/pci.c#L156
it's called from ob_pci_map():
https://github.com/openbios/openbios/blob/master/drivers/pci.c#L373
It only expects IO or MMIO space and instead of finding what space is requested from pci-addr.hi it only looks at pci-addr.lo to decide. I think this is probably not how this should work. OK, the comment near ob_pci_map() says it's for mapping PCI MMIO or IO so it was probably not meant to allow access to config space but the map-in word seems to allow that as well. So what's the recommended way here? Which of these functions should be changed to add support for config space or should that be handled in ob_pci_bus_map_in already?
Right, moving the detection and handling of the space into map-in rather than relying on the caller to do it seems to be the right thing here. It shouldn't take you too long to make the relevant changes:
- Change pci_bus_addr_to_host_addr() to return arch->cfg_addr if the space code indicates CONFIGURATION_SPACE (a switch statement is probably better here)
- Create pci_decode_phys_addr() as the opposite to pci_encode_phys_addr() that takes an array of 3 u32s and sets flags, space_code, dev and addr
- Switch pci_decode_pci_addr() in ob_pci_map() to use your new pci_decode_phys_addr() function
- ...at which point it probably makes sense to merge ob_pci_map() into ob_pci_bus_map_in(). There are a couple of callers that you'll need to fix up, and possibly vga.fs too.
That should give you a basic working PCI map-in word. Once you get the virtual address for a PCI device configuration space you can easily test by reading a 16-bit LE word and if all is well you'll get the PCI device id back:
0 0 1007814 100 " map-in" $call-parent \ should place virt address on stack le-w@ \ should perform LE read from virt and return 5046 \ on the stack (the device id of your ATI card)
Once the basics work the next step is to look at moving the ob_pci_map() logic into a call-parent chain (particularly the config, IO and MMIO base addresses) to implement the config-* words within the PCI bus node itself.
ATB,
Mark.