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

Last change on this file since 410 was 407, checked in by alain, 7 years ago

First implementation of fork/exec.

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