18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2014 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 in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * 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) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#ifndef __AMDGPU_IRQ_H__ 258c2ecf20Sopenharmony_ci#define __AMDGPU_IRQ_H__ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <linux/irqdomain.h> 288c2ecf20Sopenharmony_ci#include "soc15_ih_clientid.h" 298c2ecf20Sopenharmony_ci#include "amdgpu_ih.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define AMDGPU_MAX_IRQ_SRC_ID 0x100 328c2ecf20Sopenharmony_ci#define AMDGPU_MAX_IRQ_CLIENT_ID 0x100 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define AMDGPU_IRQ_CLIENTID_LEGACY 0 358c2ecf20Sopenharmony_ci#define AMDGPU_IRQ_CLIENTID_MAX SOC15_IH_CLIENTID_MAX 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW 4 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct amdgpu_device; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cienum amdgpu_interrupt_state { 428c2ecf20Sopenharmony_ci AMDGPU_IRQ_STATE_DISABLE, 438c2ecf20Sopenharmony_ci AMDGPU_IRQ_STATE_ENABLE, 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistruct amdgpu_iv_entry { 478c2ecf20Sopenharmony_ci unsigned client_id; 488c2ecf20Sopenharmony_ci unsigned src_id; 498c2ecf20Sopenharmony_ci unsigned ring_id; 508c2ecf20Sopenharmony_ci unsigned vmid; 518c2ecf20Sopenharmony_ci unsigned vmid_src; 528c2ecf20Sopenharmony_ci uint64_t timestamp; 538c2ecf20Sopenharmony_ci unsigned timestamp_src; 548c2ecf20Sopenharmony_ci unsigned pasid; 558c2ecf20Sopenharmony_ci unsigned pasid_src; 568c2ecf20Sopenharmony_ci unsigned src_data[AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW]; 578c2ecf20Sopenharmony_ci const uint32_t *iv_entry; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistruct amdgpu_irq_src { 618c2ecf20Sopenharmony_ci unsigned num_types; 628c2ecf20Sopenharmony_ci atomic_t *enabled_types; 638c2ecf20Sopenharmony_ci const struct amdgpu_irq_src_funcs *funcs; 648c2ecf20Sopenharmony_ci void *data; 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistruct amdgpu_irq_client { 688c2ecf20Sopenharmony_ci struct amdgpu_irq_src **sources; 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* provided by interrupt generating IP blocks */ 728c2ecf20Sopenharmony_cistruct amdgpu_irq_src_funcs { 738c2ecf20Sopenharmony_ci int (*set)(struct amdgpu_device *adev, struct amdgpu_irq_src *source, 748c2ecf20Sopenharmony_ci unsigned type, enum amdgpu_interrupt_state state); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci int (*process)(struct amdgpu_device *adev, 778c2ecf20Sopenharmony_ci struct amdgpu_irq_src *source, 788c2ecf20Sopenharmony_ci struct amdgpu_iv_entry *entry); 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistruct amdgpu_irq { 828c2ecf20Sopenharmony_ci bool installed; 838c2ecf20Sopenharmony_ci spinlock_t lock; 848c2ecf20Sopenharmony_ci /* interrupt sources */ 858c2ecf20Sopenharmony_ci struct amdgpu_irq_client client[AMDGPU_IRQ_CLIENTID_MAX]; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci /* status, etc. */ 888c2ecf20Sopenharmony_ci bool msi_enabled; /* msi enabled */ 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci /* interrupt rings */ 918c2ecf20Sopenharmony_ci struct amdgpu_ih_ring ih, ih1, ih2; 928c2ecf20Sopenharmony_ci const struct amdgpu_ih_funcs *ih_funcs; 938c2ecf20Sopenharmony_ci struct work_struct ih1_work, ih2_work; 948c2ecf20Sopenharmony_ci struct amdgpu_irq_src self_irq; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci /* gen irq stuff */ 978c2ecf20Sopenharmony_ci struct irq_domain *domain; /* GPU irq controller domain */ 988c2ecf20Sopenharmony_ci unsigned virq[AMDGPU_MAX_IRQ_SRC_ID]; 998c2ecf20Sopenharmony_ci uint32_t srbm_soft_reset; 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_civoid amdgpu_irq_disable_all(struct amdgpu_device *adev); 1038c2ecf20Sopenharmony_ciirqreturn_t amdgpu_irq_handler(int irq, void *arg); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciint amdgpu_irq_init(struct amdgpu_device *adev); 1068c2ecf20Sopenharmony_civoid amdgpu_irq_fini(struct amdgpu_device *adev); 1078c2ecf20Sopenharmony_ciint amdgpu_irq_add_id(struct amdgpu_device *adev, 1088c2ecf20Sopenharmony_ci unsigned client_id, unsigned src_id, 1098c2ecf20Sopenharmony_ci struct amdgpu_irq_src *source); 1108c2ecf20Sopenharmony_civoid amdgpu_irq_dispatch(struct amdgpu_device *adev, 1118c2ecf20Sopenharmony_ci struct amdgpu_ih_ring *ih); 1128c2ecf20Sopenharmony_ciint amdgpu_irq_update(struct amdgpu_device *adev, struct amdgpu_irq_src *src, 1138c2ecf20Sopenharmony_ci unsigned type); 1148c2ecf20Sopenharmony_ciint amdgpu_irq_get(struct amdgpu_device *adev, struct amdgpu_irq_src *src, 1158c2ecf20Sopenharmony_ci unsigned type); 1168c2ecf20Sopenharmony_ciint amdgpu_irq_put(struct amdgpu_device *adev, struct amdgpu_irq_src *src, 1178c2ecf20Sopenharmony_ci unsigned type); 1188c2ecf20Sopenharmony_cibool amdgpu_irq_enabled(struct amdgpu_device *adev, struct amdgpu_irq_src *src, 1198c2ecf20Sopenharmony_ci unsigned type); 1208c2ecf20Sopenharmony_civoid amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciint amdgpu_irq_add_domain(struct amdgpu_device *adev); 1238c2ecf20Sopenharmony_civoid amdgpu_irq_remove_domain(struct amdgpu_device *adev); 1248c2ecf20Sopenharmony_ciunsigned amdgpu_irq_create_mapping(struct amdgpu_device *adev, unsigned src_id); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#endif 127