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

Last change on this file since 304 was 282, checked in by max@…, 7 years ago

Don't use CURRENT_THREAD->core, since it is not yet initialized.

File size: 5.5 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
38
39///////////////////////////////////
40void dev_pic_init( chdev_t  * pic )
41{
42    // get implementation
43    uint32_t impl = pic->impl;
44
45    // set chdev name
46    strcpy( pic->name , "pic" );
47
48    // call the implementation-specific PIC driver
49    hal_drivers_pic_init(pic, impl);
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    irq_dmsg("\n[INFO] %s : core = [%x,%d] / source_chdev_xp = %l\n",
86             __FUNCTION__ , local_cxy , lid , src_chdev_xp );
87
88    // get pointer on PIC chdev
89    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
90    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
91
92    // get pointer on enable_irq function
93    enable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_irq ) );
94
95    // call relevant driver function
96    f( lid , src_chdev_xp );
97}
98
99//////////////////////////////////////
100void dev_pic_disable_irq( lid_t   lid,
101                          xptr_t  src_chdev_xp )
102{
103    irq_dmsg("\n[INFO] %s : core = [%x,%d] / source_chdev_xp = %l\n",
104             __FUNCTION__ , local_cxy , lid , src_chdev_xp );
105
106    // get pointer on PIC chdev
107    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
108    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
109
110    // get pointer on disable_irq function
111    disable_irq_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.disable_irq ) );
112
113    // call relevant driver function
114    f( lid , src_chdev_xp );
115}
116
117////////////////////////////////////////////
118void dev_pic_enable_timer( uint32_t period )
119{
120    irq_dmsg("\n[INFO] %s : core = [%x,%d] / period = %d\n",
121             __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , period );
122
123    // get pointer on PIC chdev
124    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
125    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
126
127    // get pointer on enable_timer function
128    enable_timer_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_timer ) );
129
130    // call relevant driver function
131    f( period );
132}
133
134/////////////////////////
135void dev_pic_enable_ipi()
136{
137    irq_dmsg("\n[INFO] %s : core = [%x,?]\n",
138             __FUNCTION__ , local_cxy );
139
140    // get pointer on PIC chdev
141    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
142    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
143
144    // get pointer on enable_timer function
145    enable_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.enable_ipi ) );
146
147    // call relevant driver function
148    f();
149}
150
151//////////////////////////////////
152void dev_pic_send_ipi( cxy_t  cxy,
153                       lid_t  lid )
154{
155    irq_dmsg("\n[INFO] %s : enter / src_core = [%x,%d] / dst_core = [%x,%d] / cycle = %d\n",
156             __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
157
158    // get pointer on PIC chdev
159    chdev_t * pic_ptr = (chdev_t *)GET_PTR( chdev_dir.pic );
160    cxy_t     pic_cxy = GET_CXY( chdev_dir.pic );
161
162    // get pointer on send_ipi function
163    send_ipi_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.send_ipi ) );
164
165    // call relevant driver function
166    f( cxy , lid );
167
168    irq_dmsg("\n[INFO] %s : exit / src_core = [%x,%d] / dst_core = [%x,%d] / cycle = %d\n",
169             __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cxy, lid, hal_time_stamp() );
170}
171
Note: See TracBrowser for help on using the repository browser.