Path: blob/master/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
26517 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/*23* This file defines the private interface between the24* AMD kernel graphics drivers and the AMD KFD.25*/2627#ifndef KGD_KFD_INTERFACE_H_INCLUDED28#define KGD_KFD_INTERFACE_H_INCLUDED2930#include <linux/types.h>31#include <linux/bitmap.h>32#include <linux/dma-fence.h>33#include "amdgpu_irq.h"34#include "amdgpu_gfx.h"3536struct pci_dev;37struct amdgpu_device;3839struct kfd_dev;40struct kgd_mem;4142enum kfd_preempt_type {43KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN = 0,44KFD_PREEMPT_TYPE_WAVEFRONT_RESET,45KFD_PREEMPT_TYPE_WAVEFRONT_SAVE46};4748struct kfd_vm_fault_info {49uint64_t page_addr;50uint32_t vmid;51uint32_t mc_id;52uint32_t status;53bool prot_valid;54bool prot_read;55bool prot_write;56bool prot_exec;57};5859/* For getting GPU local memory information from KGD */60struct kfd_local_mem_info {61uint64_t local_mem_size_private;62uint64_t local_mem_size_public;63uint32_t vram_width;64uint32_t mem_clk_max;65};6667enum kgd_memory_pool {68KGD_POOL_SYSTEM_CACHEABLE = 1,69KGD_POOL_SYSTEM_WRITECOMBINE = 2,70KGD_POOL_FRAMEBUFFER = 3,71};7273struct kfd_cu_occupancy {74u32 wave_cnt;75u32 doorbell_off;76};7778/**79* enum kfd_sched_policy80*81* @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp)82* scheduling. In this scheduling mode we're using the firmware code to83* schedule the user mode queues and kernel queues such as HIQ and DIQ.84* the HIQ queue is used as a special queue that dispatches the configuration85* to the cp and the user mode queues list that are currently running.86* the DIQ queue is a debugging queue that dispatches debugging commands to the87* firmware.88* in this scheduling mode user mode queues over subscription feature is89* enabled.90*91* @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over92* subscription feature disabled.93*94* @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly95* set the command processor registers and sets the queues "manually". This96* mode is used *ONLY* for debugging proposes.97*98*/99enum kfd_sched_policy {100KFD_SCHED_POLICY_HWS = 0,101KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION,102KFD_SCHED_POLICY_NO_HWS103};104105struct kgd2kfd_shared_resources {106/* Bit n == 1 means VMID n is available for KFD. */107unsigned int compute_vmid_bitmap;108109/* number of pipes per mec */110uint32_t num_pipe_per_mec;111112/* number of queues per pipe */113uint32_t num_queue_per_pipe;114115/* Bit n == 1 means Queue n is available for KFD */116DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);117118/* SDMA doorbell assignments (SOC15 and later chips only). Only119* specific doorbells are routed to each SDMA engine. Others120* are routed to IH and VCN. They are not usable by the CP.121*/122uint32_t *sdma_doorbell_idx;123124/* From SOC15 onward, the doorbell index range not usable for CP125* queues.126*/127uint32_t non_cp_doorbells_start;128uint32_t non_cp_doorbells_end;129130/* Base address of doorbell aperture. */131phys_addr_t doorbell_physical_address;132133/* Size in bytes of doorbell aperture. */134size_t doorbell_aperture_size;135136/* Number of bytes at start of aperture reserved for KGD. */137size_t doorbell_start_offset;138139/* GPUVM address space size in bytes */140uint64_t gpuvm_size;141142/* Minor device number of the render node */143int drm_render_minor;144145bool enable_mes;146};147148struct tile_config {149uint32_t *tile_config_ptr;150uint32_t *macro_tile_config_ptr;151uint32_t num_tile_configs;152uint32_t num_macro_tile_configs;153154uint32_t gb_addr_config;155uint32_t num_banks;156uint32_t num_ranks;157};158159#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096160161/**162* struct kfd2kgd_calls163*164* @program_sh_mem_settings: A function that should initiate the memory165* properties such as main aperture memory type (cache / non cached) and166* secondary aperture base address, size and memory type.167* This function is used only for no cp scheduling mode.168*169* @set_pasid_vmid_mapping: Exposes pasid/vmid pair to the H/W for no cp170* scheduling mode. Only used for no cp scheduling mode.171*172* @hqd_load: Loads the mqd structure to a H/W hqd slot. used only for no cp173* sceduling mode.174*175* @hqd_sdma_load: Loads the SDMA mqd structure to a H/W SDMA hqd slot.176* used only for no HWS mode.177*178* @hqd_dump: Dumps CPC HQD registers to an array of address-value pairs.179* Array is allocated with kmalloc, needs to be freed with kfree by caller.180*181* @hqd_sdma_dump: Dumps SDMA HQD registers to an array of address-value pairs.182* Array is allocated with kmalloc, needs to be freed with kfree by caller.183*184* @hqd_is_occupies: Checks if a hqd slot is occupied.185*186* @hqd_destroy: Destructs and preempts the queue assigned to that hqd slot.187*188* @hqd_sdma_is_occupied: Checks if an SDMA hqd slot is occupied.189*190* @hqd_sdma_destroy: Destructs and preempts the SDMA queue assigned to that191* SDMA hqd slot.192*193* @set_scratch_backing_va: Sets VA for scratch backing memory of a VMID.194* Only used for no cp scheduling mode195*196* @set_vm_context_page_table_base: Program page table base for a VMID197*198* @invalidate_tlbs: Invalidate TLBs for a specific PASID199*200* @invalidate_tlbs_vmid: Invalidate TLBs for a specific VMID201*202* @read_vmid_from_vmfault_reg: On Hawaii the VMID is not set in the203* IH ring entry. This function allows the KFD ISR to get the VMID204* from the fault status register as early as possible.205*206* @get_cu_occupancy: Function pointer that returns to caller the number207* of wave fronts that are in flight for all of the queues of a process208* as identified by its pasid. It is important to note that the value209* returned by this function is a snapshot of current moment and cannot210* guarantee any minimum for the number of waves in-flight. This function211* is defined for devices that belong to GFX9 and later GFX families. Care212* must be taken in calling this function as it is not defined for devices213* that belong to GFX8 and below GFX families.214*215* This structure contains function pointers to services that the kgd driver216* provides to amdkfd driver.217*218*/219struct kfd2kgd_calls {220/* Register access functions */221void (*program_sh_mem_settings)(struct amdgpu_device *adev, uint32_t vmid,222uint32_t sh_mem_config, uint32_t sh_mem_ape1_base,223uint32_t sh_mem_ape1_limit, uint32_t sh_mem_bases,224uint32_t inst);225226int (*set_pasid_vmid_mapping)(struct amdgpu_device *adev, u32 pasid,227unsigned int vmid, uint32_t inst);228229int (*init_interrupts)(struct amdgpu_device *adev, uint32_t pipe_id,230uint32_t inst);231232int (*hqd_load)(struct amdgpu_device *adev, void *mqd, uint32_t pipe_id,233uint32_t queue_id, uint32_t __user *wptr,234uint32_t wptr_shift, uint32_t wptr_mask,235struct mm_struct *mm, uint32_t inst);236237int (*hiq_mqd_load)(struct amdgpu_device *adev, void *mqd,238uint32_t pipe_id, uint32_t queue_id,239uint32_t doorbell_off, uint32_t inst);240241int (*hqd_sdma_load)(struct amdgpu_device *adev, void *mqd,242uint32_t __user *wptr, struct mm_struct *mm);243244int (*hqd_dump)(struct amdgpu_device *adev,245uint32_t pipe_id, uint32_t queue_id,246uint32_t (**dump)[2], uint32_t *n_regs, uint32_t inst);247248int (*hqd_sdma_dump)(struct amdgpu_device *adev,249uint32_t engine_id, uint32_t queue_id,250uint32_t (**dump)[2], uint32_t *n_regs);251252bool (*hqd_is_occupied)(struct amdgpu_device *adev,253uint64_t queue_address, uint32_t pipe_id,254uint32_t queue_id, uint32_t inst);255256int (*hqd_destroy)(struct amdgpu_device *adev, void *mqd,257enum kfd_preempt_type reset_type,258unsigned int timeout, uint32_t pipe_id,259uint32_t queue_id, uint32_t inst);260261bool (*hqd_sdma_is_occupied)(struct amdgpu_device *adev, void *mqd);262263int (*hqd_sdma_destroy)(struct amdgpu_device *adev, void *mqd,264unsigned int timeout);265266int (*wave_control_execute)(struct amdgpu_device *adev,267uint32_t gfx_index_val,268uint32_t sq_cmd, uint32_t inst);269bool (*get_atc_vmid_pasid_mapping_info)(struct amdgpu_device *adev,270uint8_t vmid,271uint16_t *p_pasid);272273/* No longer needed from GFXv9 onward. The scratch base address is274* passed to the shader by the CP. It's the user mode driver's275* responsibility.276*/277void (*set_scratch_backing_va)(struct amdgpu_device *adev,278uint64_t va, uint32_t vmid);279280void (*set_vm_context_page_table_base)(struct amdgpu_device *adev,281uint32_t vmid, uint64_t page_table_base);282uint32_t (*read_vmid_from_vmfault_reg)(struct amdgpu_device *adev);283284uint32_t (*enable_debug_trap)(struct amdgpu_device *adev,285bool restore_dbg_registers,286uint32_t vmid);287uint32_t (*disable_debug_trap)(struct amdgpu_device *adev,288bool keep_trap_enabled,289uint32_t vmid);290int (*validate_trap_override_request)(struct amdgpu_device *adev,291uint32_t trap_override,292uint32_t *trap_mask_supported);293uint32_t (*set_wave_launch_trap_override)(struct amdgpu_device *adev,294uint32_t vmid,295uint32_t trap_override,296uint32_t trap_mask_bits,297uint32_t trap_mask_request,298uint32_t *trap_mask_prev,299uint32_t kfd_dbg_trap_cntl_prev);300uint32_t (*set_wave_launch_mode)(struct amdgpu_device *adev,301uint8_t wave_launch_mode,302uint32_t vmid);303uint32_t (*set_address_watch)(struct amdgpu_device *adev,304uint64_t watch_address,305uint32_t watch_address_mask,306uint32_t watch_id,307uint32_t watch_mode,308uint32_t debug_vmid,309uint32_t inst);310uint32_t (*clear_address_watch)(struct amdgpu_device *adev,311uint32_t watch_id);312void (*get_iq_wait_times)(struct amdgpu_device *adev,313uint32_t *wait_times,314uint32_t inst);315void (*build_dequeue_wait_counts_packet_info)(struct amdgpu_device *adev,316uint32_t wait_times,317uint32_t sch_wave,318uint32_t que_sleep,319uint32_t *reg_offset,320uint32_t *reg_data);321void (*get_cu_occupancy)(struct amdgpu_device *adev,322struct kfd_cu_occupancy *cu_occupancy,323int *max_waves_per_cu, uint32_t inst);324void (*program_trap_handler_settings)(struct amdgpu_device *adev,325uint32_t vmid, uint64_t tba_addr, uint64_t tma_addr,326uint32_t inst);327uint64_t (*hqd_get_pq_addr)(struct amdgpu_device *adev,328uint32_t pipe_id, uint32_t queue_id,329uint32_t inst);330uint64_t (*hqd_reset)(struct amdgpu_device *adev,331uint32_t pipe_id, uint32_t queue_id,332uint32_t inst, unsigned int utimeout);333uint32_t (*hqd_sdma_get_doorbell)(struct amdgpu_device *adev,334int engine, int queue);335};336337#endif /* KGD_KFD_INTERFACE_H_INCLUDED */338339340