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

Last change on this file since 599 was 565, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

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