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

Last change on this file since 481 was 481, checked in by alain, 9 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
RevLine 
[258]1///////////////////////////////////////////////////////////////////////////////////
2// File     : mmc_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
[481]8#include <hard_config.h>
[258]9#include <mmc_driver.h>
[456]10#include <tty0.h>
[481]11#include <locks.h>
[258]12#include <utils.h>
[481]13
[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
[320]32#if !defined(SEG_MMC_BASE)
33# error: You must define SEG_MMC_BASE in the hard_config.h file
34#endif
35
[333]36#if !defined(PERI_CLUSTER_INCREMENT)
37# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
[320]38#endif
39
[345]40///////////////////////////////////////////////////////////////////////////////
[456]41// This low level function returns the value contained in register
42// defined by the ("func" / "index") arguments,
[345]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///////////////////////////////////////////////////////////////////////////////
[456]59// This low level function sets a new value in register
60// defined by the ("func" / "index") arguments,
[345]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
[437]77/////////////////////////////////////////
[297]78void _mmc_inval( paddr_t      buf_paddr,
79                 unsigned int buf_length )
[258]80{
[263]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);
[258]85
[263]86    // parameters checking
87    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
88    {
[437]89        _puts("\n[GIET ERROR] in _memc_inval() : illegal cluster coordinates\n");
[263]90        _exit();
91    }
92
[481]93    // get the hard queuing lock protecting exclusive access to MEMC
94    _spin_lock_acquire( &_mmc_lock[x][y] );
[258]95
96    // write inval arguments
[481]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 );
[258]101
102    // release the lock
[481]103    _spin_lock_release( &_mmc_lock[x][y] );
[258]104}
[437]105
106///////////////////////////////////////
[297]107void _mmc_sync( paddr_t      buf_paddr,
108                unsigned int buf_length )
[258]109{
[263]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);
[258]114
[263]115    // parameters checking
116    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
117    {
[437]118        _puts( "\n[GIET ERROR] in _memc_sync() : illegal cluster coordinates");
[263]119        _exit();
120    }
121
[481]122    // get the hard queuing lock protecting exclusive access to MEMC
123    _spin_lock_acquire( &_mmc_lock[x][y] );
[258]124
125    // write inval arguments
[345]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);
[258]130
[345]131    // release the lock
[481]132    _spin_lock_release( &_mmc_lock[x][y] );
[258]133}
134
[437]135///////////////////////////////////////////////////////
[297]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{
[426]140    unsigned int gpid       = _get_procid();
141    unsigned int cluster_xy = gpid >> P_WIDTH;
[298]142    unsigned int x          = cluster_xy >> Y_WIDTH;
143    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
[437]144    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
[298]145
[437]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");
[297]153}
154
155
156
[258]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.