xref: /openbmc/linux/arch/powerpc/include/asm/highmem.h (revision b2441318)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b8b572e1SStephen Rothwell /*
3b8b572e1SStephen Rothwell  * highmem.h: virtual kernel memory mappings for high memory
4b8b572e1SStephen Rothwell  *
5b8b572e1SStephen Rothwell  * PowerPC version, stolen from the i386 version.
6b8b572e1SStephen Rothwell  *
7b8b572e1SStephen Rothwell  * Used in CONFIG_HIGHMEM systems for memory pages which
8b8b572e1SStephen Rothwell  * are not addressable by direct kernel virtual addresses.
9b8b572e1SStephen Rothwell  *
10b8b572e1SStephen Rothwell  * Copyright (C) 1999 Gerhard Wichert, Siemens AG
11b8b572e1SStephen Rothwell  *		      Gerhard.Wichert@pdb.siemens.de
12b8b572e1SStephen Rothwell  *
13b8b572e1SStephen Rothwell  *
14b8b572e1SStephen Rothwell  * Redesigned the x86 32-bit VM architecture to deal with
15b8b572e1SStephen Rothwell  * up to 16 Terrabyte physical memory. With current x86 CPUs
16b8b572e1SStephen Rothwell  * we now support up to 64 Gigabytes physical RAM.
17b8b572e1SStephen Rothwell  *
18b8b572e1SStephen Rothwell  * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
19b8b572e1SStephen Rothwell  */
20b8b572e1SStephen Rothwell 
21b8b572e1SStephen Rothwell #ifndef _ASM_HIGHMEM_H
22b8b572e1SStephen Rothwell #define _ASM_HIGHMEM_H
23b8b572e1SStephen Rothwell 
24b8b572e1SStephen Rothwell #ifdef __KERNEL__
25b8b572e1SStephen Rothwell 
26b8b572e1SStephen Rothwell #include <linux/interrupt.h>
27b8b572e1SStephen Rothwell #include <asm/kmap_types.h>
28b8b572e1SStephen Rothwell #include <asm/tlbflush.h>
29b8b572e1SStephen Rothwell #include <asm/page.h>
30b8b572e1SStephen Rothwell #include <asm/fixmap.h>
31b8b572e1SStephen Rothwell 
32b8b572e1SStephen Rothwell extern pte_t *kmap_pte;
33b8b572e1SStephen Rothwell extern pgprot_t kmap_prot;
34b8b572e1SStephen Rothwell extern pte_t *pkmap_page_table;
35b8b572e1SStephen Rothwell 
36b8b572e1SStephen Rothwell /*
37b8b572e1SStephen Rothwell  * Right now we initialize only a single pte table. It can be extended
38b8b572e1SStephen Rothwell  * easily, subsequent pte tables have to be allocated in one physical
39b8b572e1SStephen Rothwell  * chunk of RAM.
40b8b572e1SStephen Rothwell  */
41ca9153a3SIlya Yanok /*
42e1240122SYuri Tikhonov  * We use one full pte table with 4K pages. And with 16K/64K/256K pages pte
43e1240122SYuri Tikhonov  * table covers enough memory (32MB/512MB/2GB resp.), so that both FIXMAP
44e1240122SYuri Tikhonov  * and PKMAP can be placed in a single pte table. We use 512 pages for PKMAP
45e1240122SYuri Tikhonov  * in case of 16K/64K/256K page sizes.
46ca9153a3SIlya Yanok  */
47ca9153a3SIlya Yanok #ifdef CONFIG_PPC_4K_PAGES
48ca9153a3SIlya Yanok #define PKMAP_ORDER	PTE_SHIFT
49ca9153a3SIlya Yanok #else
50e1240122SYuri Tikhonov #define PKMAP_ORDER	9
51ca9153a3SIlya Yanok #endif
52ca9153a3SIlya Yanok #define LAST_PKMAP	(1 << PKMAP_ORDER)
53ca9153a3SIlya Yanok #ifndef CONFIG_PPC_4K_PAGES
54ca9153a3SIlya Yanok #define PKMAP_BASE	(FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1))
55ca9153a3SIlya Yanok #else
56b8b572e1SStephen Rothwell #define PKMAP_BASE	((FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK)
57ca9153a3SIlya Yanok #endif
58ca9153a3SIlya Yanok #define LAST_PKMAP_MASK	(LAST_PKMAP-1)
59b8b572e1SStephen Rothwell #define PKMAP_NR(virt)  ((virt-PKMAP_BASE) >> PAGE_SHIFT)
60b8b572e1SStephen Rothwell #define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
61b8b572e1SStephen Rothwell 
62b8b572e1SStephen Rothwell extern void *kmap_high(struct page *page);
63b8b572e1SStephen Rothwell extern void kunmap_high(struct page *page);
643e4d3af5SPeter Zijlstra extern void *kmap_atomic_prot(struct page *page, pgprot_t prot);
653e4d3af5SPeter Zijlstra extern void __kunmap_atomic(void *kvaddr);
66b8b572e1SStephen Rothwell 
67b8b572e1SStephen Rothwell static inline void *kmap(struct page *page)
68b8b572e1SStephen Rothwell {
69b8b572e1SStephen Rothwell 	might_sleep();
70b8b572e1SStephen Rothwell 	if (!PageHighMem(page))
71b8b572e1SStephen Rothwell 		return page_address(page);
72b8b572e1SStephen Rothwell 	return kmap_high(page);
73b8b572e1SStephen Rothwell }
74b8b572e1SStephen Rothwell 
75b8b572e1SStephen Rothwell static inline void kunmap(struct page *page)
76b8b572e1SStephen Rothwell {
77b8b572e1SStephen Rothwell 	BUG_ON(in_interrupt());
78b8b572e1SStephen Rothwell 	if (!PageHighMem(page))
79b8b572e1SStephen Rothwell 		return;
80b8b572e1SStephen Rothwell 	kunmap_high(page);
81b8b572e1SStephen Rothwell }
82b8b572e1SStephen Rothwell 
83a24401bcSCong Wang static inline void *kmap_atomic(struct page *page)
84b8b572e1SStephen Rothwell {
853e4d3af5SPeter Zijlstra 	return kmap_atomic_prot(page, kmap_prot);
86b8b572e1SStephen Rothwell }
87b8b572e1SStephen Rothwell 
88850f6ac3SBenjamin Herrenschmidt 
89b8b572e1SStephen Rothwell #define flush_cache_kmaps()	flush_cache_all()
90b8b572e1SStephen Rothwell 
91b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
92b8b572e1SStephen Rothwell 
93b8b572e1SStephen Rothwell #endif /* _ASM_HIGHMEM_H */
94