Skip to content

Commit 52fbf5b

Browse files
Rajat Jainbjorn-helgaas
authored andcommitted
PCI: Cache ACS capability offset in device
Currently the ACS capability is being looked up at a number of places. Read and store it once at enumeration so that it can be used by all later. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rajat Jain <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent cbe4203 commit 52fbf5b

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

drivers/pci/p2pdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static int pci_bridge_has_acs_redir(struct pci_dev *pdev)
253253
int pos;
254254
u16 ctrl;
255255

256-
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
256+
pos = pdev->acs_cap;
257257
if (!pos)
258258
return 0;
259259

drivers/pci/pci.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ static void pci_disable_acs_redir(struct pci_dev *dev)
831831
if (!pci_dev_specific_disable_acs_redir(dev))
832832
return;
833833

834-
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
834+
pos = dev->acs_cap;
835835
if (!pos) {
836836
pci_warn(dev, "cannot disable ACS redirect for this hardware as it does not have ACS capabilities\n");
837837
return;
@@ -857,7 +857,7 @@ static void pci_std_enable_acs(struct pci_dev *dev)
857857
u16 cap;
858858
u16 ctrl;
859859

860-
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
860+
pos = dev->acs_cap;
861861
if (!pos)
862862
return;
863863

@@ -883,7 +883,7 @@ static void pci_std_enable_acs(struct pci_dev *dev)
883883
* pci_enable_acs - enable ACS if hardware support it
884884
* @dev: the PCI device
885885
*/
886-
void pci_enable_acs(struct pci_dev *dev)
886+
static void pci_enable_acs(struct pci_dev *dev)
887887
{
888888
if (!pci_acs_enable)
889889
goto disable_acs_redir;
@@ -3362,7 +3362,7 @@ static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
33623362
int pos;
33633363
u16 cap, ctrl;
33643364

3365-
pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
3365+
pos = pdev->acs_cap;
33663366
if (!pos)
33673367
return false;
33683368

@@ -3487,6 +3487,18 @@ bool pci_acs_path_enabled(struct pci_dev *start,
34873487
return true;
34883488
}
34893489

3490+
/**
3491+
* pci_acs_init - Initialize ACS if hardware supports it
3492+
* @dev: the PCI device
3493+
*/
3494+
void pci_acs_init(struct pci_dev *dev)
3495+
{
3496+
dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3497+
3498+
if (dev->acs_cap)
3499+
pci_enable_acs(dev);
3500+
}
3501+
34903502
/**
34913503
* pci_rebar_find_pos - find position of resize ctrl reg for BAR
34923504
* @pdev: PCI device

drivers/pci/pci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
532532
return resource_alignment(res);
533533
}
534534

535-
void pci_enable_acs(struct pci_dev *dev);
535+
void pci_acs_init(struct pci_dev *dev);
536536
#ifdef CONFIG_PCI_QUIRKS
537537
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
538538
int pci_dev_specific_enable_acs(struct pci_dev *dev);

drivers/pci/probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ static void pci_init_capabilities(struct pci_dev *dev)
23902390
pci_ats_init(dev); /* Address Translation Services */
23912391
pci_pri_init(dev); /* Page Request Interface */
23922392
pci_pasid_init(dev); /* Process Address Space ID */
2393-
pci_enable_acs(dev); /* Enable ACS P2P upstream forwarding */
2393+
pci_acs_init(dev); /* Access Control Services */
23942394
pci_ptm_init(dev); /* Precision Time Measurement */
23952395
pci_aer_init(dev); /* Advanced Error Reporting */
23962396
pci_dpc_init(dev); /* Downstream Port Containment */

drivers/pci/quirks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4653,7 +4653,7 @@ static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)
46534653
if (!pci_quirk_intel_spt_pch_acs_match(dev))
46544654
return -ENOTTY;
46554655

4656-
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
4656+
pos = dev->acs_cap;
46574657
if (!pos)
46584658
return -ENOTTY;
46594659

@@ -4961,7 +4961,7 @@ static int pci_quirk_enable_intel_spt_pch_acs(struct pci_dev *dev)
49614961
if (!pci_quirk_intel_spt_pch_acs_match(dev))
49624962
return -ENOTTY;
49634963

4964-
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
4964+
pos = dev->acs_cap;
49654965
if (!pos)
49664966
return -ENOTTY;
49674967

@@ -4988,7 +4988,7 @@ static int pci_quirk_disable_intel_spt_pch_acs_redir(struct pci_dev *dev)
49884988
if (!pci_quirk_intel_spt_pch_acs_match(dev))
49894989
return -ENOTTY;
49904990

4991-
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
4991+
pos = dev->acs_cap;
49924992
if (!pos)
49934993
return -ENOTTY;
49944994

@@ -5355,7 +5355,7 @@ int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *l, int timeout)
53555355
bool found;
53565356
struct pci_dev *bridge = bus->self;
53575357

5358-
pos = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ACS);
5358+
pos = bridge->acs_cap;
53595359

53605360
/* Disable ACS SV before initial config reads */
53615361
if (pos) {

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ struct pci_dev {
486486
#ifdef CONFIG_PCI_P2PDMA
487487
struct pci_p2pdma *p2pdma;
488488
#endif
489+
u16 acs_cap; /* ACS Capability offset */
489490
phys_addr_t rom; /* Physical address if not from BAR */
490491
size_t romlen; /* Length if not from BAR */
491492
char *driver_override; /* Driver name to force a match */

0 commit comments

Comments
 (0)