Skip to content

Commit

Permalink
riscv: add ZONE_DMA32
Browse files Browse the repository at this point in the history
This patch allows devices that require memory that can be addressed
using 32-bit addresses to work easily on RISC-V systems.  The newly
improved dma-direct ops will tap into this pool automatically for
32-bit addressing.

Based on an earlier patch from Wesley W. Terpstra.

CC: Wesley W. Terpstra <terpstra@sifive.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
  • Loading branch information
Christoph Hellwig authored and Palmer Dabbelt committed Jan 31, 2018
1 parent f1b65f2 commit 5ec9c4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ config RISCV
select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
select ARCH_WANT_OPTIONAL_GPIOLIB
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
select HAVE_DMA_API_DEBUG
select HAVE_DMA_CONTIGUOUS
select HAVE_GENERIC_DMA_COHERENT
Expand All @@ -43,6 +44,10 @@ config MMU
config ARCH_PHYS_ADDR_T_64BIT
def_bool y

config ZONE_DMA32
bool
default y

config ARCH_DMA_ADDR_T_64BIT
def_bool y

Expand Down
9 changes: 9 additions & 0 deletions arch/riscv/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ static void __init setup_bootmem(void)
early_init_fdt_scan_reserved_mem();
memblock_allow_resize();
memblock_dump_all();

for_each_memblock(memory, reg) {
unsigned long start_pfn = memblock_region_memory_base_pfn(reg);
unsigned long end_pfn = memblock_region_memory_end_pfn(reg);

memblock_set_node(PFN_PHYS(start_pfn),
PFN_PHYS(end_pfn - start_pfn),
&memblock.memory, 0);
}
}

void __init setup_arch(char **cmdline_p)
Expand Down
10 changes: 6 additions & 4 deletions arch/riscv/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/initrd.h>
#include <linux/memblock.h>
#include <linux/swap.h>
#include <linux/sizes.h>

#include <asm/tlbflush.h>
#include <asm/sections.h>
Expand All @@ -25,11 +26,12 @@

static void __init zone_sizes_init(void)
{
unsigned long zones_size[MAX_NR_ZONES];
unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };

memset(zones_size, 0, sizeof(zones_size));
zones_size[ZONE_NORMAL] = max_mapnr;
free_area_init_node(0, zones_size, pfn_base, NULL);
max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;

free_area_init_nodes(max_zone_pfns);
}

void setup_zero_page(void)
Expand Down

0 comments on commit 5ec9c4f

Please sign in to comment.