* [PATCH 00/14] mailbox: pcc: Fixes and cleanup/refactoring
@ 2025-03-03 10:51 Sudeep Holla
2025-03-03 10:51 ` [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling Sudeep Holla
0 siblings, 1 reply; 4+ messages in thread
From: Sudeep Holla @ 2025-03-03 10:51 UTC (permalink / raw)
To: linux-acpi, linux-kernel
Cc: Sudeep Holla, Jassi Brar, Huisong Li, Adam Young, Robbie King,
Andi Shyti, linux-i2c, Jean Delvare, Guenter Roeck, linux-hwmon,
Rafael J. Wysocki
Here is a summary of the changes in this patch series:
1. Fix for race condition in updating of the chan_in_use flag
Ensures correct updating of the chan_in_use flag to avoid potential race
conditions.
2. Interrupt handling fix
Ensures platform acknowledgment interrupts are always cleared to avoid
leaving the interrupt asserted forever.
3. Endian conversion cleanup
Removes unnecessary endianness conversion in the PCC mailbox driver.
4. Memory mapping improvements
Uses acpi_os_ioremap() instead of direct mapping methods for better ACPI
compatibility.
5. Return early if the command complete register is absent
Ensures that if no GAS (Generic Address Structure) register is available,
the function exits early.
6. Refactor IRQ handler and move error handling to a separate function
Improves readability of error handling in the PCC mailbox driver’s
interrupt handler.
7. Code restructuring to avoid unnecessary forward declaration
Moves pcc_mbox_ioremap() function to a more appropriate location with
no functional impact.
8. Shared memory mapping refactoring/enhancements
Ensures the shared memory is always mapped and unmapped in the PCC
mailbox driver when the PCC channel is requested and release.
9. Refactored check_and_ack() Function
Simplifies and improves the logic for handling type4 platform notification
acknowledgments.
10-14. Shared memory handling simplifications across multiple drivers
Simplifies shared memory handling in:
Kunpeng HCCS driver (soc: hisilicon)
Apm X-Gene Slimpro I2C driver
X-Gene hardware monitoring driver (hwmon)
ACPI PCC driver
ACPI CPPC driver
The X-gene related changes now change the mapping attributes to align
with ACPI specification. There are possibilities for more cleanups on
top of these changes around how the shmem is accessed within these
driver. Also, we can just target 10-14 for following merge window
after 1-9 is merged.
Overall, the patch series focuses on improving correctness, efficiency, and
maintainability of the PCC mailbox driver and related components by fixing
race conditions, optimizing memory handling, simplifying shared memory
interactions, and refactoring code for clarity.
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
Huisong Li (1):
mailbox: pcc: Fix the possible race in updation of chan_in_use flag
Sudeep Holla (13):
mailbox: pcc: Always clear the platform ack interrupt first
mailbox: pcc: Drop unnecessary endianness conversion of pcc_hdr.flags
mailbox: pcc: Return early if no GAS register from pcc_mbox_cmd_complete_check
mailbox: pcc: Use acpi_os_ioremap() instead of ioremap()
mailbox: pcc: Refactor error handling in irq handler into separate function
mailbox: pcc: Move pcc_mbox_ioremap() before pcc_mbox_request_channel()
mailbox: pcc: Always map the shared memory communication address
mailbox: pcc: Refactor and simplify check_and_ack()
soc: hisilicon: kunpeng_hccs: Simplify PCC shared memory region handling
i2c: xgene-slimpro: Simplify PCC shared memory region handling
hwmon: (xgene-hwmon) Simplify PCC shared memory region handling
ACPI: PCC: Simplify PCC shared memory region handling
ACPI: CPPC: Simplify PCC shared memory region handling
drivers/acpi/acpi_pcc.c | 13 +---
drivers/acpi/cppc_acpi.c | 16 +----
drivers/hwmon/xgene-hwmon.c | 40 ++---------
drivers/i2c/busses/i2c-xgene-slimpro.c | 39 ++--------
drivers/mailbox/pcc.c | 128 ++++++++++++++++++---------------
drivers/soc/hisilicon/kunpeng_hccs.c | 38 ++++------
drivers/soc/hisilicon/kunpeng_hccs.h | 2 -
include/acpi/pcc.h | 5 --
8 files changed, 97 insertions(+), 184 deletions(-)
---
base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6
change-id: 20250303-pcc_fixes_updates-55a17fd28e76
Best regards,
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling
2025-03-03 10:51 [PATCH 00/14] mailbox: pcc: Fixes and cleanup/refactoring Sudeep Holla
@ 2025-03-03 10:51 ` Sudeep Holla
2025-03-03 13:55 ` Guenter Roeck
0 siblings, 1 reply; 4+ messages in thread
From: Sudeep Holla @ 2025-03-03 10:51 UTC (permalink / raw)
To: linux-acpi, linux-kernel
Cc: Sudeep Holla, Jassi Brar, Huisong Li, Adam Young, Jean Delvare,
Guenter Roeck, linux-hwmon
The PCC driver now handles mapping and unmapping of shared memory
areas as part of pcc_mbox_{request,free}_channel(). Without these before,
this xgene hwmon driver did handling of those mappings like several
other PCC mailbox client drivers.
There were redundant operations, leading to unnecessary code. Maintaining
the consistency across these driver was harder due to scattered handling
of shmem.
Just use the mapped shmem and remove all redundant operations from this
driver.
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
drivers/hwmon/xgene-hwmon.c | 40 ++++------------------------------------
1 file changed, 4 insertions(+), 36 deletions(-)
diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index 1e3bd129a922d25ff25142d864503377773304a8..ea350d4de902c4e6fc4de1cd54a8b75edfad1119 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -102,9 +102,6 @@ struct xgene_hwmon_dev {
struct device *hwmon_dev;
bool temp_critical_alarm;
-
- phys_addr_t comm_base_addr;
- void *pcc_comm_addr;
u64 usecs_lat;
};
@@ -125,7 +122,8 @@ static u16 xgene_word_tst_and_clr(u16 *addr, u16 mask)
static int xgene_hwmon_pcc_rd(struct xgene_hwmon_dev *ctx, u32 *msg)
{
- struct acpi_pcct_shared_memory *generic_comm_base = ctx->pcc_comm_addr;
+ struct acpi_pcct_shared_memory __iomem *generic_comm_base =
+ ctx->pcc_chan->shmem;
u32 *ptr = (void *)(generic_comm_base + 1);
int rc, i;
u16 val;
@@ -523,7 +521,8 @@ static void xgene_hwmon_rx_cb(struct mbox_client *cl, void *msg)
static void xgene_hwmon_pcc_rx_cb(struct mbox_client *cl, void *msg)
{
struct xgene_hwmon_dev *ctx = to_xgene_hwmon_dev(cl);
- struct acpi_pcct_shared_memory *generic_comm_base = ctx->pcc_comm_addr;
+ struct acpi_pcct_shared_memory __iomem *generic_comm_base =
+ ctx->pcc_chan->shmem;
struct slimpro_resp_msg amsg;
/*
@@ -649,7 +648,6 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
} else {
struct pcc_mbox_chan *pcc_chan;
const struct acpi_device_id *acpi_id;
- int version;
acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
&pdev->dev);
@@ -658,8 +656,6 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
goto out_mbox_free;
}
- version = (int)acpi_id->driver_data;
-
if (device_property_read_u32(&pdev->dev, "pcc-channel",
&ctx->mbox_idx)) {
dev_err(&pdev->dev, "no pcc-channel property\n");
@@ -685,34 +681,6 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
goto out;
}
- /*
- * This is the shared communication region
- * for the OS and Platform to communicate over.
- */
- ctx->comm_base_addr = pcc_chan->shmem_base_addr;
- if (ctx->comm_base_addr) {
- if (version == XGENE_HWMON_V2)
- ctx->pcc_comm_addr = (void __force *)devm_ioremap(&pdev->dev,
- ctx->comm_base_addr,
- pcc_chan->shmem_size);
- else
- ctx->pcc_comm_addr = devm_memremap(&pdev->dev,
- ctx->comm_base_addr,
- pcc_chan->shmem_size,
- MEMREMAP_WB);
- } else {
- dev_err(&pdev->dev, "Failed to get PCC comm region\n");
- rc = -ENODEV;
- goto out;
- }
-
- if (!ctx->pcc_comm_addr) {
- dev_err(&pdev->dev,
- "Failed to ioremap PCC comm region\n");
- rc = -ENOMEM;
- goto out;
- }
-
/*
* pcc_chan->latency is just a Nominal value. In reality
* the remote processor could be much slower to reply.
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling
2025-03-03 10:51 ` [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling Sudeep Holla
@ 2025-03-03 13:55 ` Guenter Roeck
2025-03-03 15:05 ` Sudeep Holla
0 siblings, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2025-03-03 13:55 UTC (permalink / raw)
To: Sudeep Holla, linux-acpi, linux-kernel
Cc: Jassi Brar, Huisong Li, Adam Young, Jean Delvare, linux-hwmon
On 3/3/25 02:51, Sudeep Holla wrote:
> The PCC driver now handles mapping and unmapping of shared memory
> areas as part of pcc_mbox_{request,free}_channel(). Without these before,
> this xgene hwmon driver did handling of those mappings like several
> other PCC mailbox client drivers.
>
> There were redundant operations, leading to unnecessary code. Maintaining
> the consistency across these driver was harder due to scattered handling
> of shmem.
>
> Just use the mapped shmem and remove all redundant operations from this
> driver.
>
> Cc: Jean Delvare <jdelvare@suse.com>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: linux-hwmon@vger.kernel.org
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Note that I'll apply a fix this week which will cause a context conflict.
See below.
> ---
> drivers/hwmon/xgene-hwmon.c | 40 ++++------------------------------------
...
> @@ -685,34 +681,6 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
> goto out;
> }
>
> - /*
> - * This is the shared communication region
> - * for the OS and Platform to communicate over.
> - */
> - ctx->comm_base_addr = pcc_chan->shmem_base_addr;
> - if (ctx->comm_base_addr) {
> - if (version == XGENE_HWMON_V2)
> - ctx->pcc_comm_addr = (void __force *)devm_ioremap(&pdev->dev,
> - ctx->comm_base_addr,
> - pcc_chan->shmem_size);
> - else
> - ctx->pcc_comm_addr = devm_memremap(&pdev->dev,
> - ctx->comm_base_addr,
> - pcc_chan->shmem_size,
> - MEMREMAP_WB);
> - } else {
> - dev_err(&pdev->dev, "Failed to get PCC comm region\n");
> - rc = -ENODEV;
> - goto out;
> - }
> -
> - if (!ctx->pcc_comm_addr) {
This needed to be IS_ERR_OR_NULL() since devm_memremap() returns an ERR_PTR.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling
2025-03-03 13:55 ` Guenter Roeck
@ 2025-03-03 15:05 ` Sudeep Holla
0 siblings, 0 replies; 4+ messages in thread
From: Sudeep Holla @ 2025-03-03 15:05 UTC (permalink / raw)
To: Guenter Roeck
Cc: linux-acpi, linux-kernel, Sudeep Holla, Jassi Brar, Huisong Li,
Adam Young, Jean Delvare, linux-hwmon
On Mon, Mar 03, 2025 at 05:55:57AM -0800, Guenter Roeck wrote:
> On 3/3/25 02:51, Sudeep Holla wrote:
> > The PCC driver now handles mapping and unmapping of shared memory
> > areas as part of pcc_mbox_{request,free}_channel(). Without these before,
> > this xgene hwmon driver did handling of those mappings like several
> > other PCC mailbox client drivers.
> >
> > There were redundant operations, leading to unnecessary code. Maintaining
> > the consistency across these driver was harder due to scattered handling
> > of shmem.
> >
> > Just use the mapped shmem and remove all redundant operations from this
> > driver.
> >
> > Cc: Jean Delvare <jdelvare@suse.com>
> > Cc: Guenter Roeck <linux@roeck-us.net>
> > Cc: linux-hwmon@vger.kernel.org
> > Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
>
> Acked-by: Guenter Roeck <linux@roeck-us.net>
>
> Note that I'll apply a fix this week which will cause a context conflict.
> See below.
>
Sure, I was planning to repost these individually after the mailbox changes
are merged. I am not sure if I can get some testing on this xgene platform
as I am changing the mapping attributes which currently is different for
different versions of firmware and both are incorrect in terms of ACPI spec.
In short, no rush. The idea of posting these is to show how duplicate code
can be removed. I will post it independently sometime in the future.
>
> This needed to be IS_ERR_OR_NULL() since devm_memremap() returns an ERR_PTR.
>
True. IIRC, there are few valid iomem related sparse warnings which I plan
to fix and post it together once the PCC changes are merged.
Thanks for the review.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-03 15:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 10:51 [PATCH 00/14] mailbox: pcc: Fixes and cleanup/refactoring Sudeep Holla
2025-03-03 10:51 ` [PATCH 12/14] hwmon: (xgene-hwmon) Simplify PCC shared memory region handling Sudeep Holla
2025-03-03 13:55 ` Guenter Roeck
2025-03-03 15:05 ` Sudeep Holla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox