From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390707; b=gPV7H1mTDJOXHv4ZE0HXU1Y0SsBSC5+Mvjm7omPBiW+QrQwywQwMwwvGHThh+GG9ARD+ hjrrXvddRRwt7BzURktLEsiKOGW5hi88CLAZmMBew64TBOjJHpAPo8Sa/HMRY2mLsVtnj 9GLOyxncrwL2YwEO+mk6hMAEvToM8vqRwzqET7m0srVp3Jyyo+gkDjVA60H/HzKDyFIEn S/zfbnXr9YTq8ggQzTCBXaDde7rkpxVoc+/NfYtc90Jb5nXllcMORt6Bu15vzEWUs5gZV 5nA1d2ZvZx2Kj9aKcd3SoCBczVJwtGgGkg4xDwy2GQ/0a++YUE3Mzg1VAU++6cxz9sw== 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=BhF7zcL7oZUzaz1J4tE+0P+OXRSrIIrWewAFfd+VCyr+PrIk9ebGspBHnKYbgJWj1g3d 4W5rQsH6YpVDgWTh0BrZZ/cHr75JZnosWuJAOPrOPQyilOY1CVOihA6r0rU4tlRInsB25 izJoCq7bWO6tT/u3B8BgQJ1zHgya1BumgLbTPFbHMPswfEyYYAkpWUfmrGq+GcMZ9QLLR v7TerfDq+P1DAcfuoX8sSbtUh3xSUpunZ/Hn89wby691msxD2da1YkNF8iOi9VoJYvA8U vLGCm0zHYiOsOqlGratHybOcjHdpjXJVXOKZcUfmM2qqI0SEY6X8aidqCiW4KzDSdMA== 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.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 A3924606A33B for ; Fri, 4 Dec 2026 13:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A3924606A33B 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-f182.google.com with SMTP id 5a478bee46e88-385c497bf94so2056761eec.1 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=u5KgiGjg+9htG381+fLel/ork2m+XegfP2+0sCKrOmRv/XwJtzcrqfcCi1JNQXyS7W A2QWSx6ZuatRXhPxyymys0Y0qN8QF7V2gU03D0/frN6veJSr9L5wOQlOy1OeTyuYELtq XZqmTlsPfD2Fily5CwYmaE7oz/eKAzdVjcN+z5lxyVIM5/Q50rTiQzNS6D4Wl4bTH7FJ gKI8hWBX9KXlDtFSiawMu7fFt1hUbpj1yIBQx7VFHtcRWcQcsHOsKI5k/NT+J7IGYnmP znUv+tVuCc5k0S2V02amyQn07TjVEMyz/vhGXxPPDae2V0K/i1rbXKtE+V+b1+XT9Lk5 GE4g== X-Forwarded-Encrypted: i=1; AL+hErEwbwnUnBc3fPJMai7+GJxm5c6zdEpJjjW0O0G3JV8zuRxJN8HLA9nE6BCKx1Q7caqfYtMGXufcvKcucOwbkw==@vger.kernel.org X-Gm-Message-State: AB4q+uESXj9oHlw3XcyI5DXlUOXsVLQRQSoi5NTdiClsW+VKGjTGJL4b C7bAhF+MoUioe8upfiwGrjas06Ans4gchj56BC5g6Dlq+/1N73pUTQ8= X-Gm-Gg: AZFdTZcI6RYGDN8+giVaPNM8Ze7ums73U3raZyUAs6lujlmQP6FIWyG0cfL5utaJWwr EV3Bpf+8m1DgXpTQ+twi88so8lWohTImyeq6/1bpW5wAnGmkHY52fL5aSFG5nsdnIKdiQ8fTrU8 /MhsMMTbkUs3tA8mNzkDaIgIstm0qh7xs9rCyBZpHgmMhaEtT2AMJ/J9LUxv/FZFVmYlYSLNgXY wx4IBfdpYCV+1J3ix3N0W+SRT/gGDwZsmdrll7Tr2QhGgKeWDlGaZ0Or14sWrX4twgzUfT4boy6 oWG4CgsKbVMp+tapP+TOl5uIqZHPkRj9Dy3w7bwfOLJT2T4HkvUOuWV+Pdgegh1qUlpKja6ttBO seFS7HutKAYhwmppfGGH0aej47QtPy7O+tu84QVj+UtWKbfYDbN0dTEBeHFu16C55fVr5gBoG3k P0qRiZE5MD0gcK1mgvbvVupGbhZoJpmCaGViKsZDHMT3kQmRtB2a1i1nzO7F/zZdtKFbJlVqJ48 qmnLAhcDdVo8pX4SFgnaFWaNEAgggP2ZF2khmnnyp5PTWCMQTufMf77wMGJGF2Ine2HY7TUlXGc iJGCbusdM5PQTwtTKp2oO2ANzi4n/CJYURYmagnVbgFAKj11xUOFU+NsKUmfzg== 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-watchdog@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