From patchwork Sat Apr 10 07:18:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1464591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=eVaBA0Te; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=yD5HzMW9; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=XPTMW6yK; dkim=neutral header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=WVxZLh1y; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FHRFd4txmz9sWT for ; Sat, 10 Apr 2021 17:19:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cPue8eMfBlJPWG5DRr5fVo7QvlNZYNmtawo/XeO60BM=; b=eVaBA0TeMmxnZ4nnLBaJcb0j8 J/KXB7wfbbbvxHbd3nNwyLDKSmul8xkIpG+LnCBi62/Qy09Q1TwN1DBZRLWN3Ob2Ln4gi7yw+tk6S djU5EhfbvNQIRRECzIMBL4b69F3AP+UpvUA0xh75N1+MF3Igi1dgxrAhsZq/0vmcvjMx+qtbKFPeH Ui/BAFrLZD8Je3Z1rbWPpoBEc7O8YQsDESd7ROxv/czXfDBPf7Es6bgTiq7hnxtAcj6JHOCGLoFql 9PRlUo2AYX6zn6aoe4u74HHydjGKFIwh48f6v9ozIDJEq3rydY7Wr/nHgDvqpG5sngC/f4MpT1bB6 A3WuwKJrw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lV7tg-002M4P-5z; Sat, 10 Apr 2021 07:19:12 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lV7tH-002Lzu-R9 for opensbi@desiato.infradead.org; Sat, 10 Apr 2021 07:18:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=v1g3Jo0aXtmZEPoW5lGT8wMW/Oq60TpGaeBJJZQTyrc=; b=yD5HzMW9Q1JG6LL/HtApKH8qzx WVwvAs+i19WJpxh1OAQo4aWncZ5OxTyuF1Z4d5d3sRA2TmanCLc169XOpxpebxVPIJYCMK7WWyaDI 8yN1jboF6wwgKAzzOZken1Hwp6omnivwLeEdabR7ktyPHQRfWN7qFcAefGG8/YRXIyVNEufWqAG+g nXV2NJyWeZ60EdSFmYJskVBJ3IS7jtHdepho8QfG4yq0cEx023kS4fAdhWRog/uOj49W9wT5Ce3FF SEXYvjJKRBl36tti+jLNsEEDFYkc0p57nmRLY/6qBmFuG6wa0D6gj/r4p0cMvP33y+hgykElfbfid 0Fdv0WUQ==; Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lV7tF-004yCo-5n for opensbi@lists.infradead.org; Sat, 10 Apr 2021 07:18:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1618039125; x=1649575125; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=vc5Yqlbj4QGQUYW9cYvnMOh/H3MMz2ED4lZKNIpwX0g=; b=XPTMW6yK4+C4CaKINIfhN/0amwPZ/7XeX6sFwUyBMGTApjYtmtIX1eh4 P+/+RJEIQXN9RZmvi1I9s95zuVOr7Am43rlOpPVk7ZdvJZTLt6qr0tTum 6YjnF19ngmVdChJ+ruCOZKjta496okgY3/mYebIWdq5eCXsqXTzvQVgdr CsDVN8prRQTJq7MaldvFN9cAXaoQ5Utyek7wl6qvo+nyAlw8tQGBzpiEs hVqeHW0+fY3AkFOQfq0wm2Lh+M+BW2oQTmVtzcYcs+Ul5aH3lP2lsTqzY w+KBDfHfePXe8MXWEuMAYyCvikEaxjxTGLBzNvnTB0UOr7hB88vgka71n Q==; IronPort-SDR: CCr2wp277cvyyOQqsvqc3ipAmlShw71Qi+w+61sZ7DL2r58Lp9jzKOciAbx869Z1inhzITDt8f nsrzKRtA7Kj239HknheTc4ykZbzlXSJeTGrO4y66Cp/egQwtVgnSwYRlVWQReBvwnRTXQzvrQh 5t2X/6FGLaDVA34I+Nk1HmJ2wFYijM4NXs9/x5zJx6eMgw6W1WvCr/602WJL9s1FlUwwKotdgc EBlX96JDyWvGLgDROw1t3DAecgCNM1Oj2aaljIqu4WQ/uxcL769t3BYpkNW6Wnf0I3UrqgNz2W Y3k= X-IronPort-AV: E=Sophos;i="5.82,210,1613404800"; d="scan'208";a="164366710" Received: from mail-mw2nam12lp2044.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.44]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2021 15:18:44 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PxlHS2bcZOOzSGaBrKS6QkzmcFr02luKcMJ5VjonFXqnzXqWpdnla0WK04MXLnX0OPGkQuAg1eNNDCqSDF2snFbKpPSLI1LjdMxx7SiSg/2YjmLctJLBlftLOEBss99pZMrmvnroFXpWr0EcuHamdK6ubgia8B+6GsdbCANBah3BQp6BJMuTttera3RSEMs54oMSKageSjPRcA2qq30lCtyoZF70QWLHJFJFXvdryAIf4ut7rMTd0TJyJnH9qYDIHdpIK+W8yW0JzANnvVfnXEuRxNlpJcSB/Ui1VGp+weCpP+q2vYh52mZ/qsTWA9HiUAOZXH0GtWay03Mv3VYoHQ== 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=v1g3Jo0aXtmZEPoW5lGT8wMW/Oq60TpGaeBJJZQTyrc=; b=d5yQUAuU2nCxLVoIU0ESWN4eYyLlW4A7/9kkd8Txqh5fSm9AvEfymq8Ik78Avl67HH1KrFkT/MpKcQkexrI5hJ+V2NE+IwXula6h/HnnzNcahfZBLGFY+qccvaxCPKS6ymu4Ss0K3NDjeYJSeNAi/WSrUq6xMNx5RLe4k/iATP6RO1nmV74un7glh41qMk8amVR0x4+7DkugFxOill1jC2YtfRMAJM5LKjAIWW+AhiocS4HAg30AAzm7Uo19FxBDd/HXNbG42b6U47S0MG0t/KBD3VQY6cyX1TGCv6SYbmwuLGcoGuNQedgZfS2ky0Aij4HKcBB5MxcuVczJdkoAVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1g3Jo0aXtmZEPoW5lGT8wMW/Oq60TpGaeBJJZQTyrc=; b=WVxZLh1yi7A3NgzlMpXVKiDhRJqdya259IIyHK8J/Sx8uMRxYY3Ay672iti8nEDHjAfDxbPgnWdqKKpw8gWHSPC/99OnKwJYu2M8bXlBAiaVWzzFFITolQhThomRl6d1tWGbxK2Ih3kzTTVCWFa95/Z3KOf8j5NHiRtlSplrEN4= Authentication-Results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com; Received: from DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) by DM6PR04MB6362.namprd04.prod.outlook.com (2603:10b6:5:1e7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Sat, 10 Apr 2021 07:18:44 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::38c0:cc46:192b:1868]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::38c0:cc46:192b:1868%7]) with mapi id 15.20.4020.018; Sat, 10 Apr 2021 07:18:44 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 2/7] lib: sbi: Add sbi_domain_memregion_init() API Date: Sat, 10 Apr 2021 12:48:03 +0530 Message-Id: <20210410071808.759856-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210410071808.759856-1-anup.patel@wdc.com> References: <20210410071808.759856-1-anup.patel@wdc.com> X-Originating-IP: [122.179.48.237] X-ClientProxiedBy: MAXPR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::24) To DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.48.237) by MAXPR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:5d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Sat, 10 Apr 2021 07:18:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ac3087e-1d25-4eaa-977b-08d8fbf0dfe1 X-MS-TrafficTypeDiagnostic: DM6PR04MB6362: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R8ojWht1oYiPETOxht0OSPgGfI90Ja4l+IleyazxaPF7WI/GOPxts2EtGAjLzJpoyeptObz8DtPhVMMxVlYXXY5mTNmjMjdD5zAOUkYWu7C3foVOfrdiQQAiI/EnSSul5qxJcXkmF94fnhDmMeixTkszHLbUgD206Tb8a3MWDqVx0xAtWqQHrjIPFTvpZH6b18t/Xv23strH5exSu8NFWiWcj+C/cdDdgyX+0KxVt7EdMj7lQTFqoVzzyktM0yVVZFcQVPLP+iib+2l39A6uK6sl6htbl9lTXN2P6Z9Enz2m5JDtVZQVTsNzKnsxVhFSuzyUHY9Vp1dSgsKb7pZrUzE+AyauGISrnYruCHjpzZZ5LlXfmSFFQrARE/InUJTxkIoCaX/HrL6ipCmb+4TblQ07aqFJA+8zKFSt7pd/c1Qcv1OmsCanMDhnSFQQNyXfQ1wCNJ0rDQSG71R9y/nZsozW88Tef9objEP6If7N+zjptCde/A+2unYnNfwY45+ftivEccsa1Wwv2n31flHj9gXWLc3QoZ6u1Bf5/YLBF0GIaw2EacOepvby85D3drnOD1e7WGD3E3oGwpwU9xunYyOyCJNGIx+M+quE1dSzCvupgKY1gbbt0R6c/O2uvWbgX/S3F6MpNthz+FFo1f1YZsad+mn8H8ESIsmy/+6yozQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR04MB6201.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(366004)(346002)(136003)(39860400002)(110136005)(8936002)(83380400001)(8676002)(38100700002)(8886007)(54906003)(4326008)(316002)(38350700002)(52116002)(2906002)(186003)(16526019)(1076003)(55016002)(6636002)(26005)(66556008)(86362001)(66476007)(6666004)(44832011)(5660300002)(66946007)(36756003)(2616005)(7696005)(956004)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Lx6CoaWxcDzmAfULDF5tyCRVVRGBJ98cILApvVKBqjtdFRPyKvfhI6Y6Hd0oV+hHB7DrIV6Ub8vifyteinQCvV6O0kdKbHukMfDZPlID/FHAfiWSck7r11JtOj8d2pQW88a8g8vDqwx/k4PrwyJacZSzrmR4g5g08ZgvLBKe2I5kDrJd/cGklHyZhRwTz9K6SHgqa4M/TY/YR6jz5QxHGehG1VB77HyKTsYFW21QvAvxU0W5YMi3tG4ZzpAaccna1iqq8fcANXBfvgXqDamuGo1/AY9QUburoDXC/ymMaL2RUspq+sJ4NRpfm7bXOu+TwGSt3QkQCXVjeHZIFF5KStqbS2kLaq0FxI7NefoztsG+69CH+v6/c+68cwGPskv7XwbeXI9XQSVvt1G6bJtTJoQjoDpFq94KWWR4a3/MvYkcufDK7zsD5H/2ojMVRMS0Yfv8w8Y7UwnBtFX/8bIikhwlIZN1VH2R5NxeKuzV00qZNulr8O5Va1cpqyx//JsfaInjzuX+t49nrgvwYvAC87mew9ChKt48eBT9d5DQ4BejMmIpuSDDL9CDs37qX8n5Vp/GgQI7hd7C/NttM5pWqiWGHLPzaKnXJEP9s093lUA2KLrZo8SCo913DdNyw78d0aaNColnb7nIWT5v+nO8bF/f6CcD7tDwYndSo55TybipmFob014EgHx0qt180rpvIOtByZEPRLyJZhTjcEt2HgcdQnrMxSWM5C6MlmuXTjpGsGKegLnLACz2dhhadZyxRyuA9k5RbD/WsKnq9wYxxUkmZZYzeavaGNfw9ULf0GnXF40hQRjeMdnULoiCkUONfRrQsvvxz/4iLzJO3z5F+sSaY0qhOJ4bkA7TJO0I8yqbSxq8ABqHDiuXwOcDxPGmtiBHweu48qxXzlqk0iloq/zLjM9vWxQBcEh6ExM9PYcQrllD5Li+8enxH6mpmpEGhtOuobGkyvpN8nwKPfuqUD3JvHHclbO0u6eWeGfJzyA5fj2EXLTGngsNUeQgSwOO8/fXCudQZN3taM3cg35RlgYIaOm2CYMdcNStfprFwVbvMdmOMaGpp1G/FNT1Xk4vDjln9z3B6Wk1SWaH1Z2WatE0gUk9CeuT6qB4crQ+PG6Sj6j8IA/eNup8erzzyuB1oR5Cqn5v88ZKYRvCCbGqPoVNcGpmgeuSy3T4QWwI5tR70YXjdkR4xd96uh+f4OLKs2taQqw2Dl8814MCo/FqO+MkOSN6c9jzb0lTPm50BIULdOOXjK2kNAdDTGg0FrYILopBT/YF0RppGtflEC9Ujg98fRiGsCzSGe2gjzAAhqt9DdNEZvPFrxPXBaSiOBRA X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ac3087e-1d25-4eaa-977b-08d8fbf0dfe1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2021 07:18:44.1490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: q53CUFIji7n1/pvqY8O2YZMef7k1COa1zS1WT55MICZwI763DjXFmv06oPSGdBBIZscC7op6ltmjP+B0p5kRVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6362 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210410_001845_291103_4C614B01 X-CRM114-Status: GOOD ( 16.14 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This patch adds sbi_domain_memregion_init() helper API which can be used by platform support to initialize a domain memory region before adding it to the root domain. Signed-off-by: Anup Patel --- include/sbi/sbi_domain.h | 14 +++++++++++++ lib/sbi/sbi_domain.c | 45 ++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 9 d [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.153.144 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds sbi_domain_memregion_init() helper API which can be used by platform support to initialize a domain memory region before adding it to the root domain. Signed-off-by: Anup Patel Reviewed-by: Xiang W Reviewed-by: Alistair Francis --- include/sbi/sbi_domain.h | 14 +++++++++++++ lib/sbi/sbi_domain.c | 45 ++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index 1f8b942..f9f4f7d 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -127,6 +127,20 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, /** Initialize a domain memory region as firmware region */ void sbi_domain_memregion_initfw(struct sbi_domain_memregion *reg); +/** + * Initialize a domain memory region based on it's physical + * address and size. + * + * @param addr start physical address of memory region + * @param size physical size of memory region + * @param flags memory region flags + * @param reg pointer to memory region being initialized + */ +void sbi_domain_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_domain_memregion *reg); + /** * Check whether we can access specified address for given mode and * memory region flags under a domain diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 2849241..164f35c 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -72,6 +72,35 @@ void sbi_domain_memregion_initfw(struct sbi_domain_memregion *reg) sbi_memcpy(reg, &root_memregs[ROOT_FW_REGION], sizeof(*reg)); } +void sbi_domain_memregion_init(unsigned long addr, + unsigned long size, + unsigned long flags, + struct sbi_domain_memregion *reg) +{ + unsigned long base = 0, order; + + for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { + if (order < __riscv_xlen) { + base = addr & ~((1UL << order) - 1UL); + if ((base <= addr) && + (addr < (base + (1UL << order))) && + (base <= (addr + size - 1UL)) && + ((addr + size - 1UL) < (base + (1UL << order)))) + break; + } else { + base = 0; + break; + } + + } + + if (reg) { + reg->base = base; + reg->order = order; + reg->flags = flags; + } +} + bool sbi_domain_check_addr(const struct sbi_domain *dom, unsigned long addr, unsigned long mode, unsigned long access_flags) @@ -507,17 +536,15 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) const struct sbi_platform *plat = sbi_platform_ptr(scratch); /* Root domain firmware memory region */ - root_memregs[ROOT_FW_REGION].order = log2roundup(scratch->fw_size); - root_memregs[ROOT_FW_REGION].base = scratch->fw_start & - ~((1UL << root_memregs[0].order) - 1UL); - root_memregs[ROOT_FW_REGION].flags = 0; + sbi_domain_memregion_init(scratch->fw_start, scratch->fw_size, 0, + &root_memregs[ROOT_FW_REGION]); /* Root domain allow everything memory region */ - root_memregs[ROOT_ALL_REGION].order = __riscv_xlen; - root_memregs[ROOT_ALL_REGION].base = 0; - root_memregs[ROOT_ALL_REGION].flags = (SBI_DOMAIN_MEMREGION_READABLE | - SBI_DOMAIN_MEMREGION_WRITEABLE | - SBI_DOMAIN_MEMREGION_EXECUTABLE); + sbi_domain_memregion_init(0, ~0UL, + (SBI_DOMAIN_MEMREGION_READABLE | + SBI_DOMAIN_MEMREGION_WRITEABLE | + SBI_DOMAIN_MEMREGION_EXECUTABLE), + &root_memregs[ROOT_ALL_REGION]); /* Root domain memory region end */ root_memregs[ROOT_END_REGION].order = 0;