Subversion Repositories HelenOS

Rev

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

Rev 1817 Rev 1818
Line 50... Line 50...
50
uintptr_t last_frame = 0;
50
uintptr_t last_frame = 0;
51
 
51
 
52
#define L1_PT_SHIFT 10
52
#define L1_PT_SHIFT 10
53
#define L2_PT_SHIFT 0
53
#define L2_PT_SHIFT 0
54
 
54
 
-
 
55
#define L1_PT_ENTRIES   1024
-
 
56
#define L2_PT_ENTRIES   1024
-
 
57
 
55
#define L1_OFFSET_MASK          0x3ff
58
#define L1_OFFSET_MASK          (L1_PT_ENTRIES - 1)
56
#define L2_OFFSET_MASK          0x3ff
59
#define L2_OFFSET_MASK          (L2_PT_ENTRIES - 1)
57
 
60
 
58
#define PFN2PTL1_OFFSET(pfn)    ((pfn >> L1_PT_SHIFT) & L1_OFFSET_MASK)
61
#define PFN2PTL1_OFFSET(pfn)    ((pfn >> L1_PT_SHIFT) & L1_OFFSET_MASK)
59
#define PFN2PTL2_OFFSET(pfn)    ((pfn >> L2_PT_SHIFT) & L2_OFFSET_MASK)
62
#define PFN2PTL2_OFFSET(pfn)    ((pfn >> L2_PT_SHIFT) & L2_OFFSET_MASK)
60
 
63
 
61
#define PAGE_MASK   (~(PAGE_SIZE - 1))
64
#define PAGE_MASK   (~(PAGE_SIZE - 1))
Line 83... Line 86...
83
        pfn_t start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.pt_base), PAGE_SIZE)) + start_info.nr_pt_frames;
86
        pfn_t start = ADDR2PFN(ALIGN_UP(KA2PA(start_info.pt_base), PAGE_SIZE)) + start_info.nr_pt_frames;
84
        size_t size = start_info.nr_pages - start;
87
        size_t size = start_info.nr_pages - start;
85
       
88
       
86
        /* Create identity mapping */
89
        /* Create identity mapping */
87
        pfn_t phys;
90
        pfn_t phys;
-
 
91
        count_t count = 0;
88
        for (phys = start; phys < start + size; phys++) {
92
        for (phys = start; phys < start + size; phys++) {
89
            mmu_update_t updates[1];
93
            mmu_update_t updates[L2_PT_ENTRIES];
90
            pfn_t virt = ADDR2PFN(PA2KA(PFN2ADDR(phys)));
94
            pfn_t virt = ADDR2PFN(PA2KA(PFN2ADDR(phys)));
91
           
95
           
92
            size_t ptl1_offset = PFN2PTL1_OFFSET(virt);
96
            size_t ptl1_offset = PFN2PTL1_OFFSET(virt);
93
            size_t ptl2_offset = PFN2PTL2_OFFSET(virt);
97
            size_t ptl2_offset = PFN2PTL2_OFFSET(virt);
94
           
98
           
Line 107... Line 111...
107
                unsigned long *ptl2_base2 = (unsigned long *) PTE2ADDR(start_info.pt_base[ptl1_offset2]);
111
                unsigned long *ptl2_base2 = (unsigned long *) PTE2ADDR(start_info.pt_base[ptl1_offset2]);
108
               
112
               
109
                if (ptl2_base2 == 0)
113
                if (ptl2_base2 == 0)
110
                    panic("Unable to find page table reference");
114
                    panic("Unable to find page table reference");
111
               
115
               
112
                updates[0].ptr = (uintptr_t) &ptl2_base2[ptl2_offset2];
116
                updates[count].ptr = (uintptr_t) &ptl2_base2[ptl2_offset2];
113
                updates[0].val = PFN2ADDR(start_info.mfn_list[start]) | L1_PROT;
117
                updates[count].val = PFN2ADDR(start_info.mfn_list[start]) | L1_PROT;
114
                if (xen_mmu_update(updates, 1, NULL, DOMID_SELF) < 0)
118
                if (xen_mmu_update(updates, count + 1, NULL, DOMID_SELF) < 0)
115
                    panic("Unable to map new page table");
119
                    panic("Unable to map new page table");
-
 
120
                count = 0;
116
               
121
               
117
                mmu_ext.cmd = MMUEXT_PIN_L1_TABLE;
122
                mmu_ext.cmd = MMUEXT_PIN_L1_TABLE;
118
                mmu_ext.arg1.mfn = start_info.mfn_list[start];
123
                mmu_ext.arg1.mfn = start_info.mfn_list[start];
119
                if (xen_mmuext_op(&mmu_ext, 1, NULL, DOMID_SELF) < 0)
124
                if (xen_mmuext_op(&mmu_ext, 1, NULL, DOMID_SELF) < 0)
120
                    panic("Error pinning new page table");
125
                    panic("Error pinning new page table");
121
               
126
               
122
                unsigned long *ptl0 = (unsigned long *) PFN2ADDR(start_info.mfn_list[ADDR2PFN(KA2PA(start_info.pt_base))]);
127
                unsigned long *ptl0 = (unsigned long *) PFN2ADDR(start_info.mfn_list[ADDR2PFN(KA2PA(start_info.pt_base))]);
123
               
128
               
124
                updates[0].ptr = (uintptr_t) &ptl0[ptl1_offset];
129
                updates[count].ptr = (uintptr_t) &ptl0[ptl1_offset];
125
                updates[0].val = PFN2ADDR(start_info.mfn_list[start]) | L2_PROT;
130
                updates[count].val = PFN2ADDR(start_info.mfn_list[start]) | L2_PROT;
126
                if (xen_mmu_update(updates, 1, NULL, DOMID_SELF) < 0)
131
                if (xen_mmu_update(updates, count + 1, NULL, DOMID_SELF) < 0)
127
                    panic("Unable to update PTE for page table");
132
                    panic("Unable to update PTE for page table");
-
 
133
                count = 0;
128
               
134
               
129
                ptl2_base = (unsigned long *) PTE2ADDR(start_info.pt_base[ptl1_offset]);
135
                ptl2_base = (unsigned long *) PTE2ADDR(start_info.pt_base[ptl1_offset]);
130
                start++;
136
                start++;
131
                size--;
137
                size--;
132
            }
138
            }
133
           
139
           
134
            updates[0].ptr = (uintptr_t) &ptl2_base[ptl2_offset];
140
            updates[count].ptr = (uintptr_t) &ptl2_base[ptl2_offset];
135
            updates[0].val = PFN2ADDR(start_info.mfn_list[phys]) | L2_PROT;
141
            updates[count].val = PFN2ADDR(start_info.mfn_list[phys]) | L2_PROT;
-
 
142
            count++;
-
 
143
           
-
 
144
            if ((count == L2_PT_ENTRIES) || (phys + 1 == start + size)) {
136
            if (xen_mmu_update(updates, 1, NULL, DOMID_SELF) < 0)
145
                if (xen_mmu_update(updates, count, NULL, DOMID_SELF) < 0)
137
                panic("Unable to update PTE");
146
                    panic("Unable to update PTE");
-
 
147
                count = 0;
-
 
148
            }
138
        }
149
        }
139
       
150
       
140
        zone_create(start, size, start, 0);
151
        zone_create(start, size, start, 0);
141
        last_frame = start + size;
152
        last_frame = start + size;
142
    }
153
    }