[1] | 1 | /* |
---|
| 2 | * soclib_mmc.c - soclib simple block device driver implementation. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH.. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH. is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH. is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | #include <hal_types.h> |
---|
| 26 | #include <device.h> |
---|
| 27 | #include <dev_mmc.h> |
---|
| 28 | #include <soclib_mmc.h> |
---|
| 29 | #include <spinlock.h> |
---|
| 30 | #include <thread.h> |
---|
| 31 | #include <printk.h> |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | ///////////////////////////////////// |
---|
| 35 | void soclib_mmc_init( xptr_t dev_xp ) |
---|
| 36 | { |
---|
| 37 | // get local pointer on MMC device descriptor |
---|
| 38 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
| 39 | |
---|
| 40 | // get extended pointer on MMC peripheral from MMC device |
---|
| 41 | xptr_t mmc_xp = dev_ptr->base; |
---|
| 42 | |
---|
| 43 | // get local pointer on MMC segment base |
---|
| 44 | uint32_t * base = (uint32_t *)GET_PTR( mmc_xp ); |
---|
| 45 | |
---|
| 46 | // enable MMC IRQ |
---|
| 47 | *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_IRQ_ENABLE) = 1; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | ////////////////////////////////////////////////////////////////// |
---|
| 52 | void __attribute__ ((noinline)) soclib_mmc_command( xptr_t th_xp ) |
---|
| 53 | { |
---|
| 54 | xptr_t dev_xp; // extended pointer on MMC device |
---|
| 55 | uint32_t type; // MMC command : type |
---|
| 56 | uint64_t buf_paddr; // MMC command : buffer physical address |
---|
| 57 | uint32_t buf_size; // MMC command : buffer size |
---|
| 58 | uint32_t reg_index; // MMC command : register index in MMC peripheral |
---|
| 59 | uint32_t * reg_ptr; // MMC command : pointer on dst/src buffer in client cluster |
---|
| 60 | |
---|
| 61 | // get client thread cluster and local pointer |
---|
| 62 | cxy_t th_cxy = GET_CXY( th_xp ); |
---|
| 63 | thread_t * th_ptr = (thread_t *)GET_PTR( th_xp ); |
---|
| 64 | |
---|
| 65 | // get command type and extended pointer on MMC device |
---|
| 66 | type = hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.mmc.type ) ); |
---|
| 67 | dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.mmc.dev_xp ) ); |
---|
| 68 | |
---|
| 69 | // get MMC device cluster and local pointer |
---|
| 70 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
| 71 | device_t * dev_ptr = (device_t *)GET_PTR( dev_xp ); |
---|
| 72 | |
---|
| 73 | // get extended pointer on SOCLIB-MMC peripheral |
---|
| 74 | xptr_t mmc_xp = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
| 75 | |
---|
| 76 | // get SOCLIB_MMC peripheral cluster and local pointer |
---|
| 77 | cxy_t mmc_cxy = GET_CXY( mmc_xp ); |
---|
| 78 | uint32_t * mmc_ptr = (uint32_t *)GET_PTR( mmc_xp ); |
---|
| 79 | |
---|
| 80 | if( (type == MMC_CC_INVAL) || (type == MMC_CC_SYNC) ) |
---|
| 81 | { |
---|
| 82 | // get buffer paddr |
---|
| 83 | buf_paddr = hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.mmc.buf_paddr ) ); |
---|
| 84 | |
---|
| 85 | // split buffer paddr in two 32 bits words |
---|
| 86 | uint32_t buf_lo = (uint32_t)( buf_paddr ); |
---|
| 87 | uint32_t buf_hi = (uint32_t)( buf_paddr>>32 ); |
---|
| 88 | |
---|
| 89 | // get buffer size |
---|
| 90 | buf_size = hal_remote_lw( XPTR( th_cxy , &th_ptr->dev.mmc.buf_size ) ); |
---|
| 91 | |
---|
| 92 | // get command type |
---|
| 93 | uint32_t cc_cmd = MMC_CC_INVAL ? SOCLIB_MMC_CC_INVAL : SOCLIB_MMC_CC_SYNC; |
---|
| 94 | |
---|
| 95 | // set SOCLIB_MMC registers to start INVAL/SYNC operation |
---|
| 96 | hal_remote_sw( XPTR( mmc_cxy , mmc_ptr + SOCLIB_MMC_ADDR_LO ) , buf_lo ); |
---|
| 97 | hal_remote_sw( XPTR( mmc_cxy , mmc_ptr + SOCLIB_MMC_ADDR_HI ) , buf_hi ); |
---|
| 98 | hal_remote_sw( XPTR( mmc_cxy , mmc_ptr + SOCLIB_MMC_BUF_LENGTH ) , buf_size ); |
---|
| 99 | hal_remote_sw( XPTR( mmc_cxy , mmc_ptr + SOCLIB_MMC_CMD_TYPE ) , cc_cmd ); |
---|
| 100 | } |
---|
| 101 | else // (type == MMC_GET_ERROR) or (type == MMC_GET_ERROR) pr (type == MMC_GET_INSTRU ) |
---|
| 102 | { |
---|
| 103 | // get src/dst buffer local pointer and register index |
---|
| 104 | reg_ptr = (uint32_t *)hal_remote_lpt( XPTR( th_cxy , &th_ptr->dev.mmc.reg_ptr ) ); |
---|
| 105 | reg_index = hal_remote_lw( XPTR( th_cxy , &th_ptr->dev.mmc.reg_index ) ); |
---|
| 106 | |
---|
| 107 | // move register to/from local buffer |
---|
| 108 | if( (type == MMC_GET_ERROR) || (type == MMC_GET_INSTRU) ) |
---|
| 109 | { |
---|
| 110 | *reg_ptr = hal_remote_lw( XPTR( mmc_cxy , mmc_ptr + reg_index ) ); |
---|
| 111 | } |
---|
| 112 | else // type == MMC_SET_ERROR |
---|
| 113 | { |
---|
| 114 | hal_remote_sw( XPTR( mmc_cxy , mmc_ptr + reg_index ) , *reg_ptr ); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } // end soclib_mmc_cmd() |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | //////////////////////////////////////////////////////////////// |
---|
| 121 | void __attribute__ ((noinline)) soclib_mmc_isr( device_t * dev ) |
---|
| 122 | { |
---|
| 123 | // get extended pointer on MMC peripheral from MMC device |
---|
| 124 | xptr_t mmc_xp = dev->base; |
---|
| 125 | |
---|
| 126 | // get local pointer on MMC segment base |
---|
| 127 | uint32_t * base = (uint32_t *)GET_PTR( mmc_xp ); |
---|
| 128 | |
---|
| 129 | // get faulty ADDRESS and SRCID from MMC registers |
---|
| 130 | uint32_t paddr_lo = *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_ADDR_LO); |
---|
| 131 | uint32_t paddr_hi = *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_ADDR_HI); |
---|
| 132 | uint32_t srcid = *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_SRCID); |
---|
| 133 | |
---|
| 134 | paddr_t paddr = (((paddr_t)paddr_hi)<<32) + ((paddr_t)paddr_lo); |
---|
| 135 | |
---|
| 136 | // reset MMC IRQ |
---|
| 137 | *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_IRQ_RESET) = 0; |
---|
| 138 | |
---|
| 139 | // print an error message on kernel terminal TODO : should be improved |
---|
| 140 | printk("\n[ERROR] reported from MMC in cluster %x : faulty address = %l / srcid = %x\n", |
---|
| 141 | paddr , srcid ); |
---|
| 142 | |
---|
| 143 | } // end soclib_mmc_isr() |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|