From patchwork Sat Aug 7 08:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 493386 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp1031624jap; Sat, 7 Aug 2021 00:34:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUIFaSC1aMAd9fj8na1e/uLb3wTaSb+36e5Xo52AtRI3SmoxItAUvMS1r8uroNj0Pg3TGz X-Received: by 2002:a17:906:76c1:: with SMTP id q1mr13909283ejn.156.1628321689728; Sat, 07 Aug 2021 00:34:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1628321689; cv=pass; d=google.com; s=arc-20160816; b=jc0b/5dLBMqymUrf/hHZgZjFGbfiBJSpJQ8uGnErF8YiY6RG13xZMqtV9zXDvyw42S hHUr4B9XgsUhKm3Gi+bOtRhhnihJhzHwvySQLKpKB5VY6mCfj5lvXC+5AXfgQQZwhGKX /1rrwPvTGb0Rqd+sVq79+huVUIoztfBwlHsnn2GriQwBqcMDL2hgQK/TZ/jBMZxAqe1g 5dxIR5UMVVNFNN2+lalI5SMw6CkwM+UYyEk2prbE8OF3F4R5tAW7nC0haiorcRYyLdsK 0lJPKaA1TNDblgElItsb4cnernwE3bPkdTVz3H90xGM2m+NwE8wvD4FQ3y47xbRf7H3Q zmCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=60llg4HubmrqZlaIx9oPpFo2tpUa83jimkMpnqkrtac=; b=fB9kF/4S7W6wiHHZUAMlqL6oLTnIV+VV9I4Ei1L0wbVWprVY3bgwcmZ1yR9uuuwviv hHMqUkj4/+nrJvOqKoCplQovu1uiZoo1PzDJ+NXr808HUWDrjnzMTTQSlfJptaqbCGel lkj8SBNhGREv3h/K2DF43GxBdYxcNBfgZ0SqlCjv6+KMfmnbauPeKT62+pPA8Apc3Y8p yaq1Kq+QiF/1FIITi9UZSC/igpjK89vdxVOc+A1l+QoGI4fx+8Lj1fIkWzq/UogIZKo/ 2VH995WwHndtMgqu+9TE9zLXwKSMVWt9mr1155VuY9oB8rozYA+XlNhXUzRmn29MzbDH od3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=MqnQxwix; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id g17si10718045edb.446.2021.08.07.00.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 00:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=MqnQxwix; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC54D8312F; Sat, 7 Aug 2021 09:34:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="MqnQxwix"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1DC9A83239; Sat, 7 Aug 2021 09:28:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on062c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::62c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0722483256 for ; Sat, 7 Aug 2021 09:28:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QRymuYpNTPukpCSkCDqdSncR+d6tJBcIk+rAnTkArbgaEQshSvjb5Y26oOLfh3/8SkoNIlZSzqHf5zsYROL9n55iyyI48zNR9HmnMIhUSEsMKBu+lKgCqbwZNLFKkNs2jisvI7snkylIOfKPUGuydXu4TPOykmiXclFjc2dy09jhVOFnSVls6AFFZ40oZxxHvA6k345vMCRcBtDVLEK7MOhaarwrxsHtr6cdrX/o9rL/v5NbMqHAnDC/DwTYKAurBHauZ0KwoCQAgwfwQLsO3iwltzqBHwvUqzd1m3p9oe3ipNPZBnre6JvzKzdjTBT1NdO3ZNQJ239EB+lAIXJG8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=60llg4HubmrqZlaIx9oPpFo2tpUa83jimkMpnqkrtac=; b=gLeYsxalfEE5WkYuoSqVyWYhawuzLDaycYAxzWQAVuh8A/4vOlf8leRx+qZGgGsNKrYN/DpuCoRJRa4XeaOyMELSM2B1BZx9pbXtftaEw8IQ1RwksH9vmGzM0nt9qQSq2v84WK7byG13w/nyvmkNqf3FWAbOaU9QSL1lo3r7A7yOba7cAAajt51/+99/udg+0nOGvWN8l4uHVH1x7y8JPGUrEMTV5IRd2P6MZSc+4Y6YJzHj0wfacxRxlsGdxEDpwGObZmnhYN+ZKGZxEuGYnQilCTOzHdauGmnOT4vhblkmfq5Uuq7C8ifbZ5vDlVgpDP2BTqK6Iih6xI2uwXjD9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=60llg4HubmrqZlaIx9oPpFo2tpUa83jimkMpnqkrtac=; b=MqnQxwix6+ugBlyIoNePzYpY9Al7fSCAjxOLLMUHwISplO/jTEcgMULf1gOLYI4oEz7F6W7fBKwjWG2HQpXChteWdJ4cEM7BN1byNvCNqAaicPwSky+DtEuZR77G7x1mqHOjm8WLJqQJz4Spsuyp66h0FJRDLPaRb8/VTqKNWUA= Authentication-Results: denx.de; dkim=none (message not signed) header.d=none; denx.de; dmarc=none action=none header.from=oss.nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB6PR0402MB2758.eurprd04.prod.outlook.com (2603:10a6:4:96::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16; Sat, 7 Aug 2021 07:27:59 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c445:d742:eb76:86dd]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c445:d742:eb76:86dd%9]) with mapi id 15.20.4394.019; Sat, 7 Aug 2021 07:27:59 +0000 From: "Peng Fan (OSS)" To: sbabic@denx.de, festevam@gmail.com Cc: u-boot@lists.denx.de, uboot-imx@nxp.com, Peng Fan Subject: [PATCH V5 30/44] imx8ulp: unify rdc functions Date: Sat, 7 Aug 2021 16:00:59 +0800 Message-Id: <20210807080113.16020-31-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210807080113.16020-1-peng.fan@oss.nxp.com> References: <20210807080113.16020-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SG2PR01CA0133.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::13) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by SG2PR01CA0133.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Sat, 7 Aug 2021 07:27:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45396be4-09e6-457e-6dd3-08d95974e1ac X-MS-TrafficTypeDiagnostic: DB6PR0402MB2758: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:359; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mcbpszobBnMFOq4+zyIB+mcCRjGcf9TCI6f5YMqX9wO77hqKwB0rNJmQicof+py2SZkmxQlQ0y8zLVZCEaZ5N1xv1UnlshtRIb6iA3Qf4fxcFrIZOCoRMoV3WTJCcnxsB2HMT79aw6R6oLtntfCNlLFQD1FpeOUZnv/ygxsGPey3xF+VfV6skfz5gJO6t6NDp/Rhy5wYihTuqZb30WWR5j0batf2WLeSzTS7FlmoqJHNoST0mpkJLX8xSYKF4iaMnCpzotdNqP040VbCs3MCVnf2O9tu/KiAW12T2amkHpphIdOEN7K/P4p1l2ykbQUSIxpZS0Y93GBcBSW0U2T+IqvZfJ9eTkxTKE4+DUb92cKv3c3vMApuVuvoVABQolX4DU+B9yUKw9eogKSUR26usAxTELEo6VYWB4VgZKI/UAFxT55Kx2Avg/R6uJeaHLmn2VKrhhKrjKmC5PQL/xua8PCMLegsyoCrRqAZjsu5eaeEL6QGnZG511NRXh7Ak8z0lAkUU1pka4sssiw0Ob086nDXyj8noUvoqwqVZTxMyfkFgicHXN4Z+xJ8FVGFafZd73zXSsRLhfW9mh3QPyr5q7MFmHdUkNynRfS+riCMVTF+EEdQ9CxSQlW9NPOiVsz/9EaUV2Kqkuuouo5cFuL5DXCwc8C9IXyqTqJXdbVwFUorvNwbHrooYDLVTzcekyUf6oI0VnO1zrPoSOhSk2yhPjkKpeRuhQN551ztlTe+bzo= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(136003)(396003)(39860400002)(346002)(376002)(66946007)(66556008)(66476007)(8936002)(52116002)(5660300002)(6506007)(4326008)(6512007)(30864003)(38100700002)(2906002)(38350700002)(2616005)(8676002)(478600001)(956004)(1076003)(83380400001)(186003)(26005)(86362001)(6486002)(316002)(32563001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j8HSh81bcN0HV6fMJp4ZIPhQKiDzb5odOurHLiSy2dFrKWwJ2grcvU/Rj8SP4yDbJsRztlw+M2dOZ8wuBubrIrMkM50Wwjk8Dn9IAclGEpoQj8xHuMAaod/WScTzSlyOtvcB5pjBgJLAEtSHHnTJuDNrKCyyD4m+ziv4E8TSqceaDOw/yUjsDztlCFbk0grC/A3GXr2nefU1tW/ZHsW7Yjy5iFe/0TGQxxGDlc+xtTkyZBOh4WoVtTdplLcEuxI4wAgg0IT2XjlxxGVzmF6s3kPvzUsXtPNUHuai1IYbpZKgsBK2kwm56dhXkx5OpIcBJGMOMjcHFjssrd+u7haN4YSCwFX7x6Y2nKWoCordt5U2VCTx4G7wjPe4yVWgBJFj7XDqxjIo3VZ660CvEwukAC6UlsZNQBqIyLVl1+LugmGgtp/PwekfW9iAQbMwNfaXhqO7RBKoi7rCzb/hA3fZm10RniGJghE5dleiE3WcGqwrEbvOqyUGf4XVUbO3UMeFjU3OI9/MxWwauH193oQa28DcZKiL5RoTPU0fRJwBAwvzsJZghLykarS9wSKDkQ8ByizERpbaRRLV9e6PxznCUcOF8obmlLLd91EtTL6mYP+ClC2Cr89Us6Wmx/KQlxOyQtFljd88DxGKfrjiFMnwmNuHyqYBJPKNFlx17mx3d7yqXjZ0zxVsNvghGMKKzCrJj0wiMX6XrsaOyKaBv8nc5S/QH4U15gcD1KqnpgCh4Eu6D/git5CS63Z4aSk6tD+rPDN9OUbd8OKNtD7BTXH2/ambnTF4rRbE9nGTYGMhqIRcjl7f3m366QydbVf/yiBTkPVhDweTH9VEBPH0Re4yaKvRRZKV9zSrfOmO64+aU6bnheVnHwJQ8YnFhGq0s5oOdiaXEXv2Om/xuOls4GSXDiHW2yHNfVK7UHE7gv/2iHU4hdC6A5m/EXJLwH+FygqH23chTeQimliln+tTpyJce1Buw5YsI25vpeb4Gc3Gl0syQW7KG2T9P7rYhyAks9cQ5QKbM+88lYmxjxk/dC/sSc9Im3DC1dS94Mp57Yvt21Vmq2osLdGOfBGoJ5xh8Vivt7e3WtqYfwAcpdS32qyzEVDZ7Aqcbmpgh8BoTSAyCMfTZyjF9vy5f2GLardHZ5beUpswyCLMvFvLS/C0paoEIenctA7sDYTpoGK7xcrvEeOKJ0/Dd0CuqtJBdQPeYSMcD+pRqWB5nLgFRUzq1UpEV7MedX3Ci0VpXzY0Eg11APrqxjCephITtg43pR/6Rzwuo5xcXMrpd24dZOfW1PiGDyQa4e3eeXLGfWrnGblBetJPVjB+YxnXiAZqJn9uAtV+ X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45396be4-09e6-457e-6dd3-08d95974e1ac X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2021 07:27:58.9107 (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: qNpZQSGB9xO47tyU/hJOuel+bYDZncW93x2rqvH8ncggaZWwlCRvck4MHtcLMNs6ZIIL5j2sc9rvkFRv+2hk3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0402MB2758 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Peng Fan Unify rdc function to rdc.c Update soc.c to use new rdc function Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/rdc.h | 27 +++ arch/arm/mach-imx/imx8ulp/rdc.c | 283 +++++++++++++++++++++++- arch/arm/mach-imx/imx8ulp/soc.c | 180 ++------------- 3 files changed, 317 insertions(+), 173 deletions(-) create mode 100644 arch/arm/include/asm/arch-imx8ulp/rdc.h -- 2.30.0 diff --git a/arch/arm/include/asm/arch-imx8ulp/rdc.h b/arch/arm/include/asm/arch-imx8ulp/rdc.h new file mode 100644 index 0000000000..97463756b0 --- /dev/null +++ b/arch/arm/include/asm/arch-imx8ulp/rdc.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2021 NXP + */ + +#ifndef __ASM_ARCH_IMX8ULP_RDC_H +#define __ASM_ARCH_IMX8ULP_RDC_H + +enum rdc_type { + RDC_TRDC, + RDC_XRDC, +}; + +int release_rdc(enum rdc_type type); +void xrdc_mrc_region_set_access(int mrc_index, u32 addr, u32 access); +int xrdc_config_mrc_dx_perm(u32 mrc_con, u32 region, u32 dom, u32 dxsel); +int xrdc_config_mrc_w0_w1(u32 mrc_con, u32 region, u32 w0, u32 size); +int xrdc_config_mrc_w3_w4(u32 mrc_con, u32 region, u32 w3, u32 w4); +int xrdc_config_pdac(u32 bridge, u32 index, u32 dom, u32 perm); +int xrdc_config_pdac_openacc(u32 bridge, u32 index); +int trdc_mbc_set_access(u32 mbc_x, u32 dom_x, u32 mem_x, u32 blk_x, bool sec_access); +int trdc_mrc_region_set_access(u32 mrc_x, u32 dom_x, u32 addr_start, u32 addr_end, bool sec_access); + +void xrdc_init_mda(void); +void xrdc_init_mrc(void); + +#endif diff --git a/arch/arm/mach-imx/imx8ulp/rdc.c b/arch/arm/mach-imx/imx8ulp/rdc.c index 7a098718da..e2eca0633e 100644 --- a/arch/arm/mach-imx/imx8ulp/rdc.c +++ b/arch/arm/mach-imx/imx8ulp/rdc.c @@ -1,18 +1,17 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright 2020 NXP + * Copyright 2021 NXP */ #include -#include -#include #include -#include -#include +#include +#include #include -#include - -DECLARE_GLOBAL_DATA_PTR; +#include +#include +#include +#include #define XRDC_ADDR 0x292f0000 #define MRC_OFFSET 0x2000 @@ -41,6 +40,45 @@ DECLARE_GLOBAL_DATA_PTR; #define D4SEL_DAT (SP(RW) | SU(RW)) #define D3SEL_DAT SP(RW) +struct mbc_mem_dom { + u32 mem_glbcfg[4]; + u32 nse_blk_index; + u32 nse_blk_set; + u32 nse_blk_clr; + u32 nsr_blk_clr_all; + u32 memn_glbac[8]; + /* The upper only existed in the beginning of each MBC */ + u32 mem0_blk_cfg_w[64]; + u32 mem0_blk_nse_w[16]; + u32 mem1_blk_cfg_w[8]; + u32 mem1_blk_nse_w[2]; + u32 mem2_blk_cfg_w[8]; + u32 mem2_blk_nse_w[2]; + u32 mem3_blk_cfg_w[8]; + u32 mem3_blk_nse_w[2];/*0x1F0, 0x1F4 */ + u32 reserved[2]; +}; + +struct mrc_rgn_dom { + u32 mrc_glbcfg[4]; + u32 nse_rgn_indirect; + u32 nse_rgn_set; + u32 nse_rgn_clr; + u32 nse_rgn_clr_all; + u32 memn_glbac[8]; + /* The upper only existed in the beginning of each MRC */ + u32 rgn_desc_words[8][2]; /* 8 regions, 2 words per region */ + u32 reserved[16]; + u32 rgn_nse; + u32 reserved2[15]; +}; + +struct trdc { + u8 res0[0x1000]; + struct mbc_mem_dom mem_dom[4][8]; + struct mrc_rgn_dom mrc_dom[2][8]; +}; + union dxsel_perm { struct { u8 dx; @@ -142,3 +180,232 @@ int xrdc_config_pdac(u32 bridge, u32 index, u32 dom, u32 perm) return 0; } + +int release_rdc(enum rdc_type type) +{ + ulong s_mu_base = 0x27020000UL; + struct imx8ulp_s400_msg msg; + int ret; + u32 rdc_id = (type == RDC_XRDC) ? 0x78 : 0x74; + + msg.version = AHAB_VERSION; + msg.tag = AHAB_CMD_TAG; + msg.size = 2; + msg.command = AHAB_RELEASE_RDC_REQ_CID; + msg.data[0] = (rdc_id << 8) | 0x2; /* A35 XRDC */ + + mu_hal_init(s_mu_base); + mu_hal_sendmsg(s_mu_base, 0, *((u32 *)&msg)); + mu_hal_sendmsg(s_mu_base, 1, msg.data[0]); + + ret = mu_hal_receivemsg(s_mu_base, 0, (u32 *)&msg); + if (!ret) { + ret = mu_hal_receivemsg(s_mu_base, 1, &msg.data[0]); + if (!ret) { + if ((msg.data[0] & 0xff) == 0xd6) + return 0; + } + + return -EIO; + } + + return ret; +} + +void xrdc_mrc_region_set_access(int mrc_index, u32 addr, u32 access) +{ + ulong xrdc_base = 0x292f0000, off; + u32 mrgd[5]; + u8 mrcfg, j, region_num; + u8 dsel; + + mrcfg = readb(xrdc_base + 0x140 + mrc_index); + region_num = mrcfg & 0x1f; + + for (j = 0; j < region_num; j++) { + off = 0x2000 + mrc_index * 0x200 + j * 0x20; + + mrgd[0] = readl(xrdc_base + off); + mrgd[1] = readl(xrdc_base + off + 4); + mrgd[2] = readl(xrdc_base + off + 8); + mrgd[3] = readl(xrdc_base + off + 0xc); + mrgd[4] = readl(xrdc_base + off + 0x10); + + debug("MRC [%u][%u]\n", mrc_index, j); + debug("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", + mrgd[0], mrgd[1], mrgd[2], mrgd[3], mrgd[4]); + + /* hit */ + if (addr >= mrgd[0] && addr <= mrgd[1]) { + /* find domain 7 DSEL */ + dsel = (mrgd[2] >> 21) & 0x7; + if (dsel == 1) { + mrgd[4] &= ~0xFFF; + mrgd[4] |= (access & 0xFFF); + } else if (dsel == 2) { + mrgd[4] &= ~0xFFF0000; + mrgd[4] |= ((access & 0xFFF) << 16); + } + + /* not handle other cases, since S400 only set ACCESS1 and 2 */ + writel(mrgd[4], xrdc_base + off + 0x10); + return; + } + } +} + +void xrdc_init_mda(void) +{ + ulong xrdc_base = XRDC_ADDR, off; + u32 i = 0; + + /* Set MDA3-5 for PXP, ENET, CAAM to DID 1*/ + for (i = 3; i <= 5; i++) { + off = 0x800 + i * 0x20; + writel(0x200000A1, xrdc_base + off); + writel(0xA00000A1, xrdc_base + off); + } + + /* Set MDA10 -15 to DID 3 for video */ + for (i = 10; i <= 15; i++) { + off = 0x800 + i * 0x20; + writel(0x200000A3, xrdc_base + off); + writel(0xA00000A3, xrdc_base + off); + } +} + +void xrdc_init_mrc(void) +{ + /* The MRC8 is for SRAM1 */ + xrdc_config_mrc_w0_w1(8, 0, 0x21000000, 0x10000); + /* Allow for all domains: So domain 2/3 (HIFI DSP/LPAV) is ok to access */ + xrdc_config_mrc_dx_perm(8, 0, 0, 1); + xrdc_config_mrc_dx_perm(8, 0, 1, 1); + xrdc_config_mrc_dx_perm(8, 0, 2, 1); + xrdc_config_mrc_dx_perm(8, 0, 3, 1); + xrdc_config_mrc_dx_perm(8, 0, 4, 1); + xrdc_config_mrc_dx_perm(8, 0, 5, 1); + xrdc_config_mrc_dx_perm(8, 0, 6, 1); + xrdc_config_mrc_dx_perm(8, 0, 7, 1); + xrdc_config_mrc_w3_w4(8, 0, 0x0, 0x80000FFF); + + /* The MRC6 is for video modules to ddr */ + xrdc_config_mrc_w0_w1(6, 0, 0x80000000, 0x80000000); + xrdc_config_mrc_dx_perm(6, 0, 3, 1); /* allow for domain 3 video */ + xrdc_config_mrc_w3_w4(6, 0, 0x0, 0x80000FFF); +} + +int trdc_mbc_set_access(u32 mbc_x, u32 dom_x, u32 mem_x, u32 blk_x, bool sec_access) +{ + struct trdc *trdc_base = (struct trdc *)0x28031000U; + struct mbc_mem_dom *mbc_dom; + u32 *cfg_w, *nse_w; + u32 index, offset, val; + + mbc_dom = &trdc_base->mem_dom[mbc_x][dom_x]; + + switch (mem_x) { + case 0: + cfg_w = &mbc_dom->mem0_blk_cfg_w[blk_x / 8]; + nse_w = &mbc_dom->mem0_blk_nse_w[blk_x / 32]; + break; + case 1: + cfg_w = &mbc_dom->mem1_blk_cfg_w[blk_x / 8]; + nse_w = &mbc_dom->mem1_blk_nse_w[blk_x / 32]; + break; + case 2: + cfg_w = &mbc_dom->mem2_blk_cfg_w[blk_x / 8]; + nse_w = &mbc_dom->mem2_blk_nse_w[blk_x / 32]; + break; + case 3: + cfg_w = &mbc_dom->mem3_blk_cfg_w[blk_x / 8]; + nse_w = &mbc_dom->mem3_blk_nse_w[blk_x / 32]; + break; + default: + return -EINVAL; + }; + + index = blk_x % 8; + offset = index * 4; + + val = readl((void __iomem *)cfg_w); + + val &= ~(0xFU << offset); + + /* MBC0-3 + * Global 0, 0x7777 secure pri/user read/write/execute, S400 has already set it. + * So select MBC0_MEMN_GLBAC0 + */ + if (sec_access) { + val |= (0x0 << offset); + writel(val, (void __iomem *)cfg_w); + } else { + val |= (0x8 << offset); /* nse bit set */ + writel(val, (void __iomem *)cfg_w); + } + + return 0; +} + +int trdc_mrc_region_set_access(u32 mrc_x, u32 dom_x, u32 addr_start, u32 addr_end, bool sec_access) +{ + struct trdc *trdc_base = (struct trdc *)0x28031000U; + struct mrc_rgn_dom *mrc_dom; + u32 *desc_w; + u32 start, end; + u32 i, free = 8; + bool vld, hit = false; + + mrc_dom = &trdc_base->mrc_dom[mrc_x][dom_x]; + + for (i = 0; i < 8; i++) { + desc_w = &mrc_dom->rgn_desc_words[i][0]; + + start = readl((void __iomem *)desc_w) & 0xfff; + end = readl((void __iomem *)(desc_w + 1)); + vld = end & 0x1; + end = end & 0xfff; + + if (start == 0 && end == 0 && !vld && free >= 8) + free = i; + + /* Check all the region descriptors, even overlap */ + if (addr_start >= end || addr_end <= start || !vld) + continue; + + /* MRC0,1 + * Global 0, 0x7777 secure pri/user read/write/execute, S400 has already set it. + * So select MRCx_MEMN_GLBAC0 + */ + if (sec_access) { + writel(start, (void __iomem *)desc_w); + writel(end | 0x1, (void __iomem *)(desc_w + 1)); + } else { + writel(start, (void __iomem *)desc_w); + writel((end | 0x1 | 0x10), (void __iomem *)(desc_w + 1)); + } + + if (addr_start >= start && addr_end <= end) + hit = true; + } + + if (!hit) { + if (free >= 8) + return -EFAULT; + + desc_w = &mrc_dom->rgn_desc_words[free][0]; + + addr_start &= ~0xfff; + addr_end &= ~0xfff; + + if (sec_access) { + writel(addr_start, (void __iomem *)desc_w); + writel(addr_end | 0x1, (void __iomem *)(desc_w + 1)); + } else { + writel(addr_start, (void __iomem *)desc_w); + writel((addr_end | 0x1 | 0x10), (void __iomem *)(desc_w + 1)); + } + } + + return 0; +} diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c index 29f7d5be02..c5e20408c6 100644 --- a/arch/arm/mach-imx/imx8ulp/soc.c +++ b/arch/arm/mach-imx/imx8ulp/soc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -344,180 +345,29 @@ static void set_core0_reset_vector(u32 entry) setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26)); } -enum rdc_type { - RDC_TRDC, - RDC_XRDC, -}; - -static int release_rdc(enum rdc_type type) -{ - ulong s_mu_base = 0x27020000UL; - struct imx8ulp_s400_msg msg; - int ret; - u32 rdc_id = (type == RDC_XRDC) ? 0x78 : 0x74; - - msg.version = AHAB_VERSION; - msg.tag = AHAB_CMD_TAG; - msg.size = 2; - msg.command = AHAB_RELEASE_RDC_REQ_CID; - msg.data[0] = (rdc_id << 8) | 0x2; /* A35 XRDC */ - - mu_hal_init(s_mu_base); - mu_hal_sendmsg(s_mu_base, 0, *((u32 *)&msg)); - mu_hal_sendmsg(s_mu_base, 1, msg.data[0]); - - ret = mu_hal_receivemsg(s_mu_base, 0, (u32 *)&msg); - if (!ret) { - ret = mu_hal_receivemsg(s_mu_base, 1, &msg.data[0]); - if (!ret) { - if ((msg.data[0] & 0xff) == 0xd6) - return 0; - } - - return -EIO; - } - - return ret; -} - -struct mbc_mem_dom { - u32 mem_glbcfg[4]; - u32 nse_blk_index; - u32 nse_blk_set; - u32 nse_blk_clr; - u32 nsr_blk_clr_all; - u32 memn_glbac[8]; - /* The upper only existed in the beginning of each MBC */ - u32 mem0_blk_cfg_w[64]; - u32 mem0_blk_nse_w[16]; - u32 mem1_blk_cfg_w[8]; - u32 mem1_blk_nse_w[2]; - u32 mem2_blk_cfg_w[8]; - u32 mem2_blk_nse_w[2]; - u32 mem3_blk_cfg_w[8]; - u32 mem3_blk_nse_w[2];/*0x1F0, 0x1F4 */ - u32 reserved[2]; -}; - -struct trdc { - u8 res0[0x1000]; - struct mbc_mem_dom mem_dom[4][8]; -}; - -/* MBC[m]_[d]_MEM[s]_BLK_CFG_W[w] */ -int trdc_mbc_set_access(u32 mbc_x, u32 dom_x, u32 mem_x, u32 blk_x, u32 perm) -{ - struct trdc *trdc_base = (struct trdc *)0x28031000U; - struct mbc_mem_dom *mbc_dom; - u32 *cfg_w, *nse_w; - u32 index, offset, val; - - mbc_dom = &trdc_base->mem_dom[mbc_x][dom_x]; - - switch (mem_x) { - case 0: - cfg_w = &mbc_dom->mem0_blk_cfg_w[blk_x / 8]; - nse_w = &mbc_dom->mem0_blk_nse_w[blk_x / 32]; - break; - case 1: - cfg_w = &mbc_dom->mem1_blk_cfg_w[blk_x / 8]; - nse_w = &mbc_dom->mem1_blk_nse_w[blk_x / 32]; - break; - case 2: - cfg_w = &mbc_dom->mem2_blk_cfg_w[blk_x / 8]; - nse_w = &mbc_dom->mem2_blk_nse_w[blk_x / 32]; - break; - case 3: - cfg_w = &mbc_dom->mem3_blk_cfg_w[blk_x / 8]; - nse_w = &mbc_dom->mem3_blk_nse_w[blk_x / 32]; - break; - default: - return -EINVAL; - }; - - index = blk_x % 8; - offset = index * 4; - - val = readl((void __iomem *)cfg_w); - - val &= ~(0xFU << offset); - - if (perm == 0x7700) { - val |= (0x0 << offset); - writel(perm, (void __iomem *)cfg_w); - } else if (perm == 0x0077) { - val |= (0x8 << offset); /* nse bit set */ - writel(val, (void __iomem *)cfg_w); - } else { - return -EINVAL; - } - - return 0; -} - -int trdc_set_access(void) +static int trdc_set_access(void) { /* - * CGC0: PBridge0 slot 47 - * trdc_mbc_set_access(2, 7, 0, 47, 0x7700); - * For secure access, default single boot already support, - * For non-secure access, need add in future per usecase. + * TRDC mgr + 4 MBC + 2 MRC. + * S400 should already configure when release RDC + * A35 only map non-secure region for pbridge0 and 1, set sec_access to false */ - trdc_mbc_set_access(2, 7, 0, 49, 0x7700); - trdc_mbc_set_access(2, 7, 0, 50, 0x7700); - trdc_mbc_set_access(2, 7, 0, 51, 0x7700); - trdc_mbc_set_access(2, 7, 0, 52, 0x7700); + trdc_mbc_set_access(2, 7, 0, 49, false); + trdc_mbc_set_access(2, 7, 0, 50, false); + trdc_mbc_set_access(2, 7, 0, 51, false); + trdc_mbc_set_access(2, 7, 0, 52, false); + trdc_mbc_set_access(2, 7, 0, 53, false); + trdc_mbc_set_access(2, 7, 0, 54, false); - trdc_mbc_set_access(2, 7, 0, 47, 0x0077); + /* CGC0: PBridge0 slot 47 */ + trdc_mbc_set_access(2, 7, 0, 47, false); - /* iomuxc 0 */ - trdc_mbc_set_access(2, 7, 1, 33, 0x7700); + /* Iomuxc0: : PBridge1 slot 33 */ + trdc_mbc_set_access(2, 7, 1, 33, false); return 0; } -static void xrdc_mrc_region_set_access(int mrc_index, u32 addr, u32 access) -{ - ulong xrdc_base = 0x292f0000, off; - u32 mrgd[5]; - u8 mrcfg, j, region_num; - u8 dsel; - - mrcfg = readb(xrdc_base + 0x140 + mrc_index); - region_num = mrcfg & 0x1f; - - for (j = 0; j < region_num; j++) { - off = 0x2000 + mrc_index * 0x200 + j * 0x20; - - mrgd[0] = readl(xrdc_base + off); - mrgd[1] = readl(xrdc_base + off + 4); - mrgd[2] = readl(xrdc_base + off + 8); - mrgd[3] = readl(xrdc_base + off + 0xc); - mrgd[4] = readl(xrdc_base + off + 0x10); - - debug("MRC [%u][%u]\n", mrc_index, j); - debug("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", - mrgd[0], mrgd[1], mrgd[2], mrgd[3], mrgd[4]); - - /* hit */ - if (addr >= mrgd[0] && addr <= mrgd[1]) { - /* find domain 7 DSEL */ - dsel = (mrgd[2] >> 21) & 0x7; - if (dsel == 1) { - mrgd[4] &= ~0xFFF; - mrgd[4] |= (access & 0xFFF); - } else if (dsel == 2) { - mrgd[4] &= ~0xFFF0000; - mrgd[4] |= ((access & 0xFFF) << 16); - } - - /* not handle other cases, since S400 only set ACCESS1 and 2 */ - writel(mrgd[4], xrdc_base + off + 0x10); - return; - } - } -} - int arch_cpu_init(void) { if (IS_ENABLED(CONFIG_SPL_BUILD)) {