[1] | 1 | /* |
---|
[3] | 2 | * dev_iob.c - IOB (bridge to external I/O) generic device API implementation. |
---|
[1] | 3 | * |
---|
| 4 | * Authors Alain Greiner (2017) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[3] | 16 | * MERCHANTABILITY or FITNESS FOR A PARTIOBLAR PURPOSE. See the GNU |
---|
[1] | 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[14] | 24 | #include <kernel_config.h> |
---|
[1] | 25 | #include <hal_types.h> |
---|
| 26 | #include <hal_special.h> |
---|
| 27 | #include <remote_spinlock.h> |
---|
[3] | 28 | #include <chdev.h> |
---|
[1] | 29 | #include <printk.h> |
---|
[422] | 30 | #include <string.h> |
---|
[346] | 31 | #include <hal_drivers.h> |
---|
[3] | 32 | #include <dev_iob.h> |
---|
[1] | 33 | |
---|
[3] | 34 | //////////////////////////////////// |
---|
| 35 | void dev_iob_init( chdev_t * chdev ) |
---|
[1] | 36 | { |
---|
[346] | 37 | // get implementation |
---|
[3] | 38 | uint32_t impl = chdev->impl; |
---|
[1] | 39 | |
---|
[23] | 40 | // set chdev name |
---|
| 41 | strcpy( chdev->name , "iob" ); |
---|
| 42 | |
---|
[1] | 43 | // call driver init function |
---|
[346] | 44 | hal_drivers_iob_init( chdev , impl ); |
---|
[1] | 45 | } |
---|
| 46 | |
---|
| 47 | ////////////////////////////////////////// |
---|
[3] | 48 | void dev_iob_iommu_enable( xptr_t dev_xp ) |
---|
[1] | 49 | { |
---|
[3] | 50 | // get IOB chdev descriptor cluster and local pointer |
---|
| 51 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 52 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 53 | |
---|
[346] | 54 | // get pointer on set_active function |
---|
| 55 | iob_set_active_t * f = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.set_active ) ); |
---|
[1] | 56 | |
---|
[346] | 57 | // call relevant driver function |
---|
| 58 | remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 59 | f( dev_xp , 1 ); |
---|
| 60 | remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
[1] | 61 | } |
---|
| 62 | |
---|
| 63 | /////////////////////////////////////////// |
---|
[3] | 64 | void dev_iob_iommu_disable( xptr_t dev_xp ) |
---|
[1] | 65 | { |
---|
[3] | 66 | // get IOB chdev descriptor cluster and local pointer |
---|
| 67 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 68 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 69 | |
---|
[346] | 70 | // get pointer on set_active function |
---|
| 71 | iob_set_active_t * f = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.set_active ) ); |
---|
[1] | 72 | |
---|
| 73 | // call driver function |
---|
[346] | 74 | remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 75 | f( dev_xp , 0 ); |
---|
| 76 | remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
[1] | 77 | } |
---|
| 78 | |
---|
| 79 | //////////////////////////////////////// |
---|
[3] | 80 | void dev_iob_set_ptpr( xptr_t dev_xp, |
---|
[1] | 81 | uint32_t wdata ) |
---|
| 82 | { |
---|
[3] | 83 | // get IOB chdev descriptor cluster and local pointer |
---|
| 84 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 85 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 86 | |
---|
[346] | 87 | // get pointer on set_ptpr function |
---|
| 88 | iob_set_ptpr_t * f = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.set_ptpr ) ); |
---|
[1] | 89 | |
---|
| 90 | // call driver function |
---|
[346] | 91 | remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 92 | f( dev_xp , wdata ); |
---|
| 93 | remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 94 | |
---|
[1] | 95 | } |
---|
[346] | 96 | |
---|
[1] | 97 | //////////////////////////////////////// |
---|
[3] | 98 | void dev_iob_inval_page( xptr_t dev_xp, |
---|
[1] | 99 | vpn_t vpn ) |
---|
| 100 | { |
---|
[3] | 101 | // get IOB chdev descriptor cluster and local pointer |
---|
| 102 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 103 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 104 | |
---|
[346] | 105 | // get pointer on inval_page function |
---|
| 106 | iob_inval_page_t * f = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.inval_page ) ); |
---|
[1] | 107 | |
---|
| 108 | // call driver function |
---|
[346] | 109 | remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 110 | f( dev_xp , vpn ); |
---|
| 111 | remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
[1] | 112 | } |
---|
| 113 | |
---|
| 114 | /////////////////////////////////////////// |
---|
[3] | 115 | void dev_iob_get_status( xptr_t dev_xp, |
---|
[1] | 116 | uint32_t * error, |
---|
| 117 | uint32_t * bvar, |
---|
| 118 | uint32_t * srcid ) |
---|
| 119 | { |
---|
[3] | 120 | // get IOB chdev descriptor cluster and local pointer |
---|
| 121 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 122 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
[1] | 123 | |
---|
[346] | 124 | // get pointer on the functions |
---|
| 125 | iob_get_error_t * f_get_error = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.get_error ) ); |
---|
| 126 | iob_get_srcid_t * f_get_srcid = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.get_srcid ) ); |
---|
| 127 | iob_get_bvar_t * f_get_bvar = hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->ext.iob.get_bvar ) ); |
---|
[1] | 128 | |
---|
| 129 | // call driver function |
---|
[346] | 130 | remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
| 131 | *error = f_get_error( dev_xp ); |
---|
| 132 | *srcid = f_get_srcid( dev_xp ); |
---|
| 133 | *bvar = f_get_bvar( dev_xp ); |
---|
| 134 | remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); |
---|
[1] | 135 | } |
---|
| 136 | |
---|