From patchwork Mon Oct 21 08:38:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13843726 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 2F4F41E2305; Mon, 21 Oct 2024 08:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500062; cv=none; b=eTA3S9Zb3VJgAVdOX7HOHSZBGbGKvOKwhQ8/f9kPXD+PE8CkvhK670H4PrCQ0v2KyFyLFRPoM61ly+eh2FcSCNhQYTEKgil3pr2XuOVshojPz6jsRt90hvJ5qf0bA3EMpo1swgITB+hP4Nsro1SpJECZ7Om72x4OrS5xQomNMAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500062; c=relaxed/simple; bh=xrr2Tv8Prfj751SqQj7aeRu7DO0u4LIk/A0YJQFm5So=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jDIWyE1eS6exwgWHbb8NZ0vWpHUCxAzU4K0hHniKOWQEX8qGlkjPpBuHTKNZ5z++oHZGb5hKkT2hYfRYhDGMTIlKTnG3CUpFbSRZqEXz1GgGtxkpZmCYQbEcyWiAVNfahjedQhkuWJ9talmETj2PBeOTOtEJ3KapV/yPAUvVtwc= 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=YLF9/g6j; arc=none smtp.client-ip=198.175.65.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="YLF9/g6j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500062; x=1761036062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xrr2Tv8Prfj751SqQj7aeRu7DO0u4LIk/A0YJQFm5So=; b=YLF9/g6jILXA8ASOlMJnZrRgOBgQk6Mg/6DkCdEuoqfdnHmjLW3doMXz OQSoY/bZCKGgsjqVOPCzzTLMDhXXZiM3Zr4YJ6kaLDQHS2Q+XsMDnoyW5 YLk5FZh6jwoKSN5+tFe5p+4E7UvLyx/n1KitNOQ+zZhnMtPHjWT9q2wbJ WpZy4pM9Z30dTPM+XxqYhX8pkNxkP+o+1tKWyf/sElVqtcgL6+O39S5NP tJneEaVw0/r2tp+4zlT7qM33sxXinKjU+UOahMRkntv5sFDl+9OHfiu8I eV0SJnI20Pma3n9mNk8QYGqqbSggBh8wjOzePoBH3EB8T5aJ7UbZ0T+0Z w==; X-CSE-ConnectionGUID: VMtG4tLGSuSg+QliFrndSA== X-CSE-MsgGUID: S1s0wD1ZTTCNO1fvaVcSBA== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32778772" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32778772" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:41:01 -0700 X-CSE-ConnectionGUID: JtwHjyYTTYy/RijISxA6BQ== X-CSE-MsgGUID: Q2tD/Z3PQESKEIzH/FrH5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="84250915" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 21 Oct 2024 01:40:58 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 417341E0; Mon, 21 Oct 2024 11:40:57 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Mika Westerberg , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v2 1/3] platform/x86: intel_scu_ipc: Replace workaround by 32-bit IO Date: Mon, 21 Oct 2024 11:38:51 +0300 Message-ID: <20241021084053.2443545-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021084053.2443545-1-andriy.shevchenko@linux.intel.com> References: <20241021084053.2443545-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 Signed-off-by: Andy Shevchenko Acked-by: Mika Westerberg --- drivers/platform/x86/intel_scu_ipc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 5b16d29c93d7..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) { @@ -325,11 +319,10 @@ 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 */ - /* 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); + 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); } mutex_unlock(&ipclock); return err; From patchwork Mon Oct 21 08:38:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13843727 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 A00531E231E; Mon, 21 Oct 2024 08:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500063; cv=none; b=Xn3oEsVJGJNiuCcfYb0LGvB68SBjvsb30QxrnfzMGv4gCiyxBBLElQZTv2B0SEUb54BxRyxbndJ3cTwNowzQiHDrJFEIKi4wtlz9YOUDWebyXgJ5IWDeGt3tTS+JcnAsa7efomko+DRY4+N8T6MKduZq7A82sOKNjHSEB/odYQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500063; c=relaxed/simple; bh=Uw/SIwF2245678j94ASDHZGPpwER4WoN8ongnmaFp5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PeyTVWZdEPB4mn0ULyKie8Sc40dItPi3J5CZQvDMnO1sTG7EcyyBReOgG2vsIeN+XyuDKD4vw7/43VI0d8yZ0qHbvHEo6Tg5CaFsTFlRSP58VayVZCN90ld1vGRuWn63lANdt3UaVivdQrWZvMjGP5xKUwjPzRa24Vp6S2IqH7Y= 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=iRUhjDrS; arc=none smtp.client-ip=192.198.163.18 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="iRUhjDrS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500061; x=1761036061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uw/SIwF2245678j94ASDHZGPpwER4WoN8ongnmaFp5M=; b=iRUhjDrSoeEcRmZct7YkPoU5C9tiWxi1Eo3icSX5U+pSh7tnN99U3XG9 vP8NsVHGKpdjyMAPviYgXAMzW40v5qPydZBB/QSReNd8OFLfZn9qT7O5M t3w8E9+Fbo+Ovb1FUElLXBt5ckNd5PsmzU58km2uL6jJsoE7GaUqmLmHW FcK3jbxPqKYJ9QQ8KVplNam0gY5s4iHPbYZjujsk7mUjJAnYp4nN0encB nxFS906+5AgUwLpQKlZFn/brPGBoQnG7MLaDu3fL/Rtrug4LDYv6eaxM3 tsDf0v6vXLcWwAEZIAz984kXjCfTqFNYv+HCwwxsNk5bvLaRRiRHwrfRp A==; X-CSE-ConnectionGUID: V4akWeIDQUmxE8jIKldrag== X-CSE-MsgGUID: ssMcxp0HQeKzginFxi41nQ== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="28407186" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="28407186" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:41:01 -0700 X-CSE-ConnectionGUID: y9Hez4PrTYCisd5KBLG3EA== X-CSE-MsgGUID: wuMUai4+QDCuOOBBwDGNNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="110299464" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 21 Oct 2024 01:40:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D1096299; Mon, 21 Oct 2024 11:40:57 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Mika Westerberg , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v2 2/3] platform/x86: intel_scu_ipc: Simplify code with cleanup helpers Date: Mon, 21 Oct 2024 11:38:52 +0300 Message-ID: <20241021084053.2443545-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021084053.2443545-1-andriy.shevchenko@linux.intel.com> References: <20241021084053.2443545-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 Signed-off-by: Andy Shevchenko Acked-by: Mika Westerberg --- drivers/platform/x86/intel_scu_ipc.c | 101 ++++++++++++--------------- 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 290b38627542..3a1584ed7db8 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]; @@ -319,13 +317,14 @@ 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); - } - mutex_unlock(&ipclock); - return err; + if (err) + return err; + + for (nc = 0, offset = 0; nc < 4; nc++, offset += 4) + wbuf[nc] = ipc_data_readl(scu, offset); + memcpy(data, wbuf, count); + + return 0; } /** @@ -446,17 +445,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; @@ -485,18 +482,17 @@ 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) 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++) @@ -505,20 +501,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; } - mutex_unlock(&ipclock); - 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); @@ -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 08:38:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13843728 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 14B0B1E2600; Mon, 21 Oct 2024 08:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500064; cv=none; b=eMFv0WE2jR3/yQOAoWufuOrp1134YN9xjLitFIued35nVy+1JmyjZ+fbTxhySMdim3fo0Xk5DYnU8yDvC98SzvIBljq7tYamBjTr8yIkko1flAt39Unr0PWmsc3EyKX3ShHcxLGxUe66MEvu1gYj3rF31qlYIBzms+M7l0ZWmKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729500064; c=relaxed/simple; bh=3vdjcqeukS/8Km0duETYAbLAA9L9ljye3GpgyOjOLRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uL6+lG6Q/6IzcaiGV6AkXdESyz8PUZ4XiHc5nDBvV+L4FWpFkeUkTjJkM/ecsuKw2ZXk+m/7EEBDN4uggVOZFwUQ7Im6pqLfWG9f436z14ts7VyQ0L2TwoMEbcAreY8KKHESyHx3DbBY6YHoTe4KYfmChJF1JRItswebv/O+5Mk= 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=Fh9mRi04; arc=none smtp.client-ip=198.175.65.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="Fh9mRi04" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729500063; x=1761036063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3vdjcqeukS/8Km0duETYAbLAA9L9ljye3GpgyOjOLRk=; b=Fh9mRi04VBOBwqHWtOGUkd6Ogj/sPYyMTqg7TFiKlc34VUy7jG2vnKaS +fwS6nKuVq2iTRxf5UxUUx0KLmE69AkezWR9jgzn44gb1Zi+31yr5Ya1U 01dHtjPkgafK3cZdGhVp8654orU2vfzMnAi9AVQj6zN13XyQCLUQ1ym/g aR1DbrgBZ7WKyWgC63X7tzJsvS8IAVdVaUm4RMGa49p6JsZlrghnjJMr0 JHXNV+tW8/9n+wiO4JgnuJ/rpMKgX0/l2CLdTm0nVuSiE4IJ4Ucld9TOO BnptAwj+CF5nDKKKX4VnvRqA6raWAOFIabajSE+bVV/DkK9CcIEpcfArD Q==; X-CSE-ConnectionGUID: srf7yLliQRKVMtiPq5wo6g== X-CSE-MsgGUID: DHnCcy0UR0GBdgV6V2grEQ== X-IronPort-AV: E=McAfee;i="6700,10204,11231"; a="32778775" X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="32778775" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2024 01:41:01 -0700 X-CSE-ConnectionGUID: 2zCiUT2sT/K/JgfOen6olA== X-CSE-MsgGUID: KHi4TWIvQICfifSP7huU9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,220,1725346800"; d="scan'208";a="84250933" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 21 Oct 2024 01:40:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 32C6935B; Mon, 21 Oct 2024 11:40:58 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Mika Westerberg , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v2 3/3] platform/x86: intel_scu_ipc: Save a copy of the entire struct intel_scu_ipc_data Date: Mon, 21 Oct 2024 11:38:53 +0300 Message-ID: <20241021084053.2443545-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241021084053.2443545-1-andriy.shevchenko@linux.intel.com> References: <20241021084053.2443545-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 3a1584ed7db8..f7db90a14afd 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) @@ -535,13 +535,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); } @@ -562,6 +562,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; @@ -580,25 +581,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; } @@ -621,7 +622,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);