|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v4 4/5] vPCI: move capability-list init
... both for when the functions are invoked and where they live in source.
Don't invoke them directly in vpci_init_header(), but instead first thing
in vpci_init_capabilities().
Suggested-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v4: New.
--- a/xen/drivers/vpci/cap.c
+++ b/xen/drivers/vpci/cap.c
@@ -159,15 +159,150 @@ static int vpci_ext_capability_hide(
return 0;
}
+static int vpci_init_capability_list(struct pci_dev *pdev)
+{
+ int rc;
+ bool mask_cap_list = false;
+ bool is_hwdom = is_hardware_domain(pdev->domain);
+
+ if ( pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST )
+ {
+ /* Only expose capabilities to the guest that vPCI can handle. */
+ unsigned int next, ttl = 48;
+ static const unsigned int supported_caps[] = {
+ PCI_CAP_ID_MSI,
+ PCI_CAP_ID_MSIX,
+ };
+ /*
+ * For dom0, we should expose all capabilities instead of a fixed
+ * capabilities array, so setting n to 0 here is to get the next
+ * capability position directly in pci_find_next_cap_ttl.
+ */
+ const unsigned int n = is_hwdom ? 0 : ARRAY_SIZE(supported_caps);
+
+ next = pci_find_next_cap_ttl(pdev->sbdf, PCI_CAPABILITY_LIST,
+ supported_caps, n, &ttl);
+
+ rc = vpci_add_register(pdev->vpci, vpci_read_val,
+ is_hwdom ? vpci_hw_write8 : NULL,
+ PCI_CAPABILITY_LIST, 1,
+ (void *)(uintptr_t)next);
+ if ( rc )
+ return rc;
+
+ next &= ~3;
+
+ if ( !next && !is_hwdom )
+ /*
+ * If we don't have any supported capabilities to expose to the
+ * guest, mask the PCI_STATUS_CAP_LIST bit in the status
+ * register.
+ */
+ mask_cap_list = true;
+
+ while ( next && ttl )
+ {
+ unsigned int pos = next;
+
+ next = pci_find_next_cap_ttl(pdev->sbdf,
+ pos + PCI_CAP_LIST_NEXT,
+ supported_caps, n, &ttl);
+
+ if ( !is_hwdom )
+ {
+ rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
+ pos + PCI_CAP_LIST_ID, 1, NULL);
+ if ( rc )
+ return rc;
+ }
+
+ rc = vpci_add_register(pdev->vpci, vpci_read_val,
+ is_hwdom ? vpci_hw_write8 : NULL,
+ pos + PCI_CAP_LIST_NEXT, 1,
+ (void *)(uintptr_t)next);
+ if ( rc )
+ return rc;
+
+ next &= ~3;
+ }
+ }
+
+ /* Return early for the hw domain, no masking of PCI_STATUS. */
+ if ( is_hwdom )
+ return 0;
+
+ /* Utilize rsvdp_mask to hide PCI_STATUS_CAP_LIST from the guest. */
+ return vpci_add_register_mask(pdev->vpci, vpci_hw_read16, vpci_hw_write16,
+ PCI_STATUS, 2, NULL,
+ PCI_STATUS_RO_MASK &
+ ~(mask_cap_list ? PCI_STATUS_CAP_LIST : 0),
+ PCI_STATUS_RW1C_MASK,
+ mask_cap_list ? PCI_STATUS_CAP_LIST : 0,
+ PCI_STATUS_RSVDZ_MASK);
+}
+
+static int vpci_init_ext_capability_list(const struct pci_dev *pdev)
+{
+ unsigned int pos = PCI_CFG_SPACE_SIZE;
+
+ if ( !pdev->ext_cfg )
+ return 0;
+
+ if ( !is_hardware_domain(pdev->domain) )
+ /* Extended capabilities read as zero, write ignore for DomU */
+ return vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+ pos, 4, (void *)0);
+
+ do
+ {
+ uint32_t header = pci_conf_read32(pdev->sbdf, pos);
+ int rc;
+
+ if ( header == 0xffffffffU )
+ {
+ printk(XENLOG_WARNING
+ "%pd %pp: broken extended cap list, offset %#x\n",
+ pdev->domain, &pdev->sbdf, pos);
+ return 0;
+ }
+
+ rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
+ pos, 4, (void *)(uintptr_t)header);
+ if ( rc == -EEXIST )
+ {
+ printk(XENLOG_WARNING
+ "%pd %pp: overlap in extended cap list, offset %#x\n",
+ pdev->domain, &pdev->sbdf, pos);
+ return 0;
+ }
+
+ if ( rc )
+ return rc;
+
+ pos = PCI_EXT_CAP_NEXT(header);
+ } while ( pos >= PCI_CFG_SPACE_SIZE );
+
+ return 0;
+}
+
int vpci_init_capabilities(struct pci_dev *pdev)
{
+ int rc;
+
+ rc = vpci_init_capability_list(pdev);
+ if ( rc )
+ return rc;
+
+ rc = vpci_init_ext_capability_list(pdev);
+ if ( rc )
+ return rc;
+
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);
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -744,132 +744,6 @@ static int bar_add_rangeset(const struct
return !bar->mem ? -ENOMEM : 0;
}
-static int vpci_init_capability_list(struct pci_dev *pdev)
-{
- int rc;
- bool mask_cap_list = false;
- bool is_hwdom = is_hardware_domain(pdev->domain);
-
- if ( pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST )
- {
- /* Only expose capabilities to the guest that vPCI can handle. */
- unsigned int next, ttl = 48;
- static const unsigned int supported_caps[] = {
- PCI_CAP_ID_MSI,
- PCI_CAP_ID_MSIX,
- };
- /*
- * For dom0, we should expose all capabilities instead of a fixed
- * capabilities array, so setting n to 0 here is to get the next
- * capability position directly in pci_find_next_cap_ttl.
- */
- const unsigned int n = is_hwdom ? 0 : ARRAY_SIZE(supported_caps);
-
- next = pci_find_next_cap_ttl(pdev->sbdf, PCI_CAPABILITY_LIST,
- supported_caps, n, &ttl);
-
- rc = vpci_add_register(pdev->vpci, vpci_read_val,
- is_hwdom ? vpci_hw_write8 : NULL,
- PCI_CAPABILITY_LIST, 1,
- (void *)(uintptr_t)next);
- if ( rc )
- return rc;
-
- next &= ~3;
-
- if ( !next && !is_hwdom )
- /*
- * If we don't have any supported capabilities to expose to the
- * guest, mask the PCI_STATUS_CAP_LIST bit in the status
- * register.
- */
- mask_cap_list = true;
-
- while ( next && ttl )
- {
- unsigned int pos = next;
-
- next = pci_find_next_cap_ttl(pdev->sbdf,
- pos + PCI_CAP_LIST_NEXT,
- supported_caps, n, &ttl);
-
- if ( !is_hwdom )
- {
- rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
- pos + PCI_CAP_LIST_ID, 1, NULL);
- if ( rc )
- return rc;
- }
-
- rc = vpci_add_register(pdev->vpci, vpci_read_val,
- is_hwdom ? vpci_hw_write8 : NULL,
- pos + PCI_CAP_LIST_NEXT, 1,
- (void *)(uintptr_t)next);
- if ( rc )
- return rc;
-
- next &= ~3;
- }
- }
-
- /* Return early for the hw domain, no masking of PCI_STATUS. */
- if ( is_hwdom )
- return 0;
-
- /* Utilize rsvdp_mask to hide PCI_STATUS_CAP_LIST from the guest. */
- return vpci_add_register_mask(pdev->vpci, vpci_hw_read16, vpci_hw_write16,
- PCI_STATUS, 2, NULL,
- PCI_STATUS_RO_MASK &
- ~(mask_cap_list ? PCI_STATUS_CAP_LIST : 0),
- PCI_STATUS_RW1C_MASK,
- mask_cap_list ? PCI_STATUS_CAP_LIST : 0,
- PCI_STATUS_RSVDZ_MASK);
-}
-
-static int vpci_init_ext_capability_list(const struct pci_dev *pdev)
-{
- unsigned int pos = PCI_CFG_SPACE_SIZE;
-
- if ( !pdev->ext_cfg )
- return 0;
-
- if ( !is_hardware_domain(pdev->domain) )
- /* Extended capabilities read as zero, write ignore for DomU */
- return vpci_add_register(pdev->vpci, vpci_read_val, NULL,
- pos, 4, (void *)0);
-
- do
- {
- uint32_t header = pci_conf_read32(pdev->sbdf, pos);
- int rc;
-
- if ( header == 0xffffffffU )
- {
- printk(XENLOG_WARNING
- "%pd %pp: broken extended cap list, offset %#x\n",
- pdev->domain, &pdev->sbdf, pos);
- return 0;
- }
-
- rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
- pos, 4, (void *)(uintptr_t)header);
- if ( rc == -EEXIST )
- {
- printk(XENLOG_WARNING
- "%pd %pp: overlap in extended cap list, offset %#x\n",
- pdev->domain, &pdev->sbdf, pos);
- return 0;
- }
-
- if ( rc )
- return rc;
-
- pos = PCI_EXT_CAP_NEXT(header);
- } while ( pos >= PCI_CFG_SPACE_SIZE );
-
- return 0;
-}
-
int vpci_init_header(struct pci_dev *pdev)
{
uint16_t cmd;
@@ -918,14 +792,6 @@ int vpci_init_header(struct pci_dev *pde
if ( rc )
return rc;
- rc = vpci_init_capability_list(pdev);
- if ( rc )
- return rc;
-
- rc = vpci_init_ext_capability_list(pdev);
- if ( rc )
- return rc;
-
if ( pdev->ignore_bars )
return 0;
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |