From patchwork Thu Dec 5 04:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vabhav Sharma X-Patchwork-Id: 13894702 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2045.outbound.protection.outlook.com [40.107.103.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69431198857 for ; Thu, 5 Dec 2024 04:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733374627; cv=fail; b=CHuy8GcsFoNF/6FFPSt1Q4HTGcgVw9XfU29WKXVwmKHTQvhaQx/NAmRNiOfG6LAMaxZ46mEzc8an6DzR6Wj8WzeFdvudtFYj7hsCpKnM+sV8gSSgyqSHqnPlGL79E7OdZX2eB/mCqoMYwkp61yBd5EBCF1ZWmyVIhjHomMIinJo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733374627; c=relaxed/simple; bh=un9iXQ5xghbtZREQMJotfWmXPPOY7jR+nhscSRxZpvg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=uIp/ZlDRKlZQuOOM9aZT2ZyykeXoZrQ2V8rOetbjJvnxlpnClb5REMD4WzyuzE8+ZToKzi+Rz/lMO/rhkpJFeQWcI1jaVAGT4i5ReuAiRdneegTb7utw83rXbKaCMknwox4xL95j9kAKeZqmzy3IITXRWobAyFQezKIB7b5r81k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=FnSeSH6o; arc=fail smtp.client-ip=40.107.103.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="FnSeSH6o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dcLJjmU1xwBcCbZyAeNy6aIqPwy1UOk+Q6RLmOtChPD5797al2X64HhN5MGYJtfJ0Do0SOlO+OjIesY6LYntfkPTw97Il8aYhfuToiYAIYkQ9UwZ4tJNRq5EIzcKoT3h3XilqF3EOg0PuJLN4Q/2Ycrxn/WbkeukimdYNL+hjyS85fbHiI8PKRG25p0leYE0BSVJExfsAyjTIMvc/NyGP142pepFZ8beKCBJRLI/ehI/O2Z5lUrvQBZJlzg8kxsurZP0Tt0epWq0avUvFobKNgaP0b5jGwxqdDNL+WJKnRRlvFLFf+t9qEMwEIMunMh8dbISpfpuCL6wM93ki9cl2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G7veCpghGih4EyT0+UxUfwK10HmZpxhIQyYrVveOB7c=; b=sl74ktbwqC0XMhxv6P7m9Q0vfhJ8BhZPdty7EsPhsn10f8mhCzQiMjMNYEU3MedZceNTByHqmt4pjB1ULptCuwDLW2JBqVExP53jVZmLXb+p5MhYMWxQJ7tEtSiiSURSo7B9XCNITrSd8hitpWYSiHRE+Q03lyTcT/VGsNPEj9gPOKc5PdPp29+WP7eJO/407ASGk7TIXhoWLk+5V1FnByJjECTxgRuJ1lcCazX3+NI0GbkXSXY984UWnNkXGpskR5lxBqe8VcoZ38tOB8LA/BCA/QfrZ4zwDeJYMyMhC6gRPYVXXqAEQLjR1r22QI64x7l0ZmTkFbKdOdkCizet+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G7veCpghGih4EyT0+UxUfwK10HmZpxhIQyYrVveOB7c=; b=FnSeSH6oQHAs5vlYmN4AKZZhfpjjsEcnpEIVzYoLfdrbFPqITXMb0oZUTqZfJpuh0ULefZxNwei9paExy7gM0SOshOLJpnyJHGzEK9VgeaE1zzv2MJyOX5cII7TIFP8+FK0tAYKbnWeCWlqViml1ud3OfyomDC3wkZKH3QPSBfkxx9QpA5r1eYQaNjZVtQ0vPI/H8vBusk5QVxnvioIRg4ypx3iSPmb/+kdkZDg/0jHj3FsYqVLCF/T58b2Ku8IPQwgakkPivv6nLX2b2JY16/hS/Z04I8uyL2uDE7SnHKLqwSmj0ROrBHQHXGmnM05mY3Y1sS1V22SwKlneO08D8Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS1PR04MB9358.eurprd04.prod.outlook.com (2603:10a6:20b:4dc::19) by DB8PR04MB6794.eurprd04.prod.outlook.com (2603:10a6:10:11b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Thu, 5 Dec 2024 04:56:55 +0000 Received: from AS1PR04MB9358.eurprd04.prod.outlook.com ([fe80::d74b:21b6:d315:cb84]) by AS1PR04MB9358.eurprd04.prod.outlook.com ([fe80::d74b:21b6:d315:cb84%5]) with mapi id 15.20.8230.010; Thu, 5 Dec 2024 04:56:55 +0000 From: Vabhav Sharma Date: Thu, 05 Dec 2024 05:56:34 +0100 Subject: [PATCH v4 3/4] firmware: imx: Add SC APIs required for secvio module Message-Id: <20241205-secvio-v4-3-5c37cdc39573@nxp.com> References: <20241205-secvio-v4-0-5c37cdc39573@nxp.com> In-Reply-To: <20241205-secvio-v4-0-5c37cdc39573@nxp.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dong Aisheng , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, frank.li@nxp.com, pankaj.gupta@nxp.com, daniel.baluta@nxp.com, silvano.dininno@nxp.com, V.Sethi@nxp.com, meenakshi.aggarwal@nxp.com, Vabhav Sharma , Franck LENORMAND , Iuliana Prodan , Horia Geanta X-Mailer: b4 0.13.0 X-ClientProxiedBy: AM9P192CA0022.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::27) To AS1PR04MB9358.eurprd04.prod.outlook.com (2603:10a6:20b:4dc::19) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS1PR04MB9358:EE_|DB8PR04MB6794:EE_ X-MS-Office365-Filtering-Correlation-Id: 329330a6-883e-4f45-8de1-08dd14e93d13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|1800799024|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?LN/F1SY9FhV6pH2Kr5tsL6wphelZJAI?= =?utf-8?q?H/oDEFZT/MvcH+0PfcS0XIyRdGwBsSxq9wHZFO5kPt63gANZs6j5FaSorgqxBq+PC?= =?utf-8?q?VbUuBk54/ym2aw5BDcMu4vSDIo2rI5b2aIE6eXvp0erepCicYHNMCXCH2BXcABzTQ?= =?utf-8?q?MlpSrkmXpx7HhIT93xoWURYRhhpUijj7nkGh54IPgoy710C+ZW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SKVAFqVV/7D?= =?utf-8?q?X0jiIymYDJlqWpcrXpkEMe1SYweb+bPfgEL7J8vMg7MVDsktkbGF+VjtLHNedGAkB?= =?utf-8?q?WUMzyfebCuvxbmFrXTlDxZEyn4FlQUkg5jAsvEV7iNjcE7BccKeodIBZzjlg8Y8a1?= =?utf-8?q?SnMj7RQQHsxV4TqGo53EuXmfPeAZ/V4EOkDFz5eYC9rdcmJd0AqEXY8oex1RcAchP?= =?utf-8?q?0X29PvEtffRMXxmPG9lLcWf2sxdpAwTT0+jFIC0yPLIGu4ApP9CBnyDtCDmcsNMia?= =?utf-8?q?nboGDkHeWgPG/mdA7fnLkRUO8a3SWFTY3A=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS1PR04MB9358.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(1800799024)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XB1gr0IsfCU31j5Ur+f2aLdxeB8u?= =?utf-8?q?6HVSlLn4ua2j2ZUMvox6IeM6UuryLuBcwJ2nevD5Zf3gOM2zrP6ZpYUhWF2YPxdC/?= =?utf-8?q?mb9NNVUpb8UJwbIEEJgY6L7jHLPdZW5dGRE63Ovub+57z9341ajTIgoybi1MjIAme?= =?utf-8?q?pP4Y3DNZugoBxU0YdHJGPtnPRc7tUFhDl4eC9+6zBzWdeeQhmmJzrTMWnhPH0nYrD?= =?utf-8?q?D1112CS91iWUqF4pgzlt2wYd+C8htbhXmfRk3IZlMiojmoiNV98jNoctZI/l0fKJZ?= =?utf-8?q?50eRL/x95BPbQ42+C1RSStYr1QnalThP86qBIu7Qms3i1iW4vRkqOPPDOXRXhgCRM?= =?utf-8?q?bYlY1gxPif8MQsPvgFjZrSPZV9j7alLKFitJflZAzC7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WQh5ZROgkRYoP?= =?utf-8?q?Gsx02l77osbHlqRexyLbQa8bC1DCHsV7vGO3PQ7yup5y7KFSDdvFX8KLjY214lGUn?= =?utf-8?q?WxL+GFmF1nnq58hVsJKV51l0ef88i98v8l0tdz6jytyTE5XD2RlfIfoT7jozmNroB?= =?utf-8?q?XwlGcMKQTWT1oAe/sp9udTq850uKfV2mrmmzrBI6lyUYgOMzGNAVUqDgpTZ1rAlwe?= =?utf-8?q?7fX11oq5seBgnPrxF2JDPxcCoeSU2K5UDtFeQUPCTMRz0m4xVhkxENaN+rnwsyFzZ?= =?utf-8?q?6CyhC0MqiEE4?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 329330a6-883e-4f45-8de1-08dd14e93d13 X-MS-Exchange-CrossTenant-AuthSource: AS1PR04MB9358.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 04:56:54.2793 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wDeeJqyV7EpqXpmKYaN8sAHpulUIE/VmHTVv/LNo5RwXeTwvyaRV13T1VavyXk/GTMKI6Dsabrhptebb0Afvcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB6794 The Security Violation module requires below System Controller Security controller API to interact with SNVS block via SCFW - imx_sc_seco_build_info - imx_sc_seco_secvio_enable - imx_sc_seco_secvio_config - imx_sc_seco_secvio_dgo_config Signed-off-by: Franck LENORMAND Reviewed-by: Iuliana Prodan Reviewed-by: Horia Geanta Signed-off-by: Dong Aisheng Signed-off-by: Vabhav Sharma --- drivers/firmware/imx/Makefile | 2 +- drivers/firmware/imx/imx-scu.c | 4 +- drivers/firmware/imx/seco.c | 216 ++++++++++++++++++++++++++++++++++ include/linux/firmware/imx/ipc.h | 1 + include/linux/firmware/imx/sci.h | 4 + include/linux/firmware/imx/svc/seco.h | 69 +++++++++++ 6 files changed, 294 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile index 8d046c341be8..7aaecf570c56 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IMX_DSP) += imx-dsp.o -obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o +obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o seco.o obj-${CONFIG_IMX_SCMI_MISC_DRV} += sm-misc.o diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.c index 1dd4362ef9a3..c96dc73689a8 100644 --- a/drivers/firmware/imx/imx-scu.c +++ b/drivers/firmware/imx/imx-scu.c @@ -242,9 +242,11 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *msg, bool have_resp) * APIs are defined as void function in SCU firmware, so they * should be treated as return success always. */ - if ((saved_svc == IMX_SC_RPC_SVC_MISC) && + if (((saved_svc == IMX_SC_RPC_SVC_MISC) && (saved_func == IMX_SC_MISC_FUNC_UNIQUE_ID || saved_func == IMX_SC_MISC_FUNC_GET_BUTTON_STATUS)) + || (saved_svc == IMX_SC_RPC_SVC_SECO && + saved_func == IMX_SC_SECO_FUNC_BUILD_INFO)) ret = 0; } diff --git a/drivers/firmware/imx/seco.c b/drivers/firmware/imx/seco.c new file mode 100644 index 000000000000..2d6bf301ac87 --- /dev/null +++ b/drivers/firmware/imx/seco.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020, 2024 NXP + * + * File containing client-side RPC functions for the SECO service. These + * function are ported to clients that communicate to the SC. + */ + +#include + +struct imx_sc_msg_seco_get_build_id { + struct imx_sc_rpc_msg hdr; + u32 version; + u32 commit; +} __packed __aligned(4); + +int imx_sc_seco_build_info(struct imx_sc_ipc *ipc, uint32_t *version, + uint32_t *commit) +{ + struct imx_sc_msg_seco_get_build_id msg; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + int ret; + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = IMX_SC_RPC_SVC_SECO; + hdr->func = IMX_SC_SECO_FUNC_BUILD_INFO; + hdr->size = 1; + + ret = imx_scu_call_rpc(ipc, &msg, true); + if (ret) + return ret; + + if (version) + *version = msg.version; + if (commit) + *commit = msg.commit; + + return 0; +} +EXPORT_SYMBOL(imx_sc_seco_build_info); + +int imx_sc_seco_secvio_enable(struct imx_sc_ipc *ipc) +{ + struct imx_sc_rpc_msg msg; + struct imx_sc_rpc_msg *hdr = &msg; + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = IMX_SC_RPC_SVC_SECO; + hdr->func = IMX_SC_SECO_FUNC_SECVIO_ENABLE; + hdr->size = 1; + + return imx_scu_call_rpc(ipc, &msg, true); +} +EXPORT_SYMBOL(imx_sc_seco_secvio_enable); + +struct imx_sc_msg_req_seco_config { + struct imx_sc_rpc_msg hdr; + u32 data0; + u32 data1; + u32 data2; + u32 data3; + u32 data4; + u8 id; + u8 access; + u8 size; +} __packed __aligned(4); + +struct imx_sc_msg_resp_seco_config { + struct imx_sc_rpc_msg hdr; + u32 data0; + u32 data1; + u32 data2; + u32 data3; + u32 data4; +} __packed __aligned(4); + +int imx_sc_seco_secvio_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data0, u32 *data1, u32 *data2, u32 *data3, + u32 *data4, u8 size) +{ + struct imx_sc_msg_req_seco_config msg; + struct imx_sc_msg_resp_seco_config *resp; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + int ret; + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = IMX_SC_RPC_SVC_SECO; + hdr->func = IMX_SC_SECO_FUNC_SECVIO_CONFIG; + hdr->size = 7; + + /* Check the pointers on data are valid and set it if doing a write */ + switch (size) { + case 5: + if (data4) { + if (access) + msg.data4 = *data4; + } else { + return -EINVAL; + } + fallthrough; + case 4: + if (data3) { + if (access) + msg.data3 = *data3; + } else { + return -EINVAL; + } + fallthrough; + case 3: + if (data2) { + if (access) + msg.data2 = *data2; + } else { + return -EINVAL; + } + fallthrough; + case 2: + if (data1) { + if (access) + msg.data1 = *data1; + } else { + return -EINVAL; + } + fallthrough; + case 1: + if (data0) { + if (access) + msg.data0 = *data0; + } else { + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + msg.id = id; + msg.access = access; + msg.size = size; + + ret = imx_scu_call_rpc(ipc, &msg, true); + if (ret) + return ret; + + resp = (struct imx_sc_msg_resp_seco_config *)&msg; + + /* Pointers already checked so we just copy the data if reading */ + if (!access) + switch (size) { + case 5: + *data4 = resp->data4; + fallthrough; + case 4: + *data3 = resp->data3; + fallthrough; + case 3: + *data2 = resp->data2; + fallthrough; + case 2: + *data1 = resp->data1; + fallthrough; + case 1: + *data0 = resp->data0; + } + + return 0; +} +EXPORT_SYMBOL(imx_sc_seco_secvio_config); + +struct imx_sc_msg_req_seco_dgo_config { + struct imx_sc_rpc_msg hdr; + u32 data; + u8 id; + u8 access; +} __packed __aligned(4); + +struct imx_sc_msg_resp_seco_dgo_config { + struct imx_sc_rpc_msg hdr; + u32 data; +} __packed __aligned(4); + +int imx_sc_seco_secvio_dgo_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data) +{ + struct imx_sc_msg_req_seco_dgo_config msg; + struct imx_sc_msg_resp_seco_dgo_config *resp; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + int ret; + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = IMX_SC_RPC_SVC_SECO; + hdr->func = IMX_SC_SECO_FUNC_SECVIO_DGO_CONFIG; + hdr->size = 3; + + if (access) { + if (data) + msg.data = *data; + else + return -EINVAL; + } + + msg.access = access; + msg.id = id; + + ret = imx_scu_call_rpc(ipc, &msg, true); + if (ret) + return ret; + + resp = (struct imx_sc_msg_resp_seco_dgo_config *)&msg; + + if (!access && data) + *data = resp->data; + + return 0; +} +EXPORT_SYMBOL(imx_sc_seco_secvio_dgo_config); diff --git a/include/linux/firmware/imx/ipc.h b/include/linux/firmware/imx/ipc.h index 0b4643571625..df38ab8e7e2e 100644 --- a/include/linux/firmware/imx/ipc.h +++ b/include/linux/firmware/imx/ipc.h @@ -25,6 +25,7 @@ enum imx_sc_rpc_svc { IMX_SC_RPC_SVC_PAD = 6, IMX_SC_RPC_SVC_MISC = 7, IMX_SC_RPC_SVC_IRQ = 8, + IMX_SC_RPC_SVC_SECO = 9, }; struct imx_sc_rpc_msg { diff --git a/include/linux/firmware/imx/sci.h b/include/linux/firmware/imx/sci.h index df17196df5ff..947e49d8bebc 100644 --- a/include/linux/firmware/imx/sci.h +++ b/include/linux/firmware/imx/sci.h @@ -15,6 +15,10 @@ #include #include #include +#include + +#define IMX_SC_IRQ_SECVIO BIT(6) /* Security violation */ +#define IMX_SC_IRQ_GROUP_WAKE 3 /* Wakeup interrupts */ #if IS_ENABLED(CONFIG_IMX_SCU) int imx_scu_enable_general_irq_channel(struct device *dev); diff --git a/include/linux/firmware/imx/svc/seco.h b/include/linux/firmware/imx/svc/seco.h new file mode 100644 index 000000000000..508444c02d39 --- /dev/null +++ b/include/linux/firmware/imx/svc/seco.h @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020, 2024 NXP + * + * Header file containing the public API for the System Controller (SC) + * Security Controller (SECO) function. + * + * SECO_SVC (SVC) Security Controller Service + * + * Module for the Security Controller (SECO) service. + */ + +#ifndef _SC_SECO_API_H +#define _SC_SECO_API_H + +#include +#include + +/* + * This type is used to indicate RPCs/RM/SECO function calls. + */ +enum imx_sc_seco_func { + IMX_SC_SECO_FUNC_UNKNOWN = 0, + IMX_SC_SECO_FUNC_BUILD_INFO = 16, + IMX_SC_SECO_FUNC_SECVIO_ENABLE = 25, + IMX_SC_SECO_FUNC_SECVIO_CONFIG = 26, + IMX_SC_SECO_FUNC_SECVIO_DGO_CONFIG = 27, +}; + +#if IS_ENABLED(CONFIG_IMX_SCU) +int imx_sc_seco_build_info(struct imx_sc_ipc *ipc, uint32_t *version, + uint32_t *commit); +int imx_sc_seco_secvio_enable(struct imx_sc_ipc *ipc); +int imx_sc_seco_secvio_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data0, u32 *data1, u32 *data2, u32 *data3, + u32 *data4, u8 size); +int imx_sc_seco_secvio_dgo_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data); +#else /* IS_ENABLED(CONFIG_IMX_SCU) */ +static inline +int imx_sc_seco_build_info(struct imx_sc_ipc *ipc, uint32_t *version, + uint32_t *commit) +{ + return -EOPNOTSUPP; +} + +static inline +int imx_sc_seco_secvio_enable(struct imx_sc_ipc *ipc) +{ + return -EOPNOTSUPP; +} + +static inline +int imx_sc_seco_secvio_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data0, u32 *data1, u32 *data2, u32 *data3, + u32 *data4, u8 size) +{ + return -EOPNOTSUPP; +} + +static inline +int imx_sc_seco_secvio_dgo_config(struct imx_sc_ipc *ipc, u8 id, u8 access, + u32 *data) +{ + return -EOPNOTSUPP; +} +#endif /* IS_ENABLED(CONFIG_IMX_SCU) */ + +#endif /* _SC_SECO_API_H */