[258] | 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> |
---|
[456] | 10 | #include <tty0.h> |
---|
[258] | 11 | #include <utils.h> |
---|
[345] | 12 | #include <io.h> |
---|
[258] | 13 | |
---|
[263] | 14 | #if !defined(X_SIZE) |
---|
| 15 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 16 | #endif |
---|
| 17 | |
---|
[263] | 18 | #if !defined(Y_SIZE) |
---|
| 19 | # error: You must define X_SIZE in the hard_config.h file |
---|
[258] | 20 | #endif |
---|
| 21 | |
---|
[263] | 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 | |
---|
[320] | 30 | #if !defined(SEG_MMC_BASE) |
---|
| 31 | # error: You must define SEG_MMC_BASE in the hard_config.h file |
---|
| 32 | #endif |
---|
| 33 | |
---|
[333] | 34 | #if !defined(PERI_CLUSTER_INCREMENT) |
---|
| 35 | # error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file |
---|
[320] | 36 | #endif |
---|
| 37 | |
---|
[345] | 38 | /////////////////////////////////////////////////////////////////////////////// |
---|
[456] | 39 | // This low level function returns the value contained in register |
---|
| 40 | // defined by the ("func" / "index") arguments, |
---|
[345] | 41 | // in the MMC component contained in cluster "cluster_xy" |
---|
| 42 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 43 | static |
---|
| 44 | unsigned int _mmc_get_register( unsigned int cluster_xy, // cluster index |
---|
| 45 | unsigned int func, // function index |
---|
| 46 | unsigned int index ) // register index |
---|
| 47 | { |
---|
| 48 | unsigned int vaddr = |
---|
| 49 | SEG_MMC_BASE + |
---|
| 50 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 51 | (MMC_REG(func, index) << 2); |
---|
| 52 | |
---|
| 53 | return ioread32( (void*)vaddr ); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /////////////////////////////////////////////////////////////////////////////// |
---|
[456] | 57 | // This low level function sets a new value in register |
---|
| 58 | // defined by the ("func" / "index") arguments, |
---|
[345] | 59 | // in the MMC component contained in cluster "cluster_xy" |
---|
| 60 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 61 | static |
---|
| 62 | void _mmc_set_register( unsigned int cluster_xy, // cluster index |
---|
| 63 | unsigned int func, // func index |
---|
| 64 | unsigned int index, // register index |
---|
| 65 | unsigned int value ) // value to be written |
---|
| 66 | { |
---|
| 67 | unsigned int vaddr = |
---|
| 68 | SEG_MMC_BASE + |
---|
| 69 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
| 70 | (MMC_REG(func, index) << 2); |
---|
| 71 | |
---|
| 72 | iowrite32( (void*)vaddr, value ); |
---|
| 73 | } |
---|
| 74 | |
---|
[437] | 75 | ///////////////////////////////////////// |
---|
[297] | 76 | void _mmc_inval( paddr_t buf_paddr, |
---|
| 77 | unsigned int buf_length ) |
---|
[258] | 78 | { |
---|
[263] | 79 | // compute cluster coordinates |
---|
| 80 | unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH)); |
---|
| 81 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 82 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[258] | 83 | |
---|
[263] | 84 | // parameters checking |
---|
| 85 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
| 86 | { |
---|
[437] | 87 | _puts("\n[GIET ERROR] in _memc_inval() : illegal cluster coordinates\n"); |
---|
[263] | 88 | _exit(); |
---|
| 89 | } |
---|
| 90 | |
---|
[258] | 91 | // get the hard lock protecting exclusive access to MEMC |
---|
[345] | 92 | while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) ); |
---|
[258] | 93 | |
---|
| 94 | // write inval arguments |
---|
[345] | 95 | _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO , (unsigned int)buf_paddr); |
---|
| 96 | _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI , (unsigned int)(buf_paddr>>32)); |
---|
| 97 | _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length); |
---|
| 98 | _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE , MEMC_CMD_INVAL); |
---|
[258] | 99 | |
---|
| 100 | // release the lock |
---|
[345] | 101 | _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0); |
---|
[258] | 102 | } |
---|
[437] | 103 | |
---|
| 104 | /////////////////////////////////////// |
---|
[297] | 105 | void _mmc_sync( paddr_t buf_paddr, |
---|
| 106 | unsigned int buf_length ) |
---|
[258] | 107 | { |
---|
[263] | 108 | // compute cluster coordinates |
---|
| 109 | unsigned int cluster_xy = (unsigned int)(buf_paddr>>(40-X_WIDTH-Y_WIDTH)); |
---|
| 110 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 111 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[258] | 112 | |
---|
[263] | 113 | // parameters checking |
---|
| 114 | if ( (x >= X_SIZE) || (y >= Y_SIZE) ) |
---|
| 115 | { |
---|
[437] | 116 | _puts( "\n[GIET ERROR] in _memc_sync() : illegal cluster coordinates"); |
---|
[263] | 117 | _exit(); |
---|
| 118 | } |
---|
| 119 | |
---|
[258] | 120 | // get the hard lock protecting exclusive access to MEMC |
---|
[345] | 121 | while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) ); |
---|
[258] | 122 | |
---|
| 123 | // write inval arguments |
---|
[345] | 124 | _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO , (unsigned int)buf_paddr); |
---|
| 125 | _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI , (unsigned int)(buf_paddr>>32)); |
---|
| 126 | _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length); |
---|
| 127 | _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE , MEMC_CMD_SYNC); |
---|
[258] | 128 | |
---|
[345] | 129 | // release the lock |
---|
| 130 | _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0); |
---|
[258] | 131 | } |
---|
| 132 | |
---|
[437] | 133 | /////////////////////////////////////////////////////// |
---|
[297] | 134 | void _mmc_isr( unsigned int irq_type, // should be HWI |
---|
| 135 | unsigned int irq_id, // index returned by ICU |
---|
| 136 | unsigned int channel ) // unused |
---|
| 137 | { |
---|
[426] | 138 | unsigned int gpid = _get_procid(); |
---|
| 139 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
[298] | 140 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 141 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
[437] | 142 | unsigned int p = gpid & ((1<<P_WIDTH)-1); |
---|
[298] | 143 | |
---|
[437] | 144 | _puts("[GIET ERROR] MMC IRQ received by processor["); |
---|
| 145 | _putd( x ); |
---|
| 146 | _puts(","); |
---|
| 147 | _putd( y ); |
---|
| 148 | _puts(","); |
---|
| 149 | _putd( p ); |
---|
| 150 | _puts("] but _mmc_isr() not implemented\n"); |
---|
[297] | 151 | } |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | |
---|
[258] | 155 | // Local Variables: |
---|
| 156 | // tab-width: 4 |
---|
| 157 | // c-basic-offset: 4 |
---|
| 158 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 159 | // indent-tabs-mode: nil |
---|
| 160 | // End: |
---|
| 161 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 162 | |
---|