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

Last change on this file since 431 was 422, checked in by alain, 7 years ago

cosmetic

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>
[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
[407]88irq_dmsg("\n[DBG] %s : core = [%x,%d] / src_chdev_cxy = %x / src_chdev_ptr = %x\n",
89__FUNCTION__ , local_cxy , lid , GET_CXY(src_chdev_xp) , GET_PTR(src_chdev_xp) );
90
[188]91    // get pointer on PIC chdev
[201]92    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
93    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]94
[201]95    // get pointer on enable_irq function
[205]96    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]97
[188]98    // call relevant driver function
[205]99    f( lid , src_chdev_xp );
[188]100}
101
[205]102//////////////////////////////////////
103void dev_pic_disable_irq( lid_t   lid,
104                          xptr_t  src_chdev_xp )
[1]105{
[279]106
[407]107irq_dmsg("\n[DBG] %s : core = [%x,%d] / src_chdev_cxy = %x / src_chdev_ptr = %x\n",
108__FUNCTION__ , local_cxy , lid , GET_CXY(src_chdev_xp) , GET_PTR(src_chdev_xp) );
109
[188]110    // get pointer on PIC chdev
[201]111    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
112    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]113
[201]114    // get pointer on disable_irq function
[205]115    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]116
[188]117    // call relevant driver function
[205]118    f( lid , src_chdev_xp );
[188]119}
[1]120
[188]121////////////////////////////////////////////
122void dev_pic_enable_timer( uint32_t period )
123{
[279]124
[407]125irq_dmsg("\n[DBG] %s : core = [%x,%d] / period = %d\n",
126__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period );
127
[188]128    // get pointer on PIC chdev
[201]129    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
130    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]131
[201]132    // get pointer on enable_timer function
[205]133    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]134
[188]135    // call relevant driver function
[201]136    f( period );
[188]137}
[1]138
[279]139/////////////////////////
140void dev_pic_enable_ipi()
141{
142
[407]143irq_dmsg("\n[DBG] %s : core = [%x,%d] / cycle %d\n",
144__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , hal_time_stamp() );
145
[279]146    // get pointer on PIC chdev
147    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
148    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
149
150    // get pointer on enable_timer function
151    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
152
153    // call relevant driver function
154    f();
155}
156
[188]157//////////////////////////////////
158void dev_pic_send_ipi( cxy_t  cxy,
159                       lid_t  lid )
160{
[279]161
[407]162irq_dmsg("\n[DBG] %s : src_core = [%x,%d] / dst_core = [%x,%d] / cycle %d\n",
163__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
164
[188]165    // get pointer on PIC chdev
[201]166    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
167    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]168
[201]169    // get pointer on send_ipi function
[205]170    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]171
[188]172    // call relevant driver function
[201]173    f( cxy , lid );
[407]174}
[279]175
[407]176//////////////////////
177void dev_pic_ack_ipi()
178{
179
180irq_dmsg("\n[DBG] %s : core = [%x,%d] / cycle %d\n",
181__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, hal_time_stamp() );
182
183    // get pointer on PIC chdev
184    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
185    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
186
187    // get pointer on ack_ipi function
188    ack_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.ack_ipi ) );
189
190    // call relevant driver function
191    f();
[188]192}
193
[407]194/////////////////////////////
195void dev_pic_inputs_display()
196{
197    uint32_t k;
198    uint32_t save_sr;
199
200    // get pointers on TXT0 chdev
201    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
202    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
203    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
204
205    // get extended pointer on remote TXT0 chdev lock
206    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
207
208    // get TXT0 lock in busy waiting mode
209    remote_spinlock_lock_busy( lock_xp , &save_sr );
210
211    nolock_printk("\n***** iopic_inputs\n");
212
213    for( k = 0 ; k < CONFIG_MAX_IOC_CHANNELS ; k++ )
214    {
215        nolock_printk(" - IOC[%d]    hwi_id = %d\n", k , iopic_input.ioc[k] );
216    }
217
218    for( k = 0 ; k < CONFIG_MAX_TXT_CHANNELS ; k++ )
219    {
220        nolock_printk(" - TXT_TX[%d] hwi_id = %d\n", k , iopic_input.txt_tx[k] );
221        nolock_printk(" - TXT_RX[%d] hwi_id = %d\n", k , iopic_input.txt_rx[k] );
222    }
223
224    for( k = 0 ; k < CONFIG_MAX_NIC_CHANNELS ; k++ )
225    {
226        nolock_printk(" - NIC_TX[%d] hwi_id = %d\n", k , iopic_input.nic_tx[k] );
227        nolock_printk(" - NIC_RX[%d] hwi_id = %d\n", k , iopic_input.nic_rx[k] );
228    }
229
230    // release TXT0 lock
231    remote_spinlock_unlock_busy( lock_xp , save_sr );
232}
233
234
Note: See TracBrowser for help on using the repository browser.