From nobody Mon Feb 9 09:34:43 2026 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=1dmarc=pass fromdomain=xilinx.com) ARC-Seal: i=2; a=rsa-sha256; t=1600957676; cv=pass; d=zohomail.com; s=zohoarc; b=bxTkszNuhcOxfTwnP/tMzKw7OyQ4JxNVsxVf9+Z0navh0NC45Zx57Y1bNRDEedXbR3EcAxd/JVeaX4ZQvh9vy9jtHf7O/xt/v08vT/y858EZvp7NkaXFt5163nlPoIFpwfECJs1zVDpf+5NfodGh+MiG17FyCxxwFtlP2Zu94AA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600957676; h=Content-Type: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=UGMjhOGlWII9upFOj1WGAEAbwykzpWtNVCvHbuOelTI=; b=Z1DUf4tXcoc2TPQTa7WCdrODfqtH3VEO6EO2NP/RVahRbFDwhoVZfgiM5Ch2di8FQA/2YW5nEXfoKd9SnST4gJi8yAeBP+OoGpazrwautHCAG/4DoM2VsD2rRXCfvhbwQowax1Om+uyeQKhUah1qTgelJsOf8wdZB3Jckhm+1uA= 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=1dmarc=pass fromdomain=xilinx.com) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600957676604335.6008837189353; Thu, 24 Sep 2020 07:27:56 -0700 (PDT) Received: from localhost ([::1]:51436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLSDx-0004q3-TZ for importer@patchew.org; Thu, 24 Sep 2020 10:27:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLS4R-0003ne-Ja for qemu-devel@nongnu.org; Thu, 24 Sep 2020 10:18:03 -0400 Received: from mail-mw2nam10on2045.outbound.protection.outlook.com ([40.107.94.45]:37473 helo=NAM10-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 1kLS49-0002Pk-Kv for qemu-devel@nongnu.org; Thu, 24 Sep 2020 10:18:03 -0400 Received: from SA0PR11CA0089.namprd11.prod.outlook.com (2603:10b6:806:d2::34) by DM5PR02MB3385.namprd02.prod.outlook.com (2603:10b6:4:68::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14; Thu, 24 Sep 2020 14:17:42 +0000 Received: from SN1NAM02FT024.eop-nam02.prod.protection.outlook.com (2603:10b6:806:d2:cafe::5) by SA0PR11CA0089.outlook.office365.com (2603:10b6:806:d2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.22 via Frontend Transport; Thu, 24 Sep 2020 14:17:42 +0000 Received: from xsj-pvapsmtpgw01 (149.199.60.83) by SN1NAM02FT024.mail.protection.outlook.com (10.152.72.127) with Microsoft SMTP Server id 15.20.3412.21 via Frontend Transport; Thu, 24 Sep 2020 14:17:42 +0000 Received: from [149.199.38.66] (port=46158 helo=smtp.xilinx.com) by xsj-pvapsmtpgw01 with esmtp (Exim 4.90) (envelope-from ) id 1kLS3p-0005Yk-1e; Thu, 24 Sep 2020 07:17:25 -0700 Received: from [127.0.0.1] (helo=xsj-smtp-dlp2.xlnx.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1kLS46-0007Tc-0i; Thu, 24 Sep 2020 07:17:42 -0700 Received: from xsj-pvapsmtp01 (xsj-mail.xilinx.com [149.199.38.66]) by xsj-smtp-dlp2.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id 08OEHeLe017391; Thu, 24 Sep 2020 07:17:41 -0700 Received: from [10.140.6.35] (helo=xhdsaipava40.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1kLS44-0007St-DS; Thu, 24 Sep 2020 07:17:40 -0700 Received: by xhdsaipava40.xilinx.com (Postfix, from userid 14131) id E2EE213C0663; Thu, 24 Sep 2020 19:51:00 +0530 (IST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGCLv0jebs1aFX6S0b2f2kE+g0I4XO+oLi36aP0s99x1RCleSf7TqIkONyWHPPPnwqAUki/H0XmkMgvJqnn9PGQ8d3LVj84tYpSyGw3lJwha35yVCLPFD9Dm3gguYGzX89g/jQOvTQDOjsp+xsq/ZaBWstiIgU55F+/+LcX2tFKbIwsGdpK+inltjYplMv2/KhC82I1XD3+uOzsr50pCQ/G39v4H8dI8f2DMBtrM2cpVbAEj+dbR+UjDyQZQjST8J4DzUT6Cofod4+Vb7i2kSBfe6WHd/ZHpBVC0laU1csxMkrGVr558Qro0EwYxfTMWGLmGbN9WO/QxPQRfOTGupA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UGMjhOGlWII9upFOj1WGAEAbwykzpWtNVCvHbuOelTI=; b=lFr1UVMoqT1GEp68CxGNNJu0UMbYxEYKEKGro6MSp7HhQv/h0W/kKz5A/oJiMn5xswf8wq4pitS3w0XEDUFiYMfZMYzddGdsUy1Hz6lObjbFdy7RCisJVSGPl7b8mnGI0gvNcSgzNEbgNI+PEp/9ZsKawQrBcHAN1J0S4/xWJDp0tjP7j8rWnbBPkTWb6P9WvixvgBjUxX7X9aLNXnBNwTGlSq/iXB/exE9WhP4JE8qzW6HZmKNE4HyfdevzBe5RerftaH7nfhtYIkicDQi/uvZkS5kjI0lBTtiaACrkbTfZ+SYcB0JfspzjRce6zq0N5w4O3YfhV/HZmIoifkjqqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.60.83) smtp.rcpttodomain=wdc.com smtp.mailfrom=xilinx.com; dmarc=bestguesspass 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=UGMjhOGlWII9upFOj1WGAEAbwykzpWtNVCvHbuOelTI=; b=hta30khEWXr2qedvpmHnsO78IvM6hwv+L+GnBXFc+Gb9zwcYHvmlQ/SF7oactXyClF7OgWOWxXXa5VuN9i3qu/F0o1dY1JywiKwQyh9YNixApJGKqgtpZrRmRTEKLdu/q3cejn3+c6XjomqePj/QaP3ApbFyVDkHDbWUkBQqLMU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=bestguesspass 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.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; From: Sai Pavan Boddu To: Peter Maydell , Markus Armbruster , =?UTF-8?q?=27Marc-Andr=C3=A9=20Lureau=27?= , Paolo Bonzini , Gerd Hoffmann , Edgar Iglesias , Francisco Eduardo Iglesias Subject: [PATCH v10 5/7] misc: Add versal-usb2-ctrl-regs module Date: Thu, 24 Sep 2020 19:50:54 +0530 Message-Id: <1600957256-6494-6-git-send-email-sai.pavan.boddu@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600957256-6494-1-git-send-email-sai.pavan.boddu@xilinx.com> References: <1600957256-6494-1-git-send-email-sai.pavan.boddu@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-MS-PublicTrafficType: Email MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: aaf91202-99cc-48dd-9ffa-08d8609499b9 X-MS-TrafficTypeDiagnostic: DM5PR02MB3385: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:352; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gNbKBa9e33Vi1gq6vE2YDT7g79FJsISt8k2G7gFu0VWMVUjwBvfpSQhG6kYOk5ai7xeK/8HGgOxAdsP6zXjJ0Ov5OdHmbykl3NBo4B7P76saVyzzCNCooxXxauoMB7iIL3jqmA1gGX9FSuMY6NpdaaUW7Mujmr34JfhEcVdR6V/C7og/7x/L3zgNruD4jyz8RI7xp2dqHc/e7inqED6EXfm9TmAhqhSPDHcDcEy/pd0Tisb2+Jp1y8YMhvG2vIoBKHKuWIiu6qLSr72PtaMV30GB6GbAZjV+/tGm6AyjTprOajsEtzsbaoiQ51vjtq+B6ev7eTh/+TTRgJNJ0T1/j0siGWqiTaCZHyzY+Lg13bFtdmyzlxPsqhZqJAtanfxNbntT3RCIsrvUmTvpnnuuXg== X-Forefront-Antispam-Report: CIP:149.199.60.83; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapsmtpgw01; PTR:unknown-60-83.xilinx.com; CAT:NONE; SFS:(39860400002)(136003)(346002)(376002)(396003)(46966005)(336012)(83380400001)(7416002)(36756003)(70206006)(6666004)(5660300002)(70586007)(8936002)(47076004)(2616005)(54906003)(82740400003)(426003)(82310400003)(81166007)(107886003)(6636002)(2906002)(478600001)(6266002)(30864003)(8676002)(42186006)(316002)(110136005)(4326008)(26005)(186003)(356005)(19627235002); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2020 14:17:42.3290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aaf91202-99cc-48dd-9ffa-08d8609499b9 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.83]; Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT024.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3385 Received-SPF: pass client-ip=40.107.94.45; envelope-from=saipava@xilinx.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/24 10:17:44 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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: Eduardo Habkost , Vikram Garhwal , qemu-devel@nongnu.org, Paul Zimmerman , Sai Pavan Boddu , Alistair Francis , Ying Fang , =?UTF-8?q?=27Philippe=20Mathieu-Daud=C3=A9=27?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This module emulates control registers of versal usb2 controller, this is a= dded just to make guest happy. In general this module would control the phy-reset signal from usb controller, data coherency of the transactions, signals the host system errors received from controller. Signed-off-by: Sai Pavan Boddu Signed-off-by: Vikram Garhwal --- hw/misc/meson.build | 1 + hw/misc/xlnx-versal-usb2-ctrl-regs.c | 222 +++++++++++++++++++++++= ++++ include/hw/misc/xlnx-versal-usb2-ctrl-regs.h | 45 ++++++ 3 files changed, 268 insertions(+) create mode 100644 hw/misc/xlnx-versal-usb2-ctrl-regs.c create mode 100644 include/hw/misc/xlnx-versal-usb2-ctrl-regs.h diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 793d45b..b336dd1 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -109,3 +109,4 @@ specific_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files= ('mips_cmgcr.c', 'mips_cp specific_ss.add(when: 'CONFIG_MIPS_ITU', if_true: files('mips_itu.c')) =20 specific_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) +specific_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-us= b2-ctrl-regs.c')) diff --git a/hw/misc/xlnx-versal-usb2-ctrl-regs.c b/hw/misc/xlnx-versal-usb= 2-ctrl-regs.c new file mode 100644 index 0000000..94fd7cf --- /dev/null +++ b/hw/misc/xlnx-versal-usb2-ctrl-regs.c @@ -0,0 +1,222 @@ +/* + * QEMU model of the VersalUsb2CtrlRegs Register control/Status block for + * USB2.0 controller + * + * This module should control phy_reset, permanent device plugs, frame len= gth + * time adjust & setting of coherency paths. None of which are emulated in + * present model. + * + * Copyright (c) 2020 Xilinx Inc. Vikram Garhwal + * + * 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/sysbus.h" +#include "hw/irq.h" +#include "hw/register.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qom/object.h" +#include "migration/vmstate.h" +#include "hw/misc/xlnx-versal-usb2-ctrl-regs.h" + +#ifndef XILINX_VERSAL_USB2_CTRL_REGS_ERR_DEBUG +#define XILINX_VERSAL_USB2_CTRL_REGS_ERR_DEBUG 0 +#endif + +REG32(BUS_FILTER, 0x30) + FIELD(BUS_FILTER, BYPASS, 0, 4) +REG32(PORT, 0x34) + FIELD(PORT, HOST_SMI_BAR_WR, 4, 1) + FIELD(PORT, HOST_SMI_PCI_CMD_REG_WR, 3, 1) + FIELD(PORT, HOST_MSI_ENABLE, 2, 1) + FIELD(PORT, PWR_CTRL_PRSNT, 1, 1) + FIELD(PORT, HUB_PERM_ATTACH, 0, 1) +REG32(JITTER_ADJUST, 0x38) + FIELD(JITTER_ADJUST, FLADJ, 0, 6) +REG32(BIGENDIAN, 0x40) + FIELD(BIGENDIAN, ENDIAN_GS, 0, 1) +REG32(COHERENCY, 0x44) + FIELD(COHERENCY, USB_COHERENCY, 0, 1) +REG32(XHC_BME, 0x48) + FIELD(XHC_BME, XHC_BME, 0, 1) +REG32(REG_CTRL, 0x60) + FIELD(REG_CTRL, SLVERR_ENABLE, 0, 1) +REG32(IR_STATUS, 0x64) + FIELD(IR_STATUS, HOST_SYS_ERR, 1, 1) + FIELD(IR_STATUS, ADDR_DEC_ERR, 0, 1) +REG32(IR_MASK, 0x68) + FIELD(IR_MASK, HOST_SYS_ERR, 1, 1) + FIELD(IR_MASK, ADDR_DEC_ERR, 0, 1) +REG32(IR_ENABLE, 0x6c) + FIELD(IR_ENABLE, HOST_SYS_ERR, 1, 1) + FIELD(IR_ENABLE, ADDR_DEC_ERR, 0, 1) +REG32(IR_DISABLE, 0x70) + FIELD(IR_DISABLE, HOST_SYS_ERR, 1, 1) + FIELD(IR_DISABLE, ADDR_DEC_ERR, 0, 1) +REG32(USB3, 0x78) + +static void ir_update_irq(VersalUsb2CtrlRegs *s) +{ + bool pending =3D s->regs[R_IR_STATUS] & ~s->regs[R_IR_MASK]; + qemu_set_irq(s->irq_ir, pending); +} + +static void ir_status_postw(RegisterInfo *reg, uint64_t val64) +{ + VersalUsb2CtrlRegs *s =3D XILINX_VERSAL_USB2_CTRL_REGS(reg->opaque); + /* + * TODO: This should also clear USBSTS.HSE field in USB XHCI register. + * May be combine both the modules. + */ + ir_update_irq(s); +} + +static uint64_t ir_enable_prew(RegisterInfo *reg, uint64_t val64) +{ + VersalUsb2CtrlRegs *s =3D XILINX_VERSAL_USB2_CTRL_REGS(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_IR_MASK] &=3D ~val; + ir_update_irq(s); + return 0; +} + +static uint64_t ir_disable_prew(RegisterInfo *reg, uint64_t val64) +{ + VersalUsb2CtrlRegs *s =3D XILINX_VERSAL_USB2_CTRL_REGS(reg->opaque); + uint32_t val =3D val64; + + s->regs[R_IR_MASK] |=3D val; + ir_update_irq(s); + return 0; +} + +static const RegisterAccessInfo usb2_regs_regs_info[] =3D { + { .name =3D "BUS_FILTER", .addr =3D A_BUS_FILTER, + .rsvd =3D 0xfffffff0, + },{ .name =3D "PORT", .addr =3D A_PORT, + .rsvd =3D 0xffffffe0, + },{ .name =3D "JITTER_ADJUST", .addr =3D A_JITTER_ADJUST, + .reset =3D 0x20, + .rsvd =3D 0xffffffc0, + },{ .name =3D "BIGENDIAN", .addr =3D A_BIGENDIAN, + .rsvd =3D 0xfffffffe, + },{ .name =3D "COHERENCY", .addr =3D A_COHERENCY, + .rsvd =3D 0xfffffffe, + },{ .name =3D "XHC_BME", .addr =3D A_XHC_BME, + .reset =3D 0x1, + .rsvd =3D 0xfffffffe, + },{ .name =3D "REG_CTRL", .addr =3D A_REG_CTRL, + .rsvd =3D 0xfffffffe, + },{ .name =3D "IR_STATUS", .addr =3D A_IR_STATUS, + .rsvd =3D 0xfffffffc, + .w1c =3D 0x3, + .post_write =3D ir_status_postw, + },{ .name =3D "IR_MASK", .addr =3D A_IR_MASK, + .reset =3D 0x3, + .rsvd =3D 0xfffffffc, + .ro =3D 0x3, + },{ .name =3D "IR_ENABLE", .addr =3D A_IR_ENABLE, + .rsvd =3D 0xfffffffc, + .pre_write =3D ir_enable_prew, + },{ .name =3D "IR_DISABLE", .addr =3D A_IR_DISABLE, + .rsvd =3D 0xfffffffc, + .pre_write =3D ir_disable_prew, + },{ .name =3D "USB3", .addr =3D A_USB3, + } +}; + +static void usb2_regs_reset(DeviceState *dev) +{ + VersalUsb2CtrlRegs *s =3D XILINX_VERSAL_USB2_CTRL_REGS(dev); + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(s->regs_info); ++i) { + register_reset(&s->regs_info[i]); + } + + ir_update_irq(s); +} + +static const MemoryRegionOps usb2_regs_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 usb2_regs_init(Object *obj) +{ + VersalUsb2CtrlRegs *s =3D XILINX_VERSAL_USB2_CTRL_REGS(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + RegisterInfoArray *reg_array; + + memory_region_init(&s->iomem, obj, TYPE_XILINX_VERSAL_USB2_CTRL_REGS, + USB2_REGS_R_MAX * 4); + reg_array =3D + register_init_block32(DEVICE(obj), usb2_regs_regs_info, + ARRAY_SIZE(usb2_regs_regs_info), + s->regs_info, s->regs, + &usb2_regs_ops, + XILINX_VERSAL_USB2_CTRL_REGS_ERR_DEBUG, + USB2_REGS_R_MAX * 4); + memory_region_add_subregion(&s->iomem, + 0x0, + ®_array->mem); + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_irq(sbd, &s->irq_ir); +} + +static const VMStateDescription vmstate_usb2_regs =3D { + .name =3D TYPE_XILINX_VERSAL_USB2_CTRL_REGS, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, VersalUsb2CtrlRegs, USB2_REGS_R_MAX), + VMSTATE_END_OF_LIST(), + } +}; + +static void usb2_regs_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D usb2_regs_reset; + dc->vmsd =3D &vmstate_usb2_regs; +} + +static const TypeInfo usb2_regs_info =3D { + .name =3D TYPE_XILINX_VERSAL_USB2_CTRL_REGS, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VersalUsb2CtrlRegs), + .class_init =3D usb2_regs_class_init, + .instance_init =3D usb2_regs_init, +}; + +static void usb2_regs_register_types(void) +{ + type_register_static(&usb2_regs_info); +} + +type_init(usb2_regs_register_types) diff --git a/include/hw/misc/xlnx-versal-usb2-ctrl-regs.h b/include/hw/misc= /xlnx-versal-usb2-ctrl-regs.h new file mode 100644 index 0000000..975a717 --- /dev/null +++ b/include/hw/misc/xlnx-versal-usb2-ctrl-regs.h @@ -0,0 +1,45 @@ +/* + * QEMU model of the VersalUsb2CtrlRegs Register control/Status block for + * USB2.0 controller + * + * Copyright (c) 2020 Xilinx Inc. Vikram Garhwal + * + * 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_USB2_REGS_H_ +#define _XLNX_USB2_REGS_H_ + +#define TYPE_XILINX_VERSAL_USB2_CTRL_REGS "xlnx.versal-usb2-ctrl-regs" + +#define XILINX_VERSAL_USB2_CTRL_REGS(obj) \ + OBJECT_CHECK(VersalUsb2CtrlRegs, (obj), TYPE_XILINX_VERSAL_USB2_CTRL_= REGS) + +#define USB2_REGS_R_MAX ((0x78 / 4) + 1) + +typedef struct VersalUsb2CtrlRegs { + SysBusDevice parent_obj; + MemoryRegion iomem; + qemu_irq irq_ir; + + uint32_t regs[USB2_REGS_R_MAX]; + RegisterInfo regs_info[USB2_REGS_R_MAX]; +} VersalUsb2CtrlRegs; + +#endif --=20 2.7.4