From nobody Sun Nov 24 16:45:15 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-Seal: i=1; a=rsa-sha256; t=1722527134; cv=none; d=zohomail.com; s=zohoarc; b=lFLvcFS9QVr4rPZbkpw0FLvLcgJhDoxNG/FMHoJbU6jGlEbFYuRc5poV/VMipdf8+FAuy2guUfaEVAvl8bbi1TD9R9pPtsckWscURtqK7EQhkI1DRlzFdMT60hc9Z5NQ+UQxyS81k/4/XnylSqyIFU7U/FsXVlxXV5qT9hzk8Ys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722527134; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iOcxENO/NtiZFPfJ974c9QJwDS10GWjPf+VhG/y5myk=; b=MlmmTDUE59RrueguKgtGORoKJusvt1hzHKt9YjZF+ediQ/9mvinByn1+1Njq2Ssub6XNESi1hX/IfuEWr9Ov2HqroDNTHkPyNIvTUH5QbKSi0qQIWejl7nuwrjUhJ8gbcFax+cwKgp1uY9oAB3uBL62PoMb5yG8WmQJ6HUb+QrE= ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722527134337475.2516140628493; Thu, 1 Aug 2024 08:45:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZXyZ-00083z-8M; Thu, 01 Aug 2024 11:44:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZXyY-0007xO-06 for qemu-devel@nongnu.org; Thu, 01 Aug 2024 11:44:22 -0400 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZXyW-00051G-5S for qemu-devel@nongnu.org; Thu, 01 Aug 2024 11:44:21 -0400 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-264988283a3so4162322fac.0 for ; Thu, 01 Aug 2024 08:44:19 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.197.107.101]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b762e9c650sm17183a12.16.2024.08.01.08.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722527058; x=1723131858; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iOcxENO/NtiZFPfJ974c9QJwDS10GWjPf+VhG/y5myk=; b=ItorM6JulcKTjltJ3TRtj0ZqD2Hf0SeTOJO1E5rvTpdqgYWLZcjOPoSB1Nc8RLOBnX rcwVa5jF5cSflL5AvyG4JgOnukE++5dyMj7q6Qzfe1gbdSncb2mz4INY93E5mVNpoJm4 g9QRnC9P/rTr88Fobt+4At2qoN3Rg5wSiE09H4oUuNoVpOc9G6AH87cbXWAklVlUmQSs COxOOWIzkizQGIT8S6mbXqnPkoI3iQlEVs6B4YzQCueQ8H8gL21c/dHktB6aZrJZkUqu 3KXubBaGUjBH1wexoFm7/tWwjoYTsqmeo6s7PRk27bZsORB1YCF56PIudQa9O4UmjVL8 HGwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722527058; x=1723131858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iOcxENO/NtiZFPfJ974c9QJwDS10GWjPf+VhG/y5myk=; b=GsfUBB8iImqjQNDjwZu2rsLL2u89SNbAWfgbzG2ixc8msz1qrosKVDIxJUitlFQiMX T8/55CpSzLsION/wP7VGKTDVGmm42uoXE7WkFYoxbJKp/zP6lHTz/nDxkNS5I0468W7Y 7NuTJc9Xdo/YMlIuGWoEIOKZkyUhwqsbi22xt6+dzeoTz0GDbkf7qT7scmyFAwUx9+dx GvFZ/YAvc0Zp1Iihv9MuXZRhshzRKnKPKBCeEMRy+45YfLDYo6dz6xlQCPINrdqeLeSE +mn9xLci7AsElhllUcCvm4q6i3/AQTpys2ipjW01GgVbmfvqX6Hqel3Cp9Mf9xqtzxvP wpbQ== X-Gm-Message-State: AOJu0Ywame6sAEIEFyseyMyQKcVxVroXMh/YHSHq/U5+LlWCY8LaX8Je Xzyfz7Ii62i0Fd6CpKMJ4fBB6sXWQhzNcCgBBTR3y07vKHf+WoQ5qXyU31mHiJfyA1MX5LTb4gt P X-Google-Smtp-Source: AGHT+IHNvpM48M2Z2eEKK6gZxhFVihIJsL41H9Orby+KHgCe1ouAOeKdcR5g2qvzC2KkA9w3KjGm8w== X-Received: by 2002:a05:6870:d151:b0:261:1a62:a829 with SMTP id 586e51a60fabf-26891f2175emr623357fac.46.1722527058590; Thu, 01 Aug 2024 08:44:18 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, jason.chien@sifive.com, frank.chang@sifive.com, ajones@ventanamicro.com, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH for-9.2 v6 10/12] hw/riscv/riscv-iommu: add DBG support Date: Thu, 1 Aug 2024 12:43:31 -0300 Message-ID: <20240801154334.1009852-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801154334.1009852-1-dbarboza@ventanamicro.com> References: <20240801154334.1009852-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 client-ip=2001:4860:4864:20::2e; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1722527135713116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach DBG support adds three additional registers: tr_req_iova, tr_req_ctl and tr_response. The DBG cap is always enabled. No on/off toggle is provided for it. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Alistair Francis --- hw/riscv/riscv-iommu-bits.h | 17 +++++++++++ hw/riscv/riscv-iommu.c | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h index da6fb603aa..9d59c5c78d 100644 --- a/hw/riscv/riscv-iommu-bits.h +++ b/hw/riscv/riscv-iommu-bits.h @@ -82,6 +82,7 @@ struct riscv_iommu_pq_record { #define RISCV_IOMMU_CAP_ATS BIT_ULL(25) #define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26) #define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28) +#define RISCV_IOMMU_CAP_DBG BIT_ULL(31) #define RISCV_IOMMU_CAP_PAS GENMASK_ULL(37, 32) #define RISCV_IOMMU_CAP_PD8 BIT_ULL(38) #define RISCV_IOMMU_CAP_PD17 BIT_ULL(39) @@ -184,6 +185,22 @@ enum { RISCV_IOMMU_INTR_COUNT }; =20 +/* 5.24 Translation request IOVA (64bits) */ +#define RISCV_IOMMU_REG_TR_REQ_IOVA 0x0258 + +/* 5.25 Translation request control (64bits) */ +#define RISCV_IOMMU_REG_TR_REQ_CTL 0x0260 +#define RISCV_IOMMU_TR_REQ_CTL_GO_BUSY BIT_ULL(0) +#define RISCV_IOMMU_TR_REQ_CTL_NW BIT_ULL(3) +#define RISCV_IOMMU_TR_REQ_CTL_PID GENMASK_ULL(31, 12) +#define RISCV_IOMMU_TR_REQ_CTL_DID GENMASK_ULL(63, 40) + +/* 5.26 Translation request response (64bits) */ +#define RISCV_IOMMU_REG_TR_RESPONSE 0x0268 +#define RISCV_IOMMU_TR_RESPONSE_FAULT BIT_ULL(0) +#define RISCV_IOMMU_TR_RESPONSE_S BIT_ULL(9) +#define RISCV_IOMMU_TR_RESPONSE_PPN RISCV_IOMMU_PPN_FIELD + /* 5.27 Interrupt cause to vector (64bits) */ #define RISCV_IOMMU_REG_ICVEC 0x02F8 =20 diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index d127838ef8..bf90cea674 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -1756,6 +1756,50 @@ static void riscv_iommu_process_icvec_update(RISCVIO= MMUState *s) riscv_iommu_get_icvec_vector(icvec, RISCV_IOMMU_INTR_P= Q)); } =20 +static void riscv_iommu_process_dbg(RISCVIOMMUState *s) +{ + uint64_t iova =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_TR_REQ_IOVA= ); + uint64_t ctrl =3D riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_TR_REQ_CTL); + unsigned devid =3D get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_DID); + unsigned pid =3D get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_PID); + RISCVIOMMUContext *ctx; + void *ref; + + if (!(ctrl & RISCV_IOMMU_TR_REQ_CTL_GO_BUSY)) { + return; + } + + ctx =3D riscv_iommu_ctx(s, devid, pid, &ref); + if (ctx =3D=3D NULL) { + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE, + RISCV_IOMMU_TR_RESPONSE_FAULT | + (RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED << 10)= ); + } else { + IOMMUTLBEntry iotlb =3D { + .iova =3D iova, + .perm =3D ctrl & RISCV_IOMMU_TR_REQ_CTL_NW ? IOMMU_RO : IOMMU_= RW, + .addr_mask =3D ~0, + .target_as =3D NULL, + }; + int fault =3D riscv_iommu_translate(s, ctx, &iotlb, false); + if (fault) { + iova =3D RISCV_IOMMU_TR_RESPONSE_FAULT | (((uint64_t) fault) <= < 10); + } else { + iova =3D iotlb.translated_addr & ~iotlb.addr_mask; + iova >>=3D TARGET_PAGE_BITS; + iova &=3D RISCV_IOMMU_TR_RESPONSE_PPN; + + /* We do not support superpages (> 4kbs) for now */ + iova &=3D ~RISCV_IOMMU_TR_RESPONSE_S; + } + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE, iova); + } + + riscv_iommu_reg_mod64(s, RISCV_IOMMU_REG_TR_REQ_CTL, 0, + RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); + riscv_iommu_ctx_put(s, ref); +} + typedef void riscv_iommu_process_fn(RISCVIOMMUState *s); =20 static void riscv_iommu_update_ipsr(RISCVIOMMUState *s, uint64_t data) @@ -1883,6 +1927,12 @@ static MemTxResult riscv_iommu_mmio_write(void *opaq= ue, hwaddr addr, =20 return MEMTX_OK; =20 + case RISCV_IOMMU_REG_TR_REQ_CTL: + process_fn =3D riscv_iommu_process_dbg; + regb =3D RISCV_IOMMU_REG_TR_REQ_CTL; + busy =3D RISCV_IOMMU_TR_REQ_CTL_GO_BUSY; + break; + default: break; } @@ -2055,6 +2105,9 @@ static void riscv_iommu_realize(DeviceState *dev, Err= or **errp) s->cap |=3D RISCV_IOMMU_CAP_SV32X4 | RISCV_IOMMU_CAP_SV39X4 | RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; } + /* Enable translation debug interface */ + s->cap |=3D RISCV_IOMMU_CAP_DBG; + /* Report QEMU target physical address space limits */ s->cap =3D set_field(s->cap, RISCV_IOMMU_CAP_PAS, TARGET_PHYS_ADDR_SPACE_BITS); @@ -2111,6 +2164,12 @@ static void riscv_iommu_realize(DeviceState *dev, Er= ror **errp) stl_le_p(&s->regs_wc[RISCV_IOMMU_REG_IPSR], ~0); stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_ICVEC], 0); stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_DDTP], s->ddtp); + /* If debug registers enabled. */ + if (s->cap & RISCV_IOMMU_CAP_DBG) { + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_TR_REQ_IOVA], 0); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_TR_REQ_CTL], + RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); + } =20 /* Memory region for downstream access, if specified. */ if (s->target_mr) { --=20 2.45.2