source: trunk/hal/tsar_mips32/drivers/soclib_pic.c @ 689

Last change on this file since 689 was 686, checked in by alain, 4 years ago

cosmetic

File size: 20.5 KB
RevLine 
[75]1/*
2 * soclib_pic.c - soclib PIC driver implementation.
3 *
[686]4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
[141]5 *
[75]6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
[141]10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[75]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 *
[141]14 * ALMOS-MKH is distributed in the hope that it will be useful, but
[75]15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR 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
[141]20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[75]21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[451]24#include <hal_kernel_types.h>
[75]25#include <chdev.h>
26#include <soclib_pic.h>
27#include <errno.h>
28#include <string.h>
[635]29#include <bits.h>
[75]30#include <vfs.h>
[296]31#include <rpc.h>
[188]32#include <cluster.h>
33#include <printk.h>
34#include <core.h>
35#include <thread.h>
[75]36
[188]37//////////////////////////////////////////////////////////////////////////////////////
38//         Extern variables
39//////////////////////////////////////////////////////////////////////////////////////
40
[686]41extern  chdev_directory_t chdev_dir;  // defined in chdev.h / allocated in kerneL-init.c
[188]42
43extern  iopic_input_t  iopic_input;  // defined in dev_pic.h / allocated in kernel_init.c
44extern  lapic_input_t  lapic_input;  // defined in dev_pic.h / allocated in kernel_init.c
45 
[407]46
47
[188]48//////////////////////////////////////////////////////////////////////////////////////
49//        SOCLIB PIC private functions
50//////////////////////////////////////////////////////////////////////////////////////
51
[570]52/////////////////////////////////////
[481]53uint32_t soclib_pic_wti_alloc( void )
[188]54{
55    uint32_t index;
56
57    // get pointer on cluster extension for SOCLIB PIC (XCU descriptor)
58    soclib_pic_cluster_t * ext_ptr = LOCAL_CLUSTER->pic_extend;
59
[686]60assert( __FUNCTION__, (ext_ptr->first_free_wti < ext_ptr->wti_nr) ,
61"no free WTI found : too much external IRQs");
[188]62
63    // update WTI allocator
64    index = ext_ptr->first_free_wti;
65    ext_ptr->first_free_wti++;
66
67    return index;
68
69}  // end soclib_pic_wti_alloc()
70
[570]71/////////////////////////////////////////////
[481]72inline uint32_t * soclib_pic_xcu_base( void )
[188]73{
[205]74    return ((soclib_pic_cluster_t *)(LOCAL_CLUSTER->pic_extend))->xcu_base;
75}
[188]76
[205]77/////////////////////////////////////////////////////////
78inline uint32_t * soclib_pic_remote_xcu_base( cxy_t cxy )
79{
80    soclib_pic_cluster_t * extend;
[188]81
[205]82    // get extended pointer on PIC extension in remote cluster
83    extend = hal_remote_lpt( XPTR( cxy , &cluster_manager.pic_extend ) );
[188]84
[205]85        return (uint32_t *)hal_remote_lpt( XPTR( cxy , &extend->xcu_base ) );
86                 
87}
88
[188]89///////////////////////////////////////////
90void soclib_pic_xcu_status( lid_t      lid,
91                            uint32_t * hwi_status,
92                            uint32_t * wti_status,
93                            uint32_t * pti_status )
94{
95    // get local XCU segment base
96        uint32_t * base = soclib_pic_xcu_base();
97
98    // read PRIO register
[432]99    // in TSAR : XCU output [4*lid] is connected to core [lid]
100        uint32_t prio = base[ (XCU_PRIO << 5) | (lid<<2) ];
[188]101
102    *wti_status = (prio & 0x4) ? (((prio >> 24) & 0x1F) + 1) : 0;
103    *hwi_status = (prio & 0x2) ? (((prio >> 16) & 0x1F) + 1) : 0;
104    *pti_status = (prio & 0x1) ? (((prio >>  8) & 0x1F) + 1) : 0;
105
106}
107
[279]108////////////////////////////////////////////////////
109inline uint32_t soclib_pic_xcu_ack( uint32_t * reg )
110{
111    return *reg;
112}
113
[570]114///////////////////////////////////
[481]115void soclib_pic_irq_handler( void )
[188]116{
117    uint32_t   hwi_status;   // HWI index + 1  / no pending HWI if 0
118    uint32_t   wti_status;   // WTI index + 1  / no pending WTI if 0
119    uint32_t   pti_status;   // PTI index + 1  / no pending PTI if 0
120    chdev_t  * src_chdev;    // pointer on source chdev descriptor
[279]121    uint32_t   index;        // WTI / HWI / PTI index
[188]122
[406]123    uint32_t * xcu_base = soclib_pic_xcu_base();
[188]124
[406]125    core_t   * core = CURRENT_THREAD->core;
126
[188]127    // get XCU status
128    soclib_pic_xcu_status( core->lid,
129                           &hwi_status,
130                           &wti_status,
131                           &pti_status );
132
[438]133#if DEBUG_HAL_IRQS
[435]134uint32_t cycle = (uint32_t)hal_get_cycles();
[438]135if (DEBUG_HAL_IRQS < cycle )
[435]136printk("\n[DBG] %s : core[%x,%d] enter / WTI = %x / HWI = %x / PTI = %x / cycle %d\n",
137__FUNCTION__ , local_cxy , core->lid , wti_status , hwi_status , pti_status, cycle );
138#endif
[279]139
[457]140    // analyse status and handle up to 3 pending IRQs (one WTI, one HWI, one PTI)
[188]141
142    if( wti_status )          // pending WTI
143        {
144        index = wti_status - 1;
145
[438]146        ////////////////////////////////////////////////////////
[188]147        if( index < LOCAL_CLUSTER->cores_nr )   // it is an IPI
148        {
149
[686]150assert( __FUNCTION__, (index == core->lid),
151"illegal IPI index" );
152
[438]153#if DEBUG_HAL_IRQS
154if (DEBUG_HAL_IRQS < cycle )
[457]155printk("\n[DBG] %s : core[%x,%d] handling IPI\n", __FUNCTION__ , local_cxy , core->lid );
[435]156#endif
[438]157            // acknowledge IRQ (this require an XCU read)
[406]158            uint32_t   ack  = xcu_base[(XCU_WTI_REG << 5) | core->lid];
[438]159
[296]160            // check RPC FIFO,  and activate or create a RPC thread
[629]161            // condition is always true, but we use the ack value
162            // to avoid a GCC warning
[570]163            if( ack + 1 ) sched_yield("IPI received");
[188]164        }
[438]165        ////////////////////////////////////////////////////////////////
166        else                                    // it is an external IRQ
[188]167        {
168            // get pointer on source chdev
169            src_chdev = ((soclib_pic_core_t *)core->pic_extend)->wti_vector[index];
170
171                    if( src_chdev == NULL )        // strange, but not fatal
172                    {
173                printk("\n[WARNING] in %s : no handler for WTI %d on core %d in cluster %x\n",
[686]174                 __FUNCTION__ , index , core->lid , local_cxy );
[188]175
[279]176                // disable WTI in local XCU controller
[438]177                xcu_base[(XCU_MSK_WTI_DISABLE << 5) | core->lid] = 1 << core->lid;
178
179                hal_fence();
[188]180            }
181            else                                 // call relevant ISR
182            {
183
[438]184#if DEBUG_HAL_IRQS
185if (DEBUG_HAL_IRQS < cycle )
[457]186printk("\n[DBG] %s : core[%x,%d] handling external WTI %d\n",
[435]187__FUNCTION__ , local_cxy , core->lid , index );
188#endif
[188]189                // call ISR
190                    src_chdev->isr( src_chdev );
191            }
192        }
193        }
194
[438]195    /////////////////////////////////////////////////////////////
196        if( hwi_status )                     // It is an Internal IRQ
[188]197        {
198        index = hwi_status - 1;
199
200        // get pointer on source chdev
201        src_chdev = ((soclib_pic_core_t *)core->pic_extend)->hwi_vector[index];
202
203                if( src_chdev == NULL )        // strange, but not fatal
[629]204                {
[188]205            printk("\n[WARNING] in %s : no handler for HWI %d on core %d in cluster %x\n",
[686]206            __FUNCTION__ , index , core->lid , local_cxy );
[188]207
[279]208            // disable HWI in local XCU controller
[406]209            xcu_base[(XCU_MSK_HWI_DISABLE << 5) | core->lid] = 1 << core->lid;
[438]210
211            hal_fence();
[188]212                }
213        else                    // call relevant ISR
214        {
215
[438]216#if DEBUG_HAL_IRQS
217if (DEBUG_HAL_IRQS < cycle )
[457]218printk("\n[DBG] %s : core[%x,%d] handling HWI %d\n",
[435]219__FUNCTION__ , local_cxy , core->lid , index );
220#endif
[188]221            // call ISR
222                    src_chdev->isr( src_chdev );
223        }
224        }
[438]225    ///////////////////////////////////////////////////////
226    if( pti_status )                   // It is a Timer IRQ
[188]227        {
228        index = pti_status - 1;
229
[686]230assert( __FUNCTION__, (index == core->lid),
231"unconsistent PTI index\n");
[188]232
[438]233#if DEBUG_HAL_IRQS
234if (DEBUG_HAL_IRQS < cycle )
[457]235printk("\n[DBG] %s : core[%x,%d] handling PTI %d\n",
[435]236__FUNCTION__ , core->lid , local_cxy , index );
237#endif
[438]238        // acknowledge IRQ (this require a read access to XCU)
[406]239        uint32_t   ack  = xcu_base[(XCU_PTI_ACK << 5) | core->lid];
[188]240
[279]241        // execute all actions related to TICK event
[457]242        // condition is always true, but we use the ack value
243        // to avoid a GCC warning
[406]244        if( ack + 1 ) core_clock( core );
[188]245        }
246}  // end soclib_pic_irq_handler()
247
248
249
250
251//////////////////////////////////////////////////////////////////////////////////////
252//         SOCLIC PIC device  generic API
253//////////////////////////////////////////////////////////////////////////////////////
254
255/////////////////////////////////////
256void soclib_pic_init( chdev_t * pic )
257{
258    uint32_t    i;      // for loop on IOPIC inputs
259
260    // get IOPIC controller cluster and segment base pointer
[451]261    cxy_t      iopic_seg_cxy = GET_CXY( pic->base );
262    uint32_t * iopic_seg_ptr = GET_PTR( pic->base );
[188]263
[407]264    // reset the IOPIC component registers : disable all input IRQs
[188]265    for( i = 0 ; i < CONFIG_MAX_EXTERNAL_IRQS ; i++ )
266    {
267        xptr_t iopic_seg_xp = XPTR( iopic_seg_cxy,
268                                    iopic_seg_ptr + i*IOPIC_SPAN + IOPIC_MASK ); 
[570]269        hal_remote_s32( iopic_seg_xp , 0 ); 
[188]270    }
271
272}  // end soclib_pic_init()
273
274//////////////////////////////////////////////////
275void soclib_pic_extend_init( uint32_t * xcu_base )
276{
277    soclib_pic_cluster_t * cluster_ext_ptr;   
278    soclib_pic_core_t    * core_ext_ptr;
279    uint32_t               lid;
280    uint32_t               idx;
281
282    cluster_t            * cluster = LOCAL_CLUSTER;
283
284    // create core extension for all cores in cluster
285    for( lid = 0 ; lid < cluster->cores_nr ; lid++ )
286    {
287        // allocate memory for core extension
[686]288        core_ext_ptr = kmem_alloc( bits_log2( sizeof(soclib_pic_core_t)) , AF_KERNEL );
[188]289
[635]290        if( core_ext_ptr == NULL )
291        {
292            printk("\n[PANIC] in %s : cannot allocate memory for core extension\n",
293            __FUNCTION__ );
294        }
[188]295   
296        // reset the HWI / WTI  interrupt vectors
297        for( idx = 0 ; idx < SOCLIB_MAX_HWI ; idx++ ) core_ext_ptr->hwi_vector[idx] = NULL;
298        for( idx = 0 ; idx < SOCLIB_MAX_WTI ; idx++ ) core_ext_ptr->wti_vector[idx] = NULL;
299
300        // register PIC extension in core descriptor
301        cluster->core_tbl[lid].pic_extend = core_ext_ptr;
302    }
303
304    // allocate memory for cluster extension
[686]305    cluster_ext_ptr = kmem_alloc( bits_log2( sizeof(soclib_pic_cluster_t) ), AF_KERNEL );
[188]306
[635]307    if( cluster_ext_ptr == NULL )
308    {
309        printk("\n[PANIC] in %s : cannot allocate memory for cluster extension\n",
310        __FUNCTION__ );
311    }
312   
[188]313    // get XCU characteristics from the XCU config register
314    uint32_t  config = xcu_base[XCU_CONFIG<<5];
315    uint32_t  wti_nr = (config >> 16) & 0xFF; 
316    uint32_t  hwi_nr = (config >> 8 ) & 0xFF; 
317    uint32_t  pti_nr = (config      ) & 0xFF; 
318
319    // initialize the cluster extension
320    // The first WTI slots are for IPIs (one slot per core)
321    cluster_ext_ptr->xcu_base       = xcu_base;
322    cluster_ext_ptr->hwi_nr         = hwi_nr;
323    cluster_ext_ptr->wti_nr         = wti_nr;
324    cluster_ext_ptr->pti_nr         = pti_nr;
325    cluster_ext_ptr->first_free_wti = cluster->cores_nr;
326
327    // register PIC extension in cluster manager
328    cluster->pic_extend = cluster_ext_ptr;
329
[451]330    // reset the XCU component registers
331    // mask all HWIs, all WTIs, and all PTIs, for all cores in local cluster   
332    for( lid = 0 ; lid < cluster->cores_nr ; lid++ )
333    {
334        xcu_base[XCU_MSK_HWI_DISABLE << 5 | lid] = 0xFFFFFFFF;
335        xcu_base[XCU_MSK_WTI_DISABLE << 5 | lid] = 0xFFFFFFFF;
336        xcu_base[XCU_MSK_PTI_DISABLE << 5 | lid] = 0xFFFFFFFF;
337    }
338
[188]339}  // end soclib_pic_extend_init()
340
[75]341////////////////////////////////////////
[188]342void soclib_pic_bind_irq( lid_t     lid,
343                          chdev_t * src_chdev )
[75]344{
[435]345
[438]346#if DEBUG_HAL_IRQS
[435]347uint32_t cycle = (uint32_t)hal_get_cycles();
[438]348if( DEBUG_HAL_IRQS < cycle )
[435]349printk("\n[DBG] %s : thread %x enter for core[%x,%d] / cycle %d\n",
350__FUNCTION__ , CURRENT_THREAD , local_cxy , lid , cycle );
351#endif
352
[188]353    // get extended & local pointers on PIC chdev descriptor
354    xptr_t     pic_xp  = chdev_dir.pic;
355    cxy_t      pic_cxy = GET_CXY( pic_xp );
356    chdev_t *  pic_ptr = (chdev_t *)GET_PTR( pic_xp );
[75]357
[188]358    // get extended and local pointers on IOPIC  segment base
[570]359    xptr_t     seg_pic_xp  = hal_remote_l64( XPTR( pic_cxy , &pic_ptr->base ) );
[188]360    cxy_t      seg_pic_cxy = GET_CXY( seg_pic_xp );
361    uint32_t * seg_pic_ptr = (uint32_t *)GET_PTR( seg_pic_xp );
362
363    // get local pointer on XCU segment base
364    uint32_t * seg_xcu_ptr = soclib_pic_xcu_base();
365
366    // get the source chdev functionnal type, channel, and direction
367    uint32_t func    = src_chdev->func;
[534]368    uint32_t impl    = src_chdev->impl;
[188]369    uint32_t channel = src_chdev->channel;
370    bool_t   is_rx   = src_chdev->is_rx;
371
[686]372    if( ((func == DEV_FUNC_IOC) && (impl == IMPL_IOC_BDV)) || 
373        (func == DEV_FUNC_NIC)                             ||
374        ((func == DEV_FUNC_TXT) && (impl == IMPL_TXT_TTY)) ||
375        (func == DEV_FUNC_IOB) ) // external IRQ => WTI
[75]376    {
[188]377        // get external IRQ index
[679]378        uint32_t  hwi_id = 0;   
[407]379        if     (  func == DEV_FUNC_IOC            ) hwi_id = iopic_input.ioc[channel];
[686]380        else if( (func == DEV_FUNC_TXT) &&  is_rx ) hwi_id = iopic_input.txt_rx[channel];
381        else if( (func == DEV_FUNC_TXT) && !is_rx ) hwi_id = iopic_input.txt_tx[channel];
[407]382        else if( (func == DEV_FUNC_NIC) &&  is_rx ) hwi_id = iopic_input.nic_rx[channel];
383        else if( (func == DEV_FUNC_NIC) && !is_rx ) hwi_id = iopic_input.nic_tx[channel];
384        else if(  func == DEV_FUNC_IOB            ) hwi_id = iopic_input.iob;
[686]385        else 
386        {
387            printk("\n[WARNING] from %s : illegal device / func %s / is_rx %d\n",
388            __FUNCTION__, chdev_func_str(func), is_rx );
389        }
[188]390
391        // get a WTI mailbox from local XCU descriptor 
392        uint32_t wti_id = soclib_pic_wti_alloc();
393
394        // register IRQ type and index in chdev
395        src_chdev->irq_type = SOCLIB_TYPE_WTI;
396        src_chdev->irq_id   = wti_id;
397
398        // compute extended pointer on WTI mailbox in local XCU
399        xptr_t wti_xp = XPTR( local_cxy , &seg_xcu_ptr[(XCU_WTI_REG << 5) | wti_id] );
400
401            // set the IOPIC_ADDRESS and IOPIC_EXTEND registers in IOPIC
402        uint32_t lsb_wdata = (uint32_t)wti_xp;
403        uint32_t msb_wdata = (uint32_t)(wti_xp >> 32);
[407]404        xptr_t   lsb_xp = XPTR( seg_pic_cxy , seg_pic_ptr+hwi_id*IOPIC_SPAN+IOPIC_ADDRESS );
405        xptr_t   msb_xp = XPTR( seg_pic_cxy , seg_pic_ptr+hwi_id*IOPIC_SPAN+IOPIC_EXTEND );
[570]406        hal_remote_s32( lsb_xp , lsb_wdata );
407        hal_remote_s32( msb_xp , msb_wdata );
[188]408
[407]409        // enable IRQ in IOPIC
[570]410        hal_remote_s32( XPTR( seg_pic_cxy , seg_pic_ptr+hwi_id*IOPIC_SPAN+IOPIC_MASK ), 1 );
[188]411
412        // update the WTI interrupt vector for core[lid]
413        core_t * core = &LOCAL_CLUSTER->core_tbl[lid];
414        ((soclib_pic_core_t *)core->pic_extend)->wti_vector[wti_id] = src_chdev;
[407]415
[438]416#if DEBUG_HAL_IRQS
417if( DEBUG_HAL_IRQS < cycle )
[686]418printk("\n[DBG] %s : %s / channel %d / rx %d / hwi_id %d / wti_id %d / cluster %x\n",
[407]419__FUNCTION__ , chdev_func_str( func ) , channel , is_rx , hwi_id , wti_id , local_cxy );
[435]420#endif
[407]421
[75]422    }
[686]423    else if( (func == DEV_FUNC_DMA) || 
424             (func == DEV_FUNC_MMC) ||
[550]425             (func == DEV_FUNC_TXT && impl == IMPL_TXT_MTY) ||
426             (func == DEV_FUNC_IOC && impl == IMPL_IOC_SPI) )   // internal IRQ => HWI
[188]427    {
428        // get internal IRQ index
429        uint32_t hwi_id;
[686]430        if( func == DEV_FUNC_DMA )      hwi_id = lapic_input.dma[channel];
[534]431        else if (func == DEV_FUNC_TXT ) hwi_id = lapic_input.mtty;
[550]432        else if (func == DEV_FUNC_IOC ) hwi_id = lapic_input.sdcard;
[686]433        else                            hwi_id = lapic_input.mmc;
[75]434
[188]435        // register IRQ type and index in chdev
436        src_chdev->irq_type = SOCLIB_TYPE_HWI;
437        src_chdev->irq_id   = hwi_id;
438
439        // update the HWI interrupt vector for core[lid]
440        core_t * core = &LOCAL_CLUSTER->core_tbl[lid];
[468]441        ((soclib_pic_core_t *)core->pic_extend)->hwi_vector[hwi_id] = src_chdev;
[407]442
[438]443#if DEBUG_HAL_IRQS
444if( DEBUG_HAL_IRQS < cycle )
[435]445printk("\n[DBG] %s : %s / channel = %d / hwi_id = %d / cluster = %x\n",
[407]446__FUNCTION__ , chdev_func_str( func ) , channel , hwi_id , local_cxy );
[435]447#endif
[407]448
[188]449    }
450    else
451    {
[686]452        printk("\n[WARNING] from %s : illegal device / func %s / is_rx %d / impl %d\n",
453        __FUNCTION__, chdev_func_str(func), is_rx, impl );
[188]454    } 
455}  // end soclib_pic_bind_irq();
456
[205]457///////////////////////////////////////
458void soclib_pic_enable_irq( lid_t  lid,
459                            xptr_t src_chdev_xp )
[75]460{
[205]461    // get cluster and local pointer on remote src_chdev
462    cxy_t     src_chdev_cxy = GET_CXY( src_chdev_xp );
463    chdev_t * src_chdev_ptr = (chdev_t *)GET_PTR( src_chdev_xp );
[141]464
[205]465    // get local pointer on remote XCU segment base
466    uint32_t * seg_xcu_ptr = soclib_pic_remote_xcu_base( src_chdev_cxy );
467
[188]468    // get the source chdev IRQ type and index
[570]469    uint32_t irq_type = hal_remote_l32( XPTR( src_chdev_cxy , &src_chdev_ptr->irq_type ) );
470    uint32_t irq_id   = hal_remote_l32( XPTR( src_chdev_cxy , &src_chdev_ptr->irq_id ) );
[141]471
[188]472    if( irq_type == SOCLIB_TYPE_HWI )
473    {
[205]474        // enable this HWI in remote XCU controller
[432]475        // in TSAR : XCU output [4*lid] is connected to core [lid]
[570]476        hal_remote_s32( XPTR( src_chdev_cxy , 
[686]477        &seg_xcu_ptr[ (XCU_MSK_HWI_ENABLE << 5) | (lid<<2) ] ) , (1 << irq_id) );
[188]478    }
479    else if( irq_type == SOCLIB_TYPE_WTI )
480    {
[279]481        // enable this WTI in remote XCU controller
[432]482        // in TSAR : XCU output [4*lid] is connected to core [lid]
[570]483        hal_remote_s32( XPTR( src_chdev_cxy , 
[686]484        &seg_xcu_ptr[ (XCU_MSK_WTI_ENABLE << 5) | (lid<<2) ] ) , (1 << irq_id) );
[188]485    }
486    else
487    {
[686]488        printk("\n[WARNING] from %s : illegal IRQ type %d\n",
489        __FUNCTION__, irq_type );
[188]490    }
491} // end soclib_pic_enable_irq()
[75]492
[205]493////////////////////////////////////////
494void soclib_pic_disable_irq( lid_t  lid,
495                             xptr_t src_chdev_xp )
[188]496{
[205]497    // get cluster and local pointer on remote src_chdev
498    cxy_t     src_chdev_cxy = GET_CXY( src_chdev_xp );
499    chdev_t * src_chdev_ptr = (chdev_t *)GET_PTR( src_chdev_xp );
[75]500
[205]501    // get local pointer on remote XCU segment base
502    uint32_t * seg_xcu_ptr = soclib_pic_remote_xcu_base( src_chdev_cxy );
503
[188]504    // get the source chdev IRQ type and index
[570]505    uint32_t irq_type = hal_remote_l32( XPTR( src_chdev_cxy , &src_chdev_ptr->irq_type ) );
506    uint32_t irq_id   = hal_remote_l32( XPTR( src_chdev_cxy , &src_chdev_ptr->irq_id ) );
[75]507
[188]508    if( irq_type == SOCLIB_TYPE_HWI )
509    {
[432]510        // enable this HWI in remote XCU controller
511        // in TSAR : XCU output [4*lid] is connected to core [lid]
[570]512        hal_remote_s32( XPTR( src_chdev_cxy , 
[686]513        &seg_xcu_ptr[(XCU_MSK_HWI_DISABLE << 5) | (lid<<2) ] ) , (1 << irq_id) );
[188]514    }
515    else if( irq_type == SOCLIB_TYPE_WTI )
516    {
[279]517        // enable this WTI in remote XCU controller
[432]518        // in TSAR : XCU output [4*lid] is connected to core [lid]
[570]519        hal_remote_s32( XPTR( src_chdev_cxy , 
[686]520        &seg_xcu_ptr[(XCU_MSK_WTI_DISABLE << 5) | (lid<<2) ] ) , (1 << irq_id) );
[188]521    }
522    else
523    {
[686]524        printk("\n[WARNING] from %s : illegal IRQ type %d\n",
525        __FUNCTION__, irq_type );
[188]526    }
527} // end soclib_pic_enable_irq()
[75]528
[188]529///////////////////////////////////////////////
530void soclib_pic_enable_timer( uint32_t period )
[75]531{
[188]532    // calling core local index
[457]533    lid_t  lid = CURRENT_THREAD->core->lid;
[141]534
[188]535    // get XCU segment base
536    uint32_t * base = soclib_pic_xcu_base();
[141]537
[380]538    // set period value in XCU (in cycles)
[407]539    uint32_t cycles = period * SOCLIB_CYCLES_PER_MS;
[380]540    base[(XCU_PTI_PER << 5) | lid] = cycles;
[75]541
[279]542    // enable PTI in local XCU controller
[432]543    // In TSAR : XCU output [4*lid] is connected to core [lid]
544    base[ (XCU_MSK_PTI_ENABLE << 5) | (lid<<2) ] = 1 << lid;
[75]545}
546
[279]547////////////////////////////
[481]548void soclib_pic_enable_ipi( void )
[279]549{
550    // calling core local index
[457]551    lid_t  lid = CURRENT_THREAD->core->lid;
[279]552
553    // get XCU segment base
554    uint32_t * base = soclib_pic_xcu_base();
555
556    // enable WTI in local XCU controller
[432]557    // In TSAR : XCU output [4*lid] is connected to core [lid]
558    base[ (XCU_MSK_WTI_ENABLE << 5) | (lid<<2) ] = 1 << lid;
[279]559}
560
[188]561///////////////////////////////////////
562void soclib_pic_send_ipi( cxy_t    cxy,
563                          lid_t    lid )
[75]564{
[188]565    // get pointer on local XCU segment base
566    uint32_t * base = soclib_pic_xcu_base();
[141]567
[188]568    // write to WTI mailbox[cxy][lid]
[570]569    hal_remote_s32( XPTR( cxy , &base[(XCU_WTI_REG << 5) | lid ] ) , 0 );
[188]570}
[141]571
[686]572///////////////////////////////
[481]573void soclib_pic_ack_ipi( void )
[407]574{
575    // get calling core local index
576    lid_t      lid  = CURRENT_THREAD->core->lid;
[75]577
[407]578    // get pointer on local XCU segment base
579    uint32_t * base = soclib_pic_xcu_base();
[75]580
[407]581    // acknowlege IPI
[432]582    uint32_t   ack  = base[ (XCU_WTI_REG << 5) | lid ];
[407]583
[686]584    // we make a fake use for ack value to avoid a warning
[424]585    if( (ack + 1) == 0 ) asm volatile( "nop" );
[407]586}
587   
588
Note: See TracBrowser for help on using the repository browser.