On Mon, 28 Jan 2019 05:32:15 -0800 Christoph Hellwig <hch@xxxxxxxxxxxxx> wrote: > Note that we could probably fix these by just switching IP27 and > other users of the bridge chip to use the dma_pfn_offset field > in struct device and stop overriding these functions. during my final round of tests for v2 of the patchset I found a problem with the current implementation regarding dma_pfn_offset. Right now it asumes that dma addresses are lower than physical addresses, which probably came from the sh7786 usage (at least that's how I understand the SH7786 datasheet). But for IP27 physical addresses starts at 0 and dma address is more at the end of the 64bit address space. So using following patch gets it right for IP27: diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index b7338702592a..19dfadc292f5 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -12,14 +12,14 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) { dma_addr_t dev_addr = (dma_addr_t)paddr; - return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT); + return dev_addr + ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT); } static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr) { phys_addr_t paddr = (phys_addr_t)dev_addr; - return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT); + return paddr - ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT); } static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) This of course will break SH7786. To fix both cases how about making dma_pfn_offset a signed long ? Thomas. -- SUSE Linux GmbH GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)