]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[pci] Allow pci_find_next() to return non-zero PCI segments
authorMichael Brown <mcb30@ipxe.org>
Thu, 15 Sep 2022 13:55:26 +0000 (14:55 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 15 Sep 2022 14:20:58 +0000 (15:20 +0100)
Separate the return status code from the returned PCI bus:dev.fn
address, in order to allow pci_find_next() to be used to find devices
with a non-zero PCI segment number.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/bus/pci.c
src/hci/commands/pci_cmd.c
src/include/ipxe/pci.h

index 5891e42ff4dc6c8d00c2d6b131048fb60173f10f..60d5df1125bd036eb60ef94538728441dcb35060 100644 (file)
@@ -229,9 +229,10 @@ int pci_read_config ( struct pci_device *pci ) {
  *
  * @v pci              PCI device to fill in
  * @v busdevfn         Starting bus:dev.fn address
- * @ret busdevfn       Bus:dev.fn address of next PCI device, or negative error
+ * @ret busdevfn       Bus:dev.fn address of next PCI device
+ * @ret rc             Return status code
  */
-int pci_find_next ( struct pci_device *pci, unsigned int busdevfn ) {
+int pci_find_next ( struct pci_device *pci, uint32_t *busdevfn ) {
        static unsigned int end;
        unsigned int sub_end;
        uint8_t hdrtype;
@@ -243,11 +244,11 @@ int pci_find_next ( struct pci_device *pci, unsigned int busdevfn ) {
                end = PCI_BUSDEVFN ( 0, pci_num_bus(), 0, 0 );
 
        /* Find next PCI device, if any */
-       for ( ; busdevfn < end ; busdevfn++ ) {
+       for ( ; *busdevfn < end ; (*busdevfn)++ ) {
 
                /* Check for PCI device existence */
                memset ( pci, 0, sizeof ( *pci ) );
-               pci_init ( pci, busdevfn );
+               pci_init ( pci, *busdevfn );
                if ( ( rc = pci_read_config ( pci ) ) != 0 )
                        continue;
 
@@ -267,7 +268,7 @@ int pci_find_next ( struct pci_device *pci, unsigned int busdevfn ) {
                }
 
                /* Return this device */
-               return busdevfn;
+               return 0;
        }
 
        return -ENODEV;
@@ -348,7 +349,7 @@ void pci_remove ( struct pci_device *pci ) {
  */
 static int pcibus_probe ( struct root_device *rootdev ) {
        struct pci_device *pci = NULL;
-       int busdevfn = 0;
+       uint32_t busdevfn = 0;
        int rc;
 
        for ( busdevfn = 0 ; 1 ; busdevfn++ ) {
@@ -362,8 +363,7 @@ static int pcibus_probe ( struct root_device *rootdev ) {
                }
 
                /* Find next PCI device, if any */
-               busdevfn = pci_find_next ( pci, busdevfn );
-               if ( busdevfn < 0 )
+               if ( ( rc = pci_find_next ( pci, &busdevfn ) ) != 0 )
                        break;
 
                /* Look for a driver */
index a2a811aa00f5deaf332fc386a69595317c54d3b3..515798baf1228eb6c9669bf02e39dc659c84242d 100644 (file)
@@ -58,7 +58,7 @@ static int pciscan_exec ( int argc, char **argv ) {
        struct named_setting setting;
        struct pci_device pci;
        unsigned long prev;
-       int next;
+       uint32_t busdevfn;
        int len;
        int rc;
 
@@ -75,17 +75,15 @@ static int pciscan_exec ( int argc, char **argv ) {
        if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
                                      NULL, &setting.setting, &prev ) ) < 0 ) {
                /* Setting not yet defined: start searching from 00:00.0 */
-               prev = 0;
+               busdevfn = 0;
        } else {
                /* Setting is defined: start searching from next location */
-               prev++;
+               busdevfn = ( prev + 1 );
        }
 
        /* Find next existent PCI device */
-       if ( ( next = pci_find_next ( &pci, prev ) ) < 0 ) {
-               rc = next;
+       if ( ( rc = pci_find_next ( &pci, &busdevfn ) ) != 0 )
                goto err_find_next;
-       }
 
        /* Apply default type if necessary.  Use ":uint16" rather than
         * ":busdevfn" to allow for easy inclusion within a
@@ -96,7 +94,7 @@ static int pciscan_exec ( int argc, char **argv ) {
 
        /* Store setting */
        if ( ( rc = storen_setting ( setting.settings, &setting.setting,
-                                    next ) ) != 0 ) {
+                                    busdevfn ) ) != 0 ) {
                printf ( "Could not store \"%s\": %s\n",
                         setting.setting.name, strerror ( rc ) );
                goto err_store;
index bf6174c23e2b8c1b9041c817963c2991db67942d..bd123679a8e79a7d89d9d04e5ade7beda7f1abcc 100644 (file)
@@ -301,7 +301,7 @@ extern void adjust_pci_device ( struct pci_device *pci );
 extern unsigned long pci_bar_start ( struct pci_device *pci,
                                     unsigned int reg );
 extern int pci_read_config ( struct pci_device *pci );
-extern int pci_find_next ( struct pci_device *pci, unsigned int busdevfn );
+extern int pci_find_next ( struct pci_device *pci, uint32_t *busdevfn );
 extern int pci_find_driver ( struct pci_device *pci );
 extern int pci_probe ( struct pci_device *pci );
 extern void pci_remove ( struct pci_device *pci );