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

Last change on this file since 372 was 337, checked in by alain, 7 years ago

Introduce the delayed context switch if current thread has a lock.

File size: 5.4 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
[1]38
39///////////////////////////////////
[188]40void dev_pic_init( chdev_t  * pic )
[1]41{
[201]42    // get implementation
[188]43    uint32_t impl = pic->impl;
[1]44
[23]45    // set chdev name
[188]46    strcpy( pic->name , "pic" );
47
[252]48    // call the implementation-specific PIC driver
49    hal_drivers_pic_init(pic, impl);
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    irq_dmsg("\n[INFO] %s : core = [%x,%d] / source_chdev_xp = %l\n",
86             __FUNCTION__ , local_cxy , lid , src_chdev_xp );
87
[188]88    // get pointer on PIC chdev
[201]89    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
90    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]91
[201]92    // get pointer on enable_irq function
[205]93    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]94
[188]95    // call relevant driver function
[205]96    f( lid , src_chdev_xp );
[188]97}
98
[205]99//////////////////////////////////////
100void dev_pic_disable_irq( lid_t   lid,
101                          xptr_t  src_chdev_xp )
[1]102{
[279]103    irq_dmsg("\n[INFO] %s : core = [%x,%d] / source_chdev_xp = %l\n",
104             __FUNCTION__ , local_cxy , lid , src_chdev_xp );
105
[188]106    // get pointer on PIC chdev
[201]107    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
108    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]109
[201]110    // get pointer on disable_irq function
[205]111    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]112
[188]113    // call relevant driver function
[205]114    f( lid , src_chdev_xp );
[188]115}
[1]116
[188]117////////////////////////////////////////////
118void dev_pic_enable_timer( uint32_t period )
119{
[279]120    irq_dmsg("\n[INFO] %s : core = [%x,%d] / period = %d\n",
121             __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period );
122
[188]123    // get pointer on PIC chdev
[201]124    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
125    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]126
[201]127    // get pointer on enable_timer function
[205]128    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]129
[188]130    // call relevant driver function
[201]131    f( period );
[188]132}
[1]133
[279]134/////////////////////////
135void dev_pic_enable_ipi()
136{
[282]137    irq_dmsg("\n[INFO] %s : core = [%x,?]\n",
138             __FUNCTION__ , local_cxy );
[279]139
140    // get pointer on PIC chdev
141    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
142    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
143
144    // get pointer on enable_timer function
145    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
146
147    // call relevant driver function
148    f();
149}
150
[188]151//////////////////////////////////
152void dev_pic_send_ipi( cxy_t  cxy,
153                       lid_t  lid )
154{
[337]155    irq_dmsg("\n[INFO] %s : enter / src_core = [%x,%d] / dst_core = [%x,%d] / cycle %d\n",
[279]156             __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
157
[188]158    // get pointer on PIC chdev
[201]159    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
160    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]161
[201]162    // get pointer on send_ipi function
[205]163    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]164
[188]165    // call relevant driver function
[201]166    f( cxy , lid );
[279]167
[337]168    irq_dmsg("\n[INFO] %s : exit / src_core = [%x,%d] / dst_core = [%x,%d] / cycle %d\n",
[279]169             __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
[188]170}
171
Note: See TracBrowser for help on using the repository browser.