vpci: Refactor REGISTER_VPCI_INIT

Refactor REGISTER_VPCI_INIT to contain more capability specific
information, this will benefit further follow-on changes to hide
capability when initialization fails.

What's more, change the definition of init_header() since it is
not a capability and it is needed for all devices' PCI config space.

After refactor, the "priority" of initializing capabilities isn't
needed anymore, so delete its related codes.

Note:
Call vpci_make_msix_hole() in the end of init_msix() since the change
of sequence of init_header() and init_msix().

The cleanup hook is also added in this change, even if it's still
unused. Further changes will make use of it.

Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
This commit is contained in:
Jiqian Chen authored and Jan Beulich committed 2025-07-30 12:04:08 +02:00
1 parent a492ec7b01
commit ee2eb6849d
11 files changed
+70 -32

No files matched your search

+1 -2
View File
@@ -57,6 +57,7 @@ SECTIONS
*(.rodata)
*(.rodata.*)
VPCI_ARRAY
*(.data.rel.ro)
*(.data.rel.ro.*)
@@ -64,8 +65,6 @@ SECTIONS
__proc_info_start = .;
*(.proc.info)
__proc_info_end = .;
VPCI_ARRAY
} :text
#if defined(BUILD_ID)
+1 -2
View File
@@ -51,11 +51,10 @@ SECTIONS
*(.rodata)
*(.rodata.*)
VPCI_ARRAY
*(.data.rel.ro)
*(.data.rel.ro.*)
VPCI_ARRAY
. = ALIGN(POINTER_ALIGN);
} :text
+1 -2
View File
@@ -46,11 +46,10 @@ SECTIONS
*(.rodata)
*(.rodata.*)
VPCI_ARRAY
*(.data.rel.ro)
*(.data.rel.ro.*)
VPCI_ARRAY
. = ALIGN(POINTER_ALIGN);
} :text
+1 -1
View File
@@ -135,6 +135,7 @@ SECTIONS
*(.rodata)
*(.rodata.*)
VPCI_ARRAY
*(.data.rel.ro)
*(.data.rel.ro.*)
@@ -148,7 +149,6 @@ SECTIONS
*(.note.gnu.build-id)
__note_gnu_build_id_end = .;
#endif
VPCI_ARRAY
} PHDR(text)
#if defined(CONFIG_PVH_GUEST) && !defined(EFI)
+1 -2
View File
@@ -858,7 +858,7 @@ static int vpci_init_ext_capability_list(const struct pci_dev *pdev)
return 0;
}
static int cf_check init_header(struct pci_dev *pdev)
int vpci_init_header(struct pci_dev *pdev)
{
uint16_t cmd;
uint64_t addr, size;
@@ -1054,7 +1054,6 @@ static int cf_check init_header(struct pci_dev *pdev)
pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd);
return rc;
}
REGISTER_VPCI_INIT(init_header, VPCI_PRIORITY_MIDDLE);
/*
* Local variables:
+1 -1
View File
@@ -270,7 +270,7 @@ static int cf_check init_msi(struct pci_dev *pdev)
return 0;
}
REGISTER_VPCI_INIT(init_msi, VPCI_PRIORITY_LOW);
REGISTER_VPCI_CAP(MSI, init_msi, NULL);
void vpci_dump_msi(void)
{
+7 -2
View File
@@ -703,9 +703,14 @@ static int cf_check init_msix(struct pci_dev *pdev)
pdev->vpci->msix = msix;
list_add(&msix->next, &d->arch.hvm.msix_tables);
return 0;
/*
* vPCI header initialization will have mapped the whole BAR into the
* p2m, as MSI-X capability was not yet initialized. Crave a hole for
* the MSI-X table here, so that Xen can trap accesses.
*/
return vpci_make_msix_hole(pdev);
}
REGISTER_VPCI_INIT(init_msix, VPCI_PRIORITY_HIGH);
REGISTER_VPCI_CAP(MSIX, init_msix, NULL);
/*
* Local variables:
+1 -1
View File
@@ -118,7 +118,7 @@ static int cf_check init_rebar(struct pci_dev *pdev)
return 0;
}
REGISTER_VPCI_INIT(init_rebar, VPCI_PRIORITY_LOW);
REGISTER_VPCI_EXTCAP(REBAR, init_rebar, NULL);
/*
* Local variables:
+34 -10
View File
@@ -36,8 +36,8 @@ struct vpci_register {
};
#ifdef __XEN__
extern vpci_register_init_t *const __start_vpci_array[];
extern vpci_register_init_t *const __end_vpci_array[];
extern const vpci_capability_t __start_vpci_array[];
extern const vpci_capability_t __end_vpci_array[];
#define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array)
#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
@@ -83,6 +83,32 @@ static int assign_virtual_sbdf(struct pci_dev *pdev)
#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */
static int vpci_init_capabilities(struct pci_dev *pdev)
{
for ( unsigned int i = 0; i < NUM_VPCI_INIT; i++ )
{
const vpci_capability_t *capability = &__start_vpci_array[i];
const unsigned int cap = capability->id;
const bool is_ext = capability->is_ext;
unsigned int pos = 0;
int rc;
if ( !is_ext )
pos = pci_find_cap_offset(pdev->sbdf, cap);
else if ( is_hardware_domain(pdev->domain) )
pos = pci_find_ext_capability(pdev->sbdf, cap);
if ( !pos )
continue;
rc = capability->init(pdev);
if ( rc )
return rc;
}
return 0;
}
void vpci_deassign_device(struct pci_dev *pdev)
{
unsigned int i;
@@ -128,7 +154,6 @@ void vpci_deassign_device(struct pci_dev *pdev)
int vpci_assign_device(struct pci_dev *pdev)
{
unsigned int i;
const unsigned long *ro_map;
int rc = 0;
@@ -159,14 +184,13 @@ int vpci_assign_device(struct pci_dev *pdev)
goto out;
#endif
for ( i = 0; i < NUM_VPCI_INIT; i++ )
{
rc = __start_vpci_array[i](pdev);
if ( rc )
break;
}
rc = vpci_init_header(pdev);
if ( rc )
goto out;
out: __maybe_unused;
rc = vpci_init_capabilities(pdev);
out:
if ( rc )
vpci_deassign_device(pdev);
+21 -8
View File
@@ -13,11 +13,12 @@ typedef uint32_t vpci_read_t(const struct pci_dev *pdev, unsigned int reg,
typedef void vpci_write_t(const struct pci_dev *pdev, unsigned int reg,
uint32_t val, void *data);
typedef int vpci_register_init_t(struct pci_dev *dev);
#define VPCI_PRIORITY_HIGH "1"
#define VPCI_PRIORITY_MIDDLE "5"
#define VPCI_PRIORITY_LOW "9"
typedef struct {
unsigned int id;
bool is_ext;
int (* init)(struct pci_dev *pdev);
int (* cleanup)(const struct pci_dev *pdev);
} vpci_capability_t;
#define VPCI_ECAM_BDF(addr) (((addr) & 0x0ffff000) >> 12)
@@ -29,9 +30,21 @@ typedef int vpci_register_init_t(struct pci_dev *dev);
*/
#define VPCI_MAX_VIRT_DEV (PCI_SLOT(~0) + 1)
#define REGISTER_VPCI_INIT(x, p) \
static vpci_register_init_t *const x##_entry \
__used_section(".data.vpci." p) = (x)
#define REGISTER_VPCI_CAPABILITY(cap, name, finit, fclean, ext) \
static const vpci_capability_t name##_entry \
__used_section(".data.rel.ro.vpci") = { \
.id = (cap), \
.init = (finit), \
.cleanup = (fclean), \
.is_ext = (ext), \
}
#define REGISTER_VPCI_CAP(name, finit, fclean) \
REGISTER_VPCI_CAPABILITY(PCI_CAP_ID_##name, name, finit, fclean, false)
#define REGISTER_VPCI_EXTCAP(name, finit, fclean) \
REGISTER_VPCI_CAPABILITY(PCI_EXT_CAP_ID_##name, name, finit, fclean, true)
int __must_check vpci_init_header(struct pci_dev *pdev);
/* Assign vPCI to device by adding handlers. */
int __must_check vpci_assign_device(struct pci_dev *pdev);
+1 -1
View File
@@ -188,7 +188,7 @@
#define VPCI_ARRAY \
. = ALIGN(POINTER_ALIGN); \
__start_vpci_array = .; \
*(SORT(.data.vpci.*)) \
*(.data.rel.ro.vpci) \
__end_vpci_array = .;
#else
#define VPCI_ARRAY
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.