blob: d111d0cea9cc166d48c7bfa32d675a92e4322a3d [file] [log] [blame]
Vineet Gupta3be80aa2013-01-18 15:12:17 +05301/*
2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
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 version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#ifndef __ASM_ARC_PAGE_H
10#define __ASM_ARC_PAGE_H
11
12/* PAGE_SHIFT determines the page size */
13#if defined(CONFIG_ARC_PAGE_SIZE_16K)
14#define PAGE_SHIFT 14
15#elif defined(CONFIG_ARC_PAGE_SIZE_4K)
16#define PAGE_SHIFT 12
17#else
18/*
19 * Default 8k
20 * done this way (instead of under CONFIG_ARC_PAGE_SIZE_8K) because adhoc
21 * user code (busybox appletlib.h) expects PAGE_SHIFT to be defined w/o
22 * using the correct uClibc header and in their build our autoconf.h is
23 * not available
24 */
25#define PAGE_SHIFT 13
26#endif
27
28#ifdef __ASSEMBLY__
29#define PAGE_SIZE (1 << PAGE_SHIFT)
30#define PAGE_OFFSET (0x80000000)
31#else
32#define PAGE_SIZE (1UL << PAGE_SHIFT) /* Default 8K */
33#define PAGE_OFFSET (0x80000000UL) /* Kernel starts at 2G onwards */
34#endif
35
36#define PAGE_MASK (~(PAGE_SIZE-1))
37
Vineet Gupta5dda4dc2013-01-18 15:12:19 +053038#ifdef __KERNEL__
39
40#ifndef __ASSEMBLY__
41
42#define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
43#define free_user_page(page, addr) free_page(addr)
44
45/* TBD: for now don't worry about VIPT D$ aliasing */
46#define clear_page(paddr) memset((paddr), 0, PAGE_SIZE)
47#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
48
49#define clear_user_page(addr, vaddr, pg) clear_page(addr)
50#define copy_user_page(vto, vfrom, vaddr, pg) copy_page(vto, vfrom)
51
52#undef STRICT_MM_TYPECHECKS
53
54#ifdef STRICT_MM_TYPECHECKS
55/*
56 * These are used to make use of C type-checking..
57 */
58typedef struct {
59 unsigned long pte;
60} pte_t;
61typedef struct {
62 unsigned long pgd;
63} pgd_t;
64typedef struct {
65 unsigned long pgprot;
66} pgprot_t;
67typedef unsigned long pgtable_t;
68
69#define pte_val(x) ((x).pte)
70#define pgd_val(x) ((x).pgd)
71#define pgprot_val(x) ((x).pgprot)
72
73#define __pte(x) ((pte_t) { (x) })
74#define __pgd(x) ((pgd_t) { (x) })
75#define __pgprot(x) ((pgprot_t) { (x) })
76
77#else /* !STRICT_MM_TYPECHECKS */
78
79typedef unsigned long pte_t;
80typedef unsigned long pgd_t;
81typedef unsigned long pgprot_t;
82typedef unsigned long pgtable_t;
83
84#define pte_val(x) (x)
85#define pgd_val(x) (x)
86#define pgprot_val(x) (x)
87#define __pte(x) (x)
88#define __pgprot(x) (x)
89
90#endif
91
92#define ARCH_PFN_OFFSET (CONFIG_LINUX_LINK_BASE >> PAGE_SHIFT)
93
94#define pfn_valid(pfn) (((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
95
96/*
97 * __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
98 *
99 * These macros have historically been misnamed
100 * virt here means link-address/program-address as embedded in object code.
101 * So if kernel img is linked at 0x8000_0000 onwards, 0x8010_0000 will be
102 * 128th page, and virt_to_page( ) will return the struct page corresp to it.
103 * mem_map[ ] is an array of struct page for each page frame in the system
104 *
105 * Independent of where linux is linked at, link-addr = physical address
106 * So the old macro __pa = vaddr + PAGE_OFFSET - CONFIG_LINUX_LINK_BASE
107 * would have been wrong in case kernel is not at 0x8zs
108 */
109#define __pa(vaddr) ((unsigned long)vaddr)
110#define __va(paddr) ((void *)((unsigned long)(paddr)))
111
112#define virt_to_page(kaddr) \
113 (mem_map + ((__pa(kaddr) - CONFIG_LINUX_LINK_BASE) >> PAGE_SHIFT))
114
115#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
116
117/* Default Permissions for page, used in mmap.c */
118#ifdef CONFIG_ARC_STACK_NONEXEC
119#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE)
120#else
121#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
122 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
123#endif
124
125#define WANT_PAGE_VIRTUAL 1
126
127#include <asm-generic/memory_model.h> /* page_to_pfn, pfn_to_page */
128#include <asm-generic/getorder.h>
129
Vineet Gupta3be80aa2013-01-18 15:12:17 +0530130#endif /* !__ASSEMBLY__ */
131
132#endif /* __KERNEL__ */
133
134#endif