From: Mario Limonciello <mario.limonciello@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
John Allen <john.allen@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S . Miller" <davem@davemloft.net>,
<linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
Mario Limonciello <mario.limonciello@amd.com>
Subject: [PATCH v4 08/11] crypto: ccp: Add a sample library for ioctl use
Date: Thu, 8 Jun 2023 06:17:54 -0500 [thread overview]
Message-ID: <20230608111757.32054-9-mario.limonciello@amd.com> (raw)
In-Reply-To: <20230608111757.32054-1-mario.limonciello@amd.com>
Add a small shared library that demonstrates the usage of the
IOCTL interface. This library can be linked to but, is
intended to be loaded and used by higher level languages
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v3->v4:
* New patch
---
tools/crypto/ccp/Makefile | 13 +++++++
tools/crypto/ccp/dbc.c | 72 +++++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+)
create mode 100644 tools/crypto/ccp/Makefile
create mode 100644 tools/crypto/ccp/dbc.c
diff --git a/tools/crypto/ccp/Makefile b/tools/crypto/ccp/Makefile
new file mode 100644
index 000000000000..ae4a66d1558a
--- /dev/null
+++ b/tools/crypto/ccp/Makefile
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+CFLAGS += -D__EXPORTED_HEADERS__ -I../../../include/uapi -I../../../include
+
+TARGET = dbc_library.so
+
+all: $(TARGET)
+
+dbc_library.so: dbc.c
+ $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $<
+ chmod -x $@
+
+clean:
+ $(RM) $(TARGET)
diff --git a/tools/crypto/ccp/dbc.c b/tools/crypto/ccp/dbc.c
new file mode 100644
index 000000000000..37e813175642
--- /dev/null
+++ b/tools/crypto/ccp/dbc.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD Secure Processor Dynamic Boost Control sample library
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Mario Limonciello <mario.limonciello@amd.com>
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+/* if uapi header isn't installed, this might not yet exist */
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+#include <linux/psp-dbc.h>
+
+int get_nonce(int fd, void *nonce_out, void *signature)
+{
+ struct dbc_user_nonce tmp = {
+ .auth_needed = !!signature,
+ };
+ int ret;
+
+ assert(nonce_out);
+
+ if (signature)
+ memcpy(tmp.signature, signature, sizeof(tmp.signature));
+
+ ret = ioctl(fd, DBCIOCNONCE, &tmp);
+ if (ret)
+ return ret;
+ memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce));
+
+ return 0;
+}
+
+int set_uid(int fd, __u8 *uid, __u8 *signature)
+{
+ struct dbc_user_setuid tmp;
+
+ assert(uid);
+ assert(signature);
+
+ memcpy(tmp.uid, uid, sizeof(tmp.uid));
+ memcpy(tmp.signature, signature, sizeof(tmp.signature));
+
+ return ioctl(fd, DBCIOCUID, &tmp);
+}
+
+int process_param(int fd, int msg_index, __u8 *signature, int *data)
+{
+ struct dbc_user_param tmp = {
+ .msg_index = msg_index,
+ .param = *data,
+ };
+ int ret;
+
+ assert(signature);
+ assert(data);
+
+ memcpy(tmp.signature, signature, sizeof(tmp.signature));
+
+ ret = ioctl(fd, DBCIOCPARAM, &tmp);
+ if (ret)
+ return ret;
+
+ *data = tmp.param;
+ return 0;
+}
--
2.34.1
next prev parent reply other threads:[~2023-06-08 19:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 11:17 [PATCH v4 00/11] Add dynamic boost control support Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 01/11] crypto: ccp: Rename macro for security attributes Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 02/11] crypto: ccp: Add support for displaying PSP firmware versions Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 03/11] crypto: ccp: Add bootloader and TEE version offsets Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 04/11] crypto: ccp: move setting PSP master to earlier in the init Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 05/11] crypto: ccp: Add support for fetching a nonce for dynamic boost control Mario Limonciello
2023-06-23 8:14 ` Herbert Xu
2023-06-08 11:17 ` [PATCH v4 06/11] crypto: ccp: Add support for setting user ID " Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 07/11] crypto: ccp: Add support for getting and setting DBC parameters Mario Limonciello
2023-06-08 11:17 ` Mario Limonciello [this message]
2023-06-08 11:17 ` [PATCH v4 09/11] crypto: ccp: Add a sample python script for Dynamic Boost Control Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 10/11] crypto: ccp: Add unit tests for dynamic boost control Mario Limonciello
2023-06-08 11:17 ` [PATCH v4 11/11] crypto: ccp: Add Mario to MAINTAINERS Mario Limonciello
2023-06-21 20:59 ` [PATCH v4 00/11] Add dynamic boost control support Tom Lendacky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230608111757.32054-9-mario.limonciello@amd.com \
--to=mario.limonciello@amd.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®