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/init.h> 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 /* 42ca9153a3SIlya Yanok * We use one full pte table with 4K pages. And with 16K/64K pages pte 43ca9153a3SIlya Yanok * table covers enough memory (32MB and 512MB resp.) that both FIXMAP 44ca9153a3SIlya Yanok * and PKMAP can be placed in single pte table. We use 1024 pages for 45ca9153a3SIlya Yanok * PKMAP in case of 16K/64K pages. 46ca9153a3SIlya Yanok */ 47ca9153a3SIlya Yanok #ifdef CONFIG_PPC_4K_PAGES 48ca9153a3SIlya Yanok #define PKMAP_ORDER PTE_SHIFT 49ca9153a3SIlya Yanok #else 50ca9153a3SIlya Yanok #define PKMAP_ORDER 10 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); 64b8b572e1SStephen Rothwell 65b8b572e1SStephen Rothwell static inline void *kmap(struct page *page) 66b8b572e1SStephen Rothwell { 67b8b572e1SStephen Rothwell might_sleep(); 68b8b572e1SStephen Rothwell if (!PageHighMem(page)) 69b8b572e1SStephen Rothwell return page_address(page); 70b8b572e1SStephen Rothwell return kmap_high(page); 71b8b572e1SStephen Rothwell } 72b8b572e1SStephen Rothwell 73b8b572e1SStephen Rothwell static inline void kunmap(struct page *page) 74b8b572e1SStephen Rothwell { 75b8b572e1SStephen Rothwell BUG_ON(in_interrupt()); 76b8b572e1SStephen Rothwell if (!PageHighMem(page)) 77b8b572e1SStephen Rothwell return; 78b8b572e1SStephen Rothwell kunmap_high(page); 79b8b572e1SStephen Rothwell } 80b8b572e1SStephen Rothwell 81b8b572e1SStephen Rothwell /* 82b8b572e1SStephen Rothwell * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap 83b8b572e1SStephen Rothwell * gives a more generic (and caching) interface. But kmap_atomic can 84b8b572e1SStephen Rothwell * be used in IRQ contexts, so in some (very limited) cases we need 85b8b572e1SStephen Rothwell * it. 86b8b572e1SStephen Rothwell */ 87b8b572e1SStephen Rothwell static inline void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot) 88b8b572e1SStephen Rothwell { 89b8b572e1SStephen Rothwell unsigned int idx; 90b8b572e1SStephen Rothwell unsigned long vaddr; 91b8b572e1SStephen Rothwell 92b8b572e1SStephen Rothwell /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */ 93b8b572e1SStephen Rothwell pagefault_disable(); 94b8b572e1SStephen Rothwell if (!PageHighMem(page)) 95b8b572e1SStephen Rothwell return page_address(page); 96b8b572e1SStephen Rothwell 97b8b572e1SStephen Rothwell idx = type + KM_TYPE_NR*smp_processor_id(); 98b8b572e1SStephen Rothwell vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); 99b8b572e1SStephen Rothwell #ifdef CONFIG_DEBUG_HIGHMEM 100b8b572e1SStephen Rothwell BUG_ON(!pte_none(*(kmap_pte-idx))); 101b8b572e1SStephen Rothwell #endif 1029bf2b5cdSKumar Gala __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot)); 103f048aaceSBenjamin Herrenschmidt local_flush_tlb_page(NULL, vaddr); 104b8b572e1SStephen Rothwell 105b8b572e1SStephen Rothwell return (void*) vaddr; 106b8b572e1SStephen Rothwell } 107b8b572e1SStephen Rothwell 108b8b572e1SStephen Rothwell static inline void *kmap_atomic(struct page *page, enum km_type type) 109b8b572e1SStephen Rothwell { 110b8b572e1SStephen Rothwell return kmap_atomic_prot(page, type, kmap_prot); 111b8b572e1SStephen Rothwell } 112b8b572e1SStephen Rothwell 113b8b572e1SStephen Rothwell static inline void kunmap_atomic(void *kvaddr, enum km_type type) 114b8b572e1SStephen Rothwell { 115b8b572e1SStephen Rothwell #ifdef CONFIG_DEBUG_HIGHMEM 116b8b572e1SStephen Rothwell unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK; 117b8b572e1SStephen Rothwell enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id(); 118b8b572e1SStephen Rothwell 119b8b572e1SStephen Rothwell if (vaddr < __fix_to_virt(FIX_KMAP_END)) { 120b8b572e1SStephen Rothwell pagefault_enable(); 121b8b572e1SStephen Rothwell return; 122b8b572e1SStephen Rothwell } 123b8b572e1SStephen Rothwell 124b8b572e1SStephen Rothwell BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx)); 125b8b572e1SStephen Rothwell 126b8b572e1SStephen Rothwell /* 127b8b572e1SStephen Rothwell * force other mappings to Oops if they'll try to access 128b8b572e1SStephen Rothwell * this pte without first remap it 129b8b572e1SStephen Rothwell */ 130b8b572e1SStephen Rothwell pte_clear(&init_mm, vaddr, kmap_pte-idx); 131f048aaceSBenjamin Herrenschmidt local_flush_tlb_page(NULL, vaddr); 132b8b572e1SStephen Rothwell #endif 133b8b572e1SStephen Rothwell pagefault_enable(); 134b8b572e1SStephen Rothwell } 135b8b572e1SStephen Rothwell 136b8b572e1SStephen Rothwell static inline struct page *kmap_atomic_to_page(void *ptr) 137b8b572e1SStephen Rothwell { 138b8b572e1SStephen Rothwell unsigned long idx, vaddr = (unsigned long) ptr; 139b8b572e1SStephen Rothwell pte_t *pte; 140b8b572e1SStephen Rothwell 141b8b572e1SStephen Rothwell if (vaddr < FIXADDR_START) 142b8b572e1SStephen Rothwell return virt_to_page(ptr); 143b8b572e1SStephen Rothwell 144b8b572e1SStephen Rothwell idx = virt_to_fix(vaddr); 145b8b572e1SStephen Rothwell pte = kmap_pte - (idx - FIX_KMAP_BEGIN); 146b8b572e1SStephen Rothwell return pte_page(*pte); 147b8b572e1SStephen Rothwell } 148b8b572e1SStephen Rothwell 149b8b572e1SStephen Rothwell #define flush_cache_kmaps() flush_cache_all() 150b8b572e1SStephen Rothwell 151b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 152b8b572e1SStephen Rothwell 153b8b572e1SStephen Rothwell #endif /* _ASM_HIGHMEM_H */ 154