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

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

1) The NIC, IOC, DMA and HBA drivers have been adapted to support the new _v2p_translate() function prototype (returns void).
2) The _mmc_inval() and _mmc_sync() functions does not use anymore the hard lock in the MMC, but use a soft spin_lock.
3) The NIC driver does not use anymore the GIET_NIC_BUFSIZE, GIET_NIC_NBUFS, and GIET_NIC_TIMEOUT parameters (removed from giet_config.h file).
4) The NIC driver registers map has been modified to support 64 bytes buffer descriptors for chained buffers.

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