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

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

Cosmetic

File size: 5.5 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// The mmc_driver.c and mmc_driver.h files are part ot the GIET-VM nano-kernel.
8// This driver supports the vci_mem_cache component used in the TSAR architecture.
9//
10// This component is replicated in all clusters, and can be accessed through
11// a configuration interface as a set of uncached, memory mapped registers.
[320]12//
[258]13// The (virtual) base address of the associated segment is:
[333]14//       SEG_MMC_BASE + cluster_id * PERI_CLUSTER_INCREMENT
[258]15//
[333]16// SEG_MMC_BASE and PERI_CLUSTER_INCREMENT must be defined in hard_config.h.
[258]17////////////////////////////////////////////////////////////////////////////////
18
19#include <giet_config.h>
20#include <mmc_driver.h>
[263]21#include <tty_driver.h>
[258]22#include <utils.h>
23
[263]24#if !defined(X_SIZE)
25# error: You must define X_SIZE in the hard_config.h file
[258]26#endif
27
[263]28#if !defined(Y_SIZE)
29# error: You must define X_SIZE in the hard_config.h file
[258]30#endif
31
[263]32#if !defined(X_WIDTH)
33# error: You must define X_WIDTH in the hard_config.h file
34#endif
35
36#if !defined(Y_WIDTH)
37# error: You must define X_WIDTH in the hard_config.h file
38#endif
39
[320]40#if !defined(SEG_MMC_BASE)
41# error: You must define SEG_MMC_BASE in the hard_config.h file
42#endif
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
[258]48///////////////////////////////////////////////////////////////////////////////////
49// This function invalidates all cache lines covering a memory buffer defined
50// by the physical base address, and the length.
51// The buffer address MSB are used to compute the cluster index.
52///////////////////////////////////////////////////////////////////////////////////
[297]53void _mmc_inval( paddr_t      buf_paddr,
54                 unsigned int buf_length )
[258]55{
[263]56    // compute cluster coordinates
57    unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH));
58    unsigned int x          = cluster_xy >> Y_WIDTH;
59    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
[258]60
[263]61    // parameters checking
62    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
63    {
[295]64        _printf("\n[GIET ERROR] in _memc_inval() : illegal cluster_xy for paddr %l\n",
65                 buf_paddr );
[263]66        _exit();
67    }
68
[320]69    unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE + 
[333]70                                (cluster_xy * PERI_CLUSTER_INCREMENT) );
[258]71
72    // get the hard lock protecting exclusive access to MEMC
73    while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
74
75    // write inval arguments
76    mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
77    mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
78    mmc_address[MEMC_BUF_LENGTH] = buf_length;
79    mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_INVAL;
80
81    // release the lock
82    mmc_address[MEMC_LOCK] = 0;
83}
84///////////////////////////////////////////////////////////////////////////////////
85// This function copies to external RAM all cache lines covering a memory buffer
86// defined by the physical base address, and the length, if they are dirty.
87// The buffer address MSB are used to compute the cluster index.
88///////////////////////////////////////////////////////////////////////////////////
[297]89void _mmc_sync( paddr_t      buf_paddr,
90                unsigned int buf_length )
[258]91{
[263]92    // compute cluster coordinates
93    unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH));
94    unsigned int x          = cluster_xy >> Y_WIDTH;
95    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
[258]96
[263]97    // parameters checking
98    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
99    {
[295]100        _printf( "\n[GIET ERROR] in _memc_sync() : illegal cluster_xy for paddr %l\n",
101                 buf_paddr );
[263]102        _exit();
103    }
104
[320]105    unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE + 
[333]106                                (cluster_xy * PERI_CLUSTER_INCREMENT) );
[258]107
108    // get the hard lock protecting exclusive access to MEMC
109    while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
110
111    // write inval arguments
112    mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
113    mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
114    mmc_address[MEMC_BUF_LENGTH] = buf_length;
115    mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_SYNC;
116
117    // release the lock protecting MEMC
118    mmc_address[MEMC_LOCK] = 0;
119}
120
[297]121//////////////////////////////////////////////////////////////////////////////////
122// This ISR access the vci_mem_cache component to get the faulty physical
123// address and the associated SRCID. It must also acknowledge the IRQ.
124//
125// TODO implement...
126//////////////////////////////////////////////////////////////////////////////////
127void _mmc_isr( unsigned int irq_type,  // should be HWI
128               unsigned int irq_id,    // index returned by ICU
129               unsigned int channel )  // unused
130{
[298]131    unsigned int procid     = _get_procid();
132    unsigned int cluster_xy = procid / NB_PROCS_MAX;
133    unsigned int lpid       = procid % NB_PROCS_MAX;
134    unsigned int x          = cluster_xy >> Y_WIDTH;
135    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
136
137    _printf("[GIET ERROR] MMC IRQ received by processor[%d,%d,%d]"
138            " but _mmc_isr() not implemented...\n", x, y, lpid );
[297]139}
140
141
142
[258]143// Local Variables:
144// tab-width: 4
145// c-basic-offset: 4
146// c-file-offsets:((innamespace . 0)(inline-open . 0))
147// indent-tabs-mode: nil
148// End:
149// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
150
Note: See TracBrowser for help on using the repository browser.