From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856830; cv=pass; d=zohomail.com; s=zohoarc; b=DocR4qh4uXyKY5ak8podQLLVOepn9SVwD2OBTebFLSGcW4kT8VsPRyB+6eyeRx1XkDQH+64WavGpx/9hYaLszzhYxl/YuXdbXVUL28gn+TKu86KhBjQqPpaSelXCytlbVl8CUhsRS78SBFU9349nKb5DKxZ65ncGBit3WT7J0zE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856830; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yAhR2Zlw0BJPaDHAcxcm0lDMM1//D50nWYatagZ/iX4=; b=kI0LR+0DQ7UVY8zEU++YgYCv3mXi1cH37WFxPgl/6kXkvfBpmdgRWXi297cgunVI6refgWJgJHLMnfK+fCTKBrTrxffZQHlhvnsb9+qxqn8NeVe4VCA+c7ZOjVQ8QHV4S0sqLBJBoUjRDY72Q7nI38/dXOlYZuCsKPnHiECscTI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856830873243.5336926905993; Thu, 16 Sep 2021 22:33:50 -0700 (PDT) Received: from localhost ([::1]:52228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6VR-0008Bd-Oo for importer@patchew.org; Fri, 17 Sep 2021 01:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MN-0002xh-SM; Fri, 17 Sep 2021 01:24:27 -0400 Received: from mail-mw2nam12on2066.outbound.protection.outlook.com ([40.107.244.66]:25281 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6M5-0005sx-8A; Fri, 17 Sep 2021 01:24:26 -0400 Received: from DM3PR12CA0062.namprd12.prod.outlook.com (2603:10b6:0:56::30) by DM5PR02MB2697.namprd02.prod.outlook.com (2603:10b6:3:109::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 05:24:03 +0000 Received: from DM3NAM02FT037.eop-nam02.prod.protection.outlook.com (2603:10b6:0:56:cafe::d1) by DM3PR12CA0062.outlook.office365.com (2603:10b6:0:56::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:03 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT037.mail.protection.outlook.com (10.13.4.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:02 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:00 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-QB; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OMsqpFQyLJoG1qtC5PFH1Gk07FPxujbDf1NvCwV7uEnu8N6W28qLHldynswph1w3wzS8IgZ4s5dY1GFR6R1yh0qaHFjE7uJYTnRYgwyLHNsBVYPBbVD57BxTzycILwyYjYqFxEhdmZq+w1hsl6aDc7fEG9fFNNx/1JWAdSNwfAwWCZNbZc4Fo6Cqm9bFlhl2we3Wz6qLBt4BGCw79elrm9VyrYXih9jOSYorhy9fd0ZMyf3kUnGjVFHKEjZVWvIm8VfU9owsKcwOZSuZdiWtMZ3OqWt49y2p34wTAatbseBusNgiLAgJGzx8JS6Kh9gz320cXU9Ov4xj5Av1ZUVzCw== 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; bh=yAhR2Zlw0BJPaDHAcxcm0lDMM1//D50nWYatagZ/iX4=; b=OS9Sl+8m09DvOVtskEKdHjWUF34suh+4L0Fy2RgoAh2gkHJBmRHAWEzFoOkQN7A+Zdwozn+VGX+c/PYZQB5j/8CQucn1LfmGAHX0BQBDo4tHD7IhlGDpku8MaKELme0f9agbncBBhiicPOq9mqe+GcAMtR9V5svDKh+h30LJeEtizWdalfc0yJvsN/MWTIr2AQfrNUCseQwwiAvXSINwrlaizR7e2/zlhZ0NbhA/HF7Twxa4kJtR6XVdM+xZvsYmTSe7NXePjQ2z0FYFO0LRCvNRYhYxRjihSgSA9v4sgMR2uO8AHfTOkuc3pfRRIRPOKftAmM+ukCQlytmPrAezVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yAhR2Zlw0BJPaDHAcxcm0lDMM1//D50nWYatagZ/iX4=; b=Pg8vJL+InKYL4OmKZO4gkXuGOYNJ5cxsEkDpww8Rb0ViAozFvQN4/SZJIWmp/7S3nqVT3cifrS/MRZkBrr6Ai13Il6gPjejetcnSZWEGPv4IJpTeMbn1OC27b7itA7WCinFOm+DF04FNqL7bbdQ4WjTXHfg7OZ2sVHCCqn9X8XI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 1/9] hw/nvram: Introduce Xilinx eFuse QOM Date: Thu, 16 Sep 2021 22:23:52 -0700 Message-ID: <20210917052400.1249094-2-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 259e2ca4-4aee-4f50-1585-08d9799b5ca5 X-MS-TrafficTypeDiagnostic: DM5PR02MB2697: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WayVAF4HFFqnYDQmMRFL0NHCg93NOrB4YYAepInaNH13Le3gEouinoCuB32uIe4Ac2iOlChLPIMkGKkK7vDF1nkNtL6twuDKsxLElCLjPPTQT+gKj1xX3ryB+TIrui+/nDoLfOQVVsvpTfxFrkWKPF4LZEoTJjWtBnVWwc+P8+Jwq5IKH4vIQPzyzghXmXChyVgRKx3MWOWOJ6upROLD8WPqrlrwQCmPhhor1wgM+o2BOkGVj1VpbGZbGp1XdwT8k95RaLc34DMv1x9FbG49sAa2CZoQiNqhNesuXFENHxfDSN9oLSxWBib8YZBxTTxLyreGyTFE3zymbBt8th3V+4M+XNo+SnQUhDbqeL2cPbMELHGEcU7YFogsxaCZEE1BM7bR+PmcD2S6w5khOqSZQLDDtXeA+/2EvCbVgz1mT8Tc0ZsooH4x7ylEkR9L+cY5X0f9vImplv48IQRXg79YVx/EYt6MaxYvIQMbEn1NWX28Ei/EejbDBFjKyhneckjc4ngLlIKyQjcnWDLXxTtaP187EtlcJwx574I/o/OUuXwofScjQSnLSen+wSpkbz1J8xfZvThsBqENKHPWsB2Yfwvz4KbcaumD4ZeMtwTE00ac9Czq+tfnsGOY84Zr6bqWHpmQ3WIOP4iYhB2E+N/aOL8DdVvpy3IJndUnGetjhTmbav5SdWQp5T5zjQhSfC0Vj6ZsS6gGPinvBD0it0FdX6cgFNSzSFT+A4yb/tfJBg0SxGd60SjqyRLvNiPiCi62q5tT6c9SAggkZfnEQJsSWq7cIdp/sYSr1grNVXnFgCMSmRSD2PbKfM78gl12Pl2B6Z6MDXPG0bgYLHsqDkETzlBSkmcrgXCG4MZ3LhdF8eY= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(396003)(376002)(346002)(39860400002)(136003)(36840700001)(46966006)(1076003)(336012)(70586007)(107886003)(70206006)(426003)(2616005)(47076005)(83380400001)(44832011)(36756003)(82310400003)(36860700001)(478600001)(8936002)(7696005)(30864003)(36906005)(8676002)(2906002)(6916009)(356005)(4326008)(9786002)(7636003)(966005)(54906003)(5660300002)(26005)(186003)(316002)(6666004)(82740400003)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:02.9930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 259e2ca4-4aee-4f50-1585-08d9799b5ca5 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT037.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB2697 Received-SPF: pass client-ip=40.107.244.66; envelope-from=tongh@xilinx.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856833213100001 Content-Type: text/plain; charset="utf-8" This introduces the QOM for Xilinx eFuse, an one-time field-programmable storage bit array. The actual mmio interface to the array varies by device families and will be provided in different change-sets. Co-authored-by: Edgar E. Iglesias Co-authored-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Sai Pavan Boddu Signed-off-by: Tong Ho --- hw/nvram/Kconfig | 7 + hw/nvram/meson.build | 2 + hw/nvram/xlnx-efuse-crc.c | 119 +++++++++++++++ hw/nvram/xlnx-efuse.c | 280 ++++++++++++++++++++++++++++++++++ include/hw/nvram/xlnx-efuse.h | 132 ++++++++++++++++ 5 files changed, 540 insertions(+) create mode 100644 hw/nvram/xlnx-efuse-crc.c create mode 100644 hw/nvram/xlnx-efuse.c create mode 100644 include/hw/nvram/xlnx-efuse.h diff --git a/hw/nvram/Kconfig b/hw/nvram/Kconfig index e872fcb194..252251f366 100644 --- a/hw/nvram/Kconfig +++ b/hw/nvram/Kconfig @@ -15,3 +15,10 @@ config NMC93XX_EEPROM =20 config CHRP_NVRAM bool + +config XLNX_EFUSE_CRC + bool + +config XLNX_EFUSE + bool + select XLNX_EFUSE_CRC diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build index fd2951a860..623c94efff 100644 --- a/hw/nvram/meson.build +++ b/hw/nvram/meson.build @@ -9,5 +9,7 @@ softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom= _at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_CRC', if_true: files('xlnx-efuse-c= rc.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files('xlnx-efuse.c')) =20 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) diff --git a/hw/nvram/xlnx-efuse-crc.c b/hw/nvram/xlnx-efuse-crc.c new file mode 100644 index 0000000000..5a5cc13f39 --- /dev/null +++ b/hw/nvram/xlnx-efuse-crc.c @@ -0,0 +1,119 @@ +/* + * Xilinx eFuse/bbram CRC calculator + * + * Copyright (c) 2021 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-efuse.h" + +static uint32_t xlnx_efuse_u37_crc(uint32_t prev_crc, uint32_t data, + uint32_t addr) +{ + /* A table for 7-bit slicing */ + static const uint32_t crc_tab[128] =3D { + 0x00000000, 0xe13b70f7, 0xc79a971f, 0x26a1e7e8, + 0x8ad958cf, 0x6be22838, 0x4d43cfd0, 0xac78bf27, + 0x105ec76f, 0xf165b798, 0xd7c45070, 0x36ff2087, + 0x9a879fa0, 0x7bbcef57, 0x5d1d08bf, 0xbc267848, + 0x20bd8ede, 0xc186fe29, 0xe72719c1, 0x061c6936, + 0xaa64d611, 0x4b5fa6e6, 0x6dfe410e, 0x8cc531f9, + 0x30e349b1, 0xd1d83946, 0xf779deae, 0x1642ae59, + 0xba3a117e, 0x5b016189, 0x7da08661, 0x9c9bf696, + 0x417b1dbc, 0xa0406d4b, 0x86e18aa3, 0x67dafa54, + 0xcba24573, 0x2a993584, 0x0c38d26c, 0xed03a29b, + 0x5125dad3, 0xb01eaa24, 0x96bf4dcc, 0x77843d3b, + 0xdbfc821c, 0x3ac7f2eb, 0x1c661503, 0xfd5d65f4, + 0x61c69362, 0x80fde395, 0xa65c047d, 0x4767748a, + 0xeb1fcbad, 0x0a24bb5a, 0x2c855cb2, 0xcdbe2c45, + 0x7198540d, 0x90a324fa, 0xb602c312, 0x5739b3e5, + 0xfb410cc2, 0x1a7a7c35, 0x3cdb9bdd, 0xdde0eb2a, + 0x82f63b78, 0x63cd4b8f, 0x456cac67, 0xa457dc90, + 0x082f63b7, 0xe9141340, 0xcfb5f4a8, 0x2e8e845f, + 0x92a8fc17, 0x73938ce0, 0x55326b08, 0xb4091bff, + 0x1871a4d8, 0xf94ad42f, 0xdfeb33c7, 0x3ed04330, + 0xa24bb5a6, 0x4370c551, 0x65d122b9, 0x84ea524e, + 0x2892ed69, 0xc9a99d9e, 0xef087a76, 0x0e330a81, + 0xb21572c9, 0x532e023e, 0x758fe5d6, 0x94b49521, + 0x38cc2a06, 0xd9f75af1, 0xff56bd19, 0x1e6dcdee, + 0xc38d26c4, 0x22b65633, 0x0417b1db, 0xe52cc12c, + 0x49547e0b, 0xa86f0efc, 0x8ecee914, 0x6ff599e3, + 0xd3d3e1ab, 0x32e8915c, 0x144976b4, 0xf5720643, + 0x590ab964, 0xb831c993, 0x9e902e7b, 0x7fab5e8c, + 0xe330a81a, 0x020bd8ed, 0x24aa3f05, 0xc5914ff2, + 0x69e9f0d5, 0x88d28022, 0xae7367ca, 0x4f48173d, + 0xf36e6f75, 0x12551f82, 0x34f4f86a, 0xd5cf889d, + 0x79b737ba, 0x988c474d, 0xbe2da0a5, 0x5f16d052 + }; + + /* + * eFuse calculation is shown here: + * https://github.com/Xilinx/embeddedsw/blob/release-2019.2/lib/sw_se= rvices/xilskey/src/xilskey_utils.c#L1496 + * + * Each u32 word is appended a 5-bit value, for a total of 37 bits; se= e: + * https://github.com/Xilinx/embeddedsw/blob/release-2019.2/lib/sw_se= rvices/xilskey/src/xilskey_utils.c#L1356 + */ + uint32_t crc =3D prev_crc; + const unsigned rshf =3D 7; + const uint32_t im =3D (1 << rshf) - 1; + const uint32_t rm =3D (1 << (32 - rshf)) - 1; + const uint32_t i2 =3D (1 << 2) - 1; + const uint32_t r2 =3D (1 << 30) - 1; + + unsigned j; + uint32_t i, r; + uint64_t w; + + w =3D (uint64_t)(addr) << 32; + w |=3D data; + + /* Feed 35 bits, in 5 rounds, each a slice of 7 bits */ + for (j =3D 0; j < 5; j++) { + r =3D rm & (crc >> rshf); + i =3D im & (crc ^ w); + crc =3D crc_tab[i] ^ r; + + w >>=3D rshf; + } + + /* Feed the remaining 2 bits */ + r =3D r2 & (crc >> 2); + i =3D i2 & (crc ^ w); + crc =3D crc_tab[i << (rshf - 2)] ^ r; + + return crc; +} + +uint32_t xlnx_efuse_calc_crc(const uint32_t *data, unsigned u32_cnt, + unsigned zpads) +{ + uint32_t crc =3D 0; + unsigned index; + + for (index =3D zpads; index; index--) { + crc =3D xlnx_efuse_u37_crc(crc, 0, (index + u32_cnt)); + } + + for (index =3D u32_cnt; index; index--) { + crc =3D xlnx_efuse_u37_crc(crc, data[index - 1], index); + } + + return crc; +} diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c new file mode 100644 index 0000000000..ee1caab54c --- /dev/null +++ b/hw/nvram/xlnx-efuse.c @@ -0,0 +1,280 @@ +/* + * QEMU model of the EFUSE eFuse + * + * Copyright (c) 2015 Xilinx Inc. + * + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-efuse.h" + +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "sysemu/blockdev.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" + +#define TBIT0_OFFSET 28 +#define TBIT1_OFFSET 29 +#define TBIT2_OFFSET 30 +#define TBIT3_OFFSET 31 +#define TBITS_PATTERN (0x0AU << TBIT0_OFFSET) +#define TBITS_MASK (0x0FU << TBIT0_OFFSET) + +bool xlnx_efuse_get_bit(XlnxEFuse *s, unsigned int bit) +{ + bool b =3D s->fuse32[bit / 32] & (1 << (bit % 32)); + return b; +} + +static int efuse_bytes(XlnxEFuse *s) +{ + return ROUND_UP((s->efuse_nr * s->efuse_size) / 8, 4); +} + +static int efuse_bdrv_read(XlnxEFuse *s, Error **errp) +{ + uint32_t *ram =3D s->fuse32; + int nr =3D efuse_bytes(s); + + if (!s->blk) { + return 0; + } + + s->blk_ro =3D !blk_supports_write_perm(s->blk); + if (!s->blk_ro) { + int rc; + + rc =3D blk_set_perm(s->blk, + (BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE), + BLK_PERM_ALL, NULL); + if (rc) { + s->blk_ro =3D true; + } + } + if (s->blk_ro) { + warn_report("%s: Skip saving updates to read-only eFUSE backstore.= ", + blk_name(s->blk)); + } + + if (blk_pread(s->blk, 0, ram, nr) < 0) { + error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore= .", + blk_name(s->blk), nr); + return -1; + } + + /* Convert from little-endian backstore for each 32-bit row */ + nr /=3D 4; + while (nr--) { + ram[nr] =3D le32_to_cpu(ram[nr]); + } + + return 0; +} + +static void efuse_bdrv_sync(XlnxEFuse *s, unsigned int bit) +{ + unsigned int row_offset; + uint32_t le32; + + if (!s->blk || s->blk_ro) { + return; /* Silent on read-only backend to avoid message flood */ + } + + /* Backstore is always in little-endian */ + le32 =3D cpu_to_le32(xlnx_efuse_get_row(s, bit)); + + row_offset =3D (bit / 32) * 4; + if (blk_pwrite(s->blk, row_offset, &le32, 4, 0) < 0) { + error_report("%s: Failed to write offset %u of eFUSE backstore.", + blk_name(s->blk), row_offset); + } +} + +static int efuse_ro_bits_cmp(const void *a, const void *b) +{ + uint32_t i =3D *(const uint32_t *)a; + uint32_t j =3D *(const uint32_t *)b; + + return (i > j) - (i < j); +} + +static void efuse_ro_bits_sort(XlnxEFuse *s) +{ + uint32_t *ary =3D s->ro_bits; + const uint32_t cnt =3D s->ro_bits_cnt; + + if (ary && cnt > 1) { + qsort(ary, cnt, sizeof(ary[0]), efuse_ro_bits_cmp); + } +} + +static bool efuse_ro_bits_find(XlnxEFuse *s, uint32_t k) +{ + const uint32_t *ary =3D s->ro_bits; + const uint32_t cnt =3D s->ro_bits_cnt; + + if (!ary || !cnt) { + return false; + } + + return bsearch(&k, ary, cnt, sizeof(ary[0]), efuse_ro_bits_cmp) !=3D N= ULL; +} + +bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit) +{ + if (efuse_ro_bits_find(s, bit)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: WARN: " + "Ignored setting of readonly efuse bit<%u,%u>!\n", + object_get_canonical_path(OBJECT(s)), + (bit / 32), (bit % 32)); + return false; + } + + s->fuse32[bit / 32] |=3D 1 << (bit % 32); + efuse_bdrv_sync(s, bit); + return true; +} + +bool xlnx_efuse_k256_check(XlnxEFuse *s, uint32_t crc, unsigned start) +{ + uint32_t calc; + + /* A key always occupies multiple of whole rows */ + assert((start % 32) =3D=3D 0); + + calc =3D xlnx_efuse_calc_crc(&s->fuse32[start / 32], (256 / 32), 0); + return calc =3D=3D crc; +} + +uint32_t xlnx_efuse_tbits_check(XlnxEFuse *s) +{ + int nr; + uint32_t check =3D 0; + + for (nr =3D s->efuse_nr; nr-- > 0; ) { + int efuse_start_row_num =3D (s->efuse_size * nr) / 32; + uint32_t data =3D s->fuse32[efuse_start_row_num]; + + /* + * If the option is on, auto-init blank T-bits. + * (non-blank will still be reported as '0' in the check, e.g., + * for error-injection tests) + */ + if ((data & TBITS_MASK) =3D=3D 0 && s->init_tbits) { + data |=3D TBITS_PATTERN; + + s->fuse32[efuse_start_row_num] =3D data; + efuse_bdrv_sync(s, (efuse_start_row_num * 32 + TBIT0_OFFSET)); + } + + check =3D (check << 1) | ((data & TBITS_MASK) =3D=3D TBITS_PATTERN= ); + } + + return check; +} + +static void efuse_realize(DeviceState *dev, Error **errp) +{ + XlnxEFuse *s =3D XLNX_EFUSE(dev); + + /* Sort readonly-list for bsearch lookup */ + efuse_ro_bits_sort(s); + + if ((s->efuse_size % 32) !=3D 0) { + error_setg(errp, + "%s.efuse-size: %u: property value not multiple of 32.", + object_get_canonical_path(OBJECT(dev)), s->efuse_size); + return; + } + + s->fuse32 =3D g_malloc0(efuse_bytes(s)); + if (efuse_bdrv_read(s, errp)) { + g_free(s->fuse32); + } +} + +static void efuse_prop_set_drive(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + + qdev_prop_drive.set(obj, v, name, opaque, errp); + + /* Fill initial data if backend is attached after realized */ + if (dev->realized) { + efuse_bdrv_read(XLNX_EFUSE(obj), errp); + } +} + +static void efuse_prop_get_drive(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + qdev_prop_drive.get(obj, v, name, opaque, errp); +} + +static void efuse_prop_release_drive(Object *obj, const char *name, + void *opaque) +{ + qdev_prop_drive.release(obj, name, opaque); +} + +static const PropertyInfo efuse_prop_drive =3D { + .name =3D "str", + .description =3D "Node name or ID of a block device to use as eFUSE ba= ckend", + .realized_set_allowed =3D true, + .get =3D efuse_prop_get_drive, + .set =3D efuse_prop_set_drive, + .release =3D efuse_prop_release_drive, +}; + +static Property efuse_properties[] =3D { + DEFINE_PROP("drive", XlnxEFuse, blk, efuse_prop_drive, BlockBackend *), + DEFINE_PROP_UINT8("efuse-nr", XlnxEFuse, efuse_nr, 3), + DEFINE_PROP_UINT32("efuse-size", XlnxEFuse, efuse_size, 64 * 32), + DEFINE_PROP_BOOL("init-factory-tbits", XlnxEFuse, init_tbits, true), + DEFINE_PROP_ARRAY("read-only", XlnxEFuse, ro_bits_cnt, ro_bits, + qdev_prop_uint32, uint32_t), + DEFINE_PROP_END_OF_LIST(), +}; + +static void efuse_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D efuse_realize; + device_class_set_props(dc, efuse_properties); +} + +static const TypeInfo efuse_info =3D { + .name =3D TYPE_XLNX_EFUSE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(XlnxEFuse), + .class_init =3D efuse_class_init, +}; + +static void efuse_register_types(void) +{ + type_register_static(&efuse_info); +} +type_init(efuse_register_types) diff --git a/include/hw/nvram/xlnx-efuse.h b/include/hw/nvram/xlnx-efuse.h new file mode 100644 index 0000000000..58414e468b --- /dev/null +++ b/include/hw/nvram/xlnx-efuse.h @@ -0,0 +1,132 @@ +/* + * QEMU model of the Xilinx eFuse core + * + * Copyright (c) 2015 Xilinx Inc. + * + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef XLNX_EFUSE_H +#define XLNX_EFUSE_H + +#include "sysemu/block-backend.h" +#include "hw/qdev-core.h" + +#define TYPE_XLNX_EFUSE "xlnx,efuse" +OBJECT_DECLARE_SIMPLE_TYPE(XlnxEFuse, XLNX_EFUSE); + +struct XlnxEFuse { + DeviceState parent_obj; + BlockBackend *blk; + bool blk_ro; + uint32_t *fuse32; + + DeviceState *dev; + + bool init_tbits; + + uint8_t efuse_nr; + uint32_t efuse_size; + + uint32_t *ro_bits; + uint32_t ro_bits_cnt; +}; + +/** + * xlnx_efuse_calc_crc: + * @data: an array of 32-bit words for which the CRC should be computed + * @u32_cnt: the array size in number of 32-bit words + * @zpads: the number of 32-bit zeros prepended to @data before computation + * + * This function is used to compute the CRC for an array of 32-bit words, + * using a Xilinx-specific data padding. + * + * Returns: the computed 32-bit CRC + */ +uint32_t xlnx_efuse_calc_crc(const uint32_t *data, unsigned u32_cnt, + unsigned zpads); + +/** + * xlnx_efuse_get_bit: + * @s: the efuse object + * @bit: the efuse bit-address to read the data + * + * Returns: the bit, 0 or 1, at @bit of object @s + */ +bool xlnx_efuse_get_bit(XlnxEFuse *s, unsigned int bit); + +/** + * xlnx_efuse_set_bit: + * @s: the efuse object + * @bit: the efuse bit-address to be written a value of 1 + * + * Returns: true on success, false on failure + */ +bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit); + +/** + * xlnx_efuse_k256_check: + * @s: the efuse object + * @crc: the 32-bit CRC to be compared with + * @start: the efuse bit-address (which must be multiple of 32) of the + * start of a 256-bit array + * + * This function computes the CRC of a 256-bit array starting at @start + * then compares to the given @crc + * + * Returns: true of @crc =3D=3D computed, false otherwise + */ +bool xlnx_efuse_k256_check(XlnxEFuse *s, uint32_t crc, unsigned start); + +/** + * xlnx_efuse_tbits_check: + * @s: the efuse object + * + * This function inspects a number of efuse bits at specific addresses + * to see if they match a validation pattern. Each pattern is a group + * of 4 bits, and there are 3 groups. + * + * Returns: a 3-bit mask, where a bit of '1' means the corresponding + * group has a valid pattern. + */ +uint32_t xlnx_efuse_tbits_check(XlnxEFuse *s); + +/** + * xlnx_efuse_get_row: + * @s: the efuse object + * @bit: the efuse bit address for which a 32-bit value is read + * + * Returns: the entire 32 bits of the efuse, starting at a bit + * address that is multiple of 32 and contains the bit at @bit + */ +static inline uint32_t xlnx_efuse_get_row(XlnxEFuse *s, unsigned int bit) +{ + if (!(s->fuse32)) { + return 0; + } else { + unsigned int row_idx =3D bit / 32; + + assert(row_idx < (s->efuse_size * s->efuse_nr / 32)); + return s->fuse32[row_idx]; + } +} + +#endif --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856503; cv=pass; d=zohomail.com; s=zohoarc; b=f+8EzBRXnsLS4SCflJexbB0WQxtsylYVQHzt+oxz3YX7q4RB9e97x+ER/reYkTNJqwG5bnKhRYzcCAo/+qIwa8BFq4S5p82UnxiRQtXkyXEFkfVb6ATA991X2DpNeWf68G6c5+Wf170rvSSa9GjB/7poQ7k9C5jGeE7XSAdt7ns= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856503; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YeFbSDk9YUh3ya9cOo+hoROrf/dJPfjYa4pHLy2oQyg=; b=nNqFlPOLkKKQEiKuzsJzH0IM+gPLjCUG39Tef0o06up56XbjlgHFmYhaUxRGggk5dAYrM0Toftbr+cakPejN0PoFE1yyHiH++xyHNcAEkPMu/qTAtztAdvJRz5yR32s+b8u1wBVJxlfSeBmAWXvaI1MOOpVGCw6DO9JpLiuk+gs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856503236844.7445971832722; Thu, 16 Sep 2021 22:28:23 -0700 (PDT) Received: from localhost ([::1]:36538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6QA-0005y2-3W for importer@patchew.org; Fri, 17 Sep 2021 01:28:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MA-0002OB-7P; Fri, 17 Sep 2021 01:24:14 -0400 Received: from mail-bn8nam08on2044.outbound.protection.outlook.com ([40.107.100.44]:58336 helo=NAM04-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6M5-0005tw-2p; Fri, 17 Sep 2021 01:24:13 -0400 Received: from BN0PR04CA0020.namprd04.prod.outlook.com (2603:10b6:408:ee::25) by CH2PR02MB6136.namprd02.prod.outlook.com (2603:10b6:610:8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 05:24:03 +0000 Received: from BN1NAM02FT028.eop-nam02.prod.protection.outlook.com (2603:10b6:408:ee:cafe::5d) by BN0PR04CA0020.outlook.office365.com (2603:10b6:408:ee::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:03 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT028.mail.protection.outlook.com (10.13.2.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:02 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:00 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-RI; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FPCgHnuMUr6bIAd/EqPr4P75o7jwllg7Z6wlnQAgmEQ2Hh7Ce1b3FupleUPnIqlGaaopCmJ7RokvgxyFnQzeoSn85DuMjGBSzEwPj4I+ei/nWMMfT5b0mIi4xx6JAApj6FD8xX6MoJhQF3MMGx3Ll9xbijUASsJrZr/ZL2TPoYjqs97KqTZGMRPJIA1ABbrmr+4RIH4BEALdWN3ngKalKeZDrCIeVJd5oKWCUNCfywtclqLWKeF73ELgwFvI4PhK903foj8biBkEZ5hemQ8sQQneo5V8jbeIJUWJ29w4c72BJ7U5iUDfHKN04FW6T9JO745HxVhWaJ3C1ACSD37fpQ== 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; bh=YeFbSDk9YUh3ya9cOo+hoROrf/dJPfjYa4pHLy2oQyg=; b=RiQfeZNu4OO+1IX6NIFt9bHDSCzZHUgitAw3DIE4Qmtio5eFdTKKR8FlJsmKkNOg+I0UJ4scRgd4+dA95l3a7ElInxI3UFhscGejeLGVC+qjH1hKwFVuy7futwKvl1xV3hl/7pJyh+wropuqeDlWg64Q8tRaQ4nJbzQZA/uABuCgFEWeg+chKEu2RisuqE1nLm1+3t1kBPqPloQJUbTIml9ecMfz0P7mW/B14UHbihbTfh8WAe+TVhbZdueM4Z/q5LoyeAX87A/bV27PbVQjzi/a3sGrZHGQaJx8fv7tGmplQgNr++o0syw0AiTQ3ZF1oo1jJNkwBcLp7bbbBp9Alg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YeFbSDk9YUh3ya9cOo+hoROrf/dJPfjYa4pHLy2oQyg=; b=JgoPwWUIL6oZo2G+3ZLRb8v96YtcF9KwXXdRcIeOclJI0fx9TNBSVQSIBteHPEHzhB8LzO4OvxKeZvQaXcrOau3TyPnJzEahbLLelXV8IUVodLMSkEdz3fvVSxfKrBreVIWn1BAWuFBuLP/glT2MpHCZOiLyekZironkFzDDN5Q= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 2/9] hw/nvram: Introduce Xilinx Versal eFuse device Date: Thu, 16 Sep 2021 22:23:53 -0700 Message-ID: <20210917052400.1249094-3-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c83c08c4-3253-4a7a-b1b9-08d9799b5ca9 X-MS-TrafficTypeDiagnostic: CH2PR02MB6136: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:281; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yLTakNG08ishz0kdKsjo77TkpRsyVNppByraJdrrh8BGVjiR/Azerip9Wrpf6FLTzLDDaPgBEA4v4AHmdr3+rDRytC0TO2uPuRXV1EJIYCwrwx+Wz0W6nOY2nMfO/qBXp4N6tXXg0WcuSsq8sFbkY8/NpH7FC5RD/0uvY/bXqF3E6VHKw77zg9cQX8Nw/13RW3Oq5K2E2xerITTYUc6MWdFbhtSV7xMSBpbzbggRk/56kPVADROmZaf7Q6wij5s8ARcv0M3UaCVPBNYqiqHJWfBE/QEru32Y75YkbKEew8VK2V9P+jctjXYIeATR3957MvGfUuYJwj+t9iWYroPacDy8WPXoUkGhqJyGg0NasBdWqPCpkg5R5iC4hkPSx6ivRJtkuLAO+/0ipnLsRjayYX+E6ZUbaL2nUG/apxpik72tSgFaZaQhB3+fMCrt33HXz0fq9N6EfFG3NHIkTufXWDU2REeC3HzhmBu8pknxAetdQmz77lDmQryib7Vv2hO8f5KtLSM6PS7KrMY4flfAeP44Q27gSdO9y7MBjR9wjOMNTNPRD+gzlMeZOgQP6tLUWlhMcO0bnK+wmRiA9A3QAIV5B8pFGEi9yAJVnrwRTmriB2ONzagWP4OWf65n14SxjyT1b/Wp9N7LASnI8KGCc1r4ugYsTZlC/IhUo/iqVZjsDC5IooOT0Jchkpy4qqh0bo2I06jtssndw/fNHSHG7RAw5A/Y0Aiw+kijiRYTj1EqhMb00L4qiUs0uMlZsQChsLtO7iC/iHAxrOuzQQlFN7STBO/T7BDmUnG7UTrz1ZGw7+bGtBwfZDx+5U4yH1EN X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch01.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(6916009)(30864003)(2906002)(8676002)(9786002)(356005)(4326008)(8936002)(7696005)(36906005)(316002)(6666004)(508600001)(83380400001)(26005)(966005)(54906003)(7636003)(5660300002)(186003)(1076003)(336012)(2616005)(426003)(70206006)(70586007)(107886003)(82310400003)(36860700001)(36756003)(44832011)(47076005)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:02.9673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c83c08c4-3253-4a7a-b1b9-08d9799b5ca9 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT028.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR02MB6136 Received-SPF: pass client-ip=40.107.100.44; envelope-from=tongh@xilinx.com; helo=NAM04-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856504340100001 Content-Type: text/plain; charset="utf-8" This implements the Xilinx Versal eFuse, an one-time field-programmable non-volatile storage device. There is only one such device in the Xilinx Versal product family. This device has two separate mmio interfaces, a controller and a flatten readback. The controller provides interfaces for field-programming, configuration, control, and status. The flatten readback is a cache to provide a byte-accessible read-only interface to efficiently read efuse array. Co-authored-by: Edgar E. Iglesias Co-authored-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Sai Pavan Boddu Signed-off-by: Tong Ho --- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 3 + hw/nvram/xlnx-versal-efuse-cache.c | 114 ++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 783 +++++++++++++++++++++++++++ include/hw/nvram/xlnx-versal-efuse.h | 68 +++ 5 files changed, 972 insertions(+) create mode 100644 hw/nvram/xlnx-versal-efuse-cache.c create mode 100644 hw/nvram/xlnx-versal-efuse-ctrl.c create mode 100644 include/hw/nvram/xlnx-versal-efuse.h diff --git a/hw/nvram/Kconfig b/hw/nvram/Kconfig index 252251f366..6c2bb5afe3 100644 --- a/hw/nvram/Kconfig +++ b/hw/nvram/Kconfig @@ -22,3 +22,7 @@ config XLNX_EFUSE_CRC config XLNX_EFUSE bool select XLNX_EFUSE_CRC + +config XLNX_EFUSE_VERSAL + bool + select XLNX_EFUSE diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build index 623c94efff..62352ad8ec 100644 --- a/hw/nvram/meson.build +++ b/hw/nvram/meson.build @@ -11,5 +11,8 @@ softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('np= cm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_CRC', if_true: files('xlnx-efuse-c= rc.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files('xlnx-efuse.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true: files( + 'xlnx-versal-efuse-cach= e.c', + 'xlnx-versal-efuse-ctrl= .c')) =20 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) diff --git a/hw/nvram/xlnx-versal-efuse-cache.c b/hw/nvram/xlnx-versal-efus= e-cache.c new file mode 100644 index 0000000000..eaec64d785 --- /dev/null +++ b/hw/nvram/xlnx-versal-efuse-cache.c @@ -0,0 +1,114 @@ +/* + * QEMU model of the EFuse_Cache + * + * Copyright (c) 2017 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-versal-efuse.h" + +#include "qemu/log.h" +#include "hw/qdev-properties.h" + +#define MR_SIZE 0xC00 + +static uint64_t efuse_cache_read(void *opaque, hwaddr addr, unsigned size) +{ + XlnxVersalEFuseCache *s =3D XLNX_VERSAL_EFUSE_CACHE(opaque); + unsigned int w0 =3D QEMU_ALIGN_DOWN(addr * 8, 32); + unsigned int w1 =3D QEMU_ALIGN_DOWN((addr + size - 1) * 8, 32); + + uint64_t ret; + + assert(w0 =3D=3D w1 || (w0 + 32) =3D=3D w1); + + ret =3D xlnx_versal_efuse_read_row(s->efuse, w1, NULL); + if (w0 < w1) { + ret <<=3D 32; + ret |=3D xlnx_versal_efuse_read_row(s->efuse, w0, NULL); + } + + /* If 'addr' unaligned, the guest is always assumed to be little-endia= n. */ + addr &=3D 3; + if (addr) { + ret >>=3D 8 * addr; + } + + return ret; +} + +static void efuse_cache_write(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + /* No Register Writes allowed */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: efuse cache registers are read-onl= y", + __func__); +} + +static const MemoryRegionOps efuse_cache_ops =3D { + .read =3D efuse_cache_read, + .write =3D efuse_cache_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + }, +}; + +static void efuse_cache_init(Object *obj) +{ + XlnxVersalEFuseCache *s =3D XLNX_VERSAL_EFUSE_CACHE(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->iomem, obj, &efuse_cache_ops, s, + TYPE_XLNX_VERSAL_EFUSE_CACHE, MR_SIZE); + sysbus_init_mmio(sbd, &s->iomem); +} + +static Property efuse_cache_props[] =3D { + DEFINE_PROP_LINK("efuse", + XlnxVersalEFuseCache, efuse, + TYPE_XLNX_EFUSE, XlnxEFuse *), + + DEFINE_PROP_END_OF_LIST(), +}; + +static void efuse_cache_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + device_class_set_props(dc, efuse_cache_props); +} + +static const TypeInfo efuse_cache_info =3D { + .name =3D TYPE_XLNX_VERSAL_EFUSE_CACHE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(XlnxVersalEFuseCache), + .class_init =3D efuse_cache_class_init, + .instance_init =3D efuse_cache_init, +}; + +static void efuse_cache_register_types(void) +{ + type_register_static(&efuse_cache_info); +} + +type_init(efuse_cache_register_types) diff --git a/hw/nvram/xlnx-versal-efuse-ctrl.c b/hw/nvram/xlnx-versal-efuse= -ctrl.c new file mode 100644 index 0000000000..d362376703 --- /dev/null +++ b/hw/nvram/xlnx-versal-efuse-ctrl.c @@ -0,0 +1,783 @@ +/* + * QEMU model of the Versal eFuse controller + * + * Copyright (c) 2020 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-versal-efuse.h" + +#include "qemu/log.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" + +#ifndef XLNX_VERSAL_EFUSE_CTRL_ERR_DEBUG +#define XLNX_VERSAL_EFUSE_CTRL_ERR_DEBUG 0 +#endif + +REG32(WR_LOCK, 0x0) + FIELD(WR_LOCK, LOCK, 0, 16) +REG32(CFG, 0x4) + FIELD(CFG, SLVERR_ENABLE, 5, 1) + FIELD(CFG, MARGIN_RD, 2, 1) + FIELD(CFG, PGM_EN, 1, 1) +REG32(STATUS, 0x8) + FIELD(STATUS, AES_USER_KEY_1_CRC_PASS, 11, 1) + FIELD(STATUS, AES_USER_KEY_1_CRC_DONE, 10, 1) + FIELD(STATUS, AES_USER_KEY_0_CRC_PASS, 9, 1) + FIELD(STATUS, AES_USER_KEY_0_CRC_DONE, 8, 1) + FIELD(STATUS, AES_CRC_PASS, 7, 1) + FIELD(STATUS, AES_CRC_DONE, 6, 1) + FIELD(STATUS, CACHE_DONE, 5, 1) + FIELD(STATUS, CACHE_LOAD, 4, 1) + FIELD(STATUS, EFUSE_2_TBIT, 2, 1) + FIELD(STATUS, EFUSE_1_TBIT, 1, 1) + FIELD(STATUS, EFUSE_0_TBIT, 0, 1) +REG32(EFUSE_PGM_ADDR, 0xc) + FIELD(EFUSE_PGM_ADDR, PAGE, 13, 4) + FIELD(EFUSE_PGM_ADDR, ROW, 5, 8) + FIELD(EFUSE_PGM_ADDR, COLUMN, 0, 5) +REG32(EFUSE_RD_ADDR, 0x10) + FIELD(EFUSE_RD_ADDR, PAGE, 13, 4) + FIELD(EFUSE_RD_ADDR, ROW, 5, 8) +REG32(EFUSE_RD_DATA, 0x14) +REG32(TPGM, 0x18) + FIELD(TPGM, VALUE, 0, 16) +REG32(TRD, 0x1c) + FIELD(TRD, VALUE, 0, 8) +REG32(TSU_H_PS, 0x20) + FIELD(TSU_H_PS, VALUE, 0, 8) +REG32(TSU_H_PS_CS, 0x24) + FIELD(TSU_H_PS_CS, VALUE, 0, 8) +REG32(TRDM, 0x28) + FIELD(TRDM, VALUE, 0, 8) +REG32(TSU_H_CS, 0x2c) + FIELD(TSU_H_CS, VALUE, 0, 8) +REG32(EFUSE_ISR, 0x30) + FIELD(EFUSE_ISR, APB_SLVERR, 31, 1) + FIELD(EFUSE_ISR, CACHE_PARITY_E2, 14, 1) + FIELD(EFUSE_ISR, CACHE_PARITY_E1, 13, 1) + FIELD(EFUSE_ISR, CACHE_PARITY_E0S, 12, 1) + FIELD(EFUSE_ISR, CACHE_PARITY_E0R, 11, 1) + FIELD(EFUSE_ISR, CACHE_APB_SLVERR, 10, 1) + FIELD(EFUSE_ISR, CACHE_REQ_ERROR, 9, 1) + FIELD(EFUSE_ISR, MAIN_REQ_ERROR, 8, 1) + FIELD(EFUSE_ISR, READ_ON_CACHE_LD, 7, 1) + FIELD(EFUSE_ISR, CACHE_FSM_ERROR, 6, 1) + FIELD(EFUSE_ISR, MAIN_FSM_ERROR, 5, 1) + FIELD(EFUSE_ISR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_ISR, RD_ERROR, 3, 1) + FIELD(EFUSE_ISR, RD_DONE, 2, 1) + FIELD(EFUSE_ISR, PGM_ERROR, 1, 1) + FIELD(EFUSE_ISR, PGM_DONE, 0, 1) +REG32(EFUSE_IMR, 0x34) + FIELD(EFUSE_IMR, APB_SLVERR, 31, 1) + FIELD(EFUSE_IMR, CACHE_PARITY_E2, 14, 1) + FIELD(EFUSE_IMR, CACHE_PARITY_E1, 13, 1) + FIELD(EFUSE_IMR, CACHE_PARITY_E0S, 12, 1) + FIELD(EFUSE_IMR, CACHE_PARITY_E0R, 11, 1) + FIELD(EFUSE_IMR, CACHE_APB_SLVERR, 10, 1) + FIELD(EFUSE_IMR, CACHE_REQ_ERROR, 9, 1) + FIELD(EFUSE_IMR, MAIN_REQ_ERROR, 8, 1) + FIELD(EFUSE_IMR, READ_ON_CACHE_LD, 7, 1) + FIELD(EFUSE_IMR, CACHE_FSM_ERROR, 6, 1) + FIELD(EFUSE_IMR, MAIN_FSM_ERROR, 5, 1) + FIELD(EFUSE_IMR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IMR, RD_ERROR, 3, 1) + FIELD(EFUSE_IMR, RD_DONE, 2, 1) + FIELD(EFUSE_IMR, PGM_ERROR, 1, 1) + FIELD(EFUSE_IMR, PGM_DONE, 0, 1) +REG32(EFUSE_IER, 0x38) + FIELD(EFUSE_IER, APB_SLVERR, 31, 1) + FIELD(EFUSE_IER, CACHE_PARITY_E2, 14, 1) + FIELD(EFUSE_IER, CACHE_PARITY_E1, 13, 1) + FIELD(EFUSE_IER, CACHE_PARITY_E0S, 12, 1) + FIELD(EFUSE_IER, CACHE_PARITY_E0R, 11, 1) + FIELD(EFUSE_IER, CACHE_APB_SLVERR, 10, 1) + FIELD(EFUSE_IER, CACHE_REQ_ERROR, 9, 1) + FIELD(EFUSE_IER, MAIN_REQ_ERROR, 8, 1) + FIELD(EFUSE_IER, READ_ON_CACHE_LD, 7, 1) + FIELD(EFUSE_IER, CACHE_FSM_ERROR, 6, 1) + FIELD(EFUSE_IER, MAIN_FSM_ERROR, 5, 1) + FIELD(EFUSE_IER, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IER, RD_ERROR, 3, 1) + FIELD(EFUSE_IER, RD_DONE, 2, 1) + FIELD(EFUSE_IER, PGM_ERROR, 1, 1) + FIELD(EFUSE_IER, PGM_DONE, 0, 1) +REG32(EFUSE_IDR, 0x3c) + FIELD(EFUSE_IDR, APB_SLVERR, 31, 1) + FIELD(EFUSE_IDR, CACHE_PARITY_E2, 14, 1) + FIELD(EFUSE_IDR, CACHE_PARITY_E1, 13, 1) + FIELD(EFUSE_IDR, CACHE_PARITY_E0S, 12, 1) + FIELD(EFUSE_IDR, CACHE_PARITY_E0R, 11, 1) + FIELD(EFUSE_IDR, CACHE_APB_SLVERR, 10, 1) + FIELD(EFUSE_IDR, CACHE_REQ_ERROR, 9, 1) + FIELD(EFUSE_IDR, MAIN_REQ_ERROR, 8, 1) + FIELD(EFUSE_IDR, READ_ON_CACHE_LD, 7, 1) + FIELD(EFUSE_IDR, CACHE_FSM_ERROR, 6, 1) + FIELD(EFUSE_IDR, MAIN_FSM_ERROR, 5, 1) + FIELD(EFUSE_IDR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IDR, RD_ERROR, 3, 1) + FIELD(EFUSE_IDR, RD_DONE, 2, 1) + FIELD(EFUSE_IDR, PGM_ERROR, 1, 1) + FIELD(EFUSE_IDR, PGM_DONE, 0, 1) +REG32(EFUSE_CACHE_LOAD, 0x40) + FIELD(EFUSE_CACHE_LOAD, LOAD, 0, 1) +REG32(EFUSE_PGM_LOCK, 0x44) + FIELD(EFUSE_PGM_LOCK, SPK_ID_LOCK, 0, 1) +REG32(EFUSE_AES_CRC, 0x48) +REG32(EFUSE_AES_USR_KEY0_CRC, 0x4c) +REG32(EFUSE_AES_USR_KEY1_CRC, 0x50) +REG32(EFUSE_PD, 0x54) +REG32(EFUSE_ANLG_OSC_SW_1LP, 0x60) +REG32(EFUSE_TEST_CTRL, 0x100) + +#define R_MAX (R_EFUSE_TEST_CTRL + 1) + +#define R_WR_LOCK_UNLOCK_PASSCODE (0xDF0D) + +/* + * eFuse layout references: + * https://github.com/Xilinx/embeddedsw/blob/release-2019.2/lib/sw_servi= ces/xilnvm/src/xnvm_efuse_hw.h + */ +#define BIT_POS_OF(A_) \ + ((uint32_t)((A_) & (R_EFUSE_PGM_ADDR_ROW_MASK | \ + R_EFUSE_PGM_ADDR_COLUMN_MASK))) + +#define BIT_POS(R_, C_) \ + ((uint32_t)((R_EFUSE_PGM_ADDR_ROW_MASK \ + & ((R_) << R_EFUSE_PGM_ADDR_ROW_SHIFT)) \ + | \ + (R_EFUSE_PGM_ADDR_COLUMN_MASK \ + & ((C_) << R_EFUSE_PGM_ADDR_COLUMN_SHIFT)))) + +#define EFUSE_TBIT_POS(A_) (BIT_POS_OF(A_) >=3D BIT_POS(0, 28)) + +#define EFUSE_ANCHOR_ROW (0) +#define EFUSE_ANCHOR_3_COL (27) +#define EFUSE_ANCHOR_1_COL (1) + +#define EFUSE_AES_KEY_START BIT_POS(12, 0) +#define EFUSE_AES_KEY_END BIT_POS(19, 31) +#define EFUSE_USER_KEY_0_START BIT_POS(20, 0) +#define EFUSE_USER_KEY_0_END BIT_POS(27, 31) +#define EFUSE_USER_KEY_1_START BIT_POS(28, 0) +#define EFUSE_USER_KEY_1_END BIT_POS(35, 31) + +#define EFUSE_RD_BLOCKED_START EFUSE_AES_KEY_START +#define EFUSE_RD_BLOCKED_END EFUSE_USER_KEY_1_END + +#define EFUSE_GLITCH_DET_WR_LK BIT_POS(4, 31) +#define EFUSE_PPK0_WR_LK BIT_POS(43, 6) +#define EFUSE_PPK1_WR_LK BIT_POS(43, 7) +#define EFUSE_PPK2_WR_LK BIT_POS(43, 8) +#define EFUSE_AES_WR_LK BIT_POS(43, 11) +#define EFUSE_USER_KEY_0_WR_LK BIT_POS(43, 13) +#define EFUSE_USER_KEY_1_WR_LK BIT_POS(43, 15) +#define EFUSE_PUF_SYN_LK BIT_POS(43, 16) +#define EFUSE_DNA_WR_LK BIT_POS(43, 27) +#define EFUSE_BOOT_ENV_WR_LK BIT_POS(43, 28) + +#define EFUSE_PGM_LOCKED_START BIT_POS(44, 0) +#define EFUSE_PGM_LOCKED_END BIT_POS(51, 31) + +#define EFUSE_PUF_PAGE (2) +#define EFUSE_PUF_SYN_START BIT_POS(129, 0) +#define EFUSE_PUF_SYN_END BIT_POS(255, 27) + +#define EFUSE_KEY_CRC_LK_ROW (43) +#define EFUSE_AES_KEY_CRC_LK_MASK ((1U << 9) | (1U << 10)) +#define EFUSE_USER_KEY_0_CRC_LK_MASK (1U << 12) +#define EFUSE_USER_KEY_1_CRC_LK_MASK (1U << 14) + +/* + * A handy macro to return value of an array element, + * or a specific default if given index is out of bound. + */ +#define ARRAY_GET(A_, I_, D_) \ + ((unsigned int)(I_) < ARRAY_SIZE(A_) ? (A_)[I_] : (D_)) + +QEMU_BUILD_BUG_ON(R_MAX !=3D ARRAY_SIZE(((XlnxVersalEFuseCtrl *)0)->regs)); + +typedef struct XlnxEFuseLkSpec { + uint16_t row; + uint16_t lk_bit; +} XlnxEFuseLkSpec; + +static void efuse_imr_update_irq(XlnxVersalEFuseCtrl *s) +{ + bool pending =3D s->regs[R_EFUSE_ISR] & ~s->regs[R_EFUSE_IMR]; + qemu_set_irq(s->irq_efuse_imr, pending); +} + +static void efuse_isr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + efuse_imr_update_irq(s); +} + +static uint64_t efuse_ier_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_EFUSE_IMR] &=3D ~val; + efuse_imr_update_irq(s); + return 0; +} + +static uint64_t efuse_idr_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_EFUSE_IMR] |=3D val; + efuse_imr_update_irq(s); + return 0; +} + +static void efuse_status_tbits_sync(XlnxVersalEFuseCtrl *s) +{ + uint32_t check =3D xlnx_efuse_tbits_check(s->efuse); + uint32_t val =3D s->regs[R_STATUS]; + + val =3D FIELD_DP32(val, STATUS, EFUSE_0_TBIT, !!(check & (1 << 0))); + val =3D FIELD_DP32(val, STATUS, EFUSE_1_TBIT, !!(check & (1 << 1))); + val =3D FIELD_DP32(val, STATUS, EFUSE_2_TBIT, !!(check & (1 << 2))); + + s->regs[R_STATUS] =3D val; +} + +static void efuse_anchor_bits_check(XlnxVersalEFuseCtrl *s) +{ + unsigned page; + + if (!s->efuse || !s->efuse->init_tbits) { + return; + } + + for (page =3D 0; page < s->efuse->efuse_nr; page++) { + uint32_t row =3D 0, bit; + + row =3D FIELD_DP32(row, EFUSE_PGM_ADDR, PAGE, page); + row =3D FIELD_DP32(row, EFUSE_PGM_ADDR, ROW, EFUSE_ANCHOR_ROW); + + bit =3D FIELD_DP32(row, EFUSE_PGM_ADDR, COLUMN, EFUSE_ANCHOR_3_COL= ); + if (!xlnx_efuse_get_bit(s->efuse, bit)) { + xlnx_efuse_set_bit(s->efuse, bit); + } + + bit =3D FIELD_DP32(row, EFUSE_PGM_ADDR, COLUMN, EFUSE_ANCHOR_1_COL= ); + if (!xlnx_efuse_get_bit(s->efuse, bit)) { + xlnx_efuse_set_bit(s->efuse, bit); + } + } +} + +static void efuse_key_crc_check(RegisterInfo *reg, uint32_t crc, + uint32_t pass_mask, uint32_t done_mask, + unsigned first, uint32_t lk_mask) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + uint32_t r, lk_bits; + + /* + * To start, assume both DONE and PASS, and clear PASS by xor + * if CRC-check fails or CRC-check disabled by lock fuse. + */ + r =3D s->regs[R_STATUS] | done_mask | pass_mask; + + lk_bits =3D xlnx_efuse_get_row(s->efuse, EFUSE_KEY_CRC_LK_ROW) & lk_ma= sk; + if (lk_bits =3D=3D 0 && xlnx_efuse_k256_check(s->efuse, crc, first)) { + pass_mask =3D 0; + } + + s->regs[R_STATUS] =3D r ^ pass_mask; +} + +static void efuse_data_sync(XlnxVersalEFuseCtrl *s) +{ + efuse_status_tbits_sync(s); +} + +static int efuse_lk_spec_cmp(const void *a, const void *b) +{ + uint16_t r1 =3D ((const XlnxEFuseLkSpec *)a)->row; + uint16_t r2 =3D ((const XlnxEFuseLkSpec *)b)->row; + + return (r1 > r2) - (r1 < r2); +} + +static void efuse_lk_spec_sort(XlnxVersalEFuseCtrl *s) +{ + XlnxEFuseLkSpec *ary =3D s->extra_pg0_lock_spec; + const uint32_t n8 =3D s->extra_pg0_lock_n16 * 2; + const uint32_t sz =3D sizeof(ary[0]); + const uint32_t cnt =3D n8 / sz; + + if (ary && cnt) { + qsort(ary, cnt, sz, efuse_lk_spec_cmp); + } +} + +static uint32_t efuse_lk_spec_find(XlnxVersalEFuseCtrl *s, uint32_t row) +{ + const XlnxEFuseLkSpec *ary =3D s->extra_pg0_lock_spec; + const uint32_t n8 =3D s->extra_pg0_lock_n16 * 2; + const uint32_t sz =3D sizeof(ary[0]); + const uint32_t cnt =3D n8 / sz; + const XlnxEFuseLkSpec *item =3D NULL; + + if (ary && cnt) { + XlnxEFuseLkSpec k =3D { .row =3D row, }; + + item =3D bsearch(&k, ary, cnt, sz, efuse_lk_spec_cmp); + } + + return item ? item->lk_bit : 0; +} + +static uint32_t efuse_bit_locked(XlnxVersalEFuseCtrl *s, uint32_t bit) +{ + /* Hard-coded locks */ + static const uint16_t pg0_hard_lock[] =3D { + [4] =3D EFUSE_GLITCH_DET_WR_LK, + [37] =3D EFUSE_BOOT_ENV_WR_LK, + + [8 ... 11] =3D EFUSE_DNA_WR_LK, + [12 ... 19] =3D EFUSE_AES_WR_LK, + [20 ... 27] =3D EFUSE_USER_KEY_0_WR_LK, + [28 ... 35] =3D EFUSE_USER_KEY_1_WR_LK, + [64 ... 71] =3D EFUSE_PPK0_WR_LK, + [72 ... 79] =3D EFUSE_PPK1_WR_LK, + [80 ... 87] =3D EFUSE_PPK2_WR_LK, + }; + + uint32_t row =3D FIELD_EX32(bit, EFUSE_PGM_ADDR, ROW); + uint32_t lk_bit =3D ARRAY_GET(pg0_hard_lock, row, 0); + + return lk_bit ? lk_bit : efuse_lk_spec_find(s, row); +} + +static bool efuse_pgm_locked(XlnxVersalEFuseCtrl *s, unsigned int bit) +{ + + unsigned int lock =3D 1; + + /* Global lock */ + if (!ARRAY_FIELD_EX32(s->regs, CFG, PGM_EN)) { + goto ret_lock; + } + + /* Row lock */ + switch (FIELD_EX32(bit, EFUSE_PGM_ADDR, PAGE)) { + case 0: + if (ARRAY_FIELD_EX32(s->regs, EFUSE_PGM_LOCK, SPK_ID_LOCK) && + bit >=3D EFUSE_PGM_LOCKED_START && bit <=3D EFUSE_PGM_LOCKED_E= ND) { + goto ret_lock; + } + + lock =3D efuse_bit_locked(s, bit); + break; + case EFUSE_PUF_PAGE: + if (bit < EFUSE_PUF_SYN_START || bit > EFUSE_PUF_SYN_END) { + lock =3D 0; + goto ret_lock; + } + + lock =3D EFUSE_PUF_SYN_LK; + break; + default: + lock =3D 0; + goto ret_lock; + } + + /* Row lock by an efuse bit */ + if (lock) { + lock =3D xlnx_efuse_get_bit(s->efuse, lock); + } + + ret_lock: + return lock !=3D 0; +} + +static void efuse_pgm_addr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + unsigned bit =3D val64; + bool ok =3D false; + + /* Always zero out PGM_ADDR because it is write-only */ + s->regs[R_EFUSE_PGM_ADDR] =3D 0; + + /* + * Indicate error if bit is write-protected (or read-only + * as guarded by efuse_set_bit()). + * + * Keep it simple by not modeling program timing. + * + * Note: model must NEVER clear the PGM_ERROR bit; it is + * up to guest to do so (or by reset). + */ + if (efuse_pgm_locked(s, bit)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Denied setting of efuse<%u, %u, %u>\n", + object_get_canonical_path(OBJECT(s)), + FIELD_EX32(bit, EFUSE_PGM_ADDR, PAGE), + FIELD_EX32(bit, EFUSE_PGM_ADDR, ROW), + FIELD_EX32(bit, EFUSE_PGM_ADDR, COLUMN)); + } else if (xlnx_efuse_set_bit(s->efuse, bit)) { + ok =3D true; + if (EFUSE_TBIT_POS(bit)) { + efuse_status_tbits_sync(s); + } + } + + if (!ok) { + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, PGM_ERROR, 1); + } + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, PGM_DONE, 1); + efuse_imr_update_irq(s); +} + +static void efuse_rd_addr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + unsigned bit =3D val64; + bool denied; + + /* Always zero out RD_ADDR because it is write-only */ + s->regs[R_EFUSE_RD_ADDR] =3D 0; + + /* + * Indicate error if row is read-blocked. + * + * Note: model must NEVER clear the RD_ERROR bit; it is + * up to guest to do so (or by reset). + */ + s->regs[R_EFUSE_RD_DATA] =3D xlnx_versal_efuse_read_row(s->efuse, + bit, &denied); + if (denied) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Denied reading of efuse<%u, %u>\n", + object_get_canonical_path(OBJECT(s)), + FIELD_EX32(bit, EFUSE_RD_ADDR, PAGE), + FIELD_EX32(bit, EFUSE_RD_ADDR, ROW)); + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_ERROR, 1); + } + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_DONE, 1); + efuse_imr_update_irq(s); + return; +} + +static uint64_t efuse_cache_load_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + + if (val64 & R_EFUSE_CACHE_LOAD_LOAD_MASK) { + efuse_data_sync(s); + + ARRAY_FIELD_DP32(s->regs, STATUS, CACHE_DONE, 1); + efuse_imr_update_irq(s); + } + + return 0; +} + +static uint64_t efuse_pgm_lock_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(reg->opaque); + + /* Ignore all other bits */ + val64 =3D FIELD_EX32(val64, EFUSE_PGM_LOCK, SPK_ID_LOCK); + + /* Once the bit is written 1, only reset will clear it to 0 */ + val64 |=3D ARRAY_FIELD_EX32(s->regs, EFUSE_PGM_LOCK, SPK_ID_LOCK); + + return val64; +} + +static void efuse_aes_crc_postw(RegisterInfo *reg, uint64_t val64) +{ + efuse_key_crc_check(reg, val64, + R_STATUS_AES_CRC_PASS_MASK, + R_STATUS_AES_CRC_DONE_MASK, + EFUSE_AES_KEY_START, + EFUSE_AES_KEY_CRC_LK_MASK); +} + +static void efuse_aes_u0_crc_postw(RegisterInfo *reg, uint64_t val64) +{ + efuse_key_crc_check(reg, val64, + R_STATUS_AES_USER_KEY_0_CRC_PASS_MASK, + R_STATUS_AES_USER_KEY_0_CRC_DONE_MASK, + EFUSE_USER_KEY_0_START, + EFUSE_USER_KEY_0_CRC_LK_MASK); +} + +static void efuse_aes_u1_crc_postw(RegisterInfo *reg, uint64_t val64) +{ + efuse_key_crc_check(reg, val64, + R_STATUS_AES_USER_KEY_1_CRC_PASS_MASK, + R_STATUS_AES_USER_KEY_1_CRC_DONE_MASK, + EFUSE_USER_KEY_1_START, + EFUSE_USER_KEY_1_CRC_LK_MASK); +} + +static uint64_t efuse_wr_lock_prew(RegisterInfo *reg, uint64_t val) +{ + return val !=3D R_WR_LOCK_UNLOCK_PASSCODE; +} + +static const RegisterAccessInfo efuse_ctrl_regs_info[] =3D { + { .name =3D "WR_LOCK", .addr =3D A_WR_LOCK, + .reset =3D 0x1, + .pre_write =3D efuse_wr_lock_prew, + },{ .name =3D "CFG", .addr =3D A_CFG, + .rsvd =3D 0x9, + },{ .name =3D "STATUS", .addr =3D A_STATUS, + .rsvd =3D 0x8, + .ro =3D 0xfff, + },{ .name =3D "EFUSE_PGM_ADDR", .addr =3D A_EFUSE_PGM_ADDR, + .post_write =3D efuse_pgm_addr_postw, + },{ .name =3D "EFUSE_RD_ADDR", .addr =3D A_EFUSE_RD_ADDR, + .rsvd =3D 0x1f, + .post_write =3D efuse_rd_addr_postw, + },{ .name =3D "EFUSE_RD_DATA", .addr =3D A_EFUSE_RD_DATA, + .ro =3D 0xffffffff, + },{ .name =3D "TPGM", .addr =3D A_TPGM, + },{ .name =3D "TRD", .addr =3D A_TRD, + .reset =3D 0x19, + },{ .name =3D "TSU_H_PS", .addr =3D A_TSU_H_PS, + .reset =3D 0xff, + },{ .name =3D "TSU_H_PS_CS", .addr =3D A_TSU_H_PS_CS, + .reset =3D 0x11, + },{ .name =3D "TRDM", .addr =3D A_TRDM, + .reset =3D 0x3a, + },{ .name =3D "TSU_H_CS", .addr =3D A_TSU_H_CS, + .reset =3D 0x16, + },{ .name =3D "EFUSE_ISR", .addr =3D A_EFUSE_ISR, + .rsvd =3D 0x7fff8000, + .w1c =3D 0x80007fff, + .post_write =3D efuse_isr_postw, + },{ .name =3D "EFUSE_IMR", .addr =3D A_EFUSE_IMR, + .reset =3D 0x80007fff, + .rsvd =3D 0x7fff8000, + .ro =3D 0xffffffff, + },{ .name =3D "EFUSE_IER", .addr =3D A_EFUSE_IER, + .rsvd =3D 0x7fff8000, + .pre_write =3D efuse_ier_prew, + },{ .name =3D "EFUSE_IDR", .addr =3D A_EFUSE_IDR, + .rsvd =3D 0x7fff8000, + .pre_write =3D efuse_idr_prew, + },{ .name =3D "EFUSE_CACHE_LOAD", .addr =3D A_EFUSE_CACHE_LOAD, + .pre_write =3D efuse_cache_load_prew, + },{ .name =3D "EFUSE_PGM_LOCK", .addr =3D A_EFUSE_PGM_LOCK, + .pre_write =3D efuse_pgm_lock_prew, + },{ .name =3D "EFUSE_AES_CRC", .addr =3D A_EFUSE_AES_CRC, + .post_write =3D efuse_aes_crc_postw, + },{ .name =3D "EFUSE_AES_USR_KEY0_CRC", .addr =3D A_EFUSE_AES_USR_KEY= 0_CRC, + .post_write =3D efuse_aes_u0_crc_postw, + },{ .name =3D "EFUSE_AES_USR_KEY1_CRC", .addr =3D A_EFUSE_AES_USR_KEY= 1_CRC, + .post_write =3D efuse_aes_u1_crc_postw, + },{ .name =3D "EFUSE_PD", .addr =3D A_EFUSE_PD, + .ro =3D 0xfffffffe, + },{ .name =3D "EFUSE_ANLG_OSC_SW_1LP", .addr =3D A_EFUSE_ANLG_OSC_SW_= 1LP, + },{ .name =3D "EFUSE_TEST_CTRL", .addr =3D A_EFUSE_TEST_CTRL, + .reset =3D 0x8, + } +}; + +static void efuse_ctrl_reg_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + RegisterInfoArray *reg_array =3D opaque; + XlnxVersalEFuseCtrl *s; + Object *dev; + + assert(reg_array !=3D NULL); + + dev =3D reg_array->mem.owner; + assert(dev); + + s =3D XLNX_VERSAL_EFUSE_CTRL(dev); + + if (addr !=3D A_WR_LOCK && s->regs[R_WR_LOCK]) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s[reg_0x%02lx]: Attempt to write locked register.\= n", + object_get_canonical_path(OBJECT(s)), (long)addr); + } else { + register_write_memory(opaque, addr, data, size); + } +} + +static void efuse_ctrl_register_reset(RegisterInfo *reg) +{ + if (!reg->data || !reg->access) { + return; + } + + /* Reset must not trigger some registers' writers */ + switch (reg->access->addr) { + case A_EFUSE_AES_CRC: + case A_EFUSE_AES_USR_KEY0_CRC: + case A_EFUSE_AES_USR_KEY1_CRC: + *(uint32_t *)reg->data =3D reg->access->reset; + return; + } + + register_reset(reg); +} + +static void efuse_ctrl_reset(DeviceState *dev) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(dev); + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(s->regs_info); ++i) { + efuse_ctrl_register_reset(&s->regs_info[i]); + } + + efuse_anchor_bits_check(s); + efuse_data_sync(s); + efuse_imr_update_irq(s); +} + +static const MemoryRegionOps efuse_ctrl_ops =3D { + .read =3D register_read_memory, + .write =3D efuse_ctrl_reg_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void efuse_ctrl_realize(DeviceState *dev, Error **errp) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(dev); + const uint32_t lks_sz =3D sizeof(XlnxEFuseLkSpec) / 2; + + if (!s->efuse) { + error_setg(errp, "%s.efuse: link property not connected to XLNX-EF= USE", + object_get_canonical_path(OBJECT(dev))); + return; + } + + /* Sort property-defined pgm-locks for bsearch lookup */ + if ((s->extra_pg0_lock_n16 % lks_sz) !=3D 0) { + error_setg(errp, + "%s.pg0-lock: array property item-count not multiple of= %u", + object_get_canonical_path(OBJECT(dev)), lks_sz); + return; + } + + efuse_lk_spec_sort(s); +} + +static void efuse_ctrl_init(Object *obj) +{ + XlnxVersalEFuseCtrl *s =3D XLNX_VERSAL_EFUSE_CTRL(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + RegisterInfoArray *reg_array; + + reg_array =3D + register_init_block32(DEVICE(obj), efuse_ctrl_regs_info, + ARRAY_SIZE(efuse_ctrl_regs_info), + s->regs_info, s->regs, + &efuse_ctrl_ops, + XLNX_VERSAL_EFUSE_CTRL_ERR_DEBUG, + R_MAX * 4); + + sysbus_init_mmio(sbd, ®_array->mem); + sysbus_init_irq(sbd, &s->irq_efuse_imr); +} + +static const VMStateDescription vmstate_efuse_ctrl =3D { + .name =3D TYPE_XLNX_VERSAL_EFUSE_CTRL, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, XlnxVersalEFuseCtrl, R_MAX), + VMSTATE_END_OF_LIST(), + } +}; + +static Property efuse_ctrl_props[] =3D { + DEFINE_PROP_LINK("efuse", + XlnxVersalEFuseCtrl, efuse, + TYPE_XLNX_EFUSE, XlnxEFuse *), + DEFINE_PROP_ARRAY("pg0-lock", + XlnxVersalEFuseCtrl, extra_pg0_lock_n16, + extra_pg0_lock_spec, qdev_prop_uint16, uint16_t), + + DEFINE_PROP_END_OF_LIST(), +}; + +static void efuse_ctrl_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D efuse_ctrl_reset; + dc->realize =3D efuse_ctrl_realize; + dc->vmsd =3D &vmstate_efuse_ctrl; + device_class_set_props(dc, efuse_ctrl_props); +} + +static const TypeInfo efuse_ctrl_info =3D { + .name =3D TYPE_XLNX_VERSAL_EFUSE_CTRL, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(XlnxVersalEFuseCtrl), + .class_init =3D efuse_ctrl_class_init, + .instance_init =3D efuse_ctrl_init, +}; + +static void efuse_ctrl_register_types(void) +{ + type_register_static(&efuse_ctrl_info); +} + +type_init(efuse_ctrl_register_types) + +/* + * Retrieve a row, with unreadable bits returned as 0. + */ +uint32_t xlnx_versal_efuse_read_row(XlnxEFuse *efuse, + uint32_t bit, bool *denied) +{ + bool dummy; + + if (!denied) { + denied =3D &dummy; + } + + if (bit >=3D EFUSE_RD_BLOCKED_START && bit <=3D EFUSE_RD_BLOCKED_END) { + *denied =3D true; + return 0; + } + + *denied =3D false; + return xlnx_efuse_get_row(efuse, bit); +} diff --git a/include/hw/nvram/xlnx-versal-efuse.h b/include/hw/nvram/xlnx-v= ersal-efuse.h new file mode 100644 index 0000000000..a873dc5cb0 --- /dev/null +++ b/include/hw/nvram/xlnx-versal-efuse.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef XLNX_VERSAL_EFUSE_H +#define XLNX_VERSAL_EFUSE_H + +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "hw/register.h" +#include "hw/nvram/xlnx-efuse.h" + +#define XLNX_VERSAL_EFUSE_CTRL_R_MAX ((0x100 / 4) + 1) + +#define TYPE_XLNX_VERSAL_EFUSE_CTRL "xlnx,versal-efuse" +#define TYPE_XLNX_VERSAL_EFUSE_CACHE "xlnx,pmc-efuse-cache" + +OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCtrl, XLNX_VERSAL_EFUSE_CTRL); +OBJECT_DECLARE_SIMPLE_TYPE(XlnxVersalEFuseCache, XLNX_VERSAL_EFUSE_CACHE); + +struct XlnxVersalEFuseCtrl { + SysBusDevice parent_obj; + qemu_irq irq_efuse_imr; + + XlnxEFuse *efuse; + + void *extra_pg0_lock_spec; /* Opaque property */ + uint32_t extra_pg0_lock_n16; + + uint32_t regs[XLNX_VERSAL_EFUSE_CTRL_R_MAX]; + RegisterInfo regs_info[XLNX_VERSAL_EFUSE_CTRL_R_MAX]; +}; + +struct XlnxVersalEFuseCache { + SysBusDevice parent_obj; + MemoryRegion iomem; + + XlnxEFuse *efuse; +}; + +/** + * xlnx_versal_efuse_read_row: + * @s: the efuse object + * @bit: the bit-address within the 32-bit row to be read + * @denied: if non-NULL, to receive true if the row is write-only + * + * Returns: the 32-bit word containing address @bit; 0 if @denies is true + */ +uint32_t xlnx_versal_efuse_read_row(XlnxEFuse *s, uint32_t bit, bool *deni= ed); + +#endif --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856886; cv=pass; d=zohomail.com; s=zohoarc; b=c22SqrGD+EcVNL+O3/q1wd3Mm9UVa9BH89OoYA6yRju1BzDRkgeehHwwLdOK/snLNBo99/aoNfypKzAZArEiMROMbo6etR/I2IOctrOTj6A6W2u9fWcL5ni85SJEJ8QrFSUj9oySNvqyg6TYddIPXw3yIpgehPnTZZi+0CpHTnw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856886; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jQAkNUx7bD4IXQ8y1U4bQtW+xvD00UcUhOeJwvlbRHE=; b=bSEJ8xbEQh3r/EPP2khkU/MWpeK1gwVPEjQQnWDexE85QEh+Tdmr2x8/dIJqO9K0UpN51PwTI3Vp6rROq5+viegkoTg5inqqFpBxKPM9NYZgd0CVTM1wAyF2KiNmgb8DGD26ve+Q4slUZxe9x/Nir7yvLAA9CfGjQoF3Q7LA2aw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856886821500.92106841736575; Thu, 16 Sep 2021 22:34:46 -0700 (PDT) Received: from localhost ([::1]:54544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6WL-0001HT-O0 for importer@patchew.org; Fri, 17 Sep 2021 01:34:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MM-0002u1-1A; Fri, 17 Sep 2021 01:24:26 -0400 Received: from mail-dm6nam11on2067.outbound.protection.outlook.com ([40.107.223.67]:42592 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6M5-0005ub-6m; Fri, 17 Sep 2021 01:24:25 -0400 Received: from BN0PR04CA0119.namprd04.prod.outlook.com (2603:10b6:408:ec::34) by PH0PR02MB8844.namprd02.prod.outlook.com (2603:10b6:510:f7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 05:24:05 +0000 Received: from BN1NAM02FT035.eop-nam02.prod.protection.outlook.com (2603:10b6:408:ec:cafe::42) by BN0PR04CA0119.outlook.office365.com (2603:10b6:408:ec::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:04 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT035.mail.protection.outlook.com (10.13.2.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:04 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:00 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-SP; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iVfnfLyWRwRRw4q36hNwFvWZEBmJnfdIogzd6j4k1NAl+ksO4YURCveTKwfIEx2sIOkOzKUKbp6B8dLYNQvQS84e5g7Rqzc23TZNlBLREw00l937TsROYQe8gycPDChi9R/Qra/XX+X7GsxPPTzrT3k8W/d2FGkbiGsp6Pw5yjTlI9MJrn9Z+bgPZzwtPXPYoFrrMYbUCC3Lbs+Wq8UcEFzN4f0G3eGEAsKtJysr0Pw8jueDkZ9/twHHSXHhq1gFk42iBL7A/I8FemI45sWRvyTofFuFrDsaHEHTGKGVMn5eE18yrwZjKohn2T4KOFLbuEtJ1KyZB6BrWNNYgcJqPA== 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; bh=jQAkNUx7bD4IXQ8y1U4bQtW+xvD00UcUhOeJwvlbRHE=; b=GQgQhpq4ydEIjJPnMw8ILTkw6V71S3JU2NgxMwv7OLUhNXhgGhBdDm4alek/HbmXysbEem8KwEf/qiHGl03YOHzkB1Ffk5NvKdvAaBYl1A+wHr7wFLR6GcPGTYG8AthEQMQwnHhyO+cvfZf3wypMwPH7et0SYbq4+SR9cpG4jvGe5HQtLWWZUEeWTAKANueo+ZTFBV9peBf8N63KH0dxvZZH3FePR+sBBlNh6cP4mTFMMrSRnuCTptbXX6qI1EZtn/QT3lrnkCfO+axzS51AejlVZ/pvit799Vuspb4pZliyisrdFUEnbUPNnMmwWtHfqZE97W30qPPOKYCXKdD/UQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jQAkNUx7bD4IXQ8y1U4bQtW+xvD00UcUhOeJwvlbRHE=; b=CnXE/AKGJfX20yV+TdBT6MNoG1g/oHBSNDILMMRDxSX45mrUEswmgmYWawmQiJrYVZR09uNZxFUAEohYd/6jde2nX6tjk2LF8fmHs3JZH0z9AUYdD/s/BU/NYmlvUM8FPa3mzJw6DWuFui6uxglRzGL4Ls8/DcXIVf8b7Bm4VBw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 3/9] hw/nvram: Introduce Xilinx ZynqMP eFuse device Date: Thu, 16 Sep 2021 22:23:54 -0700 Message-ID: <20210917052400.1249094-4-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14903c99-45cf-48ee-3e5b-08d9799b5dbb X-MS-TrafficTypeDiagnostic: PH0PR02MB8844: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:2201; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gt3mRdZhkDnfCkNx+CotBcemuJJ09UayALOJr1igy91AU/mpdziTolGddIP2iUuhrwJ0ht+6MxvMtZ42eEr+dajcWxDWdsPJ0Ggp+/guEx0JPq7BtrrJrkUjyN70wGyo3PJmX/H87Cd8NSzZ3zOY2cYuF52cW8TDLAo8gw0vNFSmFmb0+foBzDvFBPXy9neA+WghyMxAjDxgIl0lXneJrbHlJMKZC6k5p/u+cc8Ru4Xfy5EMIBgTLUCT9zFzaXpgpRMtWl88KhuleUczGmUH/PrjipN0lSaMTnmG8eo/7qLN42/3ApIyPimu22TbdaP7tOehJjBGh1v/4Mmewq3BavTngLxKZQ4zpMJOd6LTHcVNVXcJeejtP3nPeU2GPvdkphlw4PoB8aPmvXHVbfCDCaIFHmbF3JzWOWhOjjGjNQ6R4sM0y6sKUOgr8/FO4Xskvt+c2JrCllr2VunEqKVJCQGcPMOpShiO/wlYH0iWS4a3+VEArdGh7PuXrzqHbf67Q4XIhgHHvdyyTMjQZsdWrfS0KiEVUDozM+T3v7g80vlNc6+QDS1XOYMsgYUmrl5+lcO/uXm0wM5LQBkmeAAVGAm7j4EvG/ZTQlMsIdcPvrEdbiCjLU77GWSw+CraW9f1ObGHCmtW3IuzKNTVhED+H8b2zPw+rqQ3RzEO325yxv9tYNa/9ITS+QFOlDJwxeZkOLtclfNT01YxVugzMNDKg5VGUK4LLZIdZ36GnAFpxf0= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch01.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(136003)(346002)(39860400002)(376002)(396003)(46966006)(36840700001)(26005)(4326008)(6916009)(6666004)(54906003)(316002)(70206006)(70586007)(36860700001)(107886003)(36756003)(8936002)(5660300002)(36906005)(2616005)(7696005)(478600001)(83380400001)(47076005)(30864003)(82740400003)(356005)(336012)(44832011)(82310400003)(1076003)(2906002)(9786002)(186003)(426003)(8676002)(7636003)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:04.7680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14903c99-45cf-48ee-3e5b-08d9799b5dbb X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT035.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB8844 Received-SPF: pass client-ip=40.107.223.67; envelope-from=tongh@xilinx.com; helo=NAM11-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856888563100001 Content-Type: text/plain; charset="utf-8" This implements the Xilinx ZynqMP eFuse, an one-time field-programmable non-volatile storage device. There is only one such device in the Xilinx ZynqMP product family. Co-authored-by: Edgar E. Iglesias Co-authored-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Sai Pavan Boddu Signed-off-by: Tong Ho --- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 2 + hw/nvram/xlnx-zynqmp-efuse.c | 855 +++++++++++++++++++++++++++ include/hw/nvram/xlnx-zynqmp-efuse.h | 44 ++ 4 files changed, 905 insertions(+) create mode 100644 hw/nvram/xlnx-zynqmp-efuse.c create mode 100644 include/hw/nvram/xlnx-zynqmp-efuse.h diff --git a/hw/nvram/Kconfig b/hw/nvram/Kconfig index 6c2bb5afe3..3059c5dae0 100644 --- a/hw/nvram/Kconfig +++ b/hw/nvram/Kconfig @@ -26,3 +26,7 @@ config XLNX_EFUSE config XLNX_EFUSE_VERSAL bool select XLNX_EFUSE + +config XLNX_EFUSE_ZYNQMP + bool + select XLNX_EFUSE diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build index 62352ad8ec..6dc54d9873 100644 --- a/hw/nvram/meson.build +++ b/hw/nvram/meson.build @@ -14,5 +14,7 @@ softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE', if_true: files(= 'xlnx-efuse.c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true: files( 'xlnx-versal-efuse-cach= e.c', 'xlnx-versal-efuse-ctrl= .c')) +softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_ZYNQMP', if_true: files( + 'xlnx-zynqmp-efuse.c')) =20 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) diff --git a/hw/nvram/xlnx-zynqmp-efuse.c b/hw/nvram/xlnx-zynqmp-efuse.c new file mode 100644 index 0000000000..1f87dbf988 --- /dev/null +++ b/hw/nvram/xlnx-zynqmp-efuse.c @@ -0,0 +1,855 @@ +/* + * QEMU model of the ZynqMP eFuse + * + * Copyright (c) 2015 Xilinx Inc. + * + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-zynqmp-efuse.h" + +#include "qemu/log.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" + +#ifndef ZYNQMP_EFUSE_ERR_DEBUG +#define ZYNQMP_EFUSE_ERR_DEBUG 0 +#endif + +REG32(WR_LOCK, 0x0) + FIELD(WR_LOCK, LOCK, 0, 16) +REG32(CFG, 0x4) + FIELD(CFG, SLVERR_ENABLE, 5, 1) + FIELD(CFG, MARGIN_RD, 2, 2) + FIELD(CFG, PGM_EN, 1, 1) + FIELD(CFG, EFUSE_CLK_SEL, 0, 1) +REG32(STATUS, 0x8) + FIELD(STATUS, AES_CRC_PASS, 7, 1) + FIELD(STATUS, AES_CRC_DONE, 6, 1) + FIELD(STATUS, CACHE_DONE, 5, 1) + FIELD(STATUS, CACHE_LOAD, 4, 1) + FIELD(STATUS, EFUSE_3_TBIT, 2, 1) + FIELD(STATUS, EFUSE_2_TBIT, 1, 1) + FIELD(STATUS, EFUSE_0_TBIT, 0, 1) +REG32(EFUSE_PGM_ADDR, 0xc) + FIELD(EFUSE_PGM_ADDR, EFUSE, 11, 2) + FIELD(EFUSE_PGM_ADDR, ROW, 5, 6) + FIELD(EFUSE_PGM_ADDR, COLUMN, 0, 5) +REG32(EFUSE_RD_ADDR, 0x10) + FIELD(EFUSE_RD_ADDR, EFUSE, 11, 2) + FIELD(EFUSE_RD_ADDR, ROW, 5, 6) +REG32(EFUSE_RD_DATA, 0x14) +REG32(TPGM, 0x18) + FIELD(TPGM, VALUE, 0, 16) +REG32(TRD, 0x1c) + FIELD(TRD, VALUE, 0, 8) +REG32(TSU_H_PS, 0x20) + FIELD(TSU_H_PS, VALUE, 0, 8) +REG32(TSU_H_PS_CS, 0x24) + FIELD(TSU_H_PS_CS, VALUE, 0, 8) +REG32(TSU_H_CS, 0x2c) + FIELD(TSU_H_CS, VALUE, 0, 4) +REG32(EFUSE_ISR, 0x30) + FIELD(EFUSE_ISR, APB_SLVERR, 31, 1) + FIELD(EFUSE_ISR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_ISR, RD_ERROR, 3, 1) + FIELD(EFUSE_ISR, RD_DONE, 2, 1) + FIELD(EFUSE_ISR, PGM_ERROR, 1, 1) + FIELD(EFUSE_ISR, PGM_DONE, 0, 1) +REG32(EFUSE_IMR, 0x34) + FIELD(EFUSE_IMR, APB_SLVERR, 31, 1) + FIELD(EFUSE_IMR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IMR, RD_ERROR, 3, 1) + FIELD(EFUSE_IMR, RD_DONE, 2, 1) + FIELD(EFUSE_IMR, PGM_ERROR, 1, 1) + FIELD(EFUSE_IMR, PGM_DONE, 0, 1) +REG32(EFUSE_IER, 0x38) + FIELD(EFUSE_IER, APB_SLVERR, 31, 1) + FIELD(EFUSE_IER, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IER, RD_ERROR, 3, 1) + FIELD(EFUSE_IER, RD_DONE, 2, 1) + FIELD(EFUSE_IER, PGM_ERROR, 1, 1) + FIELD(EFUSE_IER, PGM_DONE, 0, 1) +REG32(EFUSE_IDR, 0x3c) + FIELD(EFUSE_IDR, APB_SLVERR, 31, 1) + FIELD(EFUSE_IDR, CACHE_ERROR, 4, 1) + FIELD(EFUSE_IDR, RD_ERROR, 3, 1) + FIELD(EFUSE_IDR, RD_DONE, 2, 1) + FIELD(EFUSE_IDR, PGM_ERROR, 1, 1) + FIELD(EFUSE_IDR, PGM_DONE, 0, 1) +REG32(EFUSE_CACHE_LOAD, 0x40) + FIELD(EFUSE_CACHE_LOAD, LOAD, 0, 1) +REG32(EFUSE_PGM_LOCK, 0x44) + FIELD(EFUSE_PGM_LOCK, SPK_ID_LOCK, 0, 1) +REG32(EFUSE_AES_CRC, 0x48) +REG32(EFUSE_TBITS_PRGRMG_EN, 0x100) + FIELD(EFUSE_TBITS_PRGRMG_EN, TBITS_PRGRMG_EN, 3, 1) +REG32(DNA_0, 0x100c) +REG32(DNA_1, 0x1010) +REG32(DNA_2, 0x1014) +REG32(IPDISABLE, 0x1018) + FIELD(IPDISABLE, VCU_DIS, 8, 1) + FIELD(IPDISABLE, GPU_DIS, 5, 1) + FIELD(IPDISABLE, APU3_DIS, 3, 1) + FIELD(IPDISABLE, APU2_DIS, 2, 1) + FIELD(IPDISABLE, APU1_DIS, 1, 1) + FIELD(IPDISABLE, APU0_DIS, 0, 1) +REG32(SYSOSC_CTRL, 0x101c) + FIELD(SYSOSC_CTRL, SYSOSC_EN, 0, 1) +REG32(USER_0, 0x1020) +REG32(USER_1, 0x1024) +REG32(USER_2, 0x1028) +REG32(USER_3, 0x102c) +REG32(USER_4, 0x1030) +REG32(USER_5, 0x1034) +REG32(USER_6, 0x1038) +REG32(USER_7, 0x103c) +REG32(MISC_USER_CTRL, 0x1040) + FIELD(MISC_USER_CTRL, FPD_SC_EN_0, 14, 1) + FIELD(MISC_USER_CTRL, LPD_SC_EN_0, 11, 1) + FIELD(MISC_USER_CTRL, LBIST_EN, 10, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_7, 7, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_6, 6, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_5, 5, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_4, 4, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_3, 3, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_2, 2, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_1, 1, 1) + FIELD(MISC_USER_CTRL, USR_WRLK_0, 0, 1) +REG32(ROM_RSVD, 0x1044) + FIELD(ROM_RSVD, PBR_BOOT_ERROR, 0, 3) +REG32(PUF_CHASH, 0x1050) +REG32(PUF_MISC, 0x1054) + FIELD(PUF_MISC, REGISTER_DIS, 31, 1) + FIELD(PUF_MISC, SYN_WRLK, 30, 1) + FIELD(PUF_MISC, SYN_INVLD, 29, 1) + FIELD(PUF_MISC, TEST2_DIS, 28, 1) + FIELD(PUF_MISC, UNUSED27, 27, 1) + FIELD(PUF_MISC, UNUSED26, 26, 1) + FIELD(PUF_MISC, UNUSED25, 25, 1) + FIELD(PUF_MISC, UNUSED24, 24, 1) + FIELD(PUF_MISC, AUX, 0, 24) +REG32(SEC_CTRL, 0x1058) + FIELD(SEC_CTRL, PPK1_INVLD, 30, 2) + FIELD(SEC_CTRL, PPK1_WRLK, 29, 1) + FIELD(SEC_CTRL, PPK0_INVLD, 27, 2) + FIELD(SEC_CTRL, PPK0_WRLK, 26, 1) + FIELD(SEC_CTRL, RSA_EN, 11, 15) + FIELD(SEC_CTRL, SEC_LOCK, 10, 1) + FIELD(SEC_CTRL, PROG_GATE_2, 9, 1) + FIELD(SEC_CTRL, PROG_GATE_1, 8, 1) + FIELD(SEC_CTRL, PROG_GATE_0, 7, 1) + FIELD(SEC_CTRL, DFT_DIS, 6, 1) + FIELD(SEC_CTRL, JTAG_DIS, 5, 1) + FIELD(SEC_CTRL, ERROR_DIS, 4, 1) + FIELD(SEC_CTRL, BBRAM_DIS, 3, 1) + FIELD(SEC_CTRL, ENC_ONLY, 2, 1) + FIELD(SEC_CTRL, AES_WRLK, 1, 1) + FIELD(SEC_CTRL, AES_RDLK, 0, 1) +REG32(SPK_ID, 0x105c) +REG32(PPK0_0, 0x10a0) +REG32(PPK0_1, 0x10a4) +REG32(PPK0_2, 0x10a8) +REG32(PPK0_3, 0x10ac) +REG32(PPK0_4, 0x10b0) +REG32(PPK0_5, 0x10b4) +REG32(PPK0_6, 0x10b8) +REG32(PPK0_7, 0x10bc) +REG32(PPK0_8, 0x10c0) +REG32(PPK0_9, 0x10c4) +REG32(PPK0_10, 0x10c8) +REG32(PPK0_11, 0x10cc) +REG32(PPK1_0, 0x10d0) +REG32(PPK1_1, 0x10d4) +REG32(PPK1_2, 0x10d8) +REG32(PPK1_3, 0x10dc) +REG32(PPK1_4, 0x10e0) +REG32(PPK1_5, 0x10e4) +REG32(PPK1_6, 0x10e8) +REG32(PPK1_7, 0x10ec) +REG32(PPK1_8, 0x10f0) +REG32(PPK1_9, 0x10f4) +REG32(PPK1_10, 0x10f8) +REG32(PPK1_11, 0x10fc) + +#define BIT_POS(ROW, COLUMN) (ROW * 32 + COLUMN) +#define R_MAX (R_PPK1_11 + 1) + +/* #define EFUSE_XOSC 26 */ + +/* + * eFUSE layout references: + * ZynqMP: UG1085 (v2.1) August 21, 2019, p.277, Table 12-13 + */ +#define EFUSE_AES_RDLK BIT_POS(22, 0) +#define EFUSE_AES_WRLK BIT_POS(22, 1) +#define EFUSE_ENC_ONLY BIT_POS(22, 2) +#define EFUSE_BBRAM_DIS BIT_POS(22, 3) +#define EFUSE_ERROR_DIS BIT_POS(22, 4) +#define EFUSE_JTAG_DIS BIT_POS(22, 5) +#define EFUSE_DFT_DIS BIT_POS(22, 6) +#define EFUSE_PROG_GATE_0 BIT_POS(22, 7) +#define EFUSE_PROG_GATE_1 BIT_POS(22, 7) +#define EFUSE_PROG_GATE_2 BIT_POS(22, 9) +#define EFUSE_SEC_LOCK BIT_POS(22, 10) +#define EFUSE_RSA_EN BIT_POS(22, 11) +#define EFUSE_RSA_EN14 BIT_POS(22, 25) +#define EFUSE_PPK0_WRLK BIT_POS(22, 26) +#define EFUSE_PPK0_INVLD BIT_POS(22, 27) +#define EFUSE_PPK0_INVLD_1 BIT_POS(22, 28) +#define EFUSE_PPK1_WRLK BIT_POS(22, 29) +#define EFUSE_PPK1_INVLD BIT_POS(22, 30) +#define EFUSE_PPK1_INVLD_1 BIT_POS(22, 31) + +/* Areas. */ +#define EFUSE_TRIM_START BIT_POS(1, 0) +#define EFUSE_TRIM_END BIT_POS(1, 30) +#define EFUSE_DNA_START BIT_POS(3, 0) +#define EFUSE_DNA_END BIT_POS(5, 31) +#define EFUSE_AES_START BIT_POS(24, 0) +#define EFUSE_AES_END BIT_POS(31, 31) +#define EFUSE_ROM_START BIT_POS(17, 0) +#define EFUSE_ROM_END BIT_POS(17, 31) +#define EFUSE_IPDIS_START BIT_POS(6, 0) +#define EFUSE_IPDIS_END BIT_POS(6, 31) +#define EFUSE_USER_START BIT_POS(8, 0) +#define EFUSE_USER_END BIT_POS(15, 31) +#define EFUSE_BISR_START BIT_POS(32, 0) +#define EFUSE_BISR_END BIT_POS(39, 31) + +#define EFUSE_USER_CTRL_START BIT_POS(16, 0) +#define EFUSE_USER_CTRL_END BIT_POS(16, 16) +#define EFUSE_USER_CTRL_MASK ((uint32_t)MAKE_64BIT_MASK(0, 17)) + +#define EFUSE_PUF_CHASH_START BIT_POS(20, 0) +#define EFUSE_PUF_CHASH_END BIT_POS(20, 31) +#define EFUSE_PUF_MISC_START BIT_POS(21, 0) +#define EFUSE_PUF_MISC_END BIT_POS(21, 31) +#define EFUSE_PUF_SYN_WRLK BIT_POS(21, 30) + +#define EFUSE_SPK_START BIT_POS(23, 0) +#define EFUSE_SPK_END BIT_POS(23, 31) + +#define EFUSE_PPK0_START BIT_POS(40, 0) +#define EFUSE_PPK0_END BIT_POS(51, 31) +#define EFUSE_PPK1_START BIT_POS(52, 0) +#define EFUSE_PPK1_END BIT_POS(63, 31) + +#define EFUSE_CACHE_FLD(s, reg, field) \ + ARRAY_FIELD_DP32((s)->regs, reg, field, \ + (xlnx_efuse_get_row((s->efuse), EFUSE_ ## field) \ + >> (EFUSE_ ## field % 32))) + +#define EFUSE_CACHE_BIT(s, reg, field) \ + ARRAY_FIELD_DP32((s)->regs, reg, field, xlnx_efuse_get_bit((s->efuse),= \ + EFUSE_ ## field)) + +#define FBIT_UNKNOWN (~0) + +QEMU_BUILD_BUG_ON(R_MAX !=3D ARRAY_SIZE(((XlnxZynqMPEFuse *)0)->regs)); + +static void update_tbit_status(XlnxZynqMPEFuse *s) +{ + unsigned int check =3D xlnx_efuse_tbits_check(s->efuse); + uint32_t val =3D s->regs[R_STATUS]; + + val =3D FIELD_DP32(val, STATUS, EFUSE_0_TBIT, !!(check & (1 << 0))); + val =3D FIELD_DP32(val, STATUS, EFUSE_2_TBIT, !!(check & (1 << 1))); + val =3D FIELD_DP32(val, STATUS, EFUSE_3_TBIT, !!(check & (1 << 2))); + + s->regs[R_STATUS] =3D val; +} + +/* Update the u32 array from efuse bits. Slow but simple approach. */ +static void cache_sync_u32(XlnxZynqMPEFuse *s, unsigned int r_start, + unsigned int f_start, unsigned int f_end, + unsigned int f_written) +{ + uint32_t *u32 =3D &s->regs[r_start]; + unsigned int fbit, wbits =3D 0, u32_off =3D 0; + + /* Avoid working on bits that are not relevant. */ + if (f_written !=3D FBIT_UNKNOWN + && (f_written < f_start || f_written > f_end)) { + return; + } + + for (fbit =3D f_start; fbit <=3D f_end; fbit++, wbits++) { + if (wbits =3D=3D 32) { + /* Update the key offset. */ + u32_off +=3D 1; + wbits =3D 0; + } + u32[u32_off] |=3D xlnx_efuse_get_bit(s->efuse, fbit) << wbits; + } +} + +/* + * Keep the syncs in bit order so we can bail out for the + * slower ones. + */ +static void zynqmp_efuse_sync_cache(XlnxZynqMPEFuse *s, unsigned int bit) +{ + EFUSE_CACHE_BIT(s, SEC_CTRL, AES_RDLK); + EFUSE_CACHE_BIT(s, SEC_CTRL, AES_WRLK); + EFUSE_CACHE_BIT(s, SEC_CTRL, ENC_ONLY); + EFUSE_CACHE_BIT(s, SEC_CTRL, BBRAM_DIS); + EFUSE_CACHE_BIT(s, SEC_CTRL, ERROR_DIS); + EFUSE_CACHE_BIT(s, SEC_CTRL, JTAG_DIS); + EFUSE_CACHE_BIT(s, SEC_CTRL, DFT_DIS); + EFUSE_CACHE_BIT(s, SEC_CTRL, PROG_GATE_0); + EFUSE_CACHE_BIT(s, SEC_CTRL, PROG_GATE_1); + EFUSE_CACHE_BIT(s, SEC_CTRL, PROG_GATE_2); + EFUSE_CACHE_BIT(s, SEC_CTRL, SEC_LOCK); + EFUSE_CACHE_BIT(s, SEC_CTRL, PPK0_WRLK); + EFUSE_CACHE_BIT(s, SEC_CTRL, PPK1_WRLK); + + EFUSE_CACHE_FLD(s, SEC_CTRL, RSA_EN); + EFUSE_CACHE_FLD(s, SEC_CTRL, PPK0_INVLD); + EFUSE_CACHE_FLD(s, SEC_CTRL, PPK1_INVLD); + + /* Update the tbits. */ + update_tbit_status(s); + + /* Sync the various areas. */ + s->regs[R_MISC_USER_CTRL] =3D xlnx_efuse_get_row(s->efuse, + EFUSE_USER_CTRL_START) + & EFUSE_USER_CTRL_MASK; + s->regs[R_PUF_CHASH] =3D xlnx_efuse_get_row(s->efuse, EFUSE_PUF_CHASH_= START); + s->regs[R_PUF_MISC] =3D xlnx_efuse_get_row(s->efuse, EFUSE_PUF_MISC_S= TART); + + cache_sync_u32(s, R_DNA_0, EFUSE_DNA_START, EFUSE_DNA_END, bit); + + if (bit < EFUSE_AES_START) { + return; + } + + cache_sync_u32(s, R_ROM_RSVD, EFUSE_ROM_START, EFUSE_ROM_END, bit); + cache_sync_u32(s, R_IPDISABLE, EFUSE_IPDIS_START, EFUSE_IPDIS_END, bit= ); + cache_sync_u32(s, R_USER_0, EFUSE_USER_START, EFUSE_USER_END, bit); + cache_sync_u32(s, R_SPK_ID, EFUSE_SPK_START, EFUSE_SPK_END, bit); + cache_sync_u32(s, R_PPK0_0, EFUSE_PPK0_START, EFUSE_PPK0_END, bit); + cache_sync_u32(s, R_PPK1_0, EFUSE_PPK1_START, EFUSE_PPK1_END, bit); +} + +static void zynqmp_efuse_update_irq(XlnxZynqMPEFuse *s) +{ + bool pending =3D s->regs[R_EFUSE_ISR] & s->regs[R_EFUSE_IMR]; + qemu_set_irq(s->irq, pending); +} + +static void zynqmp_efuse_isr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + zynqmp_efuse_update_irq(s); +} + +static uint64_t zynqmp_efuse_ier_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_EFUSE_IMR] |=3D val; + zynqmp_efuse_update_irq(s); + return 0; +} + +static uint64_t zynqmp_efuse_idr_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_EFUSE_IMR] &=3D ~val; + zynqmp_efuse_update_irq(s); + return 0; +} + +static void zynqmp_efuse_pgm_addr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + unsigned bit =3D val64; + unsigned page =3D FIELD_EX32(bit, EFUSE_PGM_ADDR, EFUSE); + bool puf_prot =3D false; + const char *errmsg =3D NULL; + + /* Allow only valid array, and adjust for skipped array 1 */ + switch (page) { + case 0: + break; + case 2 ... 3: + bit =3D FIELD_DP32(bit, EFUSE_PGM_ADDR, EFUSE, page - 1); + puf_prot =3D xlnx_efuse_get_bit(s->efuse, EFUSE_PUF_SYN_WRLK); + break; + default: + errmsg =3D "Invalid address"; + goto pgm_done; + } + + if (ARRAY_FIELD_EX32(s->regs, WR_LOCK, LOCK)) { + errmsg =3D "Array write-locked"; + goto pgm_done; + } + + if (!ARRAY_FIELD_EX32(s->regs, CFG, PGM_EN)) { + errmsg =3D "Array pgm-disabled"; + goto pgm_done; + } + + if (puf_prot) { + errmsg =3D "PUF_HD-store write-locked"; + goto pgm_done; + } + + if (ARRAY_FIELD_EX32(s->regs, SEC_CTRL, AES_WRLK) + && bit >=3D EFUSE_AES_START && bit <=3D EFUSE_AES_END) { + errmsg =3D "AES key-store Write-locked"; + goto pgm_done; + } + + if (!xlnx_efuse_set_bit(s->efuse, bit)) { + errmsg =3D "Write failed"; + } + + pgm_done: + if (!errmsg) { + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, PGM_ERROR, 0); + } else { + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, PGM_ERROR, 1); + qemu_log_mask(LOG_GUEST_ERROR, + "%s - eFuse write error: %s; addr=3D0x%x\n", + object_get_canonical_path(OBJECT(s)), + errmsg, (unsigned)val64); + } + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, PGM_DONE, 1); + zynqmp_efuse_update_irq(s); +} + +static void zynqmp_efuse_rd_addr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + + /* + * Grant reads only to allowed bits; reference sources: + * 1/ XilSKey - XilSKey_ZynqMp_EfusePs_ReadRow() + * 2/ UG1085, v2.0, table 12-13 + * (note: enumerates the masks as per described in + * references to avoid mental translation). + */ +#define COL_MASK(L_, H_) \ + ((uint32_t)MAKE_64BIT_MASK((L_), (1 + (H_) - (L_)))) + + static const uint32_t ary0_col_mask[] =3D { + /* XilSKey - XSK_ZYNQMP_EFUSEPS_TBITS_ROW */ + [0] =3D COL_MASK(28, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_USR{0:7}_FUSE_ROW */ + [8] =3D COL_MASK(0, 31), [9] =3D COL_MASK(0, 31), + [10] =3D COL_MASK(0, 31), [11] =3D COL_MASK(0, 31), + [12] =3D COL_MASK(0, 31), [13] =3D COL_MASK(0, 31), + [14] =3D COL_MASK(0, 31), [15] =3D COL_MASK(0, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_MISC_USR_CTRL_ROW */ + [16] =3D COL_MASK(0, 7) | COL_MASK(10, 16), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_PBR_BOOT_ERR_ROW */ + [17] =3D COL_MASK(0, 2), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_PUF_CHASH_ROW */ + [20] =3D COL_MASK(0, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_PUF_AUX_ROW */ + [21] =3D COL_MASK(0, 23) | COL_MASK(29, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_SEC_CTRL_ROW */ + [22] =3D COL_MASK(0, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_SPK_ID_ROW */ + [23] =3D COL_MASK(0, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_PPK0_START_ROW */ + [40] =3D COL_MASK(0, 31), [41] =3D COL_MASK(0, 31), + [42] =3D COL_MASK(0, 31), [43] =3D COL_MASK(0, 31), + [44] =3D COL_MASK(0, 31), [45] =3D COL_MASK(0, 31), + [46] =3D COL_MASK(0, 31), [47] =3D COL_MASK(0, 31), + [48] =3D COL_MASK(0, 31), [49] =3D COL_MASK(0, 31), + [50] =3D COL_MASK(0, 31), [51] =3D COL_MASK(0, 31), + + /* XilSKey - XSK_ZYNQMP_EFUSEPS_PPK1_START_ROW */ + [52] =3D COL_MASK(0, 31), [53] =3D COL_MASK(0, 31), + [54] =3D COL_MASK(0, 31), [55] =3D COL_MASK(0, 31), + [56] =3D COL_MASK(0, 31), [57] =3D COL_MASK(0, 31), + [58] =3D COL_MASK(0, 31), [59] =3D COL_MASK(0, 31), + [60] =3D COL_MASK(0, 31), [61] =3D COL_MASK(0, 31), + [62] =3D COL_MASK(0, 31), [63] =3D COL_MASK(0, 31), + }; + + uint32_t col_mask =3D COL_MASK(0, 31); +#undef COL_MASK + + uint32_t efuse_idx =3D s->regs[R_EFUSE_RD_ADDR]; + uint32_t efuse_ary =3D FIELD_EX32(efuse_idx, EFUSE_RD_ADDR, EFUSE); + uint32_t efuse_row =3D FIELD_EX32(efuse_idx, EFUSE_RD_ADDR, ROW); + + switch (efuse_ary) { + case 0: /* Various */ + if (efuse_row >=3D ARRAY_SIZE(ary0_col_mask)) { + goto denied; + } + + col_mask =3D ary0_col_mask[efuse_row]; + if (!col_mask) { + goto denied; + } + break; + case 2: /* PUF helper data, adjust for skipped array 1 */ + case 3: + val64 =3D FIELD_DP32(efuse_idx, EFUSE_RD_ADDR, EFUSE, efuse_ary - = 1); + break; + default: + goto denied; + } + + s->regs[R_EFUSE_RD_DATA] =3D xlnx_efuse_get_row(s->efuse, val64) & col= _mask; + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_ERROR, 0); + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_DONE, 1); + zynqmp_efuse_update_irq(s); + return; + + denied: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Denied efuse read from array %u, row %u\n", + object_get_canonical_path(OBJECT(s)), + efuse_ary, efuse_row); + + s->regs[R_EFUSE_RD_DATA] =3D 0; + + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_ERROR, 1); + ARRAY_FIELD_DP32(s->regs, EFUSE_ISR, RD_DONE, 0); + zynqmp_efuse_update_irq(s); +} + +static void zynqmp_efuse_aes_crc_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + bool ok; + + ok =3D xlnx_efuse_k256_check(s->efuse, (uint32_t)val64, EFUSE_AES_STAR= T); + + ARRAY_FIELD_DP32(s->regs, STATUS, AES_CRC_PASS, (ok ? 1 : 0)); + ARRAY_FIELD_DP32(s->regs, STATUS, AES_CRC_DONE, 1); + + s->regs[R_EFUSE_AES_CRC] =3D 0; /* crc value is write-only */ +} + +static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg, + uint64_t valu64) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(reg->opaque); + + if (valu64 & R_EFUSE_CACHE_LOAD_LOAD_MASK) { + zynqmp_efuse_sync_cache(s, FBIT_UNKNOWN); + ARRAY_FIELD_DP32(s->regs, STATUS, CACHE_DONE, 1); + zynqmp_efuse_update_irq(s); + } + + return 0; +} + +static uint64_t zynqmp_efuse_wr_lock_prew(RegisterInfo *reg, uint64_t val) +{ + return val =3D=3D 0xDF0D ? 0 : 1; +} + +static RegisterAccessInfo zynqmp_efuse_regs_info[] =3D { + { .name =3D "WR_LOCK", .addr =3D A_WR_LOCK, + .reset =3D 0x1, + .pre_write =3D zynqmp_efuse_wr_lock_prew, + },{ .name =3D "CFG", .addr =3D A_CFG, + },{ .name =3D "STATUS", .addr =3D A_STATUS, + .rsvd =3D 0x8, + .ro =3D 0xff, + },{ .name =3D "EFUSE_PGM_ADDR", .addr =3D A_EFUSE_PGM_ADDR, + .post_write =3D zynqmp_efuse_pgm_addr_postw + },{ .name =3D "EFUSE_RD_ADDR", .addr =3D A_EFUSE_RD_ADDR, + .rsvd =3D 0x1f, + .post_write =3D zynqmp_efuse_rd_addr_postw, + },{ .name =3D "EFUSE_RD_DATA", .addr =3D A_EFUSE_RD_DATA, + .ro =3D 0xffffffff, + },{ .name =3D "TPGM", .addr =3D A_TPGM, + },{ .name =3D "TRD", .addr =3D A_TRD, + .reset =3D 0x1b, + },{ .name =3D "TSU_H_PS", .addr =3D A_TSU_H_PS, + .reset =3D 0xff, + },{ .name =3D "TSU_H_PS_CS", .addr =3D A_TSU_H_PS_CS, + .reset =3D 0xb, + },{ .name =3D "TSU_H_CS", .addr =3D A_TSU_H_CS, + .reset =3D 0x7, + },{ .name =3D "EFUSE_ISR", .addr =3D A_EFUSE_ISR, + .rsvd =3D 0x7fffffe0, + .w1c =3D 0x8000001f, + .post_write =3D zynqmp_efuse_isr_postw, + },{ .name =3D "EFUSE_IMR", .addr =3D A_EFUSE_IMR, + .reset =3D 0x8000001f, + .rsvd =3D 0x7fffffe0, + .ro =3D 0xffffffff, + },{ .name =3D "EFUSE_IER", .addr =3D A_EFUSE_IER, + .rsvd =3D 0x7fffffe0, + .pre_write =3D zynqmp_efuse_ier_prew, + },{ .name =3D "EFUSE_IDR", .addr =3D A_EFUSE_IDR, + .rsvd =3D 0x7fffffe0, + .pre_write =3D zynqmp_efuse_idr_prew, + },{ .name =3D "EFUSE_CACHE_LOAD", .addr =3D A_EFUSE_CACHE_LOAD, + .pre_write =3D zynqmp_efuse_cache_load_prew, + },{ .name =3D "EFUSE_PGM_LOCK", .addr =3D A_EFUSE_PGM_LOCK, + },{ .name =3D "EFUSE_AES_CRC", .addr =3D A_EFUSE_AES_CRC, + .post_write =3D zynqmp_efuse_aes_crc_postw, + },{ .name =3D "EFUSE_TBITS_PRGRMG_EN", .addr =3D A_EFUSE_TBITS_PRGRMG= _EN, + .reset =3D R_EFUSE_TBITS_PRGRMG_EN_TBITS_PRGRMG_EN_MASK, + },{ .name =3D "DNA_0", .addr =3D A_DNA_0, + .ro =3D 0xffffffff, + },{ .name =3D "DNA_1", .addr =3D A_DNA_1, + .ro =3D 0xffffffff, + },{ .name =3D "DNA_2", .addr =3D A_DNA_2, + .ro =3D 0xffffffff, + },{ .name =3D "IPDISABLE", .addr =3D A_IPDISABLE, + .ro =3D 0xffffffff, + },{ .name =3D "SYSOSC_CTRL", .addr =3D A_SYSOSC_CTRL, + .ro =3D 0xffffffff, + },{ .name =3D "USER_0", .addr =3D A_USER_0, + .ro =3D 0xffffffff, + },{ .name =3D "USER_1", .addr =3D A_USER_1, + .ro =3D 0xffffffff, + },{ .name =3D "USER_2", .addr =3D A_USER_2, + .ro =3D 0xffffffff, + },{ .name =3D "USER_3", .addr =3D A_USER_3, + .ro =3D 0xffffffff, + },{ .name =3D "USER_4", .addr =3D A_USER_4, + .ro =3D 0xffffffff, + },{ .name =3D "USER_5", .addr =3D A_USER_5, + .ro =3D 0xffffffff, + },{ .name =3D "USER_6", .addr =3D A_USER_6, + .ro =3D 0xffffffff, + },{ .name =3D "USER_7", .addr =3D A_USER_7, + .ro =3D 0xffffffff, + },{ .name =3D "MISC_USER_CTRL", .addr =3D A_MISC_USER_CTRL, + .ro =3D 0xffffffff, + },{ .name =3D "ROM_RSVD", .addr =3D A_ROM_RSVD, + .ro =3D 0xffffffff, + },{ .name =3D "PUF_CHASH", .addr =3D A_PUF_CHASH, + .ro =3D 0xffffffff, + },{ .name =3D "PUF_MISC", .addr =3D A_PUF_MISC, + .ro =3D 0xffffffff, + },{ .name =3D "SEC_CTRL", .addr =3D A_SEC_CTRL, + .ro =3D 0xffffffff, + },{ .name =3D "SPK_ID", .addr =3D A_SPK_ID, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_0", .addr =3D A_PPK0_0, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_1", .addr =3D A_PPK0_1, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_2", .addr =3D A_PPK0_2, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_3", .addr =3D A_PPK0_3, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_4", .addr =3D A_PPK0_4, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_5", .addr =3D A_PPK0_5, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_6", .addr =3D A_PPK0_6, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_7", .addr =3D A_PPK0_7, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_8", .addr =3D A_PPK0_8, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_9", .addr =3D A_PPK0_9, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_10", .addr =3D A_PPK0_10, + .ro =3D 0xffffffff, + },{ .name =3D "PPK0_11", .addr =3D A_PPK0_11, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_0", .addr =3D A_PPK1_0, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_1", .addr =3D A_PPK1_1, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_2", .addr =3D A_PPK1_2, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_3", .addr =3D A_PPK1_3, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_4", .addr =3D A_PPK1_4, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_5", .addr =3D A_PPK1_5, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_6", .addr =3D A_PPK1_6, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_7", .addr =3D A_PPK1_7, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_8", .addr =3D A_PPK1_8, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_9", .addr =3D A_PPK1_9, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_10", .addr =3D A_PPK1_10, + .ro =3D 0xffffffff, + },{ .name =3D "PPK1_11", .addr =3D A_PPK1_11, + .ro =3D 0xffffffff, + } +}; + +static void zynqmp_efuse_reg_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + RegisterInfoArray *reg_array =3D opaque; + XlnxZynqMPEFuse *s; + Object *dev; + + assert(reg_array !=3D NULL); + + dev =3D reg_array->mem.owner; + assert(dev); + + s =3D XLNX_ZYNQMP_EFUSE(dev); + + if (addr !=3D A_WR_LOCK && s->regs[R_WR_LOCK]) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s[reg_0x%02lx]: Attempt to write locked register.\= n", + object_get_canonical_path(OBJECT(s)), (long)addr); + } else { + register_write_memory(opaque, addr, data, size); + } +} + +static const MemoryRegionOps zynqmp_efuse_ops =3D { + .read =3D register_read_memory, + .write =3D zynqmp_efuse_reg_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void zynqmp_efuse_register_reset(RegisterInfo *reg) +{ + if (!reg->data || !reg->access) { + return; + } + + /* Reset must not trigger some registers' writers */ + switch (reg->access->addr) { + case A_EFUSE_AES_CRC: + *(uint32_t *)reg->data =3D reg->access->reset; + return; + } + + register_reset(reg); +} + +static void zynqmp_efuse_reset(DeviceState *dev) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(dev); + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(s->regs_info); ++i) { + zynqmp_efuse_register_reset(&s->regs_info[i]); + } + + zynqmp_efuse_sync_cache(s, FBIT_UNKNOWN); + ARRAY_FIELD_DP32(s->regs, STATUS, CACHE_DONE, 1); + zynqmp_efuse_update_irq(s); +} + +static void zynqmp_efuse_realize(DeviceState *dev, Error **errp) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(dev); + + if (!s->efuse) { + error_setg(errp, "%s.efuse: link property not connected to XLNX-EF= USE", + object_get_canonical_path(OBJECT(dev))); + return; + } + + s->efuse->dev =3D dev; +} + +static void zynqmp_efuse_init(Object *obj) +{ + XlnxZynqMPEFuse *s =3D XLNX_ZYNQMP_EFUSE(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + RegisterInfoArray *reg_array; + + reg_array =3D + register_init_block32(DEVICE(obj), zynqmp_efuse_regs_info, + ARRAY_SIZE(zynqmp_efuse_regs_info), + s->regs_info, s->regs, + &zynqmp_efuse_ops, + ZYNQMP_EFUSE_ERR_DEBUG, + R_MAX * 4); + + sysbus_init_mmio(sbd, ®_array->mem); + sysbus_init_irq(sbd, &s->irq); +} + +static const VMStateDescription vmstate_efuse =3D { + .name =3D TYPE_XLNX_ZYNQMP_EFUSE, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPEFuse, R_MAX), + VMSTATE_END_OF_LIST(), + } +}; + +static Property zynqmp_efuse_props[] =3D { + DEFINE_PROP_LINK("efuse", + XlnxZynqMPEFuse, efuse, + TYPE_XLNX_EFUSE, XlnxEFuse *), + + DEFINE_PROP_END_OF_LIST(), +}; + +static void zynqmp_efuse_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D zynqmp_efuse_reset; + dc->realize =3D zynqmp_efuse_realize; + dc->vmsd =3D &vmstate_efuse; + device_class_set_props(dc, zynqmp_efuse_props); +} + + +static const TypeInfo efuse_info =3D { + .name =3D TYPE_XLNX_ZYNQMP_EFUSE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(XlnxZynqMPEFuse), + .class_init =3D zynqmp_efuse_class_init, + .instance_init =3D zynqmp_efuse_init, +}; + +static void efuse_register_types(void) +{ + type_register_static(&efuse_info); +} + +type_init(efuse_register_types) diff --git a/include/hw/nvram/xlnx-zynqmp-efuse.h b/include/hw/nvram/xlnx-z= ynqmp-efuse.h new file mode 100644 index 0000000000..6b051ec4f1 --- /dev/null +++ b/include/hw/nvram/xlnx-zynqmp-efuse.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef XLNX_ZYNQMP_EFUSE_H +#define XLNX_ZYNQMP_EFUSE_H + +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "hw/register.h" +#include "hw/nvram/xlnx-efuse.h" + +#define XLNX_ZYNQMP_EFUSE_R_MAX ((0x10fc / 4) + 1) + +#define TYPE_XLNX_ZYNQMP_EFUSE "xlnx,zynqmp-efuse" +OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPEFuse, XLNX_ZYNQMP_EFUSE); + +struct XlnxZynqMPEFuse { + SysBusDevice parent_obj; + qemu_irq irq; + + XlnxEFuse *efuse; + uint32_t regs[XLNX_ZYNQMP_EFUSE_R_MAX]; + RegisterInfo regs_info[XLNX_ZYNQMP_EFUSE_R_MAX]; +}; + +#endif --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856518; cv=pass; d=zohomail.com; s=zohoarc; b=dgZMiKQU56v5jcagWJAbBUMDc67+J2jbPUcxZ1NeO5gcTTwHuV6PMdj0ujRrbO2Hu9rRolEgR7iAV3ou6SAe6t7o2cY4LqenwlxmzM93xcD0SqtHAk/DKxvrzub2ITzgSf3PrgDHVsXG3f2ycPGVGG1G9ZzEg4cdYhoDzjB+g4w= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856518; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nSjXeQCzo2EkisNx4X5thRA0ydl2xZWy3jPz6wrX0qA=; b=SWk5nBUfdL2Upz+YEnQIkg9hvNthIoRi1w0ecwySB6XOWt5pJpY0tnTUktjH9owBZtgmQ3eAPLBiY++rbwnkeJpzPWC1iRWgCPEtCpSaZ+xhwfZ7hwSX8ev1vJPMKHg9rgg9E9Cu2MBLERuSUSo/Cj6jW9mTtpHUyY4n5tMt4fg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856518876676.0434372420425; Thu, 16 Sep 2021 22:28:38 -0700 (PDT) Received: from localhost ([::1]:38000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6QP-0006xO-NM for importer@patchew.org; Fri, 17 Sep 2021 01:28:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MW-0003Vd-Ry; Fri, 17 Sep 2021 01:24:36 -0400 Received: from mail-co1nam11on2074.outbound.protection.outlook.com ([40.107.220.74]:13537 helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MT-0006FA-Du; Fri, 17 Sep 2021 01:24:36 -0400 Received: from BN9PR03CA0694.namprd03.prod.outlook.com (2603:10b6:408:ef::9) by BY5PR02MB6470.namprd02.prod.outlook.com (2603:10b6:a03:1dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Fri, 17 Sep 2021 05:24:28 +0000 Received: from BN1NAM02FT049.eop-nam02.prod.protection.outlook.com (2603:10b6:408:ef:cafe::cc) by BN9PR03CA0694.outlook.office365.com (2603:10b6:408:ef::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:28 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT049.mail.protection.outlook.com (10.13.2.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:28 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:00 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-TB; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XoecXDz/yRM/YIS9MPtqeK97FhCYtwfZ7IevIUxUb8WHb6sVXpfK3tDYFSccAwTRBnt/RLRTK/rFFvMVaWonQBh+4tE9LfA+k4SW4NKFfpgtgtpZPNHaunM0olCSIc2RrFGTYyLPCl2ofsdmCmwFrLgA2F5U1xIQvJB/Ytvt2sezS/8jOcxJn075uOrY6m9QBUO7t603fHelgmWEYmjnN1VWrtSoqg+OWBaKiNjXZNXeV5ad8Rk9zYMk3KubNMTURV+bE3qrvKAhZXCgLVwSYxNKu0Tbz5Eg4ueYlLPH8eJapfGllI1wy8UcvNCsPQ/o5SWJf4nJwGAViC8R3/knhQ== 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; bh=nSjXeQCzo2EkisNx4X5thRA0ydl2xZWy3jPz6wrX0qA=; b=oVufXiRfuCdzoR3d/Kae4RIqy50I5dzKfktLIth56TqVg7zEWS+wYwOs6VjNSqvZL40dWlVbANp66nACpc2UjrkHY0JxXkm+RgUcLnpmhAg6FkFYgi2RaM1oU+GMpvcoVz+SMMfLkqeZQyKVIPOva8VK54zw/5EhQLv0musgp0boXFQP9SNC6bRCpjcnFWBVeEFaRl4nQzBmApgRtrqJElw+7d1rHyP4+IIa73uJC9ZfA3EI5DE7qfCpoEoxHJnaYxHKK2mUaJWmTEPGH6pBgsyn/LeNAEwpNckE5mv6m0hXeeMy1CNW/yGSvB6KtR4FXG18oQaNd/dqh0lphkoe7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nSjXeQCzo2EkisNx4X5thRA0ydl2xZWy3jPz6wrX0qA=; b=QYxTlYQORuXvhW3HXy6BmwFXZ85aNykBy65BpFfCl6Xvgv3w9wUzvOo9ZvV/pIOQKjRMfQwcf7rwvKiMrc5ZMFljAVvZAu8lTKruoIqtjL7UZPJ4d7cw0pTy+bKdh0N4+xcys9pFN7gS5neRQ8hyF+0nVELVywSFDbO57yW1Zhc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 4/9] hw/nvram: Introduce Xilinx battery-backed ram Date: Thu, 16 Sep 2021 22:23:55 -0700 Message-ID: <20210917052400.1249094-5-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4874d6b4-8671-44ab-ff59-08d9799b6bb9 X-MS-TrafficTypeDiagnostic: BY5PR02MB6470: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:568; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yy/DMKEF7nGdGDJ8NaatlF4UDqfvsnPWFDRKtFU/+eomy8bLNKSVw9wa7MuncXHWCp0RWLXpIOvEb2RiwZwTnh8X0Czq5FcprvrIrE5dSpDMEkzkQAmOY+tZyd4Qx84Zlzvd3BG45N2hsY52/QvjgWyQ16xNHdJ6vdt/QoL9WHGQT1hsas6lskQ4tmBuwmRx0OZ2Mcx8QgNYt5oRa5GYw4MX8+PmT+ghDlrHWz/fgFb83iPQB6N7e51bv5ZYqcp6jSq0IHFF1BDpltg7olQDXOYlBjfH8rSP2CtQepbuR6eCgSHxNrqulS7B7Hlo+Ko/XjyYQ1ONCtc9XD6XXOwjWkNHRJWEEWffHyNLjjwe2eOVdm+Q+hkW1cvcHfuajdSIErJXoJcb03fj81jsFIxGkTg4uHO/nn/vKRs78sW/AZAEs208yLZsoNCrSWiIkM3lA2bBh1RKlshfBFEJMfm1G8HdMoBTbSJS4kW145gu1q6b+oZTNOEgjjLhfoASjjjZCH4LvTaqiTrzZ7sNnRzcM0GEbcg2ICF9BSOeW7QdEMZCKOgC/sBjkanhymLfSuc1cadHsf4icfZwHBL79i9O3qXn9/m0Ng3ThVtExi8+BltgNJt6/7TRx3JdQtw20GzNSDWicYtPi32qS4PwiR/C6ZX1A3sZo9D9lxYyOh8XtNbGfdjplOD6bcy+e5YMXb2xTV1RDQKvw9minD4CW64j0zlUPG2gyL8crUmExClFuGcm1D5TfS0H/kWPh6Z+hKvVYrD1W9L9Mig0HVOhwldhV6FYJWjIVNyHgjQs8wH8xDTT6L90BOlkWSgrfGaO3JTc X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch01.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(82310400003)(6666004)(508600001)(54906003)(70206006)(8936002)(7696005)(70586007)(9786002)(6916009)(44832011)(30864003)(107886003)(4326008)(36756003)(5660300002)(26005)(426003)(1076003)(356005)(7636003)(186003)(2616005)(8676002)(2906002)(83380400001)(966005)(36906005)(316002)(36860700001)(336012)(47076005)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:28.2399 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4874d6b4-8671-44ab-ff59-08d9799b6bb9 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT049.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6470 Received-SPF: pass client-ip=40.107.220.74; envelope-from=tongh@xilinx.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856520754100001 Content-Type: text/plain; charset="utf-8" This device is present in Versal and ZynqMP product families to store a 256-bit encryption key. Co-authored-by: Edgar E. Iglesias Co-authored-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Sai Pavan Boddu Signed-off-by: Tong Ho --- hw/nvram/Kconfig | 4 + hw/nvram/meson.build | 1 + hw/nvram/xlnx-bbram.c | 545 ++++++++++++++++++++++++++++++++++ include/hw/nvram/xlnx-bbram.h | 54 ++++ 4 files changed, 604 insertions(+) create mode 100644 hw/nvram/xlnx-bbram.c create mode 100644 include/hw/nvram/xlnx-bbram.h diff --git a/hw/nvram/Kconfig b/hw/nvram/Kconfig index 3059c5dae0..24cfc18f8b 100644 --- a/hw/nvram/Kconfig +++ b/hw/nvram/Kconfig @@ -30,3 +30,7 @@ config XLNX_EFUSE_VERSAL config XLNX_EFUSE_ZYNQMP bool select XLNX_EFUSE + +config XLNX_BBRAM + bool + select XLNX_EFUSE_CRC diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build index 6dc54d9873..202a5466e6 100644 --- a/hw/nvram/meson.build +++ b/hw/nvram/meson.build @@ -16,5 +16,6 @@ softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_VERSAL', if_true:= files( 'xlnx-versal-efuse-ctrl= .c')) softmmu_ss.add(when: 'CONFIG_XLNX_EFUSE_ZYNQMP', if_true: files( 'xlnx-zynqmp-efuse.c')) +softmmu_ss.add(when: 'CONFIG_XLNX_BBRAM', if_true: files('xlnx-bbram.c')) =20 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c new file mode 100644 index 0000000000..b70828e5bf --- /dev/null +++ b/hw/nvram/xlnx-bbram.c @@ -0,0 +1,545 @@ +/* + * QEMU model of the Xilinx BBRAM Battery Backed RAM + * + * Copyright (c) 2014-2021 Xilinx Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/nvram/xlnx-bbram.h" + +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "sysemu/blockdev.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "hw/nvram/xlnx-efuse.h" + +#ifndef XLNX_BBRAM_ERR_DEBUG +#define XLNX_BBRAM_ERR_DEBUG 0 +#endif + +REG32(BBRAM_STATUS, 0x0) + FIELD(BBRAM_STATUS, AES_CRC_PASS, 9, 1) + FIELD(BBRAM_STATUS, AES_CRC_DONE, 8, 1) + FIELD(BBRAM_STATUS, BBRAM_ZEROIZED, 4, 1) + FIELD(BBRAM_STATUS, PGM_MODE, 0, 1) +REG32(BBRAM_CTRL, 0x4) + FIELD(BBRAM_CTRL, ZEROIZE, 0, 1) +REG32(PGM_MODE, 0x8) +REG32(BBRAM_AES_CRC, 0xc) +REG32(BBRAM_0, 0x10) +REG32(BBRAM_1, 0x14) +REG32(BBRAM_2, 0x18) +REG32(BBRAM_3, 0x1c) +REG32(BBRAM_4, 0x20) +REG32(BBRAM_5, 0x24) +REG32(BBRAM_6, 0x28) +REG32(BBRAM_7, 0x2c) +REG32(BBRAM_8, 0x30) +REG32(BBRAM_SLVERR, 0x34) + FIELD(BBRAM_SLVERR, ENABLE, 0, 1) +REG32(BBRAM_ISR, 0x38) + FIELD(BBRAM_ISR, APB_SLVERR, 0, 1) +REG32(BBRAM_IMR, 0x3c) + FIELD(BBRAM_IMR, APB_SLVERR, 0, 1) +REG32(BBRAM_IER, 0x40) + FIELD(BBRAM_IER, APB_SLVERR, 0, 1) +REG32(BBRAM_IDR, 0x44) + FIELD(BBRAM_IDR, APB_SLVERR, 0, 1) +REG32(BBRAM_MSW_LOCK, 0x4c) + FIELD(BBRAM_MSW_LOCK, VAL, 0, 1) + +#define R_MAX (R_BBRAM_MSW_LOCK + 1) + +#define RAM_MAX (A_BBRAM_8 + 4 - A_BBRAM_0) + +#define BBRAM_PGM_MAGIC 0x757bdf0d + +QEMU_BUILD_BUG_ON(R_MAX !=3D ARRAY_SIZE(((XlnxBBRam *)0)->regs)); + +static bool bbram_msw_locked(XlnxBBRam *s) +{ + return ARRAY_FIELD_EX32(s->regs, BBRAM_MSW_LOCK, VAL) !=3D 0; +} + +static bool bbram_pgm_enabled(XlnxBBRam *s) +{ + return ARRAY_FIELD_EX32(s->regs, BBRAM_STATUS, PGM_MODE) !=3D 0; +} + +static void bbram_bdrv_error(XlnxBBRam *s, int rc, gchar *detail) +{ + Error *errp; + + error_setg_errno(&errp, -rc, "%s: BBRAM backstore %s failed.", + blk_name(s->blk), detail); + error_report("%s", error_get_pretty(errp)); + error_free(errp); + + g_free(detail); +} + +static void bbram_bdrv_read(XlnxBBRam *s, Error **errp) +{ + uint32_t *ram =3D &s->regs[R_BBRAM_0]; + int nr =3D RAM_MAX; + + if (!s->blk) { + return; + } + + s->blk_ro =3D !blk_supports_write_perm(s->blk); + if (!s->blk_ro) { + int rc; + + rc =3D blk_set_perm(s->blk, + (BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE), + BLK_PERM_ALL, NULL); + if (rc) { + s->blk_ro =3D true; + } + } + if (s->blk_ro) { + warn_report("%s: Skip saving updates to read-only BBRAM backstore.= ", + blk_name(s->blk)); + } + + if (blk_pread(s->blk, 0, ram, nr) < 0) { + error_setg(errp, + "%s: Failed to read %u bytes from BBRAM backstore.", + blk_name(s->blk), nr); + return; + } + + /* Convert from little-endian backstore for each 32-bit word */ + nr /=3D 4; + while (nr--) { + ram[nr] =3D le32_to_cpu(ram[nr]); + } +} + +static void bbram_bdrv_sync(XlnxBBRam *s, uint64_t hwaddr) +{ + uint32_t le32; + unsigned offset; + int rc; + + assert(A_BBRAM_0 <=3D hwaddr && hwaddr <=3D A_BBRAM_8); + + /* Backstore is always in little-endian */ + le32 =3D cpu_to_le32(s->regs[hwaddr / 4]); + + /* Update zeroized flag */ + if (le32 && (hwaddr !=3D A_BBRAM_8 || s->bbram8_wo)) { + ARRAY_FIELD_DP32(s->regs, BBRAM_STATUS, BBRAM_ZEROIZED, 0); + } + + if (!s->blk || s->blk_ro) { + return; + } + + offset =3D hwaddr - A_BBRAM_0; + rc =3D blk_pwrite(s->blk, offset, &le32, 4, 0); + if (rc < 0) { + bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offs= et)); + } +} + +static void bbram_bdrv_zero(XlnxBBRam *s) +{ + int rc; + + ARRAY_FIELD_DP32(s->regs, BBRAM_STATUS, BBRAM_ZEROIZED, 1); + + if (!s->blk || s->blk_ro) { + return; + } + + rc =3D blk_make_zero(s->blk, 0); + if (rc < 0) { + bbram_bdrv_error(s, rc, g_strdup("zeroizing")); + } + + /* Restore bbram8 if it is non-zero */ + if (s->regs[R_BBRAM_8]) { + bbram_bdrv_sync(s, A_BBRAM_8); + } +} + +static void bbram_zeroize(XlnxBBRam *s) +{ + int nr =3D RAM_MAX - (s->bbram8_wo ? 0 : 4); /* only wo bbram8 is clea= red */ + + memset(&s->regs[R_BBRAM_0], 0, nr); + bbram_bdrv_zero(s); +} + +static void bbram_update_irq(XlnxBBRam *s) +{ + bool pending =3D s->regs[R_BBRAM_ISR] & ~s->regs[R_BBRAM_IMR]; + + qemu_set_irq(s->irq_bbram, pending); +} + +static void bbram_ctrl_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t val =3D val64; + + if (val & R_BBRAM_CTRL_ZEROIZE_MASK) { + bbram_zeroize(s); + /* The bit is self clearing */ + s->regs[R_BBRAM_CTRL] &=3D ~R_BBRAM_CTRL_ZEROIZE_MASK; + } +} + +static void bbram_pgm_mode_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t val =3D val64; + + if (val =3D=3D BBRAM_PGM_MAGIC) { + bbram_zeroize(s); + + /* The status bit is cleared only by POR */ + ARRAY_FIELD_DP32(s->regs, BBRAM_STATUS, PGM_MODE, 1); + } +} + +static void bbram_aes_crc_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t calc_crc; + + if (!bbram_pgm_enabled(s)) { + /* We are not in programming mode, don't do anything */ + return; + } + + /* Perform the AES integrity check */ + s->regs[R_BBRAM_STATUS] |=3D R_BBRAM_STATUS_AES_CRC_DONE_MASK; + + /* + * Set check status. + * + * ZynqMP BBRAM check has a zero-u32 prepended; see: + * https://github.com/Xilinx/embeddedsw/blob/release-2019.2/lib/sw_se= rvices/xilskey/src/xilskey_bbramps_zynqmp.c#L311 + */ + calc_crc =3D xlnx_efuse_calc_crc(&s->regs[R_BBRAM_0], + (R_BBRAM_8 - R_BBRAM_0), s->crc_zpads); + + ARRAY_FIELD_DP32(s->regs, BBRAM_STATUS, AES_CRC_PASS, + (s->regs[R_BBRAM_AES_CRC] =3D=3D calc_crc)); +} + +static uint64_t bbram_key_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t original_data =3D *(uint32_t *) reg->data; + + if (bbram_pgm_enabled(s)) { + return val64; + } else { + /* We are not in programming mode, don't do anything */ + qemu_log_mask(LOG_GUEST_ERROR, + "Not in programming mode, dropping the write\n"); + return original_data; + } +} + +static void bbram_key_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + bbram_bdrv_sync(s, reg->access->addr); +} + +static uint64_t bbram_wo_postr(RegisterInfo *reg, uint64_t val) +{ + return 0; +} + +static uint64_t bbram_r8_postr(RegisterInfo *reg, uint64_t val) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + return s->bbram8_wo ? bbram_wo_postr(reg, val) : val; +} + +static bool bbram_r8_readonly(XlnxBBRam *s) +{ + return !bbram_pgm_enabled(s) || bbram_msw_locked(s); +} + +static uint64_t bbram_r8_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + if (bbram_r8_readonly(s)) { + val64 =3D *(uint32_t *)reg->data; + } + + return val64; +} + +static void bbram_r8_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + if (!bbram_r8_readonly(s)) { + bbram_bdrv_sync(s, A_BBRAM_8); + } +} + +static uint64_t bbram_msw_lock_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + /* Never lock if bbram8 is wo; and, only POR can clear the lock */ + if (s->bbram8_wo) { + val64 =3D 0; + } else { + val64 |=3D s->regs[R_BBRAM_MSW_LOCK]; + } + + return val64; +} + +static void bbram_isr_postw(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + + bbram_update_irq(s); +} + +static uint64_t bbram_ier_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_BBRAM_IMR] &=3D ~val; + bbram_update_irq(s); + return 0; +} + +static uint64_t bbram_idr_prew(RegisterInfo *reg, uint64_t val64) +{ + XlnxBBRam *s =3D XLNX_BBRAM(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_BBRAM_IMR] |=3D val; + bbram_update_irq(s); + return 0; +} + +static RegisterAccessInfo bbram_ctrl_regs_info[] =3D { + { .name =3D "BBRAM_STATUS", .addr =3D A_BBRAM_STATUS, + .rsvd =3D 0xee, + .ro =3D 0x3ff, + },{ .name =3D "BBRAM_CTRL", .addr =3D A_BBRAM_CTRL, + .post_write =3D bbram_ctrl_postw, + },{ .name =3D "PGM_MODE", .addr =3D A_PGM_MODE, + .post_write =3D bbram_pgm_mode_postw, + },{ .name =3D "BBRAM_AES_CRC", .addr =3D A_BBRAM_AES_CRC, + .post_write =3D bbram_aes_crc_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_0", .addr =3D A_BBRAM_0, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_1", .addr =3D A_BBRAM_1, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_2", .addr =3D A_BBRAM_2, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_3", .addr =3D A_BBRAM_3, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_4", .addr =3D A_BBRAM_4, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_5", .addr =3D A_BBRAM_5, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_6", .addr =3D A_BBRAM_6, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_7", .addr =3D A_BBRAM_7, + .pre_write =3D bbram_key_prew, + .post_write =3D bbram_key_postw, + .post_read =3D bbram_wo_postr, + },{ .name =3D "BBRAM_8", .addr =3D A_BBRAM_8, + .pre_write =3D bbram_r8_prew, + .post_write =3D bbram_r8_postw, + .post_read =3D bbram_r8_postr, + },{ .name =3D "BBRAM_SLVERR", .addr =3D A_BBRAM_SLVERR, + .rsvd =3D ~1, + },{ .name =3D "BBRAM_ISR", .addr =3D A_BBRAM_ISR, + .w1c =3D 0x1, + .post_write =3D bbram_isr_postw, + },{ .name =3D "BBRAM_IMR", .addr =3D A_BBRAM_IMR, + .ro =3D 0x1, + },{ .name =3D "BBRAM_IER", .addr =3D A_BBRAM_IER, + .pre_write =3D bbram_ier_prew, + },{ .name =3D "BBRAM_IDR", .addr =3D A_BBRAM_IDR, + .pre_write =3D bbram_idr_prew, + },{ .name =3D "BBRAM_MSW_LOCK", .addr =3D A_BBRAM_MSW_LOCK, + .pre_write =3D bbram_msw_lock_prew, + .ro =3D ~R_BBRAM_MSW_LOCK_VAL_MASK, + } +}; + +static void bbram_ctrl_reset(DeviceState *dev) +{ + XlnxBBRam *s =3D XLNX_BBRAM(dev); + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(s->regs_info); ++i) { + if (i < R_BBRAM_0 || i > R_BBRAM_8) { + register_reset(&s->regs_info[i]); + } + } + + bbram_update_irq(s); +} + +static const MemoryRegionOps bbram_ctrl_ops =3D { + .read =3D register_read_memory, + .write =3D register_write_memory, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void bbram_ctrl_realize(DeviceState *dev, Error **errp) +{ + XlnxBBRam *s =3D XLNX_BBRAM(dev); + + if (s->crc_zpads) { + s->bbram8_wo =3D true; + } + + bbram_bdrv_read(s, errp); +} + +static void bbram_ctrl_init(Object *obj) +{ + XlnxBBRam *s =3D XLNX_BBRAM(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + RegisterInfoArray *reg_array; + + reg_array =3D + register_init_block32(DEVICE(obj), bbram_ctrl_regs_info, + ARRAY_SIZE(bbram_ctrl_regs_info), + s->regs_info, s->regs, + &bbram_ctrl_ops, + XLNX_BBRAM_ERR_DEBUG, + R_MAX * 4); + + sysbus_init_mmio(sbd, ®_array->mem); + sysbus_init_irq(sbd, &s->irq_bbram); +} + +static void bbram_prop_set_drive(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev =3D DEVICE(obj); + + qdev_prop_drive.set(obj, v, name, opaque, errp); + + /* Fill initial data if backend is attached after realized */ + if (dev->realized) { + bbram_bdrv_read(XLNX_BBRAM(obj), errp); + } +} + +static void bbram_prop_get_drive(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + qdev_prop_drive.get(obj, v, name, opaque, errp); +} + +static void bbram_prop_release_drive(Object *obj, const char *name, + void *opaque) +{ + qdev_prop_drive.release(obj, name, opaque); +} + +static const PropertyInfo bbram_prop_drive =3D { + .name =3D "str", + .description =3D "Node name or ID of a block device to use as BBRAM ba= ckend", + .realized_set_allowed =3D true, + .get =3D bbram_prop_get_drive, + .set =3D bbram_prop_set_drive, + .release =3D bbram_prop_release_drive, +}; + +static const VMStateDescription vmstate_bbram_ctrl =3D { + .name =3D TYPE_XLNX_BBRAM, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, XlnxBBRam, R_MAX), + VMSTATE_END_OF_LIST(), + } +}; + +static Property bbram_ctrl_props[] =3D { + DEFINE_PROP("drive", XlnxBBRam, blk, bbram_prop_drive, BlockBackend *), + DEFINE_PROP_UINT32("crc-zpads", XlnxBBRam, crc_zpads, 1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void bbram_ctrl_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D bbram_ctrl_reset; + dc->realize =3D bbram_ctrl_realize; + dc->vmsd =3D &vmstate_bbram_ctrl; + device_class_set_props(dc, bbram_ctrl_props); +} + +static const TypeInfo bbram_ctrl_info =3D { + .name =3D TYPE_XLNX_BBRAM, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(XlnxBBRam), + .class_init =3D bbram_ctrl_class_init, + .instance_init =3D bbram_ctrl_init, +}; + +static void bbram_ctrl_register_types(void) +{ + type_register_static(&bbram_ctrl_info); +} + +type_init(bbram_ctrl_register_types) diff --git a/include/hw/nvram/xlnx-bbram.h b/include/hw/nvram/xlnx-bbram.h new file mode 100644 index 0000000000..87d59ef3c0 --- /dev/null +++ b/include/hw/nvram/xlnx-bbram.h @@ -0,0 +1,54 @@ +/* + * QEMU model of the Xilinx BBRAM Battery Backed RAM + * + * Copyright (c) 2015-2021 Xilinx Inc. + * + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef XLNX_BBRAM_H +#define XLNX_BBRAM_H + +#include "sysemu/block-backend.h" +#include "hw/qdev-core.h" +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "hw/register.h" + +#define RMAX_XLNX_BBRAM ((0x4c / 4) + 1) + +#define TYPE_XLNX_BBRAM "xlnx,bbram-ctrl" +OBJECT_DECLARE_SIMPLE_TYPE(XlnxBBRam, XLNX_BBRAM); + +struct XlnxBBRam { + SysBusDevice parent_obj; + qemu_irq irq_bbram; + + BlockBackend *blk; + + uint32_t crc_zpads; + bool bbram8_wo; + bool blk_ro; + + uint32_t regs[RMAX_XLNX_BBRAM]; + RegisterInfo regs_info[RMAX_XLNX_BBRAM]; +}; + +#endif --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856494; cv=pass; d=zohomail.com; s=zohoarc; b=F49q1G53xREhAlwycjrMzrmYs0oLBQg3vVmw8y+YLjPnDHaWA1j1pVv5G+QD/oGVtx0hTViz1W6aHV39xf1pwwOk+sdg0bc44ijYYVQzbnyAVazG9zfEPcgGg5N3EFPyB2l7AtNTKB+xyDU0gD8DgTVAAIBOnHWSRzUw361g/28= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856494; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c3P8YB8cLQTp4AWXVyThGp96CN4/DArFrdENJ8fk9Gg=; b=iZuoD1OAiuQyEHj4UYOqLne9+nTQyxnrAB14AHQGpIdspT/v1qigqBseESaqZwGtOX7ugwfeRoIZCUgeY22Sabk2DrtVrmpvpXOCn1ryxWI0vSHEl28kv40fqAnP1XNrm1Cox7z12L6y0LnML4M9QYGLOYoF+Xbrzmj9x5fy6VA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856494602529.0278322936465; Thu, 16 Sep 2021 22:28:14 -0700 (PDT) Received: from localhost ([::1]:36278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6Q0-0005nl-HK for importer@patchew.org; Fri, 17 Sep 2021 01:28:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MA-0002O8-7I; Fri, 17 Sep 2021 01:24:14 -0400 Received: from mail-dm6nam12on2044.outbound.protection.outlook.com ([40.107.243.44]:13312 helo=NAM12-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6M6-0005vC-57; Fri, 17 Sep 2021 01:24:13 -0400 Received: from DM3PR12CA0057.namprd12.prod.outlook.com (2603:10b6:0:56::25) by SN1PR02MB3774.namprd02.prod.outlook.com (2603:10b6:802:30::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Fri, 17 Sep 2021 05:24:04 +0000 Received: from DM3NAM02FT037.eop-nam02.prod.protection.outlook.com (2603:10b6:0:56:cafe::6e) by DM3PR12CA0057.outlook.office365.com (2603:10b6:0:56::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:04 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT037.mail.protection.outlook.com (10.13.4.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:04 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:00 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-Ts; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GussRz3Sw3ZOmEFdn7Th23f+bmJT/oR6iL6tFidOoNId65dmwpB9Uo7ozv59ugYGnl3R9pozjS0Osu7iasukZQidq72LPkv6OqkB9az0e+byG913Ol3JTQFiBN90a+83QwdPWdZyb7+dYT1KHzxSWwevhBigdqIX4wa9LEAKM/pzLdHxn7onX7gadtjy3jOZTkVvaW9JMcW5LP9G+V6cI25EEh2jMLviK4Dyz2JA7WXgr7L+F3OLqAPBxHHSAEoulbmn74q9aGscVW6lfXfO22jEkOdDv7agwz48wFCLurIjpZgaU8whhCPvUEL4vgtn5VFv6St+RurWNgBBmIxoIw== 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; bh=c3P8YB8cLQTp4AWXVyThGp96CN4/DArFrdENJ8fk9Gg=; b=Brigq9Ng4SrRq1QVgH9DzELGvY5cuFnTvZMIzx07fXvwHnKXiHDHJ5WNZ9CyyiAs48cRTPVAsymVmnlDpFZvkkv8QKA3X1KmhL8XBu3V+FvWrTpZrRIFuVoF2am53IS3Sy39peCU8DERYzzavBOrhd77btZOJjWy12wWnpVrMPUxJcDIezs56/iJBjheDiLjkjmHi/0PDsQ+3rqe+K9ouKQ8BxZ2U8C7vFsiIN4WXoeewgwfVL1hOJXLyBcbktFMNt79ijTTz4vtV+ZI68Kg0HhinQPp+17XyOJaa3k2ZxnIDsHVckq0Co1Xq1mkYaRMQV8b2hmmguKXYMU1lhYrcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c3P8YB8cLQTp4AWXVyThGp96CN4/DArFrdENJ8fk9Gg=; b=jJSbBMC2XvB387WLJgT09/dZWKlLtjZspJQ94HU9dEc4zZq3DbXt0iB6sfTBnUMs0Q8u+eddO6nkTmWUdQWsEUtr86AVPsRTpiHjnTcgC/KBhJaq9yVQAotMZR86ZuK9PIzieoy/VnqrKHBRmiJyL3L6smFKaS83rVhy7M5CllI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 5/9] hw/arm: xlnx-versal-virt: Add Xilinx BBRAM device Date: Thu, 16 Sep 2021 22:23:56 -0700 Message-ID: <20210917052400.1249094-6-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16d2295d-ed8e-472d-1cbe-08d9799b5d4a X-MS-TrafficTypeDiagnostic: SN1PR02MB3774: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:257; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vCZjlzCxK1GRIdDfwepm9s0U1gnSYlJ6abAy3bf9irthpvbBU62TLsyVg5Dr/zzqQo0gDKPNBqTV6pPcy09hxM6N/Mycgylu6ZEt3Cju5jb0GrypU3m9XpWL5eyFNehSbK/dCALtuwkgmDDRpzBtiXOreiESlECwkPWyMfZOFOBMhrBC1oj3Ahy/qwYKztuSAR99NaoGcdL5FHco4GCD/ewOFHdZDMalRh21aJ6Oya71HITRcOhHlc+5zrpc4EZYEfnx6OBmNY1zyt72MxYjRcXyUH7CoE/bdcawpFm8JYK8g2slEtHloYZ4XRoqKnb9rRuAHSpEyWCz5KzmFdLs+d0k/3bUEoiC01O6T+rte6ncYoSx1LYvHUbFk8rEm/ii43+wf2a3XZfSKXEbHigpvu6UFCdDse4Z4AOX86r9eewEIVwhguKnVZvsOZ/yz591LZZSiuGMvSmp/CXI/sNspgG6upfTyWL25jz3He8gr9l9X/BjhQ14xOZJhdjMkIHcvg4w0oTF3J6JqjafbSLN3W7ViF3mnMMxb46mE34cuOt0vO7hKLDZFlWlxstABej1EeiWI6sUppODNYufbF8z/XoXxXeC76TEySSsftR1OCRFD1VI7H/ubhmCXeapsay5sIwUemdgGkCwW6k8KtxRGSdcUvJLuHNZcKSy5eVeh/tzhdBn6ZQyQtXdPrhLqt1eoaXhefu+ccF7B+8R5ZfGl5x9onEozpyDC6n6+ZW7c0U= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(376002)(136003)(346002)(396003)(39860400002)(36840700001)(46966006)(47076005)(36756003)(26005)(356005)(2616005)(478600001)(6666004)(83380400001)(2906002)(70586007)(7696005)(36860700001)(44832011)(5660300002)(82310400003)(36906005)(9786002)(7636003)(54906003)(4326008)(336012)(8936002)(70206006)(6916009)(8676002)(426003)(1076003)(316002)(82740400003)(107886003)(186003)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:04.0756 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16d2295d-ed8e-472d-1cbe-08d9799b5d4a X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT037.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR02MB3774 Received-SPF: pass client-ip=40.107.243.44; envelope-from=tongh@xilinx.com; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856496471100001 Content-Type: text/plain; charset="utf-8" Connect the support for Versal Battery-Backed RAM (BBRAM) The command argument: -drive if=3Dpflash,index=3D0,... Can be used to optionally connect the bbram to a backend storage, such that field-programmed values in one invocation can be made available to next invocation. The backend storage must be a seekable binary file, and its size must be 36 bytes or larger. A file with all binary 0's is a 'blank'. Signed-off-by: Tong Ho --- hw/arm/Kconfig | 1 + hw/arm/xlnx-versal-virt.c | 36 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 18 ++++++++++++++++++ include/hw/arm/xlnx-versal.h | 5 +++++ 4 files changed, 60 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 78fdd1b935..f92fb9e568 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -381,6 +381,7 @@ config XLNX_VERSAL select XLNX_ZDMA select XLNX_ZYNQMP select OR_IRQ + select XLNX_BBRAM =20 config NPCM7XX bool diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index 5bca360dce..e1c5ead475 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -356,6 +356,26 @@ static void fdt_add_rtc_node(VersalVirt *s) g_free(name); } =20 +static void fdt_add_bbram_node(VersalVirt *s) +{ + const char compat[] =3D TYPE_XLNX_BBRAM; + const char interrupt_names[] =3D "bbram-error"; + char *name =3D g_strdup_printf("/bbram@%x", MM_PMC_BBRAM_CTRL); + + qemu_fdt_add_subnode(s->fdt, name); + + qemu_fdt_setprop_cells(s->fdt, name, "interrupts", + GIC_FDT_IRQ_TYPE_SPI, VERSAL_BBRAM_APB_IRQ_0, + GIC_FDT_IRQ_FLAGS_LEVEL_HI); + qemu_fdt_setprop(s->fdt, name, "interrupt-names", + interrupt_names, sizeof(interrupt_names)); + qemu_fdt_setprop_sized_cells(s->fdt, name, "reg", + 2, MM_PMC_BBRAM_CTRL, + 2, MM_PMC_BBRAM_CTRL_SIZE); + qemu_fdt_setprop(s->fdt, name, "compatible", compat, sizeof(compat)); + g_free(name); +} + static void fdt_nop_memory_nodes(void *fdt, Error **errp) { Error *err =3D NULL; @@ -510,6 +530,18 @@ static void create_virtio_regions(VersalVirt *s) } } =20 +static void bbram_attach_drive(XlnxBBRam *dev) +{ + DriveInfo *dinfo; + BlockBackend *blk; + + dinfo =3D drive_get_by_index(IF_PFLASH, 0); + blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + qdev_prop_set_drive(DEVICE(dev), "drive", blk); + } +} + static void sd_plugin_card(SDHCIState *sd, DriveInfo *di) { BlockBackend *blk =3D di ? blk_by_legacy_dinfo(di) : NULL; @@ -570,6 +602,7 @@ static void versal_virt_init(MachineState *machine) fdt_add_usb_xhci_nodes(s); fdt_add_sd_nodes(s); fdt_add_rtc_node(s); + fdt_add_bbram_node(s); fdt_add_cpu_nodes(s, psci_conduit); fdt_add_clk_node(s, "/clk125", 125000000, s->phandle.clk_125Mhz); fdt_add_clk_node(s, "/clk25", 25000000, s->phandle.clk_25Mhz); @@ -579,6 +612,9 @@ static void versal_virt_init(MachineState *machine) memory_region_add_subregion_overlap(get_system_memory(), 0, &s->soc.fpd.apu.mr, 0); =20 + /* Attach bbram backend, if given */ + bbram_attach_drive(&s->soc.pmc.bbram); + /* Plugin SD cards. */ for (i =3D 0; i < ARRAY_SIZE(s->soc.pmc.iou.sd); i++) { sd_plugin_card(&s->soc.pmc.iou.sd[i], drive_get_next(IF_SD)); diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c index 547a26603a..23451ae012 100644 --- a/hw/arm/xlnx-versal.c +++ b/hw/arm/xlnx-versal.c @@ -314,6 +314,23 @@ static void versal_create_xrams(Versal *s, qemu_irq *p= ic) } } =20 +static void versal_create_bbram(Versal *s, qemu_irq *pic) +{ + SysBusDevice *sbd; + + object_initialize_child_with_props(OBJECT(s), "bbram", &s->pmc.bbram, + sizeof(s->pmc.bbram), TYPE_XLNX_BBR= AM, + &error_fatal, + "crc-zpads", "0", + NULL); + sbd =3D SYS_BUS_DEVICE(&s->pmc.bbram); + + sysbus_realize(sbd, &error_fatal); + memory_region_add_subregion(&s->mr_ps, MM_PMC_BBRAM_CTRL, + sysbus_mmio_get_region(sbd, 0)); + sysbus_connect_irq(sbd, 0, pic[VERSAL_BBRAM_APB_IRQ_0]); +} + /* This takes the board allocated linear DDR memory and creates aliases * for each split DDR range/aperture on the Versal address map. */ @@ -402,6 +419,7 @@ static void versal_realize(DeviceState *dev, Error **er= rp) versal_create_sds(s, pic); versal_create_rtc(s, pic); versal_create_xrams(s, pic); + versal_create_bbram(s, pic); versal_map_ddr(s); versal_unimp(s); =20 diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h index 9b79051747..1cac613338 100644 --- a/include/hw/arm/xlnx-versal.h +++ b/include/hw/arm/xlnx-versal.h @@ -24,6 +24,7 @@ #include "qom/object.h" #include "hw/usb/xlnx-usb-subsystem.h" #include "hw/misc/xlnx-versal-xramc.h" +#include "hw/nvram/xlnx-bbram.h" =20 #define TYPE_XLNX_VERSAL "xlnx-versal" OBJECT_DECLARE_SIMPLE_TYPE(Versal, XLNX_VERSAL) @@ -79,6 +80,7 @@ struct Versal { } iou; =20 XlnxZynqMPRTC rtc; + XlnxBBRam bbram; } pmc; =20 struct { @@ -105,6 +107,7 @@ struct Versal { #define VERSAL_GEM1_WAKE_IRQ_0 59 #define VERSAL_ADMA_IRQ_0 60 #define VERSAL_XRAM_IRQ_0 79 +#define VERSAL_BBRAM_APB_IRQ_0 121 #define VERSAL_RTC_APB_ERR_IRQ 121 #define VERSAL_SD0_IRQ_0 126 #define VERSAL_RTC_ALARM_IRQ 142 @@ -172,6 +175,8 @@ struct Versal { =20 #define MM_PMC_SD0 0xf1040000U #define MM_PMC_SD0_SIZE 0x10000 +#define MM_PMC_BBRAM_CTRL 0xf11f0000 +#define MM_PMC_BBRAM_CTRL_SIZE 0x00050 #define MM_PMC_CRP 0xf1260000U #define MM_PMC_CRP_SIZE 0x10000 #define MM_PMC_RTC 0xf12a0000 --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856795; cv=pass; d=zohomail.com; s=zohoarc; b=GyZ+LFQYJdHrKrH0n+uMauTigmLWOIcRQG9UL82wSfDGfwTgQeAIk8IzLtwkOEFib5N5RMtNq3IKYEICBSQ1uYar/w0iOs1ED4G89A/XPwv9OjWnWH/pRghooA5YPy4BBvHx/G/KipVTWNWuM8mJ81E4/ZlvC/j8T6/3A9qSNfk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856795; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zGwc9UnhB1o5h+zFcAs1b+jEaSzzcTzLNYtWwq595Tw=; b=bxyySU9qMSjkulYTShApYTYd3jZTGVRZeSPHfQhqXl6D4gv3xTjlxPEfEamzyRjpLWGw60fCmwszy9x/So3UGeeCWjSPnJTEtF8sPn+cAZhBYNefNCwLCNXLudX5MHbuF5N5/a/5IpN+sjzcyOCHQZ8yKXxc8GTtOuEXGzmVfDs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856795361422.29354653283224; Thu, 16 Sep 2021 22:33:15 -0700 (PDT) Received: from localhost ([::1]:50358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6Us-0006um-64 for importer@patchew.org; Fri, 17 Sep 2021 01:33:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MI-0002hF-Nd; Fri, 17 Sep 2021 01:24:22 -0400 Received: from mail-dm6nam11on2078.outbound.protection.outlook.com ([40.107.223.78]:10849 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MG-000632-Sl; Fri, 17 Sep 2021 01:24:22 -0400 Received: from DM3PR12CA0060.namprd12.prod.outlook.com (2603:10b6:0:56::28) by BL0PR02MB4754.namprd02.prod.outlook.com (2603:10b6:208:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 05:24:12 +0000 Received: from DM3NAM02FT037.eop-nam02.prod.protection.outlook.com (2603:10b6:0:56:cafe::cd) by DM3PR12CA0060.outlook.office365.com (2603:10b6:0:56::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:12 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT037.mail.protection.outlook.com (10.13.4.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:12 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:01 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:00 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-US; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AFdNxnw3RGvjwB8fRA/ep74xjl3qFX1ARcKgswWIM4uKeB361WUCdu/lAeDAqi5tjZZEyWUjc3OsJMTG2iGqz+h++1Jl/1iqO/73HorFpNrjVQ4uWc4f/+Z0fF5GWMi1WcXiN6Ox3PlRxA3emwz2fPaJ83IfNhjDVN33pzdA2L77i4Qn1vS7iD9B5cI0Hgk4GQZpPjdKO6PUkgkyyPewX1nliqqsAhNSg9P312ucR9cpm9LcdOVgjISlCeV6kzR5z0ok0hzj4dj5tSmdW5qvaiVvYeoEQOMD8+4H4vpSXkOefn/Ts7ZvEu9j4nvJPza541dytntVINRcEzoI3jvz6A== 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; bh=zGwc9UnhB1o5h+zFcAs1b+jEaSzzcTzLNYtWwq595Tw=; b=NIDuZKfetkey38lSoSzL+RiP4bSUNkHVDNBNHJLLIHPzLGBi30Q1Cb4ggN4PzXY1xMb8P0kEHwihw+6KBOleOUSqO1KLHvCdrAQTv1nbDbDGDdXDPMQmJ0Wo3U7lgqcNyBNXazyAjgJMchQI1P2IWFKOAaFfIJBH0VqrMj0N7PXdM/YAttVbCGy+MgGj178hyNZ57MHm+J/U1mSTkWAdILE96RSZp54bpol+72KGqfQXYKFLD3R5MoEb9sFN2T67z00OVa1bqYjbIUl9rcyrPHrPcdobeM2jj835t7nQNlKzcVrp9yE1nitlso9bjGXlCYmkr9XdxW2WdqkqoWfa3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zGwc9UnhB1o5h+zFcAs1b+jEaSzzcTzLNYtWwq595Tw=; b=jywZYFujWG1OC+oNsnCV5VFLVQtiDx2Ok44pPsCsSpAIf1zX72v08gqNpwtANW6YvnvXi2+2eUiQ3Rnfn0kBBA7ZpvD32qUW1I+NUtye7+w0QQVHi1kRZaytnKh4Fp/WLfzfpMItEu8JqdK6II3WyCINIt7xhS6KXapxf9wrncM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 6/9] hw/arm: xlnx-versal-virt: Add Xilinx eFUSE device Date: Thu, 16 Sep 2021 22:23:57 -0700 Message-ID: <20210917052400.1249094-7-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 48bbed9c-0bfa-4ecb-8ede-08d9799b6273 X-MS-TrafficTypeDiagnostic: BL0PR02MB4754: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:257; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qxSd4mmpNoEoTBJ11wAEiwAC+fKroNmaDsUUK+H0jsmoLIh66wLfvUzFKlCw8jWX5Lu77aJA54MhFsAzFS/O/ls1iu680R1s7GO2bdUYYXo5UyohDXlErvaZ+n6wUGWkHUpstuF/05ttYaQopcLO4aKvJNsQjk8Rlc88nCQogqoC/3CXS31zI4p7q4qLiNoPrMmmufTt/qlWsO2vG2oHMVfxTi9CQOolQreGvNvOXQVkA7bpBV7m8GmHgh2dRF3uqSvb4bvPITeebuYypbM5zfiXOrrXljqpCQUXVbxOAAphwlZenmhvP5OFcGdXYukDzzTLJrfQksYxzKEhO2FAA4sQCUS1AANlZLiOSJHamP/Lt3S3b4COEbC0HemB+UzxeOFCEr6MIKQFTnlnkjNM6pp8zxTV9Ji8H9uP2GGParHstGLQF+PjO8ngTIB3wvlvyLsw/Xw6Dp7M/BqhNBRG8VdxbIEDAFwvWJc9LGBCZw26l4dBw2mDxLGDDUWxLqEO7jkeIUdKCxjgRbbl7E7IB19FZojCec1DXd59+ncR4YEW/o+AT35MR3tKXp4QI3gNLffX7t2sp9HSFDqtP0YVF3gc0dlJdnrg7b+wAVDgiJ5lCQaK3jEWO5pcW7Uig6l6ozuPfqTZbWW9qhEMbLgzRjpt359rYQdnmb27UmFmofjo71quv3r/TBe6p5Ll6LNGgLZ2k0BpPL++cQBF3t5k+CNbxr2lvHkgQ6GOEl7l0SQ= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(346002)(136003)(396003)(46966006)(36840700001)(107886003)(8936002)(1076003)(26005)(8676002)(82310400003)(478600001)(6666004)(2906002)(336012)(4326008)(426003)(70586007)(7696005)(186003)(5660300002)(83380400001)(9786002)(54906003)(44832011)(316002)(36906005)(36860700001)(47076005)(6916009)(356005)(7636003)(36756003)(82740400003)(70206006)(2616005)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:12.7348 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48bbed9c-0bfa-4ecb-8ede-08d9799b6273 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT037.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB4754 Received-SPF: pass client-ip=40.107.223.78; envelope-from=tongh@xilinx.com; helo=NAM11-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856797027100001 Content-Type: text/plain; charset="utf-8" Connect the support for Versal eFUSE one-time field-programmable bit array. The command argument: -drive if=3Dpflash,index=3D1,... Can be used to optionally connect the bit array to a backend storage, such that field-programmed values in one invocation can be made available to next invocation. The backend storage must be a seekable binary file, and its size must be 3072 bytes or larger. A file with all binary 0's is a 'blank'. Signed-off-by: Tong Ho --- hw/arm/Kconfig | 1 + hw/arm/xlnx-versal-virt.c | 52 ++++++++++++++++++++++++++++++++++++ hw/arm/xlnx-versal.c | 39 +++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 10 +++++++ 4 files changed, 102 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index f92fb9e568..9edc05782d 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -382,6 +382,7 @@ config XLNX_VERSAL select XLNX_ZYNQMP select OR_IRQ select XLNX_BBRAM + select XLNX_EFUSE_VERSAL =20 config NPCM7XX bool diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index e1c5ead475..d2f55e29b6 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -376,6 +376,41 @@ static void fdt_add_bbram_node(VersalVirt *s) g_free(name); } =20 +static void fdt_add_efuse_ctrl_node(VersalVirt *s) +{ + const char compat[] =3D TYPE_XLNX_VERSAL_EFUSE_CTRL; + const char interrupt_names[] =3D "pmc_efuse"; + char *name =3D g_strdup_printf("/pmc_efuse@%x", MM_PMC_EFUSE_CTRL); + + qemu_fdt_add_subnode(s->fdt, name); + + qemu_fdt_setprop_cells(s->fdt, name, "interrupts", + GIC_FDT_IRQ_TYPE_SPI, VERSAL_EFUSE_IRQ, + GIC_FDT_IRQ_FLAGS_LEVEL_HI); + qemu_fdt_setprop(s->fdt, name, "interrupt-names", + interrupt_names, sizeof(interrupt_names)); + qemu_fdt_setprop_sized_cells(s->fdt, name, "reg", + 2, MM_PMC_EFUSE_CTRL, + 2, MM_PMC_EFUSE_CTRL_SIZE); + qemu_fdt_setprop(s->fdt, name, "compatible", compat, sizeof(compat)); + g_free(name); +} + +static void fdt_add_efuse_cache_node(VersalVirt *s) +{ + const char compat[] =3D TYPE_XLNX_VERSAL_EFUSE_CACHE; + char *name =3D g_strdup_printf("/xlnx_pmc_efuse_cache@%x", + MM_PMC_EFUSE_CACHE); + + qemu_fdt_add_subnode(s->fdt, name); + + qemu_fdt_setprop_sized_cells(s->fdt, name, "reg", + 2, MM_PMC_EFUSE_CACHE, + 2, MM_PMC_EFUSE_CACHE_SIZE); + qemu_fdt_setprop(s->fdt, name, "compatible", compat, sizeof(compat)); + g_free(name); +} + static void fdt_nop_memory_nodes(void *fdt, Error **errp) { Error *err =3D NULL; @@ -542,6 +577,18 @@ static void bbram_attach_drive(XlnxBBRam *dev) } } =20 +static void efuse_attach_drive(XlnxEFuse *dev) +{ + DriveInfo *dinfo; + BlockBackend *blk; + + dinfo =3D drive_get_by_index(IF_PFLASH, 1); + blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + qdev_prop_set_drive(DEVICE(dev), "drive", blk); + } +} + static void sd_plugin_card(SDHCIState *sd, DriveInfo *di) { BlockBackend *blk =3D di ? blk_by_legacy_dinfo(di) : NULL; @@ -603,6 +650,8 @@ static void versal_virt_init(MachineState *machine) fdt_add_sd_nodes(s); fdt_add_rtc_node(s); fdt_add_bbram_node(s); + fdt_add_efuse_ctrl_node(s); + fdt_add_efuse_cache_node(s); fdt_add_cpu_nodes(s, psci_conduit); fdt_add_clk_node(s, "/clk125", 125000000, s->phandle.clk_125Mhz); fdt_add_clk_node(s, "/clk25", 25000000, s->phandle.clk_25Mhz); @@ -615,6 +664,9 @@ static void versal_virt_init(MachineState *machine) /* Attach bbram backend, if given */ bbram_attach_drive(&s->soc.pmc.bbram); =20 + /* Attach efuse backend, if given */ + efuse_attach_drive(&s->soc.pmc.efuse); + /* Plugin SD cards. */ for (i =3D 0; i < ARRAY_SIZE(s->soc.pmc.iou.sd); i++) { sd_plugin_card(&s->soc.pmc.iou.sd[i], drive_get_next(IF_SD)); diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c index 23451ae012..b2705b6925 100644 --- a/hw/arm/xlnx-versal.c +++ b/hw/arm/xlnx-versal.c @@ -331,6 +331,44 @@ static void versal_create_bbram(Versal *s, qemu_irq *p= ic) sysbus_connect_irq(sbd, 0, pic[VERSAL_BBRAM_APB_IRQ_0]); } =20 +static void versal_realize_efuse_part(Versal *s, Object *dev, hwaddr base) +{ + SysBusDevice *part =3D SYS_BUS_DEVICE(dev); + + object_property_set_link(OBJECT(part), "efuse", + OBJECT(&s->pmc.efuse), &error_abort); + + sysbus_realize(part, &error_abort); + memory_region_add_subregion(&s->mr_ps, base, + sysbus_mmio_get_region(part, 0)); +} + +static void versal_create_efuse(Versal *s, qemu_irq *pic) +{ + Object *bits =3D OBJECT(&s->pmc.efuse); + Object *ctrl =3D OBJECT(&s->pmc.efuse_ctrl); + Object *cache =3D OBJECT(&s->pmc.efuse_cache); + + object_initialize_child(OBJECT(s), "efuse-ctrl", &s->pmc.efuse_ctrl, + TYPE_XLNX_VERSAL_EFUSE_CTRL); + + object_initialize_child(OBJECT(s), "efuse-cache", &s->pmc.efuse_cache, + TYPE_XLNX_VERSAL_EFUSE_CACHE); + + object_initialize_child_with_props(ctrl, "xlnx-efuse@0", bits, + sizeof(s->pmc.efuse), + TYPE_XLNX_EFUSE, &error_abort, + "efuse-nr", "3", + "efuse-size", "8192", + NULL); + + qdev_realize(DEVICE(bits), NULL, &error_abort); + versal_realize_efuse_part(s, ctrl, MM_PMC_EFUSE_CTRL); + versal_realize_efuse_part(s, cache, MM_PMC_EFUSE_CACHE); + + sysbus_connect_irq(SYS_BUS_DEVICE(ctrl), 0, pic[VERSAL_EFUSE_IRQ]); +} + /* This takes the board allocated linear DDR memory and creates aliases * for each split DDR range/aperture on the Versal address map. */ @@ -420,6 +458,7 @@ static void versal_realize(DeviceState *dev, Error **er= rp) versal_create_rtc(s, pic); versal_create_xrams(s, pic); versal_create_bbram(s, pic); + versal_create_efuse(s, pic); versal_map_ddr(s); versal_unimp(s); =20 diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h index 1cac613338..895ba12c61 100644 --- a/include/hw/arm/xlnx-versal.h +++ b/include/hw/arm/xlnx-versal.h @@ -25,6 +25,7 @@ #include "hw/usb/xlnx-usb-subsystem.h" #include "hw/misc/xlnx-versal-xramc.h" #include "hw/nvram/xlnx-bbram.h" +#include "hw/nvram/xlnx-versal-efuse.h" =20 #define TYPE_XLNX_VERSAL "xlnx-versal" OBJECT_DECLARE_SIMPLE_TYPE(Versal, XLNX_VERSAL) @@ -81,6 +82,9 @@ struct Versal { =20 XlnxZynqMPRTC rtc; XlnxBBRam bbram; + XlnxEFuse efuse; + XlnxVersalEFuseCtrl efuse_ctrl; + XlnxVersalEFuseCache efuse_cache; } pmc; =20 struct { @@ -110,6 +114,7 @@ struct Versal { #define VERSAL_BBRAM_APB_IRQ_0 121 #define VERSAL_RTC_APB_ERR_IRQ 121 #define VERSAL_SD0_IRQ_0 126 +#define VERSAL_EFUSE_IRQ 139 #define VERSAL_RTC_ALARM_IRQ 142 #define VERSAL_RTC_SECONDS_IRQ 143 =20 @@ -177,6 +182,11 @@ struct Versal { #define MM_PMC_SD0_SIZE 0x10000 #define MM_PMC_BBRAM_CTRL 0xf11f0000 #define MM_PMC_BBRAM_CTRL_SIZE 0x00050 +#define MM_PMC_EFUSE_CTRL 0xf1240000 +#define MM_PMC_EFUSE_CTRL_SIZE 0x00104 +#define MM_PMC_EFUSE_CACHE 0xf1250000 +#define MM_PMC_EFUSE_CACHE_SIZE 0x00C00 + #define MM_PMC_CRP 0xf1260000U #define MM_PMC_CRP_SIZE 0x10000 #define MM_PMC_RTC 0xf12a0000 --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856692; cv=pass; d=zohomail.com; s=zohoarc; b=eBxD9jRtCDgaFCzkohRWYbZ92Q+i9jB9RxQ0esf14BTuL38L/ZYqHySQGkDABJ854raWn5NOQu4EBOHbc+AVADgWHBrrnraRdgjS3XQX01pXsY77sZmd7mBoCyFoiJhuHAfbV72AoNrrXb7fPHHOsyQdvfEvarcOm2zLKQZwwhk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856692; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pxryyTVF4f8bKv1bhGjnN1aosMY840Y3NKNF4eL9C7Y=; b=JWkAsYvQZd5bT4Ry1DUvqPhoKRc43LDD0SZ3sgnHQ8iEG8hBVlxVjpd2s2O7KOwxWtXxD4ahIQjLO6/h/WwM2O9g1G4sIRWX9MGUoNeI9N+q/Re4Kln4ZLjwP0uUdzdRuynCEBXmK2eBwZR8Ft+UDpgFWGmQeU3Hscn7aBuLUrc= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856692616671.1239419635397; Thu, 16 Sep 2021 22:31:32 -0700 (PDT) Received: from localhost ([::1]:46884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6TD-0004Pd-Fu for importer@patchew.org; Fri, 17 Sep 2021 01:31:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MM-0002wM-JC; Fri, 17 Sep 2021 01:24:26 -0400 Received: from mail-bn8nam12on2045.outbound.protection.outlook.com ([40.107.237.45]:20001 helo=NAM12-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MK-00066e-Ja; Fri, 17 Sep 2021 01:24:26 -0400 Received: from DM5PR19CA0015.namprd19.prod.outlook.com (2603:10b6:3:151::25) by DM5PR02MB3308.namprd02.prod.outlook.com (2603:10b6:4:6a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 05:24:19 +0000 Received: from DM3NAM02FT008.eop-nam02.prod.protection.outlook.com (2603:10b6:3:151:cafe::44) by DM5PR19CA0015.outlook.office365.com (2603:10b6:3:151::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:19 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT008.mail.protection.outlook.com (10.13.5.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:19 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:01 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:01 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-V2; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ie+UlmBuLopzin4KW5AsrUaNl5J6++xRkE1tetaN7qT86wWcHiorHx+kvcBdFxheWbwi5SGeaKS2MGqO292QA2zhrAmwB8hnPWffYSlIw9IES6oPxU86xJgqzErUFZM1YI5riRgmVXuP7etprKeF/BmAoAXOr8JExgzJr9kamVCvQw8m7wW0zhChEbrhqpeV70BqmDWUJH5AS4Kj9HkabNvZryyyqOMbCEXfigdNlIK4/t3Tns9K0lu94E9it6yVVMNJy4ABirhRHaPjQUYjnVYSbK0BEU5Vny1Mr+8j45oP8YNDCy74915xO9fwLxPIivXodDbQQgMz20icX2cufA== 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; bh=pxryyTVF4f8bKv1bhGjnN1aosMY840Y3NKNF4eL9C7Y=; b=JT1Fqqm7IFZJ6FG3A8+e9vzuWokFbDbFDts0fnoQVIOL/fXikc0FdUn076kdovTsR2RfP/lFzun0VIhKqYzxtaxfBi9PBpSPFu3dHiLMeCCRhvQylDthSDUuAMFmtTiTpGpWGXJvei/IBvUfm9JlrofUBrcDc6MXkKgI10ik1zcRhZZZd2nl8pOxiUiikg6cAo4InA2f6cqamvRwOAmytXCiiPNk2bJzPcf8r6FVSBAJD8hqhjjVNvbLa891XpRphPSC4FitclQR8TWViETj++wRimCzORMdUvpy+ghWRapE8TugezxcBuzA3pJM9zB+P1UZKj5v2JmtfwwtMYWzdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pxryyTVF4f8bKv1bhGjnN1aosMY840Y3NKNF4eL9C7Y=; b=JD45lyfebbPpYpyIHy/cuRvEBqzse8JAaWNEVjo3YjLBP+RU1LL2uDpdTJegbcvYAkoaxMccoRjgYz1/DEfKBHPWu5yxUtdOVufcQpy+V7uTlDV7exXgi1QSxIxW9hEeuZMZdfIrMeEZsRa3Q/F2wOWnQnYz/uwAARWMxV/bsv4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 7/9] hw/arm: xlnx-zcu102: Add Xilinx BBRAM device Date: Thu, 16 Sep 2021 22:23:58 -0700 Message-ID: <20210917052400.1249094-8-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05f569fb-507f-4d08-9b15-08d9799b6669 X-MS-TrafficTypeDiagnostic: DM5PR02MB3308: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hZ0IFAp/JM3FHIgMMh5CHOqdwFf5UH6s6VKRsX4p+B4c3JUtZJWH4iARjKXtpp3NYVpT06+L67Vz6OzQjF9q3NrtZJDN3U6kaaePRTGLXqpTlpO+76t5XjtGUZw5yPYOUyrdvOepnK88JV+6RlLQA27rT7/L9k3TvX7HqmOa3rHxwbWD+Rl/HwaToBjcZIINvYPNxbY9cMWbq+YhBAaLpjwx8heLhLMnSxvZDzo17zPqsgKsAkVfk05RK6nrK6aKLSTaET1VcCgKk0Z+puknx9F5CnOE0OfgaXSrdwErjZQvax7c1zCf3hUSU/Lc7bV+wm+y747Moy5g++2yCJL6TNVvwM3iR5WsBScIjTnpaG0S2WxOJ9J9iCVs2c+503ZUp4++L0Lyh55Js3fGF2R6RFU4q3gBIXTBWBWlhuLFPfO/ooKa2nyOM0cOtr2+hVjoHktGIdvwVzXR+hl9xvGdpmzg8NipaMjwQOQ1TlO18COmEZjSa8IZhgUMdTwoDwWUUXA1AxF041ahjqECxSbaHExd6NwP1RXPDlhLBm3MZy1G0aHB7ejvi/5YFolL3utVqpe35JgFSaghn7vOqHLiXINRfJ0OAduUwnhD6LaNtpZQSZl8DtE3NLU/Llx+Wh76z7bxr9l7MqOGadIoZpOeQRm6p4gVDIdogE/szanJKIJvqlehbQG8JF/NPQasqhegP35IpxLuldP7wP846+jjXxtfCRpdfx6MttJnfheIqiQ= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(396003)(136003)(39860400002)(376002)(346002)(36840700001)(46966006)(8936002)(478600001)(36906005)(7636003)(70206006)(70586007)(36756003)(7696005)(54906003)(2906002)(82310400003)(6916009)(316002)(36860700001)(186003)(26005)(47076005)(8676002)(82740400003)(83380400001)(44832011)(1076003)(426003)(107886003)(5660300002)(336012)(9786002)(356005)(2616005)(4326008)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:19.3804 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05f569fb-507f-4d08-9b15-08d9799b6669 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3308 Received-SPF: pass client-ip=40.107.237.45; envelope-from=tongh@xilinx.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856694756100001 Content-Type: text/plain; charset="utf-8" Connect the support for Xilinx ZynqMP Battery-Backed RAM (BBRAM) The command argument: -drive if=3Dpflash,index=3D2,... Can be used to optionally connect the bbram to a backend storage, such that field-programmed values in one invocation can be made available to next invocation. The backend storage must be a seekable binary file, and its size must be 36 bytes or larger. A file with all binary 0's is a 'blank'. Signed-off-by: Tong Ho --- hw/Kconfig | 1 + hw/arm/xlnx-zcu102.c | 15 +++++++++++++++ hw/arm/xlnx-zynqmp.c | 20 ++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 2 ++ 4 files changed, 38 insertions(+) diff --git a/hw/Kconfig b/hw/Kconfig index 8cb7664d70..b6fb6a4507 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -81,3 +81,4 @@ config XLNX_ZYNQMP select REGISTER select CAN_BUS select PTIMER + select XLNX_BBRAM diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c index 6c6cb02e86..b247c5779b 100644 --- a/hw/arm/xlnx-zcu102.c +++ b/hw/arm/xlnx-zcu102.c @@ -98,6 +98,18 @@ static void zcu102_modify_dtb(const struct arm_boot_info= *binfo, void *fdt) } } =20 +static void bbram_attach_drive(XlnxBBRam *dev) +{ + DriveInfo *dinfo; + BlockBackend *blk; + + dinfo =3D drive_get_by_index(IF_PFLASH, 2); + blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + qdev_prop_set_drive(DEVICE(dev), "drive", blk); + } +} + static void xlnx_zcu102_init(MachineState *machine) { XlnxZCU102 *s =3D ZCU102_MACHINE(machine); @@ -136,6 +148,9 @@ static void xlnx_zcu102_init(MachineState *machine) =20 qdev_realize(DEVICE(&s->soc), NULL, &error_fatal); =20 + /* Attach bbram backend, if given */ + bbram_attach_drive(&s->soc.bbram); + /* Create and plug in the SD cards */ for (i =3D 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { BusState *bus; diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index 4e5a471e30..1e8e2ddcc2 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -66,6 +66,9 @@ #define RTC_ADDR 0xffa60000 #define RTC_IRQ 26 =20 +#define BBRAM_ADDR 0xffcd0000 +#define BBRAM_IRQ 11 + #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */ =20 static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] =3D { @@ -226,6 +229,22 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, X= lnxZynqMPState *s, qdev_realize(DEVICE(&s->rpu_cluster), NULL, &error_fatal); } =20 +static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic) +{ + SysBusDevice *sbd; + + object_initialize_child_with_props(OBJECT(s), "bbram", &s->bbram, + sizeof(s->bbram), TYPE_XLNX_BBRAM, + &error_fatal, + "crc-zpads", "1", + NULL); + sbd =3D SYS_BUS_DEVICE(&s->bbram); + + sysbus_realize(sbd, &error_fatal); + sysbus_mmio_map(sbd, 0, BBRAM_ADDR); + sysbus_connect_irq(sbd, 0, gic[BBRAM_IRQ]); +} + static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s) { static const struct UnimpInfo { @@ -626,6 +645,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error= **errp) sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR); sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]); =20 + xlnx_zynqmp_create_bbram(s, gic_spi); xlnx_zynqmp_create_unimp_mmio(s); =20 for (i =3D 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) { diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h index c84fe15996..067e8a5238 100644 --- a/include/hw/arm/xlnx-zynqmp.h +++ b/include/hw/arm/xlnx-zynqmp.h @@ -36,6 +36,7 @@ #include "qom/object.h" #include "net/can_emu.h" #include "hw/dma/xlnx_csu_dma.h" +#include "hw/nvram/xlnx-bbram.h" =20 #define TYPE_XLNX_ZYNQMP "xlnx-zynqmp" OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPState, XLNX_ZYNQMP) @@ -100,6 +101,7 @@ struct XlnxZynqMPState { =20 MemoryRegion *ddr_ram; MemoryRegion ddr_ram_low, ddr_ram_high; + XlnxBBRam bbram; =20 MemoryRegion mr_unimp[XLNX_ZYNQMP_NUM_UNIMP_AREAS]; =20 --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856525; cv=pass; d=zohomail.com; s=zohoarc; b=Uf0dw/jgNWrQ+RvaFBQcAMQu+UN5JIysIE9en/Nw+DGBslayyQtWecotoj8X4FQvgsN3mFBT3EbuvRI88Ui3twfsEh9lhLGzq/Jkc4Hy6WUrQ4digHNZFFbQwvk/VO+9NvIl5AAVtQaLCrpNRHhV9Jwtb5mrcd9/a8XFoa8K1lo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856525; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DAgxYZw5XD6sh67NcaobeFummKCB/M4aAsQEdcYTsCA=; b=M9c4vmvwa13C16kwn0+snUXtKsui+XN2nLUD2UD5qxhPR/TVLeuLOCHaUngNo+MxUKjCSCG02xtY7svxEFvY94Fr50d7MnqudFSW4szXoNADCDDoQ5+yp5MvVbmdbvHdml/dwO2EZ6JRUAz7kEISPvpoY7TiC8c9iXPmPeLNxdU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856525287559.6608598590108; Thu, 16 Sep 2021 22:28:45 -0700 (PDT) Received: from localhost ([::1]:38724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6QW-0007Qa-8H for importer@patchew.org; Fri, 17 Sep 2021 01:28:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6ML-0002pu-39; Fri, 17 Sep 2021 01:24:25 -0400 Received: from mail-mw2nam12on2084.outbound.protection.outlook.com ([40.107.244.84]:43328 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MJ-00065H-CA; Fri, 17 Sep 2021 01:24:24 -0400 Received: from DM5PR19CA0003.namprd19.prod.outlook.com (2603:10b6:3:151::13) by DM5PR02MB2411.namprd02.prod.outlook.com (2603:10b6:3:50::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Fri, 17 Sep 2021 05:24:19 +0000 Received: from DM3NAM02FT008.eop-nam02.prod.protection.outlook.com (2603:10b6:3:151:cafe::87) by DM5PR19CA0003.outlook.office365.com (2603:10b6:3:151::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:19 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT008.mail.protection.outlook.com (10.13.5.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:18 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:01 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:01 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-Va; Thu, 16 Sep 2021 22:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YYqJN+Md7DGxd1Air39bPIMOP4NVFoMVaS3u3xPJpFZ077lP1GKPHT5myZoab2JR0ELrobreDYb0vm4kFhjnUkUOLjtPhQ/G9XJ5ucMjxmjOpf7fbnK69b4jsPehCas95L00pDutkW0uQbhyXIPjRdiCeni+G4rCu4MItsAHyOdVj/hFCJcX7xTfbDRaGH3gkvE8++ky1X6PawVMfg67CBPfH3mMLH/vKYr5RtiyS60ACw1dcTU7JynpWQw2GGkv3ZQb56EXmpB9OvaudZRCHFoCT8NXxKov+b4FPzNuhQdYe4oMXaqqoIOQ9/v9Jui9dBCHVAQvigKlreYPdBFsCA== 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; bh=DAgxYZw5XD6sh67NcaobeFummKCB/M4aAsQEdcYTsCA=; b=OuHE6iGwg1sZYVhYoGz7Gn55rM0lw/Wghux4eRTjVp2ctyohIAoDgzlmPLyzoEGV3K8/o8s6j2GBrQZFsReZO7ntTP69VyeRffkTWIJiClviIRn3ZUVZYm/3+HpMyYQaUHEdjRvbB8f07dlPZBUZU40blkcsihWOcLBEyZBlEO4BXXLZkr4w0JWXJzgjkzkjht540khCAjDYRxQeE422BXLVhVTgdSWo0gn3Pg5aEFmjqfSvx347dB7eAG/s7Xur5OYjATNfzFuWwUmygzNgAVkNkUOx4KHfrmjo2UqZVH0iMkSGnVLWKqQFljVfzcyNpppZx3NkendsrLOHGrzttQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DAgxYZw5XD6sh67NcaobeFummKCB/M4aAsQEdcYTsCA=; b=a4MlM31ZCg8QYj7N1AN0kdbm9Pqp4bEYZ1H1wFRCK6BIcW/aM3xGKt+5zJn/02+s74WrFEIKUHINJmtU4iAD4+79sh7RxkRvcxPidm+knVQRa1Iz9stTmVaPzuFlnwRuNcWmirRGQZY0yKvyKoDyVMTwGiFHJyKTWUMLQMXaLoY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 8/9] hw/arm: xlnx-zcu102: Add Xilinx eFUSE device Date: Thu, 16 Sep 2021 22:23:59 -0700 Message-ID: <20210917052400.1249094-9-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: afb59bdf-8b68-4189-4dc1-08d9799b6621 X-MS-TrafficTypeDiagnostic: DM5PR02MB2411: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:635; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a9ZAvn35uKiVT4D10XfHrWMEKiLDMZ4mu9c3YzNQp6XOzO1rkquGWPoaqq/E1XdYYbsG31DMO4C1QWYEG4gyBc3rdTetXHyGkd2LB135bWXZ4QPkpvEogfcdLLWonouHIH2+rvrNlq2bvJWaqMMbsWqpJ1nYv5N7XHT3tcsBX83NPDNuuKiBqAaAF+s3grjeepw+BYDRFpIcAFXVLq737V71G27vTtR4HlFVS74pE076poSPJwXcu552xzmA+wkfUQShfhNHKzD2whY1lYG/7MDOrssg7kdyYkTuROgqVYY5h7mDXxNJEWxvWJnhPb8FoGnYxPyVfBnE4uqPLbiLaMjf4mgUjfQCDHnVgVrR23rXHh6NYphmB5aY4GLmJxhGAQVC7LCdpxPMONsAle3nH5P3o3IrhvvDcaQFxe9FcoJww1la81XhjO0ZVUl352Iqg6NFtz9FxCcTr7aNGwCUeZ+PJPAryIb9PCeKm9s1v8OF4QE4GstDS2JnameARpW2BphmSewDEgnOrsbkQZMGVHqWpRpjoUJMjNxchGG13M9jEX9kfGY7fwwbqBv/ej2VncSZEuYliouEIwwH6VSpD7QN+YUj2soLuy1yYhupqx74L6aA922NRKzkl09lJc2rPyRETkMJzF9MabJJopPvJCJ8ewBcM+rki5GFN4yTTO7M5WmrVd4sd5W1teWyxo0CJuBFlPQxHbV1xcDvEJ/P9Nuq5KEx8/AjakXLO4auhXg= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(396003)(136003)(346002)(376002)(39860400002)(46966006)(36840700001)(70586007)(107886003)(70206006)(36860700001)(7636003)(47076005)(426003)(336012)(54906003)(82310400003)(316002)(6916009)(82740400003)(44832011)(36906005)(9786002)(2906002)(2616005)(356005)(36756003)(478600001)(8676002)(7696005)(4326008)(83380400001)(8936002)(26005)(186003)(1076003)(5660300002)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:18.9086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afb59bdf-8b68-4189-4dc1-08d9799b6621 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB2411 Received-SPF: pass client-ip=40.107.244.84; envelope-from=tongh@xilinx.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856527249100001 Content-Type: text/plain; charset="utf-8" Connect the support for ZynqMP eFUSE one-time field-programmable bit array. The command argument: -drive if=3Dpflash,index=3D3,... Can be used to optionally connect the bit array to a backend storage, such that field-programmed values in one invocation can be made available to next invocation. The backend storage must be a seekable binary file, and its size must be 768 bytes or larger. A file with all binary 0's is a 'blank'. Signed-off-by: Tong Ho --- hw/Kconfig | 1 + hw/arm/xlnx-zcu102.c | 15 +++++++++++++++ hw/arm/xlnx-zynqmp.c | 29 +++++++++++++++++++++++++++++ include/hw/arm/xlnx-zynqmp.h | 3 +++ 4 files changed, 48 insertions(+) diff --git a/hw/Kconfig b/hw/Kconfig index b6fb6a4507..ad20cce0a9 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -82,3 +82,4 @@ config XLNX_ZYNQMP select CAN_BUS select PTIMER select XLNX_BBRAM + select XLNX_EFUSE_ZYNQMP diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c index b247c5779b..3dc2b5e8ca 100644 --- a/hw/arm/xlnx-zcu102.c +++ b/hw/arm/xlnx-zcu102.c @@ -110,6 +110,18 @@ static void bbram_attach_drive(XlnxBBRam *dev) } } =20 +static void efuse_attach_drive(XlnxEFuse *dev) +{ + DriveInfo *dinfo; + BlockBackend *blk; + + dinfo =3D drive_get_by_index(IF_PFLASH, 3); + blk =3D dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; + if (blk) { + qdev_prop_set_drive(DEVICE(dev), "drive", blk); + } +} + static void xlnx_zcu102_init(MachineState *machine) { XlnxZCU102 *s =3D ZCU102_MACHINE(machine); @@ -151,6 +163,9 @@ static void xlnx_zcu102_init(MachineState *machine) /* Attach bbram backend, if given */ bbram_attach_drive(&s->soc.bbram); =20 + /* Attach efuse backend, if given */ + efuse_attach_drive(&s->soc.efuse); + /* Create and plug in the SD cards */ for (i =3D 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { BusState *bus; diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index 1e8e2ddcc2..1c52a575aa 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -69,6 +69,9 @@ #define BBRAM_ADDR 0xffcd0000 #define BBRAM_IRQ 11 =20 +#define EFUSE_ADDR 0xffcc0000 +#define EFUSE_IRQ 87 + #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */ =20 static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] =3D { @@ -245,6 +248,31 @@ static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *= s, qemu_irq *gic) sysbus_connect_irq(sbd, 0, gic[BBRAM_IRQ]); } =20 +static void xlnx_zynqmp_create_efuse(XlnxZynqMPState *s, qemu_irq *gic) +{ + Object *bits =3D OBJECT(&s->efuse); + Object *ctrl =3D OBJECT(&s->efuse_ctrl); + SysBusDevice *sbd; + + object_initialize_child(OBJECT(s), "efuse-ctrl", &s->efuse_ctrl, + TYPE_XLNX_ZYNQMP_EFUSE); + + object_initialize_child_with_props(ctrl, "xlnx-efuse@0", bits, + sizeof(s->efuse), + TYPE_XLNX_EFUSE, &error_abort, + "efuse-nr", "3", + "efuse-size", "2048", + NULL); + + qdev_realize(DEVICE(bits), NULL, &error_abort); + object_property_set_link(ctrl, "efuse", bits, &error_abort); + + sbd =3D SYS_BUS_DEVICE(ctrl); + sysbus_realize(sbd, &error_abort); + sysbus_mmio_map(sbd, 0, EFUSE_ADDR); + sysbus_connect_irq(sbd, 0, gic[EFUSE_IRQ]); +} + static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s) { static const struct UnimpInfo { @@ -646,6 +674,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error= **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]); =20 xlnx_zynqmp_create_bbram(s, gic_spi); + xlnx_zynqmp_create_efuse(s, gic_spi); xlnx_zynqmp_create_unimp_mmio(s); =20 for (i =3D 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) { diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h index 067e8a5238..062e637fe4 100644 --- a/include/hw/arm/xlnx-zynqmp.h +++ b/include/hw/arm/xlnx-zynqmp.h @@ -37,6 +37,7 @@ #include "net/can_emu.h" #include "hw/dma/xlnx_csu_dma.h" #include "hw/nvram/xlnx-bbram.h" +#include "hw/nvram/xlnx-zynqmp-efuse.h" =20 #define TYPE_XLNX_ZYNQMP "xlnx-zynqmp" OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPState, XLNX_ZYNQMP) @@ -102,6 +103,8 @@ struct XlnxZynqMPState { MemoryRegion *ddr_ram; MemoryRegion ddr_ram_low, ddr_ram_high; XlnxBBRam bbram; + XlnxEFuse efuse; + XlnxZynqMPEFuse efuse_ctrl; =20 MemoryRegion mr_unimp[XLNX_ZYNQMP_NUM_UNIMP_AREAS]; =20 --=20 2.25.1 From nobody Sat Apr 27 23:16:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1631856648; cv=pass; d=zohomail.com; s=zohoarc; b=SKvV4k6l8LLaWeuo1rOh1uG1phw8bPETTl4vrq7vy7+pcfrY0pQFkHwd7LysAzzdqa/IDSlSnkq2tiCKgeJMg+Wlb35ZnzwGS1A8J9QQkYboKekHonngjWXbsnbSQDOMxfSlvZyS/T78IneePJcvUh3CrXWYIXrGGWCLHbPcQMU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631856648; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nrTdR/n/sMT6IVhrO6KZrvuoPcX36NipLeQsyFIzeBY=; b=nnteo2XhyCrYJ+Bx4mZe97Ifx0QknDXQ8tisMhrMuxNKhZT5lIo0W2dy2MXR7IGy9wwJDsl77ao6d7I7dG4IbWmNjTBIhw6EQ9OSr9pEh3gykruDUahDMBrYRb2cik4dwUmJCvE671Cc+twBzUCoc2uxFiAfpckN/RfQItnPLQw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631856648753321.5141801085963; Thu, 16 Sep 2021 22:30:48 -0700 (PDT) Received: from localhost ([::1]:45534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mR6SV-0003VN-Lf for importer@patchew.org; Fri, 17 Sep 2021 01:30:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MK-0002pK-V8; Fri, 17 Sep 2021 01:24:24 -0400 Received: from mail-bn7nam10on2059.outbound.protection.outlook.com ([40.107.92.59]:25312 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mR6MJ-00065I-8d; Fri, 17 Sep 2021 01:24:24 -0400 Received: from DM5PR19CA0002.namprd19.prod.outlook.com (2603:10b6:3:151::12) by SN6PR02MB4654.namprd02.prod.outlook.com (2603:10b6:805:aa::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 05:24:20 +0000 Received: from DM3NAM02FT008.eop-nam02.prod.protection.outlook.com (2603:10b6:3:151:cafe::4d) by DM5PR19CA0002.outlook.office365.com (2603:10b6:3:151::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:20 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT008.mail.protection.outlook.com (10.13.5.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 05:24:20 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 16 Sep 2021 22:24:01 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 16 Sep 2021 22:24:01 -0700 Received: from [172.19.2.40] (port=58118 helo=xsjtongh40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mR6Lw-0005Y7-WE; Thu, 16 Sep 2021 22:24:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1N9G2K4qFygmPJNzsgbAhlJ4qL7WTKNchS11XdjtGbitvCp+gb7SO/zr+JZKbtimAiL7RZsKrg6wqI0JT2Q1c1ETpIY9MCbKoINU13YsQPfGvFeYc9ATaknE6QhKLOoEO79fdQhJC8EjVFMt54bM7JAwlvnw1ZOO4l/p0O0aMxoLKnLQFK9TjHORyLf1P0roKje6w79pIeIgzv4h1yl8blvWMO23zOHOOm08GrSGPLTPVHloOBvCOC0s3690VEGsQqFIx+yoekVrhmM/ZdYF8CrfX57JGZkKuZ57wbKUHTu5v+GXx6yja4zFtl170BmbzOzuM3f+27wXmlo/GLAmQ== 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; bh=nrTdR/n/sMT6IVhrO6KZrvuoPcX36NipLeQsyFIzeBY=; b=HlSKwNeYNJmqtlpog/XgZ3lTU+N977rQ2uZC6vcYpPb/koq5jXuE/0E5VaNfxg8VAnYtuLVljwL0RW71KW7MAa/4XZEMBrpVm3ciihfHbV5MQGR6QG88/3Ti+mnQ0low+54VgaTj9h2Bt5RDXJo1dgTArLM55jh4iRIlXIjVwpM9Mw7/AeVGEoFEWEcPdGkILWN1HpO/jzfWpgtd1zc0uXETbsFg8DAulFvX+A1Dawm6g8j3NfHOZu8kcf5Fvs5e8j8OV3KeEgOmHg5Q9KqmuOza+oExTYdCz/16UySDEtxgqU6bWW1WcWMNKszfHJ0tdC36LhpAth4HfAob1wmbZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=nongnu.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nrTdR/n/sMT6IVhrO6KZrvuoPcX36NipLeQsyFIzeBY=; b=cO2A4aEx97auWuIGCaTdw/9jDagqqmDWBFzH/RFB3YR0izYny0NafbhPzXhT7CG5LkVoWABkCd4shorKEEuINWOEbrEq+XInRDlAC5bDox09u+dmfmEa7UGDZ5wh8vZqcYRSosgSh5uhWAWWjWr02d76dxpZ70MvNGLy5ybPW6w= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Tong Ho To: Subject: [PATCH v3 9/9] docs/system/arm: xlnx-versal-virt: BBRAM and eFUSE Usage Date: Thu, 16 Sep 2021 22:24:00 -0700 Message-ID: <20210917052400.1249094-10-tong.ho@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052400.1249094-1-tong.ho@xilinx.com> References: <20210917052400.1249094-1-tong.ho@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a648e9f4-adbf-43ba-7811-08d9799b66d1 X-MS-TrafficTypeDiagnostic: SN6PR02MB4654: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zDvj301pGde3yJ71h8CN+LSclcTvYPI/tPQzo1XYV+96XYS0Q7Efi6eOxCbw1SYUuSRwvLdqw4WmaPnjEKDB/U+zg648kN+/ESJvh9Ty/kcRhxkVpop/7crx7Es2rYTpCfWOOQm3sLGl3eU0BniDCid+StBkgRtV26CGRUXoF51IVlqt+obyhGDELd562ZHtKuzUzDkbuouF9edHqCEgplqZ3t35BnBSbqKwbLmPdK5IYEt44oYwylS4JX7Ldjj5iJFyxF7RkJKZSrkBXj/geSQD0pUu2ErH6a6uctZJ/8HM+XgryWJwCAkx0MYjBhHAAO0cw+xbAHVg1UCS+2eBKJ9eRsl4ck4hdUzxIdoYLZDscGf5Skyhpqqf1mcuy4mnsMH54xjF/HcxaHIKa2u5ZKZs+VdW21w414igeeZ0gfVGXT4JYV4ZklZRbzTvzrbj256uOiyeEtB9K86x1gcOxuQ+SYbrL9c7zgR0nPjjk6z/tVUA7QmuFxxpcz2hS1kTnCIK8WfCWXZV4cCRmGE3BU4o5wlmsXUEWM9veJGJfrxCvTQ/CNDmFwxPCexOyfBWTUcw9qZ8DQ+Jo4INRetdMIQ5e2s+FOy4gyvJ8cyE0Vo5cRTod8sOpV2pX78RXdqAS/AlQXLOELfTyKv9nBGre7P1kvlC6ZIobEZyqgZB/kHB5F01FCDk8GPrQ9bPFmJ8Y2UzYyWvUju0OgkjenagLWkz61tpdj4prRefzn+GvhE= X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(376002)(396003)(136003)(39860400002)(346002)(46966006)(36840700001)(36860700001)(70586007)(356005)(7696005)(70206006)(2906002)(9786002)(44832011)(8936002)(4326008)(83380400001)(82310400003)(8676002)(2616005)(26005)(186003)(36906005)(336012)(426003)(7636003)(36756003)(82740400003)(54906003)(316002)(47076005)(1076003)(5660300002)(478600001)(107886003)(6916009)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 05:24:20.0621 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a648e9f4-adbf-43ba-7811-08d9799b66d1 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4654 Received-SPF: pass client-ip=40.107.92.59; envelope-from=tongh@xilinx.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, WEIRD_QUOTING=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, alistair@alistair23.me, tong.ho@xilinx.com, qemu-devel@nongnu.org, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1631856651056100001 Content-Type: text/plain; charset="utf-8" Add BBRAM and eFUSE usage to the Xilinx Versal Virt board document. Signed-off-by: Tong Ho --- docs/system/arm/xlnx-versal-virt.rst | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs/system/arm/xlnx-versal-virt.rst b/docs/system/arm/xlnx-ve= rsal-virt.rst index 27f73500d9..92ad10d2da 100644 --- a/docs/system/arm/xlnx-versal-virt.rst +++ b/docs/system/arm/xlnx-versal-virt.rst @@ -32,6 +32,8 @@ Implemented devices: - OCM (256KB of On Chip Memory) - XRAM (4MB of on chip Accelerator RAM) - DDR memory +- BBRAM (36 bytes of Battery-backed RAM) +- eFUSE (3072 bytes of one-time field-programmable bit array) =20 QEMU does not yet model any other devices, including the PL and the AI Eng= ine. =20 @@ -175,3 +177,50 @@ Run the following at the U-Boot prompt: fdt set /chosen/dom0 reg <0x00000000 0x40000000 0x0 0x03100000> booti 30000000 - 20000000 =20 +BBRAM File Backend +"""""""""""""""""" +BBRAM can have an optional file backend, which must be a seekable +binary file with a size of 36 bytes or larger. A file with all +binary 0s is a 'blank'. + +To add a file-backend for the BBRAM: + +.. code-block:: bash + + -drive if=3Dpflash,index=3D0,file=3Dversal-bbram.bin,format=3Draw + +To use a different index value, N, from default of 0, add: + +.. code-block:: bash + + -global xlnx,bbram-ctrl.drive-index=3DN + +eFUSE File Backend +"""""""""""""""""" +eFUSE can have an optional file backend, which must be a seekable +binary file with a size of 3072 bytes or larger. A file with all +binary 0s is a 'blank'. + +To add a file-backend for the eFUSE: + +.. code-block:: bash + + -drive if=3Dpflash,index=3D1,file=3Dversal-efuse.bin,format=3Draw + +To use a different index value, N, from default of 1, add: + +.. code-block:: bash + + -global xlnx,efuse.drive-index=3DN + +.. warning:: + In actual physical Versal, BBRAM and eFUSE contain sensitive data. + The QEMU device models do **not** encrypt nor obfuscate any data + when holding them in models' memory or when writing them to their + file backends. + + Thus, a file backend should be used with caution, and 'format=3Dluks' + is highly recommended (albeit with usage complexity). + + Better yet, do not use actual product data when running guest image + on this Xilinx Versal Virt board. --=20 2.25.1