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

Last change on this file since 631 was 565, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

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
[457]24#include <hal_kernel_types.h>
[1]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>
[565]30#include <remote_busylock.h>
[206]31#include <hal_drivers.h>
[1]32#include <dev_pic.h>
[188]33#include <cluster.h>
[1]34
35/////////////////////////////////////////////////////////////////////////////////////////
36// Extern global variables
37/////////////////////////////////////////////////////////////////////////////////////////
38
[3]39extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
[407]40extern iopic_input_t      iopic_input;       // allocated in kernel_init.c
[1]41
42///////////////////////////////////
[188]43void dev_pic_init( chdev_t  * pic )
[1]44{
[201]45    // get implementation
[188]46    uint32_t impl = pic->impl;
[1]47
[23]48    // set chdev name
[188]49    strcpy( pic->name , "pic" );
50
[252]51    // call the implementation-specific PIC driver
52    hal_drivers_pic_init(pic, impl);
53}
[1]54
[188]55/////////////////////////////////////////////////
56void dev_pic_extend_init( uint32_t * lapic_base )
[1]57{
[188]58    // get pointer on PIC chdev
[200]59    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
60    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]61
[200]62    // get pointer on extend_init function
[205]63    extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
[200]64
[188]65    // call relevant driver function
[200]66    f( lapic_base );
[188]67}
[1]68
[188]69/////////////////////////////////////
70void dev_pic_bind_irq( lid_t     lid,
71                       chdev_t * src_chdev )
72{
73    // get pointer on PIC chdev
[201]74    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
75    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]76
[201]77    // get pointer on bind_irq function
[205]78    bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) );
[201]79
[188]80    // call relevant driver function
[201]81    f( lid , src_chdev );
82}
[1]83
[205]84/////////////////////////////////////
85void dev_pic_enable_irq( lid_t   lid,
86                         xptr_t  src_chdev_xp )
[188]87{
[279]88
[438]89#if DEBUG_DEV_PIC
[437]90uint32_t cycle = (uint32_t)hal_get_cycles();
[438]91if( DEBUG_DEV_PIC < cycle )
[437]92printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n",
93__FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle );
94#endif
[407]95
[188]96    // get pointer on PIC chdev
[201]97    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
98    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]99
[201]100    // get pointer on enable_irq function
[205]101    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]102
[188]103    // call relevant driver function
[205]104    f( lid , src_chdev_xp );
[188]105}
106
[205]107//////////////////////////////////////
108void dev_pic_disable_irq( lid_t   lid,
109                          xptr_t  src_chdev_xp )
[1]110{
[279]111
[438]112#if DEBUG_DEV_PIC
[437]113uint32_t cycle = (uint32_t)hal_get_cycles();
[438]114if( DEBUG_DEV_PIC < cycle )
[437]115printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n",
116__FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle );
117#endif
[407]118
[188]119    // get pointer on PIC chdev
[201]120    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
121    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]122
[201]123    // get pointer on disable_irq function
[205]124    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]125
[188]126    // call relevant driver function
[205]127    f( lid , src_chdev_xp );
[188]128}
[1]129
[188]130////////////////////////////////////////////
131void dev_pic_enable_timer( uint32_t period )
132{
[279]133
[438]134#if DEBUG_DEV_PIC
[437]135uint32_t cycle = (uint32_t)hal_get_cycles();
[438]136if( DEBUG_DEV_PIC < cycle )
[437]137printk("\n[DBG] %s : core[%x,%d] / period %d / cycle %d\n",
138__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period, cycle );
139#endif
[407]140
[188]141    // get pointer on PIC chdev
[201]142    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
143    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]144
[201]145    // get pointer on enable_timer function
[205]146    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]147
[188]148    // call relevant driver function
[201]149    f( period );
[188]150}
[1]151
[279]152/////////////////////////
[483]153void dev_pic_enable_ipi( void )
[279]154{
155
[438]156#if DEBUG_DEV_PIC
[437]157uint32_t cycle = (uint32_t)hal_get_cycles();
[438]158if( DEBUG_DEV_PIC < cycle )
[437]159printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
160__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , cycle );
161#endif
[407]162
[279]163    // get pointer on PIC chdev
164    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
165    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
166
167    // get pointer on enable_timer function
168    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
169
170    // call relevant driver function
171    f();
172}
173
[188]174//////////////////////////////////
175void dev_pic_send_ipi( cxy_t  cxy,
176                       lid_t  lid )
177{
[279]178
[438]179#if DEBUG_DEV_PIC
[437]180uint32_t cycle = (uint32_t)hal_get_cycles();
[438]181if( DEBUG_DEV_PIC < cycle )
[457]182printk("\n[DBG] %s : thread %x in process %x / tgt_core[%x,%d] / cycle %d\n",
183__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cxy, lid, cycle );
[437]184#endif
[407]185
[188]186    // get pointer on PIC chdev
[201]187    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
188    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]189
[201]190    // get pointer on send_ipi function
[205]191    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]192
[188]193    // call relevant driver function
[201]194    f( cxy , lid );
[407]195}
[279]196
[407]197//////////////////////
[483]198void dev_pic_ack_ipi( void )
[407]199{
200
[438]201#if DEBUG_DEV_PIC
[437]202uint32_t cycle = (uint32_t)hal_get_cycles();
[438]203if( DEBUG_DEV_PIC < cycle )
[437]204printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
205__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle );
206#endif
[407]207
208    // get pointer on PIC chdev
209    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
210    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
211
212    // get pointer on ack_ipi function
213    ack_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.ack_ipi ) );
214
215    // call relevant driver function
216    f();
[188]217}
218
[565]219///////////////////////////////////
[483]220void dev_pic_inputs_display( void )
[407]221{
222    uint32_t k;
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
[565]233    remote_busylock_acquire( lock_xp );
[407]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
[565]255    remote_busylock_release( lock_xp );
[407]256}
257
258
Note: See TracBrowser for help on using the repository browser.