Skip to contentSkip to conversation

PCI/ACPI: add support for CXL _OSC

PATCH In review Vishal Verma 4 participants 9 messages Apr 13, 2022 – Apr 25, 2022

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

v6 cover PCI/ACPI: add support for CXL _OSC

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Add support for using the CXL definition of _OSC where applicable, and negotiating CXL specific support and control bits.

Patch 1 is a preliminary cleanup that replaces open-coded pointer arithmetic to retrieve the Control DWORD with an inline helper.

Patch 2 adds the new CXL _OSC UUID, and uses it instead of the PCI UUID when a root port is CXL enabled. It provides a fallback method for CXL-1.1 platforms that may not implement the CXL-2.0 _OSC.

Patch 3 performs negotiation for the CXL specific _OSC support and control bits.

I've tested these against a custom qemu[2], which adds the CXL _OSC (in addition to other CXL support). Specifically, _OSC support is added here[3].

[1]: https://lore.kernel.org/linux-cxl/[email protected]
[2]: https://gitlab.com/jic23/qemu/-/tree/cxl-v8-draft
[3]: https://gitlab.com/jic23/qemu/-/commit/1d67df6b6e3716c27462873f3451956f5c0673a3

Dan Williams (1):
PCI/ACPI: Prefer CXL _OSC instead of PCIe _OSC for CXL host bridges

Vishal Verma (2):
PCI/ACPI: add a helper for retrieving _OSC Control DWORDs PCI/ACPI: negotiate CXL _OSC

 include/linux/acpi.h    |  42 ++++++-
 include/acpi/acpi_bus.h |  12 +-
 drivers/acpi/bus.c      |   2 +-
 drivers/acpi/pci_root.c | 240 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 262 insertions(+), 34 deletions(-)

base-commit: 05e815539f3f161585c13a9ab023341bade2c52f

Signature · 1 line
2.35.1
#1 lore raw

PATCH v6 1/3 PCI/ACPI: add a helper for retrieving _OSC Control DWORDs

During _OSC negotiation, when the 'Control' DWORD is needed from the result buffer after running _OSC, a couple of places performed manual pointer arithmetic to offset into the right spot in the raw buffer. Add a acpi_osc_ctx_get_pci_control() helper to use the #define'd DWORD offsets to fetch the DWORDs needed from @acpi_osc_context, and replace the above instances of the open-coded arithmetic.

Reviewed by: Adam Manzanares <[email protected]>

---
 include/linux/acpi.h    | 13 +++++++++++++
 drivers/acpi/bus.c      |  2 +-
 drivers/acpi/pci_root.c |  2 +-
 3 files changed, 15 insertions(+), 2 deletions(-)
include/linux/acpi.h +13 -0
index 6274758648e3..ff4d1fdd9009 100644
@@ -607,6 +607,13 @@ extern u32 osc_sb_native_usb4_control;
 #define OSC_PCI_EXPRESS_LTR_CONTROL		0x00000020
 #define OSC_PCI_EXPRESS_DPC_CONTROL		0x00000080
 
+static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
+{
+	u32 *ret = context->ret.pointer;
+
+	return ret[OSC_CONTROL_DWORD];
+}
+
 #define ACPI_GSB_ACCESS_ATTRIB_QUICK		0x00000002
 #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV         0x00000004
 #define ACPI_GSB_ACCESS_ATTRIB_BYTE		0x00000006
@@ -1003,6 +1010,12 @@ static inline int acpi_register_wakeup_handler(int wake_irq,
 static inline void acpi_unregister_wakeup_handler(
 	bool (*wakeup)(void *context), void *context) { }
 
+struct acpi_osc_context;
+static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
+{
+	return 0;
+}
+
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
drivers/acpi/bus.c +1 -1
index 07f604832fd6..4992e05cf429 100644
@@ -405,7 +405,7 @@ static void acpi_bus_osc_negotiate_usb_control(void)
 	}
 
 	osc_sb_native_usb4_control =
