[167] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : vm_handler.c |
---|
| 3 | // Date : 01/07/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // The vm_handler.c and vm_handler.h files are part ot the GIET nano kernel. |
---|
| 8 | // They contains the kernel data structures and functions used to dynamically |
---|
| 9 | // handle the iommu page table. |
---|
| 10 | // |
---|
| 11 | // TODO : We must transfer here the functions used to statically build |
---|
| 12 | // the page tables associated to the various vspaces (now in boot_handler.c) |
---|
| 13 | // |
---|
| 14 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 15 | |
---|
| 16 | #include <vm_handler.h> |
---|
| 17 | #include <sys_handler.h> |
---|
| 18 | #include <common.h> |
---|
| 19 | #include <giet_config.h> |
---|
| 20 | |
---|
| 21 | ///////////////////////////////////////////////////////////////////////////// |
---|
[228] | 22 | // Global variable : IOMMU page table |
---|
[167] | 23 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 24 | |
---|
[228] | 25 | __attribute__((section (".iommu"))) page_table_t _iommu_ptab; |
---|
[167] | 26 | |
---|
| 27 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 28 | // _iommu_add_pte2() |
---|
| 29 | ////////////////////////////////////////////////////////////////////////////// |
---|
[228] | 30 | void _iommu_add_pte2( |
---|
| 31 | unsigned int ix1, |
---|
| 32 | unsigned int ix2, |
---|
| 33 | unsigned int ppn, |
---|
| 34 | unsigned int flags) { |
---|
| 35 | unsigned int ptba; |
---|
| 36 | unsigned int * pt_ppn; |
---|
| 37 | unsigned int * pt_flags; |
---|
[167] | 38 | |
---|
| 39 | // get pointer on iommu page table |
---|
[228] | 40 | page_table_t * pt = &_iommu_ptab; |
---|
[167] | 41 | |
---|
| 42 | // get ptba and update PT2 |
---|
[228] | 43 | if ((pt->pt1[ix1] & PTE_V) == 0) { |
---|
[167] | 44 | _puts("\n[GIET ERROR] in iommu_add_pte2 function\n"); |
---|
| 45 | _puts("the IOMMU PT1 entry is not mapped / ix1 = "); |
---|
[207] | 46 | _putx( ix1 ); |
---|
[167] | 47 | _puts("\n"); |
---|
| 48 | _exit(); |
---|
| 49 | } |
---|
[228] | 50 | else { |
---|
| 51 | ptba = pt->pt1[ix1] << 12; |
---|
| 52 | pt_flags = (unsigned int *) (ptba + 8 * ix2); |
---|
| 53 | pt_ppn = (unsigned int *) (ptba + 8 * ix2 + 4); |
---|
[167] | 54 | *pt_flags = flags; |
---|
[228] | 55 | *pt_ppn = ppn; |
---|
[167] | 56 | } |
---|
| 57 | } // end _iommu_add_pte2() |
---|
| 58 | |
---|
[228] | 59 | |
---|
[167] | 60 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 61 | // _iommu_inval_pte2() |
---|
| 62 | ////////////////////////////////////////////////////////////////////////////// |
---|
[228] | 63 | void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2) { |
---|
| 64 | unsigned int ptba; |
---|
| 65 | unsigned int * pt_flags; |
---|
[167] | 66 | |
---|
| 67 | // get pointer on iommu page table |
---|
[228] | 68 | page_table_t * pt = &_iommu_ptab; |
---|
[167] | 69 | |
---|
| 70 | // get ptba and inval PTE2 |
---|
[228] | 71 | if ((pt->pt1[ix1] & PTE_V) == 0) { |
---|
[167] | 72 | _puts("\n[GIET ERROR] in iommu_inval_pte2 function\n"); |
---|
| 73 | _puts("the IOMMU PT1 entry is not mapped / ix1 = "); |
---|
[207] | 74 | _putx( ix1 ); |
---|
[167] | 75 | _puts("\n"); |
---|
| 76 | _exit(); |
---|
| 77 | } |
---|
[228] | 78 | else { |
---|
| 79 | ptba = pt->pt1[ix1] << 12; |
---|
| 80 | pt_flags = (unsigned int *) (ptba + 8 * ix2); |
---|
[167] | 81 | *pt_flags = 0; |
---|
| 82 | } |
---|
| 83 | } // end _iommu_inval_pte2() |
---|
| 84 | |
---|
[228] | 85 | |
---|
[167] | 86 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 87 | // _v2p_translate() |
---|
| 88 | // Returns 0 if success, 1 if PTE1 or PTE2 unmapped |
---|
| 89 | ////////////////////////////////////////////////////////////////////////////// |
---|
[228] | 90 | unsigned int _v2p_translate( |
---|
| 91 | page_table_t * pt, |
---|
| 92 | unsigned int vpn, |
---|
| 93 | unsigned int * ppn, |
---|
| 94 | unsigned int * flags) { |
---|
| 95 | unsigned int ptba; |
---|
| 96 | register unsigned int * pte2; |
---|
| 97 | register unsigned int flags_value; |
---|
| 98 | register unsigned int ppn_value; |
---|
[167] | 99 | |
---|
[228] | 100 | unsigned int ix1 = vpn >> 9; |
---|
| 101 | unsigned int ix2 = vpn & 0x1FF; |
---|
| 102 | /* |
---|
| 103 | _puts("\n\n********************** entering v2p_translate"); |
---|
| 104 | _puts("\n - pt = "); |
---|
| 105 | _putx( (unsigned int)pt ); |
---|
| 106 | _puts("\n - vpn = "); |
---|
| 107 | _putx( vpn << 12 ); |
---|
| 108 | _puts("\n - ptba = "); |
---|
| 109 | _putx( pt->pt1[ix1] << 12 ) ; |
---|
| 110 | _puts("\n - &pte2 = "); |
---|
| 111 | _putx( (pt->pt1[ix1] << 12) + 8*ix2 ); |
---|
| 112 | _puts("\n - flags = "); |
---|
| 113 | _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) ); |
---|
| 114 | _puts("\n"); |
---|
| 115 | */ |
---|
[167] | 116 | // check PTE1 mapping |
---|
[228] | 117 | if ((pt->pt1[ix1] & PTE_V) == 0) { |
---|
[167] | 118 | return 1; |
---|
| 119 | } |
---|
[228] | 120 | else { |
---|
[167] | 121 | // get physical addresses of pte2 |
---|
| 122 | ptba = pt->pt1[ix1] << 12; |
---|
[228] | 123 | pte2 = (unsigned int *) (ptba + 8 * ix2); |
---|
[167] | 124 | |
---|
| 125 | // gets ppn_value and flags_value, after temporary DTLB desactivation |
---|
[228] | 126 | asm volatile ( |
---|
| 127 | "li $27, 0xFFFFFFFE \n" /* Mask for IE bits */ |
---|
| 128 | "mfc0 $26, $12 \n" /* save SR */ |
---|
| 129 | "and $27, $26, $27 \n" |
---|
| 130 | "mtc0 $27, $12 \n" /* disable Interrupts */ |
---|
[184] | 131 | |
---|
[228] | 132 | "li $27, 0xB \n" |
---|
| 133 | "mtc2 $27, $1 \n" /* DTLB unactivated */ |
---|
[189] | 134 | |
---|
[228] | 135 | "move $27, %2 \n" /* $27 <= pte2 */ |
---|
| 136 | "lw %0, 0($27) \n" /* read flags */ |
---|
| 137 | "lw %1, 4($27) \n" /* read ppn */ |
---|
[184] | 138 | |
---|
[228] | 139 | "li $27, 0xF \n" |
---|
| 140 | "mtc2 $27, $1 \n" /* DTLB activated */ |
---|
[189] | 141 | |
---|
[228] | 142 | "mtc0 $26, $12 \n" /* restore SR */ |
---|
| 143 | : "=r" (flags_value), "=r" (ppn_value) |
---|
| 144 | : "r" (pte2) |
---|
| 145 | : "$26","$27","$8"); |
---|
[167] | 146 | |
---|
| 147 | // check PTE2 mapping |
---|
[228] | 148 | if ((flags_value & PTE_V) == 0) { |
---|
[167] | 149 | return 1; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | // set return values |
---|
[228] | 153 | *ppn = ppn_value; |
---|
| 154 | *flags = flags_value; |
---|
[167] | 155 | } |
---|
| 156 | return 0; |
---|
[228] | 157 | } // end _v2p_translate() |
---|
[167] | 158 | |
---|
| 159 | // Local Variables: |
---|
| 160 | // tab-width: 4 |
---|
| 161 | // c-basic-offset: 4 |
---|
| 162 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 163 | // indent-tabs-mode: nil |
---|
| 164 | // End: |
---|
[228] | 165 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
[167] | 166 | |
---|
| 167 | |
---|