Subversion Repositories HelenOS

Rev

Rev 3022 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 38... Line 38...
38
 * mappings between virtual addresses and physical addresses.
38
 * mappings between virtual addresses and physical addresses.
39
 * Functions here are mere wrappers that call the real implementation.
39
 * Functions here are mere wrappers that call the real implementation.
40
 * They however, define the single interface.
40
 * They however, define the single interface.
41
 */
41
 */
42
 
42
 
-
 
43
/*
-
 
44
 * Note on memory prefetching and updating memory mappings, also described in:
-
 
45
 * AMD x86-64 Architecture Programmer's Manual, Volume 2, System Programming,
-
 
46
 * 7.2.1 Special Coherency Considerations.
-
 
47
 *
-
 
48
 * The processor which modifies a page table mapping can access prefetched data
-
 
49
 * from the old mapping.  In order to prevent this, we place a memory barrier
-
 
50
 * after a mapping is updated.
-
 
51
 *
-
 
52
 * We assume that the other processors are either not using the mapping yet
-
 
53
 * (i.e. during the bootstrap) or are executing the TLB shootdown code.  While
-
 
54
 * we don't care much about the former case, the processors in the latter case
-
 
55
 * will do an implicit serialization by virtue of running the TLB shootdown
-
 
56
 * interrupt handler.
-
 
57
 */
-
 
58
 
43
#include <mm/page.h>
59
#include <mm/page.h>
44
#include <arch/mm/page.h>
60
#include <arch/mm/page.h>
45
#include <arch/mm/asid.h>
61
#include <arch/mm/asid.h>
46
#include <mm/as.h>
62
#include <mm/as.h>
47
#include <mm/frame.h>
63
#include <mm/frame.h>
-
 
64
#include <arch/barrier.h>
48
#include <arch/types.h>
65
#include <arch/types.h>
49
#include <arch/asm.h>
66
#include <arch/asm.h>
50
#include <memstr.h>
67
#include <memstr.h>
51
#include <debug.h>
68
#include <debug.h>
52
#include <arch.h>
69
#include <arch.h>
Line 63... Line 80...
63
 *
80
 *
64
 * Identity-map memory structure
81
 * Identity-map memory structure
65
 * considering possible crossings
82
 * considering possible crossings
66
 * of page boundaries.
83
 * of page boundaries.
67
 *
84
 *
68
 * @param s Address of the structure.
85
 * @param s     Address of the structure.
69
 * @param size Size of the structure.
86
 * @param size      Size of the structure.
70
 */
87
 */
71
void map_structure(uintptr_t s, size_t size)
88
void map_structure(uintptr_t s, size_t size)
72
{
89
{
73
    int i, cnt, length;
90
    int i, cnt, length;
74
 
91
 
75
    length = size + (s - (s & ~(PAGE_SIZE - 1)));
92
    length = size + (s - (s & ~(PAGE_SIZE - 1)));
76
    cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
93
    cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
77
 
94
 
78
    for (i = 0; i < cnt; i++)
95
    for (i = 0; i < cnt; i++)
-
 
96
        page_mapping_insert(AS_KERNEL, s + i * PAGE_SIZE,
79
        page_mapping_insert(AS_KERNEL, s + i * PAGE_SIZE, s + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
97
            s + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
80
 
98
 
-
 
99
    /* Repel prefetched accesses to the old mapping. */
-
 
100
    memory_barrier();
81
}
101
}
82
 
102
 
83
/** Insert mapping of page to frame.
103
/** Insert mapping of page to frame.
84
 *
104
 *
85
 * Map virtual address page to physical address frame
105
 * Map virtual address page to physical address frame
86
 * using flags. Allocate and setup any missing page tables.
106
 * using flags. Allocate and setup any missing page tables.
87
 *
107
 *
88
 * The page table must be locked and interrupts must be disabled.
108
 * The page table must be locked and interrupts must be disabled.
89
 *
109
 *
90
 * @param as Address space to wich page belongs.
110
 * @param as        Address space to wich page belongs.
91
 * @param page Virtual address of the page to be mapped.
111
 * @param page      Virtual address of the page to be mapped.
92
 * @param frame Physical address of memory frame to which the mapping is done.
112
 * @param frame     Physical address of memory frame to which the mapping is
-
 
113
 *          done.
93
 * @param flags Flags to be used for mapping.
114
 * @param flags     Flags to be used for mapping.
94
 */
115
 */
95
void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
116
void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
96
{
117
{
97
    ASSERT(page_mapping_operations);
118
    ASSERT(page_mapping_operations);
98
    ASSERT(page_mapping_operations->mapping_insert);
119
    ASSERT(page_mapping_operations->mapping_insert);
99
   
120
   
100
    page_mapping_operations->mapping_insert(as, page, frame, flags);
121
    page_mapping_operations->mapping_insert(as, page, frame, flags);
-
 
122
   
-
 
123
    /* Repel prefetched accesses to the old mapping. */
-
 
124
    memory_barrier();
101
}
125
}
102
 
126
 
103
/** Remove mapping of page.
127
/** Remove mapping of page.
104
 *
128
 *
105
 * Remove any mapping of page within address space as.
129
 * Remove any mapping of page within address space as.
106
 * TLB shootdown should follow in order to make effects of
130
 * TLB shootdown should follow in order to make effects of
107
 * this call visible.
131
 * this call visible.
108
 *
132
 *
109
 * The page table must be locked and interrupts must be disabled.
133
 * The page table must be locked and interrupts must be disabled.
110
 *
134
 *
111
 * @param as Address space to wich page belongs.
135
 * @param as        Address space to wich page belongs.
112
 * @param page Virtual address of the page to be demapped.
136
 * @param page      Virtual address of the page to be demapped.
113
 */
137
 */
114
void page_mapping_remove(as_t *as, uintptr_t page)
138
void page_mapping_remove(as_t *as, uintptr_t page)
115
{
139
{
116
    ASSERT(page_mapping_operations);
140
    ASSERT(page_mapping_operations);
117
    ASSERT(page_mapping_operations->mapping_remove);
141
    ASSERT(page_mapping_operations->mapping_remove);
118
   
142
   
119
    page_mapping_operations->mapping_remove(as, page);
143
    page_mapping_operations->mapping_remove(as, page);
-
 
144
 
-
 
145
    /* Repel prefetched accesses to the old mapping. */
-
 
146
    memory_barrier();
120
}
147
}
121
 
148
 
122
/** Find mapping for virtual page
149
/** Find mapping for virtual page
123
 *
150
 *
124
 * Find mapping for virtual page.
151
 * Find mapping for virtual page.
125
 *
152
 *
126
 * The page table must be locked and interrupts must be disabled.
153
 * The page table must be locked and interrupts must be disabled.
127
 *
154
 *
128
 * @param as Address space to wich page belongs.
155
 * @param as        Address space to wich page belongs.
129
 * @param page Virtual page.
156
 * @param page      Virtual page.
130
 *
157
 *
131
 * @return NULL if there is no such mapping; requested mapping otherwise.
158
 * @return      NULL if there is no such mapping; requested mapping
-
 
159
 *          otherwise.
132
 */
160
 */
133
pte_t *page_mapping_find(as_t *as, uintptr_t page)
161
pte_t *page_mapping_find(as_t *as, uintptr_t page)
134
{
162
{
135
    ASSERT(page_mapping_operations);
163
    ASSERT(page_mapping_operations);
136
    ASSERT(page_mapping_operations->mapping_find);
164
    ASSERT(page_mapping_operations->mapping_find);