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 <tty_driver.h> |
---|
24 | #include <utils.h> |
---|
25 | |
---|
26 | #if !defined(X_SIZE) |
---|
27 | # error: You must define X_SIZE in the hard_config.h file |
---|
28 | #endif |
---|
29 | |
---|
30 | #if !defined(Y_SIZE) |
---|
31 | # error: You must define X_SIZE in the hard_config.h file |
---|
32 | #endif |
---|
33 | |
---|
34 | #if !defined(X_WIDTH) |
---|
35 | # error: You must define X_WIDTH in the hard_config.h file |
---|
36 | #endif |
---|
37 | |
---|
38 | #if !defined(Y_WIDTH) |
---|
39 | # error: You must define X_WIDTH in the hard_config.h file |
---|
40 | #endif |
---|
41 | |
---|
42 | /////////////////////////////////////////////////////////////////////////////////// |
---|
43 | // _memc_inval() |
---|
44 | // This function invalidates all cache lines covering a memory buffer defined |
---|
45 | // by the physical base address, and the length. |
---|
46 | // The buffer address MSB are used to compute the cluster index. |
---|
47 | /////////////////////////////////////////////////////////////////////////////////// |
---|
48 | void _memc_inval( paddr_t buf_paddr, |
---|
49 | unsigned int buf_length ) |
---|
50 | { |
---|
51 | // compute cluster coordinates |
---|
52 | unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH)); |
---|
53 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
54 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
55 | |
---|
56 | // parameters checking |
---|
57 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
58 | { |
---|
59 | _printf("\n[GIET ERROR] in _memc_inval() : illegal cluster_xy for paddr %l\n", |
---|
60 | buf_paddr ); |
---|
61 | _exit(); |
---|
62 | } |
---|
63 | |
---|
64 | unsigned int* mmc_address = (unsigned int*)((unsigned int)&seg_mmc_base + |
---|
65 | (cluster_xy * (unsigned int)&vseg_cluster_increment)); |
---|
66 | |
---|
67 | // get the hard lock protecting exclusive access to MEMC |
---|
68 | while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); } |
---|
69 | |
---|
70 | // write inval arguments |
---|
71 | mmc_address[MEMC_ADDR_LO] = (unsigned int)buf_paddr; |
---|
72 | mmc_address[MEMC_ADDR_HI] = (unsigned int)(buf_paddr>>32); |
---|
73 | mmc_address[MEMC_BUF_LENGTH] = buf_length; |
---|
74 | mmc_address[MEMC_CMD_TYPE] = MEMC_CMD_INVAL; |
---|
75 | |
---|
76 | // release the lock |
---|
77 | mmc_address[MEMC_LOCK] = 0; |
---|
78 | } |
---|
79 | /////////////////////////////////////////////////////////////////////////////////// |
---|
80 | // _memc_sync() |
---|
81 | // This function copies to external RAM all cache lines covering a memory buffer |
---|
82 | // defined by the physical base address, and the length, if they are dirty. |
---|
83 | // The buffer address MSB are used to compute the cluster index. |
---|
84 | /////////////////////////////////////////////////////////////////////////////////// |
---|
85 | void _memc_sync( paddr_t buf_paddr, |
---|
86 | unsigned int buf_length ) |
---|
87 | { |
---|
88 | // compute cluster coordinates |
---|
89 | unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH)); |
---|
90 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
91 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
92 | |
---|
93 | // parameters checking |
---|
94 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
95 | { |
---|
96 | _printf( "\n[GIET ERROR] in _memc_sync() : illegal cluster_xy for paddr %l\n", |
---|
97 | buf_paddr ); |
---|
98 | _exit(); |
---|
99 | } |
---|
100 | |
---|
101 | unsigned int * mmc_address = (unsigned int *) ((unsigned int)&seg_mmc_base + |
---|
102 | (cluster_xy * (unsigned int)&vseg_cluster_increment)); |
---|
103 | |
---|
104 | // get the hard lock protecting exclusive access to MEMC |
---|
105 | while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); } |
---|
106 | |
---|
107 | // write inval arguments |
---|
108 | mmc_address[MEMC_ADDR_LO] = (unsigned int)buf_paddr; |
---|
109 | mmc_address[MEMC_ADDR_HI] = (unsigned int)(buf_paddr>>32); |
---|
110 | mmc_address[MEMC_BUF_LENGTH] = buf_length; |
---|
111 | mmc_address[MEMC_CMD_TYPE] = MEMC_CMD_SYNC; |
---|
112 | |
---|
113 | // release the lock protecting MEMC |
---|
114 | mmc_address[MEMC_LOCK] = 0; |
---|
115 | } |
---|
116 | |
---|
117 | // Local Variables: |
---|
118 | // tab-width: 4 |
---|
119 | // c-basic-offset: 4 |
---|
120 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
121 | // indent-tabs-mode: nil |
---|
122 | // End: |
---|
123 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
124 | |
---|