From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.119 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796395990; b=lbbfVYiI19aypQKIH4Slu6QhcNnMTfWfuke6gLrqUaLdlQ31b4mCovj+yM+kvPTgAFLK 1WZrTrONEdzG4nGT0TAh3hfZiecAI5H563PntcqN3F61n2kn/DlAgmultQicTB/Amjpnq 1xPyz2taRZsGP+zrOkfcU6MCTg6fVhcp5G7MLamNycODnaP2vEJh983+RJvsmiVyothrs MxTpLE+7+WntqG81PF6qz6zTYJWaFFg3q82qnUZ5SJbTyeP1k18/ZoRglA5DYL80p77MB 9Q6qOizQRDHh9NxBRZ+lV1wdNdneX3DleQwh5KujQUgv+P1KvUgXW45ZrNG8MiQ162g== 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=d7ZHCImkc53fgBsIoM69QdQUDyJ4pDZFSBmG52bZNBnaOw2/K40ISSlaNMqd350VIkXy EIDHZjk+Ryaeo7e6moFv6LrvOfe7yxQVpBLoDX8m1HP2Vw6ld2HwS2bhhJYm89z+ETIm4 VGC3qhTccBzHat22Dlg+ILYT0ipP/UEXt+XP8+vPtnghf+BUuoyJlubJZeXJeDMMXomCf NMGE/Cv/Y3oAIhD7i8ViwjfZOXx3gsJM1iTDrysuJEgneAyJIAvtkjAr8JCU4KuIClQ9G vQM6xfEdkaQSfXc6xpuJvdreYDX1xs95DifZBhiuydxNUTzLDuHrO8/Ew4fyFK+fJzw== 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.119 Received: from mta1.migadu.com (out-119.mta1.migadu.com [95.215.58.119]) (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 9F465606A335 for ; Fri, 4 Dec 2026 14:53:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F465606A335 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: asahi@lists.linux.dev 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: asahi@lists.linux.dev 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: asahi@lists.linux.dev 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.