Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3261513lqp; Tue, 26 Mar 2024 04:36:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzGv2luIvCssnwzQVakKq520EHjiGsiQOUs7bZPiwe36gb6y0jt6sQOSXyU1MuPlILwqTRmS6veoDjWC4Dg4WgV5nHlycYUyd4AivhLQ== X-Google-Smtp-Source: AGHT+IGKhTmFvRCFP0ejCRbBJy6w31TpSObVDqPiTpSw1mWfm0Kc66CA7gj/obwbbeKCbO5wq6mR X-Received: by 2002:a05:6871:550:b0:229:a617:420c with SMTP id t16-20020a056871055000b00229a617420cmr5954350oal.7.1711453006459; Tue, 26 Mar 2024 04:36:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711453006; cv=pass; d=google.com; s=arc-20160816; b=W0E/wOi6CmNLNUVDg7DKmU7eHv2CIq0v6nNQUGf6ZAfg5yR05P9I9rWmlthznOUqXh 49NhtG+GrOakz/socfkVrQS60/WodCDHD45LpAAMw625yYIQWnHl7perbiRa6YMYnE07 mYF6OzOX8gYoKoowwHs+4hHQJjwZE8u+Ka1t/JQNCXNO7wJIAYaiA/ptkD1IrN1yly+2 y9TUkBaWUHK1F8YKInReeSSDgyVtWjNd+kaBfkt8fsMbQEbBzUTb5ZHTpMEOqIE21iHB qIlQzvvjxQ/O7TgOi9+DOOXvwp+pXBGIEnNrHKMtQZ2iZI45st8Kmqt3sNAaC4m4Hnh+ TP2Q== 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:dkim-signature; bh=VqYzcAK8dqNaEALutmMiYoXA86kBnoaA3vdfoWJrs0o=; fh=DQfWcJ7a6lABpgAjlslbt+lALChD4jPOSQFW0XC7h54=; b=K0UW8nTPfTHIeMDZzsaLhGmvfd6+MseOCeY7kmwTI5ZttZ/5Z/dLgPo+Q2w3XbvfJ5 skouU5BBbGS00tPSCRtqn591G4EFaMLv7i0RBDv4tCxNPeaHnlSH1H/HMQp3rlGS5zXh x0AbG3WLGgyElYNVyPUnElbXuM5uJiaJ7HftQrJxxwmcSawqyZeUbxf6norKtG0d/X6B GviLM9T9BsnGOmFnJrQJl6YGzJjntqWKhc45gpJ1sdTZPB9cxNMlvwO8sZpXIbvYFBqs mrp+7IyMIBuxphe1kQdYDO3SZ9Ia/DVlO3Vtpj7BnI1xoztG2KsR75eCN/3Vtzt2GvhL 9kvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TRKkGHV8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-118607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118607-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a10-20020a63d40a000000b005dcbb9ebe61si9244285pgh.821.2024.03.26.04.36.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 04:36:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TRKkGHV8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-118607-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118607-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A3F03B218F2 for ; Tue, 26 Mar 2024 09:03:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 405696EB5C; Tue, 26 Mar 2024 09:01:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TRKkGHV8" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C78E365197; Tue, 26 Mar 2024 09:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711443697; cv=none; b=QXPiQ1ywPet//1fXROOcfnHyAw2PCJk5xxFdonD855XGhsHPpd/SjlvsV+4/voNXY7IQOcUTT6cKUlP/tYFRLZnVk4jmQwxqYnXVmRFDv3O5HHiuBfF+uCDxgMssYVLBLOl52C6DCHjRPUlXj+ljiyKqHH9BQ4Yjr+wMYqrjwRo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711443697; c=relaxed/simple; bh=c+MuKXOKkKdXjy1Y8M+WHe8wQaylbGo3X0SgvA9A7To=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ud5V2oFVq9VWoTIcJ76rECC3rZBLZCmyswGv4XdMVKJk/W3F45fLRU1HGgzPMRFMzRg2EpqazlD+B4BDC9+f3ggU2SGBuvCcWWVrbcuGwO0O1UVeQAHJsXIIiVNpQeBGcdjRZVB53cFn7at6QR6hIydFJifiIkykkdKeqH2UkMA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TRKkGHV8; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711443696; x=1742979696; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c+MuKXOKkKdXjy1Y8M+WHe8wQaylbGo3X0SgvA9A7To=; b=TRKkGHV8S1N4SBA8jbemQLLf9oneHKnDcqipVzQkEoAhdaZp+/30A7aQ zmYXbAOalgCBRAsAYrWXrGiMsXC8U2yebVc9HHpBJ6UtFEUTqQ3cCqWPn oANGGlDDjZ8K1x8avgJsg/Hw8ojgG1Eoy3z7BxHqki4QFRtLLQzHdA+2R foFdT3BEnxcgVmfewZUyKrNCcgg+HPiibUsk1MyJonXh7ZtTYMqgGCdWQ Rnt6pzUcCq+v0PNaPfIbcWRALaJuWnVyxp0Ym2Wg8SnoMhShT0pXvs5ZK Lbm+BsYat4ZcUzsX+KZnVABUErKu7I+A+aN1Ik69FUDl+pqxRxDACSAon Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11024"; a="6343366" X-IronPort-AV: E=Sophos;i="6.07,155,1708416000"; d="scan'208";a="6343366" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 02:01:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,155,1708416000"; d="scan'208";a="20614525" Received: from yungchua-ws.ostc.intel.com (HELO yungchua-ws.intel.com) ([10.54.69.90]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 02:01:28 -0700 From: Bard Liao To: linux-sound@vger.kernel.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: [PATCH 7/7] soundwire: bus: add stream refcount Date: Tue, 26 Mar 2024 09:01:22 +0000 Message-Id: <20240326090122.1051806-8-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326090122.1051806-1-yung-chuan.liao@linux.intel.com> References: <20240326090122.1051806-1-yung-chuan.liao@linux.intel.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 From: Pierre-Louis Bossart The notion of stream is by construction based on a multi-bus capability, to allow for aggregation of Peripheral devices or functions located on different segments. We currently count how many master_rt contexts are used by a stream, but we don't have the dual refcount of how many streams are allocated on a given bus. This refcount will be useful to check if BTP/BRA streams can be allocated. Note that the stream_refcount is modified in sdw_master_rt_alloc() and sdw_master_rt_free() which are both called with the bus_lock mutex held, so there's no need for refcount_ primitives for additional protection. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- drivers/soundwire/stream.c | 5 +++++ include/linux/soundwire/sdw.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index 4e9e7d2a942d..7aa4900dcf31 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -1181,6 +1181,8 @@ static struct sdw_master_runtime m_rt->bus = bus; m_rt->stream = stream; + bus->stream_refcount++; + return m_rt; } @@ -1217,6 +1219,7 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt, struct sdw_stream_runtime *stream) { struct sdw_slave_runtime *s_rt, *_s_rt; + struct sdw_bus *bus = m_rt->bus; list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) { sdw_slave_port_free(s_rt->slave, stream); @@ -1226,6 +1229,8 @@ static void sdw_master_rt_free(struct sdw_master_runtime *m_rt, list_del(&m_rt->stream_node); list_del(&m_rt->bus_node); kfree(m_rt); + + bus->stream_refcount--; } /** diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index e3a4bccc2a7e..71a7031f7b3a 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -902,6 +902,7 @@ struct sdw_master_ops { * meaningful if multi_link is set. If set to 1, hardware-based * synchronization will be used even if a stream only uses a single * SoundWire segment. + * @stream_refcount: number of streams currently using this bus */ struct sdw_bus { struct device *dev; @@ -931,6 +932,7 @@ struct sdw_bus { u32 bank_switch_timeout; bool multi_link; int hw_sync_min_links; + int stream_refcount; }; int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, -- 2.34.1