Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christoph Hellwig | f6d302e | 2018-06-15 13:08:36 +0200 | [diff] [blame] | 2 | #include <linux/dma-direct.h> |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 3 | #include <linux/init.h> |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 4 | #include <linux/swiotlb.h> |
Tiezhu Yang | 68fbb97 | 2020-05-08 16:36:05 +0800 | [diff] [blame] | 5 | #include <boot_param.h> |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 6 | |
Christoph Hellwig | 5ceda74 | 2020-08-17 17:34:03 +0200 | [diff] [blame] | 7 | dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 8 | { |
Huacai Chen | f490682 | 2014-11-04 14:13:24 +0800 | [diff] [blame] | 9 | /* 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 Hellwig | d3bc81b | 2018-06-15 13:08:41 +0200 | [diff] [blame] | 11 | long nid = (paddr >> 44) & 0x3; |
Tiezhu Yang | 68fbb97 | 2020-05-08 16:36:05 +0800 | [diff] [blame] | 12 | |
| 13 | return ((nid << 44) ^ paddr) | (nid << node_id_offset); |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 14 | } |
| 15 | |
Christoph Hellwig | 7bc5c42 | 2020-09-08 17:56:22 +0200 | [diff] [blame] | 16 | phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 17 | { |
Huacai Chen | f490682 | 2014-11-04 14:13:24 +0800 | [diff] [blame] | 18 | /* 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 Yang | 68fbb97 | 2020-05-08 16:36:05 +0800 | [diff] [blame] | 20 | long nid = (daddr >> node_id_offset) & 0x3; |
| 21 | |
| 22 | return ((nid << node_id_offset) ^ daddr) | (nid << 44); |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 23 | } |
| 24 | |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 25 | void __init plat_swiotlb_setup(void) |
| 26 | { |
| 27 | swiotlb_init(1); |
Huacai Chen | 1299b0e | 2014-03-21 18:44:06 +0800 | [diff] [blame] | 28 | } |