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

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

Introduce syscalls.

File size: 3.3 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 *
10 * ALMOS-MKH.is free software; you can redistribute it and/or modify it
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 *
14 * ALMOS-MKH.is distributed in the hope that it will be useful, but
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
20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_special.h>
26#include <dev_icu.h>
[3]27#include <chdev.h>
[1]28#include <memcpy.h>
29#include <printk.h>
30#include <soclib_pic.h>
31#include <dev_pic.h>
32
33/////////////////////////////////////////////////////////////////////////////////////////
34// Extern global variables
35/////////////////////////////////////////////////////////////////////////////////////////
36
[3]37extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
[1]38
[3]39extern chdev_pic_input_t  chdev_pic_input;   // allocated in kernel_init.c
[1]40
41///////////////////////////////////
[3]42void dev_pic_init( chdev_t * chdev,
43                   uint32_t  irq_nr )
[1]44{
[3]45    // set PIC chdev extension field
46    chdev->ext.pic.irq_nr = irq_nr;
[1]47
[3]48    // get implementation
49    uint32_t impl = chdev->impl;
[1]50
[23]51    // set chdev name
52    strcpy( chdev->name , "pic" );
53 
[3]54    // call the relevant driver init function
[1]55    if( impl == IMPL_PIC_SOC )
56    {
[3]57        soclib_pic_init( chdev );
[1]58    }
59    else
60    {
[3]61        assert( false , __FUNCTION__ , "illegal PIC device implementation" );
[1]62    }
63} // end dev_pic_init()
64
65/////////////////////////////////////////
66void dev_pic_bind_irq( uint32_t   irq_id,
67                       cxy_t      cxy,
68                       uint32_t   wti_id )
69{
70    // get extended pointer on WTI mailbox
[3]71    xptr_t wti_xp = XPTR( cxy , dev_icu_wti_ptr( wti_id ) );
[1]72
[3]73    // get extended pointer on PIC chdev from directory
74    xptr_t dev_xp = chdev_dir.pic;
[1]75
[3]76    // get PIC chdev cluster and local pointer
77    cxy_t     dev_cxy = GET_CXY( dev_xp );
78    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]79
80    // get implementation index and segment base
81    uint32_t impl   = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
82
83    // call the implementation specific driver function
84    if( impl == IMPL_PIC_SOC )
85    {
86        soclib_pic_bind_irq( dev_xp , irq_id , wti_xp );
87    }
88}  // end dev_pic_link_wti()
89
90//////////////////////////////////////////
91void dev_pic_unbind_irq( uint32_t irq_id )
92{
[3]93    // get extended pointer on PIC chdev from directory
94    xptr_t dev_xp = chdev_dir.pic;
[1]95
[3]96    // get PIC chdev cluster and local pointer
97    cxy_t     dev_cxy = GET_CXY( dev_xp );
98    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]99
100    // get implementation index
101    uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
102
103    // call the implementation specific driver function
104    if( impl == IMPL_PIC_SOC )
105    {
106        soclib_pic_unbind_irq( dev_xp , irq_id );
107    }
108} // end dev_pic_disable_irq()
109
110
Note: See TracBrowser for help on using the repository browser.