xref: /linux/arch/mips/loongson64/dma.c (revision 40a48dd3bb85bcd795d37ef8129af7eca978d669)
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*40a48dd3SJiaxun Yang #include <asm/bootinfo.h>
668fbb972STiezhu Yang #include <boot_param.h>
76fbde6b4SJiaxun Yang 
85ceda740SChristoph Hellwig dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
96fbde6b4SJiaxun Yang {
106fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
116fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
126fbde6b4SJiaxun Yang 	long nid = (paddr >> 44) & 0x3;
1368fbb972STiezhu Yang 
1468fbb972STiezhu Yang 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
156fbde6b4SJiaxun Yang }
166fbde6b4SJiaxun Yang 
177bc5c428SChristoph Hellwig phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
186fbde6b4SJiaxun Yang {
196fbde6b4SJiaxun Yang 	/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
206fbde6b4SJiaxun Yang 	 * Loongson-3's 48bit address space and embed it into 40bit */
2168fbb972STiezhu Yang 	long nid = (daddr >> node_id_offset) & 0x3;
2268fbb972STiezhu Yang 
2368fbb972STiezhu Yang 	return ((nid << node_id_offset) ^ daddr) | (nid << 44);
246fbde6b4SJiaxun Yang }
256fbde6b4SJiaxun Yang 
266fbde6b4SJiaxun Yang void __init plat_swiotlb_setup(void)
276fbde6b4SJiaxun Yang {
28c6af2aa9SChristoph Hellwig 	swiotlb_init(true, SWIOTLB_VERBOSE);
296fbde6b4SJiaxun Yang }
30