svn commit: r223885 - head/sys/dev/pci

2011-07-09 Thread Konstantin Belousov
Author: kib
Date: Sat Jul  9 14:30:13 2011
New Revision: 223885
URL: http://svn.freebsd.org/changeset/base/223885

Log:
  Implement pci_find_class(9), the function to find a pci device by its class.
  
  Sponsored by: The FreeBSD Foundation
  Reviewed by:  jhb
  MFC after:1 week

Modified:
  head/sys/dev/pci/pci.c
  head/sys/dev/pci/pcivar.h

Modified: head/sys/dev/pci/pci.c
==
--- head/sys/dev/pci/pci.c  Sat Jul  9 14:29:23 2011(r223884)
+++ head/sys/dev/pci/pci.c  Sat Jul  9 14:30:13 2011(r223885)
@@ -347,6 +347,21 @@ pci_find_device(uint16_t vendor, uint16_
return (NULL);
 }
 
+device_t
+pci_find_class(uint8_t class, uint8_t subclass)
+{
+   struct pci_devinfo *dinfo;
+
+   STAILQ_FOREACH(dinfo, pci_devq, pci_links) {
+   if (dinfo-cfg.baseclass == class 
+   dinfo-cfg.subclass == subclass) {
+   return (dinfo-cfg.dev);
+   }
+   }
+
+   return (NULL);
+}
+
 static int
 pci_printf(pcicfgregs *cfg, const char *fmt, ...)
 {

Modified: head/sys/dev/pci/pcivar.h
==
--- head/sys/dev/pci/pcivar.h   Sat Jul  9 14:29:23 2011(r223884)
+++ head/sys/dev/pci/pcivar.h   Sat Jul  9 14:30:13 2011(r223885)
@@ -457,6 +457,7 @@ pci_msix_count(device_t dev)
 device_t pci_find_bsf(uint8_t, uint8_t, uint8_t);
 device_t pci_find_dbsf(uint32_t, uint8_t, uint8_t, uint8_t);
 device_t pci_find_device(uint16_t, uint16_t);
+device_t pci_find_class(uint8_t class, uint8_t subclass);
 
 /* Can be used by drivers to manage the MSI-X table. */
 intpci_pending_msix(device_t dev, u_int index);
___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


Re: svn commit: r223885 - head/sys/dev/pci

2011-07-09 Thread Warner Losh
Should't this be called 'pci_find_first_class()?  Also, can you add a man page 
for it, or at least document what it is supposed to be used for in the code?

Warenr

On Jul 9, 2011, at 8:30 AM, Konstantin Belousov wrote:

 Author: kib
 Date: Sat Jul  9 14:30:13 2011
 New Revision: 223885
 URL: http://svn.freebsd.org/changeset/base/223885
 
 Log:
  Implement pci_find_class(9), the function to find a pci device by its class.
 
  Sponsored by:The FreeBSD Foundation
  Reviewed by: jhb
  MFC after:   1 week
 
 Modified:
  head/sys/dev/pci/pci.c
  head/sys/dev/pci/pcivar.h
 
 Modified: head/sys/dev/pci/pci.c
 ==
 --- head/sys/dev/pci/pci.cSat Jul  9 14:29:23 2011(r223884)
 +++ head/sys/dev/pci/pci.cSat Jul  9 14:30:13 2011(r223885)
 @@ -347,6 +347,21 @@ pci_find_device(uint16_t vendor, uint16_
   return (NULL);
 }
 
 +device_t
 +pci_find_class(uint8_t class, uint8_t subclass)
 +{
 + struct pci_devinfo *dinfo;
 +
 + STAILQ_FOREACH(dinfo, pci_devq, pci_links) {
 + if (dinfo-cfg.baseclass == class 
 + dinfo-cfg.subclass == subclass) {
 + return (dinfo-cfg.dev);
 + }
 + }
 +
 + return (NULL);
 +}
 +
 static int
 pci_printf(pcicfgregs *cfg, const char *fmt, ...)
 {
 
 Modified: head/sys/dev/pci/pcivar.h
 ==
 --- head/sys/dev/pci/pcivar.h Sat Jul  9 14:29:23 2011(r223884)
 +++ head/sys/dev/pci/pcivar.h Sat Jul  9 14:30:13 2011(r223885)
 @@ -457,6 +457,7 @@ pci_msix_count(device_t dev)
 device_t pci_find_bsf(uint8_t, uint8_t, uint8_t);
 device_t pci_find_dbsf(uint32_t, uint8_t, uint8_t, uint8_t);
 device_t pci_find_device(uint16_t, uint16_t);
 +device_t pci_find_class(uint8_t class, uint8_t subclass);
 
 /* Can be used by drivers to manage the MSI-X table. */
 int   pci_pending_msix(device_t dev, u_int index);
 
 

___
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org


Re: svn commit: r223885 - head/sys/dev/pci

2011-07-09 Thread Kostik Belousov
On Sat, Jul 09, 2011 at 12:56:10PM -0600, Warner Losh wrote:
 Should't this be called 'pci_find_first_class()? Also, can you add a
 man page for it, or at least document what it is supposed to be used
 for in the code?

 Warenr
Sure, I will add a man page.

Regarding the name, the intended use is to look up some unique devices
on the hierarchy, like HOST-PCI bridge, or (used in the driver
which requires this function) PCI-ISA bridge. It is known that device
belonging to the supplied class is unique in the whole PCI buses hierarchy
on the machine where the driver is attaching.

'First' there probably cannot be given any strong sense, since it would
be a first device in some unspecified order.

 
 On Jul 9, 2011, at 8:30 AM, Konstantin Belousov wrote:
 
  Author: kib
  Date: Sat Jul  9 14:30:13 2011
  New Revision: 223885
  URL: http://svn.freebsd.org/changeset/base/223885
  
  Log:
   Implement pci_find_class(9), the function to find a pci device by its 
  class.
  
   Sponsored by:  The FreeBSD Foundation
   Reviewed by:   jhb
   MFC after: 1 week
  
  Modified:
   head/sys/dev/pci/pci.c
   head/sys/dev/pci/pcivar.h
  
  Modified: head/sys/dev/pci/pci.c
  ==
  --- head/sys/dev/pci/pci.c  Sat Jul  9 14:29:23 2011(r223884)
  +++ head/sys/dev/pci/pci.c  Sat Jul  9 14:30:13 2011(r223885)
  @@ -347,6 +347,21 @@ pci_find_device(uint16_t vendor, uint16_
  return (NULL);
  }
  
  +device_t
  +pci_find_class(uint8_t class, uint8_t subclass)
  +{
  +   struct pci_devinfo *dinfo;
  +
  +   STAILQ_FOREACH(dinfo, pci_devq, pci_links) {
  +   if (dinfo-cfg.baseclass == class 
  +   dinfo-cfg.subclass == subclass) {
  +   return (dinfo-cfg.dev);
  +   }
  +   }
  +
  +   return (NULL);
  +}
  +
  static int
  pci_printf(pcicfgregs *cfg, const char *fmt, ...)
  {
  
  Modified: head/sys/dev/pci/pcivar.h
  ==
  --- head/sys/dev/pci/pcivar.h   Sat Jul  9 14:29:23 2011
  (r223884)
  +++ head/sys/dev/pci/pcivar.h   Sat Jul  9 14:30:13 2011
  (r223885)
  @@ -457,6 +457,7 @@ pci_msix_count(device_t dev)
  device_t pci_find_bsf(uint8_t, uint8_t, uint8_t);
  device_t pci_find_dbsf(uint32_t, uint8_t, uint8_t, uint8_t);
  device_t pci_find_device(uint16_t, uint16_t);
  +device_t pci_find_class(uint8_t class, uint8_t subclass);
  
  /* Can be used by drivers to manage the MSI-X table. */
  int pci_pending_msix(device_t dev, u_int index);
  
  
 


pgpELibwqfSPy.pgp
Description: PGP signature