source: trunk/hal/tsar_mips32/drivers/soclib_pic.c @ 141

Last change on this file since 141 was 141, checked in by max@…, 5 years ago

style

File size: 4.0 KB
Line 
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 <chdev.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////////////////////////////////////////
33void soclib_pic_init( chdev_t  * chdev )
34{
35    // get PIC controller segment cluster and local pointer
36    cxy_t      seg_cxy = (cxy_t)GET_CXY( chdev->base );
37    uint32_t * seg_ptr = (uint32_t *)GET_PTR( chdev->base );
38    uint32_t   i;
39
40    // reset the MASK registers for all input IRQs
41    for( i = 0 ; i < CONFIG_MAX_IRQS_PER_PIC ; i++ )
42    {
43        hal_remote_sw( XPTR( seg_cxy , seg_ptr + i*IOPIC_SPAN + IOPIC_MASK ) , 0 );
44    }
45}
46
47////////////////////////////////////////////
48void soclib_pic_bind_irq( xptr_t     dev_xp,
49                          uint32_t   irq_id,
50                          xptr_t     xp_wti )
51{
52    // get PIC device descriptor cluster and local pointer
53    cxy_t     dev_cxy = GET_CXY( dev_xp );
54    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
55
56    // get extended pointer on PIC segment base from PIC device descriptor
57    xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
58
59    // get PIC controller segment cluster and local pointer
60    cxy_t      seg_cxy = (cxy_t)GET_CXY( seg_xp);
61    uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp );
62
63    uint32_t lsb = (uint32_t)xp_wti;
64    uint32_t msb  = (uint32_t)(xp_wti>>32);
65
66    // set the IOPIC_ADDRESS and IOPIC_EXTEND registers
67    hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_ADDRESS ) , lsb );
68    hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_EXTEND  ) , msb );
69
70    // set IOPIC_MASK register
71    hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_MASK    ) , 1   );
72}
73
74//////////////////////////////////////////////
75void soclib_pic_unbind_irq( xptr_t     dev_xp,
76                            uint32_t   irq_id )
77{
78    // get PIC device descriptor cluster and local pointer
79    cxy_t     dev_cxy = GET_CXY( dev_xp );
80    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
81
82    // get extended pointer on PIC segment base from PIC device descriptor
83    xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
84
85    // get PIC controller segment cluster and local pointer
86    cxy_t      seg_cxy = (cxy_t)GET_CXY( seg_xp);
87    uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp );
88
89    // set IOPIC_MASK register
90    hal_remote_sw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_MASK    ) , 0   );
91}
92
93//////////////////////////////////////////////
94void soclib_pic_get_status( xptr_t     dev_xp,
95                            uint32_t   irq_id,
96                            uint32_t * status)
97{
98    // get PIC device descriptor cluster and local pointer
99    cxy_t     dev_cxy = GET_CXY( dev_xp );
100    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
101
102    // get extended pointer on PIC segment base from PIC device descriptor
103    xptr_t seg_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
104
105    // get PIC controller segment cluster and local pointer
106    cxy_t      seg_cxy = (cxy_t)GET_CXY( seg_xp);
107    uint32_t * seg_ptr = (uint32_t *)GET_PTR( seg_xp );
108
109    // return status
110    *status = hal_remote_lw( XPTR( seg_cxy , seg_ptr+irq_id*IOPIC_SPAN+IOPIC_STATUS ) );
111}
112
Note: See TracBrowser for help on using the repository browser.