Skip to contentSkip to conversation

PCI/VFIO: use pcie_flags_reg instead of access PCI-E Capabilities Register

PATCH In review Yijing Wang 2 participants 3 messages Mar 27, 2013 – Apr 2, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/VFIO: use pcie_flags_reg instead of access PCI-E Capabilities Register

Currently, we use pcie_flags_reg to cache PCI-E Capabilities Register, because PCI-E Capabilities Register bits are almost read-only. This patch use pcie_flags_reg instead of another access PCI-E Capabilities Register.

---
 drivers/vfio/pci/vfio_pci_config.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
drivers/vfio/pci/vfio_pci_config.c +1 -5
index aeb00fc..afc6ca4 100644
@@ -1017,13 +1017,9 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
 		return byte;
 	case PCI_CAP_ID_EXP:
 		/* length based on version */
-		ret = pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &word);
-		if (ret)
-			return pcibios_err_to_errno(ret);
-
 		vdev->extended_caps = true;
 
-		if ((word & PCI_EXP_FLAGS_VERS) == 1)
+		if ((pdev->pcie_flags_reg & PCI_EXP_FLAGS_VERS) == 1)
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V1;
 		else
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V2;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 15 lines · Yijing Wang

Currently, we use pcie_flags_reg to cache PCI-E Capabilities Register, because PCI-E Capabilities Register bits are almost read-only. This patch use pcie_flags_reg instead of another access PCI-E Capabilities Register.

---
 drivers/vfio/pci/vfio_pci_config.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
drivers/vfio/pci/vfio_pci_config.c +0 -0
index aeb00fc..afc6ca4 100644
@@ -1017,13 +1017,9 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
 		return byte;

drivers/vfio/pci/vfio_pci_config.c static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) · line 1022

Quoted 10 lines
drivers/vfio/pci/vfio_pci_config.c +1 -5
 	case PCI_CAP_ID_EXP:
 		/* length based on version */
-		ret = pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &word);
-		if (ret)
-			return pcibios_err_to_errno(ret);
-
 		vdev->extended_caps = true;
 
-		if ((word & PCI_EXP_FLAGS_VERS) == 1)
+		if ((pdev->pcie_flags_reg & PCI_EXP_FLAGS_VERS) == 1)

It looks like we should be using pcie_caps_reg(pdev) here instead of directly accessing pcie_flags_reg. Thanks,

Alex

Quoted 3 lines
drivers/vfio/pci/vfio_pci_config.c +0 -0
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V1;
 		else
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V2;
#2 lore raw
Quoted 10 lines
Quoted 10 lines
drivers/vfio/pci/vfio_pci_config.c +0 -4
@@ -1017,13 +1017,9 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
 		return byte;
 	case PCI_CAP_ID_EXP:
 		/* length based on version */
-		ret = pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &word);
-		if (ret)
-			return pcibios_err_to_errno(ret);
-
 		vdev->extended_caps = true;
 
Quoted 5 lines

drivers/vfio/pci/vfio_pci_config.c static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) · line 1022

Quoted 2 lines
drivers/vfio/pci/vfio_pci_config.c +1 -1
-		if ((word & PCI_EXP_FLAGS_VERS) == 1)
+		if ((pdev->pcie_flags_reg & PCI_EXP_FLAGS_VERS) == 1)

It looks like we should be using pcie_caps_reg(pdev) here instead of directly accessing pcie_flags_reg. Thanks,

That's right, I forget Myron Stowe introduced the PCIe Cap accessor function pcie_caps_reg(). I will resend the updated patch.

Thanks!
Yijing

Quoted 12 lines

Alex

drivers/vfio/pci/vfio_pci_config.c static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) · line 1025

Quoted 3 lines
drivers/vfio/pci/vfio_pci_config.c +0 -0
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V1;
 		else
 			return PCI_CAP_EXP_ENDPOINT_SIZEOF_V2;

.

Signature · 2 lines
Thanks!
Yijing