xref: /linux/arch/mips/loongson64/dma.c (revision 68fbb9721ea76b2a3088b749e004456f2de05b9f)
16fbde6b4SJiaxun Yang // SPDX-License-Identifier: GPL-2.0
26fbde6b4SJiaxun Yang #include <linux/dma-direct.h>
36fbde6b4SJiaxun Yang #include <linux/init.h>
46fbde6b4SJiaxun Yang #include <linux/swiotlb.h>
5*68fbb972STiezhu Yang #include <boot_param.h>
66fbde6b4SJiaxun Yang 
76fbde6b4SJiaxun Yang dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
86fbde6b4SJiaxun Yang {
96fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
106fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
116fbde6b4SJiaxun Yang 	long nid = (paddr >> 44) & 0x3;
12*68fbb972STiezhu Yang 
13*68fbb972STiezhu Yang 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
146fbde6b4SJiaxun Yang }
156fbde6b4SJiaxun Yang 
166fbde6b4SJiaxun Yang phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
176fbde6b4SJiaxun Yang {
186fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
196fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
20*68fbb972STiezhu Yang 	long nid = (daddr >> node_id_offset) & 0x3;
21*68fbb972STiezhu Yang 
22*68fbb972STiezhu Yang 	return ((nid << node_id_offset) ^ daddr) | (nid << 44);
236fbde6b4SJiaxun Yang }
246fbde6b4SJiaxun Yang 
256fbde6b4SJiaxun Yang void __init plat_swiotlb_setup(void)
266fbde6b4SJiaxun Yang {
276fbde6b4SJiaxun Yang 	swiotlb_init(1);
286fbde6b4SJiaxun Yang }
29