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

Last change on this file since 675 was 647, checked in by alain, 5 years ago

...miscelaneous...

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