Skip to contentSkip to conversation

acpi: add support for CXL _OSC

PATCH Superseded Vishal Verma 2 participants 9 messages Mar 30, 2022

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover acpi: add support for CXL _OSC

Changes since v2[1]:
- Add a prep patch replacing pointer arithmetic with a helper (David)
- Make is_pcie/is_cxl helpers inline (David)
- Tidy up the if/else in the above helpers (David)

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: Use CXL _OSC instead of PCIe _OSC

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

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

base-commit: 05e815539f3f161585c13a9ab023341bade2c52f

Signature · 1 line
2.35.1
#1 lore raw

PATCH v3 1/3 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.

---
 include/linux/acpi.h    | 12 ++++++++++++
 drivers/acpi/bus.c      |  2 +-
 drivers/acpi/pci_root.c |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)
include/linux/acpi.h +12 -0
index 6274758648e3..5c5bac255d35 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,11 @@ static inline int acpi_register_wakeup_handler(int wake_irq,
 static inline void acpi_unregister_wakeup_handler(
 	bool (*wakeup)(void *context), void *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

Re: [PATCH v3 1/3] acpi: add a helper for retrieving _OSC Control DWORDs

Look at previous subject lines and copy the style instead of making up something new.

Quoted 6 lines · Vishal Verma

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.

Bjorn

#3 lore raw

Re: [PATCH v3 1/3] acpi: add a helper for retrieving _OSC Control DWORDs

Quoted 2 lines · Bjorn Helgaas

Look at previous subject lines and copy the style instead of making up something new.

Yep will fix.

Quoted 10 lines · Vishal Verma
Quoted 6 lines

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.

Bjorn

#4 lore raw

PATCH v3 2/3 PCI/ACPI: Use CXL _OSC instead of PCIe _OSC

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 | 70 ++++++++++++++++++++++++++++++++---------
 3 files changed, 65 insertions(+), 15 deletions(-)
include/linux/acpi.h +4 -0
index 5c5bac255d35..bc1f4314d266 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 +55 -15

136 lines not on this page · raw message

Signature · 1 line
2.35.1
#5 lore raw

PATCH v3 3/3 acpi/pci_root: 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 'CL Native Hot Plug'. Request control for 'CXL Memory Error Reporting'. The requests are dependent on CONFIG_* based pre-requisites, 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/

Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Robert Moore <[email protected]>
Cc Dan Williams <[email protected]>
---
 include/linux/acpi.h    |  28 +++++++-
 include/acpi/acpi_bus.h |   6 +-
 drivers/acpi/pci_root.c | 145 ++++++++++++++++++++++++++++++++++------
 3 files changed, 157 insertions(+), 22 deletions(-)
include/linux/acpi.h +27 -1
index bc1f4314d266..6e4b90109da2 100644
@@ -554,10 +554,15 @@ 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 & 3 are device-specific, and 4 & 5 are specific to CXL platforms
+ */
 #define OSC_QUERY_DWORD				0	/* DWORD 1 */
 #define OSC_SUPPORT_DWORD			1	/* DWORD 2 */
 #define OSC_CONTROL_DWORD			2	/* DWORD 3 */
+#define OSC_CXL_SUPPORT_DWORD			3	/* DWORD 4 */
+#define OSC_CXL_CONTROL_DWORD			4	/* DWORD 5 */
 
 /* _OSC Capabilities DWORD 1: Query/Control and Error Returns (generic) */
 #define OSC_QUERY_ENABLE			0x00000001  /* input */
@@ -611,6 +616,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 +632,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_CXL_CONTROL_DWORD];
+}
+
 #define ACPI_GSB_ACCESS_ATTRIB_QUICK		0x00000002
 #define ACPI_GSB_ACCESS_ATTRIB_SEND_RCV         0x00000004
 #define ACPI_GSB_ACCESS_ATTRIB_BYTE		0x00000006
@@ -1019,6 +1040,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..0fdd913c1fd7 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 cxl_osc_support_set;	/* _OSC state of CXL support bits */
+	u32 cxl_osc_control_set;	/* _OSC state of CXL control bits */
 	phys_addr_t mcfg_addr;
 };
 
drivers/acpi/pci_root.c +126 -19

257 lines not on this page · raw message

Signature · 1 line
2.35.1
#6 lore raw

Re: [PATCH v3 3/3] acpi/pci_root: negotiate CXL _OSC

Don't just make up new prefixes for the subject line. Previous ones look like this:

PCI/ACPI: Fix acpi_pci_osc_control_set() kernel-doc comment
ACPI: Use acpi_fetch_acpi_dev() instead of acpi_bus_get_device() PCI/ACPI: Check for _OSC support in acpi_pci_osc_control_set() PCI/ACPI: Move _OSC query checks to separate function PCI/ACPI: Move supported and control calculations to separate functions PCI/ACPI: Remove OSC_PCI_SUPPORT_MASKS and OSC_PCI_CONTROL_MASKS
ACPI: pci_root: Unify the message printing
PCI/ACPI: Clarify message about _OSC failure
PCI/ACPI: Remove unnecessary osc_lock
PCI/ACPI: Make acpi_pci_osc_control_set() static
PCI/ACPI: Replace open coded variant of resource_union()

So I think "PCI/ACPI: " would be a good choice. Also capitalize the next word as all the above do.

Quoted 1 line · Vishal Verma

Add full support for negotiating _OSC as defined in the CXL 2.0 spec, as

Please include a section reference.

Quoted 3 lines

applicable to CXL-enabled platforms. Advertise support for the CXL features we support - 'CXL 2.0 port/device register access', 'Protocol Error Reporting', and 'CL Native Hot Plug'. Request control for 'CXL

"CL" looks like a typo for "CXL"?

Quoted 2 lines

Memory Error Reporting'. The requests are dependent on CONFIG_* based pre-requisites, and prior PCI enabling, similar to how the standard PCI

s/pre-requisites/prerequisites/

Quoted 12 lines

_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.

Quoted 7 lines

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

Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Robert Moore <[email protected]>
Cc Dan Williams <[email protected]>

What was reported by the robot? If it just complained about something in v1 or v2, I think there's no point in mentioning this here. It's the same as ordinary review comments (like these I'm composing), and they don't need to be acknowledged. I think "Reported-by" is great when giving credit for bug fixes, but that's not what's happening here.

Bjorn

#7 lore raw

Re: [PATCH v3 3/3] acpi/pci_root: negotiate CXL _OSC

Quoted 15 lines · Bjorn Helgaas

Don't just make up new prefixes for the subject line.  Previous ones look like this:

  PCI/ACPI: Fix acpi_pci_osc_control_set() kernel-doc comment
  ACPI: Use acpi_fetch_acpi_dev() instead of acpi_bus_get_device() PCI/ACPI: Check for _OSC support in acpi_pci_osc_control_set() PCI/ACPI: Move _OSC query checks to separate function PCI/ACPI: Move supported and control calculations to separate functions PCI/ACPI: Remove OSC_PCI_SUPPORT_MASKS and OSC_PCI_CONTROL_MASKS
  ACPI: pci_root: Unify the message printing
  PCI/ACPI: Clarify message about _OSC failure
  PCI/ACPI: Remove unnecessary osc_lock
  PCI/ACPI: Make acpi_pci_osc_control_set() static
  PCI/ACPI: Replace open coded variant of resource_union()

Quoted 2 lines

So I think "PCI/ACPI: " would be a good choice.  Also capitalize the next word as all the above do.

Yep will change to "PCI/ACPI:"

Quoted 5 lines · Vishal Verma
Quoted 1 line

Add full support for negotiating _OSC as defined in the CXL 2.0 spec, as

Please include a section reference.

Ok

Quoted 6 lines
Quoted 4 lines

applicable to CXL-enabled platforms. Advertise support for the CXL features we support - 'CXL 2.0 port/device register access', 'Protocol Error Reporting', and 'CL Native Hot Plug'. Request control for 'CXL

"CL" looks like a typo for "CXL"?

Yep, fixed for v4.

Quoted 5 lines
Quoted 3 lines

Memory Error Reporting'. The requests are dependent on CONFIG_* based pre-requisites, and prior PCI enabling, similar to how the standard PCI

s/pre-requisites/prerequisites/

Ack.

Quoted 21 lines
Quoted 13 lines

_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.

Quoted 7 lines

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

Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Robert Moore <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 6 lines

What was reported by the robot?  If it just complained about something in v1 or v2, I think there's no point in mentioning this here.  It's the same as ordinary review comments (like these I'm composing), and they don't need to be acknowledged.  I think "Reported-by" is great when giving credit for bug fixes, but that's not what's happening here.

Correct it was a compile warning, and actually it wasn't on-list - 0day sent it privately, because it was on the RFC version. It makes sense to treat it as a normal review comment - I only added the tag because the 0day emails ask you to (I suppose they use the trailers for metrics on actionable feedback generated by the bot). I'm happy to drop it if that's preferred here.

Quoted 2 lines

Bjorn

#8 lore raw

Re: [PATCH v3 3/3] acpi/pci_root: negotiate CXL _OSC

Quoted 11 lines · Vishal L
Quoted 8 lines · Bjorn Helgaas
Quoted 1 line

What was reported by the robot?  If it just complained about something in v1 or v2, I think there's no point in mentioning this here.  It's the same as ordinary review comments (like these I'm composing), and they don't need to be acknowledged.  I think "Reported-by" is great when giving credit for bug fixes, but that's not what's happening here.

Quoted 6 lines

Correct it was a compile warning, and actually it wasn't on-list - 0day sent it privately, because it was on the RFC version. It makes sense to treat it as a normal review comment - I only added the tag because the 0day emails ask you to (I suppose they use the trailers for metrics on actionable feedback generated by the bot). I'm happy to drop it if that's preferred here.

Yeah, I know. I *love* the 0-day bot and the fact that it tests things before they're even merged, but I wish it would only ask you to add the tag if it's something that has already been merged, where the likely outcome is a tiny bug-fix patch where it's obvious what "Reported-by" refers to.

Bjorn