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

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

Introduce syscalls.

File size: 3.3 KB
Line 
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>
27#include <chdev.h>
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
37extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
38
39extern chdev_pic_input_t  chdev_pic_input;   // allocated in kernel_init.c
40
41///////////////////////////////////
42void dev_pic_init( chdev_t * chdev,
43                   uint32_t  irq_nr )
44{
45    // set PIC chdev extension field
46    chdev->ext.pic.irq_nr = irq_nr;
47
48    // get implementation
49    uint32_t impl = chdev->impl;
50
51    // set chdev name
52    strcpy( chdev->name , "pic" );
53 
54    // call the relevant driver init function
55    if( impl == IMPL_PIC_SOC )
56    {
57        soclib_pic_init( chdev );
58    }
59    else
60    {
61        assert( false , __FUNCTION__ , "illegal PIC device implementation" );
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
71    xptr_t wti_xp = XPTR( cxy , dev_icu_wti_ptr( wti_id ) );
72
73    // get extended pointer on PIC chdev from directory
74    xptr_t dev_xp = chdev_dir.pic;
75
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 );
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{
93    // get extended pointer on PIC chdev from directory
94    xptr_t dev_xp = chdev_dir.pic;
95
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 );
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.