source: soft/giet_vm/giet_drivers/xcu_driver.c @ 496

Last change on this file since 496 was 496, checked in by alain, 9 years ago

1) Introduce access functions to MMC intrumentation registers.
2) Use _printf for error or debug messages.

File size: 10.1 KB
RevLine 
[258]1///////////////////////////////////////////////////////////////////////////////////
2// File     : xcu_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
[320]8#include <hard_config.h>
[258]9#include <giet_config.h>
10#include <xcu_driver.h>
[456]11#include <tty0.h>
[263]12#include <mapping_info.h>
[258]13#include <utils.h>
[345]14#include <io.h>
[258]15
[263]16#if !defined(X_SIZE)
17# error: You must define X_SIZE in the hard_config.h file
[258]18#endif
19
[263]20#if !defined(Y_SIZE)
21# error: You must define X_SIZE in the hard_config.h file
[258]22#endif
23
[263]24#if !defined(X_WIDTH)
25# error: You must define X_WIDTH in the hard_config.h file
26#endif
27
28#if !defined(Y_WIDTH)
29# error: You must define X_WIDTH in the hard_config.h file
30#endif
31
[258]32#if !defined(NB_PROCS_MAX)
33# error: You must define NB_PROCS_MAX in the hard_config.h file
34#endif
35
[320]36#if !defined( USE_XCU )
37# error: You must define USE_XCU in the hard_config.h file
[258]38#endif
39
[320]40#if !defined( SEG_XCU_BASE )
41# error: You must define SEG_XCU_BASE in the hard_config.h file
42#endif
[295]43
[333]44#if !defined( PERI_CLUSTER_INCREMENT )
45# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
[320]46#endif
47
[345]48///////////////////////////////////////////////////////////////////////////////
49// This low level function returns the value contained in register "index"
50// in the XCU component contained in cluster "cluster_xy"
51///////////////////////////////////////////////////////////////////////////////
52static
53unsigned int _xcu_get_register( unsigned int cluster_xy, // cluster index
54                                unsigned int func,       // function index
55                                unsigned int index )     // register index
56{
57    unsigned int vaddr =
58        SEG_XCU_BASE + 
59        (cluster_xy * PERI_CLUSTER_INCREMENT) +
60        (XCU_REG(func, index) << 2);
[320]61
[345]62    return ioread32( (void*)vaddr );
63}
64
65///////////////////////////////////////////////////////////////////////////////
66// This low level function sets a new value in register "index"
67// in the XCU component contained in cluster "cluster_xy"
68///////////////////////////////////////////////////////////////////////////////
69static
70void _xcu_set_register( unsigned int cluster_xy,       // cluster index
71                        unsigned int func,             // func index
72                        unsigned int index,            // register index
73                        unsigned int value )           // value to be written
74{
75    unsigned int vaddr =
76        SEG_XCU_BASE + 
77        (cluster_xy * PERI_CLUSTER_INCREMENT) +
78        (XCU_REG(func, index) << 2);
79       
80    iowrite32( (void*)vaddr, value );
81}
82
[437]83////////////////////////////////////////////
[295]84void _xcu_set_mask( unsigned int cluster_xy, 
85                    unsigned int channel, 
86                    unsigned int value,
87                    unsigned int irq_type ) 
[258]88{
[320]89#if USE_XCU
[258]90    // parameters checking
[263]91    unsigned int x = cluster_xy >> Y_WIDTH;
92    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]93    if (x >= X_SIZE)                                   _exit(); 
94    if (y >= Y_SIZE)                                   _exit(); 
95    if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit(); 
[258]96
[345]97    unsigned int func = 0;
[320]98    if      (irq_type == IRQ_TYPE_PTI) func = XCU_MSK_PTI_ENABLE;
99    else if (irq_type == IRQ_TYPE_WTI) func = XCU_MSK_WTI_ENABLE;
100    else if (irq_type == IRQ_TYPE_HWI) func = XCU_MSK_HWI_ENABLE;
[295]101    else
102    { 
[496]103        _printf("[GIET ERROR] _xcu_set_mask() receives illegal IRQ type\n");
[295]104        _exit();
105    }
106
[345]107    _xcu_set_register(cluster_xy, func, channel, value);
[295]108
[258]109#else
[496]110    _printf("[GIET ERROR] _xcu_set_mask() should not be used if USE_XCU not set\n");
[295]111    _exit();
[258]112#endif
113}
114
[437]115/////////////////////////////////////////////
[295]116void _xcu_get_index( unsigned int cluster_xy, 
117                     unsigned int channel,   
118                     unsigned int * index, 
119                     unsigned int * irq_type )
[258]120{
[320]121#if USE_XCU
[258]122    // parameters checking
[263]123    unsigned int x = cluster_xy >> Y_WIDTH;
124    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]125    if (x >= X_SIZE)                                   _exit(); 
126    if (y >= Y_SIZE)                                   _exit(); 
127    if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit(); 
[258]128
[345]129    unsigned int prio = _xcu_get_register(cluster_xy, XCU_PRIO, channel);
[258]130    unsigned int pti_ok = (prio & 0x00000001);
131    unsigned int hwi_ok = (prio & 0x00000002);
[295]132    unsigned int wti_ok = (prio & 0x00000004);
[258]133    unsigned int pti_id = (prio & 0x00001F00) >> 8;
134    unsigned int hwi_id = (prio & 0x001F0000) >> 16;
[295]135    unsigned int wti_id = (prio & 0x1F000000) >> 24;
136    if      (pti_ok)
137    {
138        *index    = pti_id;
139        *irq_type = IRQ_TYPE_PTI;
140    }
141    else if (hwi_ok)
142    {
143        *index    = hwi_id;
144        *irq_type = IRQ_TYPE_HWI;
145    }
146    else if (wti_ok) 
147    {
148        *index    = wti_id;
149        *irq_type = IRQ_TYPE_WTI;
150    }
151    else 
152    {
153        *index = 32;
154    }
155 
[258]156#else
[496]157    _printf("[GIET ERROR] _xcu_get_index should not be used if USE_XCU is not set\n");
[295]158    _exit();
[258]159#endif
160}
161
[437]162////////////////////////////////////////////
[295]163void _xcu_send_wti( unsigned int cluster_xy,
164                    unsigned int wti_index,
165                    unsigned int wdata )
[258]166{ 
[320]167#if USE_XCU
[258]168    // parameters checking
[263]169    unsigned int x = cluster_xy >> Y_WIDTH;
170    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]171    if (x >= X_SIZE)               _exit(); 
172    if (y >= Y_SIZE)               _exit(); 
173    if (wti_index >= 32)           _exit(); 
[258]174
[345]175    _xcu_set_register(cluster_xy, XCU_WTI_REG, wti_index, wdata);
[275]176
[258]177#else
[496]178    _printf("[GIET ERROR] _xcu_send_wti() should not be used if USE_XCU is not set\n");
[295]179    _exit();
[258]180#endif
181} 
182
[490]183////////////////////////////////////////////
184void _xcu_send_wti_paddr( unsigned int cluster_xy,
185                          unsigned int wti_index,
186                          unsigned int wdata )
187{ 
188#if USE_XCU
189    // parameters checking
190    unsigned int x = cluster_xy >> Y_WIDTH;
191    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
192    if (x >= X_SIZE)               _exit(); 
193    if (y >= Y_SIZE)               _exit(); 
194    if (wti_index >= 32)           _exit(); 
195
196    paddr_t paddr =
197         SEG_XCU_BASE + ((paddr_t)cluster_xy << 32) + 
198        (XCU_REG(XCU_WTI_REG, wti_index) << 2);
199
200    _physical_write(paddr, wdata);
201
202#else
203    _puts("[GIET ERROR] _xcu_send_wti() should not be used if USE_XCU is not set\n");
204    _exit();
205#endif
206}
[437]207///////////////////////////////////////////////////
[295]208void _xcu_get_wti_value( unsigned int   cluster_xy,
209                         unsigned int   wti_index,
210                         unsigned int * value )
211{
[320]212#if USE_XCU
[295]213    // parameters checking
214    unsigned int x = cluster_xy >> Y_WIDTH;
215    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
216    if (x >= X_SIZE)               _exit(); 
217    if (y >= Y_SIZE)               _exit(); 
218    if (wti_index >= 32)           _exit(); 
219 
[345]220    *value = _xcu_get_register(cluster_xy, XCU_WTI_REG, wti_index);
[295]221
222#else
[496]223    _printf("[GIET ERROR] in _xcu_get_wti_value() USE_XCU is not set\n");
[295]224    _exit();
225#endif
226}
227
[437]228////////////////////////////////////////////////////
[295]229void _xcu_get_wti_address( unsigned int   wti_index,
230                           unsigned int * address )
231{
[320]232#if USE_XCU
[295]233    if (wti_index >= 32)           _exit(); 
234 
[345]235    *address = SEG_XCU_BASE + (XCU_REG(XCU_WTI_REG, wti_index)<<2); 
[295]236
237#else
[496]238    _printf("[GIET ERROR] in _xcu_get_wti_address() USE_XCU is not set\n");
[295]239    _exit();
240#endif
241}
242
[437]243///////////////////////////////////////////////
[295]244void _xcu_timer_start( unsigned int cluster_xy,
245                       unsigned int pti_index,
246                       unsigned int period )
[258]247{
[320]248#if USE_XCU
[258]249    // parameters checking
[263]250    unsigned int x = cluster_xy >> Y_WIDTH;
251    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]252    if (x >= X_SIZE)             _exit(); 
253    if (y >= Y_SIZE)             _exit(); 
[258]254
[345]255    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, period);
[275]256
[258]257#else
[496]258    _printf("[GIET ERROR] in _xcu_timer_start() USE_XCU is not set\n");
[295]259    _exit();
[258]260#endif
261}
262
[437]263//////////////////////////////////////////////
[295]264void _xcu_timer_stop( unsigned int cluster_xy, 
265                      unsigned int pti_index) 
[258]266{
[320]267#if USE_XCU
[258]268    // parameters checking
[263]269    unsigned int x = cluster_xy >> Y_WIDTH;
270    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]271    if (x >= X_SIZE)             _exit(); 
272    if (y >= Y_SIZE)             _exit(); 
[258]273
[345]274    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0);
[275]275
[258]276#else
[496]277    _printf("[GIET ERROR] in _xcu_timer_stop() USE_XCU is not set\n");
[295]278    _exit();
[258]279#endif
280}
281
[437]282///////////////////////////////////////////////////////////
[320]283unsigned int _xcu_timer_reset_irq( unsigned int cluster_xy, 
284                                   unsigned int pti_index ) 
[258]285{
[320]286#if USE_XCU
[258]287    // parameters checking
[263]288    unsigned int x = cluster_xy >> Y_WIDTH;
289    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]290    if (x >= X_SIZE)             _exit(); 
291    if (y >= Y_SIZE)             _exit(); 
[258]292
[320]293    // This return value is not used / avoid a compilation warning.
[345]294    return _xcu_get_register(cluster_xy, XCU_PTI_ACK, pti_index);
[295]295
[258]296#else
[437]297    _puts("[GIET ERROR] in _xcu_timer_reset_irq() USE_XCU is not set\n");
[295]298    _exit();
[320]299    return 0;
[258]300#endif
301}
302
[437]303///////////////////////////////////////////////////
[295]304void _xcu_timer_reset_cpt( unsigned int cluster_xy, 
305                           unsigned int pti_index ) 
[258]306{
[320]307#if USE_XCU
[258]308    // parameters checking
[263]309    unsigned int x = cluster_xy >> Y_WIDTH;
310    unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
[295]311    if (x >= X_SIZE)             _exit(); 
312    if (y >= Y_SIZE)             _exit(); 
[258]313
[345]314    unsigned int per = _xcu_get_register(cluster_xy, XCU_PTI_PER, pti_index);
[258]315
316    // we write 0 first because if the timer is currently running,
317    // the corresponding timer counter is not reset
[345]318    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0);
319    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, per);
[295]320
[258]321#else
[437]322    _puts("[GIET ERROR] in _xcu_timer_reset_cpt() USE_XCU is not set\n");
[295]323    _exit();
[258]324#endif
325}
326
327
328// Local Variables:
329// tab-width: 4
330// c-basic-offset: 4
331// c-file-offsets:((innamespace . 0)(inline-open . 0))
332// indent-tabs-mode: nil
333// End:
334// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
335
Note: See TracBrowser for help on using the repository browser.