blob: c631d006194b476db9d4f307a3e034f20625aa60 [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
2 * linux/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 - 2005 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_PAGE_H
12#define _XTENSA_PAGE_H
13
14#ifdef __KERNEL__
15
16#include <asm/processor.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070017
Chris Zankel173d6682006-12-10 02:18:48 -080018#define XCHAL_KSEG_CACHED_VADDR 0xd0000000
19#define XCHAL_KSEG_BYPASS_VADDR 0xd8000000
20#define XCHAL_KSEG_PADDR 0x00000000
21#define XCHAL_KSEG_SIZE 0x08000000
22
Chris Zankel9a8fd552005-06-23 22:01:26 -070023/*
24 * PAGE_SHIFT determines the page size
25 * PAGE_ALIGN(x) aligns the pointer to the (next) page boundary
26 */
27
Chris Zankel173d6682006-12-10 02:18:48 -080028#define PAGE_SHIFT 12
Chris Zankel9a8fd552005-06-23 22:01:26 -070029#define PAGE_SIZE (1 << PAGE_SHIFT)
30#define PAGE_MASK (~(PAGE_SIZE-1))
31#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE - 1) & PAGE_MASK)
32
Chris Zankel9a8fd552005-06-23 22:01:26 -070033#define PAGE_OFFSET XCHAL_KSEG_CACHED_VADDR
Chris Zankel173d6682006-12-10 02:18:48 -080034#define MAX_MEM_PFN XCHAL_KSEG_SIZE
35#define PGTABLE_START 0x80000000
Chris Zankel9a8fd552005-06-23 22:01:26 -070036
37#ifdef __ASSEMBLY__
38
39#define __pgprot(x) (x)
40
41#else
42
43/*
44 * These are used to make use of C type-checking..
45 */
46
47typedef struct { unsigned long pte; } pte_t; /* page table entry */
48typedef struct { unsigned long pgd; } pgd_t; /* PGD table entry */
49typedef struct { unsigned long pgprot; } pgprot_t;
50
51#define pte_val(x) ((x).pte)
52#define pgd_val(x) ((x).pgd)
53#define pgprot_val(x) ((x).pgprot)
54
55#define __pte(x) ((pte_t) { (x) } )
56#define __pgd(x) ((pgd_t) { (x) } )
57#define __pgprot(x) ((pgprot_t) { (x) } )
58
59/*
60 * Pure 2^n version of get_order
61 */
62
Adrian Bunkd99cf712005-09-03 15:57:53 -070063static inline int get_order(unsigned long size)
Chris Zankel9a8fd552005-06-23 22:01:26 -070064{
65 int order;
66#ifndef XCHAL_HAVE_NSU
67 unsigned long x1, x2, x4, x8, x16;
68
69 size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
70 x1 = size & 0xAAAAAAAA;
71 x2 = size & 0xCCCCCCCC;
72 x4 = size & 0xF0F0F0F0;
73 x8 = size & 0xFF00FF00;
74 x16 = size & 0xFFFF0000;
75 order = x2 ? 2 : 0;
76 order += (x16 != 0) * 16;
77 order += (x8 != 0) * 8;
78 order += (x4 != 0) * 4;
79 order += (x1 != 0);
80
81 return order;
82#else
83 size = (size - 1) >> PAGE_SHIFT;
84 asm ("nsau %0, %1" : "=r" (order) : "r" (size));
85 return 32 - order;
86#endif
87}
88
89
90struct page;
91extern void clear_page(void *page);
92extern void copy_page(void *to, void *from);
93
94/*
95 * If we have cache aliasing and writeback caches, we might have to do
96 * some extra work
97 */
98
99#if (DCACHE_WAY_SIZE > PAGE_SIZE)
100void clear_user_page(void *addr, unsigned long vaddr, struct page* page);
101void copy_user_page(void *to,void* from,unsigned long vaddr,struct page* page);
102#else
103# define clear_user_page(page,vaddr,pg) clear_page(page)
104# define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
105#endif
106
107/*
108 * This handles the memory map. We handle pages at
109 * XCHAL_KSEG_CACHED_VADDR for kernels with 32 bit address space.
110 * These macros are for conversion of kernel address, not user
111 * addresses.
112 */
113
114#define __pa(x) ((unsigned long) (x) - PAGE_OFFSET)
115#define __va(x) ((void *)((unsigned long) (x) + PAGE_OFFSET))
116#define pfn_valid(pfn) ((unsigned long)pfn < max_mapnr)
KAMEZAWA Hiroyuki655a0442006-03-27 01:15:52 -0800117#ifdef CONFIG_DISCONTIGMEM
Chris Zankel9a8fd552005-06-23 22:01:26 -0700118# error CONFIG_DISCONTIGMEM not supported
119#endif
120
121#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
122#define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
123#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
124#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
125
126#define WANT_PAGE_VIRTUAL
127
128
129#endif /* __ASSEMBLY__ */
130
131#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
132 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
133
134#endif /* __KERNEL__ */
KAMEZAWA Hiroyuki655a0442006-03-27 01:15:52 -0800135#include <asm-generic/memory_model.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -0700136#endif /* _XTENSA_PAGE_H */