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

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

Change dev_pic_enable_irq() and dev_pic_disable_irq() prototypes
to handle remote IRQs.

File size: 5.0 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>
[204]28#include <soclib_pic.h>
[1]29#include <dev_pic.h>
[188]30#include <cluster.h>
[1]31
32/////////////////////////////////////////////////////////////////////////////////////////
33// Extern global variables
34/////////////////////////////////////////////////////////////////////////////////////////
35
[3]36extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
[1]37
38///////////////////////////////////
[188]39void dev_pic_init( chdev_t  * pic )
[1]40{
[201]41    // get implementation
[188]42    uint32_t impl = pic->impl;
[1]43
[23]44    // set chdev name
[188]45    strcpy( pic->name , "pic" );
46
47    // call the relevant driver init function,
48    // and register commands in PIC device extension
49    if( impl == IMPL_PIC_SCL )
[1]50    {
[188]51        // call the PIC SOCLIB driver
[204]52        soclib_pic_init( pic );
53
54        // update the PIC chdev extension
55        pic->ext.pic.enable_timer = &soclib_pic_enable_timer;
56        pic->ext.pic.enable_irq   = &soclib_pic_enable_irq;
57        pic->ext.pic.disable_irq  = &soclib_pic_disable_irq;
58        pic->ext.pic.bind_irq     = &soclib_pic_bind_irq;
59        pic->ext.pic.send_ipi     = &soclib_pic_send_ipi;
60        pic->ext.pic.extend_init  = &soclib_pic_extend_init;
[1]61    }
[188]62    else if( impl == IMPL_PIC_I86 )
63    {
64        assert( false , __FUNCTION__ , "missing implementation for X86\n" );
65    }
[1]66    else
67    {
[188]68        assert( false , __FUNCTION__ , "undefined PIC device implementation" );
[1]69    }
70} // end dev_pic_init()
71
[188]72/////////////////////////////////////////////////
73void dev_pic_extend_init( uint32_t * lapic_base )
[1]74{
[188]75    // get pointer on PIC chdev
[200]76    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
77    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]78
[200]79    // get pointer on extend_init function
[205]80    extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
[200]81
[188]82    // call relevant driver function
[200]83    f( lapic_base );
[188]84}
[1]85
[188]86/////////////////////////////////////
87void dev_pic_bind_irq( lid_t     lid,
88                       chdev_t * src_chdev )
89{
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 bind_irq function
[205]95    bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) );
[201]96
[188]97    // call relevant driver function
[201]98    f( lid , src_chdev );
99}
[1]100
[205]101/////////////////////////////////////
102void dev_pic_enable_irq( lid_t   lid,
103                         xptr_t  src_chdev_xp )
[188]104{
105    // get pointer on PIC chdev
[201]106    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
107    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]108
[201]109    // get pointer on enable_irq function
[205]110    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
[201]111
[188]112    // call relevant driver function
[205]113    f( lid , src_chdev_xp );
[188]114}
115
[205]116//////////////////////////////////////
117void dev_pic_disable_irq( lid_t   lid,
118                          xptr_t  src_chdev_xp )
[1]119{
[188]120    // get pointer on PIC chdev
[201]121    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
122    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]123
[201]124    // get pointer on disable_irq function
[205]125    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
[201]126
[188]127    // call relevant driver function
[205]128    f( lid , src_chdev_xp );
[188]129}
[1]130
[188]131////////////////////////////////////////////
132void dev_pic_enable_timer( uint32_t period )
133{
134    // get pointer on PIC chdev
[201]135    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
136    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]137
[201]138    // get pointer on enable_timer function
[205]139    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
[201]140
[188]141    // call relevant driver function
[201]142    f( period );
[188]143}
[1]144
[188]145//////////////////////////////////
146void dev_pic_send_ipi( cxy_t  cxy,
147                       lid_t  lid )
148{
149    // get pointer on PIC chdev
[201]150    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
151    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
[1]152
[201]153    // get pointer on send_ipi function
[205]154    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
[201]155
[188]156    // call relevant driver function
[201]157    f( cxy , lid );
[188]158}
159
Note: See TracBrowser for help on using the repository browser.