From nobody Sat Nov 23 20:56:48 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1730347198; cv=none; d=zohomail.com; s=zohoarc; b=DONvog5nATo3shm39L3Z2okPD17Dn2tO4NUSHeoJWPs4T6Xu72w0L2JBFEAaTBA0WaLkLAfooHfSQgQODwfxYctW2xenelXjHOYbEIVeE8qsrWO8hD2bBwu+CU3b+pCotdaVV4ie5ibIEiN1qfg0jW3DrzlxoRK2fM8jFZMImbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730347198; 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=cx0Q7bCE/J0FipubUOwFDCZkHtQ/CtbKr+Goun6/KbM=; b=V2EowawfoctHt9NAtNhCE7gQPCg9AWkprGsIpnP9msid49JJ3jOyK+CIfwKwbSv6a4wQnYLvG2tesQwMqCsA5TLxH3rpnGjIbCx/foMeyVxWuum2OGN/jMkecUIFyVRY+SD5UTWS/lPi9nKFPh770iwxCJf/alhnLNQFu9uIjIc= 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; dmarc=pass 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 1730347198102384.2729004385328; Wed, 30 Oct 2024 20:59:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6MI4-0005N5-Rd; Wed, 30 Oct 2024 23:56:09 -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 1t6MHq-0004A3-FS for qemu-devel@nongnu.org; Wed, 30 Oct 2024 23:55:54 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6MHo-0004Gg-Pe for qemu-devel@nongnu.org; Wed, 30 Oct 2024 23:55:54 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-20cb47387ceso5269405ad.1 for ; Wed, 30 Oct 2024 20:55:52 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21105707064sm3022795ad.70.2024.10.30.20.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 20:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730346951; x=1730951751; 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=cx0Q7bCE/J0FipubUOwFDCZkHtQ/CtbKr+Goun6/KbM=; b=nREuHJpa9+LO3740wG879MMABZ8LOUlIJ4BeE20Tn7uKiht/LgqSY0CSfBHSUWaDh+ lurSrHGq7iNMn32mKJA3+QXdXkr8IFpFOTn0ETVSI96je7ieFwFAmFInVbF5aVIUfRj1 J2M1ghZqcfEvUER8IQjdeKCSBoigIFxld+XEr8wL3kvtdQAK1wfALITlXk/EvuHjNyyD peM+jH8DLIAyz2/y8nvuOClCYb2PDXfEvotwthuno4P6Ip6YdxIA+9FXmPRcMlZ/HrQH 1+UbclXEb0y4wAfTN9Dp0eSlyZ/UtUZcHMv0I1RfPc/ije69GBR1iM68ui7se1grnMnM Yk5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730346951; x=1730951751; 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=cx0Q7bCE/J0FipubUOwFDCZkHtQ/CtbKr+Goun6/KbM=; b=o+r6pUpJMwPqSxvgldYIeSG0PpJUVohFRu6Lv4LFyNfk64AnxlrcHpjwxgXV5sG06x 5w9Hs7oWxejhUyGlGFP1tZfjxIYmPB6kgGoty2L8ugUIxR76onbKEuB1rIlS3ZY6ivhe 9See7pyEqhcyR6S9JYl4sXuegWdlj04ik+hbPOUnLEN9Y1xzsZMGTA98X+kDUTzwslxm E/EeVs8SI4g6gshSclqreYZmK5Mu4cU/4ngfVduHs+ru7NDoxosbtKQJ1MAs0cX6NFmF MGKubWMkyE3r/TRmCdcmanqouHd8bjHLcAmlf1Er8pe9q0CpnMegqOwbyULI8JW2CX9y GptA== X-Gm-Message-State: AOJu0YzCkdCB/abu+QmF53YCEjKlcenHbgdu+Yejp5C1VdPcLR8+30iD /2YumtnbvXFdbeU+jE8hiFPsfnP7ZsieSKBUPjKexpN8fSwpaHWIf3lHT3QO X-Google-Smtp-Source: AGHT+IFlf4JdNNzc+VaMwnp75n2S3GmSdUjqn9SAf+CYSxCoIMHeNqceNGTM6Y9GeFDEBjTpXsFamQ== X-Received: by 2002:a17:903:41c4:b0:20c:6b11:deef with SMTP id d9443c01a7336-210c6c3692dmr245692865ad.48.1730346950865; Wed, 30 Oct 2024 20:55:50 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 45/50] hw/riscv/riscv-iommu: add DBG support Date: Thu, 31 Oct 2024 13:53:13 +1000 Message-ID: <20241031035319.731906-46-alistair.francis@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241031035319.731906-1-alistair.francis@wdc.com> References: <20241031035319.731906-1-alistair.francis@wdc.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=2607:f8b0:4864:20::62b; envelope-from=alistair23@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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.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 @gmail.com) X-ZM-MESSAGEID: 1730347199415116600 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 Message-ID: <20241016204038.649340-11-dbarboza@ventanamicro.com> Signed-off-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 96a994b9aa..6359ae0353 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 #define RISCV_IOMMU_ICVEC_CIV GENMASK_ULL(3, 0) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 1a8da005c0..feb650549a 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -1764,6 +1764,50 @@ static void riscv_iommu_process_pq_control(RISCVIOMM= UState *s) riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, ctrl_set, ctrl_clr); } =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_icvec(RISCVIOMMUState *s, uint64_t data) @@ -1928,6 +1972,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; } @@ -2065,6 +2115,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); @@ -2121,6 +2174,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.47.0