forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/arch/mips/cavium-octeon/dma-octeon.c
....@@ -11,7 +11,7 @@
1111 * Copyright (C) 2010 Cavium Networks, Inc.
1212 */
1313 #include <linux/dma-direct.h>
14
-#include <linux/bootmem.h>
14
+#include <linux/memblock.h>
1515 #include <linux/swiotlb.h>
1616 #include <linux/types.h>
1717 #include <linux/init.h>
....@@ -168,7 +168,7 @@
168168 }
169169 #endif /* CONFIG_PCI */
170170
171
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
171
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
172172 {
173173 #ifdef CONFIG_PCI
174174 if (dev && dev_is_pci(dev))
....@@ -177,7 +177,7 @@
177177 return paddr;
178178 }
179179
180
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
180
+phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
181181 {
182182 #ifdef CONFIG_PCI
183183 if (dev && dev_is_pci(dev))
....@@ -190,29 +190,25 @@
190190
191191 void __init plat_swiotlb_setup(void)
192192 {
193
- int i;
193
+ phys_addr_t start, end;
194194 phys_addr_t max_addr;
195195 phys_addr_t addr_size;
196196 size_t swiotlbsize;
197197 unsigned long swiotlb_nslabs;
198
+ u64 i;
198199
199200 max_addr = 0;
200201 addr_size = 0;
201202
202
- for (i = 0 ; i < boot_mem_map.nr_map; i++) {
203
- struct boot_mem_map_entry *e = &boot_mem_map.map[i];
204
- if (e->type != BOOT_MEM_RAM && e->type != BOOT_MEM_INIT_RAM)
205
- continue;
206
-
203
+ for_each_mem_range(i, &start, &end) {
207204 /* These addresses map low for PCI. */
208
- if (e->addr > 0x410000000ull && !OCTEON_IS_OCTEON2())
205
+ if (start > 0x410000000ull && !OCTEON_IS_OCTEON2())
209206 continue;
210207
211
- addr_size += e->size;
208
+ addr_size += (end - start);
212209
213
- if (max_addr < e->addr + e->size)
214
- max_addr = e->addr + e->size;
215
-
210
+ if (max_addr < end)
211
+ max_addr = end;
216212 }
217213
218214 swiotlbsize = PAGE_SIZE;
....@@ -244,7 +240,10 @@
244240 swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
245241 swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
246242
247
- octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize);
243
+ octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
244
+ if (!octeon_swiotlb)
245
+ panic("%s: Failed to allocate %zu bytes align=%lx\n",
246
+ __func__, swiotlbsize, PAGE_SIZE);
248247
249248 if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
250249 panic("Cannot allocate SWIOTLB buffer");