source: trunk/kernel/devices/dev_pic.c @ 428

Last change on this file since 428 was 422, checked in by alain, 7 years ago

cosmetic

File size: 7.1 KB
Line 
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 <chdev.h>
27#include <printk.h>
28#include <string.h>
29#include <thread.h>
30#include <hal_drivers.h>
31#include <dev_pic.h>
32#include <cluster.h>
33
34/////////////////////////////////////////////////////////////////////////////////////////
35// Extern global variables
36/////////////////////////////////////////////////////////////////////////////////////////
37
38extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
39extern iopic_input_t      iopic_input;       // allocated in kernel_init.c
40
41///////////////////////////////////
42void dev_pic_init( chdev_t  * pic )
43{
44    // get implementation
45    uint32_t impl = pic->impl;
46
47    // set chdev name
48    strcpy( pic->name , "pic" );
49
50    // call the implementation-specific PIC driver
51    hal_drivers_pic_init(pic, impl);
52}
53
54/////////////////////////////////////////////////
55void dev_pic_extend_init( uint32_t * lapic_base )
56{
57    // get pointer on PIC chdev
58    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
59    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
60
61    // get pointer on extend_init function
62    extend_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
63
64    // call relevant driver function
65    f( lapic_base );
66}
67
68/////////////////////////////////////
69void dev_pic_bind_irq( lid_t     lid,
70                       chdev_t * src_chdev )
71{
72    // get pointer on PIC chdev
73    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
74    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
75
76    // get pointer on bind_irq function
77    bind_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.bind_irq ) );
78
79    // call relevant driver function
80    f( lid , src_chdev );
81}
82
83/////////////////////////////////////
84void dev_pic_enable_irq( lid_t   lid,
85                         xptr_t  src_chdev_xp )
86{
87
88irq_dmsg("\n[DBG] %s : core = [%x,%d] / src_chdev_cxy = %x / src_chdev_ptr = %x\n",
89__FUNCTION__ , local_cxy , lid , GET_CXY(src_chdev_xp) , GET_PTR(src_chdev_xp) );
90
91    // get pointer on PIC chdev
92    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
93    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
94
95    // get pointer on enable_irq function
96    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
97
98    // call relevant driver function
99    f( lid , src_chdev_xp );
100}
101
102//////////////////////////////////////
103void dev_pic_disable_irq( lid_t   lid,
104                          xptr_t  src_chdev_xp )
105{
106
107irq_dmsg("\n[DBG] %s : core = [%x,%d] / src_chdev_cxy = %x / src_chdev_ptr = %x\n",
108__FUNCTION__ , local_cxy , lid , GET_CXY(src_chdev_xp) , GET_PTR(src_chdev_xp) );
109
110    // get pointer on PIC chdev
111    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
112    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
113
114    // get pointer on disable_irq function
115    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
116
117    // call relevant driver function
118    f( lid , src_chdev_xp );
119}
120
121////////////////////////////////////////////
122void dev_pic_enable_timer( uint32_t period )
123{
124
125irq_dmsg("\n[DBG] %s : core = [%x,%d] / period = %d\n",
126__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period );
127
128    // get pointer on PIC chdev
129    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
130    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
131
132    // get pointer on enable_timer function
133    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
134
135    // call relevant driver function
136    f( period );
137}
138
139/////////////////////////
140void dev_pic_enable_ipi()
141{
142
143irq_dmsg("\n[DBG] %s : core = [%x,%d] / cycle %d\n",
144__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , hal_time_stamp() );
145
146    // get pointer on PIC chdev
147    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
148    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
149
150    // get pointer on enable_timer function
151    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
152
153    // call relevant driver function
154    f();
155}
156
157//////////////////////////////////
158void dev_pic_send_ipi( cxy_t  cxy,
159                       lid_t  lid )
160{
161
162irq_dmsg("\n[DBG] %s : src_core = [%x,%d] / dst_core = [%x,%d] / cycle %d\n",
163__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
164
165    // get pointer on PIC chdev
166    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
167    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
168
169    // get pointer on send_ipi function
170    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
171
172    // call relevant driver function
173    f( cxy , lid );
174}
175
176//////////////////////
177void dev_pic_ack_ipi()
178{
179
180irq_dmsg("\n[DBG] %s : core = [%x,%d] / cycle %d\n",
181__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, hal_time_stamp() );
182
183    // get pointer on PIC chdev
184    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
185    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
186
187    // get pointer on ack_ipi function
188    ack_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.ack_ipi ) );
189
190    // call relevant driver function
191    f();
192}
193
194/////////////////////////////
195void dev_pic_inputs_display()
196{
197    uint32_t k;
198    uint32_t save_sr;
199
200    // get pointers on TXT0 chdev
201    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
202    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
203    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
204
205    // get extended pointer on remote TXT0 chdev lock
206    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
207
208    // get TXT0 lock in busy waiting mode
209    remote_spinlock_lock_busy( lock_xp , &save_sr );
210
211    nolock_printk("\n***** iopic_inputs\n");
212
213    for( k = 0 ; k < CONFIG_MAX_IOC_CHANNELS ; k++ )
214    {
215        nolock_printk(" - IOC[%d]    hwi_id = %d\n", k , iopic_input.ioc[k] );
216    }
217
218    for( k = 0 ; k < CONFIG_MAX_TXT_CHANNELS ; k++ )
219    {
220        nolock_printk(" - TXT_TX[%d] hwi_id = %d\n", k , iopic_input.txt_tx[k] );
221        nolock_printk(" - TXT_RX[%d] hwi_id = %d\n", k , iopic_input.txt_rx[k] );
222    }
223
224    for( k = 0 ; k < CONFIG_MAX_NIC_CHANNELS ; k++ )
225    {
226        nolock_printk(" - NIC_TX[%d] hwi_id = %d\n", k , iopic_input.nic_tx[k] );
227        nolock_printk(" - NIC_RX[%d] hwi_id = %d\n", k , iopic_input.nic_rx[k] );
228    }
229
230    // release TXT0 lock
231    remote_spinlock_unlock_busy( lock_xp , save_sr );
232}
233
234
Note: See TracBrowser for help on using the repository browser.