From patchwork Thu Mar 9 05:51:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1754423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lpkCAxgT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=F8vcV+DV; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PXJGY33T0z2471 for ; Thu, 9 Mar 2023 16:51:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Th82paUlHCwbTEu9D6u6sQitRQX/JljV1DzguGDbD+E=; b=lpkCAxgTj3WzR/ hiR+2HNLGJQ94z7eVBvrbRRGSVHgRjXC1O9kd2/l5JP1k4LgD5cruN07T0TniaKZt8y3TBvC0SfbU qwVQ+1GwWahWvEK9iOilDFe7RawMYn4h8qGxsltKjpdJiGuw78ao9UqDbbgJKSZqURIL6hX0fsgxo KuyN2gI5vmA5rhNBDVSLLr95rauaUz9c1zrUVc05Gz1GqkkUUn2OxUjNQ0ILKBrsbBnpex8rTahal ycIQi9I8lrgW77ASMO/7g+xEytdMvS2ZytCqiNETpy8ciXlubrZEtSYst/VafMbszN0nzcRuMe3ui NYmgqe7SyJHUr2Rueh1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pa9Bg-007z5R-8D; Thu, 09 Mar 2023 05:51:36 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pa9Bd-007z0u-J2 for opensbi@lists.infradead.org; Thu, 09 Mar 2023 05:51:35 +0000 Received: by mail-pj1-x102f.google.com with SMTP id l1so1124763pjt.2 for ; Wed, 08 Mar 2023 21:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1678341093; 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=8qenaJQ7qKfMHJQpWs3ZZQ7m9zukT8W/DnR72EXto+s=; b=F8vcV+DVMK++z8jgjzgJzXBxftm2y8UhOiuMKrl+g/S9lY644HxOJsY1Z4zARhfnP4 IBerVhlXz0cpEgIEj6vHPyikeXGZHAsPfjVAHFMWKWmmvCgwJpVSWNNMZnFAGZ8lGZIz ah22wHCqBNY1dP+bm7gGJx6ynSvP69nUe8S8B3Wi/U0VFOtBwn71BjXU5oWai6Ebs9Iu W2kxs0ieS1NeLmqh3jV/nyogCMmYym56+5kNfzHBYnAlE9lKd/uEqMuKho894RjJVmyC b6vh2ZSm+Xxt986VaMNMw2jjufz7ct71vsIWpxR1WvZAjh62OS0/WkmX7dnMRL2Eym2O lcdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678341093; 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=8qenaJQ7qKfMHJQpWs3ZZQ7m9zukT8W/DnR72EXto+s=; b=Piih52jMs+4O2pJge1VOHahlc1wMWH+GfIvbIWnRg8JgiLX5smNcKiJEEreJGhJA9E xjX8mEMxCDxyokTOK7lN936GnXYIVJreBgzDPf/22UsFJboLq4/lAIKB2Xko7ugD5UAE kvrxH4VRpf0SnUOxlxJO/ZMOLX4xPfJDydvR4mRzqAHC/hfyJtME9zleAHKJ5IbaLtBa XX4UQh+W8N50LEkQYX8ccjTLT+6uV7btfw9yM2oBFrhvzozy8cGrNEYUMNeXIqb+lIMQ jmaILJgWXtVJ6ZuIulF76XMGAl9jiU9PphYbWbVVYFMFNpv0jTdyjtatt4wkGNEE9+v9 dQ7Q== X-Gm-Message-State: AO0yUKV5V8pLIleht63u9Fkz+K63T7+W0+S6c87aBVGzvxNC7UkB/jJt kx6pIF+ADrWGIwnhQNrmH8L8NWc/dCd8ioAeTfKSTQ== X-Google-Smtp-Source: AK7set+SgKi1Z7VACfBcErRxDwwwrICf0s99dh1uidbpapiHpMX2UaW7LXFG9eqPw2w8DFASeYRCBw== X-Received: by 2002:a17:902:b488:b0:19d:19fb:55ec with SMTP id y8-20020a170902b48800b0019d19fb55ecmr16317502plr.6.1678341092880; Wed, 08 Mar 2023 21:51:32 -0800 (PST) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id 13-20020a170902e9cd00b0019ac9c4f32esm10590724plk.309.2023.03.08.21.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 21:51:32 -0800 (PST) From: Mayuresh Chitale To: opensbi@lists.infradead.org Cc: Mayuresh Chitale Subject: [PATCH v3 6/8] lib: sbi_pmu: Use dedicated event code for platform firmware events Date: Thu, 9 Mar 2023 11:21:10 +0530 Message-Id: <20230309055112.1516581-7-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309055112.1516581-1-mchitale@ventanamicro.com> References: <20230309055112.1516581-1-mchitale@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230308_215133_648686_CD93A7E2 X-CRM114-Status: GOOD ( 16.51 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For all platform specific firmware event operations use the dedicated event code (0xFFFF) when matching against the input firmware event. Furthermore save the real platform specific firmware event cod [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102f listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For all platform specific firmware event operations use the dedicated event code (0xFFFF) when matching against the input firmware event. Furthermore save the real platform specific firmware event code received as the event data for future use. Signed-off-by: Mayuresh Chitale Reviewed-by: Anup Patel --- lib/sbi/sbi_pmu.c | 65 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 1169ef2..d083198 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -122,7 +122,12 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata) event_idx_code_max = SBI_PMU_HW_GENERAL_MAX; break; case SBI_PMU_EVENT_TYPE_FW: - if (SBI_PMU_FW_MAX <= event_idx_code && + if ((event_idx_code >= SBI_PMU_FW_MAX && + event_idx_code <= SBI_PMU_FW_RESERVED_MAX) || + event_idx_code > SBI_PMU_FW_PLATFORM) + return SBI_EINVAL; + + if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding) return pmu_dev->fw_event_validate_encoding(edata); else @@ -187,12 +192,19 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval) if (event_idx_type != SBI_PMU_EVENT_TYPE_FW) return SBI_EINVAL; - if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_data[hartid][cidx - num_hw_ctrs] = - pmu_dev->fw_counter_read_value(cidx - num_hw_ctrs); + if ((event_code >= SBI_PMU_FW_MAX && + event_code <= SBI_PMU_FW_RESERVED_MAX) || + event_code > SBI_PMU_FW_PLATFORM) + return SBI_EINVAL; - *cval = fw_counters_data[hartid][cidx - num_hw_ctrs]; + if (SBI_PMU_FW_PLATFORM == event_code) { + if (pmu_dev && pmu_dev->fw_counter_read_value) + *cval = pmu_dev->fw_counter_read_value(cidx - + num_hw_ctrs); + else + *cval = 0; + } else + *cval = fw_counters_data[hartid][cidx - num_hw_ctrs]; return 0; } @@ -367,8 +379,17 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, int ret; u32 hartid = current_hartid(); - if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_start) { + if ((event_code >= SBI_PMU_FW_MAX && + event_code <= SBI_PMU_FW_RESERVED_MAX) || + event_code > SBI_PMU_FW_PLATFORM) + return SBI_EINVAL; + + if (SBI_PMU_FW_PLATFORM == event_code) { + if (!pmu_dev || + !pmu_dev->fw_counter_start) { + return SBI_EINVAL; + } + ret = pmu_dev->fw_counter_start(cidx - num_hw_ctrs, event_data, ival, ival_update); @@ -386,12 +407,13 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask, unsigned long flags, uint64_t ival) { + u32 hartid = current_hartid(); int event_idx_type; uint32_t event_code; int ret = SBI_EINVAL; bool bUpdate = false; int i, cidx; - uint64_t edata = 0; + uint64_t edata; if ((cbase + sbi_fls(cmask)) >= total_ctrs) return ret; @@ -405,9 +427,13 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask, if (event_idx_type < 0) /* Continue the start operation for other counters */ continue; - else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) { + edata = (event_code == SBI_PMU_FW_PLATFORM) ? + fw_counters_data[hartid][cidx - num_hw_ctrs] + : 0x0; ret = pmu_ctr_start_fw(cidx, event_code, edata, ival, bUpdate); + } else ret = pmu_ctr_start_hw(cidx, ival, bUpdate); } @@ -441,7 +467,12 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code) { int ret; - if (SBI_PMU_FW_MAX <= event_code && + if ((event_code >= SBI_PMU_FW_MAX && + event_code <= SBI_PMU_FW_RESERVED_MAX) || + event_code > SBI_PMU_FW_PLATFORM) + return SBI_EINVAL; + + if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { ret = pmu_dev->fw_counter_stop(cidx - num_hw_ctrs); if (ret) @@ -651,13 +682,18 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask, { int i, cidx; + if ((event_code >= SBI_PMU_FW_MAX && + event_code <= SBI_PMU_FW_RESERVED_MAX) || + event_code > SBI_PMU_FW_PLATFORM) + return SBI_EINVAL; + for_each_set_bit(i, &cmask, BITS_PER_LONG) { cidx = i + cbase; if (cidx < num_hw_ctrs || total_ctrs <= cidx) continue; if (active_events[hartid][i] != SBI_PMU_EVENT_IDX_INVALID) continue; - if (SBI_PMU_FW_MAX <= event_code && + if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding) { if (!pmu_dev->fw_counter_match_encoding(cidx - num_hw_ctrs, edata)) @@ -702,6 +738,9 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, /* Any firmware counter can be used track any firmware event */ ctr_idx = pmu_ctr_find_fw(cidx_base, cidx_mask, event_code, hartid, event_data); + if (event_code == SBI_PMU_FW_PLATFORM) + fw_counters_data[hartid][ctr_idx - num_hw_ctrs] = + event_data; } else { ctr_idx = pmu_ctr_find_hw(cidx_base, cidx_mask, flags, event_idx, event_data); @@ -721,7 +760,7 @@ skip_match: if (flags & SBI_PMU_CFG_FLAG_CLEAR_VALUE) fw_counters_data[hartid][ctr_idx - num_hw_ctrs] = 0; if (flags & SBI_PMU_CFG_FLAG_AUTO_START) { - if (SBI_PMU_FW_MAX <= event_code && + if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start( ctr_idx - num_hw_ctrs, event_data,