| [408] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : iommu.c |
|---|
| 3 | // Date : 01/09/2014 |
|---|
| 4 | // Author : alain greiner |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | // The iommu.c and iommu.h files are part ot the GIET-VM nano kernel. |
|---|
| 8 | // They contain the functions used to dynamically handle the iommu page table. |
|---|
| 9 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 10 | |
|---|
| 11 | #include <utils.h> |
|---|
| 12 | #include <tty_driver.h> |
|---|
| 13 | #include <vmem.h> |
|---|
| 14 | #include <giet_config.h> |
|---|
| 15 | #include <tty_driver.h> |
|---|
| 16 | |
|---|
| 17 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 18 | // Global variable : IOMMU page table. |
|---|
| 19 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 20 | |
|---|
| 21 | extern page_table_t _iommu_ptab; |
|---|
| 22 | |
|---|
| 23 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 24 | // This function map a PTE2 in IOMMU page table |
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 26 | void _iommu_add_pte2( unsigned int ix1, |
|---|
| 27 | unsigned int ix2, |
|---|
| 28 | unsigned int ppn, |
|---|
| 29 | unsigned int flags ) |
|---|
| 30 | { |
|---|
| 31 | unsigned int ptba; |
|---|
| 32 | unsigned int * pt_ppn; |
|---|
| 33 | unsigned int * pt_flags; |
|---|
| 34 | |
|---|
| 35 | // get pointer on iommu page table |
|---|
| 36 | page_table_t* pt = &_iommu_ptab; |
|---|
| 37 | |
|---|
| 38 | // get ptba and update PT2 |
|---|
| 39 | if ((pt->pt1[ix1] & PTE_V) == 0) |
|---|
| 40 | { |
|---|
| 41 | _printf("\n[GIET ERROR] in iommu_add_pte2() : " |
|---|
| 42 | "IOMMU PT1 entry not mapped / ix1 = %d\n", ix1 ); |
|---|
| 43 | _exit(); |
|---|
| 44 | } |
|---|
| 45 | else |
|---|
| 46 | { |
|---|
| 47 | ptba = pt->pt1[ix1] << 12; |
|---|
| 48 | pt_flags = (unsigned int *) (ptba + 8 * ix2); |
|---|
| 49 | pt_ppn = (unsigned int *) (ptba + 8 * ix2 + 4); |
|---|
| 50 | *pt_flags = flags; |
|---|
| 51 | *pt_ppn = ppn; |
|---|
| 52 | } |
|---|
| 53 | } // end _iommu_add_pte2() |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 57 | // This function unmap a PTE2 in IOMMU page table |
|---|
| 58 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | void _iommu_inval_pte2( unsigned int ix1, |
|---|
| 60 | unsigned int ix2 ) |
|---|
| 61 | { |
|---|
| 62 | unsigned int ptba; |
|---|
| 63 | unsigned int * pt_flags; |
|---|
| 64 | |
|---|
| 65 | // get pointer on iommu page table |
|---|
| 66 | page_table_t * pt = &_iommu_ptab; |
|---|
| 67 | |
|---|
| 68 | // get ptba and inval PTE2 |
|---|
| 69 | if ((pt->pt1[ix1] & PTE_V) == 0) |
|---|
| 70 | { |
|---|
| 71 | _printf("\n[GIET ERROR] in iommu_inval_pte2() " |
|---|
| 72 | "IOMMU PT1 entry not mapped / ix1 = %d\n", ix1 ); |
|---|
| 73 | _exit(); |
|---|
| 74 | } |
|---|
| 75 | else |
|---|
| 76 | { |
|---|
| 77 | ptba = pt->pt1[ix1] << 12; |
|---|
| 78 | pt_flags = (unsigned int *) (ptba + 8 * ix2); |
|---|
| 79 | *pt_flags = 0; |
|---|
| 80 | } |
|---|
| 81 | } // end _iommu_inval_pte2() |
|---|
| 82 | |
|---|
| 83 | // Local Variables: |
|---|
| 84 | // tab-width: 4 |
|---|
| 85 | // c-basic-offset: 4 |
|---|
| 86 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 87 | // indent-tabs-mode: nil |
|---|
| 88 | // End: |
|---|
| 89 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 90 | |
|---|
| 91 | |
|---|