| 1 | /* |
|---|
| 2 | * dev_pic.c - PIC (External Interrupt Controler) generic device API implementation. |
|---|
| 3 | * |
|---|
| 4 | * Authors Alain Greiner (2016,2017,2018) |
|---|
| 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 |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTPICLAR PURPOSE. See the GNU |
|---|
| 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 | |
|---|
| 24 | #include <hal_types.h> |
|---|
| 25 | #include <hal_special.h> |
|---|
| 26 | #include <chdev.h> |
|---|
| 27 | #include <printk.h> |
|---|
| 28 | #include <string.h> |
|---|
| 29 | #include <thread.h> |
|---|
| 30 | #include <hal_drivers.h> |
|---|
| 31 | #include <dev_pic.h> |
|---|
| 32 | #include <cluster.h> |
|---|
| 33 | |
|---|
| 34 | ///////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 35 | // Extern global variables |
|---|
| 36 | ///////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 37 | |
|---|
| 38 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
|---|
| 39 | extern iopic_input_t iopic_input; // allocated in kernel_init.c |
|---|
| 40 | |
|---|
| 41 | /////////////////////////////////// |
|---|
| 42 | void dev_pic_init( chdev_t * pic ) |
|---|
| 43 | { |
|---|
| 44 | // get implementation |
|---|
| 45 | uint32_t impl = pic->impl; |
|---|
| 46 | |
|---|
| 47 | // set chdev name |
|---|
| 48 | strcpy( pic->name , "pic" ); |
|---|
| 49 | |
|---|
| 50 | // call the implementation-specific PIC driver |
|---|
| 51 | hal_drivers_pic_init(pic, impl); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | ///////////////////////////////////////////////// |
|---|
| 55 | void dev_pic_extend_init( uint32_t * lapic_base ) |
|---|
| 56 | { |
|---|
| 57 | // get pointer on PIC chdev |
|---|
| 58 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 59 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 60 | |
|---|
| 61 | // get pointer on extend_init function |
|---|
| 62 | extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); |
|---|
| 63 | |
|---|
| 64 | // call relevant driver function |
|---|
| 65 | f( lapic_base ); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | ///////////////////////////////////// |
|---|
| 69 | void dev_pic_bind_irq( lid_t lid, |
|---|
| 70 | chdev_t * src_chdev ) |
|---|
| 71 | { |
|---|
| 72 | // get pointer on PIC chdev |
|---|
| 73 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 74 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 75 | |
|---|
| 76 | // get pointer on bind_irq function |
|---|
| 77 | bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) ); |
|---|
| 78 | |
|---|
| 79 | // call relevant driver function |
|---|
| 80 | f( lid , src_chdev ); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | ///////////////////////////////////// |
|---|
| 84 | void dev_pic_enable_irq( lid_t lid, |
|---|
| 85 | xptr_t src_chdev_xp ) |
|---|
| 86 | { |
|---|
| 87 | |
|---|
| 88 | #if DEBUG_DEV_PIC |
|---|
| 89 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 90 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 91 | printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n", |
|---|
| 92 | __FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle ); |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | // get pointer on PIC chdev |
|---|
| 96 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 97 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 98 | |
|---|
| 99 | // get pointer on enable_irq function |
|---|
| 100 | enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) ); |
|---|
| 101 | |
|---|
| 102 | // call relevant driver function |
|---|
| 103 | f( lid , src_chdev_xp ); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | ////////////////////////////////////// |
|---|
| 107 | void dev_pic_disable_irq( lid_t lid, |
|---|
| 108 | xptr_t src_chdev_xp ) |
|---|
| 109 | { |
|---|
| 110 | |
|---|
| 111 | #if DEBUG_DEV_PIC |
|---|
| 112 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 113 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 114 | printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n", |
|---|
| 115 | __FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle ); |
|---|
| 116 | #endif |
|---|
| 117 | |
|---|
| 118 | // get pointer on PIC chdev |
|---|
| 119 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 120 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 121 | |
|---|
| 122 | // get pointer on disable_irq function |
|---|
| 123 | disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) ); |
|---|
| 124 | |
|---|
| 125 | // call relevant driver function |
|---|
| 126 | f( lid , src_chdev_xp ); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | //////////////////////////////////////////// |
|---|
| 130 | void dev_pic_enable_timer( uint32_t period ) |
|---|
| 131 | { |
|---|
| 132 | |
|---|
| 133 | #if DEBUG_DEV_PIC |
|---|
| 134 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 135 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 136 | printk("\n[DBG] %s : core[%x,%d] / period %d / cycle %d\n", |
|---|
| 137 | __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period, cycle ); |
|---|
| 138 | #endif |
|---|
| 139 | |
|---|
| 140 | // get pointer on PIC chdev |
|---|
| 141 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 142 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 143 | |
|---|
| 144 | // get pointer on enable_timer function |
|---|
| 145 | enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) ); |
|---|
| 146 | |
|---|
| 147 | // call relevant driver function |
|---|
| 148 | f( period ); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | ///////////////////////// |
|---|
| 152 | void dev_pic_enable_ipi() |
|---|
| 153 | { |
|---|
| 154 | |
|---|
| 155 | #if DEBUG_DEV_PIC |
|---|
| 156 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 157 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 158 | printk("\n[DBG] %s : core[%x,%d] / cycle %d\n", |
|---|
| 159 | __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , cycle ); |
|---|
| 160 | #endif |
|---|
| 161 | |
|---|
| 162 | // get pointer on PIC chdev |
|---|
| 163 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 164 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 165 | |
|---|
| 166 | // get pointer on enable_timer function |
|---|
| 167 | enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) ); |
|---|
| 168 | |
|---|
| 169 | // call relevant driver function |
|---|
| 170 | f(); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | ////////////////////////////////// |
|---|
| 174 | void dev_pic_send_ipi( cxy_t cxy, |
|---|
| 175 | lid_t lid ) |
|---|
| 176 | { |
|---|
| 177 | |
|---|
| 178 | #if DEBUG_DEV_PIC |
|---|
| 179 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 180 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 181 | printk("\n[DBG] %s : src_core[%x,%d] / dst_core[%x,%d] / cycle %d\n", |
|---|
| 182 | __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, cycle ); |
|---|
| 183 | #endif |
|---|
| 184 | |
|---|
| 185 | // get pointer on PIC chdev |
|---|
| 186 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 187 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 188 | |
|---|
| 189 | // get pointer on send_ipi function |
|---|
| 190 | send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) ); |
|---|
| 191 | |
|---|
| 192 | // call relevant driver function |
|---|
| 193 | f( cxy , lid ); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | ////////////////////// |
|---|
| 197 | void dev_pic_ack_ipi() |
|---|
| 198 | { |
|---|
| 199 | |
|---|
| 200 | #if DEBUG_DEV_PIC |
|---|
| 201 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
|---|
| 202 | if( DEBUG_DEV_PIC < cycle ) |
|---|
| 203 | printk("\n[DBG] %s : core[%x,%d] / cycle %d\n", |
|---|
| 204 | __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle ); |
|---|
| 205 | #endif |
|---|
| 206 | |
|---|
| 207 | // get pointer on PIC chdev |
|---|
| 208 | chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic ); |
|---|
| 209 | cxy_t pic_cxy = GET_CXY( chdev_dir.pic ); |
|---|
| 210 | |
|---|
| 211 | // get pointer on ack_ipi function |
|---|
| 212 | ack_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.ack_ipi ) ); |
|---|
| 213 | |
|---|
| 214 | // call relevant driver function |
|---|
| 215 | f(); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | ///////////////////////////// |
|---|
| 219 | void dev_pic_inputs_display() |
|---|
| 220 | { |
|---|
| 221 | uint32_t k; |
|---|
| 222 | uint32_t save_sr; |
|---|
| 223 | |
|---|
| 224 | // get pointers on TXT0 chdev |
|---|
| 225 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
|---|
| 226 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
|---|
| 227 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
|---|
| 228 | |
|---|
| 229 | // get extended pointer on remote TXT0 chdev lock |
|---|
| 230 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
|---|
| 231 | |
|---|
| 232 | // get TXT0 lock in busy waiting mode |
|---|
| 233 | remote_spinlock_lock_busy( lock_xp , &save_sr ); |
|---|
| 234 | |
|---|
| 235 | nolock_printk("\n***** iopic_inputs\n"); |
|---|
| 236 | |
|---|
| 237 | for( k = 0 ; k < CONFIG_MAX_IOC_CHANNELS ; k++ ) |
|---|
| 238 | { |
|---|
| 239 | nolock_printk(" - IOC[%d] hwi_id = %d\n", k , iopic_input.ioc[k] ); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | for( k = 0 ; k < CONFIG_MAX_TXT_CHANNELS ; k++ ) |
|---|
| 243 | { |
|---|
| 244 | nolock_printk(" - TXT_TX[%d] hwi_id = %d\n", k , iopic_input.txt_tx[k] ); |
|---|
| 245 | nolock_printk(" - TXT_RX[%d] hwi_id = %d\n", k , iopic_input.txt_rx[k] ); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | for( k = 0 ; k < CONFIG_MAX_NIC_CHANNELS ; k++ ) |
|---|
| 249 | { |
|---|
| 250 | nolock_printk(" - NIC_TX[%d] hwi_id = %d\n", k , iopic_input.nic_tx[k] ); |
|---|
| 251 | nolock_printk(" - NIC_RX[%d] hwi_id = %d\n", k , iopic_input.nic_rx[k] ); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | // release TXT0 lock |
|---|
| 255 | remote_spinlock_unlock_busy( lock_xp , save_sr ); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | |
|---|