From patchwork Mon Feb 24 19:08:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8513AC021A4 for ; Mon, 24 Feb 2025 19:09:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdp6-0005f2-Hi; Mon, 24 Feb 2025 14:09:04 -0500 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 1tmdom-0005cY-LY for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:42 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdok-0004mS-45 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:39 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-220c665ef4cso83363435ad.3 for ; Mon, 24 Feb 2025 11:08:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424115; x=1741028915; 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=H5YKF3HsuWUbiaPLrEWpm5TtTdaWovSQz+CQU4mRVEM=; b=dpK6cZ2QMtzDHQv4rI3ryw/lvFDX3IXr1yUy19U0jFus831iUieovlFiO0OE8EO6O3 gAkmv/LFc/bHOXBk3NZq+abJ7ewRE3Mc/i+qifDaBDp4CWFoF9KryvemJR4PS1sw5vEK AbXp3NQt/jwSxPTPZwp9IsVw6X2VI98neo5YrEArfYHDNh/eIamu5ceFBfUxHDqBDHCR ulJY1ABVN4RvSfu4rfbn4ZA8J0bmKRUCght9bhA5BDHenDw7pfAHWuFBN9ieHQI9+/pg 7y7NsEQi47NBv7gBfN7BjmSWLqKz8LQDFOzUFXImYwDWJJw4+Gq6XZtN73XDytjBfGPZ Bnpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424115; x=1741028915; 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=H5YKF3HsuWUbiaPLrEWpm5TtTdaWovSQz+CQU4mRVEM=; b=q6ZQoumh8toHWhb/YVa9XyB3nyM6tFZckuQCVW4l9uFD7d0H6+q+iJZtOR/NZcphpU 7aB8nUo3hG4ukfbM9nE/MAWF74dW7mgUmjELpn41N7bbfr6uovKKxlJe45/qdKCdRlWe UhTj0nr+6j4Pxm/6hgu6ujuN2DTPw9VF3bW5hvzbMxIBmf9RLTwQwlwMmqv57wQflXTF xTH4yocqpDlbHpnwKqORtyrrP9vC+KiR0yFEYeI3ZYkdcNLyGyamBjiTFTk32IUmSzPT HGDUXHD808J1tD8OGq8pxXWtWdGekOjYxgLlLnobbzqbpLmzwYwex7TrXIA+kia3DxvX Lrng== X-Gm-Message-State: AOJu0Yz/2b01zrWsiW+du1egUbkFYtYl0Q2LuXMXQdzbF4wnO8OWG4Ef aU0sd/wUf6k9Wap8o1QFycR3eNLf9TTLpGMW01NXxFZnow9yfnhT9f8xl72nMFXSI+ejGitiXra z X-Gm-Gg: ASbGncvLEccJeJByqkvycLAXdsrN8ay/crz/fOSDgNum8WptQew0TtcoszXu4XCJ9B0 ZuUvEy5ARKtPTcXI0LjzspC31701IrFF4Be1xuzANu7RKbA+RdvfArxqWPIpjIDJ+8Opl1KrJof IB7aQ9yONhy+RVhzrbY5PbpTDdUOeWeFd8BD7FEsbnNbt7t0RkEgiJddyoNCbswsDL3l8WEwUV3 eC3WGvj6b+ORnBapScTQHWrnRZZg+afmXeHezFz0Q5zHj1T2ZqGtPsDrfZrJEA/Dip1qVv3HlRx CBMy8Qv+SUsF1eYGpdtRWPuuh1kcug== X-Google-Smtp-Source: AGHT+IHFR7q/79SWVCsSWTocNfY/RAdad1m2qaTUQPu16hfUp1z4NaZP/483YVQ8VlKndyGV0Z9boA== X-Received: by 2002:a17:902:f544:b0:215:6cb2:7877 with SMTP id d9443c01a7336-2219ff827cdmr287717055ad.4.1740424114844; Mon, 24 Feb 2025 11:08:34 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:34 -0800 (PST) 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, Daniel Henrique Barboza Subject: [PATCH v2 01/11] hw/riscv/riscv-iommu.h: add missing headers Date: Mon, 24 Feb 2025 16:08:16 -0300 Message-ID: <20250224190826.1858473-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x635.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This header is incomplete, i.e. it is using definitions that are being supplied by the .c files that are including it. Adding this header into a fresh .c file will result in errors: /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:30:17: error: field ‘parent_obj’ has incomplete type 30 | DeviceState parent_obj; | ^~~~~~~~~~ /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:50:5: error: unknown type name ‘dma_addr_t’; did you mean ‘in_addr_t’? 50 | dma_addr_t cq_addr; /* Command queue base physical address */ | ^~~~~~~~~~ | in_addr_t (...) /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:62:5: error: unknown type name ‘QemuThread’; did you mean ‘GThread’? 62 | QemuThread core_proc; /* Background processing thread */ | ^~~~~~~~~~ | GThread /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:63:5: error: unknown type name ‘QemuCond’ 63 | QemuCond core_cond; /* Background processing wake up signal */ | ^~~~~~~~ /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:71:18: error: field ‘trap_as’ has incomplete type 71 | AddressSpace trap_as; | ^~~~~~~ /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:72:18: error: field ‘trap_mr’ has incomplete type 72 | MemoryRegion trap_mr; | ^~~~~~~ /home/danielhb/work/qemu/hw/riscv/riscv-iommu.h:80:18: error: field ‘regs_mr’ has incomplete type 80 | MemoryRegion regs_mr; | ^~~~~~~ Fix it by adding the missing headers for these definitions. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/riscv-iommu.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index fa8a50fa24..d2608d2f9b 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -20,6 +20,8 @@ #define HW_RISCV_IOMMU_STATE_H #include "qom/object.h" +#include "hw/qdev-properties.h" +#include "system/dma.h" #include "hw/riscv/iommu.h" #include "hw/riscv/riscv-iommu-bits.h" From patchwork Mon Feb 24 19:08:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D086CC021BB for ; Mon, 24 Feb 2025 19:10:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpJ-0005iK-94; Mon, 24 Feb 2025 14:09:13 -0500 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 1tmdoo-0005d2-Cw for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:45 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdom-0004nB-B6 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:41 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-220ecbdb4c2so17471625ad.3 for ; Mon, 24 Feb 2025 11:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424118; x=1741028918; 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=JPj0bGMKB5weN7nB95sHvNTAUUO2MS1Ep+drM1URK0w=; b=S5eTTgQr8a/bAwV00jSmU7mi+1YthBDeoD3S3rjnnuwoVNX/riXz3ORfnF+2kaOrls 3gPBju7RykCgrG4VU5nAzy6w/e7CLpmjdo4RpVIpHnYGcIeqbwqWD16nus7XMLmF2HXm ruF9c5B6iOdLF+3DyDgvojCy8xKcHnQWmkYx3YqzjO9dtRW10Aw0Gni0G8XiRN4Hnsgc p2blPdvZCmb/tV4WWsj+Fn19RtxzqYVIFx7QVHUtMVgKHrpr73gjVfhP0Xvp+/oGJSJN +nCNq1PdSXPb0r2qKXng76oW/mztTrKikPqvC6TUP0QfCE+QTd8I35qN/rQZ/IwYo/hj XGcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424118; x=1741028918; 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=JPj0bGMKB5weN7nB95sHvNTAUUO2MS1Ep+drM1URK0w=; b=wEfu2Bbl8JHBQNWaf/NukZ5GL9cOF8c/oszE9BBTHoCZ74ha1OXGl1PtmWUiboQmcz NGowlb+w0UbGXYxqXdlulduFcufADf1V9lGND63uwiD1vQxUQWhPin8eeIxiQ/6odg8s PIEBRJxTsvdTDGemuA9qPSzG8Ok2f1Y2AJhGKj/z0hLNy00tlN+O+5Yw4QGJ5fv+FyUG 06grJEG+WsQUgrDkuquaxfsRr5C2VVNBDRzwyP0/887CRyri3V5rxM475qB+FoGq7BxR BYnUeR3hYXOuwxOhiCmv5+3hEB3z0cDwkf38KGC4N38jmXBnBSD7MnNwQubjuuAXXWoU qe0g== X-Gm-Message-State: AOJu0YybkipyzetamnpRnc43kzjLeXVoj0afEZ9wqJx3MJrkf6nGttXg KHS/UqfGx2B1hnLOf6P8u1rWZG3mq2hViq4TnnXDiO2iAqpT0583QQUqY/7NEVZH+JNbKHsKAbc k X-Gm-Gg: ASbGncvZOW3egWiiEFxI1euyw7BO2Wh95K1zmvH03lGwZI9i60XX9He4ceEmTvypYeR mPZEI9GuYosfa5vlkSrKWOUL8X09e+cIZqPMvW2o2bDtByLNSXE1FAdGFPmsq5leCaXJ7Z2iMe0 OcOLrHusGMabwIM2CNE1toWnSRkntWx0DZetoMcEyRf92unz0pAqI1xhmlxBRgqAb/yRt9wUb6Y z2rNsce2PaGDLyFgwOYwUAPWlwGakE1xssZJdbq5dMaE4ArjkvHz6ao4EknE63cmU6VPy+bL8Cb ypk47t4vVY8iiS7f9vyufKksfOZVtg== X-Google-Smtp-Source: AGHT+IFYhjaiPEStxe7iJhguFOlJkhsmR296m3qkWSYgJmmzVTrn7IWMNOHrxKTyJb3amy5qpvAmzg== X-Received: by 2002:a17:902:f64c:b0:21f:49f2:e33f with SMTP id d9443c01a7336-221a0ed7885mr233705535ad.21.1740424117994; Mon, 24 Feb 2025 11:08:37 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:37 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 02/11] hw/riscv/riscv-iommu-bits.h: HPM bits Date: Mon, 24 Feb 2025 16:08:17 -0300 Message-ID: <20250224190826.1858473-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62c.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, UPPERCASE_50_75=0.008 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach Add the relevant HPM (High Performance Monitor) bits that we'll be using in the next patches. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-bits.h | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h index de599b80d6..b7cb1bc736 100644 --- a/hw/riscv/riscv-iommu-bits.h +++ b/hw/riscv/riscv-iommu-bits.h @@ -88,6 +88,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_HPM BIT_ULL(30) #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) @@ -197,6 +198,52 @@ enum { RISCV_IOMMU_INTR_COUNT }; +#define RISCV_IOMMU_IOCOUNT_NUM 31 + +/* 5.19 Performance monitoring counter overflow status (32bits) */ +#define RISCV_IOMMU_REG_IOCOUNTOVF 0x0058 +#define RISCV_IOMMU_IOCOUNTOVF_CY BIT(0) + +/* 5.20 Performance monitoring counter inhibits (32bits) */ +#define RISCV_IOMMU_REG_IOCOUNTINH 0x005C +#define RISCV_IOMMU_IOCOUNTINH_CY BIT(0) + +/* 5.21 Performance monitoring cycles counter (64bits) */ +#define RISCV_IOMMU_REG_IOHPMCYCLES 0x0060 +#define RISCV_IOMMU_IOHPMCYCLES_COUNTER GENMASK_ULL(62, 0) +#define RISCV_IOMMU_IOHPMCYCLES_OVF BIT_ULL(63) + +/* 5.22 Performance monitoring event counters (31 * 64bits) */ +#define RISCV_IOMMU_REG_IOHPMCTR_BASE 0x0068 +#define RISCV_IOMMU_REG_IOHPMCTR(_n) \ + (RISCV_IOMMU_REG_IOHPMCTR_BASE + (_n * 0x8)) + +/* 5.23 Performance monitoring event selectors (31 * 64bits) */ +#define RISCV_IOMMU_REG_IOHPMEVT_BASE 0x0160 +#define RISCV_IOMMU_REG_IOHPMEVT(_n) \ + (RISCV_IOMMU_REG_IOHPMEVT_BASE + (_n * 0x8)) +#define RISCV_IOMMU_IOHPMEVT_EVENT_ID GENMASK_ULL(14, 0) +#define RISCV_IOMMU_IOHPMEVT_DMASK BIT_ULL(15) +#define RISCV_IOMMU_IOHPMEVT_PID_PSCID GENMASK_ULL(35, 16) +#define RISCV_IOMMU_IOHPMEVT_DID_GSCID GENMASK_ULL(59, 36) +#define RISCV_IOMMU_IOHPMEVT_PV_PSCV BIT_ULL(60) +#define RISCV_IOMMU_IOHPMEVT_DV_GSCV BIT_ULL(61) +#define RISCV_IOMMU_IOHPMEVT_IDT BIT_ULL(62) +#define RISCV_IOMMU_IOHPMEVT_OF BIT_ULL(63) + +enum RISCV_IOMMU_HPMEVENT_id { + RISCV_IOMMU_HPMEVENT_INVALID = 0, + RISCV_IOMMU_HPMEVENT_URQ = 1, + RISCV_IOMMU_HPMEVENT_TRQ = 2, + RISCV_IOMMU_HPMEVENT_ATS_RQ = 3, + RISCV_IOMMU_HPMEVENT_TLB_MISS = 4, + RISCV_IOMMU_HPMEVENT_DD_WALK = 5, + RISCV_IOMMU_HPMEVENT_PD_WALK = 6, + RISCV_IOMMU_HPMEVENT_S_VS_WALKS = 7, + RISCV_IOMMU_HPMEVENT_G_WALKS = 8, + RISCV_IOMMU_HPMEVENT_MAX = 9 +}; + /* 5.24 Translation request IOVA (64bits) */ #define RISCV_IOMMU_REG_TR_REQ_IOVA 0x0258 From patchwork Mon Feb 24 19:08:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC269C021A4 for ; Mon, 24 Feb 2025 19:12:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpP-0005mc-Ru; Mon, 24 Feb 2025 14:09:19 -0500 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 1tmdot-0005e2-2F for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:49 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdoq-0004nr-4W for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:46 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-220e6028214so104180045ad.0 for ; Mon, 24 Feb 2025 11:08:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424121; x=1741028921; 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=y00TMw2vSZi5W2xAmzPCeeztV06fpu0c/uIoObcPADo=; b=mhD70UbeAQ6Y8hFiQ5nArPUZyQAEdai4MubaZwbNXmxOeSCcWthHReHY+ylgAtS0JA wQecAV4SZ5PAXLJ4JpEXviw5+ZuakTwTb+skFrwW+AHw5q1ck+w5pyzE13DpSdDsfc/r /InxpoB8KBbPiaqS8vSwZgb0uw1uMJgL/s7hmJ2rpRXrBG7GbPfUNxg8Q2uHTpAFezMd 1o1cpF2QJ4YI10WIy7j8lcdyxeY+gpBzgBMBC8il+/70ltlBXpKxI98AcAz8wIBmzNzs zf6m+9oujdTGgzc5+nNe5ozS1MQDfGqOb2u3itOBWbEmd/i5vSIdtxB89TawYLcRPJZs oUFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424121; x=1741028921; 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=y00TMw2vSZi5W2xAmzPCeeztV06fpu0c/uIoObcPADo=; b=rjXe5In3pxk3J1xeQTNUgxDBMOailLPzivHaHhsF2OXh6VmZkBRWmE5VtPk2t+ymbv WlA9X8LPYS7XiQ86mhpTYHcuYrACFQ5VY5cR2DkqzTXeBQwYc6TZq07LLzmmvWOXUVfM zxJ1gNoktug5V6UcEAYsRocLhU0P8kyCHy4M4UcDI3gdTAyIx3lgvZnaqDYga7T9UU5C 6ahZKlE0p2x5Jiqx7GPgldevt7v1wRswXv8BvDojQ1vmxy36b0kMUhkpiS5QjAMVgZuB SmL8mWgoFgRQArKsz8zrFH4gdeu0+DtTVPG+HVaLHLJmfDs9CHwfZ1j8k+ABfXQDWdqO L45w== X-Gm-Message-State: AOJu0YyQuhYtow46GH1GwIht+HgAA2yfMSGnHJmGw94u1PGwpykg9Qdc nglpY1mKgWQ6+C9n2R+fYJ6FXaVujaRUL7JT3CrozU06vt1WLJMcE4rzM3ictJPRrNwrltdBtEZ y X-Gm-Gg: ASbGncs8zFRL++YzonrMKiSdINfdBcB0iEI27h5bDjCHCZ+Xe1HJWsM5888TzbUDfMa 8yQKp+WlBpcK1Fgs7whhfdmefpvazXmF6/bq1GruVE13U1pRDSARGz+rsfdYDDLQ3nvlZqjE8WP vYmogWno2hDtOhfD27lR5X8qEudqR+pqr3JzoSaOwImWZU8LuxIm/FPAN3nE7oWkN47+5o8Vf2R VT5anw4icSNFVq2pAwaItfziAk9mKiLK+hq6D2oylhnPGyZfC63oDv0ywD8CemTaJ38MyaR8xSm h+t0x0pkm2FpzqLwIjXTaeIEn9J6hQ== X-Google-Smtp-Source: AGHT+IHZNxLhuq6IbT4egGK+sPGlkME5fcwkKPSrljUHnL5eJpsGBN+nRqLJ8JVkTS8PCNC8oJqybQ== X-Received: by 2002:a17:903:2f03:b0:220:f7bb:842 with SMTP id d9443c01a7336-221a00211cdmr232171835ad.42.1740424121024; Mon, 24 Feb 2025 11:08:41 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:40 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 03/11] hw/riscv/riscv-iommu: add riscv-iommu-hpm file Date: Mon, 24 Feb 2025 16:08:18 -0300 Message-ID: <20250224190826.1858473-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62d.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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach The HPM (Hardware Performance Monitor) support consists of almost 7 hundred lines that would be put on top of the base riscv-iommu emulation. To avoid clogging riscv-iommu.c, add a separated riscv-iommu-hpm file that will contain HPM specific code. We'll start by adding riscv_iommu_hpmcycle_read(), a helper that will be called during the riscv_iommu_mmio_read() callback. This change will have no effect on the existing emulation since we're not declaring HPM feature support. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/meson.build | 3 ++- hw/riscv/riscv-iommu-hpm.c | 54 ++++++++++++++++++++++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 27 +++++++++++++++++++ hw/riscv/riscv-iommu.c | 24 ++++++++++++++++- hw/riscv/riscv-iommu.h | 4 +++ 5 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 hw/riscv/riscv-iommu-hpm.c create mode 100644 hw/riscv/riscv-iommu-hpm.h diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index 3c7e083aca..c22f3a7216 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -10,7 +10,8 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) -riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c')) +riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( + 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) hw_arch += {'riscv': riscv_ss} diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c new file mode 100644 index 0000000000..5833ab8956 --- /dev/null +++ b/hw/riscv/riscv-iommu-hpm.c @@ -0,0 +1,54 @@ +/* + * RISC-V IOMMU - Hardware Performance Monitor (HPM) helpers + * + * Copyright (C) 2022-2023 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/timer.h" +#include "cpu_bits.h" +#include "riscv-iommu-hpm.h" +#include "riscv-iommu.h" +#include "riscv-iommu-bits.h" +#include "trace.h" + +/* For now we assume IOMMU HPM frequency to be 1GHz so 1-cycle is of 1-ns. */ +static inline uint64_t get_cycles(void) +{ + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); +} + +uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) +{ + const uint64_t cycle = riscv_iommu_reg_get64( + s, RISCV_IOMMU_REG_IOHPMCYCLES); + const uint32_t inhibit = riscv_iommu_reg_get32( + s, RISCV_IOMMU_REG_IOCOUNTINH); + const uint64_t ctr_prev = s->hpmcycle_prev; + const uint64_t ctr_val = s->hpmcycle_val; + + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { + /* + * Counter should not increment if inhibit bit is set. We can't really + * stop the QEMU_CLOCK_VIRTUAL, so we just return the last updated + * counter value to indicate that counter was not incremented. + */ + return (ctr_val & RISCV_IOMMU_IOHPMCYCLES_COUNTER) | + (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); + } + + return (ctr_val + get_cycles() - ctr_prev) | + (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h new file mode 100644 index 0000000000..231c110ff2 --- /dev/null +++ b/hw/riscv/riscv-iommu-hpm.h @@ -0,0 +1,27 @@ +/* + * RISC-V IOMMU - Hardware Performance Monitor (HPM) helpers + * + * Copyright (C) 2022-2023 Rivos Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef HW_RISCV_IOMMU_HPM_H +#define HW_RISCV_IOMMU_HPM_H + +#include "qom/object.h" +#include "hw/riscv/riscv-iommu.h" + +uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); + +#endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index e7568ca227..0fbd50bb52 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -29,6 +29,7 @@ #include "cpu_bits.h" #include "riscv-iommu.h" #include "riscv-iommu-bits.h" +#include "riscv-iommu-hpm.h" #include "trace.h" #define LIMIT_CACHE_CTX (1U << 7) @@ -2153,7 +2154,28 @@ static MemTxResult riscv_iommu_mmio_read(void *opaque, hwaddr addr, return MEMTX_ACCESS_ERROR; } - ptr = &s->regs_rw[addr]; + /* Compute cycle register value. */ + if ((addr & ~7) == RISCV_IOMMU_REG_IOHPMCYCLES) { + val = riscv_iommu_hpmcycle_read(s); + ptr = (uint8_t *)&val + (addr & 7); + } else if ((addr & ~3) == RISCV_IOMMU_REG_IOCOUNTOVF) { + /* + * Software can read RISCV_IOMMU_REG_IOCOUNTOVF before timer + * callback completes. In which case CY_OF bit in + * RISCV_IOMMU_IOHPMCYCLES_OVF would be 0. Here we take the + * CY_OF bit state from RISCV_IOMMU_REG_IOHPMCYCLES register as + * it's not dependent over the timer callback and is computed + * from cycle overflow. + */ + val = ldq_le_p(&s->regs_rw[addr]); + val |= (riscv_iommu_hpmcycle_read(s) & RISCV_IOMMU_IOHPMCYCLES_OVF) + ? RISCV_IOMMU_IOCOUNTOVF_CY + : 0; + ptr = (uint8_t *)&val + (addr & 3); + } else { + ptr = &s->regs_rw[addr]; + } + val = ldn_le_p(ptr, size); *data = val; diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index d2608d2f9b..59db3fd02a 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -81,6 +81,10 @@ struct RISCVIOMMUState { QLIST_ENTRY(RISCVIOMMUState) iommus; QLIST_HEAD(, RISCVIOMMUSpace) spaces; + + /* HPM cycle counter */ + uint64_t hpmcycle_val; /* Current value of cycle register */ + uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ }; void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, From patchwork Mon Feb 24 19:08:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 682FDC021BC for ; Mon, 24 Feb 2025 19:14:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpW-0005oV-8C; Mon, 24 Feb 2025 14:09:26 -0500 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 1tmdox-0005fI-V8 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:56 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdos-0004oQ-70 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:51 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-220f4dd756eso99445885ad.3 for ; Mon, 24 Feb 2025 11:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424124; x=1741028924; 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=JYchZo+9Zfqk3JonMm8w+m2V870HZdVGqg6ShWsJhJU=; b=d652Pa7U9P4EkpheSontKOiGIwpUjAZ4Ug4UiDSwS//8q/4WpnB+sfTnder+xL4zmc Um3iWAWVv6dFzggYWI5HYaro7Sf6SrxCMiceEZ28Vcr7KEHhxOgSzyuS7kKiG1UiCR/Q Nrgph7lMXmy/qgcVZoVTBLBizmDeC7Lberp+h0YHHve+3Agk0w1bcpeP3wkSBCYbS5Ea 0+WQGBeWnKQOYyUt57BSWY0AHwJgNu0/BW+s2w0CBVnlwf09flMoA65lbPN22H6AxvPh KbwQK4jIYtEe/WcMGTl5B83cMdXY7PnK2ZQk1LGmTkSV/3j1A07QHRAZMid66L4zwE33 nZPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424124; x=1741028924; 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=JYchZo+9Zfqk3JonMm8w+m2V870HZdVGqg6ShWsJhJU=; b=qvcHhi5K9MJkl7IOEgLGDGpWAAGmUQpj4v3ETKOFqpeS6NXz2re/WtU0KiZxIMiYaJ Fi4MUngbddokqWjZcw0dM2FTNWbBlfGHeps+3md455KW9VoodpXIk08/0Cs85iD3PWLG i0mmSb9EPw7tbmiyDMuyr8F0zcL4AcLkjiZCcpMg/GwkwRGcotGPli6QM+SalIWRxWq4 8qUhitYbCmW+eVUMSam+ZeR2+wjWh1OrMrtGf+NiRcpFNQu+mV5z/7+37d/j89E1JkOB iFUai97celc/EzJkeeRzZkvJrYoFAzpJQ9mbJttQ4fP1cyJyMaQ0jk9ZXqJalWr9mKLc tpsQ== X-Gm-Message-State: AOJu0Yxdb+QdtDuVAZCiivNVie9J8Dc6XQtkWbQ2P/qmFUbaigDNEW/j /qpbsnAUNvoBKAIjwa5sHIurn/egi1d5FBze2Jpy6O62BvboDnWuHjG4snjmQvA0w+Ijb3zb4cN 4 X-Gm-Gg: ASbGnctor+rALcO9G4XZXwT6zWISpAaaC3iL6dkTdVJIeMNtSck97VZjDXCSe7nvc3w YbfCONLN+SdeVmahnVp2kJZ3Ui1BkmU7mBq/Z9KcceyIP0ANAeh1AXYfGdoFXjIG9efCNsj+Rk3 T1+zLd5PzXiQ7z812gUKmbuod/QBrWWWLqDKNHAaGVLOVxF7r6Z5JG6WnXVHHeenktPIqRiEY+N kgVl2QoyDLRJuQo7G4OgSQcZkjeoc78Cglnpcfvp3bI3LosZ4ndSUBPr5vTwQoathKYh9OCu8PH YAKoqgS4sD7Ttg6cQ7OZEl5sooarlQ== X-Google-Smtp-Source: AGHT+IEVlIMoanCBBkichfHkavrPwyrHunPZy4KaMU1TNXh4zsvbzOg8KXxPSzA0d+FvQzOyML5GBg== X-Received: by 2002:a17:903:19ec:b0:21f:658b:8ed5 with SMTP id d9443c01a7336-22307b4556emr5265175ad.6.1740424124169; Mon, 24 Feb 2025 11:08:44 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:43 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 04/11] hw/riscv/riscv-iommu: add riscv_iommu_hpm_incr_ctr() Date: Mon, 24 Feb 2025 16:08:19 -0300 Message-ID: <20250224190826.1858473-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62f.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach This function will increment a specific counter, generating an interrupt when an overflow occurs. Some extra changes in riscv-iommu.c were required to add this new helper in riscv-iommu-hpm.c: - RISCVIOMMUContext was moved to riscv-iommu.h, making it visible in riscv-iommu-hpm.c; - riscv_iommu_notify() is now public. No behavior change is made since HPM support is not being advertised yet. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 114 +++++++++++++++++++++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 2 + hw/riscv/riscv-iommu.c | 43 +++++++++----- hw/riscv/riscv-iommu.h | 18 ++++++ 4 files changed, 162 insertions(+), 15 deletions(-) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 5833ab8956..8eca5ee17e 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -52,3 +52,117 @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) return (ctr_val + get_cycles() - ctr_prev) | (cycle & RISCV_IOMMU_IOHPMCYCLES_OVF); } + +static void hpm_incr_ctr(RISCVIOMMUState *s, uint32_t ctr_idx) +{ + const uint32_t off = ctr_idx << 3; + uint64_t cntr_val; + + cntr_val = ldq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); + stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val + 1); + + /* Handle the overflow scenario. */ + if (cntr_val == UINT64_MAX) { + /* + * Generate interrupt only if OF bit is clear. +1 to offset the cycle + * register OF bit. + */ + const uint32_t ovf = + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, + BIT(ctr_idx + 1), 0); + if (!get_field(ovf, BIT(ctr_idx + 1))) { + riscv_iommu_reg_mod64(s, + RISCV_IOMMU_REG_IOHPMEVT_BASE + off, + RISCV_IOMMU_IOHPMEVT_OF, + 0); + riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); + } + } +} + +void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, + unsigned event_id) +{ + const uint32_t inhibit = riscv_iommu_reg_get32( + s, RISCV_IOMMU_REG_IOCOUNTINH); + uint32_t did_gscid; + uint32_t pid_pscid; + uint32_t ctr_idx; + gpointer value; + uint32_t ctrs; + uint64_t evt; + + if (!(s->cap & RISCV_IOMMU_CAP_HPM)) { + return; + } + + value = g_hash_table_lookup(s->hpm_event_ctr_map, + GUINT_TO_POINTER(event_id)); + if (value == NULL) { + return; + } + + for (ctrs = GPOINTER_TO_UINT(value); ctrs != 0; ctrs &= ctrs - 1) { + ctr_idx = ctz32(ctrs); + if (get_field(inhibit, BIT(ctr_idx + 1))) { + continue; + } + + evt = riscv_iommu_reg_get64(s, + RISCV_IOMMU_REG_IOHPMEVT_BASE + (ctr_idx << 3)); + + /* + * It's quite possible that event ID has been changed in counter + * but hashtable hasn't been updated yet. We don't want to increment + * counter for the old event ID. + */ + if (event_id != get_field(evt, RISCV_IOMMU_IOHPMEVT_EVENT_ID)) { + continue; + } + + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_IDT)) { + did_gscid = get_field(ctx->gatp, RISCV_IOMMU_DC_IOHGATP_GSCID); + pid_pscid = get_field(ctx->ta, RISCV_IOMMU_DC_TA_PSCID); + } else { + did_gscid = ctx->devid; + pid_pscid = ctx->process_id; + } + + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_PV_PSCV)) { + /* + * If the transaction does not have a valid process_id, counter + * increments if device_id matches DID_GSCID. If the transaction + * has a valid process_id, counter increments if device_id + * matches DID_GSCID and process_id matches PID_PSCID. See + * IOMMU Specification, Chapter 5.23. Performance-monitoring + * event selector. + */ + if (ctx->process_id && + get_field(evt, RISCV_IOMMU_IOHPMEVT_PID_PSCID) != pid_pscid) { + continue; + } + } + + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_DV_GSCV)) { + uint32_t mask = ~0; + + if (get_field(evt, RISCV_IOMMU_IOHPMEVT_DMASK)) { + /* + * 1001 1011 mask = GSCID + * 0000 0111 mask = mask ^ (mask + 1) + * 1111 1000 mask = ~mask; + */ + mask = get_field(evt, RISCV_IOMMU_IOHPMEVT_DID_GSCID); + mask = mask ^ (mask + 1); + mask = ~mask; + } + + if ((get_field(evt, RISCV_IOMMU_IOHPMEVT_DID_GSCID) & mask) != + (did_gscid & mask)) { + continue; + } + } + + hpm_incr_ctr(s, ctr_idx); + } +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index 231c110ff2..411d869dce 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -23,5 +23,7 @@ #include "hw/riscv/riscv-iommu.h" uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); +void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, + unsigned event_id); #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 0fbd50bb52..0b15acf4e6 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -39,7 +39,6 @@ #define PPN_PHYS(ppn) ((ppn) << TARGET_PAGE_BITS) #define PPN_DOWN(phy) ((phy) >> TARGET_PAGE_BITS) -typedef struct RISCVIOMMUContext RISCVIOMMUContext; typedef struct RISCVIOMMUEntry RISCVIOMMUEntry; /* Device assigned I/O address space */ @@ -52,19 +51,6 @@ struct RISCVIOMMUSpace { QLIST_ENTRY(RISCVIOMMUSpace) list; }; -/* Device translation context state. */ -struct RISCVIOMMUContext { - uint64_t devid:24; /* Requester Id, AKA device_id */ - uint64_t process_id:20; /* Process ID. PASID for PCIe */ - uint64_t tc; /* Translation Control */ - uint64_t ta; /* Translation Attributes */ - uint64_t satp; /* S-Stage address translation and protection */ - uint64_t gatp; /* G-Stage address translation and protection */ - uint64_t msi_addr_mask; /* MSI filtering - address mask */ - uint64_t msi_addr_pattern; /* MSI filtering - address pattern */ - uint64_t msiptp; /* MSI redirection page table pointer */ -}; - typedef enum RISCVIOMMUTransTag { RISCV_IOMMU_TRANS_TAG_BY, /* Bypass */ RISCV_IOMMU_TRANS_TAG_SS, /* Single Stage */ @@ -101,7 +87,7 @@ static uint8_t riscv_iommu_get_icvec_vector(uint32_t icvec, uint32_t vec_type) } } -static void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) +void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) { uint32_t ipsr, icvec, vector; @@ -423,6 +409,13 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, } } + + if (pass == S_STAGE) { + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_S_VS_WALKS); + } else { + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_G_WALKS); + } + /* Read page table entry */ if (sc[pass].ptesize == 4) { uint32_t pte32 = 0; @@ -941,6 +934,7 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) /* Device directory tree walk */ for (; depth-- > 0; ) { + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_DD_WALK); /* * Select device id index bits based on device directory tree level * and device context format. @@ -968,6 +962,8 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) addr = PPN_PHYS(get_field(de, RISCV_IOMMU_DDTE_PPN)); } + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_DD_WALK); + /* index into device context entry page */ addr |= (ctx->devid * dc_len) & ~TARGET_PAGE_MASK; @@ -1033,6 +1029,8 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) } for (depth = mode - RISCV_IOMMU_DC_FSC_PDTP_MODE_PD8; depth-- > 0; ) { + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_PD_WALK); + /* * Select process id index bits based on process directory tree * level. See IOMMU Specification, 2.2. Process-Directory-Table. @@ -1050,6 +1048,8 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx) addr = PPN_PHYS(get_field(de, RISCV_IOMMU_PC_FSC_PPN)); } + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_PD_WALK); + /* Leaf entry in PDT */ addr |= (ctx->process_id << 4) & ~TARGET_PAGE_MASK; if (dma_memory_read(s->target_as, addr, &dc.ta, sizeof(uint64_t) * 2, @@ -1419,6 +1419,8 @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, GHashTable *iot_cache; int fault; + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_URQ); + iot_cache = g_hash_table_ref(s->iot_cache); /* * TC[32] is reserved for custom extensions, used here to temporarily @@ -1429,6 +1431,7 @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, /* Check for ATS request. */ if (iotlb->perm == IOMMU_NONE) { + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_ATS_RQ); /* Check if ATS is disabled. */ if (!(ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS)) { enable_pri = false; @@ -1447,6 +1450,8 @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, goto done; } + riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_TLB_MISS); + /* Translate using device directory / page table information. */ fault = riscv_iommu_spa_fetch(s, ctx, iotlb); @@ -2375,6 +2380,10 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->trap_mr, OBJECT(dev), &riscv_iommu_trap_ops, s, "riscv-iommu-trap", ~0ULL); address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); + + if (s->cap & RISCV_IOMMU_CAP_HPM) { + s->hpm_event_ctr_map = g_hash_table_new(g_direct_hash, g_direct_equal); + } } static void riscv_iommu_unrealize(DeviceState *dev) @@ -2383,6 +2392,10 @@ static void riscv_iommu_unrealize(DeviceState *dev) g_hash_table_unref(s->iot_cache); g_hash_table_unref(s->ctx_cache); + + if (s->cap & RISCV_IOMMU_CAP_HPM) { + g_hash_table_unref(s->hpm_event_ctr_map); + } } void riscv_iommu_reset(RISCVIOMMUState *s) diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index 59db3fd02a..4384f39515 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -85,12 +85,30 @@ struct RISCVIOMMUState { /* HPM cycle counter */ uint64_t hpmcycle_val; /* Current value of cycle register */ uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ + + /* HPM event counters */ + GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ }; void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, Error **errp); void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode); void riscv_iommu_reset(RISCVIOMMUState *s); +void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type); + +typedef struct RISCVIOMMUContext RISCVIOMMUContext; +/* Device translation context state. */ +struct RISCVIOMMUContext { + uint64_t devid:24; /* Requester Id, AKA device_id */ + uint64_t process_id:20; /* Process ID. PASID for PCIe */ + uint64_t tc; /* Translation Control */ + uint64_t ta; /* Translation Attributes */ + uint64_t satp; /* S-Stage address translation and protection */ + uint64_t gatp; /* G-Stage address translation and protection */ + uint64_t msi_addr_mask; /* MSI filtering - address mask */ + uint64_t msi_addr_pattern; /* MSI filtering - address pattern */ + uint64_t msiptp; /* MSI redirection page table pointer */ +}; /* private helpers */ From patchwork Mon Feb 24 19:08:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 301A5C021BB for ; Mon, 24 Feb 2025 19:12:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpL-0005ka-IA; Mon, 24 Feb 2025 14:09:15 -0500 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 1tmdox-0005fH-UX for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:55 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdov-0004pI-7W for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:50 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-220e989edb6so130908315ad.1 for ; Mon, 24 Feb 2025 11:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424127; x=1741028927; 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=4UfwpO8Eu9sCwL2GSf/WbzwHM6yqn5zegav9+WOljQY=; b=HWrKF5T7LvdY5uffVLPiKXwRo4XPaRbXkAnBAcZnAKcrZrLmmKi8+ZJ4JTOklTWTXc clQRz4YgWWW8dN+/X4V8K0y8AbpvXOnFSt6XGT5Dlc7CcVs+Ntez31wayXqODV/WwSBX rq31GI35Z1AAOyTR73/8gAmU6BJENJid/j+Qmc0HF7Y5q2wR3tmpfy0KoxZIvJoHQbYf pX/aQoYuOAyfKinwo/aWYeCnvMwJO6vOPzAKjd6D3I8aKgGrSg7nDtwSmQ3CMk4FnsZj vHD7B9CU1KZ3ocr91EfxNknwc/xAfqZCN8OzcJ+b22sAxm67DoEEnRWsHJQYE99g+IP1 BjIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424127; x=1741028927; 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=4UfwpO8Eu9sCwL2GSf/WbzwHM6yqn5zegav9+WOljQY=; b=RpLZuwZxA62mzip6+i26qjER6ffT2Bt0kM2o0n6nGVZU8f3D3hI6Y07WAKA8U7FwRU ooocM2IziWDmyGEtcIVsOCNQZ6P7umh468KlHRRATNsmlsivL9Z3WX5nUkEUMU8mF+EW qFTkxgsyc2I9P74Op0E/pPChEoKnimVEsyuvWRmL8Phvr2LD7FdsGlxndXLutIoWL3GL 3N3O1+N6xhHynHwuiShKKv4gj0khuU+YQ7BeA/0z9ALIEdzjUQGfEZel22mTy4at7y8z tLqG2emyGF1Psd3ZaLzfT9dLqBMgENV9IJHBGTx69eTcW2QvWyaFHjTMllNAlWJ2Zx8F YHzg== X-Gm-Message-State: AOJu0YwodgCpSi2lIkF1gfSTadQHpeZZVLOjzi9/v77yswfsDfL5InQ7 8459saRx+F0bSuWpB2ll3pK5wq6B7qpNgmXLCCtGIwYkgexDHVFxmA5WZ8F0N0jlTE7b0EMpPrv H X-Gm-Gg: ASbGnctMbEWbUKclXa2M1tw/9+M383XBPOe0zSTcyzEZ6ldM27Lb72rSzakEhXPupEc n6LQTraoigAJ2G5b6zKJyi1jmHg3o9WuiqAOI+BI7Lk/DCs6GuHTXC0U44UZH8iLgoUJJ6T67GT coiKGfk+GuYSnPa5kviddDEmlw8u3AmbrWb849Z+rsp4IJozNuh5ZkJVpWfM1DXN6ihjv3MxGuA t2omVUZGD2rQgznwmuwSwaH0dxqe48IDXBQjhaUzCFKheAU8kjmxP69d/CvGvbJxJK5eOHgxcW6 Ye9AekH2A69oBp/MoM4u9oY2LFhJOw== X-Google-Smtp-Source: AGHT+IHDTySX0ti5ZDneN6q495ON+qmdfsWi9TgpHRAU0rtkXq22UCK/zoXsNyZQWPF1qQ4meAA9Vw== X-Received: by 2002:a17:902:f54b:b0:220:d28a:c5c7 with SMTP id d9443c01a7336-22307b4bc13mr5406275ad.21.1740424127265; Mon, 24 Feb 2025 11:08:47 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:46 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 05/11] hw/riscv/riscv-iommu: instantiate hpm_timer Date: Mon, 24 Feb 2025 16:08:20 -0300 Message-ID: <20250224190826.1858473-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x633.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach The next HPM related changes requires the HPM overflow timer to be initialized by the riscv-iommu base emulation. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 36 ++++++++++++++++++++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 1 + hw/riscv/riscv-iommu.c | 3 +++ hw/riscv/riscv-iommu.h | 2 ++ 4 files changed, 42 insertions(+) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 8eca5ee17e..325088333e 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -166,3 +166,39 @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, hpm_incr_ctr(s, ctr_idx); } } + +/* Timer callback for cycle counter overflow. */ +void riscv_iommu_hpm_timer_cb(void *priv) +{ + RISCVIOMMUState *s = priv; + const uint32_t inhibit = riscv_iommu_reg_get32( + s, RISCV_IOMMU_REG_IOCOUNTINH); + uint32_t ovf; + + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { + return; + } + + if (s->irq_overflow_left > 0) { + uint64_t irq_trigger_at = + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->irq_overflow_left; + timer_mod_anticipate_ns(s->hpm_timer, irq_trigger_at); + s->irq_overflow_left = 0; + return; + } + + ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); + if (!get_field(ovf, RISCV_IOMMU_IOCOUNTOVF_CY)) { + /* + * We don't need to set hpmcycle_val to zero and update hpmcycle_prev to + * current clock value. The way we calculate iohpmcycs will overflow + * and return the correct value. This avoids the need to synchronize + * timer callback and write callback. + */ + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, + RISCV_IOMMU_IOCOUNTOVF_CY, 0); + riscv_iommu_reg_mod64(s, RISCV_IOMMU_REG_IOHPMCYCLES, + RISCV_IOMMU_IOHPMCYCLES_OVF, 0); + riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); + } +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index 411d869dce..cd896d3b7c 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -25,5 +25,6 @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, unsigned event_id); +void riscv_iommu_hpm_timer_cb(void *priv); #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 0b15acf4e6..f26aa15f55 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2382,6 +2382,8 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); if (s->cap & RISCV_IOMMU_CAP_HPM) { + s->hpm_timer = + timer_new_ns(QEMU_CLOCK_VIRTUAL, riscv_iommu_hpm_timer_cb, s); s->hpm_event_ctr_map = g_hash_table_new(g_direct_hash, g_direct_equal); } } @@ -2395,6 +2397,7 @@ static void riscv_iommu_unrealize(DeviceState *dev) if (s->cap & RISCV_IOMMU_CAP_HPM) { g_hash_table_unref(s->hpm_event_ctr_map); + timer_free(s->hpm_timer); } } diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index 4384f39515..2fef6eed27 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -83,8 +83,10 @@ struct RISCVIOMMUState { QLIST_HEAD(, RISCVIOMMUSpace) spaces; /* HPM cycle counter */ + QEMUTimer *hpm_timer; uint64_t hpmcycle_val; /* Current value of cycle register */ uint64_t hpmcycle_prev; /* Saved value of QEMU_CLOCK_VIRTUAL clock */ + uint64_t irq_overflow_left; /* Value beyond INT64_MAX after overflow */ /* HPM event counters */ GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ From patchwork Mon Feb 24 19:08:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDB47C021A4 for ; Mon, 24 Feb 2025 19:12:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpN-0005lX-Qi; Mon, 24 Feb 2025 14:09:17 -0500 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 1tmdp1-0005fV-0s for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:56 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdoy-0004pd-7w for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:54 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-220c8f38febso101996175ad.2 for ; Mon, 24 Feb 2025 11:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424130; x=1741028930; 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=Yk1rl5jPE9Nq4m5iJHnqOZWE623sEepVUXfLI4QAl9s=; b=gElUSMMvO2wPmc/dK3K5rAts/kvmtaWf0Mzn2fzWRbtR3/4U4pgbEJVzoHbKJZQ0qk h3mIZUwjVDj8xrvd0vdphaTNvHx9eDR4U3q0a3U6QWsUguvG8Lvik4S2AsCpc7TRoSsd iEVp2AsBp3CSlgE+5OYY2opdoELAOkQq6pxnX2Vt+iiypjhJnO7Bso0kWpE2ZPbNA1t6 5May6tvCNWpoVahwylSdgL+sBlGrDl+U+c0B6b0aMtylblIB16HXJE9Hgf0muxASaroe SVflj0B2txypNOTImHS+oRN/O1dD1bZmLGHPk0XQrOJfsgP0sv12D9uhpSnCU31eXNCM wbSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424130; x=1741028930; 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=Yk1rl5jPE9Nq4m5iJHnqOZWE623sEepVUXfLI4QAl9s=; b=u3IQSN1uyX0cP+OnQ8+tsXqVxwhnvXk1Eh7rTVKdxbvIOHxmh7+JUKxlct/3ZQ6Sds T/RzdnKcQUAilzl09kMhdQjLHkD8anMNwcLmot/3lmfyS3S0+n4OCm0PTqLgEgqzM7rw 8yYMR2+G+X+NIf3e0uhaKdvm+kiWfHSkWlGhJRp3jboplLts54GljK8wdGTqgguJs+80 0tkaSzae+5Q7gKBEUITMQpvxDPYYVf9WhjwuY8v8HcTk8ogPUxp1it6reDjtr/lovlRf fjDmLKUciVPZSMnXR+/BN7QWEymcOcdrlz8l1soImowbWMvPrrE7zrqldihI2Yzsee4T 46SA== X-Gm-Message-State: AOJu0YwGCY6mton28fY7hbKgLsvWBBosN8nh7nrkaPHztGrxhxAzT4Dp GPTTgnUJYx16o5VAJvSkiSEV4iutZARSQ9ToHLHXXBPa7B9hc3ZsnoWDqbidnPnBKWUoWlcKTuq s X-Gm-Gg: ASbGnctDR9axyGcfnvvVewrsQ70OQUoq/3IbmAWB/ASDpttB+ocbz/bUtLhj4emKh22 nkQW66Znqwehd/mdPL/rQxNiVWgtA6HGOePeGI7cmh5yUtF914bffOlKBOGbSWIFlrTBesMhtkH 1qe8GD4hrhRwbV8NqxXqccyoBDszbPRU2fbSd9ZwmXC/9W+YsZ/PScOQUDDVX07YE8BS0zA/BkM agq9ajWW+zyMooHOsI+n1bClqnJySkZjFrPtRitCxofisu5kW5nJYQTO+RyFgR4qsu4UrqC/UlA QAUbvjEHbTOZcuC+pVlZBXkXa39sYQ== X-Google-Smtp-Source: AGHT+IGvd/3CkakVkdQqy3xTxE6xG/4agTOWBT2PT3gfzJF0nw3kTYz4Ij71i3IzNaVfa8gN3x4wig== X-Received: by 2002:a17:902:f544:b0:215:6cb2:7877 with SMTP id d9443c01a7336-2219ff827cdmr287733175ad.4.1740424130477; Mon, 24 Feb 2025 11:08:50 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:50 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 06/11] hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes Date: Mon, 24 Feb 2025 16:08:21 -0300 Message-ID: <20250224190826.1858473-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x630.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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach RISCV_IOMMU_REG_IOCOUNTINH is done by riscv_iommu_process_iocntinh_cy(), which is called during riscv_iommu_mmio_write() callback via a new riscv_iommu_pricess_hpm_writes() helper. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 60 ++++++++++++++++++++++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 1 + hw/riscv/riscv-iommu.c | 38 ++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 325088333e..70814b942d 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -202,3 +202,63 @@ void riscv_iommu_hpm_timer_cb(void *priv) riscv_iommu_notify(s, RISCV_IOMMU_INTR_PM); } } + +static void hpm_setup_timer(RISCVIOMMUState *s, uint64_t value) +{ + const uint32_t inhibit = riscv_iommu_reg_get32( + s, RISCV_IOMMU_REG_IOCOUNTINH); + uint64_t overflow_at, overflow_ns; + + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { + return; + } + + /* + * We are using INT64_MAX here instead to UINT64_MAX because cycle counter + * has 63-bit precision and INT64_MAX is the maximum it can store. + */ + if (value) { + overflow_ns = INT64_MAX - value + 1; + } else { + overflow_ns = INT64_MAX; + } + + overflow_at = (uint64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + overflow_ns; + + if (overflow_at > INT64_MAX) { + s->irq_overflow_left = overflow_at - INT64_MAX; + overflow_at = INT64_MAX; + } + + timer_mod_anticipate_ns(s->hpm_timer, overflow_at); +} + +/* Updates the internal cycle counter state when iocntinh:CY is changed. */ +void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) +{ + const uint32_t inhibit = riscv_iommu_reg_get32( + s, RISCV_IOMMU_REG_IOCOUNTINH); + + /* We only need to process CY bit toggle. */ + if (!(inhibit ^ prev_cy_inh)) { + return; + } + + if (!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY)) { + /* + * Cycle counter is enabled. Just start the timer again and update + * the clock snapshot value to point to the current time to make + * sure iohpmcycles read is correct. + */ + s->hpmcycle_prev = get_cycles(); + hpm_setup_timer(s, s->hpmcycle_val); + } else { + /* + * Cycle counter is disabled. Stop the timer and update the cycle + * counter to record the current value which is last programmed + * value + the cycles passed so far. + */ + s->hpmcycle_val = s->hpmcycle_val + (get_cycles() - s->hpmcycle_prev); + timer_del(s->hpm_timer); + } +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index cd896d3b7c..ee888650fb 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -26,5 +26,6 @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s); void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, unsigned event_id); void riscv_iommu_hpm_timer_cb(void *priv); +void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index f26aa15f55..a4580dca0b 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2024,6 +2024,27 @@ static void riscv_iommu_update_ipsr(RISCVIOMMUState *s, uint64_t data) riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IPSR, ipsr_set, ipsr_clr); } +static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, + uint32_t regb, + bool prev_cy_inh) +{ + switch (regb) { + case RISCV_IOMMU_REG_IOCOUNTINH: + riscv_iommu_process_iocntinh_cy(s, prev_cy_inh); + break; + + case RISCV_IOMMU_REG_IOHPMCYCLES: + case RISCV_IOMMU_REG_IOHPMCYCLES + 4: + /* not yet implemented */ + break; + + case RISCV_IOMMU_REG_IOHPMEVT_BASE ... + RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4: + /* not yet implemented */ + break; + } +} + /* * Write the resulting value of 'data' for the reg specified * by 'reg_addr', after considering read-only/read-write/write-clear @@ -2051,6 +2072,7 @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, uint32_t regb = addr & ~3; uint32_t busy = 0; uint64_t val = 0; + bool cy_inh = false; if ((addr & (size - 1)) != 0) { /* Unsupported MMIO alignment or access size */ @@ -2118,6 +2140,16 @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, busy = RISCV_IOMMU_TR_REQ_CTL_GO_BUSY; break; + case RISCV_IOMMU_REG_IOCOUNTINH: + if (addr != RISCV_IOMMU_REG_IOCOUNTINH) { + break; + } + /* Store previous value of CY bit. */ + cy_inh = !!(riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTINH) & + RISCV_IOMMU_IOCOUNTINH_CY); + break; + + default: break; } @@ -2136,6 +2168,12 @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr, stl_le_p(&s->regs_rw[regb], rw | busy); } + /* Process HPM writes and update any internal state if needed. */ + if (regb >= RISCV_IOMMU_REG_IOCOUNTOVF && + regb <= (RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4)) { + riscv_iommu_process_hpm_writes(s, regb, cy_inh); + } + if (process_fn) { process_fn(s); } From patchwork Mon Feb 24 19:08:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95A5FC021A4 for ; Mon, 24 Feb 2025 19:12:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpQ-0005mt-Pk; Mon, 24 Feb 2025 14:09:21 -0500 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 1tmdp3-0005g6-Sl for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:04 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdp1-0004qZ-HN for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:08:57 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-21c2f1b610dso140712335ad.0 for ; Mon, 24 Feb 2025 11:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424134; x=1741028934; 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=l80pE3gkD/yQiSsoJR+m7k+bMTj+1l2cFJ9CeVi+z68=; b=ceRv9F3rxKgJgzFiIKe2+VS6HJFEBI6EVwUwTn5Y8Yvutw0/V6nvNYli59uD4ee04L ruemjuJo3xbrM2CtnvfCoC104qDUOfg2QpTEjvUb3rr5B0qajid8EjC/i7rFEgyfBplZ m1dvb5ysQYFmUnvPpqTf3K1i1us7p029/nOwGa9F3Vb81JGGkQ2dyN3tAfdLzfjM5YEP IdX6y29cg+13MwKTTUr/KGn72CtrcLEdm7kTUWYI3uOYr6WbBT5iD4IeuVx0eULNrkGM 5WFbjjt+VAJsVon5VZu5xGNqXZCjuVp9BkhbULv865W7yiDaD/uztbfbAr6gXk0bIpQ3 1MSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424134; x=1741028934; 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=l80pE3gkD/yQiSsoJR+m7k+bMTj+1l2cFJ9CeVi+z68=; b=fiHmAU716JazXGfHrXXjfvFZOZTzOoINUCrt/96Yeea9GfkCvG+JRZl/HBle8TV4rP lbxFOYfB33aXyV8H4Ury5ejdY6MozLBu8RKR2viqSl/cl653djZS+kN9Jlyq+pz6/uyW 0xiJcYovPxZ87Vhu3rSarUn7fKpIJaabrTYP839agseza6sroQHZDbs/L5hKVYi4PWcs fWScmvd5cYXGnUasYyqIyNEyC5OOvqtl4pMLwC3rpn3oWNzG1Z2fknPUHHvQC2W5pESr efO83bINmUbW6ZQu4nXwpzhQOPNZ4u+Rvc+FwlspBEv5KLyqVgn+Fz43F5NLNioWAPTr kZLw== X-Gm-Message-State: AOJu0Yy03KfAQj4QOZiecw4afXPBpJGpY5Q4PVZzZJu22pb20vj/nuPE IggKK8TqPsYCBiYMd8E2oIV6Q/7sSNSk1/f8sAq5/cwk9IlW4eu9Cnq/cAJ+nUhWs3Ftqz1b2+S M X-Gm-Gg: ASbGncvGVg2lxUX4DVVvOL5NyUmE7coV3sl7doaDJCVNim+rodpbbvGaBjdLYjkBgfT wD0YfemucD9wkwccPD4dPTLRb2ra39HDNcYV/j7pYge4O7QltIXFgxTXV7tZJ8CKn92EQhbUlpZ wjkCtzuRncnEbhroDY0ii34YORCpuA3bACd/2tirK37kdqgzLs3RxUF5DrqczgFCxuCFCsMSYdN 6xK3s1PuTRhp2JrbXk1h34z6uWaIYRTG7OT33vzdsouYFiajk+Hk5PscW48u0rKWsTcGbCa7v4+ 0SwCOGA4wL9UJeELgvmjL8uDtWjVBQ== X-Google-Smtp-Source: AGHT+IEdkN1AF/qeS//sCuqL/NEfu+nHiLqoV9sKZlzyJdTLgmySpUH+sHcP+0J8+1P8rquvpkgBFw== X-Received: by 2002:a17:902:ce87:b0:216:7cde:51a with SMTP id d9443c01a7336-22307b59658mr6107835ad.28.1740424133820; Mon, 24 Feb 2025 11:08:53 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:53 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 07/11] hw/riscv/riscv-iommu: add IOHPMCYCLES mmio write Date: Mon, 24 Feb 2025 16:08:22 -0300 Message-ID: <20250224190826.1858473-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x634.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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach RISCV_IOMMU_REG_IOHPMCYCLES writes are done by riscv_iommu_process_hpmcycle_write(), called by the mmio write callback via riscv_iommu_process_hpm_writes(). Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 19 +++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 1 + hw/riscv/riscv-iommu.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 70814b942d..1cea6b1df1 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -262,3 +262,22 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) timer_del(s->hpm_timer); } } + +void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) +{ + const uint64_t val = riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_IOHPMCYCLES); + const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); + + /* + * Clear OF bit in IOCNTOVF if it's being cleared in IOHPMCYCLES register. + */ + if (get_field(ovf, RISCV_IOMMU_IOCOUNTOVF_CY) && + !get_field(val, RISCV_IOMMU_IOHPMCYCLES_OVF)) { + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_IOCOUNTOVF, 0, + RISCV_IOMMU_IOCOUNTOVF_CY); + } + + s->hpmcycle_val = val & ~RISCV_IOMMU_IOHPMCYCLES_OVF; + s->hpmcycle_prev = get_cycles(); + hpm_setup_timer(s, s->hpmcycle_val); +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index ee888650fb..0cd550975d 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -27,5 +27,6 @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, unsigned event_id); void riscv_iommu_hpm_timer_cb(void *priv); void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); +void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s); #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index a4580dca0b..821ecba3a4 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2035,7 +2035,7 @@ static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, case RISCV_IOMMU_REG_IOHPMCYCLES: case RISCV_IOMMU_REG_IOHPMCYCLES + 4: - /* not yet implemented */ + riscv_iommu_process_hpmcycle_write(s); break; case RISCV_IOMMU_REG_IOHPMEVT_BASE ... From patchwork Mon Feb 24 19:08:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE56EC021BC for ; Mon, 24 Feb 2025 19:10:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdq3-0005tw-4R; Mon, 24 Feb 2025 14:10:03 -0500 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 1tmdpA-0005hU-Nu for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:06 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdp6-0004rP-GZ for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:03 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-220f4dd756eso99449935ad.3 for ; Mon, 24 Feb 2025 11:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424137; x=1741028937; 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=OdvxoA7MO1HEsVdmxpLT+H+KWWtGcf6+0kEyDaOkd9I=; b=hVimHlHnVWUPdVOQCt2PUaMy4LC9RwKh3oI4utkedSi9+mCwVRFAyabMVfExipcvBs fSlAdr6Hd6CJ+onjhZfHXK1VQkhLr0F5/V+LXxJaL7vOh8zTYGt9W0pnBKkQVq03Nzlt sO2JM8pZmuiPFH2aksu8yjC+nIBKnr7mI4ONwTJ2/9Yst3QbqiXw0oyvm0Uw6i1pyMcN hvCEcPYEWYdGpqFEmfD+mzfWKV70UilUrKJp0cCbU4gW84AhhpTzVAocXX5azIrA9W2i 5y/lC1x9gRKu3PjWvDwEnEh17BGrJJBauqKOTEh2IZscC6Cw2Ocfh2EymdkjGF6gQ1fv 5BEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424137; x=1741028937; 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=OdvxoA7MO1HEsVdmxpLT+H+KWWtGcf6+0kEyDaOkd9I=; b=MVNmP2xRmi8bO6xKJr24PM9Dzjk7beIzNHz4xqk0pjjo+0G5pWqSfu0W4QuKgdUKsw fUL4G2ZoXpMhr84wWbt0v8aLeWbnI5d2LOzpRMkHCktmD6c1Rv3uSciAX+MP3YPRF8gk M4Po3u4WAzQGa7YvQJvHwDRLG06D8NbfEtihtQ7MjDPV17tMH5BI6VDxcod2q/xBA1NW 0a7JMRYBHTLt4Hs7+HoC7xxwhB2z9ntdQmXe0jTPEXGDCKMjBCeLyElyICoYwMikr5jd S8I4CCEKK3Er4hacoLmOz88J6cDNiCohJCdfFGQsbKBqxU00VYqANW0RhpaJKA37c/HI B90Q== X-Gm-Message-State: AOJu0YxYDWSJCSGKW0FHeIez0yrOh8WlFI9IsfyEvpPMzgawgVGgYGkc f9syKFmBAHsD68d3hLbaif3jw+yHi69tgd70YaaglR8hmEEyIjU/ywkXonz7toMCbDhvP5dxKUR L X-Gm-Gg: ASbGncvm2ALH5I1txR4/3QdbcjaYsko9wrqKGAo1RSLokDdtCJtxmEjQ763rnA7uBW2 WEVpveXEak/vOR9qgiI+tEtv12yedbRmkCgH/TJra7psd6CU1uZ/n1oOgvPDvLBM87bwkVXdPuH 3r579MtKwQttXfw8SueeO5Nf6KHcfcHSE9KUz7mMidmRATYU0a6HlOrqa2bTTYpkl8xGSohm7lL wutvpp43PpfoNJJdtkWNgB720cZmq0M49fKC+wuiNqwPKto0w6VnHP+miQHaAM4rMtHFB1k5vqg FH++/h4xmiEM3033BG/jJoEJNK9Qfg== X-Google-Smtp-Source: AGHT+IEKv1W+/QME25fbgS5noawmtF0rlKUg3xy2kwI4RfKKE47Xf9N9drGHa9BBPFJjnVJ7AKT1hQ== X-Received: by 2002:a17:902:e5c2:b0:215:9470:7e82 with SMTP id d9443c01a7336-22307b455dcmr6044625ad.4.1740424136969; Mon, 24 Feb 2025 11:08:56 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:56 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 08/11] hw/riscv/riscv-iommu: add hpm events mmio write Date: Mon, 24 Feb 2025 16:08:23 -0300 Message-ID: <20250224190826.1858473-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x631.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach To support hpm events mmio writes, done via riscv_iommu_process_hpmevt_write(), we're also adding the 'hpm-counters' IOMMU property that are used to determine the amount of counters available in the IOMMU. Note that everything we did so far didn't change any IOMMU behavior because we're still not advertising HPM capability to software. This will be done in the next patch. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 88 ++++++++++++++++++++++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 1 + hw/riscv/riscv-iommu.c | 4 +- hw/riscv/riscv-iommu.h | 1 + 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 1cea6b1df1..5518c287a5 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -281,3 +281,91 @@ void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) s->hpmcycle_prev = get_cycles(); hpm_setup_timer(s, s->hpmcycle_val); } + +static inline bool check_valid_event_id(unsigned event_id) +{ + return event_id > RISCV_IOMMU_HPMEVENT_INVALID && + event_id < RISCV_IOMMU_HPMEVENT_MAX; +} + +static gboolean hpm_event_equal(gpointer key, gpointer value, gpointer udata) +{ + uint32_t *pair = udata; + + if (GPOINTER_TO_UINT(value) & (1 << pair[0])) { + pair[1] = GPOINTER_TO_UINT(key); + return true; + } + + return false; +} + +/* Caller must check ctr_idx against hpm_ctrs to see if its supported or not. */ +static void update_event_map(RISCVIOMMUState *s, uint64_t value, + uint32_t ctr_idx) +{ + unsigned event_id = get_field(value, RISCV_IOMMU_IOHPMEVT_EVENT_ID); + uint32_t pair[2] = { ctr_idx, RISCV_IOMMU_HPMEVENT_INVALID }; + uint32_t new_value = 1 << ctr_idx; + gpointer data; + + /* + * If EventID field is RISCV_IOMMU_HPMEVENT_INVALID + * remove the current mapping. + */ + if (event_id == RISCV_IOMMU_HPMEVENT_INVALID) { + data = g_hash_table_find(s->hpm_event_ctr_map, hpm_event_equal, pair); + + new_value = GPOINTER_TO_UINT(data) & ~(new_value); + if (new_value != 0) { + g_hash_table_replace(s->hpm_event_ctr_map, + GUINT_TO_POINTER(pair[1]), + GUINT_TO_POINTER(new_value)); + } else { + g_hash_table_remove(s->hpm_event_ctr_map, + GUINT_TO_POINTER(pair[1])); + } + + return; + } + + /* Update the counter mask if the event is already enabled. */ + if (g_hash_table_lookup_extended(s->hpm_event_ctr_map, + GUINT_TO_POINTER(event_id), + NULL, + &data)) { + new_value |= GPOINTER_TO_UINT(data); + } + + g_hash_table_insert(s->hpm_event_ctr_map, + GUINT_TO_POINTER(event_id), + GUINT_TO_POINTER(new_value)); +} + +void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg) +{ + const uint32_t ctr_idx = (evt_reg - RISCV_IOMMU_REG_IOHPMEVT_BASE) >> 3; + const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); + uint64_t val = riscv_iommu_reg_get64(s, evt_reg); + + if (ctr_idx >= s->hpm_cntrs) { + return; + } + + /* Clear OF bit in IOCNTOVF if it's being cleared in IOHPMEVT register. */ + if (get_field(ovf, BIT(ctr_idx + 1)) && + !get_field(val, RISCV_IOMMU_IOHPMEVT_OF)) { + /* +1 to offset CYCLE register OF bit. */ + riscv_iommu_reg_mod32( + s, RISCV_IOMMU_REG_IOCOUNTOVF, 0, BIT(ctr_idx + 1)); + } + + if (!check_valid_event_id(get_field(val, RISCV_IOMMU_IOHPMEVT_EVENT_ID))) { + /* Reset EventID (WARL) field to invalid. */ + val = set_field(val, RISCV_IOMMU_IOHPMEVT_EVENT_ID, + RISCV_IOMMU_HPMEVENT_INVALID); + riscv_iommu_reg_set64(s, evt_reg, val); + } + + update_event_map(s, val, ctr_idx); +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index 0cd550975d..5fc4ef2e8b 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -28,5 +28,6 @@ void riscv_iommu_hpm_incr_ctr(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, void riscv_iommu_hpm_timer_cb(void *priv); void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh); void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s); +void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg); #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 821ecba3a4..cdbb848181 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2040,7 +2040,7 @@ static void riscv_iommu_process_hpm_writes(RISCVIOMMUState *s, case RISCV_IOMMU_REG_IOHPMEVT_BASE ... RISCV_IOMMU_REG_IOHPMEVT(RISCV_IOMMU_IOCOUNT_NUM) + 4: - /* not yet implemented */ + riscv_iommu_process_hpmevt_write(s, regb & ~7); break; } } @@ -2487,6 +2487,8 @@ static const Property riscv_iommu_properties[] = { DEFINE_PROP_BOOL("g-stage", RISCVIOMMUState, enable_g_stage, TRUE), DEFINE_PROP_LINK("downstream-mr", RISCVIOMMUState, target_mr, TYPE_MEMORY_REGION, MemoryRegion *), + DEFINE_PROP_UINT8("hpm-counters", RISCVIOMMUState, hpm_cntrs, + RISCV_IOMMU_IOCOUNT_NUM), }; static void riscv_iommu_class_init(ObjectClass *klass, void* data) diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index 2fef6eed27..a31aa62144 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -90,6 +90,7 @@ struct RISCVIOMMUState { /* HPM event counters */ GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */ + uint8_t hpm_cntrs; }; void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, From patchwork Mon Feb 24 19:08:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E36C6C021A4 for ; Mon, 24 Feb 2025 19:13:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdqH-0006Pq-0x; Mon, 24 Feb 2025 14:10:13 -0500 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 1tmdpC-0005iG-HJ for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:11 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdp8-0004s3-C4 for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:05 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-221057b6ac4so91918465ad.2 for ; Mon, 24 Feb 2025 11:09:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424140; x=1741028940; 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=PlFgyYMLHSiIYGuT1lQVY7DxANtlkqeHfC/q4DqwtKg=; b=pXcQhnlrrw++uGxWHtEaJzigR1oL2HGqBA7H9fzPHUdDhZYUoRCXV+lrgK/mlEu4QC N+C7boTPR22YQkswvDgUUkhg9p3Bk4zTFIKiOxpzZuQF2LXpgyWMw63GjNucMGwuCjQ8 brFQJ1EXemaMBhL4bnnRutPoqyoTO6PhwAm+moJn7Bi1zraeAhc/8c6BwItDenT/ZNUi aXc7CYFD5eumZXUAaxRDmqy6zP7Fpf5wO7aUDTqlHjPTl29VjQwTogE9B9zBh72KNQpv 3yFw+uV1f4L6dJImLkyLtnHEutk8D0Svj4WByRVgcDPp5WMu0c5YxMT8TboEKMfRN0N9 H26g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424140; x=1741028940; 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=PlFgyYMLHSiIYGuT1lQVY7DxANtlkqeHfC/q4DqwtKg=; b=tJC7KHkUYNQSkSj15Eg2HSocywSnQXAkGasRgCe2FVn34ew8nWX4bmEdveH0a/KfUO yywAycxA6MzBf5NrtqpKQnvWOxcdPEwEPtG0b1r+LONXiKvQotfBmkggVJnhyvr2riyQ fBtK1QxO3W+3tf2MUMlurWG3LaiDfW7cZFI2V9sldyHqrnI4P4aIkSvEaumPogzFl+sW VzHQL/UFqGxLkvLR9CY9meT0+ZYc7/FWI3uu8XavJspjz/EMy0JwS8LiBTcibYYy7Nda /AVp7rOD9/vE63k//xmJXxLkFI94u/0mmdr4bgr/oL1OhvG1wmrz8XCYoFwUvDLjlQjw v8CA== X-Gm-Message-State: AOJu0YyRvpJoa8qt7t9KvbzGeO5MvMbanXH+/ITm1SydPFTGcZtHvb+W ML9hZh9nD8Jwk7jm4HDnORr6s+IRFTy+H4BA8bIk9wj4Lx7eMooCiHrgi/TO0cbs1o3/pcuzilj q X-Gm-Gg: ASbGncvbJU5RNO30S7TRo+ajrYvT7vNYmi7140tvIPE2A6xL72PnZWBOxBz5Z2dVSMM hzed/wHggCjXWP5NFzXoR57fufg6cP0n6o7A/CRNKHV46b04s81Co67zvsKTECCCkq3qpqVbuki LJTb2s6Tb2dttGP19C91ncO55wtrD0C99ZqtXJ6Jm++FtHs2K05o/cCdEfx7erUdzUg5NtX8SV0 2fhnBaqFQqRI4Evyk18mUsEWi3edRh+rawp2SJM0NUFodku6TYpzDESPLU6OIP2edN5jQ1RAzDx nRHO3Ox0Z/PyKdlvHXA1x1TxIq3bdA== X-Google-Smtp-Source: AGHT+IH+ng/T7lBNgBAgSCavnA2awGELH2dwZ0aHudfmAdGS155OhnZexaZN1WnI000uQVZya23rGw== X-Received: by 2002:a17:902:e744:b0:21f:89e5:2715 with SMTP id d9443c01a7336-221a0edd8cbmr224356635ad.19.1740424140190; Mon, 24 Feb 2025 11:09:00 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:08:59 -0800 (PST) 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, Tomasz Jeznach , Daniel Henrique Barboza Subject: [PATCH v2 09/11] hw/riscv/riscv-iommu.c: add RISCV_IOMMU_CAP_HPM cap Date: Mon, 24 Feb 2025 16:08:24 -0300 Message-ID: <20250224190826.1858473-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62a.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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Tomasz Jeznach Now that we have every piece in place we can advertise CAP_HTM to software, allowing any HPM aware driver to make use of the counters. HPM is enabled/disabled via the 'hpm-counters' attribute. Default value is 31, max value is also 31. Setting it to zero will disable HPM support. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index cdbb848181..d46beb2d64 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2357,6 +2357,15 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; } + if (s->hpm_cntrs > 0) { + /* Clip number of HPM counters to maximum supported (31). */ + if (s->hpm_cntrs > RISCV_IOMMU_IOCOUNT_NUM) { + s->hpm_cntrs = RISCV_IOMMU_IOCOUNT_NUM; + } + /* Enable hardware performance monitor interface */ + s->cap |= RISCV_IOMMU_CAP_HPM; + } + /* Out-of-reset translation mode: OFF (DMA disabled) BARE (passthrough) */ s->ddtp = set_field(0, RISCV_IOMMU_DDTP_MODE, s->enable_off ? RISCV_IOMMU_DDTP_MODE_OFF : RISCV_IOMMU_DDTP_MODE_BARE); @@ -2404,6 +2413,18 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); } + /* If HPM registers are enabled. */ + if (s->cap & RISCV_IOMMU_CAP_HPM) { + /* +1 for cycle counter bit. */ + stl_le_p(&s->regs_ro[RISCV_IOMMU_REG_IOCOUNTINH], + ~((2 << s->hpm_cntrs) - 1)); + stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_IOHPMCYCLES], 0); + memset(&s->regs_ro[RISCV_IOMMU_REG_IOHPMCTR_BASE], + 0x00, s->hpm_cntrs * 8); + memset(&s->regs_ro[RISCV_IOMMU_REG_IOHPMEVT_BASE], + 0x00, s->hpm_cntrs * 8); + } + /* Memory region for downstream access, if specified. */ if (s->target_mr) { s->target_as = g_new0(AddressSpace, 1); From patchwork Mon Feb 24 19:08:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCD9BC021BB for ; Mon, 24 Feb 2025 19:10:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdpQ-0005mr-PQ; Mon, 24 Feb 2025 14:09:21 -0500 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 1tmdpF-0005iU-NJ for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:11 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdpC-0004sf-8n for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:09 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-21c2f1b610dso140716125ad.0 for ; Mon, 24 Feb 2025 11:09:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424143; x=1741028943; 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=z8p5zfD1qIU3ybTmqcZLhj2sWdxHJ8heHhex8dKGI3k=; b=VWvS6DIYki/r6vyKNBLr/psPYB1NxdbbIbjHt8q4pUgcMVl/aBY9WHNU2goRJSfapA nDMDvaLc0fRCydsNRjnX66lO+r1WG2lN1NBeGvpL4pgZgXP1nqgJ/Vc7A2SBmHqY3DIn X2Ca0EEDAYHAOkAhV/Gb0Vpn0j2VTBVUZimbl1ETfLfkLX+PewXk9bOmJCT31ZLVtKET fhnWvdl+t/TcaYfAjJcO7VZAgAxapkbct/Ybjq8kGqvAFlDiJtV7vYprewM84E60lvsL A/XWRTFJAnwAUzSr1DOErWQlKDxo3q2SAYRBqyKz0UGNbaIW+F/0yIYxxpoHhgn1fTR8 qBwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424143; x=1741028943; 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=z8p5zfD1qIU3ybTmqcZLhj2sWdxHJ8heHhex8dKGI3k=; b=W9ptdk4A/fgrMBRhT993cwkmgNQb9InLPn09mP6/yNsI+oFdxszZTZl8/x/BvnxpDQ ppfBAtkcSNInvODE7MtPCFNRdV9BIQbQiCmPyFpXIQtYGDnKXz3mxPL/Q/H0V7+JxkJo RaC9y5TuDbgGFzYDbd27XTEMDNVo2XR7kmMEYx8+00o8YlsfRlLRsqznm1aNrafc+N+e yeXLEjmBRqsimq+hVMjF3/8e2IeQR9YxJTwQzNbzWjrguZOEuJjNUKG9tTWAbyZpMAlx H2NXKCYIy1uohppAGEOHTT50ImPzduJLMbyXeFc3UojJvvksxejnzYhVKUq2BKKEmtAJ EyJA== X-Gm-Message-State: AOJu0YyDChuxpsA1ASg3zCVotZ6TO4Gkb/FhEx4hQCvpGR3HPct1XQJ1 kVhD0C3gR8GLRAuoV7+Pc9JPgSD6PQbVNT/CK0evzf3se9+4l+w/US9kdTop9JvI/SU2o/QeWPD w X-Gm-Gg: ASbGncvhOx5e2qWmYVMn12Of7prtY5Ea3LGMRnv9yaIl+tO+vB+6BzVkFBqPyImymcW o1qHqVLawxIbugs6rec2hTz0rE83k+Ss8dvUPL18IUdrJmG7YJH7hFC1j1E2XOo+QuKtDCNEh2y KDBj3r99/JyGOmK4lHfh4I1yPGvnw6GczOCTPpxJ0reEzND16axeePB8njvcQPf/f0wKXsNDl/6 BTHtWVA1f40zLG7/FHJQh1naiOIL+tF8Bp0FcXxkSR30WWri9j2C0q/tHZTYJ8aXMu/NnUxtEhe IbX0FqQ0dJ+BjqilI4JLJddLWmRZOw== X-Google-Smtp-Source: AGHT+IFVFWhQJonmNlj8kVJsSDooCmqlP3WehKqKKacVKwMVd0on/wzMDJISKkxC5kwpH4Bg1yxokg== X-Received: by 2002:a17:902:c402:b0:21f:617a:f1b2 with SMTP id d9443c01a7336-22307e7021fmr4360865ad.46.1740424143155; Mon, 24 Feb 2025 11:09:03 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:09:02 -0800 (PST) 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, Daniel Henrique Barboza Subject: [PATCH v2 10/11] hw/riscv: add IOMMU HPM trace events Date: Mon, 24 Feb 2025 16:08:25 -0300 Message-ID: <20250224190826.1858473-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62e.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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add a handful of trace events to allow for an easier time debugging the HPM feature. Signed-off-by: Daniel Henrique Barboza Acked-by: Alistair Francis --- hw/riscv/riscv-iommu-hpm.c | 10 ++++++++++ hw/riscv/trace-events | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 5518c287a5..c5034bff79 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -39,6 +39,8 @@ uint64_t riscv_iommu_hpmcycle_read(RISCVIOMMUState *s) const uint64_t ctr_prev = s->hpmcycle_prev; const uint64_t ctr_val = s->hpmcycle_val; + trace_riscv_iommu_hpm_read(cycle, inhibit, ctr_prev, ctr_val); + if (get_field(inhibit, RISCV_IOMMU_IOCOUNTINH_CY)) { /* * Counter should not increment if inhibit bit is set. We can't really @@ -61,6 +63,8 @@ static void hpm_incr_ctr(RISCVIOMMUState *s, uint32_t ctr_idx) cntr_val = ldq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); stq_le_p(&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val + 1); + trace_riscv_iommu_hpm_incr_ctr(cntr_val); + /* Handle the overflow scenario. */ if (cntr_val == UINT64_MAX) { /* @@ -244,6 +248,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh) return; } + trace_riscv_iommu_hpm_iocntinh_cy(prev_cy_inh); + if (!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY)) { /* * Cycle counter is enabled. Just start the timer again and update @@ -268,6 +274,8 @@ void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s) const uint64_t val = riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_IOHPMCYCLES); const uint32_t ovf = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_IOCOUNTOVF); + trace_riscv_iommu_hpm_cycle_write(ovf, val); + /* * Clear OF bit in IOCNTOVF if it's being cleared in IOHPMCYCLES register. */ @@ -352,6 +360,8 @@ void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg) return; } + trace_riscv_iommu_hpm_evt_write(ctr_idx, ovf, val); + /* Clear OF bit in IOCNTOVF if it's being cleared in IOHPMEVT register. */ if (get_field(ovf, BIT(ctr_idx + 1)) && !get_field(val, RISCV_IOMMU_IOHPMEVT_OF)) { diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events index 7bcbb03d08..b50b14a654 100644 --- a/hw/riscv/trace-events +++ b/hw/riscv/trace-events @@ -19,3 +19,8 @@ riscv_iommu_sys_irq_sent(uint32_t vector) "IRQ sent to vector %u" riscv_iommu_sys_msi_sent(uint32_t vector, uint64_t msi_addr, uint32_t msi_data, uint32_t result) "MSI sent to vector %u msi_addr 0x%"PRIx64" msi_data 0x%x result %u" riscv_iommu_sys_reset_hold(int reset_type) "reset type %d" riscv_iommu_pci_reset_hold(int reset_type) "reset type %d" +riscv_iommu_hpm_read(uint64_t cycle, uint32_t inhibit, uint64_t ctr_prev, uint64_t ctr_val) "cycle 0x%"PRIx64" inhibit 0x%x ctr_prev 0x%"PRIx64" ctr_val 0x%"PRIx64 +riscv_iommu_hpm_incr_ctr(uint64_t cntr_val) "cntr_val 0x%"PRIx64 +riscv_iommu_hpm_iocntinh_cy(bool prev_cy_inh) "prev_cy_inh %d" +riscv_iommu_hpm_cycle_write(uint32_t ovf, uint64_t val) "ovf 0x%x val 0x%"PRIx64 +riscv_iommu_hpm_evt_write(uint32_t ctr_idx, uint32_t ovf, uint64_t val) "ctr_idx 0x%x ovf 0x%x val 0x%"PRIx64 From patchwork Mon Feb 24 19:08:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13988838 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC459C021A4 for ; Mon, 24 Feb 2025 19:11:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmdqg-00072B-1b; Mon, 24 Feb 2025 14:10:38 -0500 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 1tmdpH-0005ie-5S for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:12 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmdpD-0004tv-UP for qemu-devel@nongnu.org; Mon, 24 Feb 2025 14:09:10 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-221057b6ac4so91920045ad.2 for ; Mon, 24 Feb 2025 11:09:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1740424146; x=1741028946; 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=NbbIeWCW4JzTBbeBSfjq8vnpfY5VkBCOXFXILh+yEvQ=; b=ho7mdll8Cz2VDQE9g3VtscbTVzvbfMjTfNDIM5Lj1hdGG3KKpfOKn5akbwbFHsEojF chluzwHq0L8dcf4HXwAYbtH4FVUpvMWXQnWNGDpm3NdcYCijurmRgmQhXImKGz8O85OM zRwMF9FvzFG0cU7GDTQg7b1WzuGj+YCtkeQxZDMJ1uvYLn9qRBMhjfE+B+Ogi2MJa/Hz 8+cuY92Q7aRqWx9cP4Lp4Qn9MzG4rdxbWTxkG8Xy8ZrkSlarJFLFf8P6ANfxthvoGr9e nKayrFoR/Lry/h1y2F+llwOjcIFXXx86jorBiA+pWzpPzrVMkdqk2GMOzn88O6FQ18jp cdcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740424146; x=1741028946; 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=NbbIeWCW4JzTBbeBSfjq8vnpfY5VkBCOXFXILh+yEvQ=; b=gS+usAeYAdbtDRS/PAmIDr5AU6YDm6240yU3AULQEi/HqBU64i6mI288OkjBNtEA+U /552U+yz9wjz5QFEiTlR8eBLmF6YE/7ZI1fo+NNOQ8jozCRa0Z9SHyRew+MiNXg/+9Sj Ld7hQQagq6pd/SeapVXNDTDCeaUp5hDE9+0OdP4iPhtPGfsyDx270OotMirU7JCv5uYr sRAoSpErumWDU2BnsQFnrrlgaSjwyOIzKPq32/XMYhy9EmSzSEKIjKUIvnOJhTpsLHQK 0WCFrT0TzoHC+InG4Yzy1GSTZR6r1ziFpP2oAYiP6ZYLSzLHy8pdvbj4UdfydRnXg4ch epGA== X-Gm-Message-State: AOJu0YycGq+o8PQ96gY8Bfz3IBLJaA/y5Qt1ih4vEnw2CFbVpspgDs/T s3G4uWgy/fiRRMT7nOz8MldjYvhzjezOFxmjvgHaq3oBpwgAJ9z835/UKWv0bJCtwN6wvLVud3C l X-Gm-Gg: ASbGncuvNLwC40WxgISj+lc+itzuGRhG8mkKrUdJF6mRbnphyNeerLJpe/7MeIjy7uL 53UtJdz053JKErYs7NBxOyEtayKprbmriGmHSJnjxaRXdCgJG6l9Kvac7fvlOtMYtLv92Tr3Bro 1z5cEQulfUZ/u8BBT4zlnfe7v1Uap+22xMqM4Uj7kepQsbxl7rekUxYRJvvzAkrYafd7nXiMN9b A98Actnzcw7uuHH9Lrddw0yTar20g2+raULI6cLDMztdu28CQfAP2qdCtsVXLKjHXfv53WUAPig dHBHmnD7gBZ4V6yU+XcbFGhugS7GtA== X-Google-Smtp-Source: AGHT+IFTHuNTOowQJrG1m4QWiu3Af76qEeHKl/5mOFzfI7bieZkvXKSTvgSXvQdCpAy8hWN0Pv8GIQ== X-Received: by 2002:a17:902:ea10:b0:21f:9c7:2d2e with SMTP id d9443c01a7336-221a1191916mr256593245ad.40.1740424146294; Mon, 24 Feb 2025 11:09:06 -0800 (PST) Received: from grind.. ([2804:7f0:bcc0:6edb:f473:a9df:d551:443b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545df28sm183583155ad.153.2025.02.24.11.09.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 11:09:05 -0800 (PST) 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, Daniel Henrique Barboza Subject: [PATCH v2 11/11] docs/specs/riscv-iommu.rst: add HPM support info Date: Mon, 24 Feb 2025 16:08:26 -0300 Message-ID: <20250224190826.1858473-12-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224190826.1858473-1-dbarboza@ventanamicro.com> References: <20250224190826.1858473-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x630.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- docs/specs/riscv-iommu.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/specs/riscv-iommu.rst b/docs/specs/riscv-iommu.rst index b1538c9ead..000c7e1f57 100644 --- a/docs/specs/riscv-iommu.rst +++ b/docs/specs/riscv-iommu.rst @@ -82,6 +82,8 @@ Several options are available to control the capabilities of the device, namely: - "off" (Out-of-reset translation mode: 'on' for DMA disabled, 'off' for 'BARE' (passthrough)) - "s-stage": enable s-stage support - "g-stage": enable g-stage support +- "hpm-counters": number of hardware performance counters available. Maximum value is 31. + Default value is 31. Use 0 (zero) to disable HPM support riscv-iommu-sys device ----------------------