blob: 319f4826d972fe8fd3703247ec6c4c75e68ee4f2 [file] [log] [blame]
Chris Metcalf867e3592010-05-28 23:09:12 -04001/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This file contains the functions and defines necessary to modify and use
15 * the TILE page table tree.
16 */
17
18#ifndef _ASM_TILE_PGTABLE_H
19#define _ASM_TILE_PGTABLE_H
20
21#include <hv/hypervisor.h>
22
23#ifndef __ASSEMBLY__
24
25#include <linux/bitops.h>
26#include <linux/threads.h>
27#include <linux/slab.h>
28#include <linux/list.h>
29#include <linux/spinlock.h>
Chris Metcalfd5d14ed2012-03-29 13:58:43 -040030#include <linux/pfn.h>
Chris Metcalf867e3592010-05-28 23:09:12 -040031#include <asm/processor.h>
32#include <asm/fixmap.h>
Chris Metcalfd5d14ed2012-03-29 13:58:43 -040033#include <asm/page.h>
Chris Metcalf867e3592010-05-28 23:09:12 -040034
35struct mm_struct;
36struct vm_area_struct;
37
38/*
39 * ZERO_PAGE is a global shared page that is always zero: used
40 * for zero-mapped memory areas etc..
41 */
42extern unsigned long empty_zero_page[PAGE_SIZE/sizeof(unsigned long)];
43#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
44
45extern pgd_t swapper_pg_dir[];
46extern pgprot_t swapper_pgprot;
47extern struct kmem_cache *pgd_cache;
48extern spinlock_t pgd_lock;
49extern struct list_head pgd_list;
50
51/*
52 * The very last slots in the pgd_t are for addresses unusable by Linux
53 * (pgd_addr_invalid() returns true). So we use them for the list structure.
54 * The x86 code we are modelled on uses the page->private/index fields
55 * (older 2.6 kernels) or the lru list (newer 2.6 kernels), but since
56 * our pgds are so much smaller than a page, it seems a waste to
57 * spend a whole page on each pgd.
58 */
59#define PGD_LIST_OFFSET \
60 ((PTRS_PER_PGD * sizeof(pgd_t)) - sizeof(struct list_head))
61#define pgd_to_list(pgd) \
62 ((struct list_head *)((char *)(pgd) + PGD_LIST_OFFSET))
63#define list_to_pgd(list) \
64 ((pgd_t *)((char *)(list) - PGD_LIST_OFFSET))
65
66extern void pgtable_cache_init(void);
67extern void paging_init(void);
68extern void set_page_homes(void);
69
70#define FIRST_USER_ADDRESS 0
71
72#define _PAGE_PRESENT HV_PTE_PRESENT
73#define _PAGE_HUGE_PAGE HV_PTE_PAGE
74#define _PAGE_READABLE HV_PTE_READABLE
75#define _PAGE_WRITABLE HV_PTE_WRITABLE
76#define _PAGE_EXECUTABLE HV_PTE_EXECUTABLE
77#define _PAGE_ACCESSED HV_PTE_ACCESSED
78#define _PAGE_DIRTY HV_PTE_DIRTY
79#define _PAGE_GLOBAL HV_PTE_GLOBAL
80#define _PAGE_USER HV_PTE_USER
81
82/*
83 * All the "standard" bits. Cache-control bits are managed elsewhere.
84 * This is used to test for valid level-2 page table pointers by checking
85 * all the bits, and to mask away the cache control bits for mprotect.
86 */
87#define _PAGE_ALL (\
88 _PAGE_PRESENT | \
89 _PAGE_HUGE_PAGE | \
90 _PAGE_READABLE | \
91 _PAGE_WRITABLE | \
92 _PAGE_EXECUTABLE | \
93 _PAGE_ACCESSED | \
94 _PAGE_DIRTY | \
95 _PAGE_GLOBAL | \
96 _PAGE_USER \
97)
98
99#define PAGE_NONE \
100 __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
101#define PAGE_SHARED \
102 __pgprot(_PAGE_PRESENT | _PAGE_READABLE | _PAGE_WRITABLE | \
103 _PAGE_USER | _PAGE_ACCESSED)
104
105#define PAGE_SHARED_EXEC \
106 __pgprot(_PAGE_PRESENT | _PAGE_READABLE | _PAGE_WRITABLE | \
107 _PAGE_EXECUTABLE | _PAGE_USER | _PAGE_ACCESSED)
108#define PAGE_COPY_NOEXEC \
109 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_READABLE)
110#define PAGE_COPY_EXEC \
111 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | \
112 _PAGE_READABLE | _PAGE_EXECUTABLE)
113#define PAGE_COPY \
114 PAGE_COPY_NOEXEC
115#define PAGE_READONLY \
116 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_READABLE)
117#define PAGE_READONLY_EXEC \
118 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | \
119 _PAGE_READABLE | _PAGE_EXECUTABLE)
120
121#define _PAGE_KERNEL_RO \
122 (_PAGE_PRESENT | _PAGE_GLOBAL | _PAGE_READABLE | _PAGE_ACCESSED)
123#define _PAGE_KERNEL \
124 (_PAGE_KERNEL_RO | _PAGE_WRITABLE | _PAGE_DIRTY)
125#define _PAGE_KERNEL_EXEC (_PAGE_KERNEL_RO | _PAGE_EXECUTABLE)
126
127#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
128#define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL_RO)
129#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
130
131#define page_to_kpgprot(p) PAGE_KERNEL
132
133/*
134 * We could tighten these up, but for now writable or executable
135 * implies readable.
136 */
137#define __P000 PAGE_NONE
138#define __P001 PAGE_READONLY
139#define __P010 PAGE_COPY /* this is write-only, which we won't support */
140#define __P011 PAGE_COPY
141#define __P100 PAGE_READONLY_EXEC
142#define __P101 PAGE_READONLY_EXEC
143#define __P110 PAGE_COPY_EXEC
144#define __P111 PAGE_COPY_EXEC
145
146#define __S000 PAGE_NONE
147#define __S001 PAGE_READONLY
148#define __S010 PAGE_SHARED
149#define __S011 PAGE_SHARED
150#define __S100 PAGE_READONLY_EXEC
151#define __S101 PAGE_READONLY_EXEC
152#define __S110 PAGE_SHARED_EXEC
153#define __S111 PAGE_SHARED_EXEC
154
155/*
156 * All the normal _PAGE_ALL bits are ignored for PMDs, except PAGE_PRESENT
157 * and PAGE_HUGE_PAGE, which must be one and zero, respectively.
158 * We set the ignored bits to zero.
159 */
160#define _PAGE_TABLE _PAGE_PRESENT
161
162/* Inherit the caching flags from the old protection bits. */
163#define pgprot_modify(oldprot, newprot) \
164 (pgprot_t) { ((oldprot).val & ~_PAGE_ALL) | (newprot).val }
165
166/* Just setting the PFN to zero suffices. */
Chris Metcalfd5d14ed2012-03-29 13:58:43 -0400167#define pte_pgprot(x) hv_pte_set_pa((x), 0)
Chris Metcalf867e3592010-05-28 23:09:12 -0400168
169/*
170 * For PTEs and PDEs, we must clear the Present bit first when
171 * clearing a page table entry, so clear the bottom half first and
172 * enforce ordering with a barrier.
173 */
174static inline void __pte_clear(pte_t *ptep)
175{
176#ifdef __tilegx__
177 ptep->val = 0;
178#else
179 u32 *tmp = (u32 *)ptep;
180 tmp[0] = 0;
181 barrier();
182 tmp[1] = 0;
183#endif
184}
185#define pte_clear(mm, addr, ptep) __pte_clear(ptep)
186
187/*
188 * The following only work if pte_present() is true.
189 * Undefined behaviour if not..
190 */
191#define pte_present hv_pte_get_present
Chris Metcalf73636b12012-03-28 13:59:18 -0400192#define pte_mknotpresent hv_pte_clear_present
Chris Metcalf867e3592010-05-28 23:09:12 -0400193#define pte_user hv_pte_get_user
194#define pte_read hv_pte_get_readable
195#define pte_dirty hv_pte_get_dirty
196#define pte_young hv_pte_get_accessed
197#define pte_write hv_pte_get_writable
198#define pte_exec hv_pte_get_executable
199#define pte_huge hv_pte_get_page
200#define pte_rdprotect hv_pte_clear_readable
201#define pte_exprotect hv_pte_clear_executable
202#define pte_mkclean hv_pte_clear_dirty
203#define pte_mkold hv_pte_clear_accessed
204#define pte_wrprotect hv_pte_clear_writable
205#define pte_mksmall hv_pte_clear_page
206#define pte_mkread hv_pte_set_readable
207#define pte_mkexec hv_pte_set_executable
208#define pte_mkdirty hv_pte_set_dirty
209#define pte_mkyoung hv_pte_set_accessed
210#define pte_mkwrite hv_pte_set_writable
211#define pte_mkhuge hv_pte_set_page
212
213#define pte_special(pte) 0
214#define pte_mkspecial(pte) (pte)
215
216/*
217 * Use some spare bits in the PTE for user-caching tags.
218 */
219#define pte_set_forcecache hv_pte_set_client0
220#define pte_get_forcecache hv_pte_get_client0
221#define pte_clear_forcecache hv_pte_clear_client0
222#define pte_set_anyhome hv_pte_set_client1
223#define pte_get_anyhome hv_pte_get_client1
224#define pte_clear_anyhome hv_pte_clear_client1
225
226/*
227 * A migrating PTE has PAGE_PRESENT clear but all the other bits preserved.
228 */
229#define pte_migrating hv_pte_get_migrating
230#define pte_mkmigrate(x) hv_pte_set_migrating(hv_pte_clear_present(x))
231#define pte_donemigrate(x) hv_pte_set_present(hv_pte_clear_migrating(x))
232
233#define pte_ERROR(e) \
Chris Metcalf0707ad32010-06-25 17:04:17 -0400234 pr_err("%s:%d: bad pte 0x%016llx.\n", __FILE__, __LINE__, pte_val(e))
Chris Metcalf867e3592010-05-28 23:09:12 -0400235#define pgd_ERROR(e) \
Chris Metcalf0707ad32010-06-25 17:04:17 -0400236 pr_err("%s:%d: bad pgd 0x%016llx.\n", __FILE__, __LINE__, pgd_val(e))
Chris Metcalf867e3592010-05-28 23:09:12 -0400237
Chris Metcalf76c567f2011-02-28 16:37:34 -0500238/* Return PA and protection info for a given kernel VA. */
239int va_to_cpa_and_pte(void *va, phys_addr_t *cpa, pte_t *pte);
240
Chris Metcalf867e3592010-05-28 23:09:12 -0400241/*
Chris Metcalf76c567f2011-02-28 16:37:34 -0500242 * __set_pte() ensures we write the 64-bit PTE with 32-bit words in
243 * the right order on 32-bit platforms and also allows us to write
244 * hooks to check valid PTEs, etc., if we want.
245 */
246void __set_pte(pte_t *ptep, pte_t pte);
247
248/*
249 * set_pte() sets the given PTE and also sanity-checks the
Chris Metcalf867e3592010-05-28 23:09:12 -0400250 * requested PTE against the page homecaching. Unspecified parts
251 * of the PTE are filled in when it is written to memory, i.e. all
252 * caching attributes if "!forcecache", or the home cpu if "anyhome".
253 */
Chris Metcalf76c567f2011-02-28 16:37:34 -0500254extern void set_pte(pte_t *ptep, pte_t pte);
Chris Metcalf867e3592010-05-28 23:09:12 -0400255#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
256#define set_pte_atomic(pteptr, pteval) set_pte(pteptr, pteval)
257
258#define pte_page(x) pfn_to_page(pte_pfn(x))
259
260static inline int pte_none(pte_t pte)
261{
262 return !pte.val;
263}
264
265static inline unsigned long pte_pfn(pte_t pte)
266{
Chris Metcalfd5d14ed2012-03-29 13:58:43 -0400267 return PFN_DOWN(hv_pte_get_pa(pte));
Chris Metcalf867e3592010-05-28 23:09:12 -0400268}
269
270/* Set or get the remote cache cpu in a pgprot with remote caching. */
271extern pgprot_t set_remote_cache_cpu(pgprot_t prot, int cpu);
272extern int get_remote_cache_cpu(pgprot_t prot);
273
274static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
275{
Chris Metcalfd5d14ed2012-03-29 13:58:43 -0400276 return hv_pte_set_pa(prot, PFN_PHYS(pfn));
Chris Metcalf867e3592010-05-28 23:09:12 -0400277}
278
279/* Support for priority mappings. */
280extern void start_mm_caching(struct mm_struct *mm);
281extern void check_mm_caching(struct mm_struct *prev, struct mm_struct *next);
282
283/*
284 * Support non-linear file mappings (see sys_remap_file_pages).
285 * This is defined by CLIENT1 set but CLIENT0 and _PAGE_PRESENT clear, and the
286 * file offset in the 32 high bits.
287 */
288#define _PAGE_FILE HV_PTE_CLIENT1
289#define PTE_FILE_MAX_BITS 32
290#define pte_file(pte) (hv_pte_get_client1(pte) && !hv_pte_get_client0(pte))
291#define pte_to_pgoff(pte) ((pte).val >> 32)
292#define pgoff_to_pte(off) ((pte_t) { (((long long)(off)) << 32) | _PAGE_FILE })
293
294/*
295 * Encode and de-code a swap entry (see <linux/swapops.h>).
296 * We put the swap file type+offset in the 32 high bits;
297 * I believe we can just leave the low bits clear.
298 */
299#define __swp_type(swp) ((swp).val & 0x1f)
300#define __swp_offset(swp) ((swp).val >> 5)
301#define __swp_entry(type, off) ((swp_entry_t) { (type) | ((off) << 5) })
302#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).val >> 32 })
303#define __swp_entry_to_pte(swp) ((pte_t) { (((long long) ((swp).val)) << 32) })
304
305/*
Chris Metcalf867e3592010-05-28 23:09:12 -0400306 * Conversion functions: convert a page and protection to a page entry,
307 * and a page entry and page directory to the page they refer to.
308 */
309
310#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
311
312/*
313 * If we are doing an mprotect(), just accept the new vma->vm_page_prot
314 * value and combine it with the PFN from the old PTE to get a new PTE.
315 */
316static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
317{
Chris Metcalf73636b12012-03-28 13:59:18 -0400318 return pfn_pte(pte_pfn(pte), newprot);
Chris Metcalf867e3592010-05-28 23:09:12 -0400319}
320
321/*
322 * The pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
323 *
324 * This macro returns the index of the entry in the pgd page which would
325 * control the given virtual address.
326 */
327#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
328
329/*
330 * pgd_offset() returns a (pgd_t *)
331 * pgd_index() is used get the offset into the pgd page's array of pgd_t's.
332 */
333#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
334
335/*
336 * A shortcut which implies the use of the kernel's pgd, instead
337 * of a process's.
338 */
339#define pgd_offset_k(address) pgd_offset(&init_mm, address)
340
341#if defined(CONFIG_HIGHPTE)
Chris Metcalf38a6f422010-11-01 15:21:35 -0400342extern pte_t *pte_offset_map(pmd_t *, unsigned long address);
343#define pte_unmap(pte) kunmap_atomic(pte)
Chris Metcalf867e3592010-05-28 23:09:12 -0400344#else
345#define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
Chris Metcalf867e3592010-05-28 23:09:12 -0400346#define pte_unmap(pte) do { } while (0)
Chris Metcalf867e3592010-05-28 23:09:12 -0400347#endif
348
349/* Clear a non-executable kernel PTE and flush it from the TLB. */
350#define kpte_clear_flush(ptep, vaddr) \
351do { \
352 pte_clear(&init_mm, (vaddr), (ptep)); \
353 local_flush_tlb_page(FLUSH_NONEXEC, (vaddr), PAGE_SIZE); \
354} while (0)
355
356/*
357 * The kernel page tables contain what we need, and we flush when we
358 * change specific page table entries.
359 */
360#define update_mmu_cache(vma, address, pte) do { } while (0)
361
362#ifdef CONFIG_FLATMEM
363#define kern_addr_valid(addr) (1)
364#endif /* CONFIG_FLATMEM */
365
366#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
367 remap_pfn_range(vma, vaddr, pfn, size, prot)
368
369extern void vmalloc_sync_all(void);
370
371#endif /* !__ASSEMBLY__ */
372
373#ifdef __tilegx__
374#include <asm/pgtable_64.h>
375#else
376#include <asm/pgtable_32.h>
377#endif
378
379#ifndef __ASSEMBLY__
380
381static inline int pmd_none(pmd_t pmd)
382{
383 /*
384 * Only check low word on 32-bit platforms, since it might be
385 * out of sync with upper half.
386 */
387 return (unsigned long)pmd_val(pmd) == 0;
388}
389
390static inline int pmd_present(pmd_t pmd)
391{
392 return pmd_val(pmd) & _PAGE_PRESENT;
393}
394
395static inline int pmd_bad(pmd_t pmd)
396{
397 return ((pmd_val(pmd) & _PAGE_ALL) != _PAGE_TABLE);
398}
399
400static inline unsigned long pages_to_mb(unsigned long npg)
401{
402 return npg >> (20 - PAGE_SHIFT);
403}
404
405/*
406 * The pmd can be thought of an array like this: pmd_t[PTRS_PER_PMD]
407 *
408 * This function returns the index of the entry in the pmd which would
409 * control the given virtual address.
410 */
411static inline unsigned long pmd_index(unsigned long address)
412{
413 return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
414}
415
Chris Metcalf73636b12012-03-28 13:59:18 -0400416#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
417static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
418 unsigned long address,
419 pmd_t *pmdp)
420{
421 return ptep_test_and_clear_young(vma, address, pmdp_ptep(pmdp));
422}
423
424#define __HAVE_ARCH_PMDP_SET_WRPROTECT
425static inline void pmdp_set_wrprotect(struct mm_struct *mm,
426 unsigned long address, pmd_t *pmdp)
427{
428 ptep_set_wrprotect(mm, address, pmdp_ptep(pmdp));
429}
430
431
432#define __HAVE_ARCH_PMDP_GET_AND_CLEAR
433static inline pmd_t pmdp_get_and_clear(struct mm_struct *mm,
434 unsigned long address,
435 pmd_t *pmdp)
436{
437 return pte_pmd(ptep_get_and_clear(mm, address, pmdp_ptep(pmdp)));
438}
439
440static inline void __set_pmd(pmd_t *pmdp, pmd_t pmdval)
441{
442 set_pte(pmdp_ptep(pmdp), pmd_pte(pmdval));
443}
444
445#define set_pmd_at(mm, addr, pmdp, pmdval) __set_pmd(pmdp, pmdval)
446
447/* Create a pmd from a PTFN. */
448static inline pmd_t ptfn_pmd(unsigned long ptfn, pgprot_t prot)
449{
450 return pte_pmd(hv_pte_set_ptfn(prot, ptfn));
451}
452
453/* Return the page-table frame number (ptfn) that a pmd_t points at. */
454#define pmd_ptfn(pmd) hv_pte_get_ptfn(pmd_pte(pmd))
455
Chris Metcalf867e3592010-05-28 23:09:12 -0400456/*
457 * A given kernel pmd_t maps to a specific virtual address (either a
458 * kernel huge page or a kernel pte_t table). Since kernel pte_t
459 * tables can be aligned at sub-page granularity, this function can
460 * return non-page-aligned pointers, despite its name.
461 */
462static inline unsigned long pmd_page_vaddr(pmd_t pmd)
463{
464 phys_addr_t pa =
465 (phys_addr_t)pmd_ptfn(pmd) << HV_LOG2_PAGE_TABLE_ALIGN;
466 return (unsigned long)__va(pa);
467}
468
469/*
470 * A pmd_t points to the base of a huge page or to a pte_t array.
471 * If a pte_t array, since we can have multiple per page, we don't
472 * have a one-to-one mapping of pmd_t's to pages. However, this is
473 * OK for pte_lockptr(), since we just end up with potentially one
474 * lock being used for several pte_t arrays.
475 */
Chris Metcalfd5d14ed2012-03-29 13:58:43 -0400476#define pmd_page(pmd) pfn_to_page(PFN_DOWN(HV_PTFN_TO_CPA(pmd_ptfn(pmd))))
Chris Metcalf867e3592010-05-28 23:09:12 -0400477
Chris Metcalf73636b12012-03-28 13:59:18 -0400478static inline void pmd_clear(pmd_t *pmdp)
479{
480 __pte_clear(pmdp_ptep(pmdp));
481}
482
483#define pmd_mknotpresent(pmd) pte_pmd(pte_mknotpresent(pmd_pte(pmd)))
484#define pmd_young(pmd) pte_young(pmd_pte(pmd))
485#define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
486#define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))
487#define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
488#define pmd_write(pmd) pte_write(pmd_pte(pmd))
489#define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))
490#define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))
491#define pmd_huge_page(pmd) pte_huge(pmd_pte(pmd))
492#define pmd_mkhuge(pmd) pte_pmd(pte_mkhuge(pmd_pte(pmd)))
493#define __HAVE_ARCH_PMD_WRITE
494
495#define pfn_pmd(pfn, pgprot) pte_pmd(pfn_pte((pfn), (pgprot)))
496#define pmd_pfn(pmd) pte_pfn(pmd_pte(pmd))
497#define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))
498
499static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
500{
501 return pfn_pmd(pmd_pfn(pmd), newprot);
502}
503
504#ifdef CONFIG_TRANSPARENT_HUGEPAGE
505#define has_transparent_hugepage() 1
506#define pmd_trans_huge pmd_huge_page
507
508static inline pmd_t pmd_mksplitting(pmd_t pmd)
509{
510 return pte_pmd(hv_pte_set_client2(pmd_pte(pmd)));
511}
512
513static inline int pmd_trans_splitting(pmd_t pmd)
514{
515 return hv_pte_get_client2(pmd_pte(pmd));
516}
517#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
518
Chris Metcalf867e3592010-05-28 23:09:12 -0400519/*
520 * The pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
521 *
522 * This macro returns the index of the entry in the pte page which would
523 * control the given virtual address.
524 */
525static inline unsigned long pte_index(unsigned long address)
526{
527 return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
528}
529
530static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
531{
532 return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
533}
534
Chris Metcalf867e3592010-05-28 23:09:12 -0400535#include <asm-generic/pgtable.h>
536
Chris Metcalf0707ad32010-06-25 17:04:17 -0400537/* Support /proc/NN/pgtable API. */
538struct seq_file;
539int arch_proc_pgtable_show(struct seq_file *m, struct mm_struct *mm,
540 unsigned long vaddr, pte_t *ptep, void **datap);
541
Chris Metcalf867e3592010-05-28 23:09:12 -0400542#endif /* !__ASSEMBLY__ */
543
544#endif /* _ASM_TILE_PGTABLE_H */