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

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

First import

File size: 5.2 KB
Line 
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>
27#include <device.h>
28
29
30
31/////////////////////////////////////
32void soclib_xcu_init( device_t * icu,
33                      lid_t      lid )
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
44///////////////////////////////////////////////
45void soclib_xcu_disable_irq( xptr_t     icu_xp,
46                             uint32_t   mask,
47                             uint32_t   type,
48                             lid_t      lid )
49{
50    // get remote ICU cluster and local pointer
51    cxy_t      icu_cxy = GET_CXY( icu_xp );
52    device_t * icu_ptr = (device_t *)GET_PTR( icu_xp );
53
54    // get remote XCU segment base address
55        xptr_t base = (xptr_t)hal_remote_lwd( XPTR( icu_cxy , &icu_ptr->base ) );
56
57    // compute xptr on relevant XCU mask register
58    xptr_t   reg_xp;
59        if     ( type == WTI_TYPE ) reg_xp = base + ((XCU_MSK_WTI_DISABLE << 5 | lid)<<2);
60        else if( type == HWI_TYPE ) reg_xp = base + ((XCU_MSK_HWI_DISABLE << 5 | lid)<<2);
61        else                        reg_xp = base + ((XCU_MSK_PTI_DISABLE << 5 | lid)<<2);
62
63    // reset relevant XCU mask register
64        hal_remote_sw( reg_xp , mask );
65}
66
67//////////////////////////////////////////////
68void soclib_xcu_enable_irq( xptr_t     icu_xp,
69                            uint32_t   mask,
70                            uint32_t   type,
71                            lid_t      lid )
72{
73    // get remote ICU cluster and local pointer
74    cxy_t      icu_cxy = GET_CXY( icu_xp );
75    device_t * icu_ptr = (device_t *)GET_PTR( icu_xp );
76
77    // get remote XCU segment base address
78        xptr_t base = (xptr_t)hal_remote_lwd( XPTR( icu_cxy , &icu_ptr->base ) );
79
80    // compute xptr on relevant XCU mask register
81    xptr_t   reg_xp;
82        if     ( type == WTI_TYPE ) reg_xp = base + ((XCU_MSK_WTI_ENABLE << 5 | lid)<<2);
83        else if( type == HWI_TYPE ) reg_xp = base + ((XCU_MSK_HWI_ENABLE << 5 | lid)<<2);
84        else                        reg_xp = base + ((XCU_MSK_PTI_ENABLE << 5 | lid)<<2);
85
86    // set relevant XCU mask register
87        hal_remote_sw( reg_xp , mask );
88}
89
90///////////////////////////////////////////
91void soclib_xcu_set_period( device_t * icu,
92                            uint32_t   index,
93                            uint32_t   period )
94{
95    // get local ICU segment base address
96        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
97
98    // write into register
99    base[XCU_PTI_PER << 5 | index] = period;
100}
101
102//////////////////////////////////////////////
103uint32_t soclib_xcu_ack_timer( device_t * icu,
104                               uint32_t   index )
105{
106    // get local ICU segment base address
107        uint32_t * base = (uint32_t *)GET_PTR( icu->base );
108
109    // read from register
110        return base[XCU_PTI_ACK << 5 | index];
111}
112
113///////////////////////////////////////////////
114void soclib_xcu_get_status( device_t * icu,
115                            lid_t      lid,
116                            uint32_t * hwi_status,
117                            uint32_t * wti_status,
118                            uint32_t * pti_status )
119{
120    // get local ICU segment base address
121    uint32_t * base = (uint32_t *)GET_PTR( icu->base );
122
123    // read PRIO register
124        uint32_t prio = base[XCU_PRIO << 5 | lid];
125
126    if( prio & 0x4 ) *wti_status = ((prio >> 24) & 0x1F) + 1;
127    if( prio & 0x2 ) *hwi_status = ((prio >> 16) & 0x1F) + 1;
128    if( prio & 0x1 ) *pti_status = ((prio >>  8) & 0x1F) + 1;
129}
130
131/////////////////////////////////////////
132void soclib_xcu_send_ipi( xptr_t  xp_icu,
133                          lid_t   lid )
134{
135    // get target ICU device cluster and local pointer
136    cxy_t       cxy_icu = GET_CXY( xp_icu );
137    device_t  * ptr_icu = (device_t *)GET_PTR( xp_icu );
138
139    // get extended pointer on target ICU segment base
140    xptr_t  xp_base = (xptr_t)hal_remote_lwd( XPTR( cxy_icu , &ptr_icu->base ) );
141
142    // get remote ICU segment local pointer
143        uint32_t  * base = (uint32_t *)GET_PTR( xp_base );
144
145    // send IPI to remote core
146        hal_remote_sw( XPTR( cxy_icu , &base[XCU_WTI_REG << 5 | lid] ) , 0 );
147}
148
149//////////////////////////////////////////////
150uint32_t * soclib_xcu_wti_ptr( device_t * icu,
151                               uint32_t   index )
152{
153    uint32_t * base = (uint32_t *)GET_PTR( icu->base );
154
155    return &base[XCU_WTI_REG << 5 | index];
156}
Note: See TracBrowser for help on using the repository browser.