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

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

Introducing dynamic allocation of peripheral channel(TTY, NIC, TIM, CMA)
Removint the ICU driver : ICU component not supported anymore.
Removing the FBF driver.

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