-		control & ((u32 *)context.ret.pointer)[OSC_CONTROL_DWORD];
+		control &  acpi_osc_ctx_get_pci_control(&context);
 
 	acpi_bus_decode_usb_osc("USB4 _OSC: OS supports", control);
 	acpi_bus_decode_usb_osc("USB4 _OSC: OS controls",
drivers/acpi/pci_root.c +1 -1
index b76db99cced3..40a74ff3fa02 100644
@@ -185,7 +185,7 @@ static acpi_status acpi_pci_run_osc(acpi_handle handle,
 
 	status = acpi_run_osc(handle, &context);
 	if (ACPI_SUCCESS(status)) {
-		*retval = *((u32 *)(context.ret.pointer + 8));
+		*retval = acpi_osc_ctx_get_pci_control(&context);
 		kfree(context.ret.pointer);
 	}
 	return status;
Signature · 1 line
2.35.1
#2 lore raw

PATCH v6 2/3 PCI/ACPI: Prefer CXL _OSC instead of PCIe _OSC for CXL host bridges

In reply to Vishal Verma

From: Dan Williams <[email protected]>

OB In preparation for negotiating OS control of CXL _OSC features, do the minimal enabling to use CXL _OSC to handle the base PCIe feature negotiation. Recall that CXL _OSC is a super-set of PCIe _OSC and the CXL 2.0 specification mandates: "If a CXL Host Bridge device exposes CXL _OSC, CXL aware OSPM shall evaluate CXL _OSC and not evaluate PCIe _OSC."

Rather than pass a boolean flag alongside @root to all the helper functions that need to consider PCIe specifics, add is_pcie() and is_cxl() helper functions to check the flavor of @root. This also allows for dynamic fallback to PCIe _OSC in cases where an attempt to use CXL _OXC fails. This can happen on CXL 1.1 platforms that publish ACPI0016 devices to indicate CXL host bridges, but do not publish the optional CXL _OSC method. CXL _OSC is mandatory for CXL 2.0 hosts.

---
 include/linux/acpi.h    |  4 +++
 include/acpi/acpi_bus.h |  6 ++++
 drivers/acpi/pci_root.c | 69 ++++++++++++++++++++++++++++++++---------
 3 files changed, 64 insertions(+), 15 deletions(-)
include/linux/acpi.h +4 -0
index ff4d1fdd9009..fc40da914315 100644
@@ -550,6 +550,10 @@ struct acpi_osc_context {
 
 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 
+/* Number of _OSC capability DWORDS depends on bridge type */
+#define OSC_PCI_CAPABILITY_DWORDS		3
+#define OSC_CXL_CAPABILITY_DWORDS		5
+
 /* Indexes into _OSC Capabilities Buffer (DWORDs 2 & 3 are device-specific) */
 #define OSC_QUERY_DWORD				0	/* DWORD 1 */
 #define OSC_SUPPORT_DWORD			1	/* DWORD 2 */
include/acpi/acpi_bus.h +6 -0
index ca88c4706f2b..9413d2389711 100644
@@ -581,10 +581,16 @@ int unregister_acpi_bus_type(struct acpi_bus_type *);
 int acpi_bind_one(struct device *dev, struct acpi_device *adev);
 int acpi_unbind_one(struct device *dev);
 
+enum acpi_bridge_type {
+	ACPI_BRIDGE_TYPE_PCIE = 1,
+	ACPI_BRIDGE_TYPE_CXL,
+};
+
 struct acpi_pci_root {
 	struct acpi_device * device;
 	struct pci_bus *bus;
 	u16 segment;
+	int bridge_type;
 	struct resource secondary;	/* downstream bus range */
 
 	u32 osc_support_set;	/* _OSC state of support bits */
drivers/acpi/pci_root.c +54 -15

135 lines not on this page · raw message

Signature · 1 line
2.35.1
#3 lore raw

PATCH v6 3/3 PCI/ACPI: negotiate CXL _OSC

In reply to Vishal Verma

Add full support for negotiating _OSC as defined in the CXL 2.0 spec, as applicable to CXL-enabled platforms. Advertise support for the CXL features we support - 'CXL 2.0 port/device register access', 'Protocol Error Reporting', and 'CXL Native Hot Plug'. Request control for 'CXL Memory Error Reporting'. The requests are dependent on CONFIG_* based prerequisites, and prior PCI enabling, similar to how the standard PCI _OSC bits are determined.

The CXL specification does not define any additional constraints on the hotplug flow beyond PCIe native hotplug, so a kernel that supports native PCIe hotplug, supports CXL hotplug. For error handling protocol and link errors just use PCIe AER. There is nascent support for amending AER events with CXL specific status [1], but there's otherwise no additional OS responsibility for CXL errors beyond PCIe AER. CXL Memory Errors behave the same as typical memory errors so CONFIG_MEMORY_FAILURE is sufficient to indicate support to platform firmware.

[1]: https://lore.kernel.org/linux-cxl/164740402242.3912056.8303625392871313860.stgit@dwillia2-desk3.amr.corp.intel.com/

---
 include/linux/acpi.h    |  25 +++++-
 include/acpi/acpi_bus.h |   6 +-
 drivers/acpi/pci_root.c | 179 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 188 insertions(+), 22 deletions(-)
include/linux/acpi.h +24 -1
index fc40da914315..ade1bf0c2f00 100644
@@ -554,10 +554,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 #define OSC_PCI_CAPABILITY_DWORDS		3
 #define OSC_CXL_CAPABILITY_DWORDS		5
 
-/* Indexes into _OSC Capabilities Buffer (DWORDs 2 & 3 are device-specific) */
+/* Indexes into _OSC Capabilities Buffer (DWORDs 2 to 5 are device-specific) */
 #define OSC_QUERY_DWORD				0	/* DWORD 1 */
 #define OSC_SUPPORT_DWORD			1	/* DWORD 2 */
 #define OSC_CONTROL_DWORD			2	/* DWORD 3 */
+#define OSC_EXT_SUPPORT_DWORD			3	/* DWORD 4 */
+#define OSC_EXT_CONTROL_DWORD			4	/* DWORD 5 */
 
 /* _OSC Capabilities DWORD 1: Query/Control and Error Returns (generic) */
 #define OSC_QUERY_ENABLE			0x00000001  /* input */
@@ -611,6 +613,15 @@ extern u32 osc_sb_native_usb4_control;
 #define OSC_PCI_EXPRESS_LTR_CONTROL		0x00000020
 #define OSC_PCI_EXPRESS_DPC_CONTROL		0x00000080
 
+/* CXL _OSC: Capabilities DWORD 4: Support Field */
+#define OSC_CXL_1_1_PORT_REG_ACCESS_SUPPORT	0x00000001
+#define OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT	0x00000002
+#define OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT	0x00000004
+#define OSC_CXL_NATIVE_HP_SUPPORT		0x00000008
+
+/* CXL _OSC: Capabilities DWORD 5: Control Field */
+#define OSC_CXL_ERROR_REPORTING_CONTROL		0x00000001
+
 static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
 {
 	u32 *ret = context->ret.pointer;
@@ -618,6 +629,13 @@ static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
 	return ret[OSC_CONTROL_DWORD];
 }
 
+static inline u32 acpi_osc_ctx_get_cxl_control(struct acpi_osc_context *context)
+{
+	u32 *ret = context->ret.pointer;
+
+	return ret[OSC_EXT_CONTROL_DWORD];
+}
+
 #define ACPI_GSB_ACCESS_ATTRIB_QUICK		0x00000002
 #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV         0x00000004
 #define ACPI_GSB_ACCESS_ATTRIB_BYTE		0x00000006
@@ -1020,6 +1038,11 @@ static inline u32 acpi_osc_ctx_get_pci_control(struct acpi_osc_context *context)
 	return 0;
 }
 
+static inline u32 acpi_osc_ctx_get_cxl_control(struct acpi_osc_context *context)
+{
+	return 0;
+}
+
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
include/acpi/acpi_bus.h +4 -2
index 9413d2389711..f1d053a9cfd4 100644
@@ -593,8 +593,10 @@ struct acpi_pci_root {
 	int bridge_type;
 	struct resource secondary;	/* downstream bus range */
 
-	u32 osc_support_set;	/* _OSC state of support bits */
-	u32 osc_control_set;	/* _OSC state of control bits */
+	u32 osc_support_set;		/* _OSC state of support bits */
+	u32 osc_control_set;		/* _OSC state of control bits */
+	u32 osc_ext_support_set;	/* _OSC state of extended support bits */
+	u32 osc_ext_control_set;	/* _OSC state of extended control bits */
 	phys_addr_t mcfg_addr;
 };
 
drivers/acpi/pci_root.c +160 -19

291 lines not on this page · raw message

Signature · 1 line
2.35.1
#4 lore raw
In reply to Vishal Verma
Quoted 3 lines · Vishal Verma

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Rafael, or Bjorn,

Dan has offered to take this through cxl.git. Any objections to that - would you prefer it to go through either the PCI or ACPI trees instead?

Quoted 37 lines

Add support for using the CXL definition of _OSC where applicable, and negotiating CXL specific support and control bits.

Patch 1 is a preliminary cleanup that replaces open-coded pointer arithmetic to retrieve the Control DWORD with an inline helper.

Patch 2 adds the new CXL _OSC UUID, and uses it instead of the PCI UUID when a root port is CXL enabled. It provides a fallback method for CXL-1.1 platforms that may not implement the CXL-2.0 _OSC.

Patch 3 performs negotiation for the CXL specific _OSC support and control bits.

I've tested these against a custom qemu[2], which adds the CXL _OSC (in addition to other CXL support). Specifically, _OSC support is added here[3].

[1]: https://lore.kernel.org/linux-cxl/[email protected]
[2]: https://gitlab.com/jic23/qemu/-/tree/cxl-v8-draft
[3]: https://gitlab.com/jic23/qemu/-/commit/1d67df6b6e3716c27462873f3451956f5c0673a3

Dan Williams (1):
  PCI/ACPI: Prefer CXL _OSC instead of PCIe _OSC for CXL host bridges

Vishal Verma (2):
  PCI/ACPI: add a helper for retrieving _OSC Control DWORDs PCI/ACPI: negotiate CXL _OSC

 include/linux/acpi.h    |  42 ++++++- include/acpi/acpi_bus.h |  12 +-
 drivers/acpi/bus.c      |   2 +-
 drivers/acpi/pci_root.c | 240 +++++++++++++++++++++++++++++++++++-----

 4 files changed, 262 insertions(+), 34 deletions(-)

base-commit: 05e815539f3f161585c13a9ab023341bade2c52f

#5 lore raw
Quoted 8 lines · Vishal L
Quoted 3 lines · Vishal Verma

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Rafael, or Bjorn,

Dan has offered to take this through cxl.git. Any objections to that - would you prefer it to go through either the PCI or ACPI trees instead?

This would be fine with me, but I can take the series too.

Quoted 36 lines
Quoted 36 lines

Add support for using the CXL definition of _OSC where applicable, and negotiating CXL specific support and control bits.

Patch 1 is a preliminary cleanup that replaces open-coded pointer arithmetic to retrieve the Control DWORD with an inline helper.

Patch 2 adds the new CXL _OSC UUID, and uses it instead of the PCI UUID when a root port is CXL enabled. It provides a fallback method for CXL-1.1 platforms that may not implement the CXL-2.0 _OSC.

Patch 3 performs negotiation for the CXL specific _OSC support and control bits.

I've tested these against a custom qemu[2], which adds the CXL _OSC (in addition to other CXL support). Specifically, _OSC support is added here[3].

[1]: https://lore.kernel.org/linux-cxl/[email protected]
[2]: https://gitlab.com/jic23/qemu/-/tree/cxl-v8-draft
[3]: https://gitlab.com/jic23/qemu/-/commit/1d67df6b6e3716c27462873f3451956f5c0673a3

Dan Williams (1):
  PCI/ACPI: Prefer CXL _OSC instead of PCIe _OSC for CXL host bridges

Vishal Verma (2):
  PCI/ACPI: add a helper for retrieving _OSC Control DWORDs PCI/ACPI: negotiate CXL _OSC

  include/linux/acpi.h    |  42 ++++++-
  include/acpi/acpi_bus.h |  12 +-
  drivers/acpi/bus.c      |   2 +-
  drivers/acpi/pci_root.c | 240 +++++++++++++++++++++++++++++++++++-----
  4 files changed, 262 insertions(+), 34 deletions(-)

base-commit: 05e815539f3f161585c13a9ab023341bade2c52f

#6 lore raw
In reply to Verma, Vishal L
Quoted 9 lines · Vishal L
Quoted 3 lines · Vishal Verma

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Rafael, or Bjorn,

Dan has offered to take this through cxl.git. Any objections to that - would you prefer it to go through either the PCI or ACPI trees instead?

OK by me if Dan or Rafael takes it.

#7 lore raw
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Vishal L
Quoted 3 lines · Vishal Verma

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Quoted 6 lines
Quoted 4 lines

Rafael, or Bjorn,

Dan has offered to take this through cxl.git. Any objections to that - would you prefer it to go through either the PCI or ACPI trees instead?

OK by me if Dan or Rafael takes it.

Thanks Bjorn, and Rafael. It simplifies a few things if it is kept with the other CXL changes for this merge cycle, so I'll take it through cxl.git.

#8 lore raw
In reply to Bjorn Helgaas
Quoted 10 lines · Bjorn Helgaas
Quoted 8 lines · Vishal L
Quoted 3 lines · Vishal Verma

Changes since v5[1]:
- Collect an reviewed-by tags from Rafael, Adam, and David
- Fix a couple of missed s/CXL/extended/ in acpi_bus.h (Rafael)

Rafael, or Bjorn,

Dan has offered to take this through cxl.git. Any objections to that - would you prefer it to go through either the PCI or ACPI trees instead?

OK by me if Dan or Rafael takes it.

All right, so it depends on whether or not there's any pending material for the CXL tree that will depend on these patches.  If so, it likely is better to route them via CXL.