Subversion Repositories HelenOS

Rev

Rev 2222 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2222 Rev 3128
Line 43... Line 43...
43
#include <mm/page.h>
43
#include <mm/page.h>
44
#include <arch/mm/page.h>
44
#include <arch/mm/page.h>
45
#include <arch/mm/asid.h>
45
#include <arch/mm/asid.h>
46
#include <mm/as.h>
46
#include <mm/as.h>
47
#include <mm/frame.h>
47
#include <mm/frame.h>
-
 
48
#include <arch/barrier.h>
48
#include <arch/types.h>
49
#include <arch/types.h>
49
#include <arch/asm.h>
50
#include <arch/asm.h>
50
#include <memstr.h>
51
#include <memstr.h>
51
#include <debug.h>
52
#include <debug.h>
52
#include <arch.h>
53
#include <arch.h>
Line 63... Line 64...
63
 *
64
 *
64
 * Identity-map memory structure
65
 * Identity-map memory structure
65
 * considering possible crossings
66
 * considering possible crossings
66
 * of page boundaries.
67
 * of page boundaries.
67
 *
68
 *
68
 * @param s Address of the structure.
69
 * @param s     Address of the structure.
69
 * @param size Size of the structure.
70
 * @param size      Size of the structure.
70
 */
71
 */
71
void map_structure(uintptr_t s, size_t size)
72
void map_structure(uintptr_t s, size_t size)
72
{
73
{
73
    int i, cnt, length;
74
    int i, cnt, length;
74
 
75
 
75
    length = size + (s - (s & ~(PAGE_SIZE - 1)));
76
    length = size + (s - (s & ~(PAGE_SIZE - 1)));
76
    cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
77
    cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
77
 
78
 
78
    for (i = 0; i < cnt; i++)
79
    for (i = 0; i < cnt; i++)
-
 
80
        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);
81
            s + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
80
 
82
 
-
 
83
    /* Repel prefetched accesses to the old mapping. */
-
 
84
    memory_barrier();
81
}
85
}
82
 
86
 
83
/** Insert mapping of page to frame.
87
/** Insert mapping of page to frame.
84
 *
88
 *
85
 * Map virtual address page to physical address frame
89
 * Map virtual address page to physical address frame
86
 * using flags. Allocate and setup any missing page tables.
90
 * using flags. Allocate and setup any missing page tables.
87
 *
91
 *
88
 * The page table must be locked and interrupts must be disabled.
92
 * The page table must be locked and interrupts must be disabled.
89
 *
93
 *
90
 * @param as Address space to wich page belongs.
94
 * @param as        Address space to wich page belongs.
91
 * @param page Virtual address of the page to be mapped.
95
 * @param page      Virtual address of the page to be mapped.
92
 * @param frame Physical address of memory frame to which the mapping is done.
96
 * @param frame     Physical address of memory frame to which the mapping is
-
 
97
 *          done.
93
 * @param flags Flags to be used for mapping.
98
 * @param flags     Flags to be used for mapping.
94
 */
99
 */
95
void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
100
void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
96
{
101
{
97
    ASSERT(page_mapping_operations);
102
    ASSERT(page_mapping_operations);
98
    ASSERT(page_mapping_operations->mapping_insert);
103
    ASSERT(page_mapping_operations->mapping_insert);
99
   
104
   
100
    page_mapping_operations->mapping_insert(as, page, frame, flags);
105
    page_mapping_operations->mapping_insert(as, page, frame, flags);
-
 
106
   
-
 
107
    /* Repel prefetched accesses to the old mapping. */
-
 
108
    memory_barrier();
101
}
109
}
102
 
110
 
103
/** Remove mapping of page.
111
/** Remove mapping of page.
104
 *
112
 *
105
 * Remove any mapping of page within address space as.
113
 * Remove any mapping of page within address space as.
106
 * TLB shootdown should follow in order to make effects of
114
 * TLB shootdown should follow in order to make effects of
107
 * this call visible.
115
 * this call visible.
108
 *
116
 *
109
 * The page table must be locked and interrupts must be disabled.
117
 * The page table must be locked and interrupts must be disabled.
110
 *
118
 *
111
 * @param as Address space to wich page belongs.
119
 * @param as        Address space to wich page belongs.
112
 * @param page Virtual address of the page to be demapped.
120
 * @param page      Virtual address of the page to be demapped.
113
 */
121
 */
114
void page_mapping_remove(as_t *as, uintptr_t page)
122
void page_mapping_remove(as_t *as, uintptr_t page)
115
{
123
{
116
    ASSERT(page_mapping_operations);
124
    ASSERT(page_mapping_operations);
117
    ASSERT(page_mapping_operations->mapping_remove);
125
    ASSERT(page_mapping_operations->mapping_remove);
118
   
126
   
119
    page_mapping_operations->mapping_remove(as, page);
127
    page_mapping_operations->mapping_remove(as, page);
-
 
128
 
-
 
129
    /* Repel prefetched accesses to the old mapping. */
-
 
130
    memory_barrier();
120
}
131
}
121
 
132
 
122
/** Find mapping for virtual page
133
/** Find mapping for virtual page
123
 *
134
 *
124
 * Find mapping for virtual page.
135
 * Find mapping for virtual page.
125
 *
136
 *
126
 * The page table must be locked and interrupts must be disabled.
137
 * The page table must be locked and interrupts must be disabled.
127
 *
138
 *
128
 * @param as Address space to wich page belongs.
139
 * @param as        Address space to wich page belongs.
129
 * @param page Virtual page.
140
 * @param page      Virtual page.
130
 *
141
 *
131
 * @return NULL if there is no such mapping; requested mapping otherwise.
142
 * @return      NULL if there is no such mapping; requested mapping
-
 
143
 *          otherwise.
132
 */
144
 */
133
pte_t *page_mapping_find(as_t *as, uintptr_t page)
145
pte_t *page_mapping_find(as_t *as, uintptr_t page)
134
{
146
{
135
    ASSERT(page_mapping_operations);
147
    ASSERT(page_mapping_operations);
136
    ASSERT(page_mapping_operations->mapping_find);
148
    ASSERT(page_mapping_operations->mapping_find);