[XTENSA] Use the generic version of get_order
[powerpc.git] / include / asm-xtensa / page.h
1 /*
2  * include/asm-xtensa/page.h
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version2 as
6  * published by the Free Software Foundation.
7  *
8  * Copyright (C) 2001 - 2007 Tensilica Inc.
9  */
10
11 #ifndef _XTENSA_PAGE_H
12 #define _XTENSA_PAGE_H
13
14 #ifdef __KERNEL__
15
16 #include <asm/processor.h>
17 #include <asm/types.h>
18
19 /*
20  * Fixed TLB translations in the processor.
21  */
22
23 #define XCHAL_KSEG_CACHED_VADDR 0xd0000000
24 #define XCHAL_KSEG_BYPASS_VADDR 0xd8000000
25 #define XCHAL_KSEG_PADDR        0x00000000
26 #define XCHAL_KSEG_SIZE         0x08000000
27
28 /*
29  * PAGE_SHIFT determines the page size
30  * PAGE_ALIGN(x) aligns the pointer to the (next) page boundary
31  */
32
33 #define PAGE_SHIFT              12
34 #define PAGE_SIZE               (__XTENSA_UL_CONST(1) << PAGE_SHIFT)
35 #define PAGE_MASK               (~(PAGE_SIZE-1))
36 #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE - 1) & PAGE_MASK)
37
38 #define PAGE_OFFSET             XCHAL_KSEG_CACHED_VADDR
39 #define MAX_MEM_PFN             XCHAL_KSEG_SIZE
40 #define PGTABLE_START           0x80000000
41
42 #ifdef __ASSEMBLY__
43
44 #define __pgprot(x)     (x)
45
46 #else
47
48 /*
49  * These are used to make use of C type-checking..
50  */
51
52 typedef struct { unsigned long pte; } pte_t;            /* page table entry */
53 typedef struct { unsigned long pgd; } pgd_t;            /* PGD table entry */
54 typedef struct { unsigned long pgprot; } pgprot_t;
55
56 #define pte_val(x)      ((x).pte)
57 #define pgd_val(x)      ((x).pgd)
58 #define pgprot_val(x)   ((x).pgprot)
59
60 #define __pte(x)        ((pte_t) { (x) } )
61 #define __pgd(x)        ((pgd_t) { (x) } )
62 #define __pgprot(x)     ((pgprot_t) { (x) } )
63
64 /*
65  * Pure 2^n version of get_order
66  * Use 'nsau' instructions if supported by the processor or the generic version.
67  */
68
69 #if XCHAL_HAVE_NSA
70
71 static inline __attribute_const__ int get_order(unsigned long size)
72 {
73         int lz;
74         asm ("nsau %0, %1" : "=r" (lz) : "r" ((size - 1) >> PAGE_SHIFT));
75         return 32 - lz;
76 }
77
78 #else
79
80 # include <asm-generic/page.h>
81
82 #endif
83
84 struct page;
85 extern void clear_page(void *page);
86 extern void copy_page(void *to, void *from);
87
88 /*
89  * If we have cache aliasing and writeback caches, we might have to do
90  * some extra work
91  */
92
93 #if (DCACHE_WAY_SIZE > PAGE_SIZE)
94 void clear_user_page(void *addr, unsigned long vaddr, struct page* page);
95 void copy_user_page(void *to,void* from,unsigned long vaddr,struct page* page);
96 #else
97 # define clear_user_page(page,vaddr,pg)         clear_page(page)
98 # define copy_user_page(to, from, vaddr, pg)    copy_page(to, from)
99 #endif
100
101 /*
102  * This handles the memory map.  We handle pages at
103  * XCHAL_KSEG_CACHED_VADDR for kernels with 32 bit address space.
104  * These macros are for conversion of kernel address, not user
105  * addresses.
106  */
107
108 #define __pa(x)                 ((unsigned long) (x) - PAGE_OFFSET)
109 #define __va(x)                 ((void *)((unsigned long) (x) + PAGE_OFFSET))
110 #define pfn_valid(pfn)          ((unsigned long)pfn < max_mapnr)
111 #ifdef CONFIG_DISCONTIGMEM
112 # error CONFIG_DISCONTIGMEM not supported
113 #endif
114
115 #define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
116 #define page_to_virt(page)      __va(page_to_pfn(page) << PAGE_SHIFT)
117 #define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
118 #define page_to_phys(page)      (page_to_pfn(page) << PAGE_SHIFT)
119
120 #define WANT_PAGE_VIRTUAL
121
122
123 #endif /* __ASSEMBLY__ */
124
125 #define VM_DATA_DEFAULT_FLAGS   (VM_READ | VM_WRITE | VM_EXEC | \
126                                  VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
127
128 #include <asm-generic/memory_model.h>
129 #endif /* __KERNEL__ */
130 #endif /* _XTENSA_PAGE_H */