Path: blob/master/drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c
26516 views
/*1* Copyright 2014 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#include "kfd_priv.h"23#include "kfd_events.h"24#include "cik_int.h"25#include "amdgpu_amdkfd.h"26#include "kfd_smi_events.h"2728static bool cik_event_interrupt_isr(struct kfd_node *dev,29const uint32_t *ih_ring_entry,30uint32_t *patched_ihre,31bool *patched_flag)32{33const struct cik_ih_ring_entry *ihre =34(const struct cik_ih_ring_entry *)ih_ring_entry;35const struct kfd2kgd_calls *f2g = dev->kfd2kgd;36unsigned int vmid;37uint16_t pasid;38bool ret;3940/* This workaround is due to HW/FW limitation on Hawaii that41* VMID and PASID are not written into ih_ring_entry42*/43if ((ihre->source_id == CIK_INTSRC_GFX_PAGE_INV_FAULT ||44ihre->source_id == CIK_INTSRC_GFX_MEM_PROT_FAULT) &&45dev->adev->asic_type == CHIP_HAWAII) {46struct cik_ih_ring_entry *tmp_ihre =47(struct cik_ih_ring_entry *)patched_ihre;4849*patched_flag = true;50*tmp_ihre = *ihre;5152vmid = f2g->read_vmid_from_vmfault_reg(dev->adev);53ret = f2g->get_atc_vmid_pasid_mapping_info(dev->adev, vmid, &pasid);5455tmp_ihre->ring_id &= 0x000000ff;56tmp_ihre->ring_id |= vmid << 8;57tmp_ihre->ring_id |= pasid << 16;5859return ret && (pasid != 0) &&60vmid >= dev->vm_info.first_vmid_kfd &&61vmid <= dev->vm_info.last_vmid_kfd;62}6364/* Only handle interrupts from KFD VMIDs */65vmid = (ihre->ring_id & 0x0000ff00) >> 8;66if (vmid < dev->vm_info.first_vmid_kfd ||67vmid > dev->vm_info.last_vmid_kfd)68return false;6970/* If there is no valid PASID, it's likely a firmware bug */71pasid = (ihre->ring_id & 0xffff0000) >> 16;72if (WARN_ONCE(pasid == 0, "FW bug: No PASID in KFD interrupt"))73return false;7475/* Interrupt types we care about: various signals and faults.76* They will be forwarded to a work queue (see below).77*/78return ihre->source_id == CIK_INTSRC_CP_END_OF_PIPE ||79ihre->source_id == CIK_INTSRC_SDMA_TRAP ||80ihre->source_id == CIK_INTSRC_SQ_INTERRUPT_MSG ||81ihre->source_id == CIK_INTSRC_CP_BAD_OPCODE ||82((ihre->source_id == CIK_INTSRC_GFX_PAGE_INV_FAULT ||83ihre->source_id == CIK_INTSRC_GFX_MEM_PROT_FAULT) &&84!amdgpu_no_queue_eviction_on_vm_fault);85}8687static void cik_event_interrupt_wq(struct kfd_node *dev,88const uint32_t *ih_ring_entry)89{90const struct cik_ih_ring_entry *ihre =91(const struct cik_ih_ring_entry *)ih_ring_entry;92uint32_t context_id = ihre->data & 0xfffffff;93u32 pasid = (ihre->ring_id & 0xffff0000) >> 16;9495if (pasid == 0)96return;9798if (ihre->source_id == CIK_INTSRC_CP_END_OF_PIPE)99kfd_signal_event_interrupt(pasid, context_id, 28);100else if (ihre->source_id == CIK_INTSRC_SDMA_TRAP)101kfd_signal_event_interrupt(pasid, context_id, 28);102else if (ihre->source_id == CIK_INTSRC_SQ_INTERRUPT_MSG)103kfd_signal_event_interrupt(pasid, context_id & 0xff, 8);104else if (ihre->source_id == CIK_INTSRC_CP_BAD_OPCODE)105kfd_signal_hw_exception_event(pasid);106else if (ihre->source_id == CIK_INTSRC_GFX_PAGE_INV_FAULT ||107ihre->source_id == CIK_INTSRC_GFX_MEM_PROT_FAULT) {108struct kfd_process_device *pdd = NULL;109struct kfd_vm_fault_info info;110struct kfd_process *p;111112kfd_smi_event_update_vmfault(dev, pasid);113p = kfd_lookup_process_by_pasid(pasid, &pdd);114if (!pdd)115return;116117kfd_evict_process_device(pdd);118119memset(&info, 0, sizeof(info));120amdgpu_amdkfd_gpuvm_get_vm_fault_info(dev->adev, &info);121if (!info.page_addr && !info.status) {122kfd_unref_process(p);123return;124}125126kfd_signal_vm_fault_event(pdd, &info, NULL);127kfd_unref_process(p);128}129}130131const struct kfd_event_interrupt_class event_interrupt_class_cik = {132.interrupt_isr = cik_event_interrupt_isr,133.interrupt_wq = cik_event_interrupt_wq,134};135136137