Skip to contentSkip to conversation

Update PRM patches to fix some issues...

PATCH In review Erik Kaneda 2 participants 5 messages Jun 10, 2021

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

v2 cover Update PRM patches to fix some issues...

Hi Rafael, I found out that there were several misspelled struct fields that resulted from merging my PRM code with ACPICA material that caused build errors. This patch set resolves build issues by

1) fixing the spelling errors
2) defining the struct acpi_prmt_module_header that got left off. This struct is used by acpi_parse_table_entries and is not used by ACPICA so it was left out accidentally.

This patch set also fixes a crash that was caused when I split up acpi_table_prmt and acpi_table_prmt_header. These structs used to be defined in a single struct acpi_table_prmt but it was split up in order to facilitate iASL compiler implementation. The size of the 36-byte ACPI table header + the size of any additional fields are needed as parameter to the acpi_parse_table_entries function. When I split up acpi_table_prmt into two different structs, I did not adjust the parameter to acpi_parse_table_entries and this ended up breaking the PRMT parsing. I've fixed this by changing the parameter to acpi_parse_table_entries to account for this additional struct.

Sorry for the confusion! This patchset should clear things up and runs the PRM handler in the edk2 PRM samples without any issues.

I've based this on rc-5.

Thanks and sorry for the noise!
Erik

Erik Kaneda (3):
ACPICA: Add PRMT module header to facilitate parsing
PRM: implement OperationRegion handler for the PlatformRtMechanism
subtype
ACPI: Add \_SB._OSC bit for PRM

 drivers/acpi/Kconfig  |   5 +
 drivers/acpi/Makefile |   1 +
 drivers/acpi/bus.c    |   3 +
 drivers/acpi/prmt.c   | 303 ++++++++++++++++++++++++++++++++++++++++++
 drivers/acpi/tables.c |   9 ++
 include/acpi/actbl2.h |   5 +
 include/linux/acpi.h  |   2 +
 include/linux/prmt.h  |   7 +
 8 files changed, 335 insertions(+)
 create mode 100644 drivers/acpi/prmt.c
 create mode 100644 include/linux/prmt.h
Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/3 ACPICA: Add PRMT module header to facilitate parsing

ACPICA commit bd46cb07e614fd85ea69e54c1f6f0ae0a5fb20ab

This structure is used in to parse PRMT in other Operating Systems that relies on using subtable headers in order to parse ACPI tables. Although the PRMT doesn't have "subtables" it has a list of module information structures that act as subtables.

---
 include/acpi/actbl2.h | 5 +++++
 1 file changed, 5 insertions(+)
include/acpi/actbl2.h +5 -0
index 05b086d4d94a..2069ac38a4e2 100644
@@ -1728,6 +1728,11 @@ struct acpi_table_prmt_header {
 	u32 module_info_count;
 };
 
