xref: /openbmc/linux/arch/riscv/mm/hugetlbpage.c (revision ae94da898133947c2d1f005da10838478e4548db)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/hugetlb.h>
3 #include <linux/err.h>
4 
5 int pud_huge(pud_t pud)
6 {
7 	return pud_leaf(pud);
8 }
9 
10 int pmd_huge(pmd_t pmd)
11 {
12 	return pmd_leaf(pmd);
13 }
14 
15 bool __init arch_hugetlb_valid_size(unsigned long size)
16 {
17 	if (size == HPAGE_SIZE)
18 		return true;
19 	else if (IS_ENABLED(CONFIG_64BIT) && size == PUD_SIZE)
20 		return true;
21 	else
22 		return false;
23 }
24 
25 static __init int setup_hugepagesz(char *opt)
26 {
27 	unsigned long ps = memparse(opt, &opt);
28 
29 	if (arch_hugetlb_valid_size(ps)) {
30 		hugetlb_add_hstate(ilog2(ps) - PAGE_SHIFT);
31 		return 1;
32 	}
33 
34 	hugetlb_bad_size();
35 	pr_err("hugepagesz: Unsupported page size %lu M\n", ps >> 20);
36 	return 0;
37 
38 }
39 __setup("hugepagesz=", setup_hugepagesz);
40 
41 #ifdef CONFIG_CONTIG_ALLOC
42 static __init int gigantic_pages_init(void)
43 {
44 	/* With CONTIG_ALLOC, we can allocate gigantic pages at runtime */
45 	if (IS_ENABLED(CONFIG_64BIT) && !size_to_hstate(1UL << PUD_SHIFT))
46 		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
47 	return 0;
48 }
49 arch_initcall(gigantic_pages_init);
50 #endif
51