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

Last change on this file since 416 was 407, checked in by alain, 7 years ago

First implementation of fork/exec.

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