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

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

First import

File size: 3.9 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 <device.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 devices_directory_t  devices_dir;         // allocated in kernel_init.c
38
39extern devices_input_irq_t  devices_input_irq;   // allocated in kernel_init.c
40
41
42
43///////////////////////////////////
44void dev_pic_init( xptr_t   dev_xp,
45                   uint32_t irq_nr )
46{
47    // get PIC device cluster and local pointer
48    cxy_t      dev_cxy = GET_CXY( dev_xp );
49    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
50
51    // set PIC device extension field
52    dev_ptr->ext.pic.irq_nr = irq_nr;
53
54    // get implementation index from PIC device descriptor
55    uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
56
57    // set the "name" field in PIC device descriptor
58    // and call the relevant driver init function
59    if( impl == IMPL_PIC_SOC )
60    {
61        memcpy( dev_ptr->name , "PIC_TSR" , 16 );
62        soclib_pic_init( dev_xp );
63    }
64    else
65    {
66        printk("PANIC in %s: illegal PIC device implementation\n", __FUNCTION__ );
67        hal_core_sleep();
68    }
69} // end dev_pic_init()
70
71/////////////////////////////////////////
72void dev_pic_bind_irq( uint32_t   irq_id,
73                       cxy_t      cxy,
74                       uint32_t   wti_id )
75{
76    // get extended pointer on WTI mailbox
77    xptr_t wti_xp = dev_icu_wti_xptr( cxy , wti_id );
78
79    // get extended pointer on PIC device from directory
80    xptr_t dev_xp = devices_dir.pic;
81
82    // get PIC device cluster and local pointer
83    cxy_t      dev_cxy = GET_CXY( dev_xp );
84    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
85
86    // get implementation index and segment base
87    uint32_t impl   = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
88
89    // call the implementation specific driver function
90    if( impl == IMPL_PIC_SOC )
91    {
92        soclib_pic_bind_irq( dev_xp , irq_id , wti_xp );
93    }
94    else
95    {
96        printk("PANIC in %s: illegal PIC device implementation\n", __FUNCTION__ );
97        hal_core_sleep();
98    }
99}  // end dev_pic_link_wti()
100
101//////////////////////////////////////////
102void dev_pic_unbind_irq( uint32_t irq_id )
103{
104    // get extended pointer on PIC device from directory
105    xptr_t dev_xp = devices_dir.pic;
106
107    // get PIC device cluster and local pointer
108    cxy_t      dev_cxy = GET_CXY( dev_xp );
109    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
110
111    // get implementation index
112    uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
113
114    // call the implementation specific driver function
115    if( impl == IMPL_PIC_SOC )
116    {
117        soclib_pic_unbind_irq( dev_xp , irq_id );
118    }
119    else
120    {
121        printk("PANIC in %s: illegal PIC device implementation\n", __FUNCTION__ );
122        hal_core_sleep();
123    }
124   
125} // end dev_pic_disable_irq()
126
127
Note: See TracBrowser for help on using the repository browser.