blob: a6284098b126f7f3e5971eb4153dfe19121b2f20 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001Upstream-Status: Inappropriate [will not be submitted as its a workaround to address hardware issue]
2Signed-off-by: Khasim Syed Mohammed <khasim.mohammed@arm.com>
3
4From e47ab593ee36b2480f8c2196722cded42749629a Mon Sep 17 00:00:00 2001
5From: Manoj Kumar <manoj.kumar3@arm.com>
6Date: Tue, 31 Aug 2021 16:15:38 +0000
7Subject: [PATCH 2/5] n1sdp: pci_quirk: add acs override for PCI devices
8
9Patch taken from:
10https://gitlab.com/Queuecumber/linux-acs-override/raw/master/workspaces/5.4/acso.patch
11
12Change-Id: Ib926bf50524ce9990fbaa2f2f8670fe84bd571f9
13Signed-off-by: Manoj Kumar <manoj.kumar3@arm.com>
14---
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
20index 43dc35fe5bc0..a60e454854d7 100644
21--- a/Documentation/admin-guide/kernel-parameters.txt
22+++ b/Documentation/admin-guide/kernel-parameters.txt
23@@ -3892,6 +3892,14 @@
24 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
39index 4537d1ea14fd..984f30d25a6d 100644
40--- a/drivers/pci/quirks.c
41+++ b/drivers/pci/quirks.c
42@@ -3588,6 +3588,107 @@ static void quirk_no_bus_reset(struct pci_dev *dev)
43 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.
150@@ -4949,6 +5050,7 @@ static const struct pci_dev_acs_enabled {
151 { 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
158--
1592.17.1
160