19e585a52SHawking Zhang /* 29e585a52SHawking Zhang * Copyright (C) 2019 Advanced Micro Devices, Inc. 39e585a52SHawking Zhang * 49e585a52SHawking Zhang * Permission is hereby granted, free of charge, to any person obtaining a 59e585a52SHawking Zhang * copy of this software and associated documentation files (the "Software"), 69e585a52SHawking Zhang * to deal in the Software without restriction, including without limitation 79e585a52SHawking Zhang * the rights to use, copy, modify, merge, publish, distribute, sublicense, 89e585a52SHawking Zhang * and/or sell copies of the Software, and to permit persons to whom the 99e585a52SHawking Zhang * Software is furnished to do so, subject to the following conditions: 109e585a52SHawking Zhang * 119e585a52SHawking Zhang * The above copyright notice and this permission notice shall be included 129e585a52SHawking Zhang * in all copies or substantial portions of the Software. 139e585a52SHawking Zhang * 149e585a52SHawking Zhang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 159e585a52SHawking Zhang * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 169e585a52SHawking Zhang * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 179e585a52SHawking Zhang * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 189e585a52SHawking Zhang * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 199e585a52SHawking Zhang * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 209e585a52SHawking Zhang */ 219e585a52SHawking Zhang #ifndef __AMDGPU_UMC_H__ 229e585a52SHawking Zhang #define __AMDGPU_UMC_H__ 23efe17d5aSyipechai #include "amdgpu_ras.h" 249e585a52SHawking Zhang 25c5a4ef3eSJohn Clements /* 266ec598ccSStanley.Yang * (addr / 256) * 4096, the higher 26 bits in ErrorAddr 276ec598ccSStanley.Yang * is the index of 4KB block 286ec598ccSStanley.Yang */ 296ec598ccSStanley.Yang #define ADDR_OF_4KB_BLOCK(addr) (((addr) & ~0xffULL) << 4) 306ec598ccSStanley.Yang /* 31c5a4ef3eSJohn Clements * (addr / 256) * 8192, the higher 26 bits in ErrorAddr 32c5a4ef3eSJohn Clements * is the index of 8KB block 33c5a4ef3eSJohn Clements */ 34c5a4ef3eSJohn Clements #define ADDR_OF_8KB_BLOCK(addr) (((addr) & ~0xffULL) << 5) 35c5a4ef3eSJohn Clements /* channel index is the index of 256B block */ 36c5a4ef3eSJohn Clements #define ADDR_OF_256B_BLOCK(channel_index) ((channel_index) << 8) 37c5a4ef3eSJohn Clements /* offset in 256B block */ 38c5a4ef3eSJohn Clements #define OFFSET_IN_256B_BLOCK(addr) ((addr) & 0xffULL) 39c5a4ef3eSJohn Clements 40c5a4ef3eSJohn Clements #define LOOP_UMC_INST(umc_inst) for ((umc_inst) = 0; (umc_inst) < adev->umc.umc_inst_num; (umc_inst)++) 41c5a4ef3eSJohn Clements #define LOOP_UMC_CH_INST(ch_inst) for ((ch_inst) = 0; (ch_inst) < adev->umc.channel_inst_num; (ch_inst)++) 42c5a4ef3eSJohn Clements #define LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) LOOP_UMC_INST((umc_inst)) LOOP_UMC_CH_INST((ch_inst)) 43c5a4ef3eSJohn Clements 44e4b1edf4SYiPeng Chai #define LOOP_UMC_NODE_INST(node_inst) \ 452b595659SCandice Li for_each_set_bit((node_inst), &(adev->umc.active_mask), adev->umc.node_inst_num) 46e4b1edf4SYiPeng Chai 47e4b1edf4SYiPeng Chai #define LOOP_UMC_EACH_NODE_INST_AND_CH(node_inst, umc_inst, ch_inst) \ 48e4b1edf4SYiPeng Chai LOOP_UMC_NODE_INST((node_inst)) LOOP_UMC_INST_AND_CH((umc_inst), (ch_inst)) 49e4b1edf4SYiPeng Chai 50*e86bd8b2SYiPeng Chai 51*e86bd8b2SYiPeng Chai typedef int (*umc_func)(struct amdgpu_device *adev, uint32_t node_inst, 52*e86bd8b2SYiPeng Chai uint32_t umc_inst, uint32_t ch_inst, void *data); 53*e86bd8b2SYiPeng Chai 54efe17d5aSyipechai struct amdgpu_umc_ras { 55efe17d5aSyipechai struct amdgpu_ras_block_object ras_block; 56d99659a0STao Zhou void (*err_cnt_init)(struct amdgpu_device *adev); 57aaca8c38STao Zhou bool (*query_ras_poison_mode)(struct amdgpu_device *adev); 588882f90aSStanley.Yang void (*ecc_info_query_ras_error_count)(struct amdgpu_device *adev, 598882f90aSStanley.Yang void *ras_error_status); 608882f90aSStanley.Yang void (*ecc_info_query_ras_error_address)(struct amdgpu_device *adev, 618882f90aSStanley.Yang void *ras_error_status); 6249070c4eSHawking Zhang /* support different eeprom table version for different asic */ 6349070c4eSHawking Zhang void (*set_eeprom_table_version)(struct amdgpu_ras_eeprom_table_header *hdr); 6449070c4eSHawking Zhang }; 65e7da754bSMonk Liu 669e585a52SHawking Zhang struct amdgpu_umc_funcs { 679e585a52SHawking Zhang void (*init_registers)(struct amdgpu_device *adev); 68045c0216STao Zhou }; 69045c0216STao Zhou 70045c0216STao Zhou struct amdgpu_umc { 7133b97cf8STao Zhou /* max error count in one ras query call */ 7233b97cf8STao Zhou uint32_t max_ras_err_cnt_per_query; 7333b97cf8STao Zhou /* number of umc channel instance with memory map register access */ 7433b97cf8STao Zhou uint32_t channel_inst_num; 75e4b1edf4SYiPeng Chai /* number of umc instance with memory map register access */ 762b595659SCandice Li uint32_t umc_inst_num; 77e4b1edf4SYiPeng Chai 78e4b1edf4SYiPeng Chai /* Total number of umc node instance including harvest one */ 7933b97cf8STao Zhou uint32_t node_inst_num; 8033b97cf8STao Zhou 81e69c7857STao Zhou /* UMC regiser per channel offset */ 82e69c7857STao Zhou uint32_t channel_offs; 8333b97cf8STao Zhou /* how many pages are retired in one UE */ 8433b97cf8STao Zhou uint32_t retire_unit; 8503740baaSTao Zhou /* channel index table of interleaved memory */ 8633b97cf8STao Zhou const uint32_t *channel_idx_tbl; 87045c0216STao Zhou struct ras_common_if *ras_if; 88efe17d5aSyipechai 892b595659SCandice Li const struct amdgpu_umc_funcs *funcs; 902b595659SCandice Li struct amdgpu_umc_ras *ras; 912b595659SCandice Li 92045c0216STao Zhou /* active mask for umc node instance */ 93045c0216STao Zhou unsigned long active_mask; 94a6dcf9a7SHawking Zhang }; 954e9b1fa5Syipechai 961ed0e176STao Zhou int amdgpu_umc_ras_sw_init(struct amdgpu_device *adev); 9734cc4fd9STao Zhou int amdgpu_umc_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block); 9834cc4fd9STao Zhou int amdgpu_umc_poison_handler(struct amdgpu_device *adev, bool reset); 9934cc4fd9STao Zhou int amdgpu_umc_process_ecc_irq(struct amdgpu_device *adev, 100400013b2STao Zhou struct amdgpu_irq_src *source, 101400013b2STao Zhou struct amdgpu_iv_entry *entry); 102400013b2STao Zhou void amdgpu_umc_fill_error_record(struct ras_err_data *err_data, 103400013b2STao Zhou uint64_t err_addr, 104400013b2STao Zhou uint64_t retired_page, 105a3ace75cSyipechai uint32_t channel_index, 106a3ace75cSyipechai uint32_t umc_inst); 107a3ace75cSyipechai 108a3ace75cSyipechai int amdgpu_umc_process_ras_data_cb(struct amdgpu_device *adev, 109cbe4d43eSTao Zhou void *ras_error_status, 110cbe4d43eSTao Zhou struct amdgpu_iv_entry *entry); 111*e86bd8b2SYiPeng Chai int amdgpu_umc_page_retirement_mca(struct amdgpu_device *adev, 112*e86bd8b2SYiPeng Chai uint64_t err_addr, uint32_t ch_inst, uint32_t umc_inst); 113*e86bd8b2SYiPeng Chai 1149e585a52SHawking Zhang int amdgpu_umc_loop_channels(struct amdgpu_device *adev, 115 umc_func func, void *data); 116 #endif 117