From patchwork Mon Oct 21 13:34:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13844174 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 DDD281F4FC8; Mon, 21 Oct 2024 13:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517835; cv=none; b=TBrHjaWQL+kSZXySm6S7lPlkAyn0lLUKKaxyFSotiXs4JtgrQRMAmu6DLaE9BlivSdtIl3wk0raO++Pjfht7E0wD8HyPPDGevAnEHTQo7gM300zuaAXy+IwCg4P4nMOrKvW0ey9C42v96zUx7bmNdVwrcDfshuzcROoKTkVAfC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517835; c=relaxed/simple; bh=oD+19+bWPRUo+nFEhiHZ++FpJIph8ImQWAJ19j4w9BQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RHzJslL/QtOOI7a5bxbK+QtVGlFXebafnVHu1iladj3ICE3GkQdwCvB4ZQtGg/6psFD6D7MEo8m3/5YlAb2Fbes70GyohGOtExSu8hIjkVOkTg92+V82Wwcc0z851fwKNQOROyD2C2uK+I4YLDl0hnEmeJD3aU6ZCuB68QEmqT0= 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=YcIRcbq0; arc=none smtp.client-ip=192.198.163.15 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YcIRcbq0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729517834; x=1761053834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oD+19+bWPRUo+nFEhiHZ++FpJIph8ImQWAJ19j4w9BQ=; b=YcIRcbq0PGmQlUdFOIblUMeXttIOdqocvwTat9qI+vUcU/ivOUwEOF+G zTW7v9VfgXZiMzhUS45wZ7iXGo9I0bIbtAv6CfEaTAua2Rnbzr1th9tU4 5uonESf8srqbYsI6GgCbicXcsUVX0HxwXrfWWZqcvhyIvNtPfF59HS7hC 3dBEHktuQHZdCNJNMuBYFjr86RXjCDun58J/5OJnnXThZ36fsD/Qm0C/K eiHMRr2bhFAO02v6zzQB20cSrtEOy+XlRa9f+BU/Z+bgDGcjjm8Jz2Sq4 m7/Jq8GleUzD8U4OPz4VQqOz1tP8e4q5HcxbYG/vg2oqnhUxFKYynYzBu Q==; X-CSE-ConnectionGUID: dQwQriJhSKii1KtVC+HscA== X-CSE-MsgGUID: INbHtcy6RlWLGss87lndNQ== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29119826" X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="29119826" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 06:37:11 -0700 X-CSE-ConnectionGUID: Lu0rLax5QaubmbmGTfdY2A== X-CSE-MsgGUID: wNM0YO3SRGmG7RStq6LZUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="79931177" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 21 Oct 2024 06:37:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 42D2912B; Mon, 21 Oct 2024 16:37:07 +0300 (EEST) From: Andy Shevchenko To: Mika Westerberg , Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v3 1/5] platform/x86: intel_scu_ipc: Unify the flow in pwr_reg_rdwr() Date: Mon, 21 Oct 2024 16:34:29 +0300 Message-ID: <20241021133705.2933464-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> References: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unify the flow in pwr_reg_rdwr() with intel_scu_ipc_dev_command_with_size(). While read buffer is not currently being used by the callers of pwr_reg_rdwr(), this might change in the future. For the existing code it's a harmless change because the read data for the write operation is simply discarded. Tested-by: Ferry Toth Acked-by: Mika Westerberg Signed-off-by: Andy Shevchenko --- drivers/platform/x86/intel_scu_ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 5b16d29c93d7..8d11d18701a4 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -325,7 +325,7 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, } err = intel_scu_ipc_check_status(scu); - if (!err && id == IPC_CMD_PCNTRL_R) { /* Read rbuf */ + if (!err) { /* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ memcpy_fromio(cbuf, scu->ipc_base + 0x90, 16); for (nc = 0; nc < count; nc++) From patchwork Mon Oct 21 13:34:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13844171 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 4097D198E69; Mon, 21 Oct 2024 13:37:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517833; cv=none; b=s1CPRwtdRw4CdpHyfsFuvFxvg1lWe08W3UhvDu4G/FxgPc6pzWHSsGxm+4bzQFuNL5hoJ1OcdIDq2w2C60FoMqu5LZt0eF3bUzLyddIB1u+DonVzyLwvMI2+piqUrTCJGiCn1YQBkbsEFZCC3k/cH11CHOSyi+QWfcXctLs6ofo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517833; c=relaxed/simple; bh=Ub2dWPjLXcZSostXR3uZOgyUm+npCtYNbqjkwt9Nj1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RxGP3b5R23uxqoY5+dtcw05cYNJ15ydFgPjGoG9Ri39Uus+DjK7agd0sPA5cESf14jW1pvL2seXv/3+DWBAH9CFDlbE8g231T+zncbp/iDwkQzBHFcvR2AtrR7CEon/EMdcrYkv4itAyjJWu2cDYKu8xbHSvh/Kj5lhpJbwNK7w= 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=JIocV2gF; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JIocV2gF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729517831; x=1761053831; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ub2dWPjLXcZSostXR3uZOgyUm+npCtYNbqjkwt9Nj1s=; b=JIocV2gFnk6/GVfU1BNt9zcYjptyp8xhxAOaP1l5T/yuAnYjAgTSvR8q b6NfSOIcK73WSTHvdmpPwR3FDa7i/7lAKWYasdpa3l2DqnTCgkgTZ1R8R KdgSGTBD5D3JziNBH2GxnAu1Yx5hZCOIoLv9tvEg4zneGpevDeUW22AOi qqvujuyetLPiNMbGmD4bo7y/OrBW/7ONi3kvdF7UYFCkXlRoDuDfLNRBN tNzB5uze9jyL+1PMwK9AxgRaiULg+3TQpzmYsEmw02qhqyo8GYMsqDLDZ Wt7/Ki6N/BugRx6883vfwKrv0TbgujGPvALN5uIIt7rJILst3Fx8VRgte A==; X-CSE-ConnectionGUID: Lw2RZtxZQi6hpDySu+P/wQ== X-CSE-MsgGUID: rgmgpv39SK27dMMP4/2IHQ== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29210966" X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="29210966" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 06:37:10 -0700 X-CSE-ConnectionGUID: khsTC9uvTVipV93fflK3SA== X-CSE-MsgGUID: E98V/QsnSUmNIef8oq4kvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="83544886" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 21 Oct 2024 06:37:08 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5217C35B; Mon, 21 Oct 2024 16:37:07 +0300 (EEST) From: Andy Shevchenko To: Mika Westerberg , Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v3 2/5] platform/x86: intel_scu_ipc: Replace workaround by 32-bit IO Date: Mon, 21 Oct 2024 16:34:30 +0300 Message-ID: <20241021133705.2933464-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> References: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The theory is that the so called workaround in pwr_reg_rdwr() is the actual reader of the data in 32-bit chunks. For some reason the 8-bit IO won't fail after that. Replace the workaround by using 32-bit IO explicitly and then memcpy() as much data as was requested by the user. The same approach is already in use in intel_scu_ipc_dev_command_with_size(). Tested-by: Ferry Toth Acked-by: Mika Westerberg Signed-off-by: Andy Shevchenko --- drivers/platform/x86/intel_scu_ipc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 8d11d18701a4..290b38627542 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -217,12 +217,6 @@ static inline u8 ipc_read_status(struct intel_scu_ipc_dev *scu) return __raw_readl(scu->ipc_base + IPC_STATUS); } -/* Read ipc byte data */ -static inline u8 ipc_data_readb(struct intel_scu_ipc_dev *scu, u32 offset) -{ - return readb(scu->ipc_base + IPC_READ_BUFFER + offset); -} - /* Read ipc u32 data */ static inline u32 ipc_data_readl(struct intel_scu_ipc_dev *scu, u32 offset) { @@ -326,10 +320,9 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, err = intel_scu_ipc_check_status(scu); if (!err) { /* Read rbuf */ - /* Workaround: values are read as 0 without memcpy_fromio */ - memcpy_fromio(cbuf, scu->ipc_base + 0x90, 16); - for (nc = 0; nc < count; nc++) - data[nc] = ipc_data_readb(scu, nc); + for (nc = 0, offset = 0; nc < 4; nc++, offset += 4) + wbuf[nc] = ipc_data_readl(scu, offset); + memcpy(data, wbuf, count); } mutex_unlock(&ipclock); return err; From patchwork Mon Oct 21 13:34:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13844173 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 7C1D61EF923; Mon, 21 Oct 2024 13:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517835; cv=none; b=gh6N311bIWIt+Ij1xHtfXpQQhzSoIcpvWl/j6mhVYFoxh61GHTxOI9LX2RNf3eJliMbLQH/VbYZ5V14ssxcfyiEFXdVu6qT72izDX7HlUYB7hmbbTtWbOs0E7xUeHw5LAD5AXZM4vIxnlOiRe2/tiVerKLqikpyoyOIYNJdB0Gc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517835; c=relaxed/simple; bh=3MUQhfcoH/nVDWknWR7lxyKol5ZT85TjIh+n55UNxI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVHhfrcoVF+I/BR9ueh2Zfs/b1w1N/uLJHKly028mOAo2jf09428wW40tcIlqsFyGc0T2grs3QhpXdL5Trzk+6Q1IX7+8585Jw9PyLj1rDynKAPs6gHZUIuwSKIIkCt5q26D+9uPlEpSHrRCM4YyO+ibPBf3WhudFlrlp/F+7RQ= 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=Z0q+qn87; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z0q+qn87" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729517833; x=1761053833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3MUQhfcoH/nVDWknWR7lxyKol5ZT85TjIh+n55UNxI8=; b=Z0q+qn87ZE9PhAg+CeMukEkrrNPHpVgrBqZJy4TESj653tV2Nepn/ohn rVlYiMKNLsD9SnpnSJ7kYfarzqihBCvXZpBPTGNKbEubhTLHn0N8uLGHE K/ZJCa3SCevjym1mxzN/z1tVsQgs7IYvRrKApWKPsiiOQ0paBJm+JdlwS ap570DTDeDwp0L7nVIFcwTO0lzfkc/u+aaf0fZBsYrIdIBXkaHzK48hBU 0Wu8xPIxF/CRVmp9jI3NVPjz94ETr68dx/GTGngvPxADa0jYjudExs6iv tov7+QAWQEZtIF7RErNfiuXbuOfd+9aAUpvgakyi8gIUGZZhu6yXdal6t A==; X-CSE-ConnectionGUID: rtNzciWiQ4eH6FpCCA2+Xw== X-CSE-MsgGUID: CjsBjLeYQpWfHixrQxRK/g== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29210970" X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="29210970" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 06:37:10 -0700 X-CSE-ConnectionGUID: 0cwJbabsQVqhUF0xY3S2SA== X-CSE-MsgGUID: IlOKi4PtRAeUX2e4GS+hDQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="83544887" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 21 Oct 2024 06:37:08 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 60EE536B; Mon, 21 Oct 2024 16:37:07 +0300 (EEST) From: Andy Shevchenko To: Mika Westerberg , Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v3 3/5] platform/x86: intel_scu_ipc: Simplify code with cleanup helpers Date: Mon, 21 Oct 2024 16:34:31 +0300 Message-ID: <20241021133705.2933464-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> References: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use macros defined in linux/cleanup.h to automate resource lifetime control in the driver. The byproduct of this change is that the negative conditionals are swapped by positive ones that are being attached to the respective calls, hence the code uses the regular pattern, i.e. checking for the error first. Tested-by: Ferry Toth Acked-by: Mika Westerberg Signed-off-by: Andy Shevchenko --- drivers/platform/x86/intel_scu_ipc.c | 65 +++++++++++----------------- 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 290b38627542..9829d4145c58 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -13,6 +13,7 @@ * along with other APIs. */ +#include #include #include #include @@ -99,23 +100,21 @@ static struct class intel_scu_ipc_class = { */ struct intel_scu_ipc_dev *intel_scu_ipc_dev_get(void) { - struct intel_scu_ipc_dev *scu = NULL; + guard(mutex)(&ipclock); - mutex_lock(&ipclock); if (ipcdev) { get_device(&ipcdev->dev); /* * Prevent the IPC provider from being unloaded while it * is being used. */ - if (!try_module_get(ipcdev->owner)) - put_device(&ipcdev->dev); - else - scu = ipcdev; + if (try_module_get(ipcdev->owner)) + return ipcdev; + + put_device(&ipcdev->dev); } - mutex_unlock(&ipclock); - return scu; + return NULL; } EXPORT_SYMBOL_GPL(intel_scu_ipc_dev_get); @@ -289,12 +288,11 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, memset(cbuf, 0, sizeof(cbuf)); - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu = intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } for (nc = 0; nc < count; nc++, offset += 2) { cbuf[offset] = addr[nc]; @@ -324,7 +322,6 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, wbuf[nc] = ipc_data_readl(scu, offset); memcpy(data, wbuf, count); } - mutex_unlock(&ipclock); return err; } @@ -446,17 +443,15 @@ int intel_scu_ipc_dev_simple_command(struct intel_scu_ipc_dev *scu, int cmd, u32 cmdval; int err; - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu = intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } cmdval = sub << 12 | cmd; ipc_command(scu, cmdval); err = intel_scu_ipc_check_status(scu); - mutex_unlock(&ipclock); if (err) dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); return err; @@ -491,12 +486,11 @@ int intel_scu_ipc_dev_command_with_size(struct intel_scu_ipc_dev *scu, int cmd, if (inbuflen > 4 || outbuflen > 4) return -EINVAL; - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu = intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } memcpy(inbuf, in, inlen); for (i = 0; i < inbuflen; i++) @@ -515,7 +509,6 @@ int intel_scu_ipc_dev_command_with_size(struct intel_scu_ipc_dev *scu, int cmd, memcpy(out, outbuf, outlen); } - mutex_unlock(&ipclock); if (err) dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); return err; @@ -572,18 +565,15 @@ __intel_scu_ipc_register(struct device *parent, struct intel_scu_ipc_dev *scu; void __iomem *ipc_base; - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + /* We support only one IPC */ - if (ipcdev) { - err = -EBUSY; - goto err_unlock; - } + if (ipcdev) + return ERR_PTR(-EBUSY); scu = kzalloc(sizeof(*scu), GFP_KERNEL); - if (!scu) { - err = -ENOMEM; - goto err_unlock; - } + if (!scu) + return ERR_PTR(-ENOMEM); scu->owner = owner; scu->dev.parent = parent; @@ -621,13 +611,11 @@ __intel_scu_ipc_register(struct device *parent, err = device_register(&scu->dev); if (err) { put_device(&scu->dev); - goto err_unlock; + return ERR_PTR(err); } /* Assign device at last */ ipcdev = scu; - mutex_unlock(&ipclock); - return scu; err_unmap: @@ -636,9 +624,6 @@ __intel_scu_ipc_register(struct device *parent, release_mem_region(scu_data->mem.start, resource_size(&scu_data->mem)); err_free: kfree(scu); -err_unlock: - mutex_unlock(&ipclock); - return ERR_PTR(err); } EXPORT_SYMBOL_GPL(__intel_scu_ipc_register); @@ -652,12 +637,12 @@ EXPORT_SYMBOL_GPL(__intel_scu_ipc_register); */ void intel_scu_ipc_unregister(struct intel_scu_ipc_dev *scu) { - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + if (!WARN_ON(!ipcdev)) { ipcdev = NULL; device_unregister(&scu->dev); } - mutex_unlock(&ipclock); } EXPORT_SYMBOL_GPL(intel_scu_ipc_unregister); From patchwork Mon Oct 21 13:34:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13844175 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 5EC361F81B7; Mon, 21 Oct 2024 13:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517836; cv=none; b=b5oJwNqYYiZns83hBkWvV1pr1ZVUdTd5lOmZWRMPttpZNQtVcm5AIibNBoGL2XcYra0lfCmEZz+WFGT4wlAOxK2PH9Tsro2OT3WJZDf7Vb30AJu2NB40yoP88Y2WQNgCWgZBrYm8kv0X7S4nbbogT7LOn72OqqYH1csWGjU6+Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517836; c=relaxed/simple; bh=AkHhds51M/8sSSLir/oPbIB3XfHomKMWs2MteMbrEKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HPrV0bOVupYONOBlyWgxuvnClu1XdfUrt05/3BL/YUlDsoKsgOq3U4LeDTy1qfTMeIQu2IPNoJ/BknGxWv/6xSFjK6eRf6EsO4n1ksgkt9KIiphguEGK9ZcO+kyIqAWB3JgMr4bHwDr11R6TKqkBCvsyLHuQ6Q6gT2e0VQMWZy8= 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=HiGzNBB3; arc=none smtp.client-ip=192.198.163.15 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HiGzNBB3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729517834; x=1761053834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AkHhds51M/8sSSLir/oPbIB3XfHomKMWs2MteMbrEKM=; b=HiGzNBB3+UJecGytPEQ67eLUUmvVMFdNhEoDh/RXU7WfkRDvfXPGR4J7 UyNYlncc2IAeYWbUyDMo5r4QDCk5sxV6M/owq6hca0NnSDqK1krkscY9Q JXr7R2zjakO0UJn27agozC81u/XQ51M/W9E8I1KAJTP2uab4I2fyN2nXz 2G7a5n/uIuS65yj7ym75gd6RA+5BWnQZ4jtvmPg+VW1AQW/OeUnY+JDDU wl7MfZX+Jbn/QNG0ZwMf8gu98NE+DQW3bhVf+AnNzWJp3SS6S5EAvin7n x2DwoCX7DW9PNh6lR3aWVFIJg4MZIjRivJBAiZXgL8jwO/WsE+TG+DMqk w==; X-CSE-ConnectionGUID: 9Byjxli9TaC/8R5zyHE15A== X-CSE-MsgGUID: wN9XbajVRX6L6izHz8qjgw== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29119830" X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="29119830" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 06:37:11 -0700 X-CSE-ConnectionGUID: e2tgUy5FSFqfuLcdwjsRJw== X-CSE-MsgGUID: TpB8612dSN2hIy3MW6tVFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="79931179" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 21 Oct 2024 06:37:09 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6B5F24FD; Mon, 21 Oct 2024 16:37:07 +0300 (EEST) From: Andy Shevchenko To: Mika Westerberg , Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v3 4/5] platform/x86: intel_scu_ipc: Convert to check for errors first Date: Mon, 21 Oct 2024 16:34:32 +0300 Message-ID: <20241021133705.2933464-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> References: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert to use usual pattern, i.e. check for errors first. This makes code less indented and easier to read after all. Tested-by: Ferry Toth Acked-by: Mika Westerberg Signed-off-by: Andy Shevchenko --- drivers/platform/x86/intel_scu_ipc.c | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 9829d4145c58..2d25a0a86143 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -317,12 +317,15 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, } err = intel_scu_ipc_check_status(scu); - if (!err) { /* Read rbuf */ - for (nc = 0, offset = 0; nc < 4; nc++, offset += 4) - wbuf[nc] = ipc_data_readl(scu, offset); - memcpy(data, wbuf, count); - } - return err; + if (err) + return err; + + /* Read rbuf */ + for (nc = 0, offset = 0; nc < 4; nc++, offset += 4) + wbuf[nc] = ipc_data_readl(scu, offset); + memcpy(data, wbuf, count); + + return 0; } /** @@ -480,7 +483,7 @@ int intel_scu_ipc_dev_command_with_size(struct intel_scu_ipc_dev *scu, int cmd, { size_t outbuflen = DIV_ROUND_UP(outlen, sizeof(u32)); size_t inbuflen = DIV_ROUND_UP(inlen, sizeof(u32)); - u32 cmdval, inbuf[4] = {}; + u32 cmdval, inbuf[4] = {}, outbuf[4] = {}; int i, err; if (inbuflen > 4 || outbuflen > 4) @@ -499,19 +502,17 @@ int intel_scu_ipc_dev_command_with_size(struct intel_scu_ipc_dev *scu, int cmd, cmdval = (size << 16) | (sub << 12) | cmd; ipc_command(scu, cmdval); err = intel_scu_ipc_check_status(scu); - - if (!err) { - u32 outbuf[4] = {}; - - for (i = 0; i < outbuflen; i++) - outbuf[i] = ipc_data_readl(scu, 4 * i); - - memcpy(out, outbuf, outlen); + if (err) { + dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); + return err; } - if (err) - dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); - return err; + for (i = 0; i < outbuflen; i++) + outbuf[i] = ipc_data_readl(scu, 4 * i); + + memcpy(out, outbuf, outlen); + + return 0; } EXPORT_SYMBOL(intel_scu_ipc_dev_command_with_size); From patchwork Mon Oct 21 13:34:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13844176 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 5EF9C1F81BA; Mon, 21 Oct 2024 13:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517837; cv=none; b=CgKKq0pQSPMwbyTyL4zLUmxo0YcCuWWgROc7ULIfjS3Sfn9B+oZGLyknOlzm9AqIcmi6sjGTlUAnVAXu+pk9g2B5D3GL/h+DndgRQ0c6+8woNTQB4Eh4ifxtBb+f3sloLW7DsC51t2KypePgk0w9EkhypMHXS2tyUk+Z6fO0LA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729517837; c=relaxed/simple; bh=wo7aF5ZvUXZQ0PELU9vp3n7/5nCTYh0tRuOckfMDusQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YKwos7CK0uIR/6fC3yLAKRrzyzVTkdddTMRxGfZchBMXZin/UK5/YVkv8SNqXAgSTy/eFdCi7R2Va4Q4u6IImTqNLPbQXACPoO1xV890GXm/MNQ55IX3FxoJXLX6EuWHY7nEZKS5nM/jKSVJqcE2j3jx6llcPYvBewbcetXMcV8= 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=l9Xg79HQ; arc=none smtp.client-ip=192.198.163.14 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l9Xg79HQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729517834; x=1761053834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wo7aF5ZvUXZQ0PELU9vp3n7/5nCTYh0tRuOckfMDusQ=; b=l9Xg79HQia0ly/SPmz3vUU129Jsu1Gckisbj8nc+4g/Ve2bYAZHSj2WZ ZMDuUpD7MELGovi0d2yfxaagjBwUj0MH6oY1+zrdvmPZ+pnGgsMpg+zX1 qZzMJCFe9TjBU9e9yeDHeVxyg2QkKN5ElO6iKmvlzjZNn5oYfmsmDuIRR t265wZHxUhEyzSHN9Xc+tNXpgDBwLHRH3J81UBQYQ9nk+t/DbyB3s+XuL r/4nFsh0OBG/T7i1DdGTguUGmL/dUNXc+zBoyPZeKO+Ddl8628SBCsW6g 2hWi/0/uH2ylVoi2pAgj+1ObRm4rMWrjDhCwnyB9sCA/sFa9Nkld3b5k+ Q==; X-CSE-ConnectionGUID: dKQzLTUCSUGen+IO16lSKA== X-CSE-MsgGUID: V1vrB/dDQ/ONMXWS7vM13w== X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="29210975" X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="29210975" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 06:37:13 -0700 X-CSE-ConnectionGUID: D6WEVOM3RuyaFstWGXlQIg== X-CSE-MsgGUID: yh6mnUuiQMeTFwoSqLUhsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,221,1725346800"; d="scan'208";a="83544909" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 21 Oct 2024 06:37:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7693C299; Mon, 21 Oct 2024 16:37:07 +0300 (EEST) From: Andy Shevchenko To: Mika Westerberg , Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v3 5/5] platform/x86: intel_scu_ipc: Save a copy of the entire struct intel_scu_ipc_data Date: Mon, 21 Oct 2024 16:34:33 +0300 Message-ID: <20241021133705.2933464-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> References: <20241021133705.2933464-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Save a copy of the entire struct intel_scu_ipc_data for easier maintenance in case of expanding (adding new members become simpler). Acked-by: Mika Westerberg Tested-by: Ferry Toth Signed-off-by: Andy Shevchenko --- drivers/platform/x86/intel_scu_ipc.c | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 2d25a0a86143..3acf6149a9ec 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -57,11 +57,11 @@ struct intel_scu_ipc_dev { struct device dev; - struct resource mem; struct module *owner; - int irq; void __iomem *ipc_base; struct completion cmd_complete; + + struct intel_scu_ipc_data data; }; #define IPC_STATUS 0x04 @@ -255,7 +255,7 @@ static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev *scu) static int intel_scu_ipc_check_status(struct intel_scu_ipc_dev *scu) { - return scu->irq > 0 ? ipc_wait_for_interrupt(scu) : busy_loop(scu); + return scu->data.irq > 0 ? ipc_wait_for_interrupt(scu) : busy_loop(scu); } static struct intel_scu_ipc_dev *intel_scu_ipc_get(struct intel_scu_ipc_dev *scu) @@ -536,13 +536,13 @@ static irqreturn_t ioc(int irq, void *dev_id) static void intel_scu_ipc_release(struct device *dev) { - struct intel_scu_ipc_dev *scu; + struct intel_scu_ipc_dev *scu = container_of(dev, struct intel_scu_ipc_dev, dev); + struct intel_scu_ipc_data *data = &scu->data; - scu = container_of(dev, struct intel_scu_ipc_dev, dev); - if (scu->irq > 0) - free_irq(scu->irq, scu); + if (data->irq > 0) + free_irq(data->irq, scu); iounmap(scu->ipc_base); - release_mem_region(scu->mem.start, resource_size(&scu->mem)); + release_mem_region(data->mem.start, resource_size(&data->mem)); kfree(scu); } @@ -563,6 +563,7 @@ __intel_scu_ipc_register(struct device *parent, struct module *owner) { int err; + struct intel_scu_ipc_data *data; struct intel_scu_ipc_dev *scu; void __iomem *ipc_base; @@ -581,25 +582,25 @@ __intel_scu_ipc_register(struct device *parent, scu->dev.class = &intel_scu_ipc_class; scu->dev.release = intel_scu_ipc_release; - if (!request_mem_region(scu_data->mem.start, resource_size(&scu_data->mem), - "intel_scu_ipc")) { + memcpy(&scu->data, scu_data, sizeof(scu->data)); + data = &scu->data; + + if (!request_mem_region(data->mem.start, resource_size(&data->mem), "intel_scu_ipc")) { err = -EBUSY; goto err_free; } - ipc_base = ioremap(scu_data->mem.start, resource_size(&scu_data->mem)); + ipc_base = ioremap(data->mem.start, resource_size(&data->mem)); if (!ipc_base) { err = -ENOMEM; goto err_release; } scu->ipc_base = ipc_base; - scu->mem = scu_data->mem; - scu->irq = scu_data->irq; init_completion(&scu->cmd_complete); - if (scu->irq > 0) { - err = request_irq(scu->irq, ioc, 0, "intel_scu_ipc", scu); + if (data->irq > 0) { + err = request_irq(data->irq, ioc, 0, "intel_scu_ipc", scu); if (err) goto err_unmap; } @@ -622,7 +623,7 @@ __intel_scu_ipc_register(struct device *parent, err_unmap: iounmap(ipc_base); err_release: - release_mem_region(scu_data->mem.start, resource_size(&scu_data->mem)); + release_mem_region(data->mem.start, resource_size(&data->mem)); err_free: kfree(scu); return ERR_PTR(err);