Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2420363rdb; Mon, 12 Feb 2024 04:33:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6CEDcXatQG8WwOp8UfN1Tk2JgOUTOJJ+72v1fL7TcdTFE6EJYo3bS9k8SUxZMHlJasoBV X-Received: by 2002:a92:de48:0:b0:363:dec8:fedd with SMTP id e8-20020a92de48000000b00363dec8feddmr7036337ilr.12.1707741209045; Mon, 12 Feb 2024 04:33:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707741209; cv=pass; d=google.com; s=arc-20160816; b=pPsj4LreGs2oq57bimotA7dyBcfUeGsaAQuz8kOe7/JEMojB1aezJudFfSBeErG4mC 9ZtVhJTpAB9ZY/VA+bokW/urnC+TFbk4jHZ8xwM1d4GmPBRABcDveYl8OHoi7voGAqi4 GVLnrX4HuInGNwvn9iwQEPohaqxQwoxT5DVQ8WhwmYRnL3uQIWrTAjA0r/mrHAIGKla3 siqe6PV5hXNz9KrhDUFvfFNkba5x8dpGatr4GbDjXfEJzFaZDLY2yeq0Hks/RvB1Rhy9 VqrrX4RNSUeOj7Ej6TFK7FiusLfFc6j7ItU6oEMXO7UjeyJcEO0TubAS5Dh8fM5P+6yd S25g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=4mUjNUITRP5XEHV6BkJXYYu6se2V8qu9LBG0CO68NgQ=; fh=E28LblHE15USGw0wne5TefE/KBr4BbVYBMuuzmaIV5s=; b=wP0TWCvLWugeoTdy4f5dDWpc85VRnpPa/ZSUkFxPPFkOIf8V4RnGY8lhiU+5b63pPQ dtlajWFdAvl1XF552g+58YTBFoGN2rPREgh/LDUck0xQ8j+8cEt0RszupFMX/YAK0lIE rLbbyKWYle/DrJ5VeeV5l1T11o5akrjSeJE9XnQluayXdxJLom6508KwnMfXuMaAHFwA x54MZJOt5f44RAvb2IrEVdT7fgGQRLhLFDeEl3v4DFtE+aTrRce/TpadTsZRsbA4+EC3 CwvHB9A72si5OuVTwpO7s8QEVmjJHi8hBoNisHB6y4RXRWohvGIecccOEEZcTmFllbVW Ma2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-61548-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWq2Q2dOeeg5wBWKV88B10th51GodFxZmKieHTtBrsNIgua3+R4tONh4GJ5/iwyLBbGSXVH8xvLD2clDbHPd9SgoiSQwV69m5kIXVn9cw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ch2-20020a056a0208c200b005cdfde5e3f3si185554pgb.250.2024.02.12.04.33.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:33:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61548-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-61548-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AD97B287E5A for ; Mon, 12 Feb 2024 12:33:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 414483A1BE; Mon, 12 Feb 2024 12:33:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03FCC1E487 for ; Mon, 12 Feb 2024 12:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707741186; cv=none; b=ZvI7gIuPXNjZEdar2ryd23FEtmaW76xEMsX3MONAOdY9N7vq04lPsmC9TIqnFhvuOYOFrh/T7CSkCErCnh1p/vT/c/Oac5wvg+34MYwB/ifdvqX3ZtJoj7z4plJcZ8t67tDJnzY0nb+7yZdAxTT19aSunc/duhzazcwUny24YzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707741186; c=relaxed/simple; bh=JlkQiW/QuL/OX9TPCicFNqlZdcMRLppLsC1w6NTqto0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X6UhkiMppLK/uGb/oCUdlBBdvW9mTmGrk0IlZMqCj54Ov3guU3bs0R/kx+gNXZxGkkOU+s9JNNUStVbveUbnf+ezSj9kpfHFAqw7Ec7/euTrGm5QUk8UINa+XcIPe+2PdmzqFgRBLICNXXd8+K1PYwWg0WHlvsIxa9MPeXNAyI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4A3BAFEC; Mon, 12 Feb 2024 04:33:44 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7A3E03F7BD; Mon, 12 Feb 2024 04:33:01 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 01/11] firmware: arm_scmi: Check for notification support Date: Mon, 12 Feb 2024 12:32:23 +0000 Message-ID: <20240212123233.1230090-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212123233.1230090-1-cristian.marussi@arm.com> References: <20240212123233.1230090-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When registering protocol events, use the optional .is_notify_supported callback provided by the protocol to check if that specific notification type is available for that particular resource on the running system, marking it as unsupported otherwise. Then, when a notification enable request is received, return an error if it was previously marked as unsuppported, so avoiding to send a needless notification enable command and check the returned value for failure. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/notify.c | 17 ++++++++++++++++- drivers/firmware/arm_scmi/notify.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c index 0efd20cd9d69..27c52531194d 100644 --- a/drivers/firmware/arm_scmi/notify.c +++ b/drivers/firmware/arm_scmi/notify.c @@ -99,6 +99,7 @@ #define PROTO_ID_MASK GENMASK(31, 24) #define EVT_ID_MASK GENMASK(23, 16) #define SRC_ID_MASK GENMASK(15, 0) +#define NOTIF_UNSUPP -1 /* * Builds an unsigned 32bit key from the given input tuple to be used @@ -788,6 +789,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, pd->ph = ph; for (i = 0; i < ee->num_events; i++, evt++) { + int id; struct scmi_registered_event *r_evt; r_evt = devm_kzalloc(ni->handle->dev, sizeof(*r_evt), @@ -809,6 +811,11 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, if (!r_evt->report) return -ENOMEM; + for (id = 0; id < r_evt->num_sources; id++) + if (ee->ops->is_notify_supported && + !ee->ops->is_notify_supported(ph, r_evt->evt->id, id)) + refcount_set(&r_evt->sources[id], NOTIF_UNSUPP); + pd->registered_events[i] = r_evt; /* Ensure events are updated */ smp_wmb(); @@ -1166,7 +1173,13 @@ static inline int __scmi_enable_evt(struct scmi_registered_event *r_evt, int ret = 0; sid = &r_evt->sources[src_id]; - if (refcount_read(sid) == 0) { + if (refcount_read(sid) == NOTIF_UNSUPP) { + dev_dbg(r_evt->proto->ph->dev, + "Notification NOT supported - proto_id:%d evt_id:%d src_id:%d", + r_evt->proto->id, r_evt->evt->id, + src_id); + ret = -EOPNOTSUPP; + } else if (refcount_read(sid) == 0) { ret = REVT_NOTIFY_ENABLE(r_evt, r_evt->evt->id, src_id); if (!ret) @@ -1179,6 +1192,8 @@ static inline int __scmi_enable_evt(struct scmi_registered_event *r_evt, } else { for (; num_sources; src_id++, num_sources--) { sid = &r_evt->sources[src_id]; + if (refcount_read(sid) == NOTIF_UNSUPP) + continue; if (refcount_dec_and_test(sid)) REVT_NOTIFY_DISABLE(r_evt, r_evt->evt->id, src_id); diff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi/notify.h index 4e9b627edfef..76758a736cf4 100644 --- a/drivers/firmware/arm_scmi/notify.h +++ b/drivers/firmware/arm_scmi/notify.h @@ -35,6 +35,8 @@ struct scmi_protocol_handle; /** * struct scmi_event_ops - Protocol helpers called by the notification core. + * @is_notify_supported: Return 0 if the specified notification for the + * specified resource (src_id) is supported. * @get_num_sources: Returns the number of possible events' sources for this * protocol * @set_notify_enabled: Enable/disable the required evt_id/src_id notifications @@ -50,6 +52,8 @@ struct scmi_protocol_handle; * process context. */ struct scmi_event_ops { + bool (*is_notify_supported)(const struct scmi_protocol_handle *ph, + u8 evt_id, u32 src_id); int (*get_num_sources)(const struct scmi_protocol_handle *ph); int (*set_notify_enabled)(const struct scmi_protocol_handle *ph, u8 evt_id, u32 src_id, bool enabled); -- 2.43.0