From patchwork Mon Feb 12 12:32:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 199720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2396096dyd; Mon, 12 Feb 2024 04:33:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhrw5P0+hz6wOAHqd2CL2XcryUj5c1CLOdQ31HkXo+BFUaX/KO0N0lHj+h3k2sCdKFg82w X-Received: by 2002:a17:906:ae93:b0:a3c:92c2:66e0 with SMTP id md19-20020a170906ae9300b00a3c92c266e0mr2049037ejb.64.1707741226393; Mon, 12 Feb 2024 04:33:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707741226; cv=pass; d=google.com; s=arc-20160816; b=JnoquxLbR+EYCJe72ulgZKOK+7tV+WtjLGX4iMsQGqQNGIBr2Jg63bxBqsTwyveiT4 GnQ0H0ug5rAK0uKqC+iSwsK1eVgjPbherXTjNBCt1NPZh79LvTnPuHis3FzmRPNphzvS p6tet2Stc6b66s/kwbCSCylvyX5S1Tsw46bT2w0rcCb3aL6LZHbd5QQNJbDbF3OR7Ohi 3OfTYm9Kp3OOaVhUh95XpaUeyO5z/jRLuTuw4qIsuqC7avHswdij/w4I2FQNk5r4+pzY zaKVRb8orm6Utbo5LObDJ7xofQeMRRUANlyIoNfJ3NuDvbypIb45hOICo7NjH/sNvTzF CMpg== 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=MxMFHXAH879fk6I31q6eIo5lOeTgt1mTw8MedubiXvk=; b=jei+YWMgM5Wf3WM0EsXGcJNtw6/HRPwtpbYoVVOV5KzqzeIp5qjNGwD5H9U9nM6evT XrwC+nh1KFbOQhJMB7u3iAzJvADK6hsdWwypFethSoSaZzv1QP5xtPSw8fpJ2U9TYCaA 8I0ln5nyh1i9hqat2r8LbUPiW+XDd6tb4c6f4D4hYCa4PgOfRgumm9ay3FqDF/nZNFdl dEl4bVtycDTqQbQJPZjhwPGkVgBAgxmE3KAgkYPFovJbm9UNWlFvucyDzOJnNB7v4ZUw aMhe253OYtrofG+iEsnYdGkPujrsvI53LQZyPJwg4h/B5ds0cqZ21dfxjlkBgntCVsyN Znrg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61548-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUroFARm80dWqRsIAkeGjNTAH+aE/d6TI6AdEJ/RwLa4zEtQvatAmyHQMrvL2TTYlpB7jAEVx7ulhAqbDeSy+wYHP82Bw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t26-20020a1709063e5a00b00a3c9abc9b56si143295eji.892.2024.02.12.04.33.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:33:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61548-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61548-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 078551F257EA for ; Mon, 12 Feb 2024 12:33:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57F373A29E; Mon, 12 Feb 2024 12:33:08 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790696464031536091 X-GMAIL-MSGID: 1790696464031536091 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);