ACPI: Add support for PCC Operation Region
Subsystems (2)
cover ACPI: Add support for PCC Operation Region
Hi,
This series adds support for ACPI PCC OpRegion added in ACPI 6.3 I understand that the ACPICA changes need to go via different route, but I am posting it together to give complete narative/picture for the review/discussion.
Regards,
Sudeep
Sudeep Holla (3):
ACPICA: Fix wrong interpretation of PCC address
ACPICA: Add support for PCC Opregion special context data
ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype
drivers/acpi/Kconfig | 5 ++ drivers/acpi/Makefile | 1 + drivers/acpi/acpica/evregion.c | 11 ++++ drivers/acpi/acpica/exfield.c | 7 +-- drivers/acpi/bus.c | 1 + drivers/acpi/pcc_opregion.c | 111 +++++++++++++++++++++++++++++++++ include/acpi/actypes.h | 8 +++ include/linux/acpi.h | 6 ++ 8 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 drivers/acpi/pcc_opregion.c
--
2.25.1
PATCH 1/3 ACPICA: Fix wrong interpretation of PCC address
With the PCC Opregion in the firmware and we are hitting below kernel crash:
-->8
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 Workqueue: pm pm_runtime_work pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __memcpy+0x54/0x260 lr : acpi_ex_write_data_to_field+0xb8/0x194 Call trace: __memcpy+0x54/0x260 acpi_ex_store_object_to_node+0xa4/0x1d4 acpi_ex_store+0x44/0x164 acpi_ex_opcode_1A_1T_1R+0x25c/0x508 acpi_ds_exec_end_op+0x1b4/0x44c acpi_ps_parse_loop+0x3a8/0x614 acpi_ps_parse_aml+0x90/0x2f4 acpi_ps_execute_method+0x11c/0x19c acpi_ns_evaluate+0x1ec/0x2b0 acpi_evaluate_object+0x170/0x2b0 acpi_device_set_power+0x118/0x310 acpi_dev_suspend+0xd4/0x180 acpi_subsys_runtime_suspend+0x28/0x38 __rpm_callback+0x74/0x328 rpm_suspend+0x2d8/0x624 pm_runtime_work+0xa4/0xb8 process_one_work+0x194/0x25c worker_thread+0x260/0x49c kthread+0x14c/0x30c ret_from_fork+0x10/0x20 Code: f9000006 f81f80a7 d65f03c0 361000c2 (b9400026) ---[ end trace 24d8a032fa77b68a ]---
The reason for the crash is that the PCC channel index passed via region.address in acpi_ex_store_object_to_node is interpreted as the channel subtype incorrectly.
Assuming the PCC OpRegion support is not used by any other type, let us remove the subtype check as the AML has no access to the subtype information. Once we remove it, the kernel crash disappears and correctly complains about missing PCC Opregion handler.
ACPI Error: No handler for Region [PFRM] ((____ptrval____)) [PCC] (20210730/evregion-130) ACPI Error: Region PCC (ID=10) has no handler (20210730/exfldio-261)
ACPI Error: Aborting method \_SB.ETH0._PS3 due to previous error (AE_NOT_EXIST) (20210730/psparse-531)
--- drivers/acpi/acpica/exfield.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/acpica/exfield.c +1 -6
@@ -330,12 +330,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc, obj_desc->field.base_byte_offset, source_desc->buffer.pointer, data_length); -if ((obj_desc->field.region_obj->region.address == -PCC_MASTER_SUBSPACE - &&MASTER_SUBSPACE_COMMAND (obj_desc->field. - base_byte_offset)) - ||GENERIC_SUBSPACE_COMMAND (obj_desc->field. - base_byte_offset)) { +if (MASTER_SUBSPACE_COMMAND (obj_desc->field.base_byte_offset)) {/* Perform the write */
Signature · 1 line
2.25.1
PATCH 2/3 ACPICA: Add support for PCC Opregion special context data
In reply to Sudeep HollaPCC Opregion added in ACPIC 6.3 requires special context data similar to GPIO and Generic Serial Bus as it needs to know the internal PCC buffer and its length as well as the PCC channel index when the opregion handler is being executed by the OSPM.
Lets add support for the special context data needed by PCC Opregion.
--- drivers/acpi/acpica/evregion.c | 11 +++++++++++ include/acpi/actypes.h | 8 ++++++++ 2 files changed, 19 insertions(+)
drivers/acpi/acpica/evregion.c +11 -0
@@ -162,6 +162,17 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,return_ACPI_STATUS (AE_NOT_EXIST ); } +if (region_obj->region.space_id == +ACPI_ADR_SPACE_PLATFORM_COMM ) { +struct acpi_pcc_info *ctx = + handler_desc->address_space.context; + + ctx->internal_buffer = + field_obj->field.internal_pcc_buffer; + ctx->length = region_obj->region.length; + ctx->subspace_id = region_obj->region.address; + } +/* * We must exit the interpreter because the region setup will * potentially execute control methods (for example, the _REG method
include/acpi/actypes.h +8 -0
@@ -1098,6 +1098,14 @@ struct acpi_connection_info {u8 access_length; }; +/* Special Context data for PCC Opregion (ACPI 6.3) */ + +struct acpi_pcc_info { +u8 subspace_id; +u16 length; +u8 *internal_buffer; +}; +typedef acpi_status (*acpi_adr_space_setup) (acpi_handle region_handle, u32 function,
Signature · 1 line
2.25.1
PATCH 3/3 ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype
In reply to Sudeep HollaPCC OpRegion provides a mechanism to communicate with the platform directly from the AML. PCCT provides the list of PCC channel available in the platform, a subset or all of them can be used in PCC Opregion.
This patch registers the PCC OpRegion handler before ACPI tables are loaded. This relies on the special context data passed to identify and setup the PCC channel before the OpRegion handler is executed for the first time.
Typical PCC Opregion declaration looks like this:
OperationRegion (PFRM, PCC, 2, 0x74)
Field (PFRM, ByteAcc, NoLock, Preserve)
{
SIGN, 32,
FLGS, 32,
LEN, 32,
CMD, 32,
DATA, 800
}It contains 4 named double words followed by 100 bytes of buffer names DATA.
ASL can fill out the buffer something like:
/* Create global or local buffer */
Name (BUFF, Buffer (0x0C){})
/* Create double word fields over the buffer */
CreateDWordField (BUFF, 0x0, WD0)
CreateDWordField (BUFF, 0x04, WD1)
CreateDWordField (BUFF, 0x08, WD2)
/* Fill the named fields */
WD0 = 0x50434300
SIGN = BUFF
WD0 = 1
FLGS = BUFF
WD0 = 0x10
LEN = BUFF
/* Fill the payload in the DATA buffer */
WD0 = 0
WD1 = 0x08
WD2 = 0
DATA = BUFF
/* Write to CMD field to trigger handler */
WD0 = 0x4404
CMD = BUFFThis buffer is recieved by acpi_pcc_opregion_space_handler. This handler will fetch the commplete buffer via internal_pcc_buffer.
The setup handler will receive the special PCC context data which will contain the PCC channel index which used to setup the channel. The buffer pointer and length is saved in region context which is then used in the handler.
--- drivers/acpi/Kconfig | 5 ++ drivers/acpi/Makefile | 1 + drivers/acpi/bus.c | 1 + drivers/acpi/pcc_opregion.c | 111 ++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++ 5 files changed, 124 insertions(+) create mode 100644 drivers/acpi/pcc_opregion.c
drivers/acpi/Kconfig +5 -0
@@ -524,6 +524,11 @@ config ACPI_PPTT bool endif +config ACPI_PCC_OPREGION + bool "PCC Opregion" + depends on PCC + default y + source "drivers/acpi/pmic/Kconfig" config ACPI_VIOT
drivers/acpi/Makefile +1 -0
@@ -67,6 +67,7 @@ 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 +acpi-$(CONFIG_ACPI_PCC_OPREGION) += pcc_opregion.o # Address translation acpi-$(CONFIG_ACPI_ADXL) += acpi_adxl.o
drivers/acpi/bus.c +1 -0
@@ -1320,6 +1320,7 @@ static int __init acpi_init(void)pr_debug ("%s: kset create error\n" , __func__);init_prmt (); +init_pcc_opregion (); result =acpi_bus_init ();if (result) {kobject_put (acpi_kobj);
drivers/acpi/pcc_opregion.c new file +111 -0
111 lines not on this page · raw message
include/linux/acpi.h +6 -0
@@ -1384,6 +1384,12 @@ static inline int find_acpi_cpu_cache_topology(unsigned int cpu, int level) }#endif +#ifdef CONFIG_ACPI_PCC_OPREGION +void init_pcc_opregion (void ); +#else +static inline void init_pcc_opregion (void ) { } +#endif +#ifdef CONFIG_ACPI extern void acpi_device_notify (struct device *dev);extern void acpi_device_notify_remove (struct device *dev);
Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerHi Sudeep,
Quoted 8 lines · Sudeep Holla
Hi,
This series adds support for ACPI PCC OpRegion added in ACPI 6.3 I understand that the ACPICA changes need to go via different route, but I am posting it together to give complete narative/picture for the review/discussion.
Quoted 6 lines
Regards,
SudeepSudeep Holla (3):
ACPICA: Fix wrong interpretation of PCC address
ACPICA: Add support for PCC Opregion special context data
The above two need to be submitted to the upstream project via GitHub at https://github.com/acpica/acpica
The will be applicable to the Linux code base only after they have been accepted by the upstream.
Quoted 1 line
ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype
And this one will be applied when the above happens.
Thanks!
Hi Rafael,
Thanks for the response, sorry for the delay as I was away.
Quoted 14 lines · Rafael J. Wysocki
Hi Sudeep,
Quoted 11 lines · Sudeep Holla
Hi,
This series adds support for ACPI PCC OpRegion added in ACPI 6.3 I understand that the ACPICA changes need to go via different route, but I am posting it together to give complete narative/picture for the review/discussion.
Regards,
Sudeep
Quoted 7 lines
Quoted 3 lines
Sudeep Holla (3):
ACPICA: Fix wrong interpretation of PCC address
ACPICA: Add support for PCC Opregion special context dataThe above two need to be submitted to the upstream project via GitHub at https://github.com/acpica/acpica
Thanks for the info, I had a rough idea but posted these for reference here anyways.
Quoted 3 lines
The will be applicable to the Linux code base only after they have been accepted by the upstream.
Sure, I have now sent the pull request(https://github.com/acpica/acpica/pull/735)
Quoted 4 lines
Quoted 1 line
ACPI: PCC: Implement OperationRegion handler for the PCC Type 3 subtype
And this one will be applied when the above happens.
Make sense.
Signature · 2 lines
Regards, Sudeep