pci: Introduce parse_pci_sbdf{_seg}()
PATCH v2 1/15 pci: Introduce parse_pci_sbdf{_seg}()
In reply to a message not in the archiveIn many places, we're parsing a PCI string into individual parts (seg, bus, dev, fn) and then transform it into a pci_sbdf_t using PCI_SBDF macro. Rather than converting from parts to pci_sbdf_t and vice versa, introduce a new function that parses a PCI string into a pci_sbdf_t structure directly.
--- xen/drivers/pci/pci.c | 18 ++++++++++++++++++ xen/include/xen/pci.h | 3 +++ 2 files changed, 21 insertions(+)
xen/drivers/pci/pci.c +18 -0
@@ -202,3 +202,21 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,return s; } + +const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci (s, &seg, &bus, &dev, &func); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out; +} + +const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci_seg (s, &seg, &bus, &dev, &func, def_seg); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out; +}
xen/include/xen/pci.h +3 -0
@@ -280,6 +280,9 @@ const char *parse_pci_seg(const char *s, unsigned int *seg_p, unsigned int *bus_p, unsigned int *dev_p, unsigned int *func_p, bool *def_seg); +const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf); +const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg); +#define PCI_BAR_VF (1u << 0)#define PCI_BAR_LAST (1u << 1)#define PCI_BAR_ROM (1u << 2)
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 2/15 vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
In reply to a message not in the archiveUse a dedicated pci_sbdf_t struct that we update instead of recreating one each time we need it.
No functional change intended.
--- xen/drivers/passthrough/vtd/dmar.c | 43 ++++++++++++------------------ 1 file changed, 17 insertions(+), 26 deletions(-)
xen/drivers/passthrough/vtd/dmar.c +17 -26
@@ -310,7 +310,7 @@ static int __init acpi_parse_dev_scope( {struct acpi_ioapic_unit *acpi_ioapic_unit;const struct acpi_dmar_device_scope *acpi_scope; -u16 bus, sub_bus, sec_bus; +u16 sub_bus, sec_bus;const struct acpi_dmar_pci_path *path;struct acpi_drhd_unit *drhd = type ==DMAR_TYPE ? container_of(scope, struct acpi_drhd_unit, scope) : NULL;
@@ -332,29 +332,27 @@ static int __init acpi_parse_dev_scope(while ( start < end ) { +pci_sbdf_t dev_sbdf; acpi_scope = start; path = (const void *)(acpi_scope +1 ); depth = (acpi_scope->length -sizeof (*acpi_scope)) /sizeof (*path); - bus = acpi_scope->bus; + dev_sbdf =PCI_SBDF (seg, acpi_scope->bus, path->dev, path->fn);while ( --depth >0 ) { - bus =pci_conf_read8 (PCI_SBDF (seg, bus, path->dev, path->fn), -PCI_SECONDARY_BUS ); + dev_sbdf.bus =pci_conf_read8 (dev_sbdf,PCI_SECONDARY_BUS ); path++; + dev_sbdf.devfn =PCI_DEVFN (path->dev, path->fn); }switch ( acpi_scope->entry_type ) {case ACPI_DMAR_SCOPE_TYPE_BRIDGE : - sec_bus =pci_conf_read8 (PCI_SBDF (seg, bus, path->dev, path->fn), -PCI_SECONDARY_BUS ); - sub_bus =pci_conf_read8 (PCI_SBDF (seg, bus, path->dev, path->fn), -PCI_SUBORDINATE_BUS ); + sec_bus =pci_conf_read8 (dev_sbdf,PCI_SECONDARY_BUS ); + sub_bus =pci_conf_read8 (dev_sbdf,PCI_SUBORDINATE_BUS );if ( iommu_verbose )printk (VTDPREFIX " bridge: %pp start=%x sec=%x sub=%x\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn), - acpi_scope->bus, sec_bus, sub_bus); + &dev_sbdf, acpi_scope->bus, sec_bus, sub_bus);dmar_scope_add_buses (scope, sec_bus, sub_bus); gfx_only = false;
@@ -362,8 +360,7 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_HPET :if ( iommu_verbose ) -printk (VTDPREFIX " MSI HPET: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " MSI HPET: %pp\n" , &dev_sbdf);if ( drhd ) {
@@ -374,9 +371,7 @@ static int __init acpi_parse_dev_scope(if ( !acpi_hpet_unit ) goto out; acpi_hpet_unit->id = acpi_scope->enumeration_id; - acpi_hpet_unit->bus = bus; - acpi_hpet_unit->dev = path->dev; - acpi_hpet_unit->func = path->fn; + acpi_hpet_unit->bdf = dev_sbdf.bdf;list_add (&acpi_hpet_unit->list, &drhd->hpet_list); gfx_only = false;
@@ -386,16 +381,15 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_ENDPOINT :if ( iommu_verbose ) -printk (VTDPREFIX " endpoint: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " endpoint: %pp\n" , &dev_sbdf); -if ( drhd &&pci_device_detect (seg, bus, path->dev, path->fn) ) +if ( drhd &&pci_device_detect (seg, dev_sbdf.bus, dev_sbdf.dev, dev_sbdf.fn) ) { -if (pci_conf_read8 (PCI_SBDF (seg, bus, path->dev, path->fn), +if (pci_conf_read8 (dev_sbdf,PCI_CLASS_DEVICE +1 ) !=0x03 /* PCI_BASE_CLASS_DISPLAY */ ) gfx_only = false; -else if ( !seg && !bus && path->dev ==2 && !path->fn ) +else if ( !seg && !dev_sbdf.bus && path->dev ==2 && !path->fn ) igd_drhd_address = drhd->address; }
@@ -403,8 +397,7 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_IOAPIC :if ( iommu_verbose ) -printk (VTDPREFIX " IOAPIC: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " IOAPIC: %pp\n" , &dev_sbdf);if ( drhd ) {
@@ -413,9 +406,7 @@ static int __init acpi_parse_dev_scope(if ( !acpi_ioapic_unit ) goto out; acpi_ioapic_unit->apic_id = acpi_scope->enumeration_id; - acpi_ioapic_unit->ioapic.bdf.bus = bus; - acpi_ioapic_unit->ioapic.bdf.dev = path->dev; - acpi_ioapic_unit->ioapic.bdf.func = path->fn; + acpi_ioapic_unit->ioapic.info = dev_sbdf.bdf;list_add (&acpi_ioapic_unit->list, &drhd->ioapic_list); gfx_only = false;
@@ -431,7 +422,7 @@ static int __init acpi_parse_dev_scope( gfx_only = false;continue ; } - scope->devices[didx++] =PCI_BDF (bus, path->dev, path->fn); + scope->devices[didx++] = dev_sbdf.bdf; start += acpi_scope->length; }
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 3/15 pci: Use pci_sbdf_t in pci_device_detect()
In reply to a message not in the archiveUse a single pci_sbdf_t instead of each of its part as individual parameters.
ehci-dbgp will now parse a PCI segment (if specified), even if it's not used afterward.
--- xen/drivers/char/ehci-dbgp.c | 33 ++++++++++++++---------------- xen/drivers/passthrough/pci.c | 16 +++++++-------- xen/drivers/passthrough/vtd/dmar.c | 33 ++++++++++++------------------ xen/include/xen/pci.h | 2 +- 4 files changed, 37 insertions(+), 47 deletions(-)
xen/drivers/char/ehci-dbgp.c +15 -18
@@ -681,16 +681,14 @@ static int dbgp_control_msg(struct ehci_dbgp *dbgp, unsigned int devnum,return ret; } -static unsigned int __init __find_dbgp (u8 bus,u8 slot,u8 func) +static unsigned int __init __find_dbgp (pci_sbdf_t sbdf) { -uint32_t class =pci_conf_read32 (PCI_SBDF (0 , bus, slot, func), -PCI_CLASS_REVISION ); +uint32_t class =pci_conf_read32 (sbdf,PCI_CLASS_REVISION );if ( (class >>8 ) !=PCI_CLASS_SERIAL_USB_EHCI )return 0 ; -return pci_find_cap_offset (PCI_SBDF (0 , bus, slot, func), -PCI_CAP_ID_EHCI_DEBUG ); +return pci_find_cap_offset (sbdf,PCI_CAP_ID_EHCI_DEBUG ); } static unsigned int __init find_dbgp(struct ehci_dbgp *dbgp,
@@ -704,20 +702,20 @@ static unsigned int __init find_dbgp(struct ehci_dbgp *dbgp, {for ( func =0 ; func <8 ; func++ ) { +pci_sbdf_t sbdf =PCI_SBDF (0 , bus, slot, func);unsigned int cap; -if ( !pci_device_detect (0 , bus, slot, func) ) +if ( !pci_device_detect (sbdf) ) {if ( !func )break ;continue ; } - cap =__find_dbgp (bus, slot, func); + cap =__find_dbgp (sbdf);if ( !cap || ehci_num-- ) { -if ( !func && !(pci_conf_read8 (PCI_SBDF (0 , bus, slot, func), -PCI_HEADER_TYPE ) &0x80 ) ) +if ( !func && !(pci_conf_read8 (sbdf,PCI_HEADER_TYPE ) &0x80 ) )break ;continue ; }
@@ -1510,25 +1508,24 @@ void __init ehci_dbgp_init(void) }else if (strncmp (opt_dbgp +4 ,"@pci" ,4 ) ==0 ) { -unsigned int bus, slot, func; +pci_sbdf_t sbdf =PCI_SBDF (0 ,0 ,0 ,0 ); - e =parse_pci (opt_dbgp +8 ,NULL , &bus, &slot, &func); + e =parse_pci_sbdf (opt_dbgp +8 , &sbdf);if ( !e || *e )return ; - dbgp->bus = bus; - dbgp->slot = slot; - dbgp->func = func; + dbgp->bus = sbdf.bus; + dbgp->slot = sbdf.dev; + dbgp->func = sbdf.fn; -if ( !pci_device_detect (0 , bus, slot, func) ) +if ( !pci_device_detect (sbdf) )return ; - dbgp->cap =__find_dbgp (bus, slot, func); + dbgp->cap =__find_dbgp (sbdf);if ( !dbgp->cap )return ; -dbgp_printk ("Using EHCI debug port on %02x:%02x.%u\n" , - bus, slot, func); +dbgp_printk ("Using EHCI debug port on %pp\n" , &sbdf); }else return ;
xen/drivers/passthrough/pci.c +8 -8
@@ -1166,11 +1166,11 @@ out:return ret; } -bool __init pci_device_detect (u16 seg,u8 bus,u8 dev,u8 func) +bool __init pci_device_detect (pci_sbdf_t sbdf) {u32 vendor; - vendor =pci_conf_read32 (PCI_SBDF (seg, bus, dev, func),PCI_VENDOR_ID ); + vendor =pci_conf_read32 (sbdf,PCI_VENDOR_ID );/* some broken boards return 0 or ~0 if a slot is empty: */ if ( (vendor ==0xffffffffU ) || (vendor ==0x00000000U ) || (vendor ==0x0000ffffU ) || (vendor ==0xffff0000U ) )
@@ -1221,24 +1221,24 @@ static int __init cf_check _scan_pci_devices(struct pci_seg *pseg, void *arg) {for ( func =0 ; func <8 ; func++ ) { -if ( !pci_device_detect (pseg->nr, bus, dev, func) ) +pci_sbdf_t sbdf =PCI_SBDF (pseg->nr, bus, dev, func); + +if ( !pci_device_detect (sbdf) ) {if ( !func )break ;continue ; } - pdev =alloc_pdev (pseg, bus,PCI_DEVFN (dev, func)); + pdev =alloc_pdev (pseg, bus, sbdf.devfn);if ( !pdev ) {printk (XENLOG_WARNING "%pp: alloc_pdev failed\n" , - &PCI_SBDF (pseg->nr, bus, dev, func)); + &sbdf);return -ENOMEM ; } -if ( !func && !(pci_conf_read8 (PCI_SBDF (pseg->nr, bus, dev, - func), -PCI_HEADER_TYPE ) &0x80 ) ) +if ( !func && !(pci_conf_read8 (sbdf,PCI_HEADER_TYPE ) &0x80 ) )break ; } }
xen/drivers/passthrough/vtd/dmar.c +13 -20
@@ -383,7 +383,7 @@ static int __init acpi_parse_dev_scope(if ( iommu_verbose )printk (VTDPREFIX " endpoint: %pp\n" , &dev_sbdf); -if ( drhd &&pci_device_detect (seg, dev_sbdf.bus, dev_sbdf.dev, dev_sbdf.fn) ) +if ( drhd &&pci_device_detect (dev_sbdf) ) {if (pci_conf_read8 (dev_sbdf, PCI_CLASS_DEVICE + 1) != 0x03
@@ -506,7 +506,6 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)acpi_register_drhd_unit (dmaru); else { -u8 b, d, f;unsigned int i =0 ;union {const void *raw;
@@ -520,18 +519,16 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)for ( p.raw = dev_scope_start; i < dmaru->scope.devices_cnt; i++, p.raw += p.scope->length ) { +pci_sbdf_t sbdf =PCI_SBDF (drhd->segment, dmaru->scope.devices[i]); +if ( p.scope->entry_type ==ACPI_DMAR_SCOPE_TYPE_IOAPIC || p.scope->entry_type ==ACPI_DMAR_SCOPE_TYPE_HPET )continue ; - b =PCI_BUS (dmaru->scope.devices[i]); - d =PCI_SLOT (dmaru->scope.devices[i]); - f =PCI_FUNC (dmaru->scope.devices[i]); - -if ( !pci_device_detect (drhd->segment, b, d, f) ) +if ( !pci_device_detect (sbdf) ) printk(XENLOG_WARNING VTDPREFIX" Non-existent device (%pp) in this DRHD's scope!\n" , - &PCI_SBDF (drhd->segment, b, d, f)); + &sbdf); }acpi_register_drhd_unit (dmaru);
@@ -560,17 +557,14 @@ static int __init register_one_rmrr(struct acpi_rmrr_unit *rmrru)for ( ; i < rmrru->scope.devices_cnt; i++ ) { -u8 b =PCI_BUS (rmrru->scope.devices[i]); -u8 d =PCI_SLOT (rmrru->scope.devices[i]); -u8 f =PCI_FUNC (rmrru->scope.devices[i]); +pci_sbdf_t sbdf =PCI_SBDF (rmrru->segment, rmrru->scope.devices[i]); -if (pci_device_detect (rmrru->segment, b, d, f) ==0 ) +if (pci_device_detect (sbdf) ==0 ) { dprintk(XENLOG_WARNING VTDPREFIX," Non-existent device (%pp) is reported" " in RMRR [%" PRIx64", %" PRIx64"]'s scope!\n" , - &PCI_SBDF (rmrru->segment, b, d, f), - rmrru->base_address, rmrru->end_address); + &sbdf, rmrru->base_address, rmrru->end_address); ignore = true; }else
@@ -754,15 +748,13 @@ static int __init register_one_satc(struct acpi_satc_unit *satcu)for ( ; i < satcu->scope.devices_cnt; i++ ) { -uint8_t b =PCI_BUS (satcu->scope.devices[i]); -uint8_t d =PCI_SLOT (satcu->scope.devices[i]); -uint8_t f =PCI_FUNC (satcu->scope.devices[i]); +pci_sbdf_t sbdf =PCI_SBDF (satcu->segment, satcu->scope.devices[i]); -if ( !pci_device_detect (satcu->segment, b, d, f) ) +if ( !pci_device_detect (sbdf) ) { dprintk(XENLOG_WARNING VTDPREFIX," Non-existent device (%pp) is reported in SATC scope!\n" , - &PCI_SBDF(satcu->segment, b, d, f)); + &sbdf); ignore = true; }else
@@ -1185,8 +1177,9 @@ int cf_check intel_iommu_get_reserved_device_memory( static int __init cf_check parse_rmrr_param(const char *str) {const char *s = str, *cur, *stmp; -unsigned int seg, bus, dev, func, dev_count; +unsigned int dev_count;unsigned long start, end; +pci_sbdf_t sbdf; do { if ( nr_rmrr >= MAX_USER_RMRR )
xen/include/xen/pci.h +1 -1
@@ -218,7 +218,7 @@ static always_inline bool pcidevs_trylock(void)#endif bool pci_known_segment (u16 seg); -bool pci_device_detect (u16 seg,u8 bus,u8 dev,u8 func); +bool pci_device_detect (pci_sbdf_t sbdf);int scan_pci_devices (void );enum pdev_type pdev_type (u16 seg,u8 bus,u8 devfn);int find_upstream_bridge (u16 seg,u8 *bus,u8 *devfn,u8 *secbus);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 4/15 pci: Parse into pci_sbdf_t directly
In reply to a message not in the archiveUse the newly introduced parse_pci_sbdf() and parse_pci_sbdf_seg() in order to parse into a pci_sbdf_t directly instead of reconstructing it afterward.
--- xen/drivers/char/ns16550.c | 24 +++++++++++----------- xen/drivers/char/xhci-dbc.c | 6 +++--- xen/drivers/passthrough/amd/iommu_acpi.c | 26 ++++++++++++------------ xen/drivers/passthrough/vtd/dmar.c | 7 +++---- 4 files changed, 31 insertions(+), 32 deletions(-)
xen/drivers/char/ns16550.c +12 -12
@@ -1572,22 +1572,22 @@ static bool __init parse_positional(struct ns16550 *uart, char **str)#ifdef CONFIG_HAS_PCI if ( *conf ==',' && *++conf !=',' ) { -unsigned int b, d, f; +pci_sbdf_t sbdf; - conf =parse_pci (conf,NULL , &b, &d, &f); + conf =parse_pci_sbdf (conf, &sbdf);if ( !conf )PARSE_ERR_RET ("Bad port PCI coordinates" ); - uart->pci_device =PCI_SBDF (0 , b, d, f); + uart->pci_device = sbdf; uart->ps_bdf_enable = true; }if ( *conf ==',' && *++conf !=',' ) { -unsigned int b, d, f; +pci_sbdf_t sbdf; -if ( !parse_pci (conf,NULL , &b, &d, &f) ) +if ( !parse_pci_sbdf (conf, &sbdf) )PARSE_ERR_RET ("Bad bridge PCI coordinates" ); - uart->pci_bridge =PCI_SBDF (0 , b, d, f); + uart->pci_bridge = sbdf; uart->pb_bdf_enable = true; }#endif
@@ -1671,22 +1671,22 @@ static bool __init parse_namevalue_pairs(char *str, struct ns16550 *uart)case port_bdf: { -unsigned int b, d, f; +pci_sbdf_t sbdf; -if ( !parse_pci (param_value,NULL , &b, &d, &f) ) +if ( !parse_pci_sbdf (param_value, &sbdf) )PARSE_ERR_RET ("Bad port PCI coordinates\n" ); - uart->pci_device =PCI_SBDF (0 , b, d, f); + uart->pci_device = sbdf; uart->ps_bdf_enable = true;break ; }case bridge_bdf: { -unsigned int b, d, f; +pci_sbdf_t sbdf; -if ( !parse_pci (param_value,NULL , &b, &d, &f) ) +if ( !parse_pci_sbdf (param_value, &sbdf) )PARSE_ERR_RET ("Bad bridge PCI coordinates\n" ); - uart->pci_bridge =PCI_SBDF (0 , b, d, f); + uart->pci_bridge = sbdf; uart->pb_bdf_enable = true;break ; }
xen/drivers/char/xhci-dbc.c +3 -3
@@ -1357,9 +1357,9 @@ static int __init cf_check xhci_parse_dbgp(const char *opt_dbgp) }else if (strncmp (opt_dbgp +4 ,"@pci" ,4 ) ==0 ) { -unsigned int bus, slot, func; +pci_sbdf_t sbdf; - e =parse_pci (opt_dbgp +8 ,NULL , &bus, &slot, &func); + e =parse_pci_sbdf (opt_dbgp +8 , &sbdf);if ( !e || (*e && *e !=',' ) ) { printk(XENLOG_ERR
@@ -1368,7 +1368,7 @@ static int __init cf_check xhci_parse_dbgp(const char *opt_dbgp)return -EINVAL ; } - dbc->sbdf =PCI_SBDF (0 , bus, slot, func); + dbc->sbdf = sbdf; } opt = e;
xen/drivers/passthrough/amd/iommu_acpi.c +13 -13
@@ -682,8 +682,8 @@ static int __init cf_check parse_ivrs_ioapic(const char *str) {const char *s = str;unsigned long id; -unsigned int seg, bus, dev, func;unsigned int idx; +pci_sbdf_t sbdf;if ( *s !='[' )return -EINVAL ;
@@ -692,7 +692,7 @@ static int __init cf_check parse_ivrs_ioapic(const char *str)if ( *s !=']' || *++s !='=' )return -EINVAL ; - s =parse_pci (s +1 , &seg, &bus, &dev, &func); + s =parse_pci_sbdf (s +1 , &sbdf);if ( !s || *s )return -EINVAL ;
@@ -707,7 +707,7 @@ static int __init cf_check parse_ivrs_ioapic(const char *str) } } - ioapic_sbdf[idx].sbdf =PCI_SBDF (seg, bus, dev, func); + ioapic_sbdf[idx].sbdf = sbdf; ioapic_sbdf[idx].id = id; ioapic_sbdf[idx].cmdline = true;
@@ -719,7 +719,7 @@ static int __init cf_check parse_ivrs_hpet(const char *str) {const char *s = str;unsigned long id; -unsigned int seg, bus, dev, func; +pci_sbdf_t sbdf;if ( *s !='[' )return -EINVAL ;
@@ -728,12 +728,12 @@ static int __init cf_check parse_ivrs_hpet(const char *str) if ( id != (typeof(hpet_sbdf.id))id || *s != ']' || *++s != '=' )return -EINVAL ; - s =parse_pci (s +1 , &seg, &bus, &dev, &func); + s =parse_pci_sbdf (s +1 , &sbdf);if ( !s || *s )return -EINVAL ; hpet_sbdf.id = id; - hpet_sbdf.sbdf =PCI_SBDF (seg, bus, dev, func); + hpet_sbdf.sbdf = sbdf; hpet_sbdf.init =HPET_CMDL ;return 0 ;
@@ -1399,13 +1399,13 @@ static int __init cf_check parse_ivmd_param(const char *s) } do { - unsigned int seg, bus, dev, func; + pci_sbdf_t sbdf; if ( nr_ivmd >= ARRAY_SIZE(user_ivmds) ) return -E2BIG; - s = parse_pci(s + 1, &seg, &bus, &dev, &func); - if ( !s || seg ) + s = parse_pci_sbdf(s + 1, &sbdf); + if ( !s || sbdf.seg ) return -EINVAL; user_ivmds[nr_ivmd].start_address = start << PAGE_SHIFT;
@@ -1413,16 +1413,16 @@ static int __init cf_check parse_ivmd_param(const char *s) user_ivmds[nr_ivmd].header.flags =ACPI_IVMD_UNITY |ACPI_IVMD_READ |ACPI_IVMD_WRITE ; user_ivmds[nr_ivmd].header.length =sizeof (*user_ivmds); - user_ivmds[nr_ivmd].header.device_id =PCI_BDF (bus, dev, func); + user_ivmds[nr_ivmd].header.device_id = sbdf.bdf; user_ivmds[nr_ivmd].header.type =ACPI_IVRS_TYPE_MEMORY_ONE ;if ( *s =='-' ) { - s =parse_pci (s +1 , &seg, &bus, &dev, &func); -if ( !s || seg ) + s =parse_pci_sbdf (s +1 , &sbdf); +if ( !s || sbdf.seg )return -EINVAL ; - user_ivmds[nr_ivmd].aux_data =PCI_BDF (bus, dev, func); + user_ivmds[nr_ivmd].aux_data = sbdf.bdf;if ( user_ivmds[nr_ivmd].aux_data < user_ivmds[nr_ivmd].header.device_id )return -EINVAL ;
xen/drivers/passthrough/vtd/dmar.c +3 -4
@@ -1216,7 +1216,7 @@ static int __init cf_check parse_rmrr_param(const char *str) do { bool def_seg = false; - stmp = parse_pci_seg(s + 1, &seg, &bus, &dev, &func, &def_seg); + stmp = parse_pci_sbdf_seg(s + 1, &sbdf, &def_seg); if ( !stmp ) return -EINVAL;
@@ -1225,12 +1225,11 @@ static int __init cf_check parse_rmrr_param(const char *str)* Segment will be replaced with one from first device. */ if ( user_rmrrs[nr_rmrr].dev_count && def_seg ) - seg =PCI_SEG (user_rmrrs[nr_rmrr].sbdf[0 ]); + sbdf.seg =PCI_SEG (user_rmrrs[nr_rmrr].sbdf[0 ]);/* Keep sbdf's even if they differ and later report an error. */ dev_count = user_rmrrs[nr_rmrr].dev_count; - user_rmrrs[nr_rmrr].sbdf[dev_count] = -PCI_SBDF (seg, bus, dev, func).sbdf; + user_rmrrs[nr_rmrr].sbdf[dev_count] = sbdf.sbdf; user_rmrrs[nr_rmrr].dev_count++; s = stmp;
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 6/15 pci: Use pci_sbdf_t in pci_prepare_msix()
In reply to a message not in the archiveAlso take the opportunity to clean up a bit PHYSDEVOP_{prepare,release}_msix.
No functional change intended.
---
Cc: Daniel P. Smith <[email protected]>
xen/arch/x86/include/asm/msi.h | 2 +- xen/arch/x86/msi.c | 4 ++-- xen/arch/x86/physdev.c | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/x86/include/asm/msi.h +1 -1
@@ -83,7 +83,7 @@ struct msi_desc;extern int pci_enable_msi (struct pci_dev *pdev,struct msi_info *msi,struct msi_desc **desc);extern void pci_disable_msi (struct msi_desc *msi_desc); -extern int pci_prepare_msix (u16 seg,u8 bus,u8 devfn,bool off); +extern int pci_prepare_msix (pci_sbdf_t sbdf,bool off);extern void pci_cleanup_msi (struct pci_dev *pdev);extern void pci_disable_msi_all (void );extern int setup_msi_irq (struct irq_desc *desc,struct msi_desc *msidesc);
xen/arch/x86/msi.c +2 -2
@@ -1153,7 +1153,7 @@ static void __pci_disable_msix(struct msi_desc *entry)_pci_cleanup_msix (dev->msix); } -int pci_prepare_msix (u16 seg,u8 bus,u8 devfn,bool off) +int pci_prepare_msix (pci_sbdf_t sbdf,bool off) {int rc;struct pci_dev *pdev;
@@ -1162,7 +1162,7 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off)return 0 ;pcidevs_lock (); - pdev =pci_get_pdev (NULL ,PCI_SBDF (seg, bus, devfn)); + pdev =pci_get_pdev (NULL , sbdf);if ( !pdev ) rc = -ENODEV ;else if ( pdev->msix->used_entries != !!off )
xen/arch/x86/physdev.c +6 -5
@@ -512,15 +512,16 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev; +pci_sbdf_t sbdf;if (copy_from_guest (&dev, arg,1 ) ) ret = -EFAULT ;else - ret =xsm_resource_setup_pci (XSM_PRIV , - (dev.seg <<16 ) | (dev.bus <<8 ) | - dev.devfn) ?: -pci_prepare_msix (dev.seg, dev.bus, dev.devfn, - cmd != PHYSDEVOP_prepare_msix); + { + sbdf =PCI_SBDF (dev.seg, dev.bus, dev.devfn); + ret =xsm_resource_setup_pci (XSM_PRIV , sbdf.sbdf) ?: +pci_prepare_msix (sbdf, cmd != PHYSDEVOP_prepare_msix); + }break ; }
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 5/15 pci: Allow ommiting func when parsing with parse_pci_sbdf()
In reply to a message not in the archiveAllow parsing PCI SBDF with the function part omitted (i.e XXXX:YY:ZZ), in such case, the parsed PCI function is zero.
That allows us to now use parse_pci_sbdf() in parse_phantom_dev().
--- xen/drivers/passthrough/pci.c | 10 +++++----- xen/drivers/pci/pci.c | 12 ++++-------- 2 files changed, 9 insertions(+), 13 deletions(-)
xen/drivers/passthrough/pci.c +5 -5
@@ -148,7 +148,7 @@ static unsigned int nr_phantom_devs; static int __init cf_check parse_phantom_dev(const char *str) {const char *s; -unsigned int seg, bus, slot; +pci_sbdf_t sbdf;struct phantom_dev phantom;if ( !*str )
@@ -156,13 +156,13 @@ static int __init cf_check parse_phantom_dev(const char *str)if ( nr_phantom_devs >=ARRAY_SIZE (phantom_devs) )return -E2BIG ; - s =parse_pci (str, &seg, &bus, &slot,NULL ); + s =parse_pci_sbdf (str, &sbdf);if ( !s || *s !=',' )return -EINVAL ; - phantom.seg = seg; - phantom.bus = bus; - phantom.slot = slot; + phantom.seg = sbdf.seg; + phantom.bus = sbdf.bus; + phantom.slot = sbdf.dev;switch ( phantom.stride =simple_strtol (s +1 , &s,0 ) ) {
xen/drivers/pci/pci.c +4 -8
@@ -179,18 +179,14 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, seg =0 ; *def_seg = true; } +if ( func_p ) - { -if ( *s !='.' ) -return NULL ; - func =simple_strtoul (s +1 , &s,0 ); - } -else - func =0 ; + func = *s =='.' ?simple_strtoul (s +1 , &s,0 ) :0 ; +if ( seg != (seg_p ? (u16 )seg :0 ) || bus !=PCI_BUS (PCI_BDF (bus,0 )) || dev !=PCI_SLOT (PCI_DEVFN (dev,0 )) || - func !=PCI_FUNC (PCI_DEVFN (0 , func)) ) + func != (func_p ?PCI_FUNC (PCI_DEVFN (0 , func)) :0 ) )return NULL ;if ( seg_p )
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 7/15 pci: Use pci_sbdf_t in pci_ro_device()
In reply to a message not in the archiveThat has the indirect effect of properly considering segments other than 0 in xhci-dbc.
--- xen/drivers/char/ns16550.c | 3 +-- xen/drivers/char/xhci-dbc.c | 4 ++-- xen/drivers/passthrough/amd/iommu_detect.c | 7 +------ xen/drivers/passthrough/pci.c | 8 ++++---- xen/include/xen/pci.h | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-)
xen/drivers/char/ns16550.c +1 -2
@@ -450,8 +450,7 @@ static void __init cf_check ns16550_init_postirq(struct serial_port *port) PFN_UP(uart->io_base + uart->io_size) - 1) )printk (XENLOG_INFO "Error while adding MMIO range of device to mmio_ro_ranges\n" ); -if (pci_ro_device (uart->pci_device.seg, uart->pci_device.bus, - uart->pci_device.devfn) ) +if (pci_ro_device (uart->pci_device) )printk (XENLOG_INFO "Could not mark config space of %pp read-only.\n" , &uart->pci_device);
xen/drivers/char/xhci-dbc.c +2 -2
@@ -1196,7 +1196,7 @@ static void __init cf_check dbc_uart_init_postirq(struct serial_port *port)switch ( uart->dbc.share ) {case XHCI_SHARE_NONE : -if (pci_ro_device (0 , uart->dbc.sbdf.bus, uart->dbc.sbdf.devfn) ) +if (pci_ro_device (uart->dbc.sbdf) )printk (XENLOG_WARNING "Failed to mark read-only %pp used for XHCI console\n" , &uart->dbc.sbdf);
@@ -1221,7 +1221,7 @@ static void __init cf_check dbc_uart_init_postirq(struct serial_port *port)"Error while marking MMIO range of XHCI console as R/O, " "making the whole device R/O (share=no)\n"); uart->dbc.share =XHCI_SHARE_NONE ; -if (pci_ro_device (0 , uart->dbc.sbdf.bus, uart->dbc.sbdf.devfn) ) +if (pci_ro_device (uart->dbc.sbdf) )printk (XENLOG_WARNING "Failed to mark read-only %pp used for XHCI console\n" , &uart->dbc.sbdf);
xen/drivers/passthrough/amd/iommu_detect.c +1 -6
@@ -136,7 +136,6 @@ int __init amd_iommu_detect_one_acpi( const struct acpi_ivrs_hardware *ivhd_block) {struct amd_iommu *iommu; -u8 bus, dev, func;int rt =0 ;if ( ivhd_block->header.length <sizeof (*ivhd_block) )
@@ -210,10 +209,6 @@ int __init amd_iommu_detect_one_acpi(/* override IOMMU HT flags */ iommu->ht_flags = ivhd_block->header.flags; - bus =PCI_BUS (iommu->sbdf.bdf); - dev =PCI_SLOT (iommu->sbdf.bdf); - func =PCI_FUNC (iommu->sbdf.bdf); - rt =get_iommu_capabilities (iommu->sbdf, iommu->cap_offset, iommu);if ( rt ) goto out;
@@ -227,7 +222,7 @@ int __init amd_iommu_detect_one_acpi(if ( !iommu->domid_map ) goto out; - rt =pci_ro_device (iommu->sbdf.seg, bus,PCI_DEVFN (dev, func)); + rt =pci_ro_device (iommu->sbdf);if ( rt )printk (XENLOG_ERR "Could not mark config space of %pp read-only (%d)\n" , &iommu->sbdf, rt);
xen/drivers/passthrough/pci.c +4 -4
@@ -499,14 +499,14 @@ int __init pci_hide_device(unsigned int seg, unsigned int bus,return rc; } -int __init pci_ro_device (int seg,int bus,int devfn) +int __init pci_ro_device (pci_sbdf_t sbdf) { -struct pci_seg *pseg =alloc_pseg (seg); +struct pci_seg *pseg =alloc_pseg (sbdf.seg);struct pci_dev *pdev;if ( !pseg )return -ENOMEM ; - pdev =alloc_pdev (pseg, bus, devfn); + pdev =alloc_pdev (pseg, sbdf.bus, sbdf.devfn);if ( !pdev )return -ENOMEM ;
@@ -520,7 +520,7 @@ int __init pci_ro_device(int seg, int bus, int devfn)memset (pseg->ro_map,0 , sz); } -__set_bit (PCI_BDF (bus, devfn), pseg->ro_map); +__set_bit (sbdf.bdf, pseg->ro_map);_pci_hide_device (pdev);return 0 ;
xen/include/xen/pci.h +1 -1
@@ -232,7 +232,7 @@ const unsigned long *pci_get_ro_map(u16 seg);int pci_add_device (u16 seg,u8 bus,u8 devfn,const struct pci_dev_info *info,nodeid_t node);int pci_remove_device (u16 seg,u8 bus,u8 devfn); -int pci_ro_device (int seg,int bus,int devfn); +int pci_ro_device (pci_sbdf_t sbdf);int pci_hide_device (unsigned int seg,unsigned int bus,unsigned int devfn);struct pci_dev *pci_get_pdev (const struct domain *d,pci_sbdf_t sbdf);struct pci_dev *pci_get_real_pdev (pci_sbdf_t sbdf);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 8/15 pci: Use pci_sbdf_t in pci_hide_device()
In reply to a message not in the archiveNo functional change intended.
--- xen/drivers/char/ehci-dbgp.c | 2 +- xen/drivers/char/xhci-dbc.c | 2 +- xen/drivers/passthrough/pci.c | 7 +++---- xen/drivers/video/vga.c | 2 +- xen/include/xen/pci.h | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-)
xen/drivers/char/ehci-dbgp.c +1 -1
@@ -1374,7 +1374,7 @@ static void __init cf_check ehci_dbgp_init_postirq(struct serial_port *port)ehci_dbgp_setup_postirq (dbgp); -pci_hide_device (0 , dbgp->bus,PCI_DEVFN (dbgp->slot, dbgp->func)); +pci_hide_device (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func)); }static int ehci_dbgp_check_release (struct ehci_dbgp *dbgp)
xen/drivers/char/xhci-dbc.c +1 -1
@@ -1202,7 +1202,7 @@ static void __init cf_check dbc_uart_init_postirq(struct serial_port *port) &uart->dbc.sbdf);break ;case XHCI_SHARE_HWDOM : -if (pci_hide_device (0 , uart->dbc.sbdf.bus, uart->dbc.sbdf.devfn) ) +if (pci_hide_device (uart->dbc.sbdf) )printk (XENLOG_WARNING "Failed to hide %pp used for XHCI console\n" , &uart->dbc.sbdf);
xen/drivers/passthrough/pci.c +3 -4
@@ -476,18 +476,17 @@ static void __init _pci_hide_device(struct pci_dev *pdev)write_unlock (&dom_xen->pci_lock); } -int __init pci_hide_device (unsigned int seg,unsigned int bus, -unsigned int devfn) +int __init pci_hide_device (pci_sbdf_t sbdf) {struct pci_dev *pdev;struct pci_seg *pseg;int rc = -ENOMEM ;pcidevs_lock (); - pseg =alloc_pseg (seg); + pseg =alloc_pseg (sbdf.seg);if ( pseg ) { - pdev =alloc_pdev (pseg, bus, devfn); + pdev =alloc_pdev (pseg, sbdf.bus, sbdf.devfn);if ( pdev ) {_pci_hide_device (pdev);
xen/drivers/video/vga.c +1 -1
@@ -147,7 +147,7 @@ void __init video_endboot(void) {printk (XENLOG_INFO "Boot video device %02x:%02x.%u\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn)); -pci_hide_device (0 , bus, devfn); +pci_hide_device (PCI_SBDF (0 , bus, devfn)); } } }
xen/include/xen/pci.h +1 -1
@@ -233,7 +233,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node);int pci_remove_device (u16 seg,u8 bus,u8 devfn);int pci_ro_device (pci_sbdf_t sbdf); -int pci_hide_device (unsigned int seg,unsigned int bus,unsigned int devfn); +int pci_hide_device (pci_sbdf_t sbdf);struct pci_dev *pci_get_pdev (const struct domain *d,pci_sbdf_t sbdf);struct pci_dev *pci_get_real_pdev (pci_sbdf_t sbdf);void pci_check_disable_device (u16 seg,u8 bus,u8 devfn);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 10/15 pci: Use pci_sbdf_t in pci_add_device()
In reply to a message not in the archiveAlso take the opportunity to avoid refetching sbdf from pdev since we already have it now.
No functional change intended.
--- xen/arch/x86/physdev.c | 7 ++++--- xen/drivers/passthrough/pci.c | 35 ++++++++++++++++------------------- xen/drivers/pci/physdev.c | 2 +- xen/include/xen/pci.h | 3 +-- 4 files changed, 22 insertions(+), 25 deletions(-)
xen/arch/x86/physdev.c +4 -3
@@ -472,7 +472,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&manage_pci, arg,1 ) !=0 )break ; - ret =pci_add_device (0 , manage_pci.bus, manage_pci.devfn, + ret =pci_add_device (PCI_SBDF (0 , manage_pci.bus, + manage_pci.devfn),NULL ,NUMA_NO_NODE );break ; }
@@ -503,8 +504,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) pdev_info.is_virtfn = manage_pci_ext.is_virtfn; pdev_info.physfn.bus = manage_pci_ext.physfn.bus; pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn; - ret =pci_add_device (0 , manage_pci_ext.bus, - manage_pci_ext.devfn, + ret =pci_add_device (PCI_SBDF (0 , manage_pci_ext.bus, + manage_pci_ext.devfn), &pdev_info,NUMA_NO_NODE );break ; }
xen/drivers/passthrough/pci.c +16 -19
@@ -661,12 +661,11 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,return is64bits ?2 :1 ; } -int pci_add_device (u16 seg,u8 bus,u8 devfn, -const struct pci_dev_info *info,nodeid_t node) +int pci_add_device (pci_sbdf_t sbdf,const struct pci_dev_info *info,nodeid_t node) {struct pci_seg *pseg;struct pci_dev *pdev; -unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn); +unsigned int slot = sbdf.devfn, func = sbdf.devfn;const char *type;int ret;
@@ -679,17 +678,17 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,else type ="device" ; - ret =xsm_resource_plug_pci (XSM_PRIV , (seg <<16 ) | (bus <<8 ) | devfn); + ret =xsm_resource_plug_pci (XSM_PRIV , sbdf.sbdf);if ( ret )return ret; ret = -ENOMEM ;pcidevs_lock (); - pseg =alloc_pseg (seg); + pseg =alloc_pseg (sbdf.seg);if ( !pseg ) goto out; - pdev =alloc_pdev (pseg, bus, devfn); + pdev =alloc_pdev (pseg, sbdf.bus, sbdf.devfn);if ( !pdev ) goto out;
@@ -700,16 +699,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->info = *info;if ( pdev->info.is_virtfn ) { -struct pci_dev *pf_pdev = -pci_get_pdev (NULL ,PCI_SBDF (seg, info->physfn.bus, - info->physfn.devfn)); +pci_sbdf_t pf_sbdf =PCI_SBDF (sbdf.seg, info->physfn.bus, info->physfn.devfn); +struct pci_dev *pf_pdev =pci_get_pdev (NULL , pf_sbdf);if ( !pf_pdev ) {printk (XENLOG_WARNING "Attempted to add SR-IOV VF %pp without PF %pp\n" , - &pdev->sbdf, - &PCI_SBDF (seg, info->physfn.bus, info->physfn.devfn)); + &sbdf, &pf_sbdf);free_pdev (pseg, pdev); ret = -ENODEV ; goto out;
@@ -728,14 +725,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->ext_cfg )printk (XENLOG_WARNING "%pp: VF without extended config space?\n" , - &pdev->sbdf); + &sbdf); } }if ( !pdev->info.is_virtfn && !pdev->physfn.vf_rlen[0 ] ) {unsigned int pos =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_SRIOV ); -uint16_t ctrl =pci_conf_read16 (pdev->sbdf, pos +PCI_SRIOV_CTRL ); +uint16_t ctrl =pci_conf_read16 (sbdf, pos +PCI_SRIOV_CTRL );if ( !pos )/* Nothing */ ;
@@ -749,18 +746,18 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,for ( i =0 ; i <PCI_SRIOV_NUM_BARS ; ) {unsigned int idx = pos +PCI_SRIOV_BAR + i *4 ; -uint32_t bar =pci_conf_read32 (pdev->sbdf, idx); +uint32_t bar =pci_conf_read32 (sbdf, idx);if ( (bar &PCI_BASE_ADDRESS_SPACE ) ==PCI_BASE_ADDRESS_SPACE_IO ) {printk (XENLOG_WARNING "SR-IOV device %pp with vf BAR%u in IO space\n" , - &pdev->sbdf, i); + &sbdf, i); ++i;continue ; } - ret = pci_size_mem_bar(pdev->sbdf, idx, NULL, + ret = pci_size_mem_bar(sbdf, idx, NULL, &pdev->physfn.vf_rlen[i], PCI_BAR_VF | ((i == PCI_SRIOV_NUM_BARS - 1) ?
@@ -771,7 +768,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, }else printk (XENLOG_WARNING "SR-IOV device %pp has its virtual" -" functions already enabled (%04x)\n" , &pdev->sbdf, ctrl); +" functions already enabled (%04x)\n" , &sbdf, ctrl); }check_pdev (pdev);
@@ -817,14 +814,14 @@ out:pcidevs_unlock ();if ( !ret ) { -printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &pdev->sbdf); +printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &sbdf);while ( pdev->phantom_stride ) { func += pdev->phantom_stride;if (PCI_SLOT (func) )break ;printk (XENLOG_DEBUG "PCI phantom %pp\n" , - &PCI_SBDF (seg, bus, slot, func)); + &PCI_SBDF (sbdf.seg, sbdf.bus, slot, func)); } }return ret;
xen/drivers/pci/physdev.c +1 -1
@@ -50,7 +50,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }#endif - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); + ret =pci_add_device (PCI_SBDF (add.seg, add.bus, add.devfn), &pdev_info, node);break ; }
xen/include/xen/pci.h +1 -2
@@ -229,8 +229,7 @@ void setup_hwdom_pci_devices(struct domain *d,int pci_release_devices (struct domain *d);int pci_add_segment (u16 seg);const unsigned long *pci_get_ro_map (u16 seg); -int pci_add_device (u16 seg,u8 bus,u8 devfn, -const struct pci_dev_info *info,nodeid_t node); +int pci_add_device (pci_sbdf_t sbdf,const struct pci_dev_info *info,nodeid_t node);int pci_remove_device (pci_sbdf_t sbdf);int pci_ro_device (pci_sbdf_t sbdf);int pci_hide_device (pci_sbdf_t sbdf);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 9/15 pci: Use pci_sbdf_t in pci_remove_device()
In reply to a message not in the archiveNo functional change intended.
--- xen/arch/x86/physdev.c | 2 +- xen/drivers/passthrough/pci.c | 8 ++++---- xen/drivers/pci/physdev.c | 2 +- xen/include/xen/pci.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/physdev.c +1 -1
@@ -483,7 +483,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&manage_pci, arg,1 ) !=0 )break ; - ret =pci_remove_device (0 , manage_pci.bus, manage_pci.devfn); + ret =pci_remove_device (PCI_SBDF (0 , manage_pci.bus, manage_pci.devfn));break ; }
xen/drivers/passthrough/pci.c +4 -4
@@ -830,13 +830,13 @@ out:return ret; } -int pci_remove_device (u16 seg,u8 bus,u8 devfn) +int pci_remove_device (pci_sbdf_t sbdf) { -struct pci_seg *pseg =get_pseg (seg); +struct pci_seg *pseg =get_pseg (sbdf.seg);struct pci_dev *pdev;int ret; - ret =xsm_resource_unplug_pci (XSM_PRIV , (seg <<16 ) | (bus <<8 ) | devfn); + ret =xsm_resource_unplug_pci (XSM_PRIV , sbdf.sbdf);if ( ret )return ret;
@@ -847,7 +847,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn)pcidevs_lock (); list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) -if ( pdev->bus == bus && pdev->devfn == devfn ) +if ( pdev->sbdf.bdf == sbdf.bdf ) {if ( !pdev->info.is_virtfn && !list_empty (&pdev->vf_list) ) {
xen/drivers/pci/physdev.c +1 -1
@@ -64,7 +64,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&dev, arg,1 ) !=0 )break ; - ret =pci_remove_device (dev.seg, dev.bus, dev.devfn); + ret =pci_remove_device (PCI_SBDF (dev.seg, dev.bus, dev.devfn));break ; }
xen/include/xen/pci.h +1 -1
@@ -231,7 +231,7 @@ int pci_add_segment(u16 seg);const unsigned long *pci_get_ro_map (u16 seg);int pci_add_device (u16 seg,u8 bus,u8 devfn,const struct pci_dev_info *info,nodeid_t node); -int pci_remove_device (u16 seg,u8 bus,u8 devfn); +int pci_remove_device (pci_sbdf_t sbdf);int pci_ro_device (pci_sbdf_t sbdf);int pci_hide_device (pci_sbdf_t sbdf);struct pci_dev *pci_get_pdev (const struct domain *d,pci_sbdf_t sbdf);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 11/15 vtd: Rewrite igd device check in acpi_parse_dev_scope()
In reply to a message not in the archiveMake it clearer that we want to check for 0000:00:02.0 here.
--- xen/drivers/passthrough/vtd/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/vtd/dmar.c +1 -1
@@ -389,7 +389,7 @@ static int __init acpi_parse_dev_scope( PCI_CLASS_DEVICE + 1) != 0x03 /* PCI_BASE_CLASS_DISPLAY */ ) gfx_only = false; - else if ( !seg && !dev_sbdf.bus && path->dev == 2 && !path->fn ) + else if ( dev_sbdf.sbdf == PCI_SBDF(0, 0, 2, 0).sbdf ) igd_drhd_address = drhd->address; }
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 12/15 pci: Use pci_sbdf_t pci_check_disable_device()
In reply to a message not in the archiveNo functional change intended.
--- xen/drivers/passthrough/amd/iommu_init.c | 3 +-- xen/drivers/passthrough/pci.c | 4 ++-- xen/drivers/passthrough/vtd/iommu.c | 3 +-- xen/include/xen/pci.h | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +1 -2
@@ -575,8 +575,7 @@ static void cf_check parse_event_log_entry(struct amd_iommu *iommu, u32 entry[])for ( bdf =0 ; bdf < ivrs_bdf_entries; bdf++ )if (get_dma_requestor_id (iommu->sbdf.seg, bdf) == device_id ) -pci_check_disable_device (iommu->sbdf.seg,PCI_BUS (bdf), -PCI_DEVFN (bdf)); +pci_check_disable_device (PCI_SBDF (iommu->sbdf.seg, bdf)); }else printk(XENLOG_ERR "%s %08x %08x %08x %08x\n",
xen/drivers/passthrough/pci.c +2 -2
@@ -1174,14 +1174,14 @@ bool __init pci_device_detect(pci_sbdf_t sbdf)return 1 ; } -void pci_check_disable_device (u16 seg,u8 bus,u8 devfn) +void pci_check_disable_device (pci_sbdf_t sbdf) {struct pci_dev *pdev;s_time_t now =NOW ();u16 cword;pcidevs_lock (); - pdev =pci_get_real_pdev (PCI_SBDF (seg, bus, devfn)); + pdev =pci_get_real_pdev (sbdf);if ( pdev ) { if ( now < pdev->fault.time ||
xen/drivers/passthrough/vtd/iommu.c +1 -2
@@ -1072,8 +1072,7 @@ static void __do_iommu_page_fault(struct vtd_iommu *iommu)iommu_page_fault_do_one (iommu, type, fault_reason, source_id, guest_addr); -pci_check_disable_device (iommu->drhd->segment, -PCI_BUS (source_id),PCI_DEVFN (source_id)); +pci_check_disable_device (PCI_SBDF (iommu->drhd->segment, source_id)); fault_index++;if ( fault_index >cap_num_fault_regs (iommu->cap) )
xen/include/xen/pci.h +1 -1
@@ -235,7 +235,7 @@ int pci_ro_device(pci_sbdf_t sbdf);int pci_hide_device (pci_sbdf_t sbdf);struct pci_dev *pci_get_pdev (const struct domain *d,pci_sbdf_t sbdf);struct pci_dev *pci_get_real_pdev (pci_sbdf_t sbdf); -void pci_check_disable_device (u16 seg,u8 bus,u8 devfn); +void pci_check_disable_device (pci_sbdf_t sbdf);/* * Iterate without locking or preemption over all PCI devices known by Xen.
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 14/15 ehci-dbgp: Use pci_sbdf_t instead of (bus, slot, func)
In reply to a message not in the archiveWe also take the opportunity to allow the device to exist outside of segment 0 (only when specified with pci@ syntax), since it's not hardcoded anymore.
--- xen/drivers/char/ehci-dbgp.c | 71 ++++++++++++------------------------ 1 file changed, 24 insertions(+), 47 deletions(-)
xen/drivers/char/ehci-dbgp.c +24 -47
@@ -335,7 +335,8 @@ struct ehci_dbgp {struct timer timer;spinlock_t *lock;bool reset_run; -u8 bus, slot, func, bar; +u8 bar; +pci_sbdf_t sbdf;u16 pci_cr;u32 bar_val;unsigned int cap;
@@ -720,9 +721,7 @@ static unsigned int __init find_dbgp(struct ehci_dbgp *dbgp,continue ; } - dbgp->bus = bus; - dbgp->slot = slot; - dbgp->func = func; + dbgp->sbdf = sbdf;return cap; } }
@@ -1009,20 +1008,18 @@ static set_debug_port_t __read_mostly set_debug_port = default_set_debug_port; static void cf_check nvidia_set_debug_port(struct ehci_dbgp *dbgp,unsigned int port) { -uint32_t dword =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func),0x74 ); +uint32_t dword =pci_conf_read32 (dbgp->sbdf,0x74 ); dword &= ~(0x0f <<12 ); dword |= (port &0x0f ) <<12 ; -pci_conf_write32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func),0x74 , +pci_conf_write32 (dbgp->sbdf,0x74 , dword);dbgp_printk ("set debug port to %u\n" , port); }static void __init detect_set_debug_port (struct ehci_dbgp *dbgp) { -if (pci_conf_read16 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), -PCI_VENDOR_ID ) ==0x10de ) +if (pci_conf_read16 (dbgp->sbdf,PCI_VENDOR_ID ) ==0x10de ) {dbgp_printk ("using nvidia set_debug_port\n" ); set_debug_port = nvidia_set_debug_port;
@@ -1044,15 +1041,13 @@ static void ehci_dbgp_bios_handoff(struct ehci_dbgp *dbgp, u32 hcc_params)if ( !offset )return ; - cap =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - offset); + cap =pci_conf_read32 (dbgp->sbdf, offset);dbgp_printk ("dbgp: EHCI BIOS state %08x\n" , cap);if ( (cap &0xff ) ==1 && (cap &EHCI_USBLEGSUP_BIOS ) ) {dbgp_printk ("dbgp: BIOS handoff\n" ); -pci_conf_write8 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - offset +3 ,1 ); +pci_conf_write8 (dbgp->sbdf, offset +3 ,1 ); }/* if boot firmware now owns EHCI, spin till it hands it over. */
@@ -1061,8 +1056,7 @@ static void ehci_dbgp_bios_handoff(struct ehci_dbgp *dbgp, u32 hcc_params) {mdelay (10 ); msec -=10 ; - cap =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - offset); + cap =pci_conf_read32 (dbgp->sbdf, offset); }if ( cap &EHCI_USBLEGSUP_BIOS )
@@ -1070,13 +1064,11 @@ static void ehci_dbgp_bios_handoff(struct ehci_dbgp *dbgp, u32 hcc_params)/* well, possibly buggy BIOS... try to shut it down, * and hope nothing goes too wrong */ dbgp_printk ("dbgp: BIOS handoff failed: %08x\n" , cap); -pci_conf_write8 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - offset +2 ,0 ); +pci_conf_write8 (dbgp->sbdf, offset +2 ,0 ); }/* just in case, always disable EHCI SMIs */ -pci_conf_write8 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - offset +EHCI_USBLEGCTLSTS ,0 ); +pci_conf_write8 (dbgp->sbdf, offset +EHCI_USBLEGCTLSTS ,0 ); }static int ehci_dbgp_setup (struct ehci_dbgp *dbgp)
@@ -1318,19 +1310,15 @@ static void __init cf_check ehci_dbgp_init_preirq(struct serial_port *port)u32 debug_port, offset;void __iomem *ehci_bar; - debug_port =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - dbgp->cap); + debug_port =pci_conf_read32 (dbgp->sbdf, dbgp->cap); offset = (debug_port >>16 ) &0xfff ;/* double check if the mem space is enabled */ - dbgp->pci_cr =pci_conf_read8 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func), -PCI_COMMAND ); + dbgp->pci_cr =pci_conf_read8 (dbgp->sbdf,PCI_COMMAND );if ( !(dbgp->pci_cr &PCI_COMMAND_MEMORY ) ) { dbgp->pci_cr |=PCI_COMMAND_MEMORY ; -pci_conf_write16 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), -PCI_COMMAND , dbgp->pci_cr); +pci_conf_write16 (dbgp->sbdf,PCI_COMMAND , dbgp->pci_cr);dbgp_printk ("MMIO for EHCI enabled\n" ); }
@@ -1374,7 +1362,7 @@ static void __init cf_check ehci_dbgp_init_postirq(struct serial_port *port)ehci_dbgp_setup_postirq (dbgp); -pci_hide_device (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func)); +pci_hide_device (dbgp->sbdf); }static int ehci_dbgp_check_release (struct ehci_dbgp *dbgp)
@@ -1395,8 +1383,7 @@ static int ehci_dbgp_check_release(struct ehci_dbgp *dbgp)* so as to allow for reuse of the USB device, which means it is time * to shutdown the USB debug port. */ -printk (XENLOG_INFO "Releasing EHCI debug port at %02x:%02x.%u\n" , - dbgp->bus, dbgp->slot, dbgp->func); +printk (XENLOG_INFO "Releasing EHCI debug port at %pp\n" , &dbgp->sbdf);if ( dbgp->timer.function )kill_timer (&dbgp->timer);
@@ -1429,9 +1416,7 @@ static void cf_check ehci_dbgp_suspend(struct serial_port *port)stop_timer (&dbgp->timer); dbgp->timer.expires =0 ; - dbgp->pci_cr =pci_conf_read16 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func), -PCI_COMMAND ); + dbgp->pci_cr =pci_conf_read16 (dbgp->sbdf,PCI_COMMAND ); dbgp->state = dbgp_unsafe; }
@@ -1443,10 +1428,8 @@ static void cf_check ehci_dbgp_resume(struct serial_port *port)if ( !dbgp->ehci_debug )return ; -pci_conf_write32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), dbgp->bar, - dbgp->bar_val); -pci_conf_write16 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), -PCI_COMMAND , dbgp->pci_cr); +pci_conf_write32 (dbgp->sbdf, dbgp->bar, dbgp->bar_val); +pci_conf_write16 (dbgp->sbdf,PCI_COMMAND , dbgp->pci_cr);ehci_dbgp_setup_preirq (dbgp);ehci_dbgp_setup_postirq (dbgp);
@@ -1503,8 +1486,7 @@ void __init ehci_dbgp_init(void)if ( !dbgp->cap )return ; -dbgp_printk ("Found EHCI debug port on %02x:%02x.%u\n" , - dbgp->bus, dbgp->slot, dbgp->func); +dbgp_printk ("Found EHCI debug port on %pp\n" , &dbgp->sbdf); }else if (strncmp (opt_dbgp +4 ,"@pci" ,4 ) ==0 ) {
@@ -1514,9 +1496,7 @@ void __init ehci_dbgp_init(void)if ( !e || *e )return ; - dbgp->bus = sbdf.bus; - dbgp->slot = sbdf.dev; - dbgp->func = sbdf.fn; + dbgp->sbdf = sbdf;if ( !pci_device_detect (sbdf) )return ;
@@ -1530,8 +1510,7 @@ void __init ehci_dbgp_init(void)else return ; - debug_port =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), - dbgp->cap); + debug_port =pci_conf_read32 (dbgp->sbdf, dbgp->cap); dbgp->bar = (debug_port >>29 ) &0x7 ; dbgp->bar = ((dbgp->bar -1 ) *4 ) +PCI_BASE_ADDRESS_0 ; offset = (debug_port >>16 ) &0xfff ;
@@ -1542,8 +1521,7 @@ void __init ehci_dbgp_init(void)return ; } - dbgp->bar_val = bar_val =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func), dbgp->bar); + dbgp->bar_val = bar_val =pci_conf_read32 (dbgp->sbdf, dbgp->bar);dbgp_printk ("bar_val: %08x\n" , bar_val);if ( bar_val & ~PCI_BASE_ADDRESS_MEM_MASK ) {
@@ -1570,8 +1548,7 @@ int dbgp_op(const struct physdev_dbgp_op *op)case PHYSDEVOP_DBGP_BUS_UNKNOWN :break ;case PHYSDEVOP_DBGP_BUS_PCI : -if ( op->u.pci.seg || ehci_dbgp.bus != op->u.pci.bus || -PCI_DEVFN (ehci_dbgp.slot, ehci_dbgp.func) != op->u.pci.devfn ) +if (PCI_SBDF (op->u.pci.seg, op->u.pci.bus, op->u.pci.devfn).sbdf != ehci_dbgp.sbdf.sbdf )default :return 0 ;break ;
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v2 13/15 pci: Drop parse_pci{_seg}()
In reply to a message not in the archiveNo user of these functions remain, take the opportunity collapse the logic in parse_pci_sbdf{_seg}().
--- xen/drivers/pci/pci.c | 46 ++++++++----------------------------------- xen/include/xen/pci.h | 6 ------ 2 files changed, 8 insertions(+), 44 deletions(-)
xen/drivers/pci/pci.c +8 -38
@@ -151,18 +151,7 @@ void pci_intx(const struct pci_dev *pdev, bool enable)pci_conf_write16 (pdev->sbdf,PCI_COMMAND , cmd); } -const char *__init parse_pci (const char *s,unsigned int *seg_p, -unsigned int *bus_p,unsigned int *dev_p, -unsigned int *func_p) -{ -bool def_seg; - -return parse_pci_seg (s, seg_p, bus_p, dev_p, func_p, &def_seg); -} - -const char *__init parse_pci_seg (const char *s,unsigned int *seg_p, -unsigned int *bus_p,unsigned int *dev_p, -unsigned int *func_p,bool *def_seg) +const char *__init parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) {unsigned long seg =simple_strtoul (s, &s,16 ), bus, dev, func;
@@ -180,39 +169,20 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, *def_seg = true; } -if ( func_p ) - func = *s =='.' ?simple_strtoul (s +1 , &s,0 ) :0 ; + func = *s =='.' ?simple_strtoul (s +1 , &s,0 ) :0 ; -if ( seg != (seg_p ? (u16 )seg :0 ) || +if ( seg != (u16 )seg || bus !=PCI_BUS (PCI_BDF (bus,0 )) || dev !=PCI_SLOT (PCI_DEVFN (dev,0 )) || - func != (func_p ?PCI_FUNC (PCI_DEVFN (0 , func)) :0 ) ) + func !=PCI_FUNC (PCI_DEVFN (0 , func)) )return NULL ; -if ( seg_p ) - *seg_p = seg; - *bus_p = bus; - *dev_p = dev; -if ( func_p ) - *func_p = func; - -return s; -} - -const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) -{ -unsigned int seg, bus, dev, func; -const char *out =parse_pci (s, &seg, &bus, &dev, &func); - *sbdf =PCI_SBDF (seg, bus, dev, func); -return out; +return s; } -const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) +const char *__init parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) { -unsigned int seg, bus, dev, func; -const char *out =parse_pci_seg (s, &seg, &bus, &dev, &func, def_seg); - - *sbdf =PCI_SBDF (seg, bus, dev, func); -return out; +bool def_seg; +return parse_pci_sbdf_seg (s, sbdf, &def_seg); }
xen/include/xen/pci.h +0 -6
@@ -273,12 +273,6 @@ unsigned int pci_find_ext_capability(const struct pci_dev *pdev,unsigned int pci_find_next_ext_capability (const struct pci_dev *pdev,unsigned int start,unsigned int cap); -const char *parse_pci (const char *s,unsigned int *seg_p,unsigned int *bus_p, -unsigned int *dev_p,unsigned int *func_p); -const char *parse_pci_seg (const char *s,unsigned int *seg_p, -unsigned int *bus_p,unsigned int *dev_p, -unsigned int *func_p,bool *def_seg); -const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf);const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg);
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
RFC PATCH v2 15/15 docs: Document support for PCI segment in dbgp and comN parameter
In reply to a message not in the archiveNow that we accept full PCI SBDF (with segments), update the documentation accordingly.
---
In principle, it's correct, but I don't think ECAM is usable at the moment EHCI dbgp is initialized, which would prevent the device from being probed correctly if it's not on segment 0.
Same remark for comN.
--- docs/misc/xen-command-line.pandoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
docs/misc/xen-command-line.pandoc +8 -8
@@ -349,7 +349,7 @@ ACPI indicating none to be there. ### com1 (x86) ### com2 (x86) -> `= <baud>[/<base-baud>][,[DPS][,[<io-base>|pci|amt][,[<irq>|msi][,[<port-bdf>][,[<bridge-bdf>]]]]]]` +> `= <baud>[/<base-baud>][,[DPS][,[<io-base>|pci|amt][,[<irq>|msi][,[<port-sbdf>][,[<bridge-sbdf>]]]]]]` Both option `com1` and `com2` follow the same format.
@@ -371,10 +371,10 @@ Both option `com1` and `com2` follow the same format. registers. * `<irq>` is the IRQ number to use, or `0` to use the UART in poll mode only, or `msi` to set up a Message Signaled Interrupt. -* `<port-bdf>` is the PCI location of the UART, in - `<bus>:<device>.<function>` notation. -* `<bridge-bdf>` is the PCI bridge behind which is the UART, in - `<bus>:<device>.<function>` notation. +* `<port-sbdf>` is the PCI location of the UART, in + `[<seg>:]<bus>:<device>.<function>` notation. +* `<bridge-sbdf>` is the PCI bridge behind which is the UART, in + `[<seg>:]<bus>:<device>.<function>` notation. * `pci` indicates that Xen should scan the PCI bus for the UART, avoiding Intel AMT devices. * `amt` indicated that Xen should scan the PCI bus for the UART,
@@ -731,11 +731,11 @@ for the `all` value. If that isn't intended, raise the `sched_credit2_max_cpus_runqueue` value. ### dbgp -> `= ehci[ <integer> | @pci<bus>:<slot>.<func> ]` -> `= xhci[ <integer> | @pci<bus>:<slot>.<func> ][,share=<bool>|hwdom]` +> `= ehci[ <integer> | @pci[<seg>:]<bus>:<slot>.<func> ]` +> `= xhci[ <integer> | @pci[<seg>:]<bus>:<slot>.<func> ][,share=<bool>|hwdom]` Specify the USB controller to use, either by instance number (when going -over the PCI busses sequentially) or by PCI device (must be on segment 0). +over the PCI busses sequentially in segment 0) or by PCI device. Use `ehci` for EHCI debug port, use `xhci` for XHCI debug capability. XHCI driver will wait indefinitely for the debug host to connect - make sure
Signature · 10 lines
2.54.0 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [RFC PATCH v2 15/15] docs: Document support for PCI segment in dbgp and comN parameter
Quoted 8 lines · Teddy Astie
Now that we accept full PCI SBDF (with segments), update the documentation accordingly.
Signed-off-by Teddy Astie <[email protected]>---
In principle, it's correct, but I don't think ECAM is usable at the moment EHCI dbgp is initialized, which would prevent the device from being probed correctly if it's not on segment 0.
Right, that depends on what the ACPI MCFG table exposes. If you really want to allow segment numbers here, the caveat needs mentioning in the updated doc.
Jan
Quoted 16 lines · Teddy Astie
xen/drivers/pci/pci.c +8
-0@@ -202,3 +202,21 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,return s; } + +const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci (s, &seg, &bus, &dev, &func); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out;
xen/drivers/pci/pci.c const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, · line 222
Quoted 10 lines
xen/drivers/pci/pci.c +10
-0+} + +const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci_seg (s, &seg, &bus, &dev, &func, def_seg); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out; +}
You correct it later in patch 13, but these want to be __init from this patch.
Also, if you introduce these functions ahead of parse_pci{,_seg}() respectively, then the diff in patch 13 becomes far more simple.
With that, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 30 lines · Andrew Cooper
Quoted 16 lines · Teddy Astie
xen/drivers/pci/pci.c +8
-0@@ -202,3 +202,21 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,return s; } + +const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci (s, &seg, &bus, &dev, &func); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out;xen/drivers/pci/pci.c const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, · line 222
Quoted 10 lines
xen/drivers/pci/pci.c +10
-0+} + +const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci_seg (s, &seg, &bus, &dev, &func, def_seg); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out; +}You correct it later in patch 13, but these want to be
__initfrom this patch.
Quoted 4 lines
Also, if you introduce these functions ahead of parse_pci{,_seg}() respectively, then the diff in patch 13 becomes far more simple.
With that, Reviewed-by: Andrew Cooper <[email protected]>
P.S. this is what patch 13 looks like with the suggested change:
xen/drivers/pci/pci.c +0 -0
@@ -152,17 +152,6 @@ void pci_intx(const struct pci_dev *pdev, bool enable)
}
const char *__init parse_pci_sbdf(const char *s, pci_sbdf_t *sbdf)
-{
- unsigned int seg, bus, dev, func;
- const char *out = parse_pci(s, &seg, &bus, &dev, &func);
-
- *sbdf = PCI_SBDF(seg, bus, dev, func);
- return out;
-}
-
-const char *__init parse_pci(const char *s, unsigned int *seg_p,
- unsigned int *bus_p, unsigned int *dev_p, - unsigned int *func_p)
{
bool def_seg;
@@ -170,17 +159,6 @@ const char *__init parse_pci(const char *s, unsigned int *seg_p, }
const char *__init parse_pci_sbdf_seg(const char *s, pci_sbdf_t *sbdf, bool *def_seg) -{
- unsigned int seg, bus, dev, func;
- const char *out = parse_pci_seg(s, &seg, &bus, &dev, &func, def_seg); -
- *sbdf = PCI_SBDF(seg, bus, dev, func);
- return out;
-}
-
-const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,
- unsigned int *bus_p, unsigned int *dev_p, - unsigned int *func_p, bool *def_seg)
{
unsigned long seg = simple_strtoul(s, &s, 16), bus, dev, func;
~Andrew
Re: [PATCH v2 02/15] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
In reply to Teddy Astiexen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 313
Quoted 10 lines · Teddy Astie
xen/drivers/passthrough/vtd/dmar.c +1
-1@@ -310,7 +310,7 @@ static int __init acpi_parse_dev_scope( {struct acpi_ioapic_unit *acpi_ioapic_unit;const struct acpi_dmar_device_scope *acpi_scope; -u16 bus, sub_bus, sec_bus; +u16 sub_bus, sec_bus;
Please swap to uint16_t as you're editing the line anyway.
xen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 335
Quoted 8 lines
xen/drivers/passthrough/vtd/dmar.c +1
-0const struct acpi_dmar_pci_path *path;struct acpi_drhd_unit *drhd = type ==DMAR_TYPE ? container_of(scope, struct acpi_drhd_unit, scope) : NULL;@@ -332,29 +332,27 @@ static int __init acpi_parse_dev_scope(while ( start < end ) { +pci_sbdf_t dev_sbdf;
Blank line here.
xen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 386
Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +2
-3@@ -386,16 +381,15 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_ENDPOINT :if ( iommu_verbose ) -printk (VTDPREFIX " endpoint: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " endpoint: %pp\n" , &dev_sbdf); -if ( drhd &&pci_device_detect (seg, bus, path->dev, path->fn) ) +if ( drhd &&pci_device_detect (seg, dev_sbdf.bus, dev_sbdf.dev, dev_sbdf.fn) )
I was going to suggest converting pci_device_detect(), but I see that's the next patch.
Given that's the way you've got the series, it's probably not worth flipping it.
So, with the two style fixes above, Reviewed-by: Andrew Cooper <[email protected]>
Re: [PATCH v2 03/15] pci: Use pci_sbdf_t in pci_device_detect()
In reply to Teddy Astiexen/drivers/char/ehci-dbgp.c void __init ehci_dbgp_init(void) · line 1511
Quoted 10 lines · Teddy Astie
xen/drivers/char/ehci-dbgp.c +1
-1@@ -1510,25 +1508,24 @@ void __init ehci_dbgp_init(void) }else if (strncmp (opt_dbgp +4 ,"@pci" ,4 ) ==0 ) { -unsigned int bus, slot, func; +pci_sbdf_t sbdf =PCI_SBDF (0 ,0 ,0 ,0 );
Elsewhere you don't initialise sbdf, which should be fine here too.
If you do need to initialise it to all zeroes, use = {}; instead, which is shorter.
Quoted 6 lines
xen/drivers/char/ehci-dbgp.c +1
-1- e =parse_pci (opt_dbgp +8 ,NULL , &bus, &slot, &func); + e =parse_pci_sbdf (opt_dbgp +8 , &sbdf);if ( !e || *e )return ;
xen/drivers/char/ehci-dbgp.c void __init ehci_dbgp_init(void) · line 1522
Quoted 10 lines
xen/drivers/char/ehci-dbgp.c +4
-4- dbgp->bus = bus; - dbgp->slot = slot; - dbgp->func = func; + dbgp->bus = sbdf.bus; + dbgp->slot = sbdf.dev; + dbgp->func = sbdf.fn; -if ( !pci_device_detect (0 , bus, slot, func) ) +if ( !pci_device_detect (sbdf) )return ;
Looking at both this patch and the next one, and despite what I said in patch 2, I'm going to recommend separating the pci_device_detect() parts.
This patch has two separate changes going on; converting pci_device_detect(), and using parse_pci_sbdf() in some places, while patch 4 has some simple conversions to parse_pci_sbdf().
Break pci_device_detect() out on it's own. Trivial caller adjustments (e.g. acpi_parse_one_drhd(), register_one_satc(), even _scan_pci_devices()) are fine to stay with that, but for non-trivial ones (e.g. acpi_parse_dev_scope(), ehci_dbgp_init()), just wrap the caller with PCI_SBDF(...) in the interim.
Then, you want a patch for acpi_parse_dev_scope(), and a separate patch for the work in ehci-dbgp.c.
It makes the series longer but the result is easier to review because the patches are doing fewer things at once.
Quoted 5 lines
xen/drivers/passthrough/vtd/dmar.c +0
-0
xen/drivers/passthrough/vtd/dmar.c int cf_check intel_iommu_get_reserved_device_memory( · line 1185
Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +2
-1@@ -1185,8 +1177,9 @@ int cf_check intel_iommu_get_reserved_device_memory( static int __init cf_check parse_rmrr_param(const char *str) {const char *s = str, *cur, *stmp; -unsigned int seg, bus, dev, func, dev_count; +unsigned int dev_count;unsigned long start, end; +pci_sbdf_t sbdf; do { if ( nr_rmrr >= MAX_USER_RMRR )
You're missing a hunk here, and it doesn't compile. You've changed the variables, but not changed the parse_pci_seg() call.
They look like they're in patch 4, which I presume is just a rebasing error?
~Andrew
Re: [PATCH v2 05/15] pci: Allow ommiting func when parsing with parse_pci_sbdf()
In reply to Teddy AstieQuoted 17 lines · Teddy Astie
xen/drivers/pci/pci.c +1
-7@@ -179,18 +179,14 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, seg =0 ; *def_seg = true; } +if ( func_p ) - { -if ( *s !='.' ) -return NULL ; - func =simple_strtoul (s +1 , &s,0 ); - } -else - func =0 ;
xen/drivers/pci/pci.c const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, · line 192
Quoted 10 lines
xen/drivers/pci/pci.c +3
-1+ func = *s =='.' ?simple_strtoul (s +1 , &s,0 ) :0 ; +if ( seg != (seg_p ? (u16 )seg :0 ) || bus !=PCI_BUS (PCI_BDF (bus,0 )) || dev !=PCI_SLOT (PCI_DEVFN (dev,0 )) || - func !=PCI_FUNC (PCI_DEVFN (0 , func)) ) + func != (func_p ?PCI_FUNC (PCI_DEVFN (0 , func)) :0 ) )return NULL ;if ( seg_p )
My build fails with:
drivers/pci/pci.c: In function ‘parse_pci_seg’:drivers/pci/pci.c:206:45: error: ‘func’ may be used uninitialized [-Werror=maybe-uninitialized] 204 | if ( seg != (seg_p ? (u16)seg : 0) ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205 | bus != PCI_BUS(PCI_BDF(bus, 0)) ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206 | dev != PCI_SLOT(PCI_DEVFN(dev, 0)) ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
207 | func != (func_p ? PCI_FUNC(PCI_DEVFN(0, func)) : 0) )
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/pci/pci.c:185:62: note: ‘func’ was declared here
185 | unsigned long seg = simple_strtoul(s, &s, 16), bus, dev, func;
| ^~~~
cc1: all warnings being treated as errors
which is correct. For the !func_p case, func is left uninitialised, but is evaluated as part of PCI_FUNC(PCI_DEVFN(0, func)). The ternary operator there will lower to a cmov which requires both sides to be evaluated.
Again, this is something which is addressed by patch 13, but it needs to work here for bisectability.
Initialise func to 0, then use:
if ( func_p && *s == '.' )
func = simple_strtoul(s + 1, &s, 0);
and I think you can keep this line as func != PCI_FUNC(PCI_DEVFN(0, func)), which shrinks both this patch and patch 13.
~Andrew
Quoted 7 lines · Teddy Astie
In many places, we're parsing a PCI string into individual parts (seg, bus, dev, fn) and then transform it into a
pci_sbdf_tusingPCI_SBDFmacro. Rather than converting from parts topci_sbdf_tand vice versa, introduce a new function that parses a PCI string into apci_sbdf_tstructure directly.Signed-off-by Teddy Astie <[email protected]>
You introduce two functions without callers, hence two new violations of Misra rule 2.1. I understand there will be callers by the end of the series, but I think we want to remain Misra-unregressed at every patch boundary. Even for rules which aren't marked as clean (and hence blocking) yet.
Quoted 14 lines
xen/drivers/pci/pci.c +8
-0@@ -202,3 +202,21 @@ const char *__init parse_pci_seg(const char *s, unsigned int *seg_p,return s; } + +const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci (s, &seg, &bus, &dev, &func); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out;
xen/drivers/pci/pci.c const char *__init parse_pci_seg(const char *s, unsigned int *seg_p, · line 222
Quoted 10 lines
xen/drivers/pci/pci.c +10
-0+} + +const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg) +{ +unsigned int seg, bus, dev, func; +const char *out =parse_pci_seg (s, &seg, &bus, &dev, &func, def_seg); + + *sbdf =PCI_SBDF (seg, bus, dev, func); +return out; +}
Nit (for both functions): Blank line please ahead of the main return statement of a function.
Jan
Re: [PATCH v2 02/15] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
In reply to Andrew CooperQuoted 9 lines · Andrew Cooper
Quoted 8 lines · Teddy Astie
xen/drivers/passthrough/vtd/dmar.c +1
-2@@ -386,16 +381,15 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_ENDPOINT :if ( iommu_verbose ) -printk (VTDPREFIX " endpoint: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " endpoint: %pp\n" , &dev_sbdf);
Quoted 5 lines
xen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 386
Quoted 2 lines
xen/drivers/passthrough/vtd/dmar.c +1
-1-if ( drhd &&pci_device_detect (seg, bus, path->dev, path->fn) ) +if ( drhd &&pci_device_detect (seg, dev_sbdf.bus, dev_sbdf.dev, dev_sbdf.fn) )I was going to suggest converting
pci_device_detect(), but I see that's the next patch.
Nevertheless, nit: Line length wants keeping limited here.
Jan
Re: [PATCH v2 02/15] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
In reply to Teddy AstieQuoted 4 lines · Teddy Astie
xen/drivers/passthrough/vtd/dmar.c +0
-0@@ -386,16 +381,15 @@ static int __init acpi_parse_dev_scope(case ACPI_DMAR_SCOPE_TYPE_ENDPOINT :if ( iommu_verbose )
xen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 389
Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +3
-4-printk (VTDPREFIX " endpoint: %pp\n" , - &PCI_SBDF (seg, bus, path->dev, path->fn)); +printk (VTDPREFIX " endpoint: %pp\n" , &dev_sbdf); -if ( drhd &&pci_device_detect (seg, bus, path->dev, path->fn) ) +if ( drhd &&pci_device_detect (seg, dev_sbdf.bus, dev_sbdf.dev, dev_sbdf.fn) ) { -if (pci_conf_read8 (PCI_SBDF (seg, bus, path->dev, path->fn), +if (pci_conf_read8 (dev_sbdf, PCI_CLASS_DEVICE + 1) != 0x03
Another formatting remark: Technically the two lines above now can be un-wrapped (as you do in other cases), as the result fits on a single line. However, with ...
xen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 390
Quoted 1 line
xen/drivers/passthrough/vtd/dmar.c +0
-0/* PCI_BASE_CLASS_DISPLAY */ )
... the comment in mind maybe overall this would best be as
if ( pci_conf_read8(dev_sbdf, PCI_CLASS_DEVICE + 1) !=
0x03 /* PCI_BASE_CLASS_DISPLAY */ )Jan
Re: [PATCH v2 05/15] pci: Allow ommiting func when parsing with parse_pci_sbdf()
In reply to Teddy AstieQuoted 4 lines · Teddy Astie
Allow parsing PCI SBDF with the function part omitted (i.e XXXX:YY:ZZ), in such case, the parsed PCI function is zero.
That allows us to now use
parse_pci_sbdf()inparse_phantom_dev().
Well, yes, but everywhere else the func-less will now also be accepted. Like omitting (defaulting) the segment this behavior really needs to be caller controlled imo.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Teddy Astie
In many places, we're parsing a PCI string into individual parts (seg, bus, dev, fn) and then transform it into a
pci_sbdf_tusingPCI_SBDFmacro. Rather than converting from parts topci_sbdf_tand vice versa, introduce a new function that parses a PCI string into apci_sbdf_tstructure directly.
Quoted 5 lines
Quoted 1 line
Signed-off-by Teddy Astie <[email protected]>You introduce two functions without callers, hence two new violations of Misra rule 2.1. I understand there will be callers by the end of the series, but I think we want to remain Misra-unregressed at every patch boundary. Even for rules which aren't marked as clean (and hence blocking) yet.
I'm going to firmly object to this request.
2.1 is not checked and has no viable plan to be.
This patch series is nicely structured for easy review, and I'm not happy forcing it to be worse just to satisfy a check that is firmly off.
~Andrew
Re: [PATCH v2 02/15] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
In reply to Teddy Astiexen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 410
Quoted 13 lines · Teddy Astie
xen/drivers/passthrough/vtd/dmar.c +1
-3@@ -413,9 +406,7 @@ static int __init acpi_parse_dev_scope(if ( !acpi_ioapic_unit ) goto out; acpi_ioapic_unit->apic_id = acpi_scope->enumeration_id; - acpi_ioapic_unit->ioapic.bdf.bus = bus; - acpi_ioapic_unit->ioapic.bdf.dev = path->dev; - acpi_ioapic_unit->ioapic.bdf.func = path->fn; + acpi_ioapic_unit->ioapic.info = dev_sbdf.bdf;list_add (&acpi_ioapic_unit->list, &drhd->ioapic_list);
Looking at this more closely (because of an issue in a later patch), swapping bdf for info looks wonky.
It turns out to be correct, but would be better with:
xen/drivers/passthrough/vtd/dmar.c +0 -0
@@ -407,7 +407,7 @@ static int __init acpi_parse_dev_scope(
if ( !acpi_ioapic_unit )
goto out;
acpi_ioapic_unit->apic_id = acpi_scope->enumeration_id; - acpi_ioapic_unit->ioapic.info = dev_sbdf.bdf; + acpi_ioapic_unit->bdf = dev_sbdf.bdf; list_add(&acpi_ioapic_unit->list, &drhd->ioapic_list);
gfx_only = false;
xen/drivers/passthrough/vtd/dmar.h +0 -0
@@ -29,13 +29,13 @@ struct acpi_ioapic_unit {
struct list_head list;
int apic_id;
union {
- u16 info;
+ uint16_t bdf;
struct {
u16 func: 3,
dev: 5,
bus: 8;
- }bdf;
- }ioapic;
+ };
+ };
};
struct acpi_hpet_unit {
xen/drivers/passthrough/vtd/intremap.c +0 -0
@@ -98,7 +98,7 @@ static u16 apicid_to_bdf(int apic_id)
list_for_each_entry ( acpi_ioapic_unit, &drhd->ioapic_list, list ) if ( acpi_ioapic_unit->apic_id == apic_id )
- return acpi_ioapic_unit->ioapic.info;
+ return acpi_ioapic_unit->bdf;
dprintk(XENLOG_ERR VTDPREFIX, "Didn't find the bdf for the apic_id!\n"); return 0;
Personally I'd be tempted to just fold this in as well as it is relevant to the acpi_parse_dev_scope(), and because this is brining IOAPIC in line with HPET, but it could be a followup patch if you'd prefer not to mix the two.
~Andrew
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Teddy Astie
In many places, we're parsing a PCI string into individual parts (seg, bus, dev, fn) and then transform it into a
pci_sbdf_tusingPCI_SBDFmacro. Rather than converting from parts topci_sbdf_tand vice versa, introduce a new function that parses a PCI string into apci_sbdf_tstructure directly.Signed-off-by Teddy Astie <[email protected]>
Quoted 8 lines
Quoted 4 lines
You introduce two functions without callers, hence two new violations of Misra rule 2.1. I understand there will be callers by the end of the series, but I think we want to remain Misra-unregressed at every patch boundary. Even for rules which aren't marked as clean (and hence blocking) yet.
I'm going to firmly object to this request.
2.1 is not checked and has no viable plan to be.
Okay, then we need to discuss this on, perhaps, the next committers' call. Yes, the rule isn't among the clean ones. But it is among the ones checked (because it is among the ones we accepted). As per the most recent staging pipeline, at least in the -amd jobs it also doesn't have many remaining violations.
Jan
Quoted 4 lines
This patch series is nicely structured for easy review, and I'm not happy forcing it to be worse just to satisfy a check that is firmly off.
~Andrew
Re: [PATCH v2 06/15] pci: Use pci_sbdf_t in pci_prepare_msix()
In reply to Teddy AstieQuoted 16 lines · Teddy Astie
xen/arch/x86/physdev.c +1
-3@@ -512,15 +512,16 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev; +pci_sbdf_t sbdf;if (copy_from_guest (&dev, arg,1 ) ) ret = -EFAULT ;else - ret =xsm_resource_setup_pci (XSM_PRIV , - (dev.seg <<16 ) | (dev.bus <<8 ) | - dev.devfn) ?:
xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 527
Quoted 10 lines
xen/arch/x86/physdev.c +5
-2-pci_prepare_msix (dev.seg, dev.bus, dev.devfn, - cmd != PHYSDEVOP_prepare_msix); + { + sbdf =PCI_SBDF (dev.seg, dev.bus, dev.devfn); + ret =xsm_resource_setup_pci (XSM_PRIV , sbdf.sbdf) ?: +pci_prepare_msix (sbdf, cmd != PHYSDEVOP_prepare_msix); + }break ; }
You say "clean up", but IMO this is not much better. I would much prefer if it turned into this:
case PHYSDEVOP_release_msix: {
struct physdev_pci_device dev;
pci_sbdf_t sbdf;
ret = -EFAULT;
if ( copy_from_guest(&dev, arg, 1) )
break;
sbdf = PCI_SBDF(dev.seg, dev.bus, dev.devfn);
ret = xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf); if ( ret )
break;
ret = pci_prepare_msix(sbdf, cmd != PHYSDEVOP_prepare_msix); break;
}
It is slightly longer, but the cognitive complexity is far lower.
~Andrew
Re: [PATCH v2 07/15] pci: Use pci_sbdf_t in pci_ro_device()
In reply to Teddy AstieQuoted 4 lines · Teddy Astie
That has the indirect effect of properly considering segments other than 0 in xhci-dbc.
Signed-off-by Teddy Astie <[email protected]>
Considering non-zero segments is fine, but I highly doubt DBC will ever be on a non-zero segment. Amongst other things, it's now the hardware debuggers attach, and have to work prior to the CPU executing instructions. i.e. it has to work (route correctly) from the reset configuration of the fabric/etc.
Re: [PATCH v2 08/15] pci: Use pci_sbdf_t in pci_hide_device()
In reply to Teddy AstieQuoted 3 lines · Teddy Astie
No functional change intended.
Signed-off-by Teddy Astie <[email protected]>
Re: [PATCH v2 09/15] pci: Use pci_sbdf_t in pci_remove_device()
In reply to Teddy AstieQuoted 3 lines · Teddy Astie
No functional change intended.
Signed-off-by Teddy Astie <[email protected]>
Re: [PATCH v2 10/15] pci: Use pci_sbdf_t in pci_add_device()
In reply to Teddy AstieQuoted 6 lines · Teddy Astie
xen/drivers/passthrough/pci.c +0
-0@@ -661,12 +661,11 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,return is64bits ?2 :1 ;
xen/drivers/passthrough/pci.c unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos, · line 668
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-3} -int pci_add_device (u16 seg,u8 bus,u8 devfn, -const struct pci_dev_info *info,nodeid_t node) +int pci_add_device (pci_sbdf_t sbdf,const struct pci_dev_info *info,nodeid_t node) {struct pci_seg *pseg;struct pci_dev *pdev; -unsigned int slot =PCI_SLOT (devfn), func =PCI_FUNC (devfn); +unsigned int slot = sbdf.devfn, func = sbdf.devfn;
.dev and .func, surely?
But, the only uses of them are now ...
Quoted 6 lines
xen/drivers/passthrough/pci.c +1
-1@@ -817,14 +814,14 @@ out:pcidevs_unlock ();if ( !ret ) { -printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &pdev->sbdf); +printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &sbdf);
xen/drivers/passthrough/pci.c out: · line 826
Quoted 10 lines
xen/drivers/passthrough/pci.c +1
-1while ( pdev->phantom_stride ) { func += pdev->phantom_stride;if (PCI_SLOT (func) )break ;printk (XENLOG_DEBUG "PCI phantom %pp\n" , - &PCI_SBDF (seg, bus, slot, func)); + &PCI_SBDF (sbdf.seg, sbdf.bus, slot, func)); } }
... here, which is for diagnostics only.
At a minimum you can reduce their scope so they don't get reused elsewhere, but it would be nicer to remove them entirely.
Incidentally (and not something you can address in this patch), we really should see about swapping PCI_SLOT() for PCI_DEV(). It's one wonky thing in an otherwise fairly consistent naming scheme.
~Andrew
Re: [PATCH v2 11/15] vtd: Rewrite igd device check in acpi_parse_dev_scope()
In reply to Teddy AstieQuoted 3 lines · Teddy Astie
Make it clearer that we want to check for 0000:00:02.0 here.
Signed-off-by Teddy Astie <[email protected]>
In principle Reviewed-by: Andrew Cooper <[email protected]>
But, shouldn't this be part of the other adjustments to acpi_parse_dev_scope()? It's not clear why this change is split out.
Re: [PATCH v2 12/15] pci: Use pci_sbdf_t pci_check_disable_device()
In reply to Teddy AstieQuoted 3 lines · Teddy Astie
No functional change intended.
Signed-off-by Teddy Astie <[email protected]>
Re: [PATCH v2 06/15] pci: Use pci_sbdf_t in pci_prepare_msix()
In reply to Andrew CooperQuoted 45 lines · Andrew Cooper
Quoted 16 lines · Teddy Astie
xen/arch/x86/physdev.c +1
-3@@ -512,15 +512,16 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case PHYSDEVOP_prepare_msix:case PHYSDEVOP_release_msix: {struct physdev_pci_device dev; +pci_sbdf_t sbdf;if (copy_from_guest (&dev, arg,1 ) ) ret = -EFAULT ;else - ret =xsm_resource_setup_pci (XSM_PRIV , - (dev.seg <<16 ) | (dev.bus <<8 ) | - dev.devfn) ?:xen/arch/x86/physdev.c ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 527
Quoted 10 lines
xen/arch/x86/physdev.c +5
-2-pci_prepare_msix (dev.seg, dev.bus, dev.devfn, - cmd != PHYSDEVOP_prepare_msix); + { + sbdf =PCI_SBDF (dev.seg, dev.bus, dev.devfn); + ret =xsm_resource_setup_pci (XSM_PRIV , sbdf.sbdf) ?: +pci_prepare_msix (sbdf, cmd != PHYSDEVOP_prepare_msix); + }break ; }You say "clean up", but IMO this is not much better. I would much prefer if it turned into this:
case
PHYSDEVOP_release_msix: {
structphysdev_pci_devicedev;
pci_sbdf_tsbdf;ret =
-EFAULT;
if (copy_from_guest(&dev, arg, 1))
break;sbdf =
PCI_SBDF(dev.seg, dev.bus, dev.devfn);ret =
xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf); if ( ret )
break;
Quoted 6 lines
ret =
pci_prepare_msix(sbdf, cmd != PHYSDEVOP_prepare_msix); break;
}It is slightly longer, but the cognitive complexity is far lower.
This is pretty subjective, isn't it? I for one prefer forms with fewer "break", as long as indentation doesn't get overly deep.
Jan
Re: [PATCH v2 14/15] ehci-dbgp: Use pci_sbdf_t instead of (bus, slot, func)
In reply to Teddy AstieQuoted 5 lines · Teddy Astie
We also take the opportunity to allow the device to exist outside of segment 0 (only when specified with pci@ syntax), since it's not hardcoded anymore.
Signed-off-by Teddy Astie <[email protected]>
$ bloat-o-meter -c xen-syms-{before,after}
add/remove: 0/0 grow/shrink: 0/9 up/down: 0/-560 (-560)
Function old new delta
ehci_dbgp_check_release.cold 72 64 -8
dbgp_op 260 244 -16
ehci_dbgp_init_postirq 121 97 -24
ehci_dbgp_suspend 87 62 -25
ehci_dbgp_resume 150 102 -48
nvidia_set_debug_port 100 50 -50
ehci_dbgp_init_preirq 344 239 -105
ehci_dbgp_setup 692 568 -124
ehci_dbgp_init 778 618 -160
Total: Before=2016873, After=2016313, chg -0.03%
add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0 (8)
Data old new delta
ehci_dbgp 144 152 +8
Total: Before=2209383, After=2209391, chg +0.00%It's a very clear demonstration of how expensive the split parameter passing is in practice.
Quoted 9 lines
--- xen/drivers/char/ehci-dbgp.c | 71 ++++++++++++------------------------ 1 file changed, 24 insertions(+), 47 deletions(-)xen/drivers/char/ehci-dbgp.c +0
-0
xen/drivers/char/ehci-dbgp.c struct ehci_dbgp { · line 339
Quoted 6 lines
xen/drivers/char/ehci-dbgp.c +2
-1@@ -335,7 +335,8 @@ struct ehci_dbgp {struct timer timer;spinlock_t *lock;bool reset_run; -u8 bus, slot, func, bar; +u8 bar; +pci_sbdf_t sbdf;
This struct is horribly packed, but putting sbdf between lock and reset_run will pack better than having it here.
xen/drivers/char/ehci-dbgp.c static set_debug_port_t __read_mostly set_debug_port = default_set_debug_port; · line 1016
Quoted 13 lines
xen/drivers/char/ehci-dbgp.c +2
-3@@ -1009,20 +1008,18 @@ static set_debug_port_t __read_mostly set_debug_port = default_set_debug_port; static void cf_check nvidia_set_debug_port(struct ehci_dbgp *dbgp,unsigned int port) { -uint32_t dword =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func),0x74 ); +uint32_t dword =pci_conf_read32 (dbgp->sbdf,0x74 ); dword &= ~(0x0f <<12 ); dword |= (port &0x0f ) <<12 ; -pci_conf_write32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func),0x74 , +pci_conf_write32 (dbgp->sbdf,0x74 , dword);
This can be folded onto one line.
xen/drivers/char/ehci-dbgp.c int dbgp_op(const struct physdev_dbgp_op *op) · line 1552
Quoted 8 lines
xen/drivers/char/ehci-dbgp.c +1
-2@@ -1570,8 +1548,7 @@ int dbgp_op(const struct physdev_dbgp_op *op)case PHYSDEVOP_DBGP_BUS_UNKNOWN :break ;case PHYSDEVOP_DBGP_BUS_PCI : -if ( op->u.pci.seg || ehci_dbgp.bus != op->u.pci.bus || -PCI_DEVFN (ehci_dbgp.slot, ehci_dbgp.func) != op->u.pci.devfn ) +if (PCI_SBDF (op->u.pci.seg, op->u.pci.bus, op->u.pci.devfn).sbdf != ehci_dbgp.sbdf.sbdf )
This wants wrapping, somehow.
With suitable adjustments, Reviewed-by: Andrew Cooper <[email protected]>
Re: [PATCH v2 10/15] pci: Use pci_sbdf_t in pci_add_device()
In reply to Teddy AstieQuoted 2 lines · Teddy Astie
Also take the opportunity to avoid refetching sbdf from pdev since we already have it now.
I question this; see below.
xen/drivers/passthrough/pci.c unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos, · line 664
Quoted 9 lines
xen/drivers/passthrough/pci.c +1
-2@@ -661,12 +661,11 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos,return is64bits ?2 :1 ; } -int pci_add_device (u16 seg,u8 bus,u8 devfn, -const struct pci_dev_info *info,nodeid_t node) +int pci_add_device (pci_sbdf_t sbdf,const struct pci_dev_info *info,nodeid_t node)
Nit: This line is too long now.
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 702
Quoted 8 lines
xen/drivers/passthrough/pci.c +1
-3@@ -700,16 +699,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->info = *info;if ( pdev->info.is_virtfn ) { -struct pci_dev *pf_pdev = -pci_get_pdev (NULL ,PCI_SBDF (seg, info->physfn.bus, - info->physfn.devfn)); +pci_sbdf_t pf_sbdf =PCI_SBDF (sbdf.seg, info->physfn.bus, info->physfn.devfn);
As is this one.
Quoted 4 lines
xen/drivers/passthrough/pci.c +0
-0@@ -728,14 +725,14 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,if ( !pdev->ext_cfg ) printk(XENLOG_WARNING "%pp: VF without extended config space?\n",
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 devfn, · line 735
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-2- &pdev->sbdf); + &sbdf); } }if ( !pdev->info.is_virtfn && !pdev->physfn.vf_rlen[0 ] ) {unsigned int pos =pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_SRIOV ); -uint16_t ctrl =pci_conf_read16 (pdev->sbdf, pos +PCI_SRIOV_CTRL ); +uint16_t ctrl =pci_conf_read16 (sbdf, pos +PCI_SRIOV_CTRL );
Are changes like these two actually worthwhile to make? sbdf, being a function parameter, can be modified in the course of the function. pdev->sbdf, otoh, cannot (for being in a const struct field). If further sbdf, throughout the function, never had its address taken, the compiler may be able to produce better code.
Quoted 4 lines
xen/drivers/passthrough/pci.c +0
-0@@ -817,14 +814,14 @@ out:pcidevs_unlock ();if ( !ret ) {
xen/drivers/passthrough/pci.c out: · line 824
Quoted 10 lines
xen/drivers/passthrough/pci.c +2
-2-printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &pdev->sbdf); +printk (XENLOG_DEBUG "PCI add %s %pp\n" , type, &sbdf);while ( pdev->phantom_stride ) { func += pdev->phantom_stride;if (PCI_SLOT (func) )break ;printk (XENLOG_DEBUG "PCI phantom %pp\n" , - &PCI_SBDF (seg, bus, slot, func)); + &PCI_SBDF (sbdf.seg, sbdf.bus, slot, func));
Why sbdf.bus but not sbdf.slot? In fact this is a case where altering sbdf may
help: You then wouldn't need the func local variable anymore either.
xen/drivers/pci/physdev.c ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 53
Quoted 8 lines
xen/drivers/pci/physdev.c +1
-1@@ -50,7 +50,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }#endif - ret =pci_add_device (add.seg, add.bus, add.devfn, &pdev_info, node); + ret =pci_add_device (PCI_SBDF (add.seg, add.bus, add.devfn), &pdev_info, node);
Yet another overlong line.
xen/include/xen/pci.h void setup_hwdom_pci_devices(struct domain *d, · line 232
Quoted 9 lines
xen/include/xen/pci.h +1
-2@@ -229,8 +229,7 @@ void setup_hwdom_pci_devices(struct domain *d,int pci_release_devices (struct domain *d);int pci_add_segment (u16 seg);const unsigned long *pci_get_ro_map (u16 seg); -int pci_add_device (u16 seg,u8 bus,u8 devfn, -const struct pci_dev_info *info,nodeid_t node); +int pci_add_device (pci_sbdf_t sbdf,const struct pci_dev_info *info,nodeid_t node);
And again.
Jan
Re: [PATCH v2 11/15] vtd: Rewrite igd device check in acpi_parse_dev_scope()
In reply to Teddy Astiexen/drivers/passthrough/vtd/dmar.c static int __init acpi_parse_dev_scope( · line 394
Quoted 10 lines · Teddy Astie
xen/drivers/passthrough/vtd/dmar.c +1
-1@@ -389,7 +389,7 @@ static int __init acpi_parse_dev_scope( PCI_CLASS_DEVICE + 1) != 0x03 /* PCI_BASE_CLASS_DISPLAY */ ) gfx_only = false; - else if ( !seg && !dev_sbdf.bus && path->dev == 2 && !path->fn ) + else if ( dev_sbdf.sbdf == PCI_SBDF(0, 0, 2, 0).sbdf ) igd_drhd_address = drhd->address; }
Just like we have mfn_eq() and gfn_eq(), should we perhaps also have a (typesafe) sbdf_eq() for use e.g. here?
Jan
Re: [PATCH v2 13/15] pci: Drop parse_pci{_seg}()
In reply to Teddy AstieQuoted 4 lines · Teddy Astie
xen/include/xen/pci.h +0
-0@@ -273,12 +273,6 @@ unsigned int pci_find_ext_capability(const struct pci_dev *pdev, unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev,
xen/include/xen/pci.h unsigned int pci_find_ext_capability(const struct pci_dev *pdev, · line 277
Quoted 10 lines
xen/include/xen/pci.h +0
-6unsigned int start, unsigned int cap); -const char *parse_pci (const char *s,unsigned int *seg_p,unsigned int *bus_p, -unsigned int *dev_p,unsigned int *func_p); -const char *parse_pci_seg (const char *s,unsigned int *seg_p, -unsigned int *bus_p,unsigned int *dev_p, -unsigned int *func_p,bool *def_seg); -const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf);const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg);
Could I talk you into adding yet another cleanup patch on top, to drop the _sbdf again from these new functions? They really only serve an intermediate purpose.
Jan
Re: [PATCH v2 14/15] ehci-dbgp: Use pci_sbdf_t instead of (bus, slot, func)
In reply to Teddy Astiexen/drivers/char/ehci-dbgp.c struct ehci_dbgp { · line 338
Quoted 8 lines · Teddy Astie
xen/drivers/char/ehci-dbgp.c +1
-1@@ -335,7 +335,8 @@ struct ehci_dbgp {struct timer timer;spinlock_t *lock;bool reset_run; -u8 bus, slot, func, bar; +u8 bar;
Please switch to uint8_t while touching the line.
Quoted 11 lines
xen/drivers/char/ehci-dbgp.c +1
-3@@ -1009,20 +1008,18 @@ static set_debug_port_t __read_mostly set_debug_port = default_set_debug_port; static void cf_check nvidia_set_debug_port(struct ehci_dbgp *dbgp,unsigned int port) { -uint32_t dword =pci_conf_read32 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, - dbgp->func),0x74 ); +uint32_t dword =pci_conf_read32 (dbgp->sbdf,0x74 ); dword &= ~(0x0f <<12 ); dword |= (port &0x0f ) <<12 ; - pci_conf_write32(PCI_SBDF(0, dbgp->bus, dbgp->slot, dbgp->func), 0x74,
xen/drivers/char/ehci-dbgp.c static set_debug_port_t __read_mostly set_debug_port = default_set_debug_port; · line 1022
Quoted 10 lines
xen/drivers/char/ehci-dbgp.c +2
-2+pci_conf_write32 (dbgp->sbdf,0x74 , dword);dbgp_printk ("set debug port to %u\n" , port); }static void __init detect_set_debug_port (struct ehci_dbgp *dbgp) { -if (pci_conf_read16 (PCI_SBDF (0 , dbgp->bus, dbgp->slot, dbgp->func), -PCI_VENDOR_ID ) ==0x10de ) +if (pci_conf_read16 (dbgp->sbdf,PCI_VENDOR_ID ) ==0x10de )
This could also do with using PCI_VENDOR_ID_NVIDIA while touching it.
Jan
Re: [PATCH v2 13/15] pci: Drop parse_pci{_seg}()
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 9 lines · Teddy Astie
xen/include/xen/pci.h +0
-3@@ -273,12 +273,6 @@ unsigned int pci_find_ext_capability(const struct pci_dev *pdev,unsigned int pci_find_next_ext_capability (const struct pci_dev *pdev,unsigned int start,unsigned int cap); -const char *parse_pci (const char *s,unsigned int *seg_p,unsigned int *bus_p, -unsigned int *dev_p,unsigned int *func_p); -const char *parse_pci_seg(const char *s, unsigned int *seg_p,
Quoted 8 lines
xen/include/xen/pci.h unsigned int pci_find_ext_capability(const struct pci_dev *pdev, · line 277
Quoted 5 lines
xen/include/xen/pci.h +0
-3- unsigned int *bus_p, unsigned int *dev_p, - unsigned int *func_p, bool *def_seg); -const char *parse_pci_sbdf (const char *s,pci_sbdf_t *sbdf);const char *parse_pci_sbdf_seg (const char *s,pci_sbdf_t *sbdf,bool *def_seg);Could I talk you into adding yet another cleanup patch on top, to drop the
_sbdfagain from these new functions? They really only serve an intermediate purpose.
I was wondering about doing the same.
This is superficially ugly, but it avoids needing to rename the callers:
xen/include/xen/pci.h +0 -0
@@ -274,15 +274,28 @@ unsigned int pci_find_ext_capability(const struct pci_dev *pdev,
unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev, unsigned int start,
unsigned int cap);
-const char *parse_pci(const char *s, unsigned int *seg_p, unsigned int *bus_p, +const char *parse_pci_split(const char *s, unsigned int *seg_p, unsigned int *bus_p, unsigned int *dev_p, unsigned int *func_p);
-const char *parse_pci_seg(const char *s, unsigned int *seg_p,
+const char *parse_pci_split_seg(const char *s, unsigned int *seg_p,
unsigned int *bus_p, unsigned int *dev_p,
unsigned int *func_p, bool *def_seg);
const char *parse_pci_sbdf(const char *s, pci_sbdf_t *sbdf);
const char *parse_pci_sbdf_seg(const char *s, pci_sbdf_t *sbdf, bool *def_seg);
+#define _parse_pci_split(a, b, c, d, e, ...) parse_pci_split(a, b, c, d, e) +#define _parse_pci_split_seg(a, b, c, d, e, f, ...) parse_pci_split_seg(a, b, c, d, e, f) +
+#define parse_pci(a, b, ...) \
+ (count_args(__VA_ARGS__) > 0 \
+ ? _parse_pci_split(a, (void *)b, ##__VA_ARGS__, NULL, NULL, NULL) \
+ : parse_pci_sbdf(a, (void *)b))
+
+#define parse_pci_seg(a, b, c, ...) \
+ (count_args(__VA_ARGS__) > 0 \
+ ? _parse_pci_split_seg(a, (void *)b, (void *)c, __VA_ARGS__, NULL, NULL, NULL, NULL) \
+ : parse_pci_sbdf_seg(a, (void *)b, (void *)c))
+
#define PCI_BAR_VF (1u << 0)
#define PCI_BAR_LAST (1u << 1)
#define PCI_BAR_ROM (1u << 2)
You can add this after introducing the *_sbdf() functions, and then delete it after the final caller is converted.
The void casts are unavoidable because both sides fragments of the ternary are typechecked, but we regain typesafety at the end.
~Andrew
Re: [PATCH v2 04/15] pci: Parse into pci_sbdf_t directly
In reply to Teddy AstieQuoted 18 lines · Teddy Astie
Use the newly introduced
parse_pci_sbdf()andparse_pci_sbdf_seg()in order to parse into apci_sbdf_tdirectly instead of reconstructing it afterward.Signed-off-by Teddy Astie <[email protected]>--- xen/drivers/char/ns16550.c | 24 +++++++++++----------- xen/drivers/char/xhci-dbc.c | 6 +++--- xen/drivers/passthrough/amd/iommu_acpi.c | 26 ++++++++++++------------ xen/drivers/passthrough/vtd/dmar.c | 7 +++---- 4 files changed, 31 insertions(+), 32 deletions(-)xen/drivers/char/ns16550.c +0
-0@@ -1572,22 +1572,22 @@ static bool __init parse_positional(struct ns16550 *uart, char **str)#ifdef CONFIG_HAS_PCI if ( *conf ==',' && *++conf !=',' )
xen/drivers/char/ns16550.c static bool __init parse_positional(struct ns16550 *uart, char **str) · line 1580
Quoted 10 lines
xen/drivers/char/ns16550.c +3
-3{ -unsigned int b, d, f; +pci_sbdf_t sbdf; - conf =parse_pci (conf,NULL , &b, &d, &f); + conf =parse_pci_sbdf (conf, &sbdf);if ( !conf )PARSE_ERR_RET ("Bad port PCI coordinates" ); - uart->pci_device =PCI_SBDF (0 , b, d, f); + uart->pci_device = sbdf;
You could parse directly into uart->pci_device (for example)
conf = parse_pci_sbdf(conf, &uart->pci_device);
and that would eliminate a lot of the temporary sbdf variables. But to do that, you'd want to change parse_pci_sbdf() to only write the sbdf if returning non-NULL. Not strictly necessary, but it seems safer that way.
Quoted 22 lines
xen/drivers/char/ns16550.c +3
-3uart->ps_bdf_enable = true; }if ( *conf ==',' && *++conf !=',' ) { -unsigned int b, d, f; +pci_sbdf_t sbdf; -if ( !parse_pci (conf,NULL , &b, &d, &f) ) +if ( !parse_pci_sbdf (conf, &sbdf) )PARSE_ERR_RET ("Bad bridge PCI coordinates" ); - uart->pci_bridge =PCI_SBDF (0 , b, d, f); + uart->pci_bridge = sbdf; uart->pb_bdf_enable = true; }#endif xen/drivers/passthrough/vtd/dmar.c +0
-0
xen/drivers/passthrough/vtd/dmar.c static int __init cf_check parse_rmrr_param(const char *str) · line 1219
Quoted 5 lines
xen/drivers/passthrough/vtd/dmar.c +1
-1@@ -1216,7 +1216,7 @@ static int __init cf_check parse_rmrr_param(const char *str) do { bool def_seg = false; - stmp = parse_pci_seg(s + 1, &seg, &bus, &dev, &func, &def_seg); + stmp = parse_pci_sbdf_seg(s + 1, &sbdf, &def_seg);
Andrew already pointed out that sbdf is introduced in patch 3 when it should be introduced in this patch.
Regards,
Jason
Quoted 3 lines
xen/drivers/passthrough/vtd/dmar.c +0
-0if ( !stmp )return -EINVAL ;