From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390708; b=IPuyeqGjDIlxFzMUrlTHvIP6ZTeW+EujIMW521jB6ZV3VrCJiA2ERQBeCSFbuGRd2En1 tDB8EcleDoKSegj8ysAm2vYQw0Iek9ieNIUd/fcMQTn/IYIIJO5fGwbxkfpug0hnQB4dv RcOMoq8lzf83DXh5ugv+TRgciuRpo5qgs1d8MO+XlY4O01gy/T0DROcLs8v7ncpYjpWA1 a9jhUv7YQP9hzHVjXO5HNC7pZB7Q0btoU3NfVgbS1bC2VD1Tbne8VaHpWOFbw5vcqJ8Rh /+p8z0rdlpkfJ2Vk6Bg5oTOlunsAB9Tyyvqv6DAlXnyvi1QqEFyTOaVa36nSz24tnBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390708; 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=4+xZICyXSlet93nY/20V34weN7/TumHiardkv12jp/YWN71wWVUy7icDTC/p1y+dp8MY qu/Ag4K+N7Rt8tRA2p2ETwZoX9tcDxMrjqOG/gk3UcDcZx8QVf2ZYT6lwEov15Ir8joNE 2CP7r1zLgmoPpx0er1R7zLpcVXRi5f5PbBqqAuHbdQDOk/oTKRiw6okgIFQkc2n/vRCCY T5J6BMZGY5iOW2cerln5MiVNgprU64Lrt3HTy5P6nOu8PlxBv8dK+FrJv9hhCu1gGdTw0 8XRHW5r00rf0vxKvCjCYvbjwBFyqWRqMhuoKNxjde3uq1ZGufYj+JySJmoTOzcjofog== 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.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 837F1606A330 for ; Fri, 4 Dec 2026 13:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 837F1606A330 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-f173.google.com with SMTP id 5a478bee46e88-38692f62b22so1870381eec.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=pGxvPIcgi1suAYNJGJkL6Jwbn1TvqrYjzjh177HhdMCV+ZaXZHSlx+Cy4V9d6k+Mtr D4rDW4VBlQvlNV6cXJ+gNYJbicwtPPtTBR6y9Ol/BWIr6ZjsjgLAp4qrDYJnPcVv2Y3m HGxt2Jj6/5VLGFFLc77OChqwre68TgI6WHElBikBkANgT9wSupWjEdGW7nGqi7pmc5gO LuJFFZ50f4mpGOZZH0oom14DnOVqh0z5qiO+UL29WqerW6UxFWe5tM3OmfGFFAU64fD5 NYpOMdom5pPhkQcfdnQsy1EYN+U8WHeiGX15FPPDPGigDGD3ocjgkjYMzntrye06yuXA P/tg== X-Forwarded-Encrypted: i=1; AL+hErFyRjt2OEZdyY5sEx9ur9GLcNzHClrhS4Ob6nQa/4dT3BlOT9kPxKILnSd/29/fGMgv41gxBg2s5bI=@vger.kernel.org X-Gm-Message-State: AB4q+uHbzoahRAFXD7LIR+px4FGI6aftq/DpV0eoTnGXmW5hf28UmfVH +0eU9DL/qB9IlcFnzZvNFUlaoLE51wpda8DAYsNt4OFnjMuJhNaEiRs= X-Gm-Gg: AZFdTZcFN8oN8HmVT1ve6Zw3medv3lwzN48cpV2wRhHWg1A6SlyGfCFUOrJOURU1wmH aU4azg0evfImS2NPBB3uLrXRTLh2crnGI7NjAmOw2BJLxiM80IjlSopsDc8+lc797oYgNYjW0eI pDAQAI0U1sXYhtvBbkb6knhnvQHJk8EFTQcMKlbx/H6IztWdlcAKYWOZTEOpCOP/ZumGUFqvjl0 BvG/Ny8vO6uQlPIzSqs7mPwfG5qZNBAnpLWSEJSktE0rb8uO4E+rPCcCPdhL/fvS7EGSu/aKuf7 pmIiShXE4eqI8egCJgXdRMha/Erpk6sjgXzhlAHkqxJgIujvlIWAbh1/IquCe3yMhI10XTX+BA7 l3z6xf03+HQpnqfrApeiH4A2wHdfJoLdQOAhcdfgnbEx8VeO33MRon2Zml88PwpBQhoEtc/oRdZ QSWzj8S6f3y3VA4P5R+xrCSV4VsoBnLp5ybinBNe0pgwrh9i39MqZnjtFot0ahdW/xgEwxybSzz Eue3CfKmS1InWYov4XGxyMg6u85JKCezBEgNqUP6sSv0T8jE7YmUy+pDJ8L3G/nVoynLLYEMQWh WsSeTnakggTXBhh9ivZ+FpYn+Pf8WtLUOC6ZidxamRRC0bLTTrUio18903EbSQ== 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-iio@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