blob: b4e2a8c50c3e6bda1db97dd43368ea01d72e076c [file] [log] [blame]
Patrick Williams8dd68482022-10-04 07:57:18 -05001From 478d96ce8a4d30ef80975271a2ad89a77012c1b8 Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Manoj Kumar <manoj.kumar3@arm.com>
3Date: Tue, 31 Aug 2021 16:15:38 +0000
Patrick Williams8dd68482022-10-04 07:57:18 -05004Subject: [PATCH] n1sdp: pci_quirk: add acs override for PCI devices
Brad Bishopbec4ebc2022-08-03 09:55:16 -04005
6Patch taken from:
7https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.4/acso.patch
8
9Change-Id: Ib926bf50524ce9990fbaa2f2f8670fe84bd571f9
10Signed-off-by: Manoj Kumar <manoj.kumar3@arm.com>
Patrick Williams8dd68482022-10-04 07:57:18 -050011
12Upstream-Status: Inappropriate [will not be submitted as its a workaround to address hardware issue]
13Signed-off-by: Khasim Syed Mohammed <khasim.mohammed@arm.com>
Brad Bishopbec4ebc2022-08-03 09:55:16 -040014---
15 .../admin-guide/kernel-parameters.txt | 8 ++
16 drivers/pci/quirks.c | 102 ++++++++++++++++++
17 2 files changed, 110 insertions(+)
18
19diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
Patrick Williams8dd68482022-10-04 07:57:18 -050020index 4445baac48c1..ee90aeeb1dbb 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040021--- a/Documentation/admin-guide/kernel-parameters.txt
22+++ b/Documentation/admin-guide/kernel-parameters.txt
Patrick Williams8dd68482022-10-04 07:57:18 -050023@@ -3935,6 +3935,14 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -040024 nomsi [MSI] If the PCI_MSI kernel config parameter is
25 enabled, this kernel boot option can be used to
26 disable the use of MSI interrupts system-wide.
27+ pcie_acs_override [PCIE] Override missing PCIe ACS support for
28+ downstream
29+ All downstream ports - full ACS capabilities
30+ multfunction
31+ All multifunction devices - multifunction ACS subset
32+ id:nnnn:nnnn
33+ Specfic device - full ACS capabilities
34+ Specified as vid:did (vendor/device ID) in hex
35 noioapicquirk [APIC] Disable all boot interrupt quirks.
36 Safety option to keep boot IRQs enabled. This
37 should never be necessary.
38diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
Patrick Williams8dd68482022-10-04 07:57:18 -050039index a531064233f9..ebe192134a97 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040040--- a/drivers/pci/quirks.c
41+++ b/drivers/pci/quirks.c
Patrick Williams8dd68482022-10-04 07:57:18 -050042@@ -3600,6 +3600,107 @@ static void quirk_no_bus_reset(struct pci_dev *dev)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040043 dev->dev_flags |= PCI_DEV_FLAGS_NO_BUS_RESET;
44 }
45
46+static bool acs_on_downstream;
47+static bool acs_on_multifunction;
48+
49+#define NUM_ACS_IDS 16
50+struct acs_on_id {
51+ unsigned short vendor;
52+ unsigned short device;
53+};
54+static struct acs_on_id acs_on_ids[NUM_ACS_IDS];
55+static u8 max_acs_id;
56+
57+static __init int pcie_acs_override_setup(char *p)
58+{
59+ if (!p)
60+ return -EINVAL;
61+
62+ while (*p) {
63+ if (!strncmp(p, "downstream", 10))
64+ acs_on_downstream = true;
65+ if (!strncmp(p, "multifunction", 13))
66+ acs_on_multifunction = true;
67+ if (!strncmp(p, "id:", 3)) {
68+ char opt[5];
69+ int ret;
70+ long val;
71+
72+ if (max_acs_id >= NUM_ACS_IDS - 1) {
73+ pr_warn("Out of PCIe ACS override slots (%d)\n",
74+ NUM_ACS_IDS);
75+ goto next;
76+ }
77+
78+ p += 3;
79+ snprintf(opt, 5, "%s", p);
80+ ret = kstrtol(opt, 16, &val);
81+ if (ret) {
82+ pr_warn("PCIe ACS ID parse error %d\n", ret);
83+ goto next;
84+ }
85+ acs_on_ids[max_acs_id].vendor = val;
86+
87+ p += strcspn(p, ":");
88+ if (*p != ':') {
89+ pr_warn("PCIe ACS invalid ID\n");
90+ goto next;
91+ }
92+
93+ p++;
94+ snprintf(opt, 5, "%s", p);
95+ ret = kstrtol(opt, 16, &val);
96+ if (ret) {
97+ pr_warn("PCIe ACS ID parse error %d\n", ret);
98+ goto next;
99+ }
100+ acs_on_ids[max_acs_id].device = val;
101+ max_acs_id++;
102+ }
103+next:
104+ p += strcspn(p, ",");
105+ if (*p == ',')
106+ p++;
107+ }
108+
109+ if (acs_on_downstream || acs_on_multifunction || max_acs_id)
110+ pr_warn("Warning: PCIe ACS overrides enabled; This may allow non-IOMMU protected peer-to-peer DMA\n");
111+
112+ return 0;
113+}
114+early_param("pcie_acs_override", pcie_acs_override_setup);
115+
116+static int pcie_acs_overrides(struct pci_dev *dev, u16 acs_flags)
117+{
118+ int i;
119+
120+ /* Never override ACS for legacy devices or devices with ACS caps */
121+ if (!pci_is_pcie(dev) ||
122+ pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS))
123+ return -ENOTTY;
124+
125+ for (i = 0; i < max_acs_id; i++)
126+ if (acs_on_ids[i].vendor == dev->vendor &&
127+ acs_on_ids[i].device == dev->device)
128+ return 1;
129+
130+ switch (pci_pcie_type(dev)) {
131+ case PCI_EXP_TYPE_DOWNSTREAM:
132+ case PCI_EXP_TYPE_ROOT_PORT:
133+ if (acs_on_downstream)
134+ return 1;
135+ break;
136+ case PCI_EXP_TYPE_ENDPOINT:
137+ case PCI_EXP_TYPE_UPSTREAM:
138+ case PCI_EXP_TYPE_LEG_END:
139+ case PCI_EXP_TYPE_RC_END:
140+ if (acs_on_multifunction && dev->multifunction)
141+ return 1;
142+ }
143+
144+ return -ENOTTY;
145+}
146+
147 /*
148 * Some NVIDIA GPU devices do not work with bus reset, SBR needs to be
149 * prevented for those affected devices.
Patrick Williams8dd68482022-10-04 07:57:18 -0500150@@ -4968,6 +5069,7 @@ static const struct pci_dev_acs_enabled {
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400151 { PCI_VENDOR_ID_NXP, 0x8d9b, pci_quirk_nxp_rp_acs },
152 /* Zhaoxin Root/Downstream Ports */
153 { PCI_VENDOR_ID_ZHAOXIN, PCI_ANY_ID, pci_quirk_zhaoxin_pcie_ports_acs },
154+ { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides },
155 { 0 }
156 };
157