+struct acpi_prmt_module_header {
+	u16 revision;
+	u16 length;
+};
+
 struct acpi_prmt_module_info {
 	u16 revision;
 	u16 length;
Signature · 1 line
2.29.2
#2 lore raw

PATCH v2 2/3 PRM: implement OperationRegion handler for the PlatformRtMechanism subtype

In reply to Erik Kaneda

Platform Runtime Mechanism (PRM) is a firmware interface that exposes a set of binary executables that can either be called from the AML interpreter or device drivers by bypassing the AML interpreter. This change implements the AML interpreter path.

According to the specification [1], PRM services are listed in an ACPI table called the PRMT. This patch parses module and handler information listed in the PRMT and registers the PlatformRtMechanism OpRegion handler before ACPI tables are loaded.

Each service is defined by a 16-byte GUID and called from writing a 26-byte ASL buffer containing the identifier to a FieldUnit object defined inside a PlatformRtMechanism OperationRegion.

OperationRegion (PRMR, PlatformRtMechanism, 0, 26)
Field (PRMR, BufferAcc, NoLock, Preserve)
{
PRMF, 208 // Write to this field to invoke the OperationRegion Handler
}

The 26-byte ASL buffer is defined as the following:

Byte Offset Byte Length Description
=============================================================

     0             1         PRM OperationRegion handler status
     1             8         PRM service status
     9             1         PRM command
    10            16         PRM handler GUID

The ASL caller fills out a 26-byte buffer containing the PRM command and the PRM handler GUID like so:

    /* Local0 is the PRM data buffer */
    Local0 = buffer (26){}

    /* Create byte fields over the buffer */
    CreateByteField (Local0, 0x9, CMD)
    CreateField (Local0, 0x50, 0x80, GUID)

    /* Fill in the command and data fields of the data buffer */
    CMD = 0 // run command
    GUID = ToUUID("xxxx-xx-xxx-xxxx")

    /*
     * Invoke PRM service with an ID that matches GUID and save the
     * result.
     */
    Local0 = (\_SB.PRMT.PRMF = Local0)

Byte offset 0 - 8 are written by the handler as a status passed back to AML and used by ASL like so:

    /* Create byte fields over the buffer */
    CreateByteField (Local0, 0x0, PSTA)
    CreateQWordField (Local0, 0x1, USTA)

In this ASL code, PSTA contains a status from the OperationRegion and USTA contains a status from the PRM service.

The 26-byte buffer is recieved by acpi_platformrt_space_handler. This handler will look at the command value and the handler guid and take the approperiate actions.

Command value Action
=====================================================================
0 Run the PRM service indicated by the PRM handler
GUID (bytes 10-26)

1 Prevent PRM runtime updates from happening to the
service's parent module

2 Allow PRM updates from happening to the service's parent module

Note: PRM service updates will be implemented in future patches. This patch enables command value 0.

[1] https://uefi.org/sites/default/files/resources/Platform%20Runtime%20Mechanism%20-%20with%20legal%20notice.pdf

Cc Dan Williams <[email protected]>
Cc Ashok Raj <[email protected]>
Cc Rafael Wysocki <[email protected]>
---
 drivers/acpi/Kconfig  |   5 +
 drivers/acpi/Makefile |   1 +
 drivers/acpi/bus.c    |   2 +
 drivers/acpi/prmt.c   | 303 ++++++++++++++++++++++++++++++++++++++++++
 drivers/acpi/tables.c |   9 ++
 include/linux/acpi.h  |   1 +
 include/linux/prmt.h  |   7 +
 7 files changed, 328 insertions(+)
 create mode 100644 drivers/acpi/prmt.c
 create mode 100644 include/linux/prmt.h
drivers/acpi/Kconfig +5 -0
index eedec61e3476..3972de7b7565 100644
@@ -543,3 +543,8 @@ config X86_PM_TIMER
 
 	  You should nearly always say Y here because many modern
 	  systems require this timer.
+
+config ACPI_PRMT
+	bool "Platform Runtime Mechanism Support"
+	depends on EFI && X86_64
+	default y
drivers/acpi/Makefile +1 -0
index 700b41adf2db..efb0d1f64019 100644
@@ -61,6 +61,7 @@ acpi-$(CONFIG_ACPI_FPDT)	+= acpi_fpdt.o
 acpi-$(CONFIG_ACPI_LPIT)	+= acpi_lpit.o
 acpi-$(CONFIG_ACPI_GENERIC_GSI) += irq.o
 acpi-$(CONFIG_ACPI_WATCHDOG)	+= acpi_watchdog.o
+acpi-$(CONFIG_ACPI_PRMT)	+= prmt.o
 
 # Address translation
 acpi-$(CONFIG_ACPI_ADXL)	+= acpi_adxl.o
drivers/acpi/bus.c +2 -0
index be7da23fad76..3484497923d5 100644
@@ -30,6 +30,7 @@
 #include <linux/pci.h>
 #include <acpi/apei.h>
 #include <linux/suspend.h>
+#include <linux/prmt.h>
 
 #include "internal.h"
 
@@ -1330,6 +1331,7 @@ static int __init acpi_init(void)
 		acpi_kobj = NULL;
 	}
 
+	init_prmt();
 	result = acpi_bus_init();
 	if (result) {
 		disable_acpi();
drivers/acpi/prmt.c new file +303 -0

303 lines not on this page · raw message

drivers/acpi/tables.c +9 -0
index 9d581045acff..a37a1532a575 100644
@@ -39,6 +39,7 @@ static int acpi_apic_instance __initdata;
 enum acpi_subtable_type {
 	ACPI_SUBTABLE_COMMON,
 	ACPI_SUBTABLE_HMAT,
+	ACPI_SUBTABLE_PRMT,
 };
 
 struct acpi_subtable_entry {
@@ -222,6 +223,8 @@ acpi_get_entry_type(struct acpi_subtable_entry *entry)
 		return entry->hdr->common.type;
 	case ACPI_SUBTABLE_HMAT:
 		return entry->hdr->hmat.type;
+	case ACPI_SUBTABLE_PRMT:
+		return 0;
 	}
 	return 0;
 }
