Rev 689 | Rev 756 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 689 | Rev 755 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Jermar |
2 | * Copyright (C) 2006 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <genarch/mm/page_pt.h> |
29 | #include <genarch/mm/page_pt.h> |
30 | #include <mm/page.h> |
30 | #include <mm/page.h> |
31 | #include <mm/frame.h> |
31 | #include <mm/frame.h> |
32 | #include <arch/mm/page.h> |
32 | #include <arch/mm/page.h> |
33 | #include <arch/mm/asid.h> |
33 | #include <arch/mm/as.h> |
34 | #include <arch/types.h> |
34 | #include <arch/types.h> |
35 | #include <typedefs.h> |
35 | #include <typedefs.h> |
36 | #include <arch/asm.h> |
36 | #include <arch/asm.h> |
37 | #include <memstr.h> |
37 | #include <memstr.h> |
38 | 38 | ||
39 | static void pt_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root); |
39 | static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root); |
40 | static pte_t *pt_mapping_find(__address page, asid_t asid, __address root); |
40 | static pte_t *pt_mapping_find(as_t *as, __address page, __address root); |
41 | 41 | ||
42 | page_operations_t page_pt_operations = { |
42 | page_operations_t page_pt_operations = { |
43 | .mapping_insert = pt_mapping_insert, |
43 | .mapping_insert = pt_mapping_insert, |
44 | .mapping_find = pt_mapping_find |
44 | .mapping_find = pt_mapping_find |
45 | }; |
45 | }; |
46 | 46 | ||
47 | /** Map page to frame using hierarchical page tables. |
47 | /** Map page to frame using hierarchical page tables. |
48 | * |
48 | * |
49 | * Map virtual address 'page' to physical address 'frame' |
49 | * Map virtual address 'page' to physical address 'frame' |
50 | * using 'flags'. |
50 | * using 'flags'. |
51 | * |
51 | * |
- | 52 | * @param as Ignored. |
|
52 | * @param page Virtual address of the page to be mapped. |
53 | * @param page Virtual address of the page to be mapped. |
53 | * @param asid Ignored. |
- | |
54 | * @param frame Physical address of memory frame to which the mapping is done. |
54 | * @param frame Physical address of memory frame to which the mapping is done. |
55 | * @param flags Flags to be used for mapping. |
55 | * @param flags Flags to be used for mapping. |
56 | * @param root Explicit PTL0 address. |
56 | * @param root Explicit PTL0 address. |
57 | */ |
57 | */ |
58 | void pt_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root) |
58 | void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root) |
59 | { |
59 | { |
60 | pte_t *ptl0, *ptl1, *ptl2, *ptl3; |
60 | pte_t *ptl0, *ptl1, *ptl2, *ptl3; |
61 | __address newpt; |
61 | __address newpt; |
62 | 62 | ||
63 | ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS()); |
63 | ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS()); |
64 | 64 | ||
65 | if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) { |
65 | if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) { |
66 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
66 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
67 | memsetb(newpt, PAGE_SIZE, 0); |
67 | memsetb(newpt, PAGE_SIZE, 0); |
68 | SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt)); |
68 | SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt)); |
69 | SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
69 | SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
70 | } |
70 | } |
71 | 71 | ||
72 | ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page))); |
72 | ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page))); |
73 | 73 | ||
74 | if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) { |
74 | if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) { |
75 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
75 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
76 | memsetb(newpt, PAGE_SIZE, 0); |
76 | memsetb(newpt, PAGE_SIZE, 0); |
77 | SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt)); |
77 | SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt)); |
78 | SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
78 | SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
79 | } |
79 | } |
80 | 80 | ||
81 | ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page))); |
81 | ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page))); |
82 | 82 | ||
83 | if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) { |
83 | if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) { |
84 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
84 | newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
85 | memsetb(newpt, PAGE_SIZE, 0); |
85 | memsetb(newpt, PAGE_SIZE, 0); |
86 | SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt)); |
86 | SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt)); |
87 | SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
87 | SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE); |
88 | } |
88 | } |
89 | 89 | ||
90 | ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page))); |
90 | ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page))); |
91 | 91 | ||
92 | SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(page), frame); |
92 | SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(page), frame); |
93 | SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags); |
93 | SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags); |
94 | } |
94 | } |
95 | 95 | ||
96 | /** Find mapping for virtual page in hierarchical page tables. |
96 | /** Find mapping for virtual page in hierarchical page tables. |
97 | * |
97 | * |
98 | * Find mapping for virtual page. |
98 | * Find mapping for virtual page. |
99 | * |
99 | * |
- | 100 | * @param as Ignored. |
|
100 | * @param page Virtual page. |
101 | * @param page Virtual page. |
101 | * @param asid Ignored. |
- | |
102 | * @param root PTL0 address if non-zero. |
102 | * @param root PTL0 address if non-zero. |
103 | * |
103 | * |
104 | * @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise. |
104 | * @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise. |
105 | */ |
105 | */ |
106 | pte_t *pt_mapping_find(__address page, asid_t asid, __address root) |
106 | pte_t *pt_mapping_find(as_t *as, __address page, __address root) |
107 | { |
107 | { |
108 | pte_t *ptl0, *ptl1, *ptl2, *ptl3; |
108 | pte_t *ptl0, *ptl1, *ptl2, *ptl3; |
109 | 109 | ||
110 | ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS()); |
110 | ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS()); |
111 | 111 | ||
112 | if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) |
112 | if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) |
113 | return NULL; |
113 | return NULL; |
114 | 114 | ||
115 | ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page))); |
115 | ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page))); |
116 | 116 | ||
117 | if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) |
117 | if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) |
118 | return NULL; |
118 | return NULL; |
119 | 119 | ||
120 | ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page))); |
120 | ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page))); |
121 | 121 | ||
122 | if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) |
122 | if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) |
123 | return NULL; |
123 | return NULL; |
124 | 124 | ||
125 | ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page))); |
125 | ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page))); |
126 | 126 | ||
127 | return &ptl3[PTL3_INDEX(page)]; |
127 | return &ptl3[PTL3_INDEX(page)]; |
128 | } |
128 | } |
129 | 129 |