Re: [PATCH v3 1/2] make xhci platform driver use 64 bit or 32 bit DMA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/11/2014 09:58 PM, yoshihiro shimoda wrote:
Hi Mark,

-----Original Message-----
From: linux-usb-owner@xxxxxxxxxxxxxxx [mailto:linux-usb-owner@xxxxxxxxxxxxxxx] On Behalf Of Mark Langsdorf
Sent: Wednesday, November 26, 2014 6:19 AM
To: linux-usb@xxxxxxxxxxxxxxx; mathias.nyman@xxxxxxxxx
Cc: mlangsdo@xxxxxxxxxx
Subject: [PATCH v3 1/2] make xhci platform driver use 64 bit or 32 bit DMA

The xhci platform driver needs to work on systems that either only
support 64-bit DMA or only support 32-bit DMA. Attempt to set a
coherent dma mask for 64-bit DMA, and attempt again with 32-bit
DMA if that fails.

I'm afraid but I have a comment about this patch.

Since my environment (It's R-Car Gen2. It has ARM/CA15 and LPAE) has a
restriction about DMA coherent, I intend to send some patches to avoid
the restriction. And then, I found this patch.

About my environment restriction is:
  - R-Car Gen2 can use LAPE.
   - So, dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); will not fail.
  - AXI address bus width of R-Car Gen2 xHCI controller is 32 bit.
  - However, The HCCPARAMS.AC64 is set to 1.

So, in this environment, I think the xHCI driver should call
dma_set_coherent(dev, DMA_BIT_MASK(32)) because AXI address bus width is 32 bit.
However, in this case, the xHCI driver will call dma_set_coherent_mask(dev, DMA_BIT_MASK(64))
in line 4900 of drivers/usb/host/xhci.c:

	/* Set dma_mask and coherent_dma_mask to 64-bits,
	 * if xHC supports 64-bit addressing */
	if (HCC_64BIT_ADDR(xhci->hcc_params) &&
			!dma_set_mask(dev, DMA_BIT_MASK(64))) {
		xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
		dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
	}

So, I intend to send some patches to add a quirk to this condition.
However, if this patch is applied, I also need more patch for xhci-plat.c.

Or, I misunderstand about the DMA-API?

Hello,

As best I understand your question, you would need to add a
quirk. I could change the patch to help you, if you'd like:

-	/* Initialize dma_mask and coherent_dma_mask to 32-bits */
-	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
-	if (ret)
-		return ret;
-	if (!pdev->dev.dma_mask)
-		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-	else
-		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	/* Try setting the coherent_dma_mask to 64 bits, then try 32 bits */
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+	if (ret || xhci_plat_lpae_dma()) {
+		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		if (ret)
+			return ret;
+	}

bool xhci_plat_lpae_dma(void) would be a new function that returned true
if for your device and other devices that have 64-bit addressing in
general but only 32-bits of DMA. You would need to write that part.

Would that be an acceptable solution?

--Mark Langsdorf


Signed-off-by: Mark Langsdorf <mlangsdo@xxxxxxxxxx>
Tested-by: Mark Salter <msalter@xxxxxxxxxx>
---
Changes from v2:
	None
Changes from v1:
	Consolidated to use dma_set_mask_and_coherent
	Got rid of the check against sizeof(dma_addr_t)

  drivers/usb/host/xhci-plat.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 3d78b0c..34cbf65 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -96,14 +96,14 @@ static int xhci_plat_probe(struct platform_device *pdev)
  			return ret;
  	}

-	/* Initialize dma_mask and coherent_dma_mask to 32-bits */
-	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
-	if (ret)
-		return ret;
-	if (!pdev->dev.dma_mask)
-		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
-	else
-		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	/* Try setting the coherent_dma_mask to 64 bits, then try 32 bits */
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+	if (ret) {
+		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		if (ret)
+			return ret;
+	}
+

  	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  	if (!hcd)
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux