xref: /openbmc/linux/arch/powerpc/include/asm/highmem.h (revision 850f6ac3)
1b8b572e1SStephen Rothwell /*
2b8b572e1SStephen Rothwell  * highmem.h: virtual kernel memory mappings for high memory
3b8b572e1SStephen Rothwell  *
4b8b572e1SStephen Rothwell  * PowerPC version, stolen from the i386 version.
5b8b572e1SStephen Rothwell  *
6b8b572e1SStephen Rothwell  * Used in CONFIG_HIGHMEM systems for memory pages which
7b8b572e1SStephen Rothwell  * are not addressable by direct kernel virtual addresses.
8b8b572e1SStephen Rothwell  *
9b8b572e1SStephen Rothwell  * Copyright (C) 1999 Gerhard Wichert, Siemens AG
10b8b572e1SStephen Rothwell  *		      Gerhard.Wichert@pdb.siemens.de
11b8b572e1SStephen Rothwell  *
12b8b572e1SStephen Rothwell  *
13b8b572e1SStephen Rothwell  * Redesigned the x86 32-bit VM architecture to deal with
14b8b572e1SStephen Rothwell  * up to 16 Terrabyte physical memory. With current x86 CPUs
15b8b572e1SStephen Rothwell  * we now support up to 64 Gigabytes physical RAM.
16b8b572e1SStephen Rothwell  *
17b8b572e1SStephen Rothwell  * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
18b8b572e1SStephen Rothwell  */
19b8b572e1SStephen Rothwell 
20b8b572e1SStephen Rothwell #ifndef _ASM_HIGHMEM_H
21b8b572e1SStephen Rothwell #define _ASM_HIGHMEM_H
22b8b572e1SStephen Rothwell 
23b8b572e1SStephen Rothwell #ifdef __KERNEL__
24b8b572e1SStephen Rothwell 
25b8b572e1SStephen Rothwell #include <linux/interrupt.h>
26b8b572e1SStephen Rothwell #include <asm/kmap_types.h>
27b8b572e1SStephen Rothwell #include <asm/tlbflush.h>
28b8b572e1SStephen Rothwell #include <asm/page.h>
29b8b572e1SStephen Rothwell #include <asm/fixmap.h>
30b8b572e1SStephen Rothwell 
31b8b572e1SStephen Rothwell extern pte_t *kmap_pte;
32b8b572e1SStephen Rothwell extern pgprot_t kmap_prot;
33b8b572e1SStephen Rothwell extern pte_t *pkmap_page_table;
34b8b572e1SStephen Rothwell 
35b8b572e1SStephen Rothwell /*
36b8b572e1SStephen Rothwell  * Right now we initialize only a single pte table. It can be extended
37b8b572e1SStephen Rothwell  * easily, subsequent pte tables have to be allocated in one physical
38b8b572e1SStephen Rothwell  * chunk of RAM.
39b8b572e1SStephen Rothwell  */
40ca9153a3SIlya Yanok /*
41e1240122SYuri Tikhonov  * We use one full pte table with 4K pages. And with 16K/64K/256K pages pte
42e1240122SYuri Tikhonov  * table covers enough memory (32MB/512MB/2GB resp.), so that both FIXMAP
43e1240122SYuri Tikhonov  * and PKMAP can be placed in a single pte table. We use 512 pages for PKMAP
44e1240122SYuri Tikhonov  * in case of 16K/64K/256K page sizes.
45ca9153a3SIlya Yanok  */
46ca9153a3SIlya Yanok #ifdef CONFIG_PPC_4K_PAGES
47ca9153a3SIlya Yanok #define PKMAP_ORDER	PTE_SHIFT
48ca9153a3SIlya Yanok #else
49e1240122SYuri Tikhonov #define PKMAP_ORDER	9
50ca9153a3SIlya Yanok #endif
51ca9153a3SIlya Yanok #define LAST_PKMAP	(1 << PKMAP_ORDER)
52ca9153a3SIlya Yanok #ifndef CONFIG_PPC_4K_PAGES
53ca9153a3SIlya Yanok #define PKMAP_BASE	(FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1))
54ca9153a3SIlya Yanok #else
55b8b572e1SStephen Rothwell #define PKMAP_BASE	((FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK)
56ca9153a3SIlya Yanok #endif
57ca9153a3SIlya Yanok #define LAST_PKMAP_MASK	(LAST_PKMAP-1)
58b8b572e1SStephen Rothwell #define PKMAP_NR(virt)  ((virt-PKMAP_BASE) >> PAGE_SHIFT)
59b8b572e1SStephen Rothwell #define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
60b8b572e1SStephen Rothwell 
61b8b572e1SStephen Rothwell extern void *kmap_high(struct page *page);
62b8b572e1SStephen Rothwell extern void kunmap_high(struct page *page);
63850f6ac3SBenjamin Herrenschmidt extern void *kmap_atomic_prot(struct page *page, enum km_type type,
64850f6ac3SBenjamin Herrenschmidt 			      pgprot_t prot);
65850f6ac3SBenjamin Herrenschmidt extern void kunmap_atomic(void *kvaddr, enum km_type type);
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 
83b8b572e1SStephen Rothwell static inline void *kmap_atomic(struct page *page, enum km_type type)
84b8b572e1SStephen Rothwell {
85b8b572e1SStephen Rothwell 	return kmap_atomic_prot(page, type, kmap_prot);
86b8b572e1SStephen Rothwell }
87b8b572e1SStephen Rothwell 
88b8b572e1SStephen Rothwell static inline struct page *kmap_atomic_to_page(void *ptr)
89b8b572e1SStephen Rothwell {
90b8b572e1SStephen Rothwell 	unsigned long idx, vaddr = (unsigned long) ptr;
91b8b572e1SStephen Rothwell 	pte_t *pte;
92b8b572e1SStephen Rothwell 
93b8b572e1SStephen Rothwell 	if (vaddr < FIXADDR_START)
94b8b572e1SStephen Rothwell 		return virt_to_page(ptr);
95b8b572e1SStephen Rothwell 
96b8b572e1SStephen Rothwell 	idx = virt_to_fix(vaddr);
97b8b572e1SStephen Rothwell 	pte = kmap_pte - (idx - FIX_KMAP_BEGIN);
98b8b572e1SStephen Rothwell 	return pte_page(*pte);
99b8b572e1SStephen Rothwell }
100b8b572e1SStephen Rothwell 
101850f6ac3SBenjamin Herrenschmidt 
102b8b572e1SStephen Rothwell #define flush_cache_kmaps()	flush_cache_all()
103b8b572e1SStephen Rothwell 
104b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
105b8b572e1SStephen Rothwell 
106b8b572e1SStephen Rothwell #endif /* _ASM_HIGHMEM_H */
107