From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390707; b=V82t8NH+/5+BAag6ZXjqZOMXOpCfpu+azD7XmKXV7u9u1RmFlJz6P9gbqNQ1n5YHQd1t XvOKyzOEkrnhil7rxEFYBX/EzAingL/+lfGcArOPR4mw7jaeRBBoTVTaDWM9lBF2sB8Vi oEdZyvuXeMl6wU/Z2F6asy51T5HamhV7zeWWRm8Swpbl5xvF0DTENGjSFXBxw1uaJ3xrf KCWi1hwO3mdI2IUAVGchf6YUuqRcqzZLdGFLwuWq2uuBaJxBMril+qkMswOFUr3WEzb77 UoWAK5xynhNe8CMRzaFjw2v2wnA2y9tfTzPIV3Ymw2ryk+P1tlLkhgcpC6EZHkvymXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390707; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=O2cEnQEeUxfdaHNoHTL+V8CQ+1m8Ci56bGz6i+IWhVw=; b=qOqcsw5MnPL8iOZHewrW/ysfqi/Vb8BlvDzFiOPYEeeAKcdVaiJDdFU5uhxoz9xAYHho k/rMmsDKf/Xf5bxyEhCvZd9+amVqgwOwRBRIr5lIkekscc/H6ZPvf+jOT80D+2+tBDXpa q5+Em8ThCSWbyhzFLYv41g3PoEEyL1ipnn3RLSZ+nqWd5i1Jksluq/YgV66fZa4LbtES9 rl6M8Mjpix1F1WmnmTbOOhz9I4ZJFdnJMBX11d+AJcxvP2E0VQ5H6ldci9kO0/E3PtIPz dDS6ZJ/WJTA7cX9VKah4XSrDhAMJPIx48eZfpvnvoQBDC8lYjHqQuO2oVbX2ZxMZHXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QupLIuYN; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 A1487606A339 for ; Fri, 4 Dec 2026 13:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A1487606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QupLIuYN Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-38692f62b22so1870383eec.0 for ; Fri, 04 Dec 2026 05:25:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796390706; x=1796995506; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O2cEnQEeUxfdaHNoHTL+V8CQ+1m8Ci56bGz6i+IWhVw=; b=QupLIuYN6M+iw4b94Qip0luGhSfD4nPN5RnWO+r9p+JIJ8NCMjczxVJTOqIURspX2w MM/HTFL/mZ1DyaaUtQPWzDX7+FQb0l1OpGqC5tqQHvEHRnnbJRhStuJXXGaw8fuFAX+9 bg+8DhD+MBp6YFCLx3h/rrrd95xunuYqocFXecxkkxk9GWVnVHJKjpJ6gOjK0G0Q1fBD PA/Ls8u9m/gbjsP+imIqf+aUh9ajHxur97LpLqsGRZeE78ibS18xRLHvCh/w68JKDy5q yO8g/pJ1M5RecBtXeW1iz/EHKX8ZEE2J/0FIukm/wNbi+ddYdrwMqfzzm3JrjY4CJYO7 EDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796390706; x=1796995506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O2cEnQEeUxfdaHNoHTL+V8CQ+1m8Ci56bGz6i+IWhVw=; b=dwVPo9Vt3VgYDy3yy8fI0rRNjux19/d0LdQxkSDja+1DjpeeXm7y7n108ty7qVf+Ac 4g52Qr22wDAV6NPNhT4Q2fjOE0dJNXcIghrKSy0tbSFPR6y4zulGbRnhvvlsU8U/1e+h UieHW1tN1mey9/LYCFKKaczzeuCSb4HxY0GDbdJdGZJ9y/MZ5cxYH8WPIYWwpg6cIism rPu9SjMlgq93LeDt7TNednwuQemvepvVcKvL34ED3QmAUWKwyi72m87kFmVllFOKU4q3 svKCIgdP/t2NiWTrhypVnVWn46T3z8TWkJSbnFFyR3rW0PqJr0jhA+kXqaVPsScOTmgo l+8w== X-Forwarded-Encrypted: i=1; AL+hErF9LsEZU3VCdS1pOFXmPdakuMU4/kQz9poOA4oHA2qBKZXEiDW53APrO9tiJNPPEjOXgN+SorQtsx4=@vger.kernel.org X-Gm-Message-State: AB4q+uFJgEX1309/7s2+OhZpXGtuC7oiNo/m1jjWvgo2Xe4IKpOvMHEH N/crfqCmWfHGA6dvt5m9blL9wIvTqATnZp91GM9XRJE/Ik1PdxayLeU= X-Gm-Gg: AZFdTZfM6FfQfEI4woQO0dAIo95lTp+mZdF+Tk8fF5pLv3y1LeybBUacX2TKHzQw0O3 gIpOPfL1kYlAsAMYzao+lkQAZ5ch6sCJSbAAOm7M5RM66UVTlIDVCxZw8m03VAMttnNs0Q30RO9 YuoeIu3tb0SUctAsoD32YGAAvbFTbfZ8IUk5Y5zkYvPttPgGdKTF7hwM2gkj8Yo6p6dEVhkIcmY nK0rwwXICDZzDEyloBC5QR4QyRsiGWJGtGUOCHvoC/mpxcTSok4uCFb47C3AX5IGD3/MOYUwt+h G8uhXWYJ1a60k0ZfPqa6K0mIB+ToV9fLLhBu9AGkz3seH4ZNk/HuHfa6huPaP0foCU8M0E9gnjm lrLVwYfPwF/0JNkELcX09fQs+0OXjTkfclxre6s1FR0MOzBptq033BktdltAPVMOMJXvaGcrOXV Sc0VfNDdLoKVS4tmVUx97hhWb03wj1fvrI1VYP+JiQvMnu7bjfCboYsc0BkG9SDLWU4fdhhSQEl mfoFCAYwDGIcDwe/LJtO4CEEEC8hPZZJq9CZD7I0VlxBnOaouSxE12WnvdoY++hERuRep7MsGiW Df4cQzGMjj4tHTrNZmxN9qHjRZ7ymj8n7fa+gV0+9iVThag8kAJYeJ5iHvu91w== X-Received: by 2002:a05:693c:880f:10b0:384:bc32:fe6b with SMTP id 5a478bee46e88-387521699aemr1999446eec.13.1796390705312; Fri, 04 Dec 2026 05:25:05 -0800 (PST) Received: from at-Standard-PC-Q35-ICH9-2009 ([27.60.19.167]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e1c55sm7152700eec.16.2026.12.04.05.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 05:25:04 -0800 (PST) From: Atharva Tiwari To: Cc: Atharva Tiwari , Ihor Odainyi , Antoine Sidem , Aditya Garg , 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=20S=C3=A1?= , Andy Shevchenko , Lee Jones , Pavel Machek , Griffin Kroah-Hartman , Hans de Goede , =?UTF-8?q?Ilpo=20J=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 Subject: [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Date: Fri, 4 Dec 2026 08:12:54 -0500 Message-ID: <20261204131619.5059-15-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a /dev/smc device so userspace can talk to the SMC directly. Some keys that need to be written aren't handled by any driver, or affect several drivers at once, so they can't be exposed cleanly through the kernel interfaces. Keys already managed by kernel drivers can't be written this way, to avoid conflicts. Tested-by: Ihor Odainyi Tested-by: Antoine Sidem Tested-by: Aditya Garg Signed-off-by: Atharva Tiwari --- drivers/mfd/macsmc-core.c | 140 ++++++++++++++++++++++++++++++++++++ include/linux/mfd/macsmc.h | 61 ++-------------- include/uapi/linux/macsmc.h | 119 ++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+), 56 deletions(-) create mode 100644 include/uapi/linux/macsmc.h diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c index bc4200f57..a53df6f6c 100644 --- a/drivers/mfd/macsmc-core.c +++ b/drivers/mfd/macsmc-core.c @@ -6,10 +6,13 @@ #include #include +#include #include #include +#include #include #include +#include static const struct mfd_cell apple_smc_rtkit_devs[] = { MFD_CELL_NAME("macsmc-input"), @@ -112,6 +115,129 @@ static void apple_smc_disable_notifications(void *data) smc->be->disable_notifications(smc->be_cookie); } +static long apple_smc_fops_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct apple_smc *smc = file->private_data; + void __user *argp = (void __user *)arg; + int ret; + + switch (cmd) { + case IOCTL_SMC_READ: { + struct ioctl_smc_rw_payload payload; + struct apple_smc_key_info info; + + if (copy_from_user(&payload, argp, sizeof(payload))) + return -EFAULT; + + ret = apple_smc_get_key_info(smc, payload.key, &info); + if (ret < 0) + return ret; + + if (payload.size != info.size) + return -EINVAL; + + if (payload.size > 32 || !(info.flags & APPLE_SMC_READABLE)) + return -EINVAL; + + ret = apple_smc_read(smc, payload.key, payload.buf, payload.size); + if (ret < 0) + return ret; + + if (copy_to_user(argp, &payload, sizeof(payload))) + return -EFAULT; + return 0; + } + case IOCTL_SMC_WRITE: { + struct ioctl_smc_rw_payload payload; + struct apple_smc_key_info info; + + if (copy_from_user(&payload, argp, sizeof(payload))) + return -EFAULT; + + ret = apple_smc_get_key_info(smc, payload.key, &info); + if (ret < 0) + return ret; + + if (payload.size != info.size) + return -EINVAL; + + if (payload.size > 32) + return -EINVAL; + + switch (payload.key) { + case __SMC_KEY('H', 'E', '0', 'N'): + case __SMC_KEY('H', 'E', '2', 'N'): + case __SMC_KEY('H', 'I', '0', 'N'): + case __SMC_KEY('M', 'S', 'T', 'S'): + case __SMC_KEY('M', 'S', 'P', 'C'): + case __SMC_KEY('Q', 'E', 'N', 'A'): + break; + default: + return -EPERM; + } + + ret = apple_smc_write(smc, payload.key, payload.buf, payload.size); + if (ret < 0) + return ret; + + return 0; + } + case IOCTL_SMC_GET_KEY_INDEX: { + struct ioctl_smc_index_payload payload; + + if (copy_from_user(&payload, argp, sizeof(payload))) + return -EFAULT; + + ret = apple_smc_get_key_by_index(smc, payload.index, &payload.key); + if (ret < 0) + return ret; + + if (copy_to_user(argp, &payload, sizeof(payload))) + return -EFAULT; + + return 0; + } + case IOCTL_SMC_GET_KEY_INFO: { + struct ioctl_smc_info_payload payload; + + if (copy_from_user(&payload, argp, sizeof(payload))) + return -EFAULT; + + ret = apple_smc_get_key_info(smc, payload.key, &payload.info); + if (ret < 0) + return ret; + + if (copy_to_user(argp, &payload, sizeof(payload))) + return -EFAULT; + + return 0; + } + default: + return -EINVAL; + } +} + +static int apple_smc_fops_open(struct inode *inode, struct file *file) +{ + struct miscdevice *misc = file->private_data; + + file->private_data = container_of(misc, struct apple_smc, miscdev); + return 0; +} + +static const struct file_operations apple_smc_fops = { + .owner = THIS_MODULE, + .open = apple_smc_fops_open, + .unlocked_ioctl = apple_smc_fops_ioctl, + .compat_ioctl = compat_ptr_ioctl, + .llseek = noop_llseek, +}; + +static void apple_smc_misc_unregister(void *data) +{ + misc_deregister(data); +} + int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops, void *cookie, struct blocking_notifier_head *event_handlers, bool is_acpi) { @@ -150,6 +276,20 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops, if (ret) return ret; + smc->miscdev.minor = MISC_DYNAMIC_MINOR; + smc->miscdev.name = "smc"; + smc->miscdev.fops = &apple_smc_fops; + smc->miscdev.parent = dev; + smc->miscdev.mode = 0600; + + ret = misc_register(&smc->miscdev); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, apple_smc_misc_unregister, &smc->miscdev); + if (ret) + return ret; + if (smc->is_acpi) { ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_common, ARRAY_SIZE(apple_smc_acpi_common), NULL, 0, NULL); diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h index cdd040f0c..a09dc6396 100644 --- a/include/linux/mfd/macsmc.h +++ b/include/linux/mfd/macsmc.h @@ -8,44 +8,9 @@ #ifndef _LINUX_MFD_MACSMC_H #define _LINUX_MFD_MACSMC_H +#include #include - -/** - * typedef smc_key - Alias for u32 to be used for SMC keys - * - * SMC keys are 32bit integers containing packed ASCII characters in natural - * integer order, i.e. 0xAABBCCDD, which represent the FourCC ABCD. - * The SMC driver is designed with this assumption and ensures the right - * endianness is used when these are stored to memory and sent to or received - * from the actual SMC firmware (which can be done in either shared memory or - * as 64bit mailbox message on Apple Silicon). - * Internally, SMC stores these keys in a table sorted lexicographically and - * allows resolving an index into this table to the corresponding SMC key. - * Thus, storing keys as u32 is very convenient as it allows to e.g. use - * normal comparison operators which directly map to the natural order used - * by SMC firmware. - * - * This simple type alias is introduced to allow easy recognition of SMC key - * variables and arguments. - */ -typedef u32 smc_key; - -/** - * SMC_KEY - Convert FourCC SMC keys in source code to smc_key - * - * This macro can be used to easily define FourCC SMC keys in source code - * and convert these to u32 / smc_key, e.g. SMC_KEY(NTAP) will expand to - * 0x4e544150. - * - * @s: FourCC SMC key to be converted - */ -#define SMC_KEY(s) (smc_key)(_SMC_KEY(#s)) -#define _SMC_KEY(s) (((s)[0] << 24) | ((s)[1] << 16) | ((s)[2] << 8) | (s)[3]) -#define __SMC_KEY(a, b, c, d) (((u32)(a) << 24) | ((u32)(b) << 16) | ((u32)(c) << 8) | ((u32)(d))) - -#define APPLE_SMC_READABLE BIT(7) -#define APPLE_SMC_WRITABLE BIT(6) -#define APPLE_SMC_FUNCTION BIT(4) +#include #define SMC_MSG_READ_KEY 0x10 #define SMC_MSG_WRITE_KEY 0x11 @@ -66,25 +31,6 @@ typedef u32 smc_key; #define SMC_INT_SMS_SHOCK 0x6F #define SMC_INT_PLIMIT_CHANGED 0x80 -/** - * struct apple_smc_key_info - Information for a SMC key as returned by SMC - * @type_code: FourCC code indicating the type for this key. - * Known types: - * ch8*: ASCII string - * flag: Boolean, 1 or 0 - * flt: 32-bit single-precision IEEE 754 float - * hex: Binary data - * ioft: 64bit Unsigned fixed-point intger (48.16) - * {si,ui}{8,16,32,64}: Signed/Unsigned 8-/16-/32-/64-bit integer - * @size: Size of the buffer associated with this key - * @flags: Bitfield encoding flags (APPLE_SMC_{READABLE,WRITABLE,FUNCTION}) - */ -struct apple_smc_key_info { - u32 type_code; - u8 size; - u8 flags; -}; - /** * enum apple_smc_boot_stage - SMC boot stage * @APPLE_SMC_BOOTING: SMC is booting @@ -136,6 +82,7 @@ struct apple_smc_backend_ops { * @is_acpi: Is the backend ACPI based * @mutex: Mutex for non-atomic mode * @lock: Spinlock for atomic mode + * @miscdev: Misc Device struct for ioctl ops */ struct apple_smc { struct device *dev; @@ -152,6 +99,8 @@ struct apple_smc { struct mutex mutex; spinlock_t lock; + + struct miscdevice miscdev; }; /** diff --git a/include/uapi/linux/macsmc.h b/include/uapi/linux/macsmc.h new file mode 100644 index 000000000..ef784539d --- /dev/null +++ b/include/uapi/linux/macsmc.h @@ -0,0 +1,119 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT WITH Linux-syscall-note */ +/* + * Apple SMC Public Interface + * + * Copyright (C) 2026 Atharva Tiwari + */ + +#ifndef _UAPI_MACSMC_H +#define _UAPI_MACSMC_H + +#include +#include + +/** + * typedef smc_key - Alias for u32 to be used for SMC keys + * + * SMC keys are 32bit integers containing packed ASCII characters in natural + * integer order, i.e. 0xAABBCCDD, which represent the FourCC ABCD. + * The SMC driver is designed with this assumption and ensures the right + * endianness is used when these are stored to memory and sent to or received + * from the actual SMC firmware (which can be done in either shared memory or + * as 64bit mailbox message on Apple Silicon). + * Internally, SMC stores these keys in a table sorted lexicographically and + * allows resolving an index into this table to the corresponding SMC key. + * Thus, storing keys as u32 is very convenient as it allows to e.g. use + * normal comparison operators which directly map to the natural order used + * by SMC firmware. + * + * This simple type alias is introduced to allow easy recognition of SMC key + * variables and arguments. + */ +typedef __u32 smc_key; + +/** + * SMC_KEY - Convert FourCC SMC keys in source code to smc_key + * + * This macro can be used to easily define FourCC SMC keys in source code + * and convert these to u32 / smc_key, e.g. SMC_KEY(NTAP) will expand to + * 0x4e544150. + * + * @s: FourCC SMC key to be converted + */ +#define SMC_KEY(s) ((smc_key)(_SMC_KEY(#s))) +#define _SMC_KEY(s) (((s)[0] << 24) | ((s)[1] << 16) | ((s)[2] << 8) | (s)[3]) +#define __SMC_KEY(a, b, c, d) (((__u32)(a) << 24) | ((__u32)(b) << 16) | ((__u32)(c) << 8) | ((__u32)(d))) + +#define APPLE_SMC_READABLE BIT(7) +#define APPLE_SMC_WRITABLE BIT(6) +#define APPLE_SMC_FUNCTION BIT(4) +#define APPLE_SMC_CONST BIT(3) +#define APPLE_SMC_ATOMIC BIT(2) +#define APPLE_SMC_PRIVATE_READ BIT(1) +#define APPLE_SMC_PRIVATE_WRITE BIT(0) + +/** + * struct apple_smc_key_info - Information for a SMC key as returned by SMC + * @type_code: FourCC code indicating the type for this key. + * Known types: + * ch8*: ASCII string + * flag: Boolean, 1 or 0 + * flt: 32-bit single-precision IEEE 754 float + * hex: Binary data + * ioft: 64bit Unsigned fixed-point intger (48.16) + * {si,ui}{8,16,32,64}: Signed/Unsigned 8-/16-/32-/64-bit integer + * @size: Size of the buffer associated with this key + * @flags: Bitfield encoding flags (APPLE_SMC_{READABLE,WRITABLE,FUNCTION, + * CONST,ATOMIC,PRIVATE_READ,PRIVATE_WRITE}) + */ +struct apple_smc_key_info { + __u32 type_code; + __u8 size; + __u8 flags; +}; + +/** + * struct ioctl_smc_rw_payload - argument for IOCTL_SMC_READ and IOCTL_SMC_WRITE + * @key: SMC key to access. Input. + * @size: Size of the key's data in bytes. Input. It must match the size the + * SMC reports for @key (see IOCTL_SMC_GET_KEY_INFO) and cannot exceed + * the size of @buf. + * @buf: Key data. For IOCTL_SMC_READ this is filled in by the kernel with the + * value read from @key. For IOCTL_SMC_WRITE it holds the value to write to + * @key. + */ +struct ioctl_smc_rw_payload { + smc_key key; + __u32 size; + __u8 buf[32]; +}; + +/** + * struct ioctl_smc_index_payload - argument for IOCTL_SMC_GET_KEY_INDEX + * @index: Position in the SMC's key table. Input. + * @key: Key stored at @index. Filled in by the kernel. + * + * Calling this with increasing @index values lists every key the SMC exposes. + */ +struct ioctl_smc_index_payload { + __u16 index; + smc_key key; +}; + +/** + * struct ioctl_smc_info_payload - argument for IOCTL_SMC_GET_KEY_INFO + * @key: SMC key to look up. Input. + * @info: Size, type code and flags of @key. Filled in by the kernel. + */ +struct ioctl_smc_info_payload { + smc_key key; + struct apple_smc_key_info info; +}; + +#define APPLE_SMC_MAGIC 'S' +#define IOCTL_SMC_READ _IOWR(APPLE_SMC_MAGIC, 1, struct ioctl_smc_rw_payload) +#define IOCTL_SMC_WRITE _IOW(APPLE_SMC_MAGIC, 2, struct ioctl_smc_rw_payload) +#define IOCTL_SMC_GET_KEY_INDEX _IOWR(APPLE_SMC_MAGIC, 3, struct ioctl_smc_index_payload) +#define IOCTL_SMC_GET_KEY_INFO _IOWR(APPLE_SMC_MAGIC, 4, struct ioctl_smc_info_payload) + +#endif /* _UAPI_MACSMC_H */ -- 2.55.0