<div dir="ltr">By the way, any ideas on how to avoid 'bus overstealing' would <div>be greatly appreciated.<div>Static BIOS variable isn't applicable since its value isn't saved across reboots.</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-23 19:43 GMT+03:00 Alexander Bezzubikov <span dir="ltr"><<a href="mailto:zuban32s@gmail.com" target="_blank">zuban32s@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">2017-07-23 5:49 GMT+03:00 Michael S. Tsirkin <span dir="ltr"><<a href="mailto:mst@redhat.com" target="_blank">mst@redhat.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Sun, Jul 23, 2017 at 01:11:50AM +0300, Aleksandr Bezzubikov wrote:<br>
> In case of Red Hat PCI bridges reserve additional buses, which number is provided<br>
> in a vendor-specific capability.<br>
><br>
> Signed-off-by: Aleksandr Bezzubikov <<a href="mailto:zuban32s@gmail.com" target="_blank">zuban32s@gmail.com</a>><br>
> ---<br>
>  src/fw/pciinit.c | 14 ++++++++++++--<br>
>  1 file changed, 12 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c<br>
> index 864954f..f05a8b9 100644<br>
> --- a/src/fw/pciinit.c<br>
> +++ b/src/fw/pciinit.c<br>
> @@ -15,6 +15,7 @@<br>
>  #include "hw/pcidevice.h" // pci_probe_devices<br>
>  #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL<br>
>  #include "hw/pci_regs.h" // PCI_COMMAND<br>
> +#include "hw/pci_cap.h" // qemu_pci_cap<br>
>  #include "list.h" // struct hlist_node<br>
>  #include "malloc.h" // free<br>
>  #include "output.h" // dprintf<br>
> @@ -578,9 +579,18 @@ pci_bios_init_bus_rec(int bus, u8 *pci_bus)<br>
>          pci_bios_init_bus_rec(secbus, pci_bus);<br>
><br>
>          if (subbus != *pci_bus) {<br>
> +            u8 res_bus = 0;<br>
> +            if (pci_config_readw(bdf, PCI_VENDOR_ID) == PCI_VENDOR_ID_REDHAT) {<br>
<br>
</span>Check device ID as well.</blockquote></div></div><div>Not sure what ID/IDs we want to see here exactly. Now it can be </div><div>only pcie-root-port (0xC then), but </div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> +                u8 cap = pci_find_capability(bdf, PCI_CAP_ID_VNDR, 0);<br>
<br>
</span>There could be multiple vendor capabilities. You want to scan them all.<br>
<span><br>
<br>
> +                if (cap) {<br>
> +                    res_bus = pci_config_readb(bdf,<br>
> +                            cap + offsetof(struct redhat_pci_bridge_cap,<br>
> +                                           bus_res));<br>
<br>
<br>
</span>You might want to add sanity checks e.g. overflow, and capability<br>
length.<br>
<br>
Also, if all you use is offsetof, don't bother with a struct, just<br>
add some defines.<br></blockquote></span><div>OK, will move this to defines.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> +                }<br>
> +            }<br>
>              dprintf(1, "PCI: subordinate bus = 0x%x -> 0x%x\n",<br>
> -                    subbus, *pci_bus);<br>
> -            subbus = *pci_bus;<br>
> +                    subbus, *pci_bus + res_bus);<br>
> +            subbus = *pci_bus + res_bus;<br>
<br>
</span>So you take all present devices and add reserved ones - is that it?<br>
If so it looks like this will steal extra buses each time you<br>
add a child bus and reboot.<br></blockquote><div> </div></span><div>You're right, such problem persists. Will think on what can be done here.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="m_-1195235618466814499HOEnZb"><div class="m_-1195235618466814499h5"><br>
<br>
>          } else {<br>
>              dprintf(1, "PCI: subordinate bus = 0x%x\n", subbus);<br>
>          }<br>
> --<br>
> 2.7.4<br>
</div></div></blockquote></span></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_-1195235618466814499gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Alexander Bezzubikov</div></div></div></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Alexander Bezzubikov</div></div></div></div>
</div>