Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2006  Ralf Baechle <ralf@linux-mips.org>
0004  */
0005 #include <linux/dma-direct.h>
0006 #include <asm/ip32/crime.h>
0007 
0008 /*
0009  * Few notes.
0010  * 1. CPU sees memory as two chunks: 0-256M@0x0, and the rest @0x40000000+256M
0011  * 2. PCI sees memory as one big chunk @0x0 (or we could use 0x40000000 for
0012  *    native-endian)
0013  * 3. All other devices see memory as one big chunk at 0x40000000
0014  * 4. Non-PCI devices will pass NULL as struct device*
0015  *
0016  * Thus we translate differently, depending on device.
0017  */
0018 
0019 #define RAM_OFFSET_MASK 0x3fffffffUL
0020 
0021 dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
0022 {
0023     dma_addr_t dma_addr = paddr & RAM_OFFSET_MASK;
0024 
0025     if (!dev)
0026         dma_addr += CRIME_HI_MEM_BASE;
0027     return dma_addr;
0028 }
0029 
0030 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr)
0031 {
0032     phys_addr_t paddr = dma_addr & RAM_OFFSET_MASK;
0033 
0034     if (dma_addr >= 256*1024*1024)
0035         paddr += CRIME_HI_MEM_BASE;
0036     return paddr;
0037 }