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