xref: /OK3568_Linux_fs/kernel/arch/xtensa/include/asm/page.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * include/asm-xtensa/page.h
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
5*4882a593Smuzhiyun  * it under the terms of the GNU General Public License version2 as
6*4882a593Smuzhiyun  * published by the Free Software Foundation.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 2001 - 2007 Tensilica Inc.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _XTENSA_PAGE_H
12*4882a593Smuzhiyun #define _XTENSA_PAGE_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <asm/processor.h>
15*4882a593Smuzhiyun #include <asm/types.h>
16*4882a593Smuzhiyun #include <asm/cache.h>
17*4882a593Smuzhiyun #include <asm/kmem_layout.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun  * PAGE_SHIFT determines the page size
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define PAGE_SHIFT	12
24*4882a593Smuzhiyun #define PAGE_SIZE	(__XTENSA_UL_CONST(1) << PAGE_SHIFT)
25*4882a593Smuzhiyun #define PAGE_MASK	(~(PAGE_SIZE-1))
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifdef CONFIG_MMU
28*4882a593Smuzhiyun #define PAGE_OFFSET	XCHAL_KSEG_CACHED_VADDR
29*4882a593Smuzhiyun #define PHYS_OFFSET	XCHAL_KSEG_PADDR
30*4882a593Smuzhiyun #define MAX_LOW_PFN	(PHYS_PFN(XCHAL_KSEG_PADDR) + \
31*4882a593Smuzhiyun 			 PHYS_PFN(XCHAL_KSEG_SIZE))
32*4882a593Smuzhiyun #else
33*4882a593Smuzhiyun #define PAGE_OFFSET	_AC(CONFIG_DEFAULT_MEM_START, UL)
34*4882a593Smuzhiyun #define PHYS_OFFSET	_AC(CONFIG_DEFAULT_MEM_START, UL)
35*4882a593Smuzhiyun #define MAX_LOW_PFN	PHYS_PFN(0xfffffffful)
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * Cache aliasing:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * If the cache size for one way is greater than the page size, we have to
42*4882a593Smuzhiyun  * deal with cache aliasing. The cache index is wider than the page size:
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * |    |cache| cache index
45*4882a593Smuzhiyun  * | pfn  |off|	virtual address
46*4882a593Smuzhiyun  * |xxxx:X|zzz|
47*4882a593Smuzhiyun  * |    : |   |
48*4882a593Smuzhiyun  * | \  / |   |
49*4882a593Smuzhiyun  * |trans.|   |
50*4882a593Smuzhiyun  * | /  \ |   |
51*4882a593Smuzhiyun  * |yyyy:Y|zzz|	physical address
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * When the page number is translated to the physical page address, the lowest
54*4882a593Smuzhiyun  * bit(s) (X) that are part of the cache index are also translated (Y).
55*4882a593Smuzhiyun  * If this translation changes bit(s) (X), the cache index is also afected,
56*4882a593Smuzhiyun  * thus resulting in a different cache line than before.
57*4882a593Smuzhiyun  * The kernel does not provide a mechanism to ensure that the page color
58*4882a593Smuzhiyun  * (represented by this bit) remains the same when allocated or when pages
59*4882a593Smuzhiyun  * are remapped. When user pages are mapped into kernel space, the color of
60*4882a593Smuzhiyun  * the page might also change.
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * We use the address space VMALLOC_END ... VMALLOC_END + DCACHE_WAY_SIZE * 2
63*4882a593Smuzhiyun  * to temporarily map a patch so we can match the color.
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #if DCACHE_WAY_SIZE > PAGE_SIZE
67*4882a593Smuzhiyun # define DCACHE_ALIAS_ORDER	(DCACHE_WAY_SHIFT - PAGE_SHIFT)
68*4882a593Smuzhiyun # define DCACHE_ALIAS_MASK	(PAGE_MASK & (DCACHE_WAY_SIZE - 1))
69*4882a593Smuzhiyun # define DCACHE_ALIAS(a)	(((a) & DCACHE_ALIAS_MASK) >> PAGE_SHIFT)
70*4882a593Smuzhiyun # define DCACHE_ALIAS_EQ(a,b)	((((a) ^ (b)) & DCACHE_ALIAS_MASK) == 0)
71*4882a593Smuzhiyun #else
72*4882a593Smuzhiyun # define DCACHE_ALIAS_ORDER	0
73*4882a593Smuzhiyun # define DCACHE_ALIAS(a)	((void)(a), 0)
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun #define DCACHE_N_COLORS		(1 << DCACHE_ALIAS_ORDER)
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun #if ICACHE_WAY_SIZE > PAGE_SIZE
78*4882a593Smuzhiyun # define ICACHE_ALIAS_ORDER	(ICACHE_WAY_SHIFT - PAGE_SHIFT)
79*4882a593Smuzhiyun # define ICACHE_ALIAS_MASK	(PAGE_MASK & (ICACHE_WAY_SIZE - 1))
80*4882a593Smuzhiyun # define ICACHE_ALIAS(a)	(((a) & ICACHE_ALIAS_MASK) >> PAGE_SHIFT)
81*4882a593Smuzhiyun # define ICACHE_ALIAS_EQ(a,b)	((((a) ^ (b)) & ICACHE_ALIAS_MASK) == 0)
82*4882a593Smuzhiyun #else
83*4882a593Smuzhiyun # define ICACHE_ALIAS_ORDER	0
84*4882a593Smuzhiyun #endif
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #ifdef __ASSEMBLY__
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define __pgprot(x)	(x)
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #else
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /*
94*4882a593Smuzhiyun  * These are used to make use of C type-checking..
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun typedef struct { unsigned long pte; } pte_t;		/* page table entry */
98*4882a593Smuzhiyun typedef struct { unsigned long pgd; } pgd_t;		/* PGD table entry */
99*4882a593Smuzhiyun typedef struct { unsigned long pgprot; } pgprot_t;
100*4882a593Smuzhiyun typedef struct page *pgtable_t;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define pte_val(x)	((x).pte)
103*4882a593Smuzhiyun #define pgd_val(x)	((x).pgd)
104*4882a593Smuzhiyun #define pgprot_val(x)	((x).pgprot)
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define __pte(x)	((pte_t) { (x) } )
107*4882a593Smuzhiyun #define __pgd(x)	((pgd_t) { (x) } )
108*4882a593Smuzhiyun #define __pgprot(x)	((pgprot_t) { (x) } )
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /*
111*4882a593Smuzhiyun  * Pure 2^n version of get_order
112*4882a593Smuzhiyun  * Use 'nsau' instructions if supported by the processor or the generic version.
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #if XCHAL_HAVE_NSA
116*4882a593Smuzhiyun 
get_order(unsigned long size)117*4882a593Smuzhiyun static inline __attribute_const__ int get_order(unsigned long size)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	int lz;
120*4882a593Smuzhiyun 	asm ("nsau %0, %1" : "=r" (lz) : "r" ((size - 1) >> PAGE_SHIFT));
121*4882a593Smuzhiyun 	return 32 - lz;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun #else
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun # include <asm-generic/getorder.h>
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #endif
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun struct page;
131*4882a593Smuzhiyun struct vm_area_struct;
132*4882a593Smuzhiyun extern void clear_page(void *page);
133*4882a593Smuzhiyun extern void copy_page(void *to, void *from);
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun  * If we have cache aliasing and writeback caches, we might have to do
137*4882a593Smuzhiyun  * some extra work
138*4882a593Smuzhiyun  */
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun #if defined(CONFIG_MMU) && DCACHE_WAY_SIZE > PAGE_SIZE
141*4882a593Smuzhiyun extern void clear_page_alias(void *vaddr, unsigned long paddr);
142*4882a593Smuzhiyun extern void copy_page_alias(void *to, void *from,
143*4882a593Smuzhiyun 			    unsigned long to_paddr, unsigned long from_paddr);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun #define clear_user_highpage clear_user_highpage
146*4882a593Smuzhiyun void clear_user_highpage(struct page *page, unsigned long vaddr);
147*4882a593Smuzhiyun #define __HAVE_ARCH_COPY_USER_HIGHPAGE
148*4882a593Smuzhiyun void copy_user_highpage(struct page *to, struct page *from,
149*4882a593Smuzhiyun 			unsigned long vaddr, struct vm_area_struct *vma);
150*4882a593Smuzhiyun #else
151*4882a593Smuzhiyun # define clear_user_page(page, vaddr, pg)	clear_page(page)
152*4882a593Smuzhiyun # define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
153*4882a593Smuzhiyun #endif
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun /*
156*4882a593Smuzhiyun  * This handles the memory map.  We handle pages at
157*4882a593Smuzhiyun  * XCHAL_KSEG_CACHED_VADDR for kernels with 32 bit address space.
158*4882a593Smuzhiyun  * These macros are for conversion of kernel address, not user
159*4882a593Smuzhiyun  * addresses.
160*4882a593Smuzhiyun  */
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun #define ARCH_PFN_OFFSET		(PHYS_OFFSET >> PAGE_SHIFT)
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #ifdef CONFIG_MMU
___pa(unsigned long va)165*4882a593Smuzhiyun static inline unsigned long ___pa(unsigned long va)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun 	unsigned long off = va - PAGE_OFFSET;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 	if (off >= XCHAL_KSEG_SIZE)
170*4882a593Smuzhiyun 		off -= XCHAL_KSEG_SIZE;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun #ifndef CONFIG_XIP_KERNEL
173*4882a593Smuzhiyun 	return off + PHYS_OFFSET;
174*4882a593Smuzhiyun #else
175*4882a593Smuzhiyun 	if (off < XCHAL_KSEG_SIZE)
176*4882a593Smuzhiyun 		return off + PHYS_OFFSET;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	off -= XCHAL_KSEG_SIZE;
179*4882a593Smuzhiyun 	if (off >= XCHAL_KIO_SIZE)
180*4882a593Smuzhiyun 		off -= XCHAL_KIO_SIZE;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	return off + XCHAL_KIO_PADDR;
183*4882a593Smuzhiyun #endif
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun #define __pa(x)	___pa((unsigned long)(x))
186*4882a593Smuzhiyun #else
187*4882a593Smuzhiyun #define __pa(x)	\
188*4882a593Smuzhiyun 	((unsigned long) (x) - PAGE_OFFSET + PHYS_OFFSET)
189*4882a593Smuzhiyun #endif
190*4882a593Smuzhiyun #define __va(x)	\
191*4882a593Smuzhiyun 	((void *)((unsigned long) (x) - PHYS_OFFSET + PAGE_OFFSET))
192*4882a593Smuzhiyun #define pfn_valid(pfn) \
193*4882a593Smuzhiyun 	((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun #ifdef CONFIG_DISCONTIGMEM
196*4882a593Smuzhiyun # error CONFIG_DISCONTIGMEM not supported
197*4882a593Smuzhiyun #endif
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
200*4882a593Smuzhiyun #define page_to_virt(page)	__va(page_to_pfn(page) << PAGE_SHIFT)
201*4882a593Smuzhiyun #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
202*4882a593Smuzhiyun #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun #include <asm-generic/memory_model.h>
207*4882a593Smuzhiyun #endif /* _XTENSA_PAGE_H */
208