blob: 364f2f27c8723fdcbdcf3770bbd3be87717fd0c3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Christoph Hellwigf6d302e2018-06-15 13:08:36 +02002#include <linux/dma-direct.h>
Huacai Chen1299b0e2014-03-21 18:44:06 +08003#include <linux/init.h>
Huacai Chen1299b0e2014-03-21 18:44:06 +08004#include <linux/swiotlb.h>
Tiezhu Yang68fbb972020-05-08 16:36:05 +08005#include <boot_param.h>
Huacai Chen1299b0e2014-03-21 18:44:06 +08006
Christoph Hellwig5ceda742020-08-17 17:34:03 +02007dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
Huacai Chen1299b0e2014-03-21 18:44:06 +08008{
Huacai Chenf4906822014-11-04 14:13:24 +08009 /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
10 * Loongson-3's 48bit address space and embed it into 40bit */
Christoph Hellwigd3bc81b2018-06-15 13:08:41 +020011 long nid = (paddr >> 44) & 0x3;
Tiezhu Yang68fbb972020-05-08 16:36:05 +080012
13 return ((nid << 44) ^ paddr) | (nid << node_id_offset);
Huacai Chen1299b0e2014-03-21 18:44:06 +080014}
15
Christoph Hellwig7bc5c422020-09-08 17:56:22 +020016phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
Huacai Chen1299b0e2014-03-21 18:44:06 +080017{
Huacai Chenf4906822014-11-04 14:13:24 +080018 /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
19 * Loongson-3's 48bit address space and embed it into 40bit */
Tiezhu Yang68fbb972020-05-08 16:36:05 +080020 long nid = (daddr >> node_id_offset) & 0x3;
21
22 return ((nid << node_id_offset) ^ daddr) | (nid << 44);
Huacai Chen1299b0e2014-03-21 18:44:06 +080023}
24
Huacai Chen1299b0e2014-03-21 18:44:06 +080025void __init plat_swiotlb_setup(void)
26{
27 swiotlb_init(1);
Huacai Chen1299b0e2014-03-21 18:44:06 +080028}