Re: [PATCH 6/7] MIPS: SGI-IP27: use generic PCI driver

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

 



On Wed, 20 Feb 2019 07:10:56 -0800
Christoph Hellwig <hch@xxxxxxxxxxxxx> wrote:

> On Mon, Feb 18, 2019 at 11:58:07AM +0100, Thomas Bogendoerfer wrote:
> > This of course will break SH7786. To fix both cases how about making dma_pfn_offset
> >
> > a signed long ?
> 
> Yes, making it signed sounds like a good idea.

but at least my implementation looks a little bit ugly:

diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index b7338702592a..b72b1cba8911 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -12,14 +12,20 @@ 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);
+       if (dev->dma_pfn_offset > 0)
+               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);
+       if (dev->dma_pfn_offset > 0)
+               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)



For the v2 version of the IP27 rework I've used the mach-XXX include structure
of the MIPS tree to implement __phy_to_dma/__dma_to_phys for IP27. I'd prefer
it that way.

Thomas.

-- 
SUSE Linux GmbH
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux