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> |
---|
10 | #include <tty_driver.h> |
---|
11 | #include <utils.h> |
---|
12 | #include <io.h> |
---|
13 | |
---|
14 | #if !defined(X_SIZE) |
---|
15 | # error: You must define X_SIZE in the hard_config.h file |
---|
16 | #endif |
---|
17 | |
---|
18 | #if !defined(Y_SIZE) |
---|
19 | # error: You must define X_SIZE in the hard_config.h file |
---|
20 | #endif |
---|
21 | |
---|
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 | |
---|
30 | #if !defined(SEG_MMC_BASE) |
---|
31 | # error: You must define SEG_MMC_BASE in the hard_config.h file |
---|
32 | #endif |
---|
33 | |
---|
34 | #if !defined(PERI_CLUSTER_INCREMENT) |
---|
35 | # error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file |
---|
36 | #endif |
---|
37 | |
---|
38 | /////////////////////////////////////////////////////////////////////////////// |
---|
39 | // This low level function returns the value contained in register "index" |
---|
40 | // in the MMC component contained in cluster "cluster_xy" |
---|
41 | /////////////////////////////////////////////////////////////////////////////// |
---|
42 | static |
---|
43 | unsigned 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 | /////////////////////////////////////////////////////////////////////////////// |
---|
59 | static |
---|
60 | void _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 | |
---|
73 | ///////////////////////////////////////// |
---|
74 | void _mmc_inval( paddr_t buf_paddr, |
---|
75 | unsigned int buf_length ) |
---|
76 | { |
---|
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); |
---|
81 | |
---|
82 | // parameters checking |
---|
83 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
84 | { |
---|
85 | _puts("\n[GIET ERROR] in _memc_inval() : illegal cluster coordinates\n"); |
---|
86 | _exit(); |
---|
87 | } |
---|
88 | |
---|
89 | // get the hard lock protecting exclusive access to MEMC |
---|
90 | while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) ); |
---|
91 | |
---|
92 | // write inval arguments |
---|
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); |
---|
97 | |
---|
98 | // release the lock |
---|
99 | _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0); |
---|
100 | } |
---|
101 | |
---|
102 | /////////////////////////////////////// |
---|
103 | void _mmc_sync( paddr_t buf_paddr, |
---|
104 | unsigned int buf_length ) |
---|
105 | { |
---|
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); |
---|
110 | |
---|
111 | // parameters checking |
---|
112 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
113 | { |
---|
114 | _puts( "\n[GIET ERROR] in _memc_sync() : illegal cluster coordinates"); |
---|
115 | _exit(); |
---|
116 | } |
---|
117 | |
---|
118 | // get the hard lock protecting exclusive access to MEMC |
---|
119 | while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) ); |
---|
120 | |
---|
121 | // write inval arguments |
---|
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); |
---|
126 | |
---|
127 | // release the lock |
---|
128 | _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0); |
---|
129 | } |
---|
130 | |
---|
131 | /////////////////////////////////////////////////////// |
---|
132 | void _mmc_isr( unsigned int irq_type, // should be HWI |
---|
133 | unsigned int irq_id, // index returned by ICU |
---|
134 | unsigned int channel ) // unused |
---|
135 | { |
---|
136 | unsigned int gpid = _get_procid(); |
---|
137 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
138 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
139 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
140 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
141 | |
---|
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"); |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | |
---|
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 | |
---|