@@ -234,6 +237,8 @@ acpi_get_entry_length(struct acpi_subtable_entry *entry)
 		return entry->hdr->common.length;
 	case ACPI_SUBTABLE_HMAT:
 		return entry->hdr->hmat.length;
+	case ACPI_SUBTABLE_PRMT:
+		return entry->hdr->prmt.length;
 	}
 	return 0;
 }
@@ -246,6 +251,8 @@ acpi_get_subtable_header_length(struct acpi_subtable_entry *entry)
 		return sizeof(entry->hdr->common);
 	case ACPI_SUBTABLE_HMAT:
 		return sizeof(entry->hdr->hmat);
+	case ACPI_SUBTABLE_PRMT:
+		return sizeof(entry->hdr->prmt);
 	}
 	return 0;
 }
@@ -255,6 +262,8 @@ acpi_get_subtable_type(char *id)
 {
 	if (strncmp(id, ACPI_SIG_HMAT, 4) == 0)
 		return ACPI_SUBTABLE_HMAT;
+	if (strncmp(id, ACPI_SIG_PRMT, 4) == 0)
+		return ACPI_SUBTABLE_PRMT;
 	return ACPI_SUBTABLE_COMMON;
 }
 
include/linux/acpi.h +1 -0
index c60745f657e9..4c07ac22c6ba 100644
@@ -132,6 +132,7 @@ enum acpi_address_range_id {
 union acpi_subtable_headers {
 	struct acpi_subtable_header common;
 	struct acpi_hmat_structure hmat;
+	struct acpi_prmt_module_header prmt;
 };
 
 typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table);
include/linux/prmt.h new file +7 -0
new file mode 100644
index 000000000000..24da8364b919
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifdef CONFIG_ACPI_PRMT
+void init_prmt(void);
+#else
+static inline void init_prmt(void) { }
+#endif
Signature · 1 line
2.29.2
#3 lore raw

PATCH v2 3/3 ACPI: Add \_SB._OSC bit for PRM

In reply to Erik Kaneda
---
 drivers/acpi/bus.c   | 1 +
 include/linux/acpi.h | 1 +
 2 files changed, 2 insertions(+)
drivers/acpi/bus.c +1 -0
index 3484497923d5..e8119a9eca28 100644
@@ -305,6 +305,7 @@ static void acpi_bus_osc_negotiate_platform_control(void)
 
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT;
+	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PRM_SUPPORT;
 
 #ifdef CONFIG_ARM64
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_GENERIC_INITIATOR_SUPPORT;
include/linux/acpi.h +1 -0
index 4c07ac22c6ba..a618ba698a5c 100644
@@ -551,6 +551,7 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 #define OSC_SB_OSLPI_SUPPORT			0x00000100
 #define OSC_SB_CPC_DIVERSE_HIGH_SUPPORT		0x00001000
 #define OSC_SB_GENERIC_INITIATOR_SUPPORT	0x00002000
+#define OSC_SB_PRM_SUPPORT			0x00020000
 #define OSC_SB_NATIVE_USB4_SUPPORT		0x00040000
 
 extern bool osc_sb_apei_support_acked;
Signature · 1 line
2.29.2
#4 lore raw
In reply to Erik Kaneda
Quoted 21 lines · Erik Kaneda

Hi Rafael, I found out that there were several misspelled struct fields that resulted from merging my PRM code with ACPICA material that caused build errors. This patch set resolves build issues by

1) fixing the spelling errors
2) defining the struct acpi_prmt_module_header that got left off. This struct is used by acpi_parse_table_entries and is not used by ACPICA so it was left out accidentally.

This patch set also fixes a crash that was caused when I split up acpi_table_prmt and acpi_table_prmt_header. These structs used to be defined in a single struct acpi_table_prmt but it was split up in order to facilitate iASL compiler implementation. The size of the 36-byte ACPI table header + the size of any additional fields are needed as parameter to the acpi_parse_table_entries function. When I split up acpi_table_prmt into two different structs, I did not adjust the parameter to acpi_parse_table_entries and this ended up breaking the PRMT parsing. I've fixed this by changing the parameter to acpi_parse_table_entries to account for this additional struct.

Quoted 4 lines

Sorry for the confusion! This patchset should clear things up and runs the PRM handler in the edk2 PRM samples without any issues.

I've based this on rc-5.

Applied (instead of the previous version), thanks!