1. 18 9月, 2020 2 次提交
    • J
      dma-mapping: introduce DMA range map, supplanting dma_pfn_offset · e0d07278
      Jim Quinlan 提交于
      The new field 'dma_range_map' in struct device is used to facilitate the
      use of single or multiple offsets between mapping regions of cpu addrs and
      dma addrs.  It subsumes the role of "dev->dma_pfn_offset" which was only
      capable of holding a single uniform offset and had no region bounds
      checking.
      
      The function of_dma_get_range() has been modified so that it takes a single
      argument -- the device node -- and returns a map, NULL, or an error code.
      The map is an array that holds the information regarding the DMA regions.
      Each range entry contains the address offset, the cpu_start address, the
      dma_start address, and the size of the region.
      
      of_dma_configure() is the typical manner to set range offsets but there are
      a number of ad hoc assignments to "dev->dma_pfn_offset" in the kernel
      driver code.  These cases now invoke the function
      dma_direct_set_offset(dev, cpu_addr, dma_addr, size).
      Signed-off-by: NJim Quinlan <james.quinlan@broadcom.com>
      [hch: various interface cleanups]
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NMathieu Poirier <mathieu.poirier@linaro.org>
      Tested-by: NMathieu Poirier <mathieu.poirier@linaro.org>
      Tested-by: NNathan Chancellor <natechancellor@gmail.com>
      e0d07278
    • C
      usb: don't inherity DMA properties for USB devices · 6eb0233e
      Christoph Hellwig 提交于
      As the comment in usb_alloc_dev correctly states, drivers can't use
      the DMA API on usb device, and at least calling dma_set_mask on them
      is highly dangerous.  Unlike what the comment states upper level drivers
      also can't really use the presence of a dma mask to check for DMA
      support, as the dma_mask is set by default for most busses.
      
      Setting the dma_mask comes from "[PATCH] usbcore dma updates (and doc)"
      in BitKeeper times, as it seems like it was primarily for setting the
      NETIF_F_HIGHDMA flag in USB drivers, something that has long been
      fixed up since.
      
      Setting the dma_pfn_offset comes from commit b44bbc46
      ("usb: core: setup dma_pfn_offset for USB devices and, interfaces"),
      which worked around the fact that the scsi_calculate_bounce_limits
      functions wasn't going through the proper driver interface to query
      DMA information, but that function was removed in commit 21e07dba
      ("scsi: reduce use of block bounce buffers") years ago.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6eb0233e
  2. 11 9月, 2020 2 次提交
  3. 04 9月, 2020 1 次提交
    • N
      dma-mapping: introduce dma_get_seg_boundary_nr_pages() · 1e9d90db
      Nicolin Chen 提交于
      We found that callers of dma_get_seg_boundary mostly do an ALIGN
      with page mask and then do a page shift to get number of pages:
          ALIGN(boundary + 1, 1 << shift) >> shift
      
      However, the boundary might be as large as ULONG_MAX, which means
      that a device has no specific boundary limit. So either "+ 1" or
      passing it to ALIGN() would potentially overflow.
      
      According to kernel defines:
          #define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
          #define ALIGN(x, a)	ALIGN_MASK(x, (typeof(x))(a) - 1)
      
      We can simplify the logic here into a helper function doing:
        ALIGN(boundary + 1, 1 << shift) >> shift
      = ALIGN_MASK(b + 1, (1 << s) - 1) >> s
      = {[b + 1 + (1 << s) - 1] & ~[(1 << s) - 1]} >> s
      = [b + 1 + (1 << s) - 1] >> s
      = [b + (1 << s)] >> s
      = (b >> s) + 1
      
      This patch introduces and applies dma_get_seg_boundary_nr_pages()
      as an overflow-free helper for the dma_get_seg_boundary() callers
      to get numbers of pages. It also takes care of the NULL dev case
      for non-DMA API callers.
      Suggested-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NNicolin Chen <nicoleotsuka@gmail.com>
      Acked-by: NNiklas Schnelle <schnelle@linux.ibm.com>
      Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      1e9d90db
  4. 30 8月, 2020 1 次提交
    • L
      fsldma: fix very broken 32-bit ppc ioread64 functionality · 0a4c56c8
      Linus Torvalds 提交于
      Commit ef91bb19 ("kernel.h: Silence sparse warning in
      lower_32_bits") caused new warnings to show in the fsldma driver, but
      that commit was not to blame: it only exposed some very incorrect code
      that tried to take the low 32 bits of an address.
      
      That made no sense for multiple reasons, the most notable one being that
      that code was intentionally limited to only 32-bit ppc builds, so "only
      low 32 bits of an address" was completely nonsensical.  There were no
      high bits to mask off to begin with.
      
      But even more importantly fropm a correctness standpoint, turning the
      address into an integer then caused the subsequent address arithmetic to
      be completely wrong too, and the "+1" actually incremented the address
      by one, rather than by four.
      
      Which again was incorrect, since the code was reading two 32-bit values
      and trying to make a 64-bit end result of it all.  Surprisingly, the
      iowrite64() did not suffer from the same odd and incorrect model.
      
      This code has never worked, but it's questionable whether anybody cared:
      of the two users that actually read the 64-bit value (by way of some C
      preprocessor hackery and eventually the 'get_cdar()' inline function),
      one of them explicitly ignored the value, and the other one might just
      happen to work despite the incorrect value being read.
      
      This patch at least makes it not fail the build any more, and makes the
      logic superficially sane.  Whether it makes any difference to the code
      _working_ or not shall remain a mystery.
      Compile-tested-by: NGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0a4c56c8
  5. 28 8月, 2020 6 次提交
  6. 27 8月, 2020 28 次提交