source: mainline/kernel/generic/src/mm/page.c@ bbfdf62

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bbfdf62 was e3ee9b9, checked in by Martin Decky <martin@…>, 15 years ago

remove forward static function declarations and reorder functions
(if not needed for recursion, forward static function declaration only increases source code size and makes it much harder to instantly tell whether a function is actually static or not)

coding style changes
(no change in functionality)

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2001-2006 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genericmm
30 * @{
31 */
32
33/**
34 * @file
35 * @brief Virtual Address Translation subsystem.
36 *
37 * This file contains code for creating, destroying and searching
38 * mappings between virtual addresses and physical addresses.
39 * Functions here are mere wrappers that call the real implementation.
40 * They however, define the single interface.
41 *
42 */
43
44/*
45 * Note on memory prefetching and updating memory mappings, also described in:
46 * AMD x86-64 Architecture Programmer's Manual, Volume 2, System Programming,
47 * 7.2.1 Special Coherency Considerations.
48 *
49 * The processor which modifies a page table mapping can access prefetched data
50 * from the old mapping. In order to prevent this, we place a memory barrier
51 * after a mapping is updated.
52 *
53 * We assume that the other processors are either not using the mapping yet
54 * (i.e. during the bootstrap) or are executing the TLB shootdown code. While
55 * we don't care much about the former case, the processors in the latter case
56 * will do an implicit serialization by virtue of running the TLB shootdown
57 * interrupt handler.
58 *
59 */
60
61#include <mm/page.h>
62#include <arch/mm/page.h>
63#include <arch/mm/asid.h>
64#include <mm/as.h>
65#include <mm/frame.h>
66#include <arch/barrier.h>
67#include <typedefs.h>
68#include <arch/asm.h>
69#include <memstr.h>
70#include <debug.h>
71#include <arch.h>
72
73/** Virtual operations for page subsystem. */
74page_mapping_operations_t *page_mapping_operations = NULL;
75
76void page_init(void)
77{
78 page_arch_init();
79}
80
81/** Map memory structure
82 *
83 * Identity-map memory structure
84 * considering possible crossings
85 * of page boundaries.
86 *
87 * @param addr Address of the structure.
88 * @param size Size of the structure.
89 *
90 */
91void map_structure(uintptr_t addr, size_t size)
92{
93 size_t length = size + (addr - (addr & ~(PAGE_SIZE - 1)));
94 size_t cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
95
96 size_t i;
97 for (i = 0; i < cnt; i++)
98 page_mapping_insert(AS_KERNEL, addr + i * PAGE_SIZE,
99 addr + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
100
101 /* Repel prefetched accesses to the old mapping. */
102 memory_barrier();
103}
104
105/** Insert mapping of page to frame.
106 *
107 * Map virtual address page to physical address frame
108 * using flags. Allocate and setup any missing page tables.
109 *
110 * @param as Address space to wich page belongs.
111 * @param page Virtual address of the page to be mapped.
112 * @param frame Physical address of memory frame to which the mapping is
113 * done.
114 * @param flags Flags to be used for mapping.
115 *
116 */
117void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
118 unsigned int flags)
119{
120 ASSERT(page_table_locked(as));
121
122 ASSERT(page_mapping_operations);
123 ASSERT(page_mapping_operations->mapping_insert);
124
125 page_mapping_operations->mapping_insert(as, page, frame, flags);
126
127 /* Repel prefetched accesses to the old mapping. */
128 memory_barrier();
129}
130
131/** Remove mapping of page.
132 *
133 * Remove any mapping of page within address space as.
134 * TLB shootdown should follow in order to make effects of
135 * this call visible.
136 *
137 * @param as Address space to wich page belongs.
138 * @param page Virtual address of the page to be demapped.
139 *
140 */
141void page_mapping_remove(as_t *as, uintptr_t page)
142{
143 ASSERT(page_table_locked(as));
144
145 ASSERT(page_mapping_operations);
146 ASSERT(page_mapping_operations->mapping_remove);
147
148 page_mapping_operations->mapping_remove(as, page);
149
150 /* Repel prefetched accesses to the old mapping. */
151 memory_barrier();
152}
153
154/** Find mapping for virtual page
155 *
156 * Find mapping for virtual page.
157 *
158 * @param as Address space to wich page belongs.
159 * @param page Virtual page.
160 *
161 * @return NULL if there is no such mapping; requested mapping
162 * otherwise.
163 *
164 */
165pte_t *page_mapping_find(as_t *as, uintptr_t page)
166{
167 ASSERT(page_table_locked(as));
168
169 ASSERT(page_mapping_operations);
170 ASSERT(page_mapping_operations->mapping_find);
171
172 return page_mapping_operations->mapping_find(as, page);
173}
174
175/** @}
176 */
Note: See TracBrowser for help on using the repository browser.