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

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

Cosmetic

File size: 5.5 KB
Line 
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.
12//
13// The (virtual) base address of the associated segment is:
14//       SEG_MMC_BASE + cluster_id * PERI_CLUSTER_INCREMENT
15//
16// SEG_MMC_BASE and PERI_CLUSTER_INCREMENT must be defined in hard_config.h.
17////////////////////////////////////////////////////////////////////////////////
18
19#include <giet_config.h>
20#include <mmc_driver.h>
21#include <tty_driver.h>
22#include <utils.h>
23
24#if !defined(X_SIZE)
25# error: You must define X_SIZE in the hard_config.h file
26#endif
27
28#if !defined(Y_SIZE)
29# error: You must define X_SIZE in the hard_config.h file
30#endif
31
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
40#if !defined(SEG_MMC_BASE)
41# error: You must define SEG_MMC_BASE in the hard_config.h file
42#endif
43
44#if !defined(PERI_CLUSTER_INCREMENT)
45# error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file
46#endif
47
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///////////////////////////////////////////////////////////////////////////////////
53void _mmc_inval( paddr_t      buf_paddr,
54                 unsigned int buf_length )
55{
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);
60
61    // parameters checking
62    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
63    {
64        _printf("\n[GIET ERROR] in _memc_inval() : illegal cluster_xy for paddr %l\n",
65                 buf_paddr );
66        _exit();
67    }
68
69    unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE + 
70                                (cluster_xy * PERI_CLUSTER_INCREMENT) );
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///////////////////////////////////////////////////////////////////////////////////
89void _mmc_sync( paddr_t      buf_paddr,
90                unsigned int buf_length )
91{
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);
96
97    // parameters checking
98    if ( (x >= X_SIZE) || (y >= Y_SIZE) )
99    {
100        _printf( "\n[GIET ERROR] in _memc_sync() : illegal cluster_xy for paddr %l\n",
101                 buf_paddr );
102        _exit();
103    }
104
105    unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE + 
106                                (cluster_xy * PERI_CLUSTER_INCREMENT) );
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
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{
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 );
139}
140
141
142
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.