From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.120 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796395990; b=jOVD7YthcTb6e8/4P5QB7yFo/2Puztsgq4xAO2FcKQNNGlUgoFCXbwH6tMvRRafC7msx hlrcUR8FDFHa3PM3DLtmVQNELpPflv38Uop8sZ6TDPk0FG33mQnoq9cAj/+vDl5UOjJ7K u0vD6vEbuhqtaSIFsQwkcZ37SKQr2lBl9woCBEsvC8JoHd6gDLEMB/QDa+v6TEbn6x9z4 oE1mEnQKOdgc4yoRhUJ0+HKyMKq4J2cQ40ImQC48iLDdDjA1S377m4D0xCUjFP1eWUmGZ YZE8E3M3JbspVW0pp7aWGF/eKivT3hwA1ewVoleQOwLeICgXNzBTxSEfyk661RO9MHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796395990; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=kH/dbWCrakeqVX06xJBhPg5IpeQUUYoGGzxay+EdEcM=; b=it8PMi41BWMp8c2YZAPU2W2Z750kwiBl0dkGsaI7cqPrgGuCTehxqq1lVh8CxtwX6+ar Xs6MvrYBWFJVb0311U8EGQ5ElzYmvoDwMX0jsuF5G8S4G7WKUg2d/YhtuVLpQEin4CJPq BntJ+WBqEgumA08Fz6QTzwT9P4PkVV9a2yZCTOG+cpdRXJH+6aY8KudLG+uWb34X/TqtA idKqHl2TJ1BEHPK/34qPXfnBkirU52u9200J229R0i1Didb+69l0cLDugJXHVHKB2X02a WScArQTdizQv0ZHAtMpkYg9wAzadFFqkPE5cwg5thSdGOJ98Ry5i1h5P2IdTe3mCXiQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=BeFn1AlQ; arc=none smtp.remote-ip=95.215.58.120 Received: from mta1.migadu.com (out-120.mta1.migadu.com [95.215.58.120]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4A33606A33A for ; Fri, 4 Dec 2026 14:53:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4A33606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=BeFn1AlQ X-Envelope-To: linux-leds@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=MIG8YcjHCLQBuk6VgecKKkBaIQEm9/HcxTp6w6RNq5g=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796395987; v=1; x=1797000787; b=BeFn1AlQHvqahOnkHccpLBjnLVvoSEqGjYMkNL5Mt+/pbDyCO7K3R5H/xvlR6D0JH2DOlNrH xePhJTGdCjjSnOH7gJcmZHomXf0L8cgLQBMHLTkxCObZUL4lJxJrha9wgxX3WFvW/Gh8hVlU7YP jBZ/SrHkJU4ki19PuEvUJFp4= X-Envelope-To: linux-leds@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 369927dc8ea3368c; Fri, 04 Dec 2026 14:53:07 +0000 X-Mizu-Trace-ID: 369927dc8ea3368c X-Migadu-Flow: FLOW_OUT Message-ID: <70a1e05f-af45-46d0-ad03-8592e0ca0342@linux.dev> Date: Fri, 4 Dec 2026 20:22:52 +0530 X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs To: Andy Shevchenko , Atharva Tiwari Cc: Ihor Odainyi , Antoine Sidem , Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Rafael J. Wysocki" , Len Brown , Linus Walleij , Bartosz Golaszewski , Sven Peter , Janne Grunau , Neal Gompa , Guenter Roeck , Jonathan Cameron , David Lechner , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Lee Jones , Pavel Machek , Griffin Kroah-Hartman , Hans de Goede , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Sebastian Reichel , Alexandre Belloni , Wim Van Sebroeck , Jarkko Sakkinen , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , Paul Moore , James Morris , "Serge E. Hallyn" , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, mfd@lists.linux.dev, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, Linus Torvalds References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-3-atharvatiwarilinuxdev@gmail.com> Content-Language: en-US From: Aditya Garg In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 04-Dec-26 07:49 PM, Andy Shevchenko wrote: > 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 >> +#include > >> +#include > > Wrong, the asm/byteorder.h has to be used. > >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include > >> +#include > >> +#include > > With this, io.h is not required. > >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include > > ... > >> +#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? He is a new kernel dev. Not your fault for assuming he is a seasoned one. Can the maintainers be friendly and point out code errors rather than the RTFM thing for LKML as well? Or atleast point out some examples rather than just ranting.