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

Last change on this file since 647 was 647, checked in by alain, 4 years ago

...miscelaneous...

File size: 7.6 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{
[23]45    // set chdev name
[188]46    strcpy( pic->name , "pic" );
47
[252]48    // call the implementation-specific PIC driver
[647]49    hal_drivers_pic_init( pic );
[252]50}
[1]51
[188]52/////////////////////////////////////////////////
53void dev_pic_extend_init( uint32_t * lapic_base )
[1]54{
[188]55    // get pointer on PIC chdev
[200]56    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
57    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]58
[200]59    // get pointer on extend_init function
[205]60    extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
[200]61
[188]62    // call relevant driver function
[200]63    f( lapic_base );
[188]64}
[1]65
[188]66/////////////////////////////////////
67void dev_pic_bind_irq( lid_t     lid,
68                       chdev_t * src_chdev )
69{
70    // get pointer on PIC chdev
[201]71    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
72    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]73
[201]74    // get pointer on bind_irq function
[205]75    bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) );
[201]76
[188]77    // call relevant driver function
[201]78    f( lid , src_chdev );
79}
[1]80
[205]81/////////////////////////////////////
82void dev_pic_enable_irq( lid_t   lid,
83                         xptr_t  src_chdev_xp )
[188]84{
[279]85
[438]86#if DEBUG_DEV_PIC
[437]87uint32_t cycle = (uint32_t)hal_get_cycles();
[438]88if( DEBUG_DEV_PIC < cycle )
[437]89printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n",
90__FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle );
91#endif
[407]92
[188]93    // get pointer on PIC chdev
[201]94    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
95    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]96
[201]97    // get pointer on enable_irq function
[205]98    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]99
[188]100    // call relevant driver function
[205]101    f( lid , src_chdev_xp );
[188]102}
103
[205]104//////////////////////////////////////
105void dev_pic_disable_irq( lid_t   lid,
106                          xptr_t  src_chdev_xp )
[1]107{
[279]108
[438]109#if DEBUG_DEV_PIC
[437]110uint32_t cycle = (uint32_t)hal_get_cycles();
[438]111if( DEBUG_DEV_PIC < cycle )
[437]112printk("\n[DBG] %s : core[%x,%d] / src_chdev_cxy %x / src_chdev_ptr %x / cycle %d\n",
113__FUNCTION__, local_cxy, lid, GET_CXY(src_chdev_xp), GET_PTR(src_chdev_xp), cycle );
114#endif
[407]115
[188]116    // get pointer on PIC chdev
[201]117    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
118    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]119
[201]120    // get pointer on disable_irq function
[205]121    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]122
[188]123    // call relevant driver function
[205]124    f( lid , src_chdev_xp );
[188]125}
[1]126
[188]127////////////////////////////////////////////
128void dev_pic_enable_timer( uint32_t period )
129{
[279]130
[438]131#if DEBUG_DEV_PIC
[437]132uint32_t cycle = (uint32_t)hal_get_cycles();
[438]133if( DEBUG_DEV_PIC < cycle )
[437]134printk("\n[DBG] %s : core[%x,%d] / period %d / cycle %d\n",
135__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period, cycle );
136#endif
[407]137
[188]138    // get pointer on PIC chdev
[201]139    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
140    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]141
[201]142    // get pointer on enable_timer function
[205]143    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]144
[188]145    // call relevant driver function
[201]146    f( period );
[188]147}
[1]148
[279]149/////////////////////////
[483]150void dev_pic_enable_ipi( void )
[279]151{
152
[438]153#if DEBUG_DEV_PIC
[437]154uint32_t cycle = (uint32_t)hal_get_cycles();
[438]155if( DEBUG_DEV_PIC < cycle )
[437]156printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
157__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , cycle );
158#endif
[407]159
[279]160    // get pointer on PIC chdev
161    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
162    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
163
164    // get pointer on enable_timer function
165    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
166
167    // call relevant driver function
168    f();
169}
170
[188]171//////////////////////////////////
172void dev_pic_send_ipi( cxy_t  cxy,
173                       lid_t  lid )
174{
[279]175
[438]176#if DEBUG_DEV_PIC
[437]177uint32_t cycle = (uint32_t)hal_get_cycles();
[438]178if( DEBUG_DEV_PIC < cycle )
[457]179printk("\n[DBG] %s : thread %x in process %x / tgt_core[%x,%d] / cycle %d\n",
180__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cxy, lid, cycle );
[437]181#endif
[407]182
[188]183    // get pointer on PIC chdev
[201]184    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
185    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]186
[201]187    // get pointer on send_ipi function
[205]188    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]189
[188]190    // call relevant driver function
[201]191    f( cxy , lid );
[407]192}
[279]193
[407]194//////////////////////
[483]195void dev_pic_ack_ipi( void )
[407]196{
197
[438]198#if DEBUG_DEV_PIC
[437]199uint32_t cycle = (uint32_t)hal_get_cycles();
[438]200if( DEBUG_DEV_PIC < cycle )
[437]201printk("\n[DBG] %s : core[%x,%d] / cycle %d\n",
202__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle );
203#endif
[407]204
205    // get pointer on PIC chdev
206    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
207    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
208
209    // get pointer on ack_ipi function
210    ack_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.ack_ipi ) );
211
212    // call relevant driver function
213    f();
[188]214}
215
[565]216///////////////////////////////////
[483]217void dev_pic_inputs_display( void )
[407]218{
219    uint32_t k;
220
221    // get pointers on TXT0 chdev
222    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
223    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
224    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
225
226    // get extended pointer on remote TXT0 chdev lock
227    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
228
229    // get TXT0 lock in busy waiting mode
[565]230    remote_busylock_acquire( lock_xp );
[407]231
232    nolock_printk("\n***** iopic_inputs\n");
233
234    for( k = 0 ; k < CONFIG_MAX_IOC_CHANNELS ; k++ )
235    {
236        nolock_printk(" - IOC[%d]    hwi_id = %d\n", k , iopic_input.ioc[k] );
237    }
238
239    for( k = 0 ; k < CONFIG_MAX_TXT_CHANNELS ; k++ )
240    {
241        nolock_printk(" - TXT_TX[%d] hwi_id = %d\n", k , iopic_input.txt_tx[k] );
242        nolock_printk(" - TXT_RX[%d] hwi_id = %d\n", k , iopic_input.txt_rx[k] );
243    }
244
245    for( k = 0 ; k < CONFIG_MAX_NIC_CHANNELS ; k++ )
246    {
247        nolock_printk(" - NIC_TX[%d] hwi_id = %d\n", k , iopic_input.nic_tx[k] );
248        nolock_printk(" - NIC_RX[%d] hwi_id = %d\n", k , iopic_input.nic_rx[k] );
249    }
250
251    // release TXT0 lock
[565]252    remote_busylock_release( lock_xp );
[407]253}
254
255
Note: See TracBrowser for help on using the repository browser.