Changeset 228 for soft/giet_vm/sys/vm_handler.c
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/vm_handler.c
r207 r228 20 20 21 21 ///////////////////////////////////////////////////////////////////////////// 22 // 22 // Global variable : IOMMU page table 23 23 ///////////////////////////////////////////////////////////////////////////// 24 24 25 __attribute__((section (".iommu"))) page_table_t 25 __attribute__((section (".iommu"))) page_table_t _iommu_ptab; 26 26 27 27 ////////////////////////////////////////////////////////////////////////////// 28 28 // _iommu_add_pte2() 29 29 ////////////////////////////////////////////////////////////////////////////// 30 void _iommu_add_pte2( unsigned int ix1,31 unsigned int ix2,32 unsigned int ppn,33 unsigned int flags )34 {35 unsigned int 36 unsigned int *pt_ppn;37 unsigned int *pt_flags;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; 38 38 39 39 // get pointer on iommu page table 40 page_table_t * pt = &_iommu_ptab;40 page_table_t * pt = &_iommu_ptab; 41 41 42 42 // get ptba and update PT2 43 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 44 { 43 if ((pt->pt1[ix1] & PTE_V) == 0) { 45 44 _puts("\n[GIET ERROR] in iommu_add_pte2 function\n"); 46 45 _puts("the IOMMU PT1 entry is not mapped / ix1 = "); … … 49 48 _exit(); 50 49 } 51 else 52 { 53 ptba = pt->pt1[ix1] << 12; 54 pt_flags = (unsigned int*)(ptba + 8*ix2); 55 pt_ppn = (unsigned int*)(ptba + 8*ix2 + 4); 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); 56 54 *pt_flags = flags; 57 *pt_ppn 55 *pt_ppn = ppn; 58 56 } 59 57 } // end _iommu_add_pte2() 58 60 59 61 60 ////////////////////////////////////////////////////////////////////////////// 62 61 // _iommu_inval_pte2() 63 62 ////////////////////////////////////////////////////////////////////////////// 64 void _iommu_inval_pte2( unsigned int ix1, 65 unsigned int ix2 ) 66 { 67 unsigned int ptba; 68 unsigned int* pt_flags; 63 void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2) { 64 unsigned int ptba; 65 unsigned int * pt_flags; 69 66 70 67 // get pointer on iommu page table 71 page_table_t * pt = &_iommu_ptab;68 page_table_t * pt = &_iommu_ptab; 72 69 73 70 // get ptba and inval PTE2 74 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 75 { 71 if ((pt->pt1[ix1] & PTE_V) == 0) { 76 72 _puts("\n[GIET ERROR] in iommu_inval_pte2 function\n"); 77 73 _puts("the IOMMU PT1 entry is not mapped / ix1 = "); … … 80 76 _exit(); 81 77 } 82 else 83 { 84 ptba = pt->pt1[ix1] << 12; 85 pt_flags = (unsigned int*)(ptba + 8*ix2); 78 else { 79 ptba = pt->pt1[ix1] << 12; 80 pt_flags = (unsigned int *) (ptba + 8 * ix2); 86 81 *pt_flags = 0; 87 82 } 88 83 } // end _iommu_inval_pte2() 84 89 85 90 86 ////////////////////////////////////////////////////////////////////////////// … … 92 88 // Returns 0 if success, 1 if PTE1 or PTE2 unmapped 93 89 ////////////////////////////////////////////////////////////////////////////// 94 unsigned int _v2p_translate( page_table_t* pt, 95 unsigned int vpn, 96 unsigned int* ppn, 97 unsigned int* flags ) 98 { 99 unsigned int ptba; 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; 100 99 101 register unsigned int* pte2; 102 register unsigned int flags_value; 103 register unsigned int ppn_value; 104 105 unsigned int ix1 = vpn >> 9; 106 unsigned int ix2 = vpn & 0x1FF; 107 /* 108 _puts("\n\n********************** entering v2p_translate"); 109 _puts("\n - pt = "); 110 _putx( (unsigned int)pt ); 111 _puts("\n - vpn = "); 112 _putx( vpn << 12 ); 113 _puts("\n - ptba = "); 114 _putx( pt->pt1[ix1] << 12 ) ; 115 _puts("\n - &pte2 = "); 116 _putx( (pt->pt1[ix1] << 12) + 8*ix2 ); 117 _puts("\n - flags = "); 118 _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) ); 119 _puts("\n"); 120 */ 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 */ 121 116 // check PTE1 mapping 122 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 123 { 117 if ((pt->pt1[ix1] & PTE_V) == 0) { 124 118 return 1; 125 119 } 126 else 127 { 120 else { 128 121 // get physical addresses of pte2 129 122 ptba = pt->pt1[ix1] << 12; 130 pte2 = (unsigned int *)(ptba + 8*ix2);123 pte2 = (unsigned int *) (ptba + 8 * ix2); 131 124 132 125 // gets ppn_value and flags_value, after temporary DTLB desactivation 133 asm volatile ( "li $27, 0xFFFFFFFE \n" /* Mask for IE bits */ 134 "mfc0 $26, $12 \n" /* save SR */ 135 "and $27, $26, $27 \n" 136 "mtc0 $27, $12 \n" /* disable Interrupts */ 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 */ 137 131 138 139 132 "li $27, 0xB \n" 133 "mtc2 $27, $1 \n" /* DTLB unactivated */ 140 134 141 142 143 135 "move $27, %2 \n" /* $27 <= pte2 */ 136 "lw %0, 0($27) \n" /* read flags */ 137 "lw %1, 4($27) \n" /* read ppn */ 144 138 145 146 139 "li $27, 0xF \n" 140 "mtc2 $27, $1 \n" /* DTLB activated */ 147 141 148 149 :"=r"(flags_value), "=r"(ppn_value)150 :"r"(pte2)151 :"$26","$27","$8");142 "mtc0 $26, $12 \n" /* restore SR */ 143 : "=r" (flags_value), "=r" (ppn_value) 144 : "r" (pte2) 145 : "$26","$27","$8"); 152 146 153 147 // check PTE2 mapping 154 if ( (flags_value & PTE_V) == 0 ) 155 { 148 if ((flags_value & PTE_V) == 0) { 156 149 return 1; 157 150 } 158 151 159 152 // set return values 160 *ppn 161 *flags 153 *ppn = ppn_value; 154 *flags = flags_value; 162 155 } 163 156 return 0; 164 } 157 } // end _v2p_translate() 165 158 166 159 // Local Variables: … … 170 163 // indent-tabs-mode: nil 171 164 // End: 165 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 172 166 173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4174 167
Note: See TracChangeset
for help on using the changeset viewer.