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 | |
---|
37 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
38 | |
---|
39 | extern chdev_pic_input_t chdev_pic_input; // allocated in kernel_init.c |
---|
40 | |
---|
41 | /////////////////////////////////// |
---|
42 | void 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 | // call the relevant driver init function |
---|
52 | if( impl == IMPL_PIC_SOC ) |
---|
53 | { |
---|
54 | soclib_pic_init( chdev ); |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | assert( false , __FUNCTION__ , "illegal PIC device implementation" ); |
---|
59 | } |
---|
60 | } // end dev_pic_init() |
---|
61 | |
---|
62 | ///////////////////////////////////////// |
---|
63 | void dev_pic_bind_irq( uint32_t irq_id, |
---|
64 | cxy_t cxy, |
---|
65 | uint32_t wti_id ) |
---|
66 | { |
---|
67 | // get extended pointer on WTI mailbox |
---|
68 | xptr_t wti_xp = XPTR( cxy , dev_icu_wti_ptr( wti_id ) ); |
---|
69 | |
---|
70 | // get extended pointer on PIC chdev from directory |
---|
71 | xptr_t dev_xp = chdev_dir.pic; |
---|
72 | |
---|
73 | // get PIC chdev cluster and local pointer |
---|
74 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
75 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
76 | |
---|
77 | // get implementation index and segment base |
---|
78 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
79 | |
---|
80 | // call the implementation specific driver function |
---|
81 | if( impl == IMPL_PIC_SOC ) |
---|
82 | { |
---|
83 | soclib_pic_bind_irq( dev_xp , irq_id , wti_xp ); |
---|
84 | } |
---|
85 | } // end dev_pic_link_wti() |
---|
86 | |
---|
87 | ////////////////////////////////////////// |
---|
88 | void dev_pic_unbind_irq( uint32_t irq_id ) |
---|
89 | { |
---|
90 | // get extended pointer on PIC chdev from directory |
---|
91 | xptr_t dev_xp = chdev_dir.pic; |
---|
92 | |
---|
93 | // get PIC chdev cluster and local pointer |
---|
94 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
95 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
96 | |
---|
97 | // get implementation index |
---|
98 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
99 | |
---|
100 | // call the implementation specific driver function |
---|
101 | if( impl == IMPL_PIC_SOC ) |
---|
102 | { |
---|
103 | soclib_pic_unbind_irq( dev_xp , irq_id ); |
---|
104 | } |
---|
105 | } // end dev_pic_disable_irq() |
---|
106 | |
---|
107 | |
---|