Skip to content

Commit a87693e

Browse files
sumitsemwalgregkh
authored andcommitted
PCI: Separate VF BAR updates from standard BAR updates
From: Bjorn Helgaas <bhelgaas@google.com> [ Upstream commit 6ffa2489c51da77564a0881a73765ea2169f955d ] Previously pci_update_resource() used the same code path for updating standard BARs and VF BARs in SR-IOV capabilities. Split the VF BAR update into a new pci_iov_update_resource() internal interface, which makes it simpler to compute the BAR address (we can get rid of pci_resource_bar() and pci_iov_resource_bar()). This patch: - Renames pci_update_resource() to pci_std_update_resource(), - Adds pci_iov_update_resource(), - Makes pci_update_resource() a wrapper that calls the appropriate one, No functional change intended. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e4ce31c commit a87693e

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

drivers/pci/iov.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,56 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno)
572572
4 * (resno - PCI_IOV_RESOURCES);
573573
}
574574

575+
/**
576+
* pci_iov_update_resource - update a VF BAR
577+
* @dev: the PCI device
578+
* @resno: the resource number
579+
*
580+
* Update a VF BAR in the SR-IOV capability of a PF.
581+
*/
582+
void pci_iov_update_resource(struct pci_dev *dev, int resno)
583+
{
584+
struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL;
585+
struct resource *res = dev->resource + resno;
586+
int vf_bar = resno - PCI_IOV_RESOURCES;
587+
struct pci_bus_region region;
588+
u32 new;
589+
int reg;
590+
591+
/*
592+
* The generic pci_restore_bars() path calls this for all devices,
593+
* including VFs and non-SR-IOV devices. If this is not a PF, we
594+
* have nothing to do.
595+
*/
596+
if (!iov)
597+
return;
598+
599+
/*
600+
* Ignore unimplemented BARs, unused resource slots for 64-bit
601+
* BARs, and non-movable resources, e.g., those described via
602+
* Enhanced Allocation.
603+
*/
604+
if (!res->flags)
605+
return;
606+
607+
if (res->flags & IORESOURCE_UNSET)
608+
return;
609+
610+
if (res->flags & IORESOURCE_PCI_FIXED)
611+
return;
612+
613+
pcibios_resource_to_bus(dev->bus, &region, res);
614+
new = region.start;
615+
new |= res->flags & ~PCI_BASE_ADDRESS_MEM_MASK;
616+
617+
reg = iov->pos + PCI_SRIOV_BAR + 4 * vf_bar;
618+
pci_write_config_dword(dev, reg, new);
619+
if (res->flags & IORESOURCE_MEM_64) {
620+
new = region.start >> 16 >> 16;
621+
pci_write_config_dword(dev, reg + 4, new);
622+
}
623+
}
624+
575625
resource_size_t __weak pcibios_iov_resource_alignment(struct pci_dev *dev,
576626
int resno)
577627
{

drivers/pci/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ static inline void pci_restore_ats_state(struct pci_dev *dev)
277277
int pci_iov_init(struct pci_dev *dev);
278278
void pci_iov_release(struct pci_dev *dev);
279279
int pci_iov_resource_bar(struct pci_dev *dev, int resno);
280+
void pci_iov_update_resource(struct pci_dev *dev, int resno);
280281
resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
281282
void pci_restore_iov_state(struct pci_dev *dev);
282283
int pci_iov_bus_range(struct pci_bus *bus);

drivers/pci/setup-res.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include <linux/slab.h>
2626
#include "pci.h"
2727

28-
29-
void pci_update_resource(struct pci_dev *dev, int resno)
28+
static void pci_std_update_resource(struct pci_dev *dev, int resno)
3029
{
3130
struct pci_bus_region region;
3231
bool disable;
@@ -110,6 +109,16 @@ void pci_update_resource(struct pci_dev *dev, int resno)
110109
pci_write_config_word(dev, PCI_COMMAND, cmd);
111110
}
112111

112+
void pci_update_resource(struct pci_dev *dev, int resno)
113+
{
114+
if (resno <= PCI_ROM_RESOURCE)
115+
pci_std_update_resource(dev, resno);
116+
#ifdef CONFIG_PCI_IOV
117+
else if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
118+
pci_iov_update_resource(dev, resno);
119+
#endif
120+
}
121+
113122
int pci_claim_resource(struct pci_dev *dev, int resource)
114123
{
115124
struct resource *res = &dev->resource[resource];

0 commit comments

Comments
 (0)