xref: /openbmc/linux/arch/riscv/mm/hugetlbpage.c (revision 6c33a6f4)
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_present(pud) &&
8 		(pud_val(pud) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
9 }
10 
11 int pmd_huge(pmd_t pmd)
12 {
13 	return pmd_present(pmd) &&
14 		(pmd_val(pmd) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
15 }
16 
17 static __init int setup_hugepagesz(char *opt)
18 {
19 	unsigned long ps = memparse(opt, &opt);
20 
21 	if (ps == HPAGE_SIZE) {
22 		hugetlb_add_hstate(HPAGE_SHIFT - PAGE_SHIFT);
23 	} else if (IS_ENABLED(CONFIG_64BIT) && ps == PUD_SIZE) {
24 		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
25 	} else {
26 		hugetlb_bad_size();
27 		pr_err("hugepagesz: Unsupported page size %lu M\n", ps >> 20);
28 		return 0;
29 	}
30 
31 	return 1;
32 }
33 __setup("hugepagesz=", setup_hugepagesz);
34 
35 #ifdef CONFIG_CONTIG_ALLOC
36 static __init int gigantic_pages_init(void)
37 {
38 	/* With CONTIG_ALLOC, we can allocate gigantic pages at runtime */
39 	if (IS_ENABLED(CONFIG_64BIT) && !size_to_hstate(1UL << PUD_SHIFT))
40 		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
41 	return 0;
42 }
43 arch_initcall(gigantic_pages_init);
44 #endif
45