18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (C) 2019  Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included
128c2ecf20Sopenharmony_ci * in all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
158c2ecf20Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
188c2ecf20Sopenharmony_ci * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
198c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci#ifndef __AMDGPU_UMC_H__
228c2ecf20Sopenharmony_ci#define __AMDGPU_UMC_H__
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * (addr / 256) * 4096, the higher 26 bits in ErrorAddr
268c2ecf20Sopenharmony_ci * is the index of 4KB block
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define ADDR_OF_4KB_BLOCK(addr)			(((addr) & ~0xffULL) << 4)
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * (addr / 256) * 8192, the higher 26 bits in ErrorAddr
318c2ecf20Sopenharmony_ci * is the index of 8KB block
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define ADDR_OF_8KB_BLOCK(addr)			(((addr) & ~0xffULL) << 5)
348c2ecf20Sopenharmony_ci/* channel index is the index of 256B block */
358c2ecf20Sopenharmony_ci#define ADDR_OF_256B_BLOCK(channel_index)	((channel_index) << 8)
368c2ecf20Sopenharmony_ci/* offset in 256B block */
378c2ecf20Sopenharmony_ci#define OFFSET_IN_256B_BLOCK(addr)		((addr) & 0xffULL)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define LOOP_UMC_INST(umc_inst) for ((umc_inst) = 0; (umc_inst) < adev->umc.umc_inst_num; (umc_inst)++)
408c2ecf20Sopenharmony_ci#define LOOP_UMC_CH_INST(ch_inst) for ((ch_inst) = 0; (ch_inst) < adev->umc.channel_inst_num; (ch_inst)++)
418c2ecf20Sopenharmony_ci#define LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) LOOP_UMC_INST((umc_inst)) LOOP_UMC_CH_INST((ch_inst))
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct amdgpu_umc_funcs {
448c2ecf20Sopenharmony_ci	void (*err_cnt_init)(struct amdgpu_device *adev);
458c2ecf20Sopenharmony_ci	int (*ras_late_init)(struct amdgpu_device *adev);
468c2ecf20Sopenharmony_ci	void (*query_ras_error_count)(struct amdgpu_device *adev,
478c2ecf20Sopenharmony_ci					void *ras_error_status);
488c2ecf20Sopenharmony_ci	void (*query_ras_error_address)(struct amdgpu_device *adev,
498c2ecf20Sopenharmony_ci					void *ras_error_status);
508c2ecf20Sopenharmony_ci	void (*init_registers)(struct amdgpu_device *adev);
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct amdgpu_umc {
548c2ecf20Sopenharmony_ci	/* max error count in one ras query call */
558c2ecf20Sopenharmony_ci	uint32_t max_ras_err_cnt_per_query;
568c2ecf20Sopenharmony_ci	/* number of umc channel instance with memory map register access */
578c2ecf20Sopenharmony_ci	uint32_t channel_inst_num;
588c2ecf20Sopenharmony_ci	/* number of umc instance with memory map register access */
598c2ecf20Sopenharmony_ci	uint32_t umc_inst_num;
608c2ecf20Sopenharmony_ci	/* UMC regiser per channel offset */
618c2ecf20Sopenharmony_ci	uint32_t channel_offs;
628c2ecf20Sopenharmony_ci	/* channel index table of interleaved memory */
638c2ecf20Sopenharmony_ci	const uint32_t *channel_idx_tbl;
648c2ecf20Sopenharmony_ci	struct ras_common_if *ras_if;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	const struct amdgpu_umc_funcs *funcs;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciint amdgpu_umc_ras_late_init(struct amdgpu_device *adev);
708c2ecf20Sopenharmony_civoid amdgpu_umc_ras_fini(struct amdgpu_device *adev);
718c2ecf20Sopenharmony_ciint amdgpu_umc_process_ras_data_cb(struct amdgpu_device *adev,
728c2ecf20Sopenharmony_ci		void *ras_error_status,
738c2ecf20Sopenharmony_ci		struct amdgpu_iv_entry *entry);
748c2ecf20Sopenharmony_ciint amdgpu_umc_process_ecc_irq(struct amdgpu_device *adev,
758c2ecf20Sopenharmony_ci		struct amdgpu_irq_src *source,
768c2ecf20Sopenharmony_ci		struct amdgpu_iv_entry *entry);
778c2ecf20Sopenharmony_ci#endif
78