Re: [PATCH kvm-unit-tests 06/17] pci: introduce struct pci_dev

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

 



On Tue, Nov 08, 2016 at 06:35:54PM +0100, Andrew Jones wrote:
> On Tue, Nov 08, 2016 at 10:48:32AM -0500, Peter Xu wrote:
> > On Tue, Nov 08, 2016 at 01:27:31PM +0100, Alexander Gordeev wrote:
> > > On Fri, Nov 04, 2016 at 05:41:01PM +0100, Andrew Jones wrote:
> > > > >  /* Scan bus look for a specific device. Only bus 0 scanned for now. */
> > > > > -pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)
> > > > > +int pci_find_dev(struct pci_dev *pci_dev, uint16_t vendor_id, uint16_t device_id)
> > > > >  {
> > > > >  	pcidevaddr_t dev;
> > > > >  
> > > > > -	for (dev = 0; dev < 256; ++dev) {
> > > > > +	for (dev = 0; dev < PCI_DEVFN_MAX; ++dev) {
> > > > 
> > > > Why introduce this PCI_DEVFN_MAX define?
> > > > 
> > > > >  		if (pci_config_readw(dev, PCI_VENDOR_ID) == vendor_id &&
> > > > > -		    pci_config_readw(dev, PCI_DEVICE_ID) == device_id)
> > > > > -			return dev;
> > > > > +		    pci_config_readw(dev, PCI_DEVICE_ID) == device_id) {
> > > > > +			pci_dev_init(pci_dev, dev);
> > > > > +			return 0;
> > > > > +		}
> > > > >  	}
> > > > >  
> > > > > -	return PCIDEVADDR_INVALID;
> > > > > +	return -1;
> > > > 
> > > > Why not use bool for the ret type; true=good, false=bad?
> > > 
> > > Both ways look strange to me. I would leave pci_find_dev() as is (low-
> > > level) and move pci_dev_init() outside - so a usage would be i.e.:
> > > 
> > > 	dev = pci_find_dev(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_TEST);
> > > 	if (dev == PCIDEVADDR_INVALID)
> > > 		...
> > > 	pci_dev_init(&pci_dev, dev);
> > 
> > IMHO actually it'll be nicer with:
> > 
> >   struct pci_dev *pci_find_dev(uint16_t vendor_id, uint16_t device_id);
> 
> Yes, I was going to suggest this too, but then...
> 
> > 
> > But this needs dynamic allocation of memory, which might be an
> > overkill for kvm-unit-test. So I chose to allocate the pci_dev on
> > caller stack.
> 
> ...saw the value of avoiding the alloc. That said, we do have precedent
> for allocating in lib/* code already (virtio_bind), and I am currently
> reworking x86's memory management code in order to enable malloc/calloc
> use within lib code for x86. So we could go the alloc way as well...
> 
> > 
> > Anyway, I take the interface issue as a matter of taste.
> 
> Not quite. I see Alex's reasoning. Perhaps users want to simply query
> if a device is there (pci_find_dev), but not actually init a pci_dev
> struct each time they call it. Alex's proposal keeps pci_find_dev more
> generally useful.

Yep. So in the end of the day I would kept pci_find_dev() and added
pci_dev_alloc()/pci_dev_free() helpers (not sure about naming though).
The former would have to initialize pci_dev data to be consistent
and safely used by any other PCI API that takes pci_dev pointer.

> 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