]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
dma-mapping: Generalise dma_32bit_limit flag
authorRobin Murphy <robin.murphy@arm.com>
Mon, 23 Jul 2018 22:16:07 +0000 (23:16 +0100)
committerChristoph Hellwig <hch@lst.de>
Fri, 27 Jul 2018 17:01:04 +0000 (19:01 +0200)
Whilst the notion of an upstream DMA restriction is most commonly seen
in PCI host bridges saddled with a 32-bit native interface, a more
general version of the same issue can exist on complex SoCs where a bus
or point-to-point interconnect link from a device's DMA master interface
to another component along the path to memory (often an IOMMU) may carry
fewer address bits than the interfaces at both ends nominally support.
In order to properly deal with this, the first step is to expand the
dma_32bit_limit flag into an arbitrary mask.

To minimise the impact on existing code, we'll make sure to only
consider this new mask valid if set. That makes sense anyway, since a
mask of zero would represent DMA not being wired up at all, and that
would be better handled by not providing valid ops in the first place.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
arch/x86/kernel/pci-dma.c
include/linux/device.h
kernel/dma/direct.c

index ab5d9dd668d2fb2580e07881d43f4d4bb5dc3e6c..80f9fe8d27d0a28eaec0f1db5631498e3d92334d 100644 (file)
@@ -175,7 +175,7 @@ rootfs_initcall(pci_iommu_init);
 
 static int via_no_dac_cb(struct pci_dev *pdev, void *data)
 {
-       pdev->dev.dma_32bit_limit = true;
+       pdev->dev.bus_dma_mask = DMA_BIT_MASK(32);
        return 0;
 }
 
index 055a69dbcd18a8a5286d8e612fe16c1ae6245455..6d3b000be57e08d2fc83180096d4808eb2e01ae0 100644 (file)
@@ -886,6 +886,8 @@ struct dev_links_info {
  * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all
  *             hardware supports 64-bit addresses for consistent allocations
  *             such descriptors.
+ * @bus_dma_mask: Mask of an upstream bridge or bus which imposes a smaller DMA
+ *             limit than the device itself supports.
  * @dma_pfn_offset: offset of DMA memory range relatively of RAM
  * @dma_parms: A low level driver may set these to teach IOMMU code about
  *             segment limitations.
@@ -912,8 +914,6 @@ struct dev_links_info {
  * @offline:   Set after successful invocation of bus type's .offline().
  * @of_node_reused: Set if the device-tree node is shared with an ancestor
  *              device.
- * @dma_32bit_limit: bridge limited to 32bit DMA even if the device itself
- *             indicates support for a higher limit in the dma_mask field.
  *
  * At the lowest level, every device in a Linux system is represented by an
  * instance of struct device. The device structure contains the information
@@ -967,6 +967,7 @@ struct device {
                                             not all hardware supports
                                             64 bit addresses for consistent
                                             allocations such descriptors. */
+       u64             bus_dma_mask;   /* upstream dma_mask constraint */
        unsigned long   dma_pfn_offset;
 
        struct device_dma_parameters *dma_parms;
@@ -1002,7 +1003,6 @@ struct device {
        bool                    offline_disabled:1;
        bool                    offline:1;
        bool                    of_node_reused:1;
-       bool                    dma_32bit_limit:1;
 };
 
 static inline struct device *kobj_to_dev(struct kobject *kobj)
index 8be8106270c245ff299c5ef50fcc5a6689ef896b..c2860c5a9e963ea5b03fad01a2cd812f3a78e5c9 100644 (file)
@@ -180,10 +180,10 @@ int dma_direct_supported(struct device *dev, u64 mask)
                return 0;
 #endif
        /*
-        * Various PCI/PCIe bridges have broken support for > 32bit DMA even
-        * if the device itself might support it.
+        * Upstream PCI/PCIe bridges or SoC interconnects may not carry
+        * as many DMA address bits as the device itself supports.
         */
-       if (dev->dma_32bit_limit && mask > DMA_BIT_MASK(32))
+       if (dev->bus_dma_mask && mask > dev->bus_dma_mask)
                return 0;
        return 1;
 }