[1] | 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> |
---|
[3] | 26 | #include <chdev.h> |
---|
[1] | 27 | #include <printk.h> |
---|
| 28 | #include <soclib_pic.h> |
---|
| 29 | #include <dev_pic.h> |
---|
[188] | 30 | #include <cluster.h> |
---|
[1] | 31 | |
---|
| 32 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | // Extern global variables |
---|
| 34 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 35 | |
---|
[3] | 36 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[1] | 37 | |
---|
| 38 | /////////////////////////////////// |
---|
[188] | 39 | void dev_pic_init( chdev_t * pic ) |
---|
[1] | 40 | { |
---|
[3] | 41 | // get implementation |
---|
[188] | 42 | uint32_t impl = pic->impl; |
---|
[1] | 43 | |
---|
[23] | 44 | // set chdev name |
---|
[188] | 45 | strcpy( pic->name , "pic" ); |
---|
| 46 | |
---|
| 47 | // call the relevant driver init function, |
---|
| 48 | // and register commands in PIC device extension |
---|
| 49 | if( impl == IMPL_PIC_SCL ) |
---|
[1] | 50 | { |
---|
[188] | 51 | // call the PIC SOCLIB driver |
---|
| 52 | soclib_pic_init( pic ); |
---|
| 53 | |
---|
| 54 | // update the PIC chdev extension |
---|
| 55 | pic->ext.pic.enable_timer = &soclib_pic_enable_timer; |
---|
| 56 | pic->ext.pic.enable_irq = &soclib_pic_enable_irq; |
---|
| 57 | pic->ext.pic.disable_irq = &soclib_pic_disable_irq; |
---|
| 58 | pic->ext.pic.bind_irq = &soclib_pic_bind_irq; |
---|
| 59 | pic->ext.pic.send_ipi = &soclib_pic_send_ipi; |
---|
| 60 | pic->ext.pic.extend_init = &soclib_pic_extend_init; |
---|
[1] | 61 | } |
---|
[188] | 62 | else if( impl == IMPL_PIC_I86 ) |
---|
| 63 | { |
---|
| 64 | assert( false , __FUNCTION__ , "missing implementation for X86\n" ); |
---|
| 65 | } |
---|
[1] | 66 | else |
---|
| 67 | { |
---|
[188] | 68 | assert( false , __FUNCTION__ , "undefined PIC device implementation" ); |
---|
[1] | 69 | } |
---|
| 70 | } // end dev_pic_init() |
---|
| 71 | |
---|
[188] | 72 | ///////////////////////////////////////////////// |
---|
| 73 | void dev_pic_extend_init( uint32_t * lapic_base ) |
---|
[1] | 74 | { |
---|
[188] | 75 | // get pointer on PIC chdev |
---|
| 76 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 77 | |
---|
[188] | 78 | // call relevant driver function |
---|
| 79 | pic->ext.pic.extend_init( lapic_base ); |
---|
| 80 | } |
---|
[1] | 81 | |
---|
[188] | 82 | ///////////////////////////////////// |
---|
| 83 | void dev_pic_bind_irq( lid_t lid, |
---|
| 84 | chdev_t * src_chdev ) |
---|
| 85 | { |
---|
| 86 | // get pointer on PIC chdev |
---|
| 87 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 88 | |
---|
[188] | 89 | // call relevant driver function |
---|
| 90 | pic->ext.pic.bind_irq( lid , src_chdev ); |
---|
| 91 | } |
---|
[1] | 92 | |
---|
[188] | 93 | /////////////////////////////////////// |
---|
| 94 | void dev_pic_enable_irq( lid_t lid, |
---|
| 95 | chdev_t * src_chdev ) |
---|
| 96 | { |
---|
| 97 | // get pointer on PIC chdev |
---|
| 98 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 99 | |
---|
[188] | 100 | // call relevant driver function |
---|
| 101 | pic->ext.pic.enable_irq( src_chdev ); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | //////////////////////////////////////// |
---|
| 105 | void dev_pic_disable_irq( lid_t lid, |
---|
| 106 | chdev_t * src_chdev ) |
---|
[1] | 107 | { |
---|
[188] | 108 | // get pointer on PIC chdev |
---|
| 109 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 110 | |
---|
[188] | 111 | // call relevant driver function |
---|
| 112 | pic->ext.pic.disable_irq( src_chdev ); |
---|
| 113 | } |
---|
[1] | 114 | |
---|
[188] | 115 | //////////////////////////////////////////// |
---|
| 116 | void dev_pic_enable_timer( uint32_t period ) |
---|
| 117 | { |
---|
| 118 | // get pointer on PIC chdev |
---|
| 119 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 120 | |
---|
[188] | 121 | // call relevant driver function |
---|
| 122 | pic->ext.pic.enable_timer( period ); |
---|
| 123 | } |
---|
[1] | 124 | |
---|
[188] | 125 | ////////////////////////////////// |
---|
| 126 | void dev_pic_send_ipi( cxy_t cxy, |
---|
| 127 | lid_t lid ) |
---|
| 128 | { |
---|
| 129 | // get pointer on PIC chdev |
---|
| 130 | chdev_t * pic = (chdev_t *)GET_PTR( chdev_dir.pic ); |
---|
[1] | 131 | |
---|
[188] | 132 | // call relevant driver function |
---|
| 133 | pic->ext.pic.send_ipi( cxy , lid ); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | |
---|