xref: /openbmc/linux/arch/mips/loongson64/dma.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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>
568fbb972STiezhu Yang #include <boot_param.h>
66fbde6b4SJiaxun Yang 
phys_to_dma(struct device * dev,phys_addr_t paddr)75ceda740SChristoph Hellwig 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;
1268fbb972STiezhu Yang 
1368fbb972STiezhu Yang 	return ((nid << 44) ^ paddr) | (nid << node_id_offset);
146fbde6b4SJiaxun Yang }
156fbde6b4SJiaxun Yang 
dma_to_phys(struct device * dev,dma_addr_t daddr)167bc5c428SChristoph Hellwig 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 */
2068fbb972STiezhu Yang 	long nid = (daddr >> node_id_offset) & 0x3;
2168fbb972STiezhu Yang 
2268fbb972STiezhu Yang 	return ((nid << node_id_offset) ^ daddr) | (nid << 44);
236fbde6b4SJiaxun Yang }
246fbde6b4SJiaxun Yang 
plat_swiotlb_setup(void)256fbde6b4SJiaxun Yang void __init plat_swiotlb_setup(void)
266fbde6b4SJiaxun Yang {
27*c6af2aa9SChristoph Hellwig 	swiotlb_init(true, SWIOTLB_VERBOSE);
286fbde6b4SJiaxun Yang }
29