source: trunk/kernel/drivers/soclib/soclib_xcu.c @ 8

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

Introduce the chdev_t structure in place of device_t.

File size: 4.5 KB
RevLine 
[1]1/*
2 * soclib_xcu.c - soclib XCU driver 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 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
20 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <soclib_xcu.h>
25#include <hal_types.h>
26#include <core.h>
[4]27#include <chdev.h>
[1]28
29
30
[4]31////////////////////////////////////
32void soclib_xcu_init( chdev_t * icu,
33                      lid_t     lid )
[1]34{
35    // get local ICU segment base address
36        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
37
38    // write into registers
39    base[XCU_MSK_HWI_DISABLE << 5 | lid] = 0xFFFFFFFF;
40    base[XCU_MSK_WTI_DISABLE << 5 | lid] = 0xFFFFFFFF;
41    base[XCU_MSK_PTI_DISABLE << 5 | lid] = 0xFFFFFFFF;
42}
43
[4]44////////////////////////////////////////////
45void soclib_xcu_disable_irq( chdev_t  * icu,
[1]46                             uint32_t   mask,
47                             uint32_t   type,
48                             lid_t      lid )
49{
[4]50    // get XCU segment base address
51        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
[1]52
[4]53    // write into register
54        if     ( type == WTI_TYPE ) base[XCU_MSK_WTI_DISABLE << 5 | lid] = mask;
55        else if( type == HWI_TYPE ) base[XCU_MSK_HWI_DISABLE << 5 | lid] = mask;
56        else                        base[XCU_MSK_PTI_DISABLE << 5 | lid] = mask;
[1]57}
58
[4]59///////////////////////////////////////////
60void soclib_xcu_enable_irq( chdev_t  * icu,
[1]61                            uint32_t   mask,
62                            uint32_t   type,
63                            lid_t      lid )
64{
[4]65    // get XCU segment base address
66        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
[1]67
[4]68    // write into register
69        if     ( type == WTI_TYPE ) base[XCU_MSK_WTI_ENABLE << 5 | lid] = mask;
70        else if( type == HWI_TYPE ) base[XCU_MSK_HWI_ENABLE << 5 | lid] = mask;
71        else                        base[XCU_MSK_PTI_ENABLE << 5 | lid] = mask;
[1]72}
73
[4]74//////////////////////////////////////////
75void soclib_xcu_set_period( chdev_t * icu,
76                            uint32_t  index,
77                            uint32_t  period )
[1]78{
79    // get local ICU segment base address
80        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
81
82    // write into register
83    base[XCU_PTI_PER << 5 | index] = period;
84}
85
[4]86/////////////////////////////////////////////
87uint32_t soclib_xcu_ack_timer( chdev_t * icu,
88                               uint32_t  index )
[1]89{
90    // get local ICU segment base address
91        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
92
93    // read from register
94        return base[XCU_PTI_ACK << 5 | index];
95}
96
[4]97///////////////////////////////////////////
98void soclib_xcu_get_status( chdev_t  * icu,
[1]99                            lid_t      lid,
100                            uint32_t * hwi_status,
101                            uint32_t * wti_status,
102                            uint32_t * pti_status )
103{
104    // get local ICU segment base address
105    uint32_t * base = (uint32_t *)GET_PTR( icu->base );
106
107    // read PRIO register
108        uint32_t prio = base[XCU_PRIO << 5 | lid];
109
110    if( prio & 0x4 ) *wti_status = ((prio >> 24) & 0x1F) + 1;
111    if( prio & 0x2 ) *hwi_status = ((prio >> 16) & 0x1F) + 1;
112    if( prio & 0x1 ) *pti_status = ((prio >>  8) & 0x1F) + 1;
113}
114
115/////////////////////////////////////////
[4]116void soclib_xcu_send_ipi( xptr_t  icu_xp,
[1]117                          lid_t   lid )
118{
119    // get target ICU device cluster and local pointer
[4]120    cxy_t       cxy_icu = GET_CXY( icu_xp );
121    chdev_t  * ptr_icu = (chdev_t *)GET_PTR( icu_xp );
[1]122
123    // get extended pointer on target ICU segment base
124    xptr_t  xp_base = (xptr_t)hal_remote_lwd( XPTR( cxy_icu , &ptr_icu->base ) );
125
126    // get remote ICU segment local pointer
127        uint32_t  * base = (uint32_t *)GET_PTR( xp_base );
128
129    // send IPI to remote core
130        hal_remote_sw( XPTR( cxy_icu , &base[XCU_WTI_REG << 5 | lid] ) , 0 );
131}
132
133//////////////////////////////////////////////
[4]134uint32_t * soclib_xcu_wti_ptr( chdev_t  * icu,
[1]135                               uint32_t   index )
136{
137    uint32_t * base = (uint32_t *)GET_PTR( icu->base );
138
139    return &base[XCU_WTI_REG << 5 | index];
140}
Note: See TracBrowser for help on using the repository browser.