[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : vmem.c |
---|
| 3 | // Date : 01/07/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | |
---|
[455] | 8 | #include <tty0.h> |
---|
[258] | 9 | #include <utils.h> |
---|
| 10 | #include <vmem.h> |
---|
[534] | 11 | #include <ctx_handler.h> |
---|
[258] | 12 | #include <giet_config.h> |
---|
| 13 | |
---|
[534] | 14 | /////////////////////////////////////////////////////// |
---|
| 15 | unsigned long long _v2p_translate( unsigned int vaddr, |
---|
| 16 | unsigned int* flags ) |
---|
[258] | 17 | { |
---|
| 18 | unsigned long long ptba; |
---|
| 19 | unsigned long long pte2_paddr; |
---|
| 20 | |
---|
[351] | 21 | unsigned int pte2_msb; |
---|
| 22 | unsigned int pte2_lsb; |
---|
[345] | 23 | unsigned int flags_value; |
---|
| 24 | unsigned int ppn_value; |
---|
[258] | 25 | |
---|
[345] | 26 | unsigned int save_sr; |
---|
[534] | 27 | |
---|
| 28 | // decode the vaddr fields |
---|
| 29 | unsigned int offset = vaddr & 0xFFF; |
---|
| 30 | unsigned int ix1 = (vaddr >> 21) & 0x7FF; |
---|
| 31 | unsigned int ix2 = (vaddr >> 12) & 0x1FF; |
---|
[345] | 32 | |
---|
[534] | 33 | // get page table vbase address |
---|
| 34 | page_table_t* pt = (page_table_t*)_get_context_slot(CTX_PTAB_ID); |
---|
| 35 | |
---|
[258] | 36 | // get PTE1 |
---|
[534] | 37 | unsigned int pte1 = pt->pt1[ix1]; |
---|
[258] | 38 | |
---|
| 39 | // check PTE1 mapping |
---|
[408] | 40 | if ( (pte1 & PTE_V) == 0 ) |
---|
| 41 | { |
---|
[495] | 42 | _printf("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n" |
---|
[534] | 43 | " vaddr = %x / ptab = %x / pte1_vaddr = %x / pte1_value = %x\n", |
---|
| 44 | vaddr , (unsigned int)pt, &(pt->pt1[ix1]) , pte1 ); |
---|
[408] | 45 | _exit(); |
---|
| 46 | } |
---|
[258] | 47 | |
---|
[408] | 48 | // test big/small page |
---|
| 49 | if ( (pte1 & PTE_T) == 0 ) // big page |
---|
| 50 | { |
---|
| 51 | *flags = pte1 & 0xFFC00000; |
---|
[534] | 52 | offset = offset | (ix2<<12); |
---|
| 53 | return (((unsigned long long)(pte1 & 0x7FFFF)) << 21) | offset; |
---|
[408] | 54 | } |
---|
| 55 | else // small page |
---|
| 56 | { |
---|
[258] | 57 | |
---|
[495] | 58 | // get physical addresses of pte2 |
---|
| 59 | ptba = ((unsigned long long)(pte1 & 0x0FFFFFFF)) << 12; |
---|
[408] | 60 | pte2_paddr = ptba + 8*ix2; |
---|
[495] | 61 | |
---|
| 62 | // split physical address in two 32 bits words |
---|
[408] | 63 | pte2_lsb = (unsigned int) pte2_paddr; |
---|
| 64 | pte2_msb = (unsigned int) (pte2_paddr >> 32); |
---|
[345] | 65 | |
---|
[408] | 66 | // disable interrupts and save status register |
---|
| 67 | _it_disable( &save_sr ); |
---|
| 68 | |
---|
| 69 | // get ppn_value and flags_value, using a physical read |
---|
| 70 | // after temporary DTLB desactivation |
---|
| 71 | asm volatile ( |
---|
[345] | 72 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
---|
| 73 | "andi $3, $2, 0xb \n" |
---|
| 74 | "mtc2 $3, $1 \n" /* DTLB off */ |
---|
[258] | 75 | |
---|
[351] | 76 | "move $4, %3 \n" /* $4 <= pte_lsb */ |
---|
[408] | 77 | "mtc2 %2, $24 \n" /* PADDR_EXT <= pte_msb */ |
---|
[351] | 78 | "lw %0, 0($4) \n" /* read flags */ |
---|
| 79 | "lw %1, 4($4) \n" /* read ppn */ |
---|
[258] | 80 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
| 81 | |
---|
[345] | 82 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
---|
[258] | 83 | : "=r" (flags_value), "=r" (ppn_value) |
---|
[345] | 84 | : "r" (pte2_msb) , "r" (pte2_lsb) |
---|
[351] | 85 | : "$2", "$3", "$4" ); |
---|
[258] | 86 | |
---|
[408] | 87 | // restore saved status register |
---|
| 88 | _it_restore( &save_sr ); |
---|
[345] | 89 | |
---|
[408] | 90 | // check PTE2 mapping |
---|
| 91 | if ( (flags_value & PTE_V) == 0 ) |
---|
| 92 | { |
---|
[495] | 93 | _printf("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n" |
---|
[534] | 94 | " vaddr = %x / ptab = %x / pte1_value = %x\n" |
---|
[495] | 95 | " pte2_paddr = %l / ppn = %x / flags = %x\n", |
---|
[534] | 96 | vaddr , pt , pte1 , pte2_paddr , ppn_value , flags_value ); |
---|
[408] | 97 | _exit(); |
---|
| 98 | } |
---|
[534] | 99 | |
---|
| 100 | *flags = flags_value & 0xFFC00000; |
---|
| 101 | return (((unsigned long long)(ppn_value & 0x0FFFFFFF)) << 12) | offset; |
---|
[408] | 102 | } |
---|
[258] | 103 | } // end _v2p_translate() |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | // Local Variables: |
---|
| 108 | // tab-width: 4 |
---|
| 109 | // c-basic-offset: 4 |
---|
| 110 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 111 | // indent-tabs-mode: nil |
---|
| 112 | // End: |
---|
| 113 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 114 | |
---|
| 115 | |
---|