[75] | 1 | /* |
---|
[626] | 2 | * soclib_mmc.c - soclib L2 cache driver implementation. |
---|
[75] | 3 | * |
---|
[657] | 4 | * Author Alain Greiner (2016,2017,2018,2019,2020) |
---|
[75] | 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 |
---|
[657] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[75] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[451] | 24 | #include <hal_kernel_types.h> |
---|
[75] | 25 | #include <chdev.h> |
---|
| 26 | #include <dev_mmc.h> |
---|
| 27 | #include <soclib_mmc.h> |
---|
| 28 | #include <thread.h> |
---|
| 29 | #include <printk.h> |
---|
| 30 | |
---|
| 31 | /////////////////////////////////////// |
---|
| 32 | void soclib_mmc_init( chdev_t * chdev ) |
---|
| 33 | { |
---|
| 34 | // get pointer on MMC segment base |
---|
| 35 | uint32_t * base = (uint32_t *)GET_PTR( chdev->base ); |
---|
| 36 | |
---|
[257] | 37 | // set driver specific fields in device descriptor |
---|
| 38 | chdev->cmd = &soclib_mmc_cmd; |
---|
| 39 | chdev->isr = &soclib_mmc_isr; |
---|
| 40 | |
---|
[75] | 41 | // enable MMC IRQ |
---|
| 42 | *(base + (SOCLIB_MMC_ERROR_FUNC << 7) + SOCLIB_MMC_ERROR_IRQ_ENABLE) = 1; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | ////////////////////////////////////////////////////////////// |
---|
| 46 | void __attribute__ ((noinline)) soclib_mmc_cmd( xptr_t th_xp ) |
---|
| 47 | { |
---|
| 48 | xptr_t dev_xp; // extended pointer on MMC device |
---|
| 49 | uint32_t type; // MMC command : type |
---|
[440] | 50 | void * buf_ptr; // MMC command : buffer pointer |
---|
[75] | 51 | uint32_t buf_size; // MMC command : buffer size |
---|
| 52 | uint32_t reg_index; // MMC command : register index in MMC peripheral |
---|
| 53 | uint32_t * reg_ptr; // MMC command : pointer on dst/src buffer in client cluster |
---|
| 54 | |
---|
| 55 | // get client thread cluster and local pointer |
---|
| 56 | cxy_t th_cxy = GET_CXY( th_xp ); |
---|
[440] | 57 | thread_t * th_ptr = GET_PTR( th_xp ); |
---|
[75] | 58 | |
---|
| 59 | // get command type and extended pointer on MMC device |
---|
[626] | 60 | type = hal_remote_l32( XPTR( th_cxy , &th_ptr->mmc_cmd.type ) ); |
---|
[570] | 61 | dev_xp = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->mmc_cmd.dev_xp ) ); |
---|
[75] | 62 | |
---|
| 63 | // get MMC device cluster and local pointer |
---|
| 64 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
[440] | 65 | chdev_t * dev_ptr = GET_PTR( dev_xp ); |
---|
[75] | 66 | |
---|
[440] | 67 | // get cluster and pointers for SOCLIB_MMC peripheral segment base |
---|
[570] | 68 | xptr_t seg_xp = (xptr_t)hal_remote_l64( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
[440] | 69 | cxy_t seg_cxy = GET_CXY( seg_xp ); |
---|
| 70 | uint32_t * seg_ptr = GET_PTR( seg_xp ); |
---|
[75] | 71 | |
---|
| 72 | if( (type == MMC_CC_INVAL) || (type == MMC_CC_SYNC) ) |
---|
| 73 | { |
---|
[440] | 74 | // get buffer pointer and size |
---|
| 75 | buf_ptr = hal_remote_lpt( XPTR( th_cxy , &th_ptr->mmc_cmd.buf_ptr ) ); |
---|
[570] | 76 | buf_size = hal_remote_l32 ( XPTR( th_cxy , &th_ptr->mmc_cmd.buf_size ) ); |
---|
[75] | 77 | |
---|
[440] | 78 | // set command type |
---|
| 79 | uint32_t cc_cmd; |
---|
[75] | 80 | if( type == MMC_CC_INVAL ) cc_cmd = SOCLIB_MMC_CC_INVAL; |
---|
| 81 | else cc_cmd = SOCLIB_MMC_CC_SYNC; |
---|
| 82 | |
---|
| 83 | // set SOCLIB_MMC registers to start INVAL/SYNC operation |
---|
[657] | 84 | hal_remote_s32( XPTR( seg_cxy , seg_ptr + |
---|
| 85 | MMC_REG( SOCLIB_MMC_CC_FUNC , SOCLIB_MMC_ADDR_LO) ) , (uint32_t)buf_ptr ); |
---|
| 86 | |
---|
| 87 | hal_remote_s32( XPTR( seg_cxy , seg_ptr + |
---|
| 88 | MMC_REG( SOCLIB_MMC_CC_FUNC , SOCLIB_MMC_ADDR_HI) ) , dev_cxy ); |
---|
| 89 | |
---|
| 90 | hal_remote_s32( XPTR( seg_cxy , seg_ptr + |
---|
| 91 | MMC_REG( SOCLIB_MMC_CC_FUNC , SOCLIB_MMC_BUF_LENGTH) ) , buf_size ); |
---|
| 92 | |
---|
| 93 | hal_remote_s32( XPTR( seg_cxy , seg_ptr + |
---|
| 94 | MMC_REG( SOCLIB_MMC_CC_FUNC , SOCLIB_MMC_CMD_TYPE) ) , cc_cmd ); |
---|
[75] | 95 | } |
---|
[657] | 96 | else if( (type == MMC_ERROR_GET) || (type == MMC_ERROR_SET) ) |
---|
[75] | 97 | { |
---|
| 98 | // get src/dst buffer local pointer and register index |
---|
[279] | 99 | reg_ptr = (uint32_t *)hal_remote_lpt( XPTR( th_cxy , &th_ptr->mmc_cmd.reg_ptr ) ); |
---|
[657] | 100 | reg_index = hal_remote_l32( XPTR( th_cxy , &th_ptr->mmc_cmd.reg_index ) ); |
---|
[75] | 101 | |
---|
[657] | 102 | // build extended pointer on relevant MMC register |
---|
| 103 | xptr_t mmc_reg_xp = XPTR( seg_cxy , seg_ptr + |
---|
| 104 | MMC_REG( SOCLIB_MMC_ERROR_FUNC , reg_index ) ); |
---|
| 105 | |
---|
| 106 | // move MMC register to/from local buffer |
---|
| 107 | if( type == MMC_ERROR_GET ) *reg_ptr = hal_remote_l32( mmc_reg_xp ); |
---|
| 108 | else hal_remote_s32( mmc_reg_xp , *reg_ptr ); |
---|
[75] | 109 | } |
---|
[657] | 110 | else // type == MMC_INSTRU_GET |
---|
| 111 | { |
---|
| 112 | // get dst buffer local pointer and register index |
---|
| 113 | reg_ptr = (uint32_t *)hal_remote_lpt( XPTR( th_cxy , &th_ptr->mmc_cmd.reg_ptr ) ); |
---|
| 114 | reg_index = hal_remote_l32( XPTR( th_cxy , &th_ptr->mmc_cmd.reg_index ) ); |
---|
| 115 | |
---|
| 116 | // build extended pointer on relevant MMC register |
---|
| 117 | xptr_t mmc_reg_xp = XPTR( seg_cxy , seg_ptr + |
---|
| 118 | MMC_REG( SOCLIB_MMC_INSTR_FUNC , reg_index ) ); |
---|
| 119 | |
---|
| 120 | // move MMC register to local buffer |
---|
| 121 | *reg_ptr = hal_remote_l32( mmc_reg_xp ); |
---|
| 122 | } |
---|
| 123 | |
---|
[75] | 124 | } // end soclib_mmc_cmd() |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | //////////////////////////////////////////////////////////////// |
---|
| 128 | void __attribute__ ((noinline)) soclib_mmc_isr( chdev_t * chdev ) |
---|
| 129 | { |
---|
| 130 | // get pointer on MMC segment base |
---|
| 131 | uint32_t * base = (uint32_t *)GET_PTR( chdev->base ); |
---|
| 132 | |
---|
| 133 | // get faulty ADDRESS and SRCID from MMC registers |
---|
[654] | 134 | uint32_t paddr_lo = *(base + MMC_REG( SOCLIB_MMC_ERROR_FUNC , SOCLIB_MMC_ERROR_ADDR_LO ) ); |
---|
| 135 | uint32_t paddr_hi = *(base + MMC_REG( SOCLIB_MMC_ERROR_FUNC , SOCLIB_MMC_ERROR_ADDR_HI ) ); |
---|
| 136 | uint32_t srcid = *(base + MMC_REG( SOCLIB_MMC_ERROR_FUNC , SOCLIB_MMC_ERROR_SRCID ) ); |
---|
[75] | 137 | |
---|
[654] | 138 | // print an error message on kernel terminal |
---|
[657] | 139 | printk("\n[ERROR] reported from MMC : bad address [%x,%x] / srcid %x / cycle %d\n", |
---|
| 140 | paddr_hi , paddr_lo , srcid , (uint32_t)hal_get_cycles() ); |
---|
[654] | 141 | |
---|
[75] | 142 | // reset MMC IRQ |
---|
[654] | 143 | *(base + MMC_REG(SOCLIB_MMC_ERROR_FUNC , SOCLIB_MMC_ERROR_IRQ_RESET) ) = 0; |
---|
[75] | 144 | |
---|
| 145 | } // end soclib_mmc_isr() |
---|