From nobody Tue Nov 26 17:16:39 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 76F81206059; Wed, 16 Oct 2024 11:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079439; cv=none; b=hMliwM8ceBTlDPQxZPcFwo6R79lv6iMUBPHCcufPIkX7nV7M/DnvS9rsOUfXkNTInMKdvHwqRWjAGb9o1W+/FWuK1cVcbXc7gfl8vpnRFcR+b+jbeMBCyQMtDR84QCQcu6JLScGr1Mj4kCZUZWv7605hPy3cyhOG4QQMoBK5ciI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079439; c=relaxed/simple; bh=v1on7WxTr15BmwhGpIyMY+hnj/xt4RZUht8X+2KbXaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZroahIyADLjPT3t3EwA2zi1O3ssgOgTYJlcqiLvtCekTEJO43LpvepSbbAk2CA7I++yCAEqu+ji39dA9hnAfVcQout0utt2077wcLglW995Jy/UMSXNOxvKPcN2jxw/9M+K7VTsmm+GMxHV+oXFSZt9qMGCx24lK0mYOVyVO8Hg= 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=S/7AqyRj; arc=none smtp.client-ip=198.175.65.20 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="S/7AqyRj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729079439; x=1760615439; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v1on7WxTr15BmwhGpIyMY+hnj/xt4RZUht8X+2KbXaY=; b=S/7AqyRjCD6wLlCkgkPvGV5WWDtfOPVfZAPXayf5jWNRzc3oNjQnshZN ZQva85hN+OOGtDGf3r7lkR8HhZRrg8rURjcYFjUYqfkrrHtKwOgBUh3M2 df387cxhoXNbXtOM+zJMNlQu5ryCvoNjGM0tt7EGG4uTaI7ox69U3LgLU BAJnweUPlNrgjAlEgIseEMzulPpXDu6RkqgkpT2wYEjoFtjguc1gObXTu BZAHCYG90rJ9fPy0VMiX+YDd1tXzOzihoM7dJq8maHGkCrtYtDQvcODW8 acCymtVDxDDk7m8ft1ae2y/fHVgEe6virDyZBwdH3g4BXZVG1sWlj5983 A==; X-CSE-ConnectionGUID: GCAwVjo3TtqmnVrGB7o0FA== X-CSE-MsgGUID: rPlaU5BRTLCJb4REZs88Lg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="28306990" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="28306990" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 04:50:38 -0700 X-CSE-ConnectionGUID: HZxH4/4NSnamAqUioHzpvw== X-CSE-MsgGUID: rREieHrfRymjLqCqutXcSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78548799" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 04:50:36 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id BD9C1159; Wed, 16 Oct 2024 14:50:34 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Mika Westerberg , Andy Shevchenko , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v1 1/3] platform/x86: intel_scu_ipc: Replace workaround by 32-bit IO Date: Wed, 16 Oct 2024 14:48:24 +0300 Message-ID: <20241016115033.858574-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241016115033.858574-1-andriy.shevchenko@linux.intel.com> References: <20241016115033.858574-1-andriy.shevchenko@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: quoted-printable Content-Type: text/plain; charset="utf-8" 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(). Signed-off-by: Andy Shevchenko Tested-by: Ferry Toth (Intel Edison-Arduino) --- 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/in= tel_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); } =20 -/* 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, } =20 err =3D intel_scu_ipc_check_status(scu); - if (!err && id =3D=3D 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 =3D 0; nc < count; nc++) - data[nc] =3D ipc_data_readb(scu, nc); + if (!err) { /* Read rbuf */ + for (nc =3D 0, offset =3D 0; nc < 4; nc++, offset +=3D 4) + wbuf[nc] =3D ipc_data_readl(scu, offset); + memcpy(data, wbuf, count); } mutex_unlock(&ipclock); return err; --=20 2.43.0.rc1.1336.g36b5255a03ac From nobody Tue Nov 26 17:16:39 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 09F6D2076BA; Wed, 16 Oct 2024 11:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079441; cv=none; b=sGsP60ntubEzkzzN+oJCHy/scL+1dh2h3mcpponvKympa3/nClGVKafWe0XktQHKvAGk0KA7BBviJOQk8xghCkbWGIR+4MEkdjWrz68ETWcGDPYHZWQnYG3jGAMRBfhZHKgxFFLSVgHR9S8qjQ7AFbEdcjxfv1BWAnP9s3VQrtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079441; c=relaxed/simple; bh=aKOY49hb3WRsd+qIY7bifniPUi/YlDVXp2RWxXuIWr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o1NDAxLlPmNQSUfhtwjrHrmck4O/6weexyHTC01HSvQhpGCOPqOLbkfS1VucgVXDjIuTQvrmTkhjkJVC2StYIYGLGpd97JABfqg9ls6xB7FPl6Qq4i8HH8/+b/+vznjstfNJY7upP01ro4DwO1gyRV94oXAhMqkYMdNK4s3jWN8= 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=PARMvzzc; arc=none smtp.client-ip=198.175.65.20 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="PARMvzzc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729079440; x=1760615440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aKOY49hb3WRsd+qIY7bifniPUi/YlDVXp2RWxXuIWr8=; b=PARMvzzcLUBaa+UVR/B0IJe3U8r93cf1R1HX40UsfQ6tAHfd2CDP++Ze nnPrFwG/GtBSgtJTnsX9JvZNfxakb+cUuuYiaG3wQB6/eO/fOYpNqDcdV 8s7reUmOYF+f+cPEFCNBOMmB265H/lg03gwbyKPAa8r9RF5U/bgfgjr7f 4kNhpPBqQ+zw9D9EVotGhlM852pVMQg278YwJh/UKT/HipnhASAE44Kk4 NyQw+eJaUgWjveT7uDhVoWNvUADye5zUMhMS05uMFWZC4I33ptVIpmdWm 5+XVUOUrwNlRm9IemFOAvb7VsemAtR4YRk5oCkPN+mB34HGG71n9atbF5 g==; X-CSE-ConnectionGUID: mxHJXBxjSCWIfZjzeKRsyQ== X-CSE-MsgGUID: v1zDnfFeQB+krDF76upwaQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="28306994" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="28306994" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 04:50:38 -0700 X-CSE-ConnectionGUID: 3hUcKA05Rn+k7hl9ugj83w== X-CSE-MsgGUID: qbR+k8R6Tmqu/RpciFpBhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="78548800" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa010.fm.intel.com with ESMTP; 16 Oct 2024 04:50:36 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C7BB91AC; Wed, 16 Oct 2024 14:50:34 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Mika Westerberg , Andy Shevchenko , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v1 2/3] platform/x86: intel_scu_ipc: Simplify code with cleanup helpers Date: Wed, 16 Oct 2024 14:48:25 +0300 Message-ID: <20241016115033.858574-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241016115033.858574-1-andriy.shevchenko@linux.intel.com> References: <20241016115033.858574-1-andriy.shevchenko@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: quoted-printable Content-Type: text/plain; charset="utf-8" Use macros defined in linux/cleanup.h to automate resource lifetime control in the driver. Signed-off-by: Andy Shevchenko Tested-by: Ferry Toth (Intel Edison-Arduino) --- drivers/platform/x86/intel_scu_ipc.c | 102 ++++++++++++--------------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/in= tel_scu_ipc.c index 290b38627542..ffb0a2524388 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. */ =20 +#include #include #include #include @@ -99,23 +100,22 @@ static struct class intel_scu_ipc_class =3D { */ struct intel_scu_ipc_dev *intel_scu_ipc_dev_get(void) { - struct intel_scu_ipc_dev *scu =3D NULL; + guard(mutex)(&ipclock); =20 - 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 =3D ipcdev; + if (try_module_get(ipcdev->owner)) + return ipcdev; + + put_device(&ipcdev->dev); } =20 - mutex_unlock(&ipclock); - return scu; + return NULL; } EXPORT_SYMBOL_GPL(intel_scu_ipc_dev_get); =20 @@ -289,12 +289,11 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu= , u16 *addr, u8 *data, =20 memset(cbuf, 0, sizeof(cbuf)); =20 - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu =3D intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } =20 for (nc =3D 0; nc < count; nc++, offset +=3D 2) { cbuf[offset] =3D addr[nc]; @@ -319,13 +318,14 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu= , u16 *addr, u8 *data, } =20 err =3D intel_scu_ipc_check_status(scu); - if (!err) { /* Read rbuf */ - for (nc =3D 0, offset =3D 0; nc < 4; nc++, offset +=3D 4) - wbuf[nc] =3D ipc_data_readl(scu, offset); - memcpy(data, wbuf, count); - } - mutex_unlock(&ipclock); - return err; + if (err) + return err; + + for (nc =3D 0, offset =3D 0; nc < 4; nc++, offset +=3D 4) + wbuf[nc] =3D ipc_data_readl(scu, offset); + memcpy(data, wbuf, count); + + return 0; } =20 /** @@ -446,17 +446,15 @@ int intel_scu_ipc_dev_simple_command(struct intel_scu= _ipc_dev *scu, int cmd, u32 cmdval; int err; =20 - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu =3D intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } =20 cmdval =3D sub << 12 | cmd; ipc_command(scu, cmdval); err =3D 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 +483,17 @@ int intel_scu_ipc_dev_command_with_size(struct intel_= scu_ipc_dev *scu, int cmd, { size_t outbuflen =3D DIV_ROUND_UP(outlen, sizeof(u32)); size_t inbuflen =3D DIV_ROUND_UP(inlen, sizeof(u32)); - u32 cmdval, inbuf[4] =3D {}; + u32 cmdval, inbuf[4] =3D {}, outbuf[4] =3D {}; int i, err; =20 if (inbuflen > 4 || outbuflen > 4) return -EINVAL; =20 - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + scu =3D intel_scu_ipc_get(scu); - if (IS_ERR(scu)) { - mutex_unlock(&ipclock); + if (IS_ERR(scu)) return PTR_ERR(scu); - } =20 memcpy(inbuf, in, inlen); for (i =3D 0; i < inbuflen; i++) @@ -505,20 +502,17 @@ int intel_scu_ipc_dev_command_with_size(struct intel_= scu_ipc_dev *scu, int cmd, cmdval =3D (size << 16) | (sub << 12) | cmd; ipc_command(scu, cmdval); err =3D intel_scu_ipc_check_status(scu); - - if (!err) { - u32 outbuf[4] =3D {}; - - for (i =3D 0; i < outbuflen; i++) - outbuf[i] =3D 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; } =20 - mutex_unlock(&ipclock); - if (err) - dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); - return err; + for (i =3D 0; i < outbuflen; i++) + outbuf[i] =3D ipc_data_readl(scu, 4 * i); + + memcpy(out, outbuf, outlen); + + return 0; } EXPORT_SYMBOL(intel_scu_ipc_dev_command_with_size); =20 @@ -572,18 +566,15 @@ __intel_scu_ipc_register(struct device *parent, struct intel_scu_ipc_dev *scu; void __iomem *ipc_base; =20 - mutex_lock(&ipclock); + guard(mutex)(&ipclock); + /* We support only one IPC */ - if (ipcdev) { - err =3D -EBUSY; - goto err_unlock; - } + if (ipcdev) + return ERR_PTR(-EBUSY); =20 scu =3D kzalloc(sizeof(*scu), GFP_KERNEL); - if (!scu) { - err =3D -ENOMEM; - goto err_unlock; - } + if (!scu) + return ERR_PTR(-ENOMEM); =20 scu->owner =3D owner; scu->dev.parent =3D parent; @@ -621,13 +612,11 @@ __intel_scu_ipc_register(struct device *parent, err =3D device_register(&scu->dev); if (err) { put_device(&scu->dev); - goto err_unlock; + return ERR_PTR(err); } =20 /* Assign device at last */ ipcdev =3D scu; - mutex_unlock(&ipclock); - return scu; =20 err_unmap: @@ -636,9 +625,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 +638,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 =3D NULL; device_unregister(&scu->dev); } - mutex_unlock(&ipclock); } EXPORT_SYMBOL_GPL(intel_scu_ipc_unregister); =20 --=20 2.43.0.rc1.1336.g36b5255a03ac From nobody Tue Nov 26 17:16:39 2024 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 46DB2207A1E; Wed, 16 Oct 2024 11:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079442; cv=none; b=oB7n/gzPrBYdyvUz7blxNrV3k9/9PbW/jdybJQTyyt7uqwwnuqc/enc3noWKF+DXW8T1kAixkNK0nI4dVwOdnaJM/KKsO/gIFQeXaAS2I7MXQa2rnk5jfbaFSjgJOw9Tf2JD3C7kwChD2RM1k3tRB2LC3KCS9NSIJBiR1gkfv0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729079442; c=relaxed/simple; bh=0u2TnzL2XRFhwUYIzbKAOkJS2xr/yU0W8afUZRGNPaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZoU5AFTMLyNtEktjlkZSLVNymB5xIp8odnpKWUutoX8az+1BspX2a/is7z6d8AIlN2uEJz8bBMXAIJ/34amx8a/kRtSdDfAhaEp+a+81oVaTgUjDDuVPwoZ6FN1q3yuyzLlsDamLh2DEJcxMTwDjUda/Xj74r7gRXGfgejnKV8E= 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=APiEVBuf; arc=none smtp.client-ip=198.175.65.11 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="APiEVBuf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729079441; x=1760615441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0u2TnzL2XRFhwUYIzbKAOkJS2xr/yU0W8afUZRGNPaE=; b=APiEVBufGwnyTWDS4VHCPk3B4tS88INovbDQm2g07rerbPS3AcJ2OPGq 3Uw6Xkb4ttPk2X4GsqPcBHgy/kP+U+AozM/ZZOpeEFSl96i0zB9//9cH2 vxPFB5J9Wdo/jAyR6u6JuMpmSEM5nM5qgdEO+46IXPfLEjCzkcmW75MO8 JiGU0ILTKuaQJj3tSvkMwnR4WT1upOF6hkgq8/PagiOvXPDzcYMyHRX/b K1icanqJ+gdWJfk+XAJRPsX5DsGMHFwMhulywYUilaHsQnhutSRKPq5wV yFuE9wxJT1S1zZLntyHmGPeAJwwnrLb7Q8RRHa5a6hpoMX7BvEsQ7TVJP w==; X-CSE-ConnectionGUID: xrOqo2lzTrCqDZ6+RzczqQ== X-CSE-MsgGUID: qm6H+QmBQEeud9u3Ir+mlQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="39069928" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="39069928" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 04:50:38 -0700 X-CSE-ConnectionGUID: tzkZgP1QT3qv7viCmFrrcw== X-CSE-MsgGUID: VxbUQNe0T56sbYSGfKY7wA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,207,1725346800"; d="scan'208";a="82974933" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa005.jf.intel.com with ESMTP; 16 Oct 2024 04:50:36 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D20C01C4; Wed, 16 Oct 2024 14:50:34 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Mika Westerberg , Andy Shevchenko , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Ferry Toth Subject: [PATCH v1 3/3] platform/x86: intel_scu_ipc: Save a copy of the entire struct intel_scu_ipc_data Date: Wed, 16 Oct 2024 14:48:26 +0300 Message-ID: <20241016115033.858574-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20241016115033.858574-1-andriy.shevchenko@linux.intel.com> References: <20241016115033.858574-1-andriy.shevchenko@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: quoted-printable Content-Type: text/plain; charset="utf-8" Save a copy of the entire struct intel_scu_ipc_data for easier maintenance in case of expanding (adding new members become simpler). Signed-off-by: Andy Shevchenko Acked-by: Mika Westerberg Tested-by: Ferry Toth (Intel Edison-Arduino) --- 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/in= tel_scu_ipc.c index ffb0a2524388..e86a255f70ba 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -57,11 +57,11 @@ =20 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; }; =20 #define IPC_STATUS 0x04 @@ -256,7 +256,7 @@ static inline int ipc_wait_for_interrupt(struct intel_s= cu_ipc_dev *scu) =20 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); } =20 static struct intel_scu_ipc_dev *intel_scu_ipc_get(struct intel_scu_ipc_de= v *scu) @@ -536,13 +536,13 @@ static irqreturn_t ioc(int irq, void *dev_id) =20 static void intel_scu_ipc_release(struct device *dev) { - struct intel_scu_ipc_dev *scu; + struct intel_scu_ipc_dev *scu =3D container_of(dev, struct intel_scu_ipc_= dev, dev); + struct intel_scu_ipc_data *data =3D &scu->data; =20 - scu =3D 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); } =20 @@ -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; =20 @@ -581,25 +582,25 @@ __intel_scu_ipc_register(struct device *parent, scu->dev.class =3D &intel_scu_ipc_class; scu->dev.release =3D intel_scu_ipc_release; =20 - 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 =3D &scu->data; + + if (!request_mem_region(data->mem.start, resource_size(&data->mem), "inte= l_scu_ipc")) { err =3D -EBUSY; goto err_free; } =20 - ipc_base =3D ioremap(scu_data->mem.start, resource_size(&scu_data->mem)); + ipc_base =3D ioremap(data->mem.start, resource_size(&data->mem)); if (!ipc_base) { err =3D -ENOMEM; goto err_release; } =20 scu->ipc_base =3D ipc_base; - scu->mem =3D scu_data->mem; - scu->irq =3D scu_data->irq; init_completion(&scu->cmd_complete); =20 - if (scu->irq > 0) { - err =3D request_irq(scu->irq, ioc, 0, "intel_scu_ipc", scu); + if (data->irq > 0) { + err =3D 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); --=20 2.43.0.rc1.1336.g36b5255a03ac