Re: [PATCH kvm-unit-tests 07/17] pci: provide pci_scan_bars()

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

 



On Wed, Oct 26, 2016 at 03:47:10PM +0800, Peter Xu wrote:
> Let's provide a more general way to scan PCI bars, rather than read the
> config registers every time.
> 
> Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
> ---
>  lib/pci.c | 14 ++++++++++++++
>  lib/pci.h |  3 +++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/lib/pci.c b/lib/pci.c
> index bb41e0f..95a6581 100644
> --- a/lib/pci.c
> +++ b/lib/pci.c
> @@ -35,6 +35,20 @@ int pci_find_dev(struct pci_dev *pci_dev, uint16_t vendor_id, uint16_t device_id
>  	return -1;
>  }
>  
> +void pci_scan_bars(struct pci_dev *dev)
> +{
> +	int i = 0;
> +
> +	for (i = 0; i < PCI_BAR_NUM; i++) {

I don't think we need a PCI_BAR_NUM def, but if you do introduce it
then please change all uses of '6' to it that should be changed.
Same goes for PCI_DEVFN_MAX.

> +		if (!pci_bar_is_valid(dev, i))
> +			continue;
> +		dev->pci_bar[i] = pci_bar_get_addr(dev, i);
> +		printf("PCI: init dev 0x%04x BAR %d [%s] addr 0x%lx\n",
> +		       dev->pci_bdf, i, pci_bar_is_memory(dev, i) ?
> +		       "MEM" : "IO", dev->pci_bar[i]);

v9 of Alex's series has introduced pci_bar_print. You'll want to
use that here after modifying it to get the bars from struct.

> +	}
> +}
> +
>  uint32_t pci_bar_mask(uint32_t bar)
>  {
>  	return (bar & PCI_BASE_ADDRESS_SPACE_IO) ?
> diff --git a/lib/pci.h b/lib/pci.h
> index af20dc5..56b49f0 100644
> --- a/lib/pci.h
> +++ b/lib/pci.h
> @@ -15,13 +15,16 @@ enum {
>  	PCIDEVADDR_INVALID = 0xffff,
>  };
>  
> +#define PCI_BAR_NUM                     (6)
>  #define PCI_DEVFN_MAX                   (256)
>  
>  struct pci_dev {
>  	uint16_t pci_bdf;
> +	phys_addr_t pci_bar[PCI_BAR_NUM];
>  };
>  
>  void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf);
> +void pci_scan_bars(struct pci_dev *dev);
>  
>  extern bool pci_probe(void);
>  extern void pci_print(void);
> -- 
> 2.7.4
>

Thanks,
drew
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux