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

Last change on this file since 262 was 258, checked in by alain, 11 years ago

This is a major release, including a deep restructuration of code.
The main evolutions are

  • use of the Tsar preloader to load the GIET boot-loader from disk
  • introduction of a FAT32 file system library,
  • use of this fat32 library by the boot-loader to load the map.bin data structure, and the various .elf files
  • reorganisation of drivers (one file per peripheral).
  • introduction of drivers for new peripherals: vci_chbuf_dma and vci_multi_ahci.
  • introduction of a new physical memory allocator in the boot code.

This release has been tested on the tsar_generic_iob architecture,
for the two following mappings: 4c_1p_iob_four.xml and 4c_1p_iob_sort.xml

File size: 3.7 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.
12///////////////////////////////////////////////////////////////////////////////////
13// The (virtual) base address of the associated segment is:
14//
15//       seg_mmc_base + cluster_id * vseg_cluster_increment
16//
17// The seg_mmc_base and vseg_cluster_increment values must be defined
18// in the giet_vsegs.ld file.
19////////////////////////////////////////////////////////////////////////////////
20
21#include <giet_config.h>
22#include <mmc_driver.h>
23#include <utils.h>
24
25#if !defined(NB_CLUSTERS)
26# error: You must define NB_CLUSTERS in the hard_config.h file
27#endif
28
29#if (NB_CLUSTERS > 256)
30# error: NB_CLUSTERS cannot be larger than 256!
31#endif
32
33///////////////////////////////////////////////////////////////////////////////////
34// _memc_inval()
35// This function invalidates all cache lines covering a memory buffer defined
36// by the physical base address, and the length.
37// The buffer address MSB are used to compute the cluster index.
38///////////////////////////////////////////////////////////////////////////////////
39void _memc_inval( paddr_t      buf_paddr,
40                  unsigned int buf_length )
41{
42    unsigned int cluster_id    = (unsigned int)((buf_paddr>>32)/(256/NB_CLUSTERS));
43
44    unsigned int* mmc_address = (unsigned int*)((unsigned int)&seg_mmc_base + 
45                                (cluster_id * (unsigned int)&vseg_cluster_increment));
46
47    // get the hard lock protecting exclusive access to MEMC
48    while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
49
50    // write inval arguments
51    mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
52    mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
53    mmc_address[MEMC_BUF_LENGTH] = buf_length;
54    mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_INVAL;
55
56    // release the lock
57    mmc_address[MEMC_LOCK] = 0;
58}
59///////////////////////////////////////////////////////////////////////////////////
60// _memc_sync()
61// This function copies to external RAM all cache lines covering a memory buffer
62// defined by the physical base address, and the length, if they are dirty.
63// The buffer address MSB are used to compute the cluster index.
64///////////////////////////////////////////////////////////////////////////////////
65void _memc_sync( paddr_t      buf_paddr,
66                 unsigned int buf_length )
67{
68    unsigned int cluster_id    = (unsigned int)((buf_paddr>>32)/(256/NB_CLUSTERS));
69
70    unsigned int * mmc_address = (unsigned int *) ((unsigned int)&seg_mmc_base + 
71                                 (cluster_id * (unsigned int)&vseg_cluster_increment));
72
73    // get the hard lock protecting exclusive access to MEMC
74    while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
75
76    // write inval arguments
77    mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
78    mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
79    mmc_address[MEMC_BUF_LENGTH] = buf_length;
80    mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_SYNC;
81
82    // release the lock protecting MEMC
83    mmc_address[MEMC_LOCK] = 0;
84}
85
86// Local Variables:
87// tab-width: 4
88// c-basic-offset: 4
89// c-file-offsets:((innamespace . 0)(inline-open . 0))
90// indent-tabs-mode: nil
91// End:
92// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
93
Note: See TracBrowser for help on using the repository browser.