blob: b3ec519e39827e58eaeb8a567303e37a6bc2e919 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_PGTABLE_32_H
3#define _ASM_X86_PGTABLE_32_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Jeremy Fitzhardingef402a652009-02-08 18:49:05 -08005#include <asm/pgtable_32_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
7/*
8 * The Linux memory management assumes a three-level page table setup. On
9 * the i386, we use that, but "fold" the mid level into the top-level page
10 * table, so that we physically have the same two-level page table as the
11 * i386 mmu expects.
12 *
13 * This file contains the functions and defines necessary to modify and use
14 * the i386 page table tree.
15 */
16#ifndef __ASSEMBLY__
17#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/threads.h>
Rusty Russellda181a82006-12-07 02:14:08 +010019#include <asm/paravirt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Jiri Slaby1977f032007-10-18 23:40:25 -070021#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/list.h>
23#include <linux/spinlock.h>
24
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080025struct mm_struct;
26struct vm_area_struct;
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028extern pgd_t swapper_pg_dir[1024];
Borislav Petkovb40827fa2010-08-28 15:58:33 +020029extern pgd_t initial_page_table[1024];
Boris Ostrovsky1e620f92016-12-08 11:44:31 -050030extern pmd_t initial_pg_pmd[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Thomas Gleixner985a34b2008-03-09 13:14:37 +010032static inline void pgtable_cache_init(void) { }
33static inline void check_pgt_cache(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070034void paging_init(void);
Thomas Gleixner945fd172018-02-28 21:14:26 +010035void sync_initial_page_table(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * Define this if things work differently on an i386 and an i486:
39 * it will (on an i486) warn about kernel memory accesses that are
Jesper Juhle49332b2005-05-01 08:59:08 -070040 * done without a 'access_ok(VERIFY_WRITE,..)'
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 */
Jesper Juhle49332b2005-05-01 08:59:08 -070042#undef TEST_ACCESS_OK
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#ifdef CONFIG_X86_PAE
45# include <asm/pgtable-3level.h>
46#else
47# include <asm/pgtable-2level.h>
48#endif
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#if defined(CONFIG_HIGHPTE)
Joe Perchescf8401472008-03-23 01:03:09 -070051#define pte_offset_map(dir, address) \
Peter Zijlstraece0e2b2010-10-26 14:21:52 -070052 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
Joe Perchescf8401472008-03-23 01:03:09 -070053 pte_index((address)))
Peter Zijlstraece0e2b2010-10-26 14:21:52 -070054#define pte_unmap(pte) kunmap_atomic((pte))
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#else
Joe Perchescf8401472008-03-23 01:03:09 -070056#define pte_offset_map(dir, address) \
57 ((pte_t *)page_address(pmd_page(*(dir))) + pte_index((address)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define pte_unmap(pte) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#endif
60
Zachary Amsden23002d82006-09-30 23:29:35 -070061/* Clear a kernel PTE and flush it from the TLB */
Joe Perchescf8401472008-03-23 01:03:09 -070062#define kpte_clear_flush(ptep, vaddr) \
63do { \
64 pte_clear(&init_mm, (vaddr), (ptep)); \
Andy Lutomirski1299ef12018-01-31 08:03:10 -080065 __flush_tlb_one_kernel((vaddr)); \
Zachary Amsden23002d82006-09-30 23:29:35 -070066} while (0)
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif /* !__ASSEMBLY__ */
69
Thomas Gleixner4757d7d82008-01-30 13:30:37 +010070/*
71 * kern_addr_valid() is (1) for FLATMEM and (0) for
72 * SPARSEMEM and DISCONTIGMEM
73 */
Andy Whitcroft05b79bd2005-06-23 00:07:57 -070074#ifdef CONFIG_FLATMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define kern_addr_valid(addr) (1)
Thomas Gleixner4757d7d82008-01-30 13:30:37 +010076#else
77#define kern_addr_valid(kaddr) (0)
78#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Boris Ostrovsky1e620f92016-12-08 11:44:31 -050080/*
81 * This is how much memory in addition to the memory covered up to
82 * and including _end we need mapped initially.
83 * We need:
84 * (KERNEL_IMAGE_SIZE/4096) / 1024 pages (worst case, non PAE)
85 * (KERNEL_IMAGE_SIZE/4096) / 512 + 4 pages (worst case for PAE)
86 *
87 * Modulo rounding, each megabyte assigned here requires a kilobyte of
88 * memory, which is currently unreclaimed.
89 *
90 * This should be a multiple of a page.
91 *
92 * KERNEL_IMAGE_SIZE should be greater than pa(_end)
93 * and small than max_low_pfn, otherwise will waste some page table entries
94 */
95#if PTRS_PER_PMD > 1
96#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
97#else
98#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
99#endif
100
101/*
102 * Number of possible pages in the lowmem region.
103 *
104 * We shift 2 by 31 instead of 1 by 32 to the left in order to avoid a
105 * gas warning about overflowing shift count when gas has been compiled
106 * with only a host target support using a 32-bit type for internal
107 * representation.
108 */
109#define LOWMEM_PAGES ((((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT))
110
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700111#endif /* _ASM_X86_PGTABLE_32_H */