source: soft/giet_vm/giet_drivers/mmc_driver.c @ 456

Last change on this file since 456 was 456, checked in by alain, 10 years ago

Defining the NIC and CMA drivers (validated by the classif application).
Updating other drivers to comply with the new tty0 common file.

File size: 5.4 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : mmc_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <giet_config.h>
9#include <mmc_driver.h>
10#include <tty0.h>
11#include <utils.h>
12#include <io.h>
13
14#if !defined(X_SIZE)
15# error: You must define X_SIZE in the hard_config.h file
16#endif
17
18#if !defined(Y_SIZE)
19# error: You must define X_SIZE in the hard_config.h file
20#endif
21
22#if !defined(X_WIDTH)
23# error: You must define X_WIDTH in the hard_config.h file
24#endif
25
26#if !defined(Y_WIDTH)
27# error: You must define X_WIDTH in the hard_config.h file
28#endif
29
30#if !defined(SEG_MMC_BASE)
31# error: You must define SEG_MMC_BASE in the hard_config.h file
32#endif
33
34#if !defined(PERI_CLUSTER_INCREMENT)
35# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
36#endif
37
38///////////////////////////////////////////////////////////////////////////////
39// This low level function returns the value contained in register
40// defined by the ("func" / "index") arguments,
41// in the MMC component contained in cluster "cluster_xy"
42///////////////////////////////////////////////////////////////////////////////
43static
44unsigned int _mmc_get_register( unsigned int cluster_xy, // cluster index
45                                unsigned int func,       // function index
46                                unsigned int index )     // register index
47{
48    unsigned int vaddr =
49        SEG_MMC_BASE + 
50        (cluster_xy * PERI_CLUSTER_INCREMENT) +
51        (MMC_REG(func, index) << 2);
52
53    return ioread32( (void*)vaddr );
54}
55
56///////////////////////////////////////////////////////////////////////////////
57// This low level function sets a new value in register
58// defined by the ("func" / "index") arguments,
59// in the MMC component contained in cluster "cluster_xy"
60///////////////////////////////////////////////////////////////////////////////
61static
62void _mmc_set_register( unsigned int cluster_xy,       // cluster index
63                        unsigned int func,             // func index
64                        unsigned int index,            // register index
65                        unsigned int value )           // value to be written
66{
67    unsigned int vaddr =
68        SEG_MMC_BASE + 
69        (cluster_xy * PERI_CLUSTER_INCREMENT) +
70        (MMC_REG(func, index) << 2);
71       
72    iowrite32( (void*)vaddr, value );
73}
74
75/////////////////////////////////////////
76void _mmc_inval( paddr_t      buf_paddr,
77                 unsigned int buf_length )
78{
79    // compute cluster coordinates
80    unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH));
81    unsigned int x          = cluster_xy >> Y_WIDTH;
82    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
83
84    // parameters checking
85    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
86    {
87        _puts("\n[GIET ERROR] in _memc_inval() : illegal cluster coordinates\n");
88        _exit();
89    }
90
91    // get the hard lock protecting exclusive access to MEMC
92    while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) );
93
94    // write inval arguments
95    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO   , (unsigned int)buf_paddr);
96    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI   , (unsigned int)(buf_paddr>>32));
97    _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length);
98    _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE  , MEMC_CMD_INVAL);
99
100    // release the lock
101    _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0);
102}
103
104///////////////////////////////////////
105void _mmc_sync( paddr_t      buf_paddr,
106                unsigned int buf_length )
107{
108    // compute cluster coordinates
109    unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH));
110    unsigned int x          = cluster_xy >> Y_WIDTH;
111    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
112
113    // parameters checking
114    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
115    {
116        _puts( "\n[GIET ERROR] in _memc_sync() : illegal cluster coordinates");
117        _exit();
118    }
119
120    // get the hard lock protecting exclusive access to MEMC
121    while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) );
122
123    // write inval arguments
124    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO   , (unsigned int)buf_paddr);
125    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI   , (unsigned int)(buf_paddr>>32));
126    _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length);
127    _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE  , MEMC_CMD_SYNC);
128
129    // release the lock
130    _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0);
131}
132
133///////////////////////////////////////////////////////
134void _mmc_isr( unsigned int irq_type,  // should be HWI
135               unsigned int irq_id,    // index returned by ICU
136               unsigned int channel )  // unused
137{
138    unsigned int gpid       = _get_procid();
139    unsigned int cluster_xy = gpid >> P_WIDTH;
140    unsigned int x          = cluster_xy >> Y_WIDTH;
141    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
142    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
143
144    _puts("[GIET ERROR] MMC IRQ received by processor[");
145    _putd( x );
146    _puts(",");
147    _putd( y );
148    _puts(",");
149    _putd( p );
150    _puts("] but _mmc_isr() not implemented\n");
151}
152
153
154
155// Local Variables:
156// tab-width: 4
157// c-basic-offset: 4
158// c-file-offsets:((innamespace . 0)(inline-open . 0))
159// indent-tabs-mode: nil
160// End:
161// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
162
Note: See TracBrowser for help on using the repository browser.