Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: dwc: Set DMA mask to 32 only if ZONE_DMA32 is enabled
@ 2023-12-21 17:40 Ajay Agarwal
  2023-12-21 18:00 ` Ajay Agarwal
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Ajay Agarwal @ 2023-12-21 17:40 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Manivannan Sadhasivam,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas, Manu Gautam, Sajid Dalvi, William McVicker
  Cc: linux-pci, Ajay Agarwal

If CONFIG_ZONE_DMA32 is disabled, then the dmam_alloc_coherent
will fail to allocate the memory if there are no 32-bit addresses
available. This will lead to the PCIe RC probe failure.
Fix this by setting the DMA mask to 32 bits only if the kernel
configuration enables DMA32 zone. Else, leave the mask as is.

Signed-off-by: Ajay Agarwal <ajayagarwal@google.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 7991f0e179b2..163a78c5f9d8 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -377,10 +377,17 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
 	 * Note until there is a better alternative found the reservation is
 	 * done by allocating from the artificially limited DMA-coherent
 	 * memory.
+	 *
+	 * Set the coherent DMA mask to 32 bits only if the DMA32 zone is
+	 * supported. Otherwise, leave the mask as is.
+	 * This ensures that the dmam_alloc_coherent is successful in
+	 * allocating the memory.
 	 */
+#ifdef CONFIG_ZONE_DMA32
 	ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
 	if (ret)
 		dev_warn(dev, "Failed to set DMA mask to 32-bit. Devices with only 32-bit MSI support may not work properly\n");
+#endif
 
 	msi_vaddr = dmam_alloc_coherent(dev, sizeof(u64), &pp->msi_data,
 					GFP_KERNEL);
-- 
2.43.0.195.gebba966016-goog


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

end of thread, other threads:[~2024-01-11  3:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 17:40 [PATCH] PCI: dwc: Set DMA mask to 32 only if ZONE_DMA32 is enabled Ajay Agarwal
2023-12-21 18:00 ` Ajay Agarwal
2023-12-21 18:05 ` Ajay Agarwal
2023-12-21 18:06 ` Ajay Agarwal
2023-12-21 18:33 ` Serge Semin
2024-01-08 17:50   ` Robin Murphy
2024-01-09 22:47     ` Serge Semin
2024-01-11  3:58       ` Ajay Agarwal
2023-12-22  5:05 ` Christoph Hellwig

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