xref: /linux/arch/mips/loongson64/dma.c (revision 6fbde6b492dfc761ad60a68fb2cb32b1eb05b786)
1*6fbde6b4SJiaxun Yang // SPDX-License-Identifier: GPL-2.0
2*6fbde6b4SJiaxun Yang #include <linux/dma-direct.h>
3*6fbde6b4SJiaxun Yang #include <linux/init.h>
4*6fbde6b4SJiaxun Yang #include <linux/swiotlb.h>
5*6fbde6b4SJiaxun Yang 
6*6fbde6b4SJiaxun Yang dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
7*6fbde6b4SJiaxun Yang {
8*6fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
9*6fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
10*6fbde6b4SJiaxun Yang 	long nid = (paddr >> 44) & 0x3;
11*6fbde6b4SJiaxun Yang 	return ((nid << 44) ^ paddr) | (nid << 37);
12*6fbde6b4SJiaxun Yang }
13*6fbde6b4SJiaxun Yang 
14*6fbde6b4SJiaxun Yang phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
15*6fbde6b4SJiaxun Yang {
16*6fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
17*6fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
18*6fbde6b4SJiaxun Yang 	long nid = (daddr >> 37) & 0x3;
19*6fbde6b4SJiaxun Yang 	return ((nid << 37) ^ daddr) | (nid << 44);
20*6fbde6b4SJiaxun Yang }
21*6fbde6b4SJiaxun Yang 
22*6fbde6b4SJiaxun Yang void __init plat_swiotlb_setup(void)
23*6fbde6b4SJiaxun Yang {
24*6fbde6b4SJiaxun Yang 	swiotlb_init(1);
25*6fbde6b4SJiaxun Yang }
26