Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs

From: Andy Shevchenko

Date: Fri Dec 04 2026 - 09:19:53 EST


On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:
> Add a backend that talks to the SMC on Intel Macs over ACPI.
> It supports the old I/O port interface, and also MMIO and
> interrupt-driven completion, which applesmc doesn't have.
> If an interrupt is missed it falls back to polling.
>
> This is the base that lets the macsmc drivers replace
> applesmc.

...

> +#include <linux/acpi.h>
> +#include <linux/bits.h>

> +#include <linux/byteorder/generic.h>

Wrong, the asm/byteorder.h has to be used.

> +#include <linux/cleanup.h>
> +#include <linux/compiler.h>
> +#include <linux/completion.h>
> +#include <linux/device.h>
> +#include <linux/devm-helpers.h>
> +#include <linux/interrupt.h>
> +#include <linux/io.h>

> +#include <linux/ioport.h>

> +#include <linux/iopoll.h>

With this, io.h is not required.

> +#include <linux/kfifo.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm.h>
> +#include <linux/reboot.h>
> +#include <linux/spinlock.h>
> +#include <linux/time.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
> +#include <linux/workqueue.h>

...

> +#define SMC_TIMEOUT_MS 1000

Why not (1 * MSEC_PER_SEC) here ?

...

> +struct apple_smc_acpi {
> + struct device *dev;
> +
> + u8 __iomem *iomem_base;
> + u32 iomem_base_addr, iomem_base_size;
> + bool is_mmio;
> +
> + u16 port_base;
> + bool has_port;
> +
> + int irq;

> + bool has_interrupt;

Why? Isn't non-positive value means no interrupt?

> + bool interrupt_enabled;

Why? Isn't IRQ core provides something for this?

> + struct completion cmd_done;
> +
> + struct blocking_notifier_head event_handlers;
> + struct work_struct shutdown_work;
> + struct work_struct notifier_work;
> +
> + DECLARE_KFIFO(event_fifo, u8, 64);
> + /* Protects event_fifo, shared between the IRQ handler and notifier_work */
> + spinlock_t event_lock;
> +};
> +
> +

Why double blank line?

> +static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
> +{
> + u8 status;
> + int ret;
> +
> + if (smc->interrupt_enabled) {
> + reinit_completion(&smc->cmd_done);
> + if (wait_for_completion_timeout(&smc->cmd_done,
> + msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> + return 0;
> +
> + smc->interrupt_enabled = 0;
> + dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> + }
> +
> + ret = read_poll_timeout(inb, status, (status & mask) == val,
> + USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
> + false, smc->port_base + SMC_IO_CMD_PORT);
> + if (ret)
> + dev_dbg(smc->dev, "port/wait: timeout value:%u, mask:%u\n", val, mask);
> +
> + return ret;
> +}

...

> +static int apple_smc_acpi_port_write_key(struct apple_smc_acpi *smc, smc_key key)
> +{
> + int i;
> +
> + for (i = 3; i >= 0; i--) {
> + if (apple_smc_acpi_port_write_byte(smc, (key >> (i * 8)) & 0xff))
> + return -EIO;
> + }

Missing blank line.

> + return 0;

This should use proper __be32 type instead.

> +}
> +
> +static int apple_smc_acpi_port_valid(struct apple_smc_acpi *smc)
> +{
> + int ret;

> + ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> + if (!ret)

Huh?! This is way non-standard. Don't do that.
This is a semantic mistake.

> + return ret;
> +
> + ret = apple_smc_acpi_port_write_cmd(smc, SMC_MSG_READ_KEY);
> + if (ret)
> + return ret;
> +
> + return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> +}

...

> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
> + {"APP0001", 0},
> + {}
> +};

Where have you been last half a year?

--
With Best Regards,
Andy Shevchenko