1 // SPDX-License-Identifier: GPL-2.0-only
3 * Author: Sudeep Holla <sudeep.holla@arm.com>
4 * Copyright 2021 Arm Limited
6 * The PCC Address Space also referred as PCC Operation Region pertains to the
7 * region of PCC subspace that succeeds the PCC signature. The PCC Operation
8 * Region works in conjunction with the PCC Table(Platform Communications
9 * Channel Table). PCC subspaces that are marked for use as PCC Operation
10 * Regions must not be used as PCC subspaces for the standard ACPI features
11 * such as CPPC, RASF, PDTT and MPST. These standard features must always use
12 * the PCC Table instead.
14 * This driver sets up the PCC Address Space and installs an handler to enable
15 * handling of PCC OpRegion in the firmware.
18 #include <linux/kernel.h>
19 #include <linux/acpi.h>
20 #include <linux/completion.h>
21 #include <linux/idr.h>
27 struct pcc_mbox_chan *pcc_chan;
28 void __iomem *pcc_comm_addr;
29 struct completion done;
30 struct mbox_client cl;
31 struct acpi_pcc_info ctx;
34 struct acpi_pcc_info pcc_ctx;
36 static void pcc_rx_callback(struct mbox_client *cl, void *m)
38 struct pcc_data *data = container_of(cl, struct pcc_data, cl);
40 complete(&data->done);
44 acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
45 void *handler_context, void **region_context)
47 struct pcc_data *data;
48 struct acpi_pcc_info *ctx = handler_context;
49 struct pcc_mbox_chan *pcc_chan;
51 data = kzalloc(sizeof(*data), GFP_KERNEL);
55 data->cl.rx_callback = pcc_rx_callback;
56 data->cl.knows_txdone = true;
57 data->ctx.length = ctx->length;
58 data->ctx.subspace_id = ctx->subspace_id;
59 data->ctx.internal_buffer = ctx->internal_buffer;
61 init_completion(&data->done);
62 data->pcc_chan = pcc_mbox_request_channel(&data->cl, ctx->subspace_id);
63 if (IS_ERR(data->pcc_chan)) {
64 pr_err("Failed to find PCC channel for subspace %d\n",
69 pcc_chan = data->pcc_chan;
70 data->pcc_comm_addr = acpi_os_ioremap(pcc_chan->shmem_base_addr,
71 pcc_chan->shmem_size);
72 if (!data->pcc_comm_addr) {
73 pr_err("Failed to ioremap PCC comm region mem for %d\n",
78 *region_context = data;
83 acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr,
84 u32 bits, acpi_integer *value,
85 void *handler_context, void *region_context)
88 struct pcc_data *data = region_context;
90 reinit_completion(&data->done);
92 /* Write to Shared Memory */
93 memcpy_toio(data->pcc_comm_addr, (void *)value, data->ctx.length);
95 ret = mbox_send_message(data->pcc_chan->mchan, NULL);
99 if (data->pcc_chan->mchan->mbox->txdone_irq)
100 wait_for_completion(&data->done);
102 mbox_client_txdone(data->pcc_chan->mchan, ret);
104 memcpy_fromio(value, data->pcc_comm_addr, data->ctx.length);
109 void __init acpi_init_pcc(void)
113 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
114 ACPI_ADR_SPACE_PLATFORM_COMM,
115 &acpi_pcc_address_space_handler,
116 &acpi_pcc_address_space_setup,
118 if (ACPI_FAILURE(status))
119 pr_alert("OperationRegion handler could not be installed\n");