From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390707; b=K7qlMT/bM7I2x/FexL5BJ0KjycRHGYNCX6S2syE5HaXETC1wDmnlLBExxxFaDaln9L2S sEKoI2+TPcm4ei4Iskd/iO0I+t+LRIqgCl4/I0p/pngvs4Rcnxaxb4bpjyo+dYhQNI6NH F907gWA8z8An/RNEhEvV8dWYOjZo0hC7KLIMpbX1JwErSY4ZKXTRpLoqip0t+enYjC3Kb 2zPCRS17vO9AzAXOjUzR4ajGSfdch+nsGH1/Eb8EPmMTaioF9K2+dvvD6f32ynJ5ygRD5 lxluPU4jPE/shV1Vr8MvCZalLDw1QsBJY/+Rvoc9E6g/0VkROxR34903/DlI402VqbQ== 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=VkZ1txD/DKkc7g0c8RZ7+ZRvWcLVImpO/POlzw/W7721tw7AxV0zaAmE6EV75IYVo8Sm swVyo2bxJXfHGJZ0kljB/KcyQbNiVVqnEacjl/k0+hnT85Xm1IWFldR8GuXCGvxn7UIPL YUzqgj+95NMAZah02Z/uMS6AIf5+CgII3Rn6qNbdxY3ZVlJ5gGFejd3147O7tHNFEZrxN e2z4NGr5emFZMrpTn4mrvGsC0Zk7+/Q6nIYvHfSbXP8eDfhZ46ouXlmx6W8sDS4zeru5p IBI8PtIx4v7807BRcRDwrFmvMngHuk8DqwhJQifvKKrUfqtbT3gmOMawuNCwUIUa/5g== 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.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 7A102606A32C for ; Fri, 4 Dec 2026 13:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7A102606A32C 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-f177.google.com with SMTP id 5a478bee46e88-385c497bf94so2056756eec.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=xKjBmHsZjIGhp4uZa7dfrs4sZ9rw+S81Eu40uv3QaVM+8hgXXcauLKfgj0ykMofv3B CgqDzeWI7YuAWbH5rR3CkGrjoKQWDYsz4MX1q0q+5ojpbreQ0N2Hy6sq8ei/BC4uO1KK h9n0CsPK8XbGy64wDHSsiDOTtfjqKgGRFcp3lYTO1vR8Z+RccjpbfV/yINGFs6BJPnUE 8QIoCJGNTLKNDMUzZfGKoGKYQbEnKjN98oGCTDdUXfABBK08BYyll1o7b8TAcWAn7yWQ lcFrdLyYcdIEsUH/1Fen6dkvjiYZTeXeQanw4u67LNh3wKfHX7JKqpTULeBC5vCMf1QW 7G3w== X-Forwarded-Encrypted: i=1; AL+hErEalZG4RfIcvh/92O+YD6dWGnDI4KwEtXOuwO3W7zR+hWUaYMmq6tTaVQKvn4HgfQUcSotjFc4luBT6@vger.kernel.org X-Gm-Message-State: AB4q+uHpyjDOhVgf5ga+nnnex04MZSCL3cMnc4mpfRX3VsAqEtWL986u mjWheFRlBXazXtMZEDANnPxALfVwxcbfVLliOIo4zZmE+tQ4FialE3U= X-Gm-Gg: AZFdTZdlww3wbzEW0xSsiPenglTdLV70vHVdcjpR3z87cLlpirfVaKaatj3/lL453rD kVrTDXOyrwxCHkiUrEDfvLWOLEVI2vWgpXN1G4yf/vFhYxI5KpLfGJEzcSUFpE2nSc78leUvKm0 JQpzjY0O877X9AUUiD8LTsZHoVbkCdTtoX7H0xXuATOY2Pb82+DrVBVs9SVyGsnQyTt3wUscNY0 plakRsYjOgGhuOErCjoIvjESvHrlC+lPLE6B2l9PhVrL+77/Hm/Mdw4zAT9xKxnBJ++DCA3Vwjz /VTMiWXUykP1nby7YnoBIMip4PzeVBYnbILexZ/kUct+pEivUDAw0MHNluoyOWbV9xjoUKdZzmt A9h+c00N9elf6V/RjKutk+3HPflOB/GLrde/RpOP6YkBeoA72ZeTwxPRo5TybmtnHpinkoTnEcd GR1JgIl3eJ4pAg0R7xe1LAjzzTDIPICCayPtKBkz9oucm4X9PEjCEjeFa51gRr0gmh5y0LVL019 gZvKJbr/pjYzWbPypcqYf2ja8Huiivo/s+2wRh2F6DDLBhqaAnvIuH+zw049lBYdkB0g1KlTEKg AUJiWOu3LpLFh31bLLdfrZeiqdvmd8P7Nv8Jf2dZTsWAM3+ZJXN5Uz+HZS96AQ== 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-leds@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