1 | /* |
---|
2 | * soclib_pic.c - soclib PIC driver implementation. |
---|
3 | * |
---|
4 | * Author 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 PARTICULAR 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 <device.h> |
---|
26 | #include <soclib_pic.h> |
---|
27 | #include <soclib_xcu.h> |
---|
28 | #include <errno.h> |
---|
29 | #include <string.h> |
---|
30 | #include <vfs.h> |
---|
31 | |
---|
32 | |
---|
33 | ////////////////////////////////////// |
---|
34 | void soclib_pic_init( xptr_t dev_xp ) |
---|
35 | { |
---|
36 | // get PIC device descriptor cluster and local pointer |
---|
37 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
38 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
39 | |
---|
40 | // get extended pointer on PIC segment base from PIC device descriptor |
---|
41 | xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
42 | |
---|
43 | // get PIC controller segment cluster and local pointer |
---|
44 | cxy_t seg_cxy = (cxy_t)GET_CXY( seg_xp ); |
---|
45 | uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp ); |
---|
46 | uint32_t i; |
---|
47 | |
---|
48 | // reset the MASK registers for all input IRQs |
---|
49 | for( i = 0 ; i < CONFIG_MAX_IRQS_PER_PIC ; i++ ) |
---|
50 | { |
---|
51 | hal_remote_sw( XPTR( seg_cxy , seg_ptr + i*IOPIC_SPAN + IOPIC_MASK ) , 0 ); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | //////////////////////////////////////////// |
---|
56 | void soclib_pic_bind_irq( xptr_t dev_xp, |
---|
57 | uint32_t irq_id, |
---|
58 | xptr_t xp_wti ) |
---|
59 | { |
---|
60 | // get PIC device descriptor cluster and local pointer |
---|
61 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
62 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
63 | |
---|
64 | // get extended pointer on PIC segment base from PIC device descriptor |
---|
65 | xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
66 | |
---|
67 | // get PIC controller segment cluster and local pointer |
---|
68 | cxy_t seg_cxy = (cxy_t)GET_CXY( seg_xp); |
---|
69 | uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp ); |
---|
70 | |
---|
71 | uint32_t lsb = (uint32_t)xp_wti; |
---|
72 | uint32_t msb = (uint32_t)(xp_wti>>32); |
---|
73 | |
---|
74 | // set the IOPIC_ADDRESS and IOPIC_EXTEND registers |
---|
75 | hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_ADDRESS ) , lsb ); |
---|
76 | hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_EXTEND ) , msb ); |
---|
77 | |
---|
78 | // set IOPIC_MASK register |
---|
79 | hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_MASK ) , 1 ); |
---|
80 | } |
---|
81 | |
---|
82 | ////////////////////////////////////////////// |
---|
83 | void soclib_pic_unbind_irq( xptr_t dev_xp, |
---|
84 | uint32_t irq_id ) |
---|
85 | { |
---|
86 | // get PIC device descriptor cluster and local pointer |
---|
87 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
88 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
89 | |
---|
90 | // get extended pointer on PIC segment base from PIC device descriptor |
---|
91 | xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
92 | |
---|
93 | // get PIC controller segment cluster and local pointer |
---|
94 | cxy_t seg_cxy = (cxy_t)GET_CXY( seg_xp); |
---|
95 | uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp ); |
---|
96 | |
---|
97 | // set IOPIC_MASK register |
---|
98 | hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_MASK ) , 0 ); |
---|
99 | } |
---|
100 | |
---|
101 | ////////////////////////////////////////////// |
---|
102 | void soclib_pic_get_status( xptr_t dev_xp, |
---|
103 | uint32_t irq_id, |
---|
104 | uint32_t * status) |
---|
105 | { |
---|
106 | // get PIC device descriptor cluster and local pointer |
---|
107 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
108 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
109 | |
---|
110 | // get extended pointer on PIC segment base from PIC device descriptor |
---|
111 | xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
112 | |
---|
113 | // get PIC controller segment cluster and local pointer |
---|
114 | cxy_t seg_cxy = (cxy_t)GET_CXY( seg_xp); |
---|
115 | uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp ); |
---|
116 | |
---|
117 | // return status |
---|
118 | *status = hal_remote_lw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_STATUS ) ); |
---|
119 | } |
---|
120 | |
---|