tools/libxl/libxl_pci.c: Extract sysfs_dev_get_class from libxl__grant_vga_iomem_permission
PATCH 1/2 tools/libxl/libxl_pci.c: Extract sysfs_dev_get_class from libxl__grant_vga_iomem_permission
--- tools/libxl/libxl_pci.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)
tools/libxl/libxl_pci.c +27 -18
@@ -531,6 +531,32 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev)return pci_device_device; } +static int sysfs_dev_get_class (libxl__gc *gc,libxl_device_pci *pcidev, +unsigned long *class) +{ +char *pci_device_class_path =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +int read_items; + +FILE *f =fopen (pci_device_class_path,"r" ); +if (!f) { +LOGE (ERROR , +"pci device " PCI_BDF " does not have class attribute" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +return ERROR_FAIL ; + } + read_items =fscanf (f,"0x%lx\n" , class); +fclose (f); +if (read_items !=1 ) { +LOGE (ERROR , +"cannot read class of pci device " PCI_BDF , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +return ERROR_FAIL ; + } + +return 0 ; +} + typedef struct { uint16_t vendor; uint16_t device;
@@ -1652,27 +1678,10 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,uint64_t vga_iomem_start =0xa0000 >>XC_PAGE_SHIFT ;uint32_t stubdom_domid;libxl_device_pci *pcidev = &d_config->pcidevs[i]; -char *pci_device_class_path = -GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -int read_items;unsigned long pci_device_class; -FILE *f =fopen (pci_device_class_path,"r" ); -if (!f) { -LOGED (ERROR , domid, -"pci device " PCI_BDF " does not have class attribute" , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -continue ; - } - read_items =fscanf (f,"0x%lx\n" , &pci_device_class); -fclose (f); -if (read_items !=1 ) { -LOGED (ERROR , domid, -"cannot read class of pci device " PCI_BDF , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +if (sysfs_dev_get_class (gc, pcidev, &pci_device_class))continue ; - }if (pci_device_class !=0x030000 )/* VGA class */ continue ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 tools/libxl/libxl_pci.c: Judge igd through class code instead of device ID
IGD passthrough couldn't work on Skylake and Kabylake, because their Device ID aren't in fixup_ids[]. Currently we need to add every intel graphic ID into fixup_ids[], it is hard to maintain.
This patch judge intel graphics through vendor id (0x8086) and class code(0x030000), this could support both the old and new intel graphics, and reduce maintain work in future.
--- tools/libxl/libxl_pci.c | 59 ++++++++----------------------------------------- 1 file changed, 9 insertions(+), 50 deletions(-)
tools/libxl/libxl_pci.c +9 -50
@@ -557,46 +557,6 @@ static int sysfs_dev_get_class(libxl__gc *gc, libxl_device_pci *pcidev,return 0 ; } -typedef struct { -uint16_t vendor; -uint16_t device; -}pci_info ; - -static const pci_info fixup_ids[] = { -/* Intel HSW Classic */ - {0x8086 ,0x0402 },/* HSWGT1D, HSWD_w7 */ - {0x8086 ,0x0406 },/* HSWGT1M, HSWM_w7 */ - {0x8086 ,0x0412 },/* HSWGT2D, HSWD_w7 */ - {0x8086 ,0x0416 },/* HSWGT2M, HSWM_w7 */ - {0x8086 ,0x041E },/* HSWGT15D, HSWD_w7 */ -/* Intel HSW ULT */ - {0x8086 ,0x0A06 },/* HSWGT1UT, HSWM_w7 */ - {0x8086 ,0x0A16 },/* HSWGT2UT, HSWM_w7 */ - {0x8086 ,0x0A26 },/* HSWGT3UT, HSWM_w7 */ - {0x8086 ,0x0A2E },/* HSWGT3UT28W, HSWM_w7 */ - {0x8086 ,0x0A1E },/* HSWGT2UX, HSWM_w7 */ - {0x8086 ,0x0A0E },/* HSWGT1ULX, HSWM_w7 */ -/* Intel HSW CRW */ - {0x8086 ,0x0D26 },/* HSWGT3CW, HSWM_w7 */ - {0x8086 ,0x0D22 },/* HSWGT3CWDT, HSWD_w7 */ -/* Intel HSW Server */ - {0x8086 ,0x041A },/* HSWSVGT2, HSWD_w7 */ -/* Intel HSW SRVR */ - {0x8086 ,0x040A },/* HSWSVGT1, HSWD_w7 */ -/* Intel BSW */ - {0x8086 ,0x1606 },/* BDWULTGT1, BDWM_w7 */ - {0x8086 ,0x1616 },/* BDWULTGT2, BDWM_w7 */ - {0x8086 ,0x1626 },/* BDWULTGT3, BDWM_w7 */ - {0x8086 ,0x160E },/* BDWULXGT1, BDWM_w7 */ - {0x8086 ,0x161E },/* BDWULXGT2, BDWM_w7 */ - {0x8086 ,0x1602 },/* BDWHALOGT1, BDWM_w7 */ - {0x8086 ,0x1612 },/* BDWHALOGT2, BDWM_w7 */ - {0x8086 ,0x1622 },/* BDWHALOGT3, BDWM_w7 */ - {0x8086 ,0x162B },/* BDWHALO28W, BDWM_w7 */ - {0x8086 ,0x162A },/* BDWGT3WRKS, BDWM_w7 */ - {0x8086 ,0x162D },/* BDWGT3SRVR, BDWM_w7 */ -}; -/* * Some devices may need some ways to work well. Here like IGD, * we have to pass a specific option to qemu.
@@ -604,24 +564,23 @@ static const pci_info fixup_ids[] = {bool libxl__is_igd_vga_passthru (libxl__gc *gc,const libxl_domain_config *d_config) { -unsigned int i, j, num =ARRAY_SIZE (fixup_ids); -uint16_t vendor, device, pt_vendor, pt_device; +unsigned int i; +uint16_t pt_vendor, pt_device; +unsigned long class;for (i =0 ; i < d_config->num_pcidevs ; i++) {libxl_device_pci *pcidev = &d_config->pcidevs[i]; pt_vendor =sysfs_dev_get_vendor (gc, pcidev); pt_device =sysfs_dev_get_device (gc, pcidev); -if (pt_vendor ==0xffff || pt_device ==0xffff ) +if (pt_vendor ==0xffff || pt_device ==0xffff || + pt_vendor !=0x8086 )continue ; -for (j =0 ; j < num ; j++) { - vendor = fixup_ids[j].vendor; - device = fixup_ids[j].device; - -if (pt_vendor == vendor && pt_device == device) -return true; - } +if (sysfs_dev_get_class (gc, pcidev, &class)) +continue ; +if (class ==0x030000 ) +return true; }return false;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/2] tools/libxl/libxl_pci.c: Judge igd through class code instead of device ID
Quoted 9 lines · Xiong Zhang
IGD passthrough couldn't work on Skylake and Kabylake, because their Device ID aren't in fixup_ids[]. Currently we need to add every intel graphic ID into fixup_ids[], it is hard to maintain.
This patch judge intel graphics through vendor id (
0x8086) and class code(0x030000), this could support both the old and new intel graphics, and reduce maintain work in future.Signed-off-by Xiong Zhang <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
On Fri, Jun 30, 2017 at 12:11:26PM +0800, Xiong Zhang wrote:
It would be better in the future you say "No functional change" here.
Quoted 26 lines
Signed-off-by Xiong Zhang <[email protected]>--- tools/libxl/libxl_pci.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)tools/libxl/libxl_pci.c +13
-0@@ -531,6 +531,32 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev)return pci_device_device; } +static int sysfs_dev_get_class (libxl__gc *gc,libxl_device_pci *pcidev, +unsigned long *class) +{ +char *pci_device_class_path =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +int read_items; + +FILE *f =fopen (pci_device_class_path,"r" ); +if (!f) { +LOGE (ERROR , +"pci device " PCI_BDF " does not have class attribute" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +return ERROR_FAIL ;
tools/libxl/libxl_pci.c static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev) · line 556
Quoted 10 lines
tools/libxl/libxl_pci.c +10
-0+ } + read_items =fscanf (f,"0x%lx\n" , class); +fclose (f); +if (read_items !=1 ) { +LOGE (ERROR , +"cannot read class of pci device " PCI_BDF , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +return ERROR_FAIL ; + } +
Please use "goto out" style error handling.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 1/2 tools/libxl/libxl_pci.c: Extract sysfs_dev_get_class from libxl__grant_vga_iomem_permission
In reply to Xiong ZhangNo functional change. Just extract this function for next patch and avoid code repetition.
---
Changes in v2:
-Add No functional change in commit message -Use 'goto out' style error handling
--- tools/libxl/libxl_pci.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-)
tools/libxl/libxl_pci.c +29 -18
@@ -531,6 +531,34 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev)return pci_device_device; } +static int sysfs_dev_get_class (libxl__gc *gc,libxl_device_pci *pcidev, +unsigned long *class) +{ +char *pci_device_class_path =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +int read_items, ret =0 ; + +FILE *f =fopen (pci_device_class_path,"r" ); +if (!f) { +LOGE (ERROR , +"pci device " PCI_BDF " does not have class attribute" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + ret =ERROR_FAIL ; + goto out; + } + read_items =fscanf (f,"0x%lx\n" , class); +fclose (f); +if (read_items !=1 ) { +LOGE (ERROR , +"cannot read class of pci device " PCI_BDF , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + ret =ERROR_FAIL ; + } + +out: +return ret; +} + typedef struct { uint16_t vendor; uint16_t device;
@@ -1652,27 +1680,10 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,uint64_t vga_iomem_start =0xa0000 >>XC_PAGE_SHIFT ;uint32_t stubdom_domid;libxl_device_pci *pcidev = &d_config->pcidevs[i]; -char *pci_device_class_path = -GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -int read_items;unsigned long pci_device_class; -FILE *f =fopen (pci_device_class_path,"r" ); -if (!f) { -LOGED (ERROR , domid, -"pci device " PCI_BDF " does not have class attribute" , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); +if (sysfs_dev_get_class (gc, pcidev, &pci_device_class))continue ; - } - read_items =fscanf (f,"0x%lx\n" , &pci_device_class); -fclose (f); -if (read_items !=1 ) { -LOGED (ERROR , domid, -"cannot read class of pci device " PCI_BDF , - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); -continue ; - }if (pci_device_class !=0x030000 )/* VGA class */ continue ;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 2/2 tools/libxl/libxl_pci.c: Judge igd through class code instead of device ID
IGD passthrough couldn't work on Skylake and Kabylake, because their Device ID aren't in fixup_ids[]. Currently we need to add every intel graphic ID into fixup_ids[], it is hard to maintain.
This patch judge intel graphics through vendor id (0x8086) and class code(0x030000), this could support both the old and new intel graphics, and reduce maintain work in future.
---
Changes in v2:
-Add Acked-by: Wei Liu <[email protected]>
--- tools/libxl/libxl_pci.c | 59 ++++++++----------------------------------------- 1 file changed, 9 insertions(+), 50 deletions(-)
tools/libxl/libxl_pci.c +9 -50
@@ -559,46 +559,6 @@ out:return ret; } -typedef struct { -uint16_t vendor; -uint16_t device; -}pci_info ; - -static const pci_info fixup_ids[] = { -/* Intel HSW Classic */ - {0x8086 ,0x0402 },/* HSWGT1D, HSWD_w7 */ - {0x8086 ,0x0406 },/* HSWGT1M, HSWM_w7 */ - {0x8086 ,0x0412 },/* HSWGT2D, HSWD_w7 */ - {0x8086 ,0x0416 },/* HSWGT2M, HSWM_w7 */ - {0x8086 ,0x041E },/* HSWGT15D, HSWD_w7 */ -/* Intel HSW ULT */ - {0x8086 ,0x0A06 },/* HSWGT1UT, HSWM_w7 */ - {0x8086 ,0x0A16 },/* HSWGT2UT, HSWM_w7 */ - {0x8086 ,0x0A26 },/* HSWGT3UT, HSWM_w7 */ - {0x8086 ,0x0A2E },/* HSWGT3UT28W, HSWM_w7 */ - {0x8086 ,0x0A1E },/* HSWGT2UX, HSWM_w7 */ - {0x8086 ,0x0A0E },/* HSWGT1ULX, HSWM_w7 */ -/* Intel HSW CRW */ - {0x8086 ,0x0D26 },/* HSWGT3CW, HSWM_w7 */ - {0x8086 ,0x0D22 },/* HSWGT3CWDT, HSWD_w7 */ -/* Intel HSW Server */ - {0x8086 ,0x041A },/* HSWSVGT2, HSWD_w7 */ -/* Intel HSW SRVR */ - {0x8086 ,0x040A },/* HSWSVGT1, HSWD_w7 */ -/* Intel BSW */ - {0x8086 ,0x1606 },/* BDWULTGT1, BDWM_w7 */ - {0x8086 ,0x1616 },/* BDWULTGT2, BDWM_w7 */ - {0x8086 ,0x1626 },/* BDWULTGT3, BDWM_w7 */ - {0x8086 ,0x160E },/* BDWULXGT1, BDWM_w7 */ - {0x8086 ,0x161E },/* BDWULXGT2, BDWM_w7 */ - {0x8086 ,0x1602 },/* BDWHALOGT1, BDWM_w7 */ - {0x8086 ,0x1612 },/* BDWHALOGT2, BDWM_w7 */ - {0x8086 ,0x1622 },/* BDWHALOGT3, BDWM_w7 */ - {0x8086 ,0x162B },/* BDWHALO28W, BDWM_w7 */ - {0x8086 ,0x162A },/* BDWGT3WRKS, BDWM_w7 */ - {0x8086 ,0x162D },/* BDWGT3SRVR, BDWM_w7 */ -}; -/* * Some devices may need some ways to work well. Here like IGD, * we have to pass a specific option to qemu.
@@ -606,24 +566,23 @@ static const pci_info fixup_ids[] = {bool libxl__is_igd_vga_passthru (libxl__gc *gc,const libxl_domain_config *d_config) { -unsigned int i, j, num =ARRAY_SIZE (fixup_ids); -uint16_t vendor, device, pt_vendor, pt_device; +unsigned int i; +uint16_t pt_vendor, pt_device; +unsigned long class;for (i =0 ; i < d_config->num_pcidevs ; i++) {libxl_device_pci *pcidev = &d_config->pcidevs[i]; pt_vendor =sysfs_dev_get_vendor (gc, pcidev); pt_device =sysfs_dev_get_device (gc, pcidev); -if (pt_vendor ==0xffff || pt_device ==0xffff ) +if (pt_vendor ==0xffff || pt_device ==0xffff || + pt_vendor !=0x8086 )continue ; -for (j =0 ; j < num ; j++) { - vendor = fixup_ids[j].vendor; - device = fixup_ids[j].device; - -if (pt_vendor == vendor && pt_device == device) -return true; - } +if (sysfs_dev_get_class (gc, pcidev, &class)) +continue ; +if (class ==0x030000 ) +return true; }return false;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 4 lines · Xiong Zhang
No functional change. Just extract this function for next patch and avoid code repetition.
Signed-off-by Xiong Zhang <[email protected]>
Note to self: maybe add some blank lines while committing.
Quoted 21 lines
---
Changes in v2:
-Add No functional change in commit message -Use 'goto out' style error handling--- tools/libxl/libxl_pci.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-)tools/libxl/libxl_pci.c +5
-0@@ -531,6 +531,34 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev)return pci_device_device; } +static int sysfs_dev_get_class (libxl__gc *gc,libxl_device_pci *pcidev, +unsigned long *class) +{ +char *pci_device_class_path =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/class" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func);
tools/libxl/libxl_pci.c static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev) · line 548
Quoted 10 lines
tools/libxl/libxl_pci.c +10
-0+int read_items, ret =0 ; + +FILE *f =fopen (pci_device_class_path,"r" ); +if (!f) { +LOGE (ERROR , +"pci device " PCI_BDF " does not have class attribute" , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + ret =ERROR_FAIL ; + goto out; + }
Here.
tools/libxl/libxl_pci.c static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev) · line 549
Quoted 1 line
tools/libxl/libxl_pci.c +1
-0+ read_items =fscanf (f,"0x%lx\n" , class);
Here.
tools/libxl/libxl_pci.c static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev) · line 550
Quoted 1 line
tools/libxl/libxl_pci.c +1
-0+fclose (f);
Here.
tools/libxl/libxl_pci.c static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcidev) · line 561
Quoted 11 lines
tools/libxl/libxl_pci.c +11
-0+if (read_items !=1 ) { +LOGE (ERROR , +"cannot read class of pci device " PCI_BDF , + pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + ret =ERROR_FAIL ; + } + +out: +return ret; +} +
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines · Wei Liu
Quoted 4 lines · Xiong Zhang
No functional change. Just extract this function for next patch and avoid code repetition.
Signed-off-by Xiong Zhang <[email protected]>Acked-by Wei Liu <[email protected]>Note to self: maybe add some blank lines while committing.
Not that I intend this patch to fix this, but poking ad sysfs nodes should be done in libxl_linux.c.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 5 lines · Roger Pau Monné
Quoted 4 lines · Wei Liu
Quoted 3 lines · Xiong Zhang
No functional change. Just extract this function for next patch and avoid code repetition.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Xiong Zhang <[email protected]>Acked-by Wei Liu <[email protected]>Note to self: maybe add some blank lines while committing.
Not that I intend this patch to fix this, but poking ad sysfs nodes should be done in
libxl_linux.c.
Indeed. Patches welcome...
Quoted 2 lines
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel