[pci] Generalise pci_num_bus() to pci_discover()

Allow pci_find_next() to discover devices beyond the first PCI
segment, by generalising pci_num_bus() (which implicitly assumes that
there is only a single PCI segment) with pci_discover() (which has the
ability to return an arbitrary contiguous chunk of PCI bus:dev.fn
address space).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2022-09-15 16:47:04 +01:00
parent 56b30364c5
commit ff228f745c
10 changed files with 78 additions and 43 deletions
+8 -5
View File
@@ -33,14 +33,17 @@ extern int efipci_write ( struct pci_device *pci, unsigned long location,
unsigned long value );
/**
* Determine number of PCI buses within system
* Find next PCI bus:dev.fn address range in system
*
* @ret num_bus Number of buses
* @v busdevfn Starting PCI bus:dev.fn address
* @v range PCI bus:dev.fn address range to fill in
*/
static inline __always_inline int
PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
static inline __always_inline void
PCIAPI_INLINE ( efi, pci_discover ) ( uint32_t busdevfn __unused,
struct pci_range *range ) {
/* EFI does not want us to scan the PCI bus ourselves */
return 0;
range->count = 0;
}
/**
+10 -6
View File
@@ -23,14 +23,18 @@ extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
unsigned long value, size_t len );
/**
* Determine number of PCI buses within system
* Find next PCI bus:dev.fn address range in system
*
* @ret num_bus Number of buses
* @v busdevfn Starting PCI bus:dev.fn address
* @v range PCI bus:dev.fn address range to fill in
*/
static inline __always_inline int
PCIAPI_INLINE ( linux, pci_num_bus ) ( void ) {
/* Assume all buses may exist */
return 0x100;
static inline __always_inline void
PCIAPI_INLINE ( linux, pci_discover ) ( uint32_t busdevfn __unused,
struct pci_range *range ) {
/* Assume all buses in segment 0 may exist */
range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
range->count = PCI_BUSDEVFN ( 1, 0, 0, 0 );
}
/**
-3
View File
@@ -262,9 +262,6 @@ struct pci_driver {
#define PCI_BUS( busdevfn ) ( ( (busdevfn) >> 8 ) & 0xff )
#define PCI_SLOT( busdevfn ) ( ( (busdevfn) >> 3 ) & 0x1f )
#define PCI_FUNC( busdevfn ) ( ( (busdevfn) >> 0 ) & 0x07 )
#define PCI_BUSDEVFN( segment, bus, slot, func ) \
( ( (segment) << 16 ) | ( (bus) << 8 ) | \
( (slot) << 3 ) | ( (func) << 0 ) )
#define PCI_FIRST_FUNC( busdevfn ) ( (busdevfn) & ~0x07 )
#define PCI_LAST_FUNC( busdevfn ) ( (busdevfn) | 0x07 )
+18 -3
View File
@@ -14,6 +14,20 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/iomap.h>
#include <config/ioapi.h>
struct pci_device;
/** A PCI bus:dev.fn address range */
struct pci_range {
/** Starting bus:dev.fn address */
uint32_t start;
/** Number of bus:dev.fn addresses within this range */
unsigned int count;
};
#define PCI_BUSDEVFN( segment, bus, slot, func ) \
( ( (segment) << 16 ) | ( (bus) << 8 ) | \
( (slot) << 3 ) | ( (func) << 0 ) )
/**
* Calculate static inline PCI I/O API function name
*
@@ -51,11 +65,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <bits/pci_io.h>
/**
* Determine number of PCI buses within system
* Find next PCI bus:dev.fn address range in system
*
* @ret num_bus Number of buses
* @v busdevfn Starting PCI bus:dev.fn address
* @v range PCI bus:dev.fn address range to fill in
*/
int pci_num_bus ( void );
void pci_discover ( uint32_t busdevfn, struct pci_range *range );
/**
* Read byte from PCI configuration space