public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation
@ 2025-06-11 16:30 Hans Zhang
  2025-06-13 12:02 ` Niklas Cassel
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Zhang @ 2025-06-11 16:30 UTC (permalink / raw)
  To: lpieralisi, bhelgaas, mani, kwilczynski
  Cc: robh, jingoohan1, linux-pci, linux-kernel, Hans Zhang

DesignWare PCIe controller drivers implement register bit manipulation
through explicit read-modify-write sequences. These patterns appear
repeatedly across multiple drivers with minor variations, creating
code duplication and maintenance overhead.

Implement dw_pcie_clear_and_set_dword() helper to encapsulate atomic
register modification. The function reads the current register value,
clears specified bits, sets new bits, and writes back the result in
a single operation. This abstraction hides bitwise manipulation details
while ensuring consistent behavior across all usage sites.

Centralizing this logic reduces future maintenance effort when modifying
register access patterns and minimizes the risk of implementation
divergence between drivers.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/dwc/pcie-designware.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index ce9e18554e42..f401c144df0f 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -707,6 +707,17 @@ static inline void dw_pcie_ep_writel_dbi2(struct dw_pcie_ep *ep, u8 func_no,
 	dw_pcie_ep_write_dbi2(ep, func_no, reg, 0x4, val);
 }
 
+static inline void dw_pcie_clear_and_set_dword(struct dw_pcie *pci, int pos,
+					       u32 clear, u32 set)
+{
+	u32 val;
+
+	val = dw_pcie_readl_dbi(pci, pos);
+	val &= ~clear;
+	val |= set;
+	dw_pcie_writel_dbi(pci, pos, val);
+}
+
 static inline void dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)
 {
 	u32 reg;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation
  2025-06-11 16:30 [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation Hans Zhang
@ 2025-06-13 12:02 ` Niklas Cassel
  2025-06-13 12:33   ` 回复: " Hans Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Niklas Cassel @ 2025-06-13 12:02 UTC (permalink / raw)
  To: Hans Zhang
  Cc: lpieralisi, bhelgaas, mani, kwilczynski, robh, jingoohan1,
	linux-pci, linux-kernel

On Thu, Jun 12, 2025 at 12:30:57AM +0800, Hans Zhang wrote:
> DesignWare PCIe controller drivers implement register bit manipulation
> through explicit read-modify-write sequences. These patterns appear
> repeatedly across multiple drivers with minor variations, creating
> code duplication and maintenance overhead.
> 
> Implement dw_pcie_clear_and_set_dword() helper to encapsulate atomic
> register modification. The function reads the current register value,
> clears specified bits, sets new bits, and writes back the result in
> a single operation. This abstraction hides bitwise manipulation details
> while ensuring consistent behavior across all usage sites.
> 
> Centralizing this logic reduces future maintenance effort when modifying
> register access patterns and minimizes the risk of implementation
> divergence between drivers.
> 
> Signed-off-by: Hans Zhang <18255117159@163.com>

No cover-letter?

Usually for things like this, it is nice to see the diffstat,
which is usually part of the cover-letter.


Kind regards,
Niklas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* 回复: [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation
  2025-06-13 12:02 ` Niklas Cassel
@ 2025-06-13 12:33   ` Hans Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Zhang @ 2025-06-13 12:33 UTC (permalink / raw)
  To: Niklas Cassel, Hans Zhang
  Cc: lpieralisi@kernel.org, bhelgaas@google.com, mani@kernel.org,
	kwilczynski@kernel.org, robh@kernel.org, jingoohan1@gmail.com,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

Hi Niklas,

I have replied to Bjorn. For the next version, I will send the patches of this series using the company's environment.

Please look at this link. Could you please also help review it? Thank you very much.
https://lore.kernel.org/linux-pci/c31c3834-247d-4a28-bd2c-4a39ea719625@163.com/

Best regards,
Hans

-----邮件原件-----
发件人: Niklas Cassel <cassel@kernel.org> 
发送时间: 2025年6月13日 20:03
收件人: Hans Zhang <18255117159@163.com>
抄送: lpieralisi@kernel.org; bhelgaas@google.com; mani@kernel.org; kwilczynski@kernel.org; robh@kernel.org; jingoohan1@gmail.com; linux-pci@vger.kernel.org; linux-kernel@vger.kernel.org
主题: Re: [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation

EXTERNAL EMAIL

On Thu, Jun 12, 2025 at 12:30:57AM +0800, Hans Zhang wrote:
> DesignWare PCIe controller drivers implement register bit manipulation 
> through explicit read-modify-write sequences. These patterns appear 
> repeatedly across multiple drivers with minor variations, creating 
> code duplication and maintenance overhead.
>
> Implement dw_pcie_clear_and_set_dword() helper to encapsulate atomic 
> register modification. The function reads the current register value, 
> clears specified bits, sets new bits, and writes back the result in a 
> single operation. This abstraction hides bitwise manipulation details 
> while ensuring consistent behavior across all usage sites.
>
> Centralizing this logic reduces future maintenance effort when 
> modifying register access patterns and minimizes the risk of 
> implementation divergence between drivers.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>

No cover-letter?

Usually for things like this, it is nice to see the diffstat, which is usually part of the cover-letter.


Kind regards,
Niklas


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-13 12:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 16:30 [PATCH 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation Hans Zhang
2025-06-13 12:02 ` Niklas Cassel
2025-06-13 12:33   ` 回复: " Hans Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox