source: trunk/kernel/devices/dev_pic.c @ 441

Last change on this file since 441 was 438, checked in by alain, 7 years ago

Fix a bug in scheduler related to RPC blocking.

File size: 7.7 KB
RevLine 
[1]1/*
2 * dev_pic.c - PIC (External Interrupt Controler) generic device API implementation.
3 *
[437]4 * Authors   Alain Greiner  (2016,2017,2018)
[1]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
[201]10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[1]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 *
[201]14 * ALMOS-MKH is distributed in the hope that it will be useful, but
[1]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
[201]20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[1]21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_special.h>
[3]26#include <chdev.h>
[1]27#include <printk.h>
[422]28#include <string.h>
[279]29#include <thread.h>
[206]30#include <hal_drivers.h>
[1]31#include <dev_pic.h>
[188]32#include <cluster.h>
[1]33
34/////////////////////////////////////////////////////////////////////////////////////////
35// Extern global variables
36/////////////////////////////////////////////////////////////////////////////////////////
37
[3]38extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
[407]39extern iopic_input_t      iopic_input;       // allocated in kernel_init.c
[1]40
41///////////////////////////////////
[188]42void dev_pic_init( chdev_t  * pic )
[1]43{
[201]44    // get implementation
[188]45    uint32_t impl = pic->impl;
[1]46
[23]47    // set chdev name
[188]48    strcpy( pic->name , "pic" );
49
[252]50    // call the implementation-specific PIC driver
51    hal_drivers_pic_init(pic, impl);
52}
[1]53
[188]54/////////////////////////////////////////////////
55void dev_pic_extend_init( uint32_t * lapic_base )
[1]56{
[188]57    // get pointer on PIC chdev
[200]58    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
59    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]60
[200]61    // get pointer on extend_init function
[205]62    extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
[200]63
[188]64    // call relevant driver function
[200]65    f( lapic_base );
[188]66}
[1]67
[188]68/////////////////////////////////////
69void dev_pic_bind_irq( lid_t     lid,
70                       chdev_t * src_chdev )
71{
72    // get pointer on PIC chdev
[201]73    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
74    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]75
[201]76    // get pointer on bind_irq function
[205]77    bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) );
[201]78
[188]79    // call relevant driver function
[201]80    f( lid , src_chdev );
81}
[1]82
[205]83/////////////////////////////////////
84void dev_pic_enable_irq( lid_t   lid,
85                         xptr_t  src_chdev_xp )
[188]86{
[279]87
[438]88#if DEBUG_DEV_PIC
[437]89uint32_t cycle = (uint32_t)hal_get_cycles();
[438]90if( DEBUG_DEV_PIC < cycle )
[437]91printk("\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
[407]94
[188]95    // get pointer on PIC chdev
[201]96    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
97    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]98
[201]99    // get pointer on enable_irq function
[205]100    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]101
[188]102    // call relevant driver function
[205]103    f( lid , src_chdev_xp );
[188]104}
105
[205]106//////////////////////////////////////
107void dev_pic_disable_irq( lid_t   lid,
108                          xptr_t  src_chdev_xp )
[1]109{
[279]110
[438]111#if DEBUG_DEV_PIC
[437]112uint32_t cycle = (uint32_t)hal_get_cycles();
[438]113if( DEBUG_DEV_PIC < cycle )
[437]114printk("\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
[407]117
[188]118    // get pointer on PIC chdev
[201]119    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
120    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]121
[201]122    // get pointer on disable_irq function
[205]123    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]124
[188]125    // call relevant driver function
[205]126    f( lid , src_chdev_xp );
[188]127}
[1]128
[188]129////////////////////////////////////////////
130void dev_pic_enable_timer( uint32_t period )
131{
[279]132
[438]133#if DEBUG_DEV_PIC
[437]134uint32_t cycle = (uint32_t)hal_get_cycles();
[438]135if( DEBUG_DEV_PIC < cycle )
[437]136printk("\n[DBG] %s : core[%x,%d] / period %d / cycle %d\n",
137__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period, cycle );
138#endif
[407]139
[188]140    // get pointer on PIC chdev
[201]141    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
142    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]143
[201]144    // get pointer on enable_timer function
[205]145    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]146
[188]147    // call relevant driver function
[201]148    f( period );
[188]149}
[1]150
[279]151/////////////////////////
152void dev_pic_enable_ipi()
153{
154
[438]155#if DEBUG_DEV_PIC
[437]156uint32_t cycle = (uint32_t)hal_get_cycles();
[438]157if( DEBUG_DEV_PIC < cycle )
[437]158printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
159__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , cycle );
160#endif
[407]161
[279]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
[188]173//////////////////////////////////
174void dev_pic_send_ipi( cxy_t  cxy,
175                       lid_t  lid )
176{
[279]177
[438]178#if DEBUG_DEV_PIC
[437]179uint32_t cycle = (uint32_t)hal_get_cycles();
[438]180if( DEBUG_DEV_PIC < cycle )
[437]181printk("\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
[407]184
[188]185    // get pointer on PIC chdev
[201]186    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
187    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]188
[201]189    // get pointer on send_ipi function
[205]190    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]191
[188]192    // call relevant driver function
[201]193    f( cxy , lid );
[407]194}
[279]195
[407]196//////////////////////
197void dev_pic_ack_ipi()
198{
199
[438]200#if DEBUG_DEV_PIC
[437]201uint32_t cycle = (uint32_t)hal_get_cycles();
[438]202if( DEBUG_DEV_PIC < cycle )
[437]203printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
204__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle );
205#endif
[407]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();
[188]216}
217
[407]218/////////////////////////////
219void 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
Note: See TracBrowser for help on using the repository browser.