AMDKFD Kernel Driver
Subsystems (4)
PATCH v4 1/23 drm/radeon: reduce number of free VMIDs and pipes in KV
In reply to Oded GabbayTo support HSA on KV, we need to limit the number of vmids and pipes that are available for radeon's use with KV.
This patch reserves VMIDs 8-15 for amdkfd (so radeon can only use VMIDs 0-7) and also makes radeon thinks that KV has only a single MEC with a single pipe in it
v3: Use define for static vmid allocation in radeon
--- drivers/gpu/drm/radeon/cik.c | 48 +++++++++++++++++++++---------------------- drivers/gpu/drm/radeon/cikd.h | 2 ++ 2 files changed, 26 insertions(+), 24 deletions(-)
drivers/gpu/drm/radeon/cik.c +24 -24
@@ -4678,12 +4678,11 @@ static int cik_mec_init(struct radeon_device *rdev)/* * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total +* Nonetheless, we assign only 1 pipe because all other pipes will +* be handled by KFD */ -if (rdev->family ==CHIP_KAVERI ) - rdev->mec.num_mec =2 ; -else - rdev->mec.num_mec =1 ; - rdev->mec.num_pipe =4 ; + rdev->mec.num_mec =1 ; + rdev->mec.num_pipe =1 ; rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe *8 ;if (rdev->mec.hpd_eop_obj ==NULL ) {
@@ -4825,28 +4824,24 @@ static int cik_cp_compute_resume(struct radeon_device *rdev)/* init the pipes */ mutex_lock (&rdev->srbm_mutex); -for (i =0 ; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) { -int me = (i <4 ) ?1 :2 ; -int pipe = (i <4 ) ? i : (i -4 ); - eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i *MEC_HPD_SIZE *2 ); + eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr; -cik_srbm_select (rdev, me, pipe,0 ,0 ); +cik_srbm_select (rdev,0 ,0 ,0 ,0 ); -/* write the EOP addr */ -WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); -WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); +/* write the EOP addr */ +WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); +WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); -/* set the VMID assigned */ -WREG32 (CP_HPD_EOP_VMID ,0 ); +/* set the VMID assigned */ +WREG32 (CP_HPD_EOP_VMID ,0 ); + +/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ + tmp =RREG32 (CP_HPD_EOP_CONTROL ); + tmp &= ~EOP_SIZE_MASK ; + tmp |=order_base_2 (MEC_HPD_SIZE /8 ); +WREG32 (CP_HPD_EOP_CONTROL , tmp); -/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ - tmp =RREG32 (CP_HPD_EOP_CONTROL ); - tmp &= ~EOP_SIZE_MASK ; - tmp |=order_base_2 (MEC_HPD_SIZE /8 ); -WREG32 (CP_HPD_EOP_CONTROL , tmp); - } -cik_srbm_select (rdev,0 ,0 ,0 ,0 );mutex_unlock (&rdev->srbm_mutex);/* init the queues. Just two for now. */
@@ -5900,8 +5895,13 @@ int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)*/ int cik_vm_init (struct radeon_device *rdev) { -/* number of VMs */ - rdev->vm_manager.nvm =16 ; +/* +* number of VMs +* VMID 0 is reserved for System +* radeon graphics/compute will use VMIDs 1-7 +* amdkfd will use VMIDs 8-15 +*/ + rdev->vm_manager.nvm =RADEON_NUM_OF_VMIDS ;/* base offset of vram pages */ if (rdev->flags &RADEON_IS_IGP ) {u64 tmp =RREG32 (MC_VM_FB_OFFSET );
drivers/gpu/drm/radeon/cikd.h +2 -0
@@ -30,6 +30,8 @@#define CIK_RB_BITMAP_WIDTH_PER_SH 2#define HAWAII_RB_BITMAP_WIDTH_PER_SH 4 +#define RADEON_NUM_OF_VMIDS 8 +/* DIDT IND registers */ #define DIDT_SQ_CTRL0 0x0# define DIDT_CTRL_EN (1 << 0)
Signature · 1 line
1.9.1
PATCH v4 6/23 Update MAINTAINERS and CREDITS files with amdkfd info
In reply to Oded Gabbay--- CREDITS | 7 +++++++ MAINTAINERS | 10 ++++++++++ 2 files changed, 17 insertions(+)
CREDITS +7 -0
@@ -1197,6 +1197,13 @@ S: R. Tocantins, 89 - Cristo Rei S: 80050-430 - Curitiba - Paraná S: Brazil +N: Oded Gabbay +E: [email protected] +D: AMD KFD maintainer +S: 12 Shraga Raphaeli +S: Petah-Tikva, 4906418 +S: Israel + N: Kumar Gala E: [email protected] D: Embedded PowerPC 6xx/7xx/74xx/82xx/83xx/85xx support
MAINTAINERS +10 -0
@@ -609,6 +609,16 @@ F: drivers/crypto/geode* F: drivers/video/fbdev/geode/ F: arch/x86/include/asm/geode.h +AMD KFD (radeon extension) +M: Oded Gabbay <[email protected]> +L: [email protected] +T: git git://people.freedesktop.org/~gabbayo/linux.git +S: Supported +F: drivers/gpu/drm/radeon/amdkfd/* +F: drivers/gpu/drm/radeon/radeon_kfd.c +F: drivers/gpu/drm/radeon/radeon_kfd.h +F: include/linux/uapi/linux/kfd_ioctl.h + AMD IOMMU (AMD-VI) M: Joerg Roedel <[email protected]> L: [email protected]
Signature · 1 line
1.9.1
PATCH v4 7/23 amdkfd: Add IOCTL set definitions of amdkfd
In reply to Oded Gabbay- KFD_IOC_GET_VERSION:
Retrieves the interface version of amdkfd
- KFD_IOC_CREATE_QUEUE:
Creates a usermode queue that runs on a specific GPU device
- KFD_IOC_DESTROY_QUEUE:
Destroys an existing usermode queue
- KFD_IOC_SET_MEMORY_POLICY:
Sets the memory policy of the default and alternate aperture of the calling process
- KFD_IOC_GET_CLOCK_COUNTERS:
Retrieves counters (timestamps) of CPU and GPU
- KFD_IOC_GET_PROCESS_APERTURES:
Retrieves information about process apertures that were initialized during the open() call of the amdkfd device
- KFD_IOC_UPDATE_QUEUE:
Updates configuration of an existing usermode queue
v3: Remove pragma pack and pmc ioctls. Added parameter for doorbell offset and a comment on counters
--- include/uapi/linux/kfd_ioctl.h | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 include/uapi/linux/kfd_ioctl.h
include/uapi/linux/kfd_ioctl.h new file +123 -0
@@ -0,0 +1,123 @@ +/* +* Copyright 2014 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef KFD_IOCTL_H_INCLUDED +#define KFD_IOCTL_H_INCLUDED + +#include <linux/types.h> +#include <linux/ioctl.h> + +#define KFD_IOCTL_CURRENT_VERSION 1 + +struct kfd_ioctl_get_version_args { +uint32_t min_supported_version;/* from KFD */ +uint32_t max_supported_version;/* from KFD */ +}; + +/* For kfd_ioctl_create_queue_args.queue_type. */ +#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 +#define KFD_IOC_QUEUE_TYPE_SDMA 1 + +struct kfd_ioctl_create_queue_args { +uint64_t ring_base_address;/* to KFD */ +uint64_t write_pointer_address;/* from KFD */ +uint64_t read_pointer_address;/* from KFD */ +uint64_t doorbell_offset;/* from KFD */ + +uint32_t ring_size;/* to KFD */ +uint32_t gpu_id;/* to KFD */ +uint32_t queue_type;/* to KFD */ +uint32_t queue_percentage;/* to KFD */ +uint32_t queue_priority;/* to KFD */ +uint32_t queue_id;/* from KFD */ +}; + +struct kfd_ioctl_destroy_queue_args { +uint32_t queue_id;/* to KFD */ +}; + +struct kfd_ioctl_update_queue_args { +uint64_t ring_base_address;/* to KFD */ + +uint32_t queue_id;/* to KFD */ +uint32_t ring_size;/* to KFD */ +uint32_t queue_percentage;/* to KFD */ +uint32_t queue_priority;/* to KFD */ +}; + +/* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */ +#define KFD_IOC_CACHE_POLICY_COHERENT 0 +#define KFD_IOC_CACHE_POLICY_NONCOHERENT 1 + +struct kfd_ioctl_set_memory_policy_args { +uint64_t alternate_aperture_base;/* to KFD */ +uint64_t alternate_aperture_size;/* to KFD */ + +uint32_t gpu_id;/* to KFD */ +uint32_t default_policy;/* to KFD */ +uint32_t alternate_policy;/* to KFD */ +}; + +/* +* All counters are monotonic. They are used for profiling of compute jobs. +* The profiling is done by userspace. +* +* In case of GPU reset, the counter should not be affected. +*/ + +struct kfd_ioctl_get_clock_counters_args { +uint64_t gpu_clock_counter;/* from KFD */ +uint64_t cpu_clock_counter;/* from KFD */ +uint64_t system_clock_counter;/* from KFD */ +uint64_t system_clock_freq;/* from KFD */ + +uint32_t gpu_id;/* to KFD */ +}; + +#define NUM_OF_SUPPORTED_GPUS 7 + +struct kfd_process_device_apertures { +uint64_t lds_base;/* from KFD */ +uint64_t lds_limit;/* from KFD */ +uint64_t scratch_base;/* from KFD */ +uint64_t scratch_limit;/* from KFD */ +uint64_t gpuvm_base;/* from KFD */ +uint64_t gpuvm_limit;/* from KFD */ +uint32_t gpu_id;/* from KFD */ +}; + +struct kfd_ioctl_get_process_apertures_args { +struct kfd_process_device_apertures process_apertures[NUM_OF_SUPPORTED_GPUS ];/* from KFD */ +uint8_t num_of_nodes;/* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/ +}; + +#define KFD_IOC_MAGIC 'K' + +#define KFD_IOC_GET_VERSION _IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args) +#define KFD_IOC_CREATE_QUEUE _IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args) +#define KFD_IOC_DESTROY_QUEUE _IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args) +#define KFD_IOC_SET_MEMORY_POLICY _IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args) +#define KFD_IOC_GET_CLOCK_COUNTERS _IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args) +#define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args) +#define KFD_IOC_UPDATE_QUEUE _IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args) + +#endif
Signature · 1 line
1.9.1
PATCH v4 8/23 amdkfd: Add amdkfd skeleton driver
In reply to Oded GabbayThis patch adds the amdkfd skeleton driver. The driver does nothing except define a /dev/kfd device.
It returns -ENODEV on all amdkfd IOCTLs.
v3: Move bool field to the end of structure, removed the pmc ioctls and added a meaningful error message for ioctl error.
--- drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 2 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 ++ drivers/gpu/drm/radeon/amdkfd/Makefile | 9 ++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 187 ++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 129 +++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 98 +++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 82 ++++++++++++ 8 files changed, 519 insertions(+) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
drivers/gpu/drm/radeon/Kconfig +2 -0
@@ -6,3 +6,5 @@ config DRM_RADEON_UMS Userspace modesetting is deprecated for quite some time now, so enable this only if you have ancient versions of the DDX drivers. + +source "drivers/gpu/drm/radeon/amdkfd/Kconfig"
drivers/gpu/drm/radeon/Makefile +2 -0
@@ -112,4 +112,6 @@ radeon-$(CONFIG_ACPI) += radeon_acpi.o obj-$(CONFIG_DRM_RADEON)+= radeon.o +obj-$(CONFIG_HSA_RADEON)+= amdkfd/ + CFLAGS_radeon_trace_points.o := -I$(src)
drivers/gpu/drm/radeon/amdkfd/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# +# Heterogenous system architecture configuration +# + +config HSA_RADEON + tristate "HSA kernel driver for AMD Radeon devices" + depends on DRM_RADEON && AMD_IOMMU_V2 && X86_64 + default m + help + Enable this if you want to use HSA features on AMD radeon devices.
drivers/gpu/drm/radeon/amdkfd/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for Heterogenous System Architecture support for AMD radeon devices +# + +ccflags-y := -Iinclude/drm + +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o + +obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c new file +187 -0
187 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device.c new file +129 -0
129 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_module.c new file +98 -0
98 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 11/23 amdkfd: Add binding/unbinding calls to amd_iommu driver
In reply to Oded GabbayThis patch adds the functions to bind and unbind pasid from a device through the amd_iommu driver.
The unbind function is called when the mm_struct of the process is released.
The bind function is not called here because it is called only in the IOCTLs which are not yet implemented at this stage of the patchset.
--- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 86 ++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 12 ++++ 3 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +85 -1
@@ -98,6 +98,63 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev)return kfd; } +static bool device_iommu_pasid_init (struct kfd_dev *kfd) +{ +const u32 required_iommu_flags =AMD_IOMMU_DEVICE_FLAG_ATS_SUP |AMD_IOMMU_DEVICE_FLAG_PRI_SUP + |AMD_IOMMU_DEVICE_FLAG_PASID_SUP ; + +struct amd_iommu_device_info iommu_info; +unsigned int pasid_limit; +int err; + + err =amd_iommu_device_info (kfd->pdev, &iommu_info); +if (err <0 ) { +dev_err (kfd_device,"error getting iommu info. is the iommu enabled?\n" ); +return false; + } + +if ((iommu_info.flags & required_iommu_flags) != required_iommu_flags) { +dev_err (kfd_device,"error required iommu flags ats(%i), pri(%i), pasid(%i)\n" , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_ATS_SUP ) !=0 , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_PRI_SUP ) !=0 , + (iommu_info.flags &AMD_IOMMU_DEVICE_FLAG_PASID_SUP ) !=0 ); +return false; + } + + pasid_limit = min_t(unsigned int, + (unsigned int )1 << kfd->device_info->max_pasid_bits, + iommu_info.max_pasids); +/* +* last pasid is used for kernel queues doorbells +* in the future the last pasid might be used for a kernel thread. +*/ + pasid_limit = min_t(unsigned int, + pasid_limit, + kfd->doorbell_process_limit -1 ); + + err =amd_iommu_init_device (kfd->pdev, pasid_limit); +if (err <0 ) { +dev_err (kfd_device,"error initializing iommu device\n" ); +return false; + } + +if (!kfd_set_pasid_limit (pasid_limit)) { +dev_err (kfd_device,"error setting pasid limit\n" ); +amd_iommu_free_device (kfd->pdev); +return false; + } + +return true; +} + +static void iommu_pasid_shutdown_callback (struct pci_dev *pdev,int pasid) +{ +struct kfd_dev *dev =kfd_device_by_pci_dev (pdev); + +if (dev) +kfd_unbind_process_from_device (dev, pasid); +} +bool kgd2kfd_device_init (struct kfd_dev *kfd,const struct kgd2kfd_shared_resources *gpu_resources) {
@@ -129,6 +186,13 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto kfd_topology_add_device_error; } +if (!device_iommu_pasid_init (kfd)) { +dev_err (kfd_device, +"Error initializing iommuv2 for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto device_iommu_pasid_error; + } +amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); kfd->init_complete = true; dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
@@ -136,6 +200,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto out; +device_iommu_pasid_error: +kfd_topology_remove_device (kfd); kfd_topology_add_device_error: kfd2kgd->fini_sa_manager (kfd->kgd); dev_err(kfd_device,
@@ -147,7 +213,10 @@ out:void kgd2kfd_device_exit (struct kfd_dev *kfd) { -kfd_topology_remove_device (kfd); +if (kfd->init_complete) { +amd_iommu_free_device (kfd->pdev); +kfd_topology_remove_device (kfd); + }kfree (kfd); }
@@ -155,12 +224,27 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)void kgd2kfd_suspend (struct kfd_dev *kfd) {BUG_ON (kfd ==NULL ); + +if (kfd->init_complete) +amd_iommu_free_device (kfd->pdev); }int kgd2kfd_resume (struct kfd_dev *kfd) { +unsigned int pasid_limit; +int err; +BUG_ON (kfd ==NULL ); + pasid_limit =kfd_get_pasid_limit (); + +if (kfd->init_complete) { + err =amd_iommu_init_device (kfd->pdev, pasid_limit); +if (err <0 ) +return -ENXIO ; +amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + } +return 0 ; }
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +1 -0
@@ -188,6 +188,7 @@ struct kfd_process {struct kfd_process *kfd_create_process (const struct task_struct *);struct kfd_process *kfd_get_process (const struct task_struct *); +void kfd_unbind_process_from_device (struct kfd_dev *dev,unsigned int pasid);struct kfd_process_device *kfd_get_process_device_data (struct kfd_dev *dev,struct kfd_process *p,int create_pdd);
drivers/gpu/drm/radeon/amdkfd/kfd_process.c +12 -0
@@ -24,6 +24,7 @@#include <linux/log2.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/amd-iommu.h> #include <linux/notifier.h> struct mm_struct ;
@@ -153,6 +154,7 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,mutex_lock (&p->mutex);list_for_each_entry_safe (pdd, temp, &p->per_device_data, per_device_list) { +amd_iommu_unbind_pasid (pdd->dev->pdev, p->pasid);list_del (&pdd->per_device_list);kfree (pdd); }
@@ -258,6 +260,7 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, struct kfd_process *p) {struct kfd_process_device *pdd =kfd_get_process_device_data (dev, p,1 ); +int err;if (pdd ==NULL )return ERR_PTR (-ENOMEM );
@@ -265,6 +268,15 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,if (pdd->bound)return pdd; + err =amd_iommu_bind_pasid (dev->pdev, p->pasid, p->lead_thread); +if (err <0 ) +return ERR_PTR (err); + +if (err <0 ) { +amd_iommu_unbind_pasid (dev->pdev, p->pasid); +return ERR_PTR (err); + } + pdd->bound = true;return pdd;
Signature · 1 line
1.9.1
PATCH v4 14/23 amdkfd: Add kernel queue module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The kernel queue module enables the amdkfd to establish kernel queues, not exposed to user space.
The kernel queues are used for HIQ (HSA Interface Queue) and DIQ (Debug Interface Queue) operations
v3: Removed use of internal typedefs and added use of the new gart allocation functions
v4: Fixed a miscalculation in kernel queue wrapping
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 101 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 33 +- 7 files changed, 1320 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -6,6 +6,7 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o kfd_queue.o kfd_mqd_manager.o + kfd_process.o kfd_queue.o kfd_mqd_manager.o \ + kfd_kernel_queue.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h new file +101 -0
101 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c new file +330 -0
330 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h new file +66 -0
66 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h new file +682 -0
682 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h new file +107 -0
107 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +32 -1
@@ -35,6 +35,15 @@#define KFD_SYSFS_FILE_MODE 0444 +/* +* When working with cp scheduler we should assign the HIQ manually or via the radeon driver +* to a fixed hqd slot, here are the fixed HIQ hqd slot definitions for Kaveri. +* In Kaveri only the first ME queues participates in the cp scheduling taking that in mind +* we set the HIQ slot in the second ME. +*/ +#define KFD_CIK_HIQ_PIPE 4 +#define KFD_CIK_HIQ_QUEUE 0 +/* GPU ID hash width in bits */ #define KFD_GPU_ID_HASH_WIDTH 16
@@ -56,6 +65,11 @@ extern int max_num_of_queues_per_process;#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 +enum cache_policy { + cache_policy_coherent, + cache_policy_noncoherent +}; +struct kfd_device_info {const struct kfd_scheduler_class *scheduler_class;unsigned int max_pasid_bits;
@@ -83,8 +97,10 @@ struct kfd_dev {struct kgd2kfd_shared_resources shared_resources; -bool init_complete; +/* QCM Device instance */ +struct device_queue_manager *dqm; +bool init_complete; };/* KGD2KFD callbacks */
@@ -366,6 +382,21 @@ int kgd2kfd_resume(struct kfd_dev *dev);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process); +/* Queue Context Management */ +int init_queue (struct queue **q,struct queue_properties properties); +void uninit_queue (struct queue *q); +void print_queue (struct queue *q); + +/* Packet Manager */ + +struct packet_manager { +struct device_queue_manager *dqm; +struct kernel_queue *priv_queue; +struct mutex lock; +bool allocated; +struct kfd_mem_obj *ib_buffer_obj; +}; +uint64_t kfd_get_number_elems (struct kfd_dev *kfd);phys_addr_t kfd_get_process_doorbells (struct kfd_dev *dev,struct kfd_process *process);
Signature · 1 line
1.9.1
PATCH v4 16/23 amdkfd: Add packet manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The packet manager module builds PM4 packets for the sole use of the CP scheduler. Those packets are used by the HIQ to submit runlists to the CP.
v3:
Removed include of cik_mqds.h
Changed lower_32/upper_32 calls to use linux macros Used new gart allocation functions
Added documentation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 +++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 72 +++ 3 files changed, 568 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -7,6 +7,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ - kfd_kernel_queue.o + kfd_kernel_queue.o kfd_packet_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c new file +495 -0
495 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +72 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 18/23 amdkfd: Add device queue manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue scheduler divides into two sections, one section is process bounded and the other section is device bounded.
The device bounded section is handled by this module.
The DQM module handles queue setup, update and tear-down from the device side. It also supports suspend/resume operation.
v3: Changed device_init, added the use of the new gart allocation functions an Added documentation.
v4:
Fixed a race in DQM queue scheduler where dqm->lock must be held when accessing dqm->queue_count and dqm->processes_count. This fixes runlist IB allocation failures when DQM is under load.
Fixed race in DQM queue destruction where queues being destroyed must be removed from qpd->queues_list prior to preemption, or concurrent queue creation activity may reschedule them while their MQD is destroyed.
Fixed EOP queue size setting in CP_HPD_EOP_CONTROL, because the size is specified as (log2(size_dwords)-1). The previous calculation assumed the size was specified in bytes, which caused interference between EOP queues when multiple MEC pipelines were active.
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 28 +- .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 995 +++++++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 43 + drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 13 + 5 files changed, 1079 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -8,6 +8,6 @@ amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ kfd_kernel_queue.o kfd_packet_manager.o \ - kfd_process_queue_manager.o + kfd_process_queue_manager.o kfd_device_queue_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +27 -1
@@ -25,6 +25,7 @@#include <linux/pci.h> #include <linux/slab.h> #include "kfd_priv.h" +#include "kfd_device_queue_manager.h" #define MQD_SIZE_ALIGNED 768
@@ -194,12 +195,33 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, }amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + kfd->dqm =device_queue_manager_init (kfd); +if (!kfd->dqm) { +dev_err (kfd_device, +"Error initializing queue manager for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto device_queue_manager_error; + } + +if (kfd->dqm->start (kfd->dqm) !=0 ) { +dev_err (kfd_device, +"Error starting queuen manager for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto dqm_start_error; + } + kfd->init_complete = true;dev_info (kfd_device,"added device (%x:%x)\n" , kfd->pdev->vendor, kfd->pdev->device); +pr_debug ("kfd: Starting kfd with the following scheduling policy %d\n" , sched_policy); + goto out; +dqm_start_error: +device_queue_manager_uninit (kfd->dqm); +device_queue_manager_error: +amd_iommu_free_device (kfd->pdev); device_iommu_pasid_error:kfd_topology_remove_device (kfd); kfd_topology_add_device_error:
@@ -214,6 +236,7 @@ out:void kgd2kfd_device_exit (struct kfd_dev *kfd) {if (kfd->init_complete) { +device_queue_manager_uninit (kfd->dqm);amd_iommu_free_device (kfd->pdev);kfd_topology_remove_device (kfd); }
@@ -225,8 +248,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd) {BUG_ON (kfd ==NULL ); -if (kfd->init_complete) +if (kfd->init_complete) { + kfd->dqm->stop (kfd->dqm);amd_iommu_free_device (kfd->pdev); + } }int kgd2kfd_resume (struct kfd_dev *kfd)
@@ -243,6 +268,7 @@ int kgd2kfd_resume(struct kfd_dev *kfd)if (err <0 )return -ENXIO ;amd_iommu_set_invalidate_ctx_cb (kfd->pdev, iommu_pasid_shutdown_callback); + kfd->dqm->start (kfd->dqm); }return 0 ;
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c new file +995 -0
995 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h +43 -0
49 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +13 -0
@@ -430,6 +430,7 @@ struct kfd_process {struct kfd_process *kfd_create_process (const struct task_struct *);struct kfd_process *kfd_get_process (const struct task_struct *); +struct kfd_process_device *kfd_bind_process_to_device (struct kfd_dev *dev,struct kfd_process *p);void kfd_unbind_process_from_device (struct kfd_dev *dev,unsigned int pasid); struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, struct kfd_process *p,
@@ -485,6 +486,9 @@ void uninit_queue(struct queue *q);void print_queue_properties (struct queue_properties *q);void print_queue (struct queue *q); +struct mqd_manager *mqd_manager_init (enum KFD_MQD_TYPE type,struct kfd_dev *dev); +struct device_queue_manager *device_queue_manager_init (struct kfd_dev *dev); +void device_queue_manager_uninit (struct device_queue_manager *dqm);struct kernel_queue *kernel_queue_init (struct kfd_dev *dev,enum kfd_queue_type type);void kernel_queue_uninit (struct kernel_queue *kq);
@@ -503,6 +507,8 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);#define KFD_HIQ_TIMEOUT (500) +#define KFD_FENCE_COMPLETED (100) +#define KFD_FENCE_INIT (10)#define KFD_UNMAP_LATENCY (15)struct packet_manager {
@@ -513,6 +519,13 @@ struct packet_manager {struct kfd_mem_obj *ib_buffer_obj; }; +int pm_init (struct packet_manager *pm,struct device_queue_manager *dqm); +void pm_uninit (struct packet_manager *pm); +int pm_send_set_resources (struct packet_manager *pm,struct scheduling_resources *res); +int pm_send_runlist (struct packet_manager *pm,struct list_head *dqm_queues); +int pm_send_query_status (struct packet_manager *pm,uint64_t fence_address,uint32_t fence_value); +int pm_send_unmap_queue (struct packet_manager *pm,enum kfd_queue_type type, +enum kfd_preempt_type_filter mode,uint32_t filter_param,bool reset);void pm_release_ib (struct packet_manager *pm);uint64_t kfd_get_number_elems (struct kfd_dev *kfd);
Signature · 1 line
1.9.1
PATCH v4 20/23 amdkfd: Implement the create/destroy/update queue IOCTLs
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
v3: Removed the use of internal typedefs, fixed debug prints, added checks for parameters and moved to using doorbell address from user
v4: Extracted some of the code in the create queue ioctl to a different function that may be also called from other ioctls in the future. Also fixed the check of the ring size argument.
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 191 ++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 8 + .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 5 +- include/uapi/linux/kfd_ioctl.h | 7 +- 4 files changed, 205 insertions(+), 6 deletions(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +188 -3
@@ -117,19 +117,204 @@ static int kfd_open(struct inode *inode, struct file *filep)return 0 ; } +static int set_queue_properties_from_user (struct queue_properties *q_properties, +struct kfd_ioctl_create_queue_args *args) +{ +if (args->queue_percentage >KFD_MAX_QUEUE_PERCENTAGE ) { +pr_err ("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + +if (args->queue_priority >KFD_MAX_QUEUE_PRIORITY ) { +pr_err ("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n" ); +return -EINVAL ; + } + +if ((args->ring_base_address) && + (!access_ok (VERIFY_WRITE , args->ring_base_address,sizeof (uint64_t )))) { +pr_err ("kfd: can't access ring base address\n" ); +return -EFAULT ; + } + +if (!is_power_of_2 (args->ring_size) && (args->ring_size !=0 )) { +pr_err ("kfd: ring size must be a power of 2 or 0\n" ); +return -EINVAL ; + } + +if (!access_ok (VERIFY_WRITE , args->read_pointer_address,sizeof (uint32_t ))) { +pr_err ("kfd: can't access read pointer\n" ); +return -EFAULT ; + } + +if (!access_ok (VERIFY_WRITE , args->write_pointer_address,sizeof (uint32_t ))) { +pr_err ("kfd: can't access write pointer\n" ); +return -EFAULT ; + } + + q_properties->is_interop = false; + q_properties->queue_percent = args->queue_percentage; + q_properties->priority = args->queue_priority; + q_properties->queue_address = args->ring_base_address; + q_properties->queue_size = args->ring_size; + q_properties->read_ptr = (uint32_t *) args->read_pointer_address; + q_properties->write_ptr = (uint32_t *) args->write_pointer_address; + +pr_debug ("Queue Percentage (%d, %d)\n" , + q_properties->queue_percent, args->queue_percentage); + +pr_debug ("Queue Priority (%d, %d)\n" , + q_properties->priority, args->queue_priority); + +pr_debug ("Queue Address (0x%llX, 0x%llX)\n" , + q_properties->queue_address, args->ring_base_address); + +pr_debug ("Queue Size (0x%llX, %u)\n" , + q_properties->queue_size, args->ring_size); + +pr_debug ("Queue r/w Pointers (0x%llX, 0x%llX)\n" , + (uint64_t ) q_properties->read_ptr, + (uint64_t ) q_properties->write_ptr); + +return 0 ; +} +static long kfd_ioctl_create_queue (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_create_queue_args args; +struct kfd_dev *dev; +int err =0 ; +unsigned int queue_id; +struct kfd_process_device *pdd; +struct queue_properties q_properties; + +memset (&q_properties,0 ,sizeof (struct queue_properties )); + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +pr_debug ("kfd: creating queue ioctl\n" ); + + err =set_queue_properties_from_user (&q_properties, &args); +if (err) +return err; + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +mutex_lock (&p->mutex); + + pdd =kfd_bind_process_to_device (dev, p); +if (IS_ERR (pdd) <0 ) { + err =PTR_ERR (pdd); + goto err_bind_process; + } + +pr_debug ("kfd: creating queue for PASID %d on GPU 0x%x\n" , + p->pasid, + dev->id); + + err =pqm_create_queue (&p->pqm, dev, filep, &q_properties,0 ,KFD_QUEUE_TYPE_COMPUTE , &queue_id); +if (err !=0 ) + goto err_create_queue; + + args.queue_id = queue_id; + +/* Return gpu_id as doorbell offset for mmap usage */ + args.doorbell_offset = args.gpu_id <<PAGE_SHIFT ; + +if (copy_to_user (arg, &args,sizeof (args))) { + err = -EFAULT ; + goto err_copy_args_out; + } + +mutex_unlock (&p->mutex); + +pr_debug ("kfd: queue id %d was created successfully\n" , args.queue_id); + +pr_debug ("ring buffer address == 0x%016llX\n" , + args.ring_base_address); + +pr_debug ("read ptr address == 0x%016llX\n" , + args.read_pointer_address); + +pr_debug ("write ptr address == 0x%016llX\n" , + args.write_pointer_address); + +return 0 ; + +err_copy_args_out: +pqm_destroy_queue (&p->pqm, queue_id); +err_create_queue: +err_bind_process: +mutex_unlock (&p->mutex); +return err; }static int kfd_ioctl_destroy_queue (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +int retval; +struct kfd_ioctl_destroy_queue_args args; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +pr_debug ("kfd: destroying queue id %d for PASID %d\n" , + args.queue_id, + p->pasid); + +mutex_lock (&p->mutex); + + retval =pqm_destroy_queue (&p->pqm, args.queue_id); + +mutex_unlock (&p->mutex); +return retval; }static int kfd_ioctl_update_queue (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +int retval; +struct kfd_ioctl_update_queue_args args; +struct queue_properties properties; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +if (args.queue_percentage >KFD_MAX_QUEUE_PERCENTAGE ) { +pr_err ("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n" ); +return -EINVAL ; + } + +if (args.queue_priority >KFD_MAX_QUEUE_PRIORITY ) { +pr_err ("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n" ); +return -EINVAL ; + } + +if ((args.ring_base_address) && + (!access_ok (VERIFY_WRITE , args.ring_base_address,sizeof (uint64_t )))) { +pr_err ("kfd: can't access ring base address\n" ); +return -EFAULT ; + } + +if (!is_power_of_2 (args.ring_size) && (args.ring_size !=0 )) { +pr_err ("kfd: ring size must be a power of 2 or 0\n" ); +return -EINVAL ; + } + + properties.queue_address = args.ring_base_address; + properties.queue_size = args.ring_size; + properties.queue_percent = args.queue_percentage; + properties.priority = args.queue_priority; + +pr_debug ("kfd: updating queue id %d for PASID %d\n" , args.queue_id, p->pasid); + +mutex_lock (&p->mutex); + + retval =pqm_update_queue (&p->pqm, args.queue_id, &properties); + +mutex_unlock (&p->mutex); + +return retval; }static long kfd_ioctl_set_memory_policy (struct file *filep,struct kfd_process *p,void __user *arg)
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +8 -0
@@ -513,7 +513,15 @@ struct process_queue_node {int pqm_init (struct process_queue_manager *pqm,struct kfd_process *p);void pqm_uninit (struct process_queue_manager *pqm); +int pqm_create_queue (struct process_queue_manager *pqm, +struct kfd_dev *dev, +struct file *f, +struct queue_properties *properties, +unsigned int flags, +enum kfd_queue_type type, +unsigned int *qid);int pqm_destroy_queue (struct process_queue_manager *pqm,unsigned int qid); +int pqm_update_queue (struct process_queue_manager *pqm,unsigned int qid,struct queue_properties *p);/* Packet Manager */
drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c +4 -1
@@ -264,7 +264,10 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)pr_debug ("kfd: In Func %s\n" , __func__); pqn =get_queue_by_qid (pqm, qid); -BUG_ON (!pqn); +if (pqn ==NULL ) { +pr_err ("kfd: queue id does not match any known queue\n" ); +return -EINVAL ; + } dev =NULL ;if (pqn->kq)
include/uapi/linux/kfd_ioctl.h +5 -2
@@ -34,8 +34,11 @@ struct kfd_ioctl_get_version_args { };/* For kfd_ioctl_create_queue_args.queue_type. */ -#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 -#define KFD_IOC_QUEUE_TYPE_SDMA 1 +#define KFD_IOC_QUEUE_TYPE_COMPUTE 0 +#define KFD_IOC_QUEUE_TYPE_SDMA 1 + +#define KFD_MAX_QUEUE_PERCENTAGE 100 +#define KFD_MAX_QUEUE_PRIORITY 15struct kfd_ioctl_create_queue_args {uint64_t ring_base_address;/* to KFD */
Signature · 1 line
1.9.1
v4 cover AMDKFD Kernel Driver
Hi,
Here is the v4 patch set of amdkfd.
This version mainly contains fixes to the code published in v3 and changes to commit messages to reflect the fixes. In addition, I have added the latest version of a patch-set prepared by Joerg Roedel that allows the mm sub-system to handle TLBs which are external to the CPU (i.e handled by the IOMMU).
The patch-set is rebased over latest drm-next (3.17-rc5) and radeon's drm-next-3.18. Therefore, I removed some mm and IOMMU patches that were part of my tree in v3 as they are already merged into kernel 3.17
For people who like to review using git, the v4 patch set is located at:
http://cgit.freedesktop.org/~gabbayo/linux/?h=amdkfd-v4
Link to v3 cover letter:
http://lwn.net/Articles/607730/
Link to v2 cover letter:
http://lists.freedesktop.org/archives/dri-devel/2014-July/064011.html
Link to v1 cover letter:
http://lwn.net/Articles/605153/
Any comment / review is appreciated.
- Oded
Alexey Skidanov (1):
amdkfd: Implement the Get Process Aperture IOCTL
Andrew Lewycky (3):
amdkfd: Add basic modules to amdkfd
amdkfd: Add interrupt handling module
amdkfd: Implement the Set Memory Policy IOCTL
Ben Goz (8):
amdkfd: Add queue module
amdkfd: Add mqd_manager module
amdkfd: Add kernel queue module
amdkfd: Add module parameter of scheduling policy
amdkfd: Add packet manager module
amdkfd: Add process queue manager module
amdkfd: Add device queue manager module
amdkfd: Implement the create/destroy/update queue IOCTLs
Evgeny Pinchuk (2):
amdkfd: Add topology module to amdkfd
amdkfd: Implement the Get Clock Counters IOCTL
Oded Gabbay (9):
drm/radeon: reduce number of free VMIDs and pipes in KV drm/radeon/cik: Don't touch int of pipes 1-7 drm/radeon: Report doorbell configuration to amdkfd drm/radeon: adding synchronization for GRBM GFX drm/radeon: Add radeon <--> amdkfd interface Update MAINTAINERS and CREDITS files with amdkfd info
amdkfd: Add IOCTL set definitions of amdkfd
amdkfd: Add amdkfd skeleton driver
amdkfd: Add binding/unbinding calls to amd_iommu driver
CREDITS | 7 + MAINTAINERS | 10 + drivers/gpu/drm/radeon/Kconfig | 2 + drivers/gpu/drm/radeon/Makefile | 3 + drivers/gpu/drm/radeon/amdkfd/Kconfig | 10 + drivers/gpu/drm/radeon/amdkfd/Makefile | 14 + drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 221 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 520 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 300 +++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.c | 995 ++++++++++++++++ .../drm/radeon/amdkfd/kfd_device_queue_manager.h | 144 +++ drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++ drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 +++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c | 330 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h | 66 ++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 147 +++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 312 +++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 ++ drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c | 495 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h | 682 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h | 107 ++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 560 +++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 350 ++++++ .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 353 ++++++ drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 ++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 +++ drivers/gpu/drm/radeon/cik.c | 154 +-- drivers/gpu/drm/radeon/cik_reg.h | 65 ++ drivers/gpu/drm/radeon/cikd.h | 53 +- drivers/gpu/drm/radeon/radeon.h | 10 + drivers/gpu/drm/radeon/radeon_device.c | 32 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 525 +++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 +++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + include/uapi/linux/kfd_ioctl.h | 126 ++ 40 files changed, 9371 insertions(+), 95 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/Kconfig create mode 100644 drivers/gpu/drm/radeon/amdkfd/Makefile create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_device_queue_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_kernel_queue.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_module.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_packet_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_headers.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pm4_opcodes.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_priv.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h create mode 100644 include/uapi/linux/kfd_ioctl.h
Signature · 1 line
1.9.1
PATCH v4 2/23 drm/radeon/cik: Don't touch int of pipes 1-7
amdkfd should set interrupts for pipes 1-7.
--- drivers/gpu/drm/radeon/cik.c | 71 +------------------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-)
drivers/gpu/drm/radeon/cik.c +1 -70
@@ -7291,8 +7291,7 @@ static int cik_irq_init(struct radeon_device *rdev)int cik_irq_set (struct radeon_device *rdev) {u32 cp_int_cntl; -u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3; -u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3; +u32 cp_m1p0;u32 crtc1 =0 , crtc2 =0 , crtc3 =0 , crtc4 =0 , crtc5 =0 , crtc6 =0 ;u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;u32 grbm_int_cntl =0 ;
@@ -7326,13 +7325,6 @@ int cik_irq_set(struct radeon_device *rdev) dma_cntl1 =RREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET ) & ~TRAP_ENABLE ; cp_m1p0 =RREG32 (CP_ME1_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p1 =RREG32 (CP_ME1_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p2 =RREG32 (CP_ME1_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p3 =RREG32 (CP_ME1_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p0 =RREG32 (CP_ME2_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p1 =RREG32 (CP_ME2_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p2 =RREG32 (CP_ME2_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p3 =RREG32 (CP_ME2_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ;if (rdev->flags &RADEON_IS_IGP ) thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL) &
@@ -7354,33 +7346,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe);break ;
@@ -7397,33 +7362,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe);break ;
@@ -7512,13 +7450,6 @@ int cik_irq_set(struct radeon_device *rdev)WREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET , dma_cntl1);WREG32 (CP_ME1_PIPE0_INT_CNTL , cp_m1p0); -WREG32 (CP_ME1_PIPE1_INT_CNTL , cp_m1p1); -WREG32 (CP_ME1_PIPE2_INT_CNTL , cp_m1p2); -WREG32 (CP_ME1_PIPE3_INT_CNTL , cp_m1p3); -WREG32 (CP_ME2_PIPE0_INT_CNTL , cp_m2p0); -WREG32 (CP_ME2_PIPE1_INT_CNTL , cp_m2p1); -WREG32 (CP_ME2_PIPE2_INT_CNTL , cp_m2p2); -WREG32 (CP_ME2_PIPE3_INT_CNTL , cp_m2p3);WREG32 (GRBM_INT_CNTL , grbm_int_cntl);
Signature · 1 line
1.9.1
PATCH v4 4/23 drm/radeon: adding synchronization for GRBM GFX
In reply to Oded GabbayImplementing a lock for selecting and accessing shader engines and arrays. This lock will make sure that radeon and amdkfd are not colliding when accessing shader engines and arrays with GRBM_GFX_INDEX register.
--- drivers/gpu/drm/radeon/cik.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon.h | 2 ++ drivers/gpu/drm/radeon/radeon_device.c | 1 + 3 files changed, 29 insertions(+)
drivers/gpu/drm/radeon/cik.c +26 -0
@@ -1563,6 +1563,8 @@ static const u32 godavari_golden_registers[] =static void cik_init_golden_registers (struct radeon_device *rdev) { +/* Some of the registers might be dependant on GRBM_GFX_INDEX */ +mutex_lock (&rdev->grbm_idx_mutex);switch (rdev->family) {case CHIP_BONAIRE : radeon_program_register_sequence(rdev,
@@ -1637,6 +1639,7 @@ static void cik_init_golden_registers(struct radeon_device *rdev)default :break ; } +mutex_unlock (&rdev->grbm_idx_mutex); }/**
@@ -3419,6 +3422,7 @@ static void cik_setup_rb(struct radeon_device *rdev,u32 disabled_rbs =0 ;u32 enabled_rbs =0 ; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {for (j =0 ; j < sh_per_se; j++) {cik_select_se_sh (rdev, i, j);
@@ -3430,6 +3434,7 @@ static void cik_setup_rb(struct radeon_device *rdev, } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =1 ;for (i =0 ; i < max_rb_num_per_se * se_num; i++) {
@@ -3440,6 +3445,7 @@ static void cik_setup_rb(struct radeon_device *rdev, rdev->config.cik.backend_enable_mask = enabled_rbs; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {cik_select_se_sh (rdev, i,0xffffffff ); data =0 ;
@@ -3467,6 +3473,7 @@ static void cik_setup_rb(struct radeon_device *rdev,WREG32 (PA_SC_RASTER_CONFIG , data); }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); }/**
@@ -3684,6 +3691,12 @@ static void cik_gpu_init(struct radeon_device *rdev)/* set HW defaults for 3D engine */ WREG32 (CP_MEQ_THRESHOLDS ,MEQ1_START (0x30 ) |MEQ2_START (0x60 )); +mutex_lock (&rdev->grbm_idx_mutex); +/* +* making sure that the following register writes will be broadcasted +* to all the shaders +*/ +cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (SX_DEBUG_1 ,0x20 );WREG32 (TA_CNTL_AUX ,0x00010000 );
@@ -3739,6 +3752,7 @@ static void cik_gpu_init(struct radeon_device *rdev)WREG32 (PA_CL_ENHANCE ,CLIP_VTX_REORDER_ENA |NUM_CLIP_SEQ (3 ));WREG32 (PA_SC_ENHANCE ,ENABLE_PA_SC_OUT_OF_ORDER ); +mutex_unlock (&rdev->grbm_idx_mutex);udelay (50 ); }
@@ -6062,6 +6076,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)u32 i, j, k;u32 mask; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < rdev->config.cik.max_shader_engines; i++) {for (j =0 ; j < rdev->config.cik.max_sh_per_se; j++) {cik_select_se_sh (rdev, i, j);
@@ -6073,6 +6088,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev) } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =SE_MASTER_BUSY_MASK |GC_MASTER_BUSY |TC0_MASTER_BUSY |TC1_MASTER_BUSY ;for (k =0 ; k < rdev->usec_timeout; k++) {
@@ -6207,10 +6223,12 @@ static int cik_rlc_resume(struct radeon_device *rdev)WREG32 (RLC_LB_CNTR_INIT ,0 );WREG32 (RLC_LB_CNTR_MAX ,0x00008000 ); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_LB_INIT_CU_MASK ,0xffffffff );WREG32 (RLC_LB_PARAMS ,0x00600408 );WREG32 (RLC_LB_CNTL ,0x80000004 ); +mutex_unlock (&rdev->grbm_idx_mutex);WREG32 (RLC_MC_CNTL ,0 );WREG32 (RLC_UCODE_CNTL ,0 );
@@ -6277,11 +6295,13 @@ static void cik_enable_cgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); tmp2 =BPM_ADDR_MASK |CGCG_OVERRIDE_0 |CGLS_ENABLE ;WREG32 (RLC_SERDES_WR_CTRL , tmp2); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);
@@ -6323,11 +6343,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_0 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);
@@ -6371,11 +6393,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_1 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp); }
@@ -6804,10 +6828,12 @@ static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)u32 mask =0 , tmp, tmp1;int i; +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev, se, sh); tmp =RREG32 (CC_GC_SHADER_ARRAY_CONFIG ); tmp1 =RREG32 (GC_USER_SHADER_ARRAY_CONFIG );cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); tmp &=0xffff0000 ;
drivers/gpu/drm/radeon/radeon.h +2 -0
@@ -2386,6 +2386,8 @@ struct radeon_device {struct radeon_atcs atcs;/* srbm instance registers */ struct mutex srbm_mutex; +/* GRBM index mutex. Protects concurrents access to GRBM index */ +struct mutex grbm_idx_mutex;/* clock, powergating flags */ u32 cg_flags;u32 pg_flags;
drivers/gpu/drm/radeon/radeon_device.c +1 -0
@@ -1299,6 +1299,7 @@ int radeon_device_init(struct radeon_device *rdev,mutex_init (&rdev->pm.mutex);mutex_init (&rdev->gpu_clock_mutex);mutex_init (&rdev->srbm_mutex); +mutex_init (&rdev->grbm_idx_mutex);init_rwsem (&rdev->pm.mclk_lock);init_rwsem (&rdev->exclusive_lock);init_waitqueue_head (&rdev->irq.vblank_queue);
Signature · 1 line
1.9.1
PATCH v4 3/23 drm/radeon: Report doorbell configuration to amdkfd
In reply to Oded Gabbayradeon and amdkfd share the doorbell aperture.
radeon sets it up, takes the doorbells required for its own rings and reports the setup to amdkfd.
radeon reserved doorbells are at the start of the doorbell aperture.
--- drivers/gpu/drm/radeon/radeon.h | 4 ++++ drivers/gpu/drm/radeon/radeon_device.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
drivers/gpu/drm/radeon/radeon.h +4 -0
@@ -697,6 +697,10 @@ struct radeon_doorbell {int radeon_doorbell_get (struct radeon_device *rdev,u32 *page);void radeon_doorbell_free (struct radeon_device *rdev,u32 doorbell); +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset);/* * IRQS.
drivers/gpu/drm/radeon/radeon_device.c +31 -0
@@ -373,6 +373,37 @@ void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell)__clear_bit (doorbell, rdev->doorbell.used); } +/** +* radeon_doorbell_get_kfd_info - Report doorbell configuration required to +* setup KFD +* +* @rdev: radeon_device pointer +* @aperture_base: output returning doorbell aperture base physical address +* @aperture_size: output returning doorbell aperture size in bytes +* @start_offset: output returning # of doorbell bytes reserved for radeon. +* +* Radeon and the KFD share the doorbell aperture. Radeon sets it up, +* takes doorbells required for its own rings and reports the setup to KFD. +* Radeon reserved doorbells are at the start of the doorbell aperture. +*/ +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset) +{ +/* The first num_doorbells are used by radeon. +* KFD takes whatever's left in the aperture. */ +if (rdev->doorbell.size > rdev->doorbell.num_doorbells *sizeof (u32)) { + *aperture_base = rdev->doorbell.base; + *aperture_size = rdev->doorbell.size; + *start_offset = rdev->doorbell.num_doorbells *sizeof (u32); + }else { + *aperture_base =0 ; + *aperture_size =0 ; + *start_offset =0 ; + } +} +/* * radeon_wb_*() * Writeback is the the method by which the the GPU updates special pages
Signature · 1 line
1.9.1
PATCH v4 5/23 drm/radeon: Add radeon <--> amdkfd interface
In reply to Oded GabbayThis patch adds the interface between the radeon driver and the amdkfd driver. The interface implementation is contained in radeon_kfd.c and radeon_kfd.h.
The interface itself is represented by a pointer to struct kfd_dev. The pointer is located inside radeon_device structure.
All the register accesses that amdkfd need are done using this interface. This allows us to avoid direct register accesses in amdkfd proper, while also avoiding locking between amdkfd and radeon.
The single exception is the doorbells that are used in both of the drivers. However, because they are located in separate pci bar pages, the danger of sharing registers between the drivers is minimal.
Having said that, we are planning to move the doorbells as well to radeon.
v3:
Add interface for sa manager init and fini. The init function will allocate a buffer on system memory and pin it to the GART address space via the radeon sa manager.
All mappings of buffers to GART address space are done via the radeon sa manager. The interface of allocate memory will use the radeon sa manager to sub allocate from the single buffer that was allocated during the init function.
Change lower_32/upper_32 calls to use linux macros
Add documentation for the interface
v4:
Change ptr field type in kgd_mem from uint32_t* to void* to match to type that is returned by radeon_sa_bo_cpu_addr
--- drivers/gpu/drm/radeon/Makefile | 1 + drivers/gpu/drm/radeon/cik.c | 9 + drivers/gpu/drm/radeon/cik_reg.h | 65 +++++ drivers/gpu/drm/radeon/cikd.h | 51 +++- drivers/gpu/drm/radeon/radeon.h | 4 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 538 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 ++++++++++++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + 9 files changed, 856 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.h
drivers/gpu/drm/radeon/Makefile +1 -0
@@ -104,6 +104,7 @@ radeon-y += \ radeon_vce.o \ vce_v1_0.o \ vce_v2_0.o \ + radeon_kfd.o radeon-$(CONFIG_COMPAT) += radeon_ioc32.o radeon-$(CONFIG_VGA_SWITCHEROO) += radeon_atpx_handler.o
drivers/gpu/drm/radeon/cik.c +9 -0
@@ -32,6 +32,7 @@#include "cik_blit_shaders.h" #include "radeon_ucode.h" #include "clearstate_ci.h" +#include "radeon_kfd.h" MODULE_FIRMWARE ("radeon/BONAIRE_pfp.bin" );MODULE_FIRMWARE ("radeon/BONAIRE_me.bin" );
@@ -7792,6 +7793,9 @@ restart_ih:while (rptr != wptr) {/* wptr/rptr are in bytes! */ ring_index = rptr /4 ; + +radeon_kfd_interrupt (rdev, (const void *) &rdev->ih.ring[ring_index]); + src_id =le32_to_cpu (rdev->ih.ring[ring_index]) &0xff ; src_data =le32_to_cpu (rdev->ih.ring[ring_index +1 ]) &0xfffffff ; ring_id =le32_to_cpu (rdev->ih.ring[ring_index +2 ]) &0xff ;
@@ -8481,6 +8485,10 @@ static int cik_startup(struct radeon_device *rdev)if (r)return r; + r =radeon_kfd_resume (rdev); +if (r) +return r; +return 0 ; }
@@ -8529,6 +8537,7 @@ int cik_resume(struct radeon_device *rdev)*/ int cik_suspend (struct radeon_device *rdev) { +radeon_kfd_suspend (rdev);radeon_pm_suspend (rdev);dce6_audio_fini (rdev);radeon_vm_manager_fini (rdev);
drivers/gpu/drm/radeon/cik_reg.h +65 -0
69 lines not on this page · raw message
drivers/gpu/drm/radeon/cikd.h +50 -1
78 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon.h +4 -0
@@ -2400,6 +2400,10 @@ struct radeon_device {u64 vram_pin_size;u64 gart_pin_size; +/* amdkfd interface */ +struct kfd_dev *kfd; +struct radeon_sa_manager kfd_bo; +struct mutex mn_lock;DECLARE_HASHTABLE (mn_hash,7 ); };
drivers/gpu/drm/radeon/radeon_drv.c +5 -0
@@ -39,6 +39,8 @@#include <linux/pm_runtime.h> #include <linux/vga_switcheroo.h> #include "drm_crtc_helper.h" +#include "radeon_kfd.h" +/* * KMS wrapper. * - 2.0.0 - initial interface
@@ -647,12 +649,15 @@ static int __init radeon_init(void)#endif } +radeon_kfd_init (); +/* let modprobe override vga console setting */ return drm_pci_init (driver, pdriver); } static void __exit radeon_exit(void) { +radeon_kfd_fini ();drm_pci_exit (driver, pdriver);radeon_unregister_atpx_handler (); }
drivers/gpu/drm/radeon/radeon_kfd.c new file +538 -0
538 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kfd.h new file +177 -0
177 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kms.c +7 -0
@@ -34,6 +34,8 @@#include <linux/slab.h> #include <linux/pm_runtime.h> +#include "radeon_kfd.h" +#if defined(CONFIG_VGA_SWITCHEROO )bool radeon_has_atpx (void );#else
@@ -63,6 +65,8 @@ int radeon_driver_unload_kms(struct drm_device *dev)pm_runtime_get_sync (dev->dev); +radeon_kfd_device_fini (rdev); +radeon_acpi_fini (rdev);radeon_modeset_fini (rdev);
@@ -142,6 +146,9 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) "Error during ACPI methods call\n"); } +radeon_kfd_device_probe (rdev); +radeon_kfd_device_init (rdev); +if (radeon_is_px (dev)) {pm_runtime_use_autosuspend (dev->dev);pm_runtime_set_autosuspend_delay (dev->dev,5000 );
Signature · 1 line
1.9.1
PATCH v4 13/23 amdkfd: Add mqd_manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The mqd_manager module handles MQD data structures.
MQD stands for Memory Queue Descriptor, which is used by the H/W to keep the usermode queue state in memory.
v3:
Removed new typedefs
Removed pragma pack 4
Remove cik_mqds.h file
Changed lower_32/upper_32 calls to use linux macros Used new gart allocation functions
Added documentation
v4:
Added missing initialization of the addr field in init_mqd()
Setting the hqd persistent.preload_req bit ON so that when queues switches on/off, their context will kept and read from the mqd when the cp reassign them, and thus the dispatched workload context kept consistent without any interrupts.
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/cik_regs.h | 221 +++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c | 312 ++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h | 88 +++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 11 + 5 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/cik_regs.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -6,6 +6,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o kfd_queue.o + kfd_process.o kfd_queue.o kfd_mqd_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/cik_regs.h new file +221 -0
221 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.c new file +312 -0
312 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_mqd_manager.h new file +88 -0
88 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +11 -0
@@ -237,6 +237,17 @@ struct queue {struct kfd_dev *device; }; +/* +* Please read the kfd_mqd_manager.h description. +*/ +enum KFD_MQD_TYPE { +KFD_MQD_TYPE_CIK_COMPUTE =0 ,/* for no cp scheduling */ +KFD_MQD_TYPE_CIK_HIQ ,/* for hiq */ +KFD_MQD_TYPE_CIK_CP ,/* for cp queues and diq */ +KFD_MQD_TYPE_CIK_SDMA ,/* for sdma queues */ +KFD_MQD_TYPE_MAX +}; +/* Data that is per-process-per device. */ struct kfd_process_device {/*
Signature · 1 line
1.9.1
PATCH v4 22/23 amdkfd: Implement the Get Clock Counters IOCTL
In reply to Oded GabbayFrom: Evgeny Pinchuk <[email protected]>
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +28 -1
@@ -373,7 +373,34 @@ out:static long kfd_ioctl_get_clock_counters (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_get_clock_counters_args args; +struct kfd_dev *dev; +struct timespec time; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +/* Reading GPU clock counter from KGD */ + args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter (dev->kgd); + +/* No access to rdtsc. Using raw monotonic time */ +getrawmonotonic (&time); + args.cpu_clock_counter = (uint64_t )timespec_to_ns (&time); + +get_monotonic_boottime (&time); + args.system_clock_counter = (uint64_t )timespec_to_ns (&time); + +/* Since the counter is in nano-seconds we use 1GHz frequency */ + args.system_clock_freq =1000000000 ; + +if (copy_to_user (arg, &args,sizeof (args))) +return -EFAULT ; + +return 0 ; }
Signature · 1 line
1.9.1
PATCH v4 10/23 amdkfd: Add basic modules to amdkfd
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
This patch adds the process module and three helper modules:
- kfd_process, which handles process which open /dev/kfd
- kfd_doorbell, which provides helper functions for doorbell allocation, release and mapping to userspace
- kfd_pasid, which provides helper functions for pasid allocation and release
- kfd_aperture, which provides helper functions for managing the LDS, Local GPU memory and Scratch memory apertures of the process
This patch only contains the basic kfd_process module, which doesn't contain the reference to the queue scheduler. This was done to allow easier code review.
Also, this patch doesn't contain the calls to the IOMMU driver for binding the pasid to the device. Again, this was done to allow easier code review
The kfd_process object is created when a process opens /dev/kfd and is closed when the mm_struct of that process is teared-down.
v3:
Removed kfd_vidmem.c file
Replaced direct mmput call to mmu_notifier release Removed typedefs
Moved bool field to end of the structure
Added new kernel params for gart usage limitation Added initialization of sa manager
Fixed debug messages
Remove support for LDS in 32 bit
Changed code to support mmap of doorbell pages from userspace Added documentation for apertures
v4:
Replaced RCU by SRCU for kfd_process list management
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 4 +- drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c | 350 +++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 31 ++- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 45 +++- drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c | 236 ++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 32 ++- drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c | 95 ++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 141 +++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 322 ++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_kfd.c | 21 +- 10 files changed, 1250 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process.c
drivers/gpu/drm/radeon/amdkfd/Makefile +3 -1
@@ -4,6 +4,8 @@ ccflags-y := -Iinclude/drm -amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ + kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ + kfd_process.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_aperture.c new file +350 -0
350 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +29 -2
@@ -38,6 +38,7 @@static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *); +static int kfd_mmap (struct file *,struct vm_area_struct *);static const char kfd_dev_name[] ="kfd" ;
@@ -46,6 +47,7 @@ static const struct file_operations kfd_fops = { .unlocked_ioctl = kfd_ioctl, .compat_ioctl = kfd_ioctl, .open = kfd_open, + .mmap = kfd_mmap, };static int kfd_char_dev_major =-1 ;
@@ -96,9 +98,22 @@ struct device *kfd_chardev(void)static int kfd_open (struct inode *inode,struct file *filep) { +struct kfd_process *process; +if (iminor (inode) !=0 )return -ENODEV ; + process =kfd_create_process (current); +if (IS_ERR (process)) +return PTR_ERR (process); + + process->is_32bit_user_mode =is_compat_task (); + +dev_dbg (kfd_device,"process %d opened, compat mode (32 bit) - %d\n" , + process->pasid, process->is_32bit_user_mode); + +kfd_init_apertures (process); +return 0 ; }
@@ -142,8 +157,9 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)"ioctl cmd 0x%x (#%d), arg 0x%lx\n" , cmd, _IOC_NR(cmd), arg); -/* TODO: add function that retrieves process */ - process =NULL ; + process =kfd_get_process (current); +if (IS_ERR (process)) +return PTR_ERR (process);switch (cmd) {case KFD_IOC_CREATE_QUEUE :
@@ -185,3 +201,14 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)return err; } + +static int kfd_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct kfd_process *process; + + process =kfd_get_process (current); +if (IS_ERR (process)) +return PTR_ERR (process); + +return kfd_doorbell_mmap (process, vma); +}
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +39 -6
74 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_doorbell.c new file +236 -0
236 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +31 -1
@@ -22,7 +22,6 @@#include <linux/module.h> #include <linux/sched.h> -#include <linux/notifier.h> #include <linux/moduleparam.h> #include <linux/device.h> #include "kfd_priv.h"
@@ -46,6 +45,16 @@ static const struct kgd2kfd_calls kgd2kfd = { .resume = kgd2kfd_resume, }; +int max_num_of_processes =KFD_MAX_NUM_OF_PROCESSES_DEFAULT ; +module_param (max_num_of_processes, int,0444 ); +MODULE_PARM_DESC (max_num_of_processes, +"Kernel cmdline parameter that defines the amdkfd maximum number of supported processes" ); + +int max_num_of_queues_per_process =KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT ; +module_param (max_num_of_queues_per_process, int,0444 ); +MODULE_PARM_DESC (max_num_of_queues_per_process, +"Kernel cmdline parameter that defines the amdkfd maximum number of supported queues per process" ); +bool kgd2kfd_init (unsigned interface_version,const struct kfd2kgd_calls *f2g,const struct kgd2kfd_calls **g2f)
@@ -69,6 +78,24 @@ static int __init kfd_module_init(void) {int err; +/* Verify module parameters */ +if ((max_num_of_processes <0 ) || + (max_num_of_processes >KFD_MAX_NUM_OF_PROCESSES )) { +pr_err ("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n" ); +return -1 ; + } + +if ((max_num_of_queues_per_process <0 ) || + (max_num_of_queues_per_process > +KFD_MAX_NUM_OF_QUEUES_PER_PROCESS )) { +pr_err ("kfd: max_num_of_queues_per_process must be between 0 to KFD_MAX_NUM_OF_QUEUES_PER_PROCESS\n" ); +return -1 ; + } + + err =kfd_pasid_init (); +if (err <0 ) + goto err_pasid; + err =kfd_chardev_init ();if (err <0 ) goto err_ioctl;
@@ -84,6 +111,8 @@ static int __init kfd_module_init(void) err_topology:kfd_chardev_exit (); err_ioctl: +kfd_pasid_exit (); +err_pasid:return err; }
@@ -91,6 +120,7 @@ static void __exit kfd_module_exit(void) {kfd_topology_shutdown ();kfd_chardev_exit (); +kfd_pasid_exit ();dev_info (kfd_device,"Removed module\n" ); }
drivers/gpu/drm/radeon/amdkfd/kfd_pasid.c new file +95 -0
95 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +141 -0
178 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_process.c new file +322 -0
322 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_kfd.c +4 -17
@@ -177,8 +177,7 @@ static u32 pool_to_domain(enum kgd_memory_pool p)static int init_sa_manager (struct kgd_dev *kgd,unsigned int size) {struct radeon_device *rdev = (struct radeon_device *)kgd; -u64 max_offset[4 ]; -int r, i; +int r;BUG_ON (kgd ==NULL );
@@ -191,21 +190,9 @@ static int init_sa_manager(struct kgd_dev *kgd, unsigned int size)if (r)return r; -/* Try to pin buffer in first 8MB, 16MB or 64MB of GART */ - max_offset[0 ] =roundup (size,8 *1024 *1024 ); - max_offset[1 ] =roundup (size,16 *1024 *1024 ); - max_offset[2 ] =roundup (size,64 *1024 *1024 ); - max_offset[3 ] =0 ; - -for (i =0 ; i <4 ; i++) { - - r =radeon_sa_bo_manager_start (rdev, &rdev->kfd_bo, - max_offset[i]); -if (!r) -return r; - } - -radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo); + r =radeon_sa_bo_manager_start (rdev, &rdev->kfd_bo); +if (r) +radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo);return r; }
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 23/23 amdkfd: Implement the Get Process Aperture IOCTL
In reply to Oded GabbayFrom: Alexey Skidanov <[email protected]>
v3: Fixed debug messages
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 47 ++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 5 +++ 2 files changed, 51 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +46 -1
@@ -406,7 +406,52 @@ static long kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_processstatic int kfd_ioctl_get_process_apertures (struct file *filp,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_get_process_apertures_args args; +struct kfd_process_device *pdd; + +dev_dbg (kfd_device,"get apertures for PASID %d" , p->pasid); + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + + args.num_of_nodes =0 ; + +mutex_lock (&p->mutex); + +/*if the process-device list isn't empty*/ +if (kfd_has_process_device_data (p)) { +/* Run over all pdd of the process */ + pdd =kfd_get_first_process_device_data (p); +do { + + args.process_apertures[args.num_of_nodes].gpu_id = pdd->dev->id; + args.process_apertures[args.num_of_nodes].lds_base = pdd->lds_base; + args.process_apertures[args.num_of_nodes].lds_limit = pdd->lds_limit; + args.process_apertures[args.num_of_nodes].gpuvm_base = pdd->gpuvm_base; + args.process_apertures[args.num_of_nodes].gpuvm_limit = pdd->gpuvm_limit; + args.process_apertures[args.num_of_nodes].scratch_base = pdd->scratch_base; + args.process_apertures[args.num_of_nodes].scratch_limit = pdd->scratch_limit; + +dev_dbg (kfd_device,"node id %u\n" , args.num_of_nodes); +dev_dbg (kfd_device,"gpu id %u\n" , pdd->dev->id); +dev_dbg (kfd_device,"lds_base %llX\n" , pdd->lds_base); +dev_dbg (kfd_device,"lds_limit %llX\n" , pdd->lds_limit); +dev_dbg (kfd_device,"gpuvm_base %llX\n" , pdd->gpuvm_base); +dev_dbg (kfd_device,"gpuvm_limit %llX\n" , pdd->gpuvm_limit); +dev_dbg (kfd_device,"scratch_base %llX\n" , pdd->scratch_base); +dev_dbg (kfd_device,"scratch_limit %llX\n" , pdd->scratch_limit); + + args.num_of_nodes++; + }while ((pdd =kfd_get_next_process_device_data (p, pdd)) !=NULL && + (args.num_of_nodes <NUM_OF_SUPPORTED_GPUS )); + } + +mutex_unlock (&p->mutex); + +if (copy_to_user (arg, &args,sizeof (args))) +return -EFAULT ; + +return 0 ; }static long kfd_ioctl (struct file *filep,unsigned int cmd,unsigned long arg)
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +5 -0
@@ -445,6 +445,11 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,struct kfd_process *p, int create_pdd); +/* Process device data iterator */ +struct kfd_process_device *kfd_get_first_process_device_data (struct kfd_process *p); +struct kfd_process_device *kfd_get_next_process_device_data (struct kfd_process *p,struct kfd_process_device *pdd); +bool kfd_has_process_device_data (struct kfd_process *p); +/* PASIDs */ int kfd_pasid_init (void );void kfd_pasid_exit (void );
Signature · 1 line
1.9.1
PATCH v4 17/23 amdkfd: Add process queue manager module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue scheduler divides into two sections, one section is process bounded and the other section is device bounded.
The process bounded section is handled by this module. The PQM handles usermode queue setup, updates and tear-down.
v3:
Used kernel parameter to limit queues per process instead of define Added use of doorbell address from user
v4:
Modified pqm_create_queue so that only when creating usermode queues the driver should return the queue properties to the userspace.
Added an info message print when no more queues can be opened because of the queue per process limitation
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 17 + drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 16 + .../drm/radeon/amdkfd/kfd_process_queue_manager.c | 350 +++++++++++++++++++++ 4 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -7,6 +7,7 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ - kfd_kernel_queue.o kfd_packet_manager.o + kfd_kernel_queue.o kfd_packet_manager.o \ + kfd_process_queue_manager.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +17 -0
@@ -365,6 +365,9 @@ struct kfd_process_device {struct kfd_dev *dev; +/* per-process-per device QCM data structure */ +struct qcm_process_device qpd; +/*Apertures*/ uint64_t lds_base;uint64_t lds_limit;
@@ -410,6 +413,8 @@ struct kfd_process {*/ struct list_head per_device_data; +struct process_queue_manager pqm; +/* The process's queues. */ size_t queue_array_size;
@@ -477,11 +482,23 @@ inline uint32_t upper_32(uint64_t x);int init_queue (struct queue **q,struct queue_properties properties);void uninit_queue (struct queue *q); +void print_queue_properties (struct queue_properties *q);void print_queue (struct queue *q);struct kernel_queue *kernel_queue_init (struct kfd_dev *dev,enum kfd_queue_type type);void kernel_queue_uninit (struct kernel_queue *kq); +/* Process Queue Manager */ +struct process_queue_node { +struct queue *q; +struct kernel_queue *kq; +struct list_head process_queue_list; +}; + +int pqm_init (struct process_queue_manager *pqm,struct kfd_process *p); +void pqm_uninit (struct process_queue_manager *pqm); +int pqm_destroy_queue (struct process_queue_manager *pqm,unsigned int qid); +/* Packet Manager */ #define KFD_HIQ_TIMEOUT (500)
drivers/gpu/drm/radeon/amdkfd/kfd_process.c +16 -0
@@ -153,6 +153,9 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,mutex_lock (&p->mutex); +/* In case our notifier is called before IOMMU notifier */ +pqm_uninit (&p->pqm); +list_for_each_entry_safe (pdd, temp, &p->per_device_data, per_device_list) {amd_iommu_unbind_pasid (pdd->dev->pdev, p->pasid);list_del (&pdd->per_device_list);
@@ -217,8 +220,16 @@ static struct kfd_process *create_process(const struct task_struct *thread)INIT_LIST_HEAD (&process->per_device_data); + err =pqm_init (&process->pqm, process); +if (err !=0 ) + goto err_process_pqm_init; +return process; +err_process_pqm_init: +hash_del_rcu (&process->kfd_processes); +synchronize_rcu (); +mmu_notifier_unregister_no_release (&process->mmu_notifier, process->mm); err_mmu_notifier:kfd_pasid_free (process->pasid); err_alloc_pasid:
@@ -243,6 +254,9 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, pdd =kzalloc (sizeof (*pdd),GFP_KERNEL );if (pdd !=NULL ) { pdd->dev = dev; +INIT_LIST_HEAD (&pdd->qpd.queues_list); +INIT_LIST_HEAD (&pdd->qpd.priv_queue_list); + pdd->qpd.dqm = dev->dqm;list_add (&pdd->per_device_list, &p->per_device_data); } }
@@ -302,6 +316,8 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid)mutex_lock (&p->mutex); +pqm_uninit (&p->pqm); + pdd =kfd_get_process_device_data (dev, p,0 );/*
drivers/gpu/drm/radeon/amdkfd/kfd_process_queue_manager.c new file +350 -0
350 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 15/23 amdkfd: Add module parameter of scheduling policy
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
This patch adds a new parameter to the amdkfd driver. This parameter enables the user to select the scheduling policy of the CP. The choices are:
* CP Scheduling with support for over-subscription
* CP Scheduling without support for over-subscription
* Without CP Scheduling
Note that the third option (Without CP scheduling) is only for debug purposes and bringup of new H/W. As such, it is _not_ guaranteed to work at all times on all H/W versions.
v3: Fixed description of parameter, changed the permissions to read_only, added a verification of the value and added documentation
--- drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 12 ++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +12 -0
@@ -45,6 +45,11 @@ static const struct kgd2kfd_calls kgd2kfd = { .resume = kgd2kfd_resume, }; +int sched_policy =KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION ; +module_param (sched_policy, int,0444 ); +MODULE_PARM_DESC (sched_policy, +"Kernel cmdline parameter that defines the amdkfd scheduling policy" ); +int max_num_of_processes =KFD_MAX_NUM_OF_PROCESSES_DEFAULT ;module_param (max_num_of_processes, int,0444 ); MODULE_PARM_DESC(max_num_of_processes,
@@ -79,6 +84,13 @@ static int __init kfd_module_init(void)int err;/* Verify module parameters */ +if ((sched_policy <KFD_SCHED_POLICY_HWS ) || + (sched_policy >KFD_SCHED_POLICY_NO_HWS )) { +pr_err ("kfd: sched_policy has invalid value\n" ); +return -1 ; + } + +/* Verify module parameters */ if ((max_num_of_processes <0 ) || (max_num_of_processes >KFD_MAX_NUM_OF_PROCESSES )) {pr_err ("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n" );
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +29 -0
@@ -65,6 +65,35 @@ extern int max_num_of_queues_per_process;#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 +/* Kernel module parameter to specify the scheduling policy */ +extern int sched_policy; + +/** +* enum kfd_sched_policy +* +* @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp) +* scheduling. In this scheduling mode we're using the firmware code to schedule +* the user mode queues and kernel queues such as HIQ and DIQ. +* the HIQ queue is used as a special queue that dispatches the configuration to +* the cp and the user mode queues list that are currently running. +* the DIQ queue is a debugging queue that dispatches debugging commands to the +* firmware. +* in this scheduling mode user mode queues over subscription feature is enabled. +* +* @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over +* subscription feature disabled. +* +* @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly +* set the command processor registers and sets the queues "manually". This mode +* is used *ONLY* for debugging proposes. +* +*/ +enum kfd_sched_policy { +KFD_SCHED_POLICY_HWS =0 , +KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION , +KFD_SCHED_POLICY_NO_HWS +}; +enum cache_policy { cache_policy_coherent, cache_policy_noncoherent
Signature · 1 line
1.9.1
PATCH v4 9/23 amdkfd: Add topology module to amdkfd
In reply to Oded GabbayFrom: Evgeny Pinchuk <[email protected]>
This patch adds the topology module to the driver. The topology is exposed to userspace through the sysfs.
The calls to add and remove a device to/from topology are done by the radeon driver.
v3:
The CPU information, that is provided in the topology section of the amdkfd driver, is extracted from the CRAT table. Unlike the CPU information located in /sys/devices/system/cpu/cpu*, which is extracted from the SRAT table.
While the CPU information provided by the CRAT and the SRAT tables might be identical, the node topology might be different. The SRAT table contains the topology of CPU nodes only. The CRAT table contains the topology of CPU and GPU nodes together (and can be interleaved). For example CPU node 1 in SRAT can be CPU node 3 in CRAT. Furthermore it's worth to mention that the CRAT table contains only HSA compatible nodes (nodes which are compliant with the HSA spec).
To recap, amdkfd exposes a different kind of topology than the one exposed by /sys/devices/system/cpu/cpu even though it may contain similar information.
v4:
The topology module doesn't support uevent handling and doesn't notify the userspace about runtime modifications. It is up to the userspace to acquire snapshots of the topology information created by the amdkfd and exposed in sysfs.
The following is an example of how the topology looks on a Kaveri A10-7850K system with amdkfd installed:
/sys/devices/virtual/kfd/kfd/
|
--- topology/
|
|--- generation_id
|--- system_properties
|--- nodes/
|
|--- 0/
|
|--- gpu_id
|--- name
|--- properties
|--- caches/
|
|--- 0/
|
|--- properties
|--- 1/
|
|--- properties
|--- 2/
|
|--- properties
|--- io_links/
|
|--- mem_banks/
|
|--- 0/
|
|--- properties
|--- 1/
|
|--- properties
|--- 2/
|
|--- properties
|--- 3/
|
|--- properties--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_crat.h | 294 +++++++ drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 7 + drivers/gpu/drm/radeon/amdkfd/kfd_module.c | 7 + drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 17 + drivers/gpu/drm/radeon/amdkfd/kfd_topology.c | 1207 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_topology.h | 168 ++++ 7 files changed, 1701 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_crat.h create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.c create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_topology.h
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -4,6 +4,6 @@ ccflags-y := -Iinclude/drm -amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o +amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_crat.h new file +294 -0
294 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +7 -0
@@ -100,6 +100,9 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, { kfd->shared_resources = *gpu_resources; +if (kfd_topology_add_device (kfd) !=0 ) +return false; + kfd->init_complete = true;dev_info (kfd_device,"added device (%x:%x)\n" , kfd->pdev->vendor, kfd->pdev->device);
@@ -109,6 +112,10 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,void kgd2kfd_device_exit (struct kfd_dev *kfd) { +int err =kfd_topology_remove_device (kfd); + +BUG_ON (err !=0 ); +kfree (kfd); }
drivers/gpu/drm/radeon/amdkfd/kfd_module.c +7 -0
@@ -73,16 +73,23 @@ static int __init kfd_module_init(void)if (err <0 ) goto err_ioctl; + err =kfd_topology_init (); +if (err <0 ) + goto err_topology; +dev_info (kfd_device,"Initialized module\n" );return 0 ; +err_topology: +kfd_chardev_exit (); err_ioctl:return err; } static void __exit kfd_module_exit(void) { +kfd_topology_shutdown ();kfd_chardev_exit ();dev_info (kfd_device,"Removed module\n" ); }
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +17 -0
@@ -32,6 +32,14 @@#include <linux/spinlock.h> #include "../radeon_kfd.h" +#define KFD_SYSFS_FILE_MODE 0444 + +/* GPU ID hash width in bits */ +#define KFD_GPU_ID_HASH_WIDTH 16 + +/* Macro for allocating structures */ +#define kfd_alloc_struct (ptr_to_struct) ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL)) +struct kfd_device_info {const struct kfd_scheduler_class *scheduler_class;unsigned int max_pasid_bits;
@@ -72,6 +80,15 @@ struct kfd_process {extern struct device *kfd_device; +/* Topology */ +int kfd_topology_init (void ); +void kfd_topology_shutdown (void ); +int kfd_topology_add_device (struct kfd_dev *gpu); +int kfd_topology_remove_device (struct kfd_dev *gpu); +struct kfd_dev *kfd_device_by_id (uint32_t gpu_id); +struct kfd_dev *kfd_device_by_pci_dev (const struct pci_dev *pdev); +struct kfd_dev *kfd_topology_enum_kfd_devices (uint8_t idx); +/* Interrupts */ void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry);
drivers/gpu/drm/radeon/amdkfd/kfd_topology.c new file +1207 -0
1,207 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_topology.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 12/23 amdkfd: Add queue module
In reply to Oded GabbayFrom: Ben Goz <[email protected]>
The queue module enables allocating and initializing queues uniformly.
v3: Removed typedef and redundant memset call. Broke long pr_debug print to one liners and Added documentation.
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 2 +- drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 123 +++++++++++++++++++++++++++++- drivers/gpu/drm/radeon/amdkfd/kfd_queue.c | 85 +++++++++++++++++++++ 3 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_queue.c
drivers/gpu/drm/radeon/amdkfd/Makefile +1 -1
@@ -6,6 +6,6 @@ ccflags-y := -Iinclude/drm amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ - kfd_process.o + kfd_process.o kfd_queue.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +122 -1
135 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_queue.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 21/23 amdkfd: Implement the Set Memory Policy IOCTL
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
--- drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 51 ++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c +50 -1
@@ -35,6 +35,7 @@#include <uapi/asm-generic/mman-common.h> #include <asm/processor.h> #include "kfd_priv.h" +#include "kfd_device_queue_manager.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);
@@ -319,7 +320,55 @@ static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, voidstatic long kfd_ioctl_set_memory_policy (struct file *filep,struct kfd_process *p,void __user *arg) { -return -ENODEV ; +struct kfd_ioctl_set_memory_policy_args args; +struct kfd_dev *dev; +int err =0 ; +struct kfd_process_device *pdd; +enum cache_policy default_policy, alternate_policy; + +if (copy_from_user (&args, arg,sizeof (args))) +return -EFAULT ; + +if (args.default_policy !=KFD_IOC_CACHE_POLICY_COHERENT + && args.default_policy !=KFD_IOC_CACHE_POLICY_NONCOHERENT ) { +return -EINVAL ; + } + +if (args.alternate_policy !=KFD_IOC_CACHE_POLICY_COHERENT + && args.alternate_policy !=KFD_IOC_CACHE_POLICY_NONCOHERENT ) { +return -EINVAL ; + } + + dev =kfd_device_by_id (args.gpu_id); +if (dev ==NULL ) +return -EINVAL ; + +mutex_lock (&p->mutex); + + pdd =kfd_bind_process_to_device (dev, p); +if (IS_ERR (pdd) <0 ) { + err =PTR_ERR (pdd); + goto out; + } + + default_policy = (args.default_policy ==KFD_IOC_CACHE_POLICY_COHERENT ) + ? cache_policy_coherent : cache_policy_noncoherent; + + alternate_policy = (args.alternate_policy ==KFD_IOC_CACHE_POLICY_COHERENT ) + ? cache_policy_coherent : cache_policy_noncoherent; + +if (!dev->dqm->set_cache_memory_policy (dev->dqm, + &pdd->qpd, + default_policy, + alternate_policy, + (void __user *)args.alternate_aperture_base, + args.alternate_aperture_size)) + err = -EINVAL ; + +out: +mutex_unlock (&p->mutex); + +return err; }static long kfd_ioctl_get_clock_counters (struct file *filep,struct kfd_process *p,void __user *arg)
Signature · 1 line
1.9.1
PATCH v4 19/23 amdkfd: Add interrupt handling module
In reply to Oded GabbayFrom: Andrew Lewycky <[email protected]>
This patch adds the interrupt handling module, in kfd_interrupt.c, and its related members in different data structures to the amdkfd driver.
The amdkfd interrupt module maintains an internal interrupt ring per amdkfd device. The internal interrupt ring contains interrupts that needs further handling. The extra handling is deferred to a later time through a workqueue.
There's no acknowledgment for the interrupts we use. The hardware simply queues a new interrupt each time without waiting.
The fixed-size internal queue means that it's possible for us to lose interrupts because we have no back-pressure to the hardware.
v3:
Change device init
Made sure spin lock is taken only if init is complete Moved bool field to the end of the structure
--- drivers/gpu/drm/radeon/amdkfd/Makefile | 3 +- drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 23 +++- drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c | 161 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 18 ++- 4 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c
drivers/gpu/drm/radeon/amdkfd/Makefile +2 -1
@@ -8,6 +8,7 @@ amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ kfd_pasid.o kfd_doorbell.o kfd_aperture.o \ kfd_process.o kfd_queue.o kfd_mqd_manager.o \ kfd_kernel_queue.o kfd_packet_manager.o \ - kfd_process_queue_manager.o kfd_device_queue_manager.o + kfd_process_queue_manager.o kfd_device_queue_manager.o \ + kfd_interrupt.o obj-$(CONFIG_HSA_RADEON) += amdkfd.o
drivers/gpu/drm/radeon/amdkfd/kfd_device.c +22 -1
@@ -31,6 +31,7 @@static const struct kfd_device_info kaveri_device_info = { .max_pasid_bits =16 , + .ih_ring_entry_size =4 *sizeof (uint32_t ) };struct kfd_deviceid {
@@ -187,6 +188,13 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd, goto kfd_topology_add_device_error; } +if (kfd_interrupt_init (kfd)) { +dev_err (kfd_device, +"Error initializing interrupts for device (%x:%x)\n" , + kfd->pdev->vendor, kfd->pdev->device); + goto kfd_interrupt_error; + } +if (!device_iommu_pasid_init (kfd)) { dev_err(kfd_device, "Error initializing iommuv2 for device (%x:%x)\n",
@@ -223,6 +231,8 @@ dqm_start_error: device_queue_manager_error:amd_iommu_free_device (kfd->pdev); device_iommu_pasid_error: +kfd_interrupt_exit (kfd); +kfd_interrupt_error:kfd_topology_remove_device (kfd); kfd_topology_add_device_error: kfd2kgd->fini_sa_manager (kfd->kgd);
@@ -238,6 +248,7 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)if (kfd->init_complete) {device_queue_manager_uninit (kfd->dqm);amd_iommu_free_device (kfd->pdev); +kfd_interrupt_exit (kfd);kfd_topology_remove_device (kfd); }
@@ -274,6 +285,16 @@ int kgd2kfd_resume(struct kfd_dev *kfd)return 0 ; } -void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry) +/* This is called directly from KGD at ISR. */ +void kgd2kfd_interrupt (struct kfd_dev *kfd,const void *ih_ring_entry) { +if (kfd->init_complete) { +spin_lock (&kfd->interrupt_lock); + +if (kfd->interrupts_active + &&enqueue_ih_ring_entry (kfd, ih_ring_entry)) +schedule_work (&kfd->interrupt_work); + +spin_unlock (&kfd->interrupt_lock); + } }
drivers/gpu/drm/radeon/amdkfd/kfd_interrupt.c new file +161 -0
161 lines not on this page · raw message
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h +15 -3
@@ -126,10 +126,19 @@ struct kfd_dev {struct kgd2kfd_shared_resources shared_resources; +void *interrupt_ring; +size_t interrupt_ring_size; +atomic_t interrupt_ring_rptr; +atomic_t interrupt_ring_wptr; +struct work_struct interrupt_work; +spinlock_t interrupt_lock; +/* QCM Device instance */ struct device_queue_manager *dqm;bool init_complete; +/* Interrupts of interest to KFD are copied from the HW ring into a SW ring. */ +bool interrupts_active; };/* KGD2KFD callbacks */
@@ -468,11 +477,14 @@ struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev);struct kfd_dev *kfd_topology_enum_kfd_devices (uint8_t idx);/* Interrupts */ -void kgd2kfd_interrupt (struct kfd_dev *dev,const void *ih_ring_entry); +int kfd_interrupt_init (struct kfd_dev *dev); +void kfd_interrupt_exit (struct kfd_dev *dev); +void kgd2kfd_interrupt (struct kfd_dev *kfd,const void *ih_ring_entry); +bool enqueue_ih_ring_entry (struct kfd_dev *kfd,const void *ih_ring_entry);/* Power Management */ -void kgd2kfd_suspend (struct kfd_dev *dev); -int kgd2kfd_resume (struct kfd_dev *dev); +void kgd2kfd_suspend (struct kfd_dev *kfd); +int kgd2kfd_resume (struct kfd_dev *kfd);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process);
Signature · 1 line
1.9.1
Re: [PATCH v4 05/23] drm/radeon: Add radeon <--> amdkfd interface
In reply to Oded GabbayQuoted 514 lines · Oded Gabbay
This patch adds the interface between the radeon driver and the amdkfd driver. The interface implementation is contained in
radeon_kfd.candradeon_kfd.h.The interface itself is represented by a pointer to struct
kfd_dev. The pointer is located insideradeon_devicestructure.All the register accesses that amdkfd need are done using this interface. This allows us to avoid direct register accesses in amdkfd proper, while also avoiding locking between amdkfd and radeon.
The single exception is the doorbells that are used in both of the drivers. However, because they are located in separate pci bar pages, the danger of sharing registers between the drivers is minimal.
Having said that, we are planning to move the doorbells as well to radeon.
v3:
Add interface for sa manager init and fini. The init function will allocate a buffer on system memory and pin it to the GART address space via the radeon sa manager.
All mappings of buffers to GART address space are done via the radeon sa manager. The interface of allocate memory will use the radeon sa manager to sub allocate from the single buffer that was allocated during the init function.
Change lower_32/upper_32 calls to use linux macros
Add documentation for the interface
v4:
Change ptr field type in
kgd_memfrom uint32_t* to void* to match to type that is returned byradeon_sa_bo_cpu_addrSigned-off-by Oded Gabbay <[email protected]>--- drivers/gpu/drm/radeon/Makefile | 1 + drivers/gpu/drm/radeon/cik.c | 9 + drivers/gpu/drm/radeon/cik_reg.h | 65 +++++ drivers/gpu/drm/radeon/cikd.h | 51 +++- drivers/gpu/drm/radeon/radeon.h | 4 + drivers/gpu/drm/radeon/radeon_drv.c | 5 + drivers/gpu/drm/radeon/radeon_kfd.c | 538 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon_kfd.h | 177 ++++++++++++ drivers/gpu/drm/radeon/radeon_kms.c | 7 + 9 files changed, 856 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.c create mode 100644 drivers/gpu/drm/radeon/radeon_kfd.hdrivers/gpu/drm/radeon/Makefile +1
-0@@ -104,6 +104,7 @@ radeon-y += \ radeon_vce.o \ vce_v1_0.o \ vce_v2_0.o \ + radeon_kfd.o radeon-$(CONFIG_COMPAT) += radeon_ioc32.o radeon-$(CONFIG_VGA_SWITCHEROO) += radeon_atpx_handler.odrivers/gpu/drm/radeon/cik.c +9
-0@@ -32,6 +32,7 @@#include "cik_blit_shaders.h" #include "radeon_ucode.h" #include "clearstate_ci.h" +#include "radeon_kfd.h" MODULE_FIRMWARE ("radeon/BONAIRE_pfp.bin" );MODULE_FIRMWARE ("radeon/BONAIRE_me.bin" );@@ -7792,6 +7793,9 @@ restart_ih:while (rptr != wptr) {/* wptr/rptr are in bytes! */ ring_index = rptr /4 ; + +radeon_kfd_interrupt (rdev, (const void *) &rdev->ih.ring[ring_index]); + src_id =le32_to_cpu (rdev->ih.ring[ring_index]) &0xff ; src_data =le32_to_cpu (rdev->ih.ring[ring_index +1 ]) &0xfffffff ; ring_id =le32_to_cpu (rdev->ih.ring[ring_index +2 ]) &0xff ;@@ -8481,6 +8485,10 @@ static int cik_startup(struct radeon_device *rdev)if (r)return r; + r =radeon_kfd_resume (rdev); +if (r) +return r; +return 0 ; }@@ -8529,6 +8537,7 @@ int cik_resume(struct radeon_device *rdev)*/ int cik_suspend (struct radeon_device *rdev) { +radeon_kfd_suspend (rdev);radeon_pm_suspend (rdev);dce6_audio_fini (rdev);radeon_vm_manager_fini (rdev);drivers/gpu/drm/radeon/cik_reg.h +65
-0@@ -147,4 +147,69 @@#define CIK_LB_DESKTOP_HEIGHT 0x6b0c +struct cik_hqd_registers { +u32 cp_mqd_base_addr; +u32 cp_mqd_base_addr_hi; +u32 cp_hqd_active; +u32 cp_hqd_vmid; +u32 cp_hqd_persistent_state; +u32 cp_hqd_pipe_priority; +u32 cp_hqd_queue_priority; +u32 cp_hqd_quantum; +u32 cp_hqd_pq_base; +u32 cp_hqd_pq_base_hi; +u32 cp_hqd_pq_rptr; +u32 cp_hqd_pq_rptr_report_addr; +u32 cp_hqd_pq_rptr_report_addr_hi; +u32 cp_hqd_pq_wptr_poll_addr; +u32 cp_hqd_pq_wptr_poll_addr_hi; +u32 cp_hqd_pq_doorbell_control; +u32 cp_hqd_pq_wptr; +u32 cp_hqd_pq_control; +u32 cp_hqd_ib_base_addr; +u32 cp_hqd_ib_base_addr_hi; +u32 cp_hqd_ib_rptr; +u32 cp_hqd_ib_control; +u32 cp_hqd_iq_timer; +u32 cp_hqd_iq_rptr; +u32 cp_hqd_dequeue_request; +u32 cp_hqd_dma_offload; +u32 cp_hqd_sema_cmd; +u32 cp_hqd_msg_type; +u32 cp_hqd_atomic0_preop_lo; +u32 cp_hqd_atomic0_preop_hi; +u32 cp_hqd_atomic1_preop_lo; +u32 cp_hqd_atomic1_preop_hi; +u32 cp_hqd_hq_scheduler0; +u32 cp_hqd_hq_scheduler1; +u32 cp_mqd_control; +}; + +struct cik_mqd { +u32 header; +u32 dispatch_initiator; +u32 dimensions[3 ]; +u32 start_idx[3 ]; +u32 num_threads[3 ]; +u32 pipeline_stat_enable; +u32 perf_counter_enable; +u32 pgm[2 ]; +u32 tba[2 ]; +u32 tma[2 ]; +u32 pgm_rsrc[2 ]; +u32 vmid; +u32 resource_limits; +u32 static_thread_mgmt01[2 ]; +u32 tmp_ring_size; +u32 static_thread_mgmt23[2 ]; +u32 restart[3 ]; +u32 thread_trace_enable; +u32 reserved1; +u32 user_data[16 ]; +u32 vgtcs_invoke_count[2 ]; +struct cik_hqd_registers queue_state; +u32 dequeue_cntr; +u32 interrupt_queue[64 ]; +}; +#endif drivers/gpu/drm/radeon/cikd.h +50
-1@@ -1139,6 +1139,9 @@#define SH_MEM_ALIGNMENT_MODE_UNALIGNED 3#define DEFAULT_MTYPE (x) ((x) << 4)#define APE1_MTYPE (x) ((x) << 7) +/* valid for both DEFAULT_MTYPE and APE1_MTYPE */ +#define MTYPE_CACHED 0 +#define MTYPE_NONCACHED 3#define SX_DEBUG_1 0x9060@@ -1449,6 +1452,16 @@#define CP_HQD_ACTIVE 0xC91C#define CP_HQD_VMID 0xC920 +#define CP_HQD_PERSISTENT_STATE 0xC924u +#define DEFAULT_CP_HQD_PERSISTENT_STATE (0x33U << 8) + +#define CP_HQD_PIPE_PRIORITY 0xC928u +#define CP_HQD_QUEUE_PRIORITY 0xC92Cu +#define CP_HQD_QUANTUM 0xC930u +#define QUANTUM_EN 1U +#define QUANTUM_SCALE_1MS (1U << 4) +#define QUANTUM_DURATION (x) ((x) << 8) +#define CP_HQD_PQ_BASE 0xC934#define CP_HQD_PQ_BASE_HI 0xC938#define CP_HQD_PQ_RPTR 0xC93C@@ -1476,12 +1489,32 @@#define PRIV_STATE (1 << 30)#define KMD_QUEUE (1 << 31) -#define CP_HQD_DEQUEUE_REQUEST 0xC974 +#define CP_HQD_IB_BASE_ADDR 0xC95Cu +#define CP_HQD_IB_BASE_ADDR_HI 0xC960u +#define CP_HQD_IB_RPTR 0xC964u +#define CP_HQD_IB_CONTROL 0xC968u +#define IB_ATC_EN (1U << 23) +#define DEFAULT_MIN_IB_AVAIL_SIZE (3U << 20) + +#define CP_HQD_DEQUEUE_REQUEST 0xC974 +#define DEQUEUE_REQUEST_DRAIN 1 +#define DEQUEUE_REQUEST_RESET 2#define CP_MQD_CONTROL 0xC99C#define MQD_VMID (x) ((x) << 0)#define MQD_VMID_MASK (0xf << 0) +#define CP_HQD_SEMA_CMD 0xC97Cu +#define CP_HQD_MSG_TYPE 0xC980u +#define CP_HQD_ATOMIC0_PREOP_LO 0xC984u +#define CP_HQD_ATOMIC0_PREOP_HI 0xC988u +#define CP_HQD_ATOMIC1_PREOP_LO 0xC98Cu +#define CP_HQD_ATOMIC1_PREOP_HI 0xC990u +#define CP_HQD_HQ_SCHEDULER0 0xC994u +#define CP_HQD_HQ_SCHEDULER1 0xC998u + +#define SH_STATIC_MEM_CONFIG 0x9604u +#define DB_RENDER_CONTROL 0x28000#define PA_SC_RASTER_CONFIG 0x28350@@ -2071,4 +2104,20 @@#define VCE_CMD_IB_AUTO 0x00000005#define VCE_CMD_SEMAPHORE 0x00000006 +#define ATC_VMID0_PASID_MAPPING 0x339Cu +#define ATC_VMID_PASID_MAPPING_UPDATE_STATUS 0x3398u +#define ATC_VMID_PASID_MAPPING_VALID (1U << 31) + +#define ATC_VM_APERTURE0_CNTL 0x3310u +#define ATS_ACCESS_MODE_NEVER 0 +#define ATS_ACCESS_MODE_ALWAYS 1 + +#define ATC_VM_APERTURE0_CNTL2 0x3318u +#define ATC_VM_APERTURE0_HIGH_ADDR 0x3308u +#define ATC_VM_APERTURE0_LOW_ADDR 0x3300u +#define ATC_VM_APERTURE1_CNTL 0x3314u +#define ATC_VM_APERTURE1_CNTL2 0x331Cu +#define ATC_VM_APERTURE1_HIGH_ADDR 0x330Cu +#define ATC_VM_APERTURE1_LOW_ADDR 0x3304u +#endif drivers/gpu/drm/radeon/radeon.h +4
-0@@ -2400,6 +2400,10 @@ struct radeon_device {u64 vram_pin_size;u64 gart_pin_size; +/* amdkfd interface */ +struct kfd_dev *kfd; +struct radeon_sa_manager kfd_bo; +struct mutex mn_lock;DECLARE_HASHTABLE (mn_hash,7 ); };drivers/gpu/drm/radeon/radeon_drv.c +5
-0@@ -39,6 +39,8 @@#include <linux/pm_runtime.h> #include <linux/vga_switcheroo.h> #include "drm_crtc_helper.h" +#include "radeon_kfd.h" +/* * KMS wrapper. * - 2.0.0 - initial interface @@ -647,12 +649,15 @@ static int __init radeon_init(void)#endif } +radeon_kfd_init (); +/* let modprobe override vga console setting */ return drm_pci_init (driver, pdriver); } static void __exit radeon_exit(void) { +radeon_kfd_fini ();drm_pci_exit (driver, pdriver);radeon_unregister_atpx_handler (); }drivers/gpu/drm/radeon/radeon_kfd.c new file +201
-0@@ -0,0 +1,538 @@ +/* +* Copyright 2014 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <linux/module.h> +#include <linux/fdtable.h> +#include <linux/uaccess.h> +#include <drm/drmP.h> +#include "radeon.h" +#include "cikd.h" +#include "cik_reg.h" +#include "radeon_kfd.h" + +#define CIK_PIPE_PER_MEC (4) + +struct kgd_mem { +struct radeon_sa_bo *sa_bo; +uint64_t gpu_addr; +void *ptr; +}; + +static int init_sa_manager (struct kgd_dev *kgd,unsigned int size); +static void fini_sa_manager (struct kgd_dev *kgd); + +static int allocate_mem (struct kgd_dev *kgd,size_t size,size_t alignment, +enum kgd_memory_pool pool,struct kgd_mem **mem); + +static void free_mem (struct kgd_dev *kgd,struct kgd_mem *mem); + +static uint64_t get_vmem_size (struct kgd_dev *kgd); +static uint64_t get_gpu_clock_counter (struct kgd_dev *kgd); + +static uint32_t get_max_engine_clock_in_mhz (struct kgd_dev *kgd); + +/* +* Register access functions +*/ + +static void kgd_program_sh_mem_settings (struct kgd_dev *kgd,uint32_t vmid,uint32_t sh_mem_config, +uint32_t sh_mem_ape1_base,uint32_t sh_mem_ape1_limit,uint32_t sh_mem_bases); +static int kgd_set_pasid_vmid_mapping (struct kgd_dev *kgd,unsigned int pasid,unsigned int vmid); +static int kgd_init_memory (struct kgd_dev *kgd); +static int kgd_init_pipeline (struct kgd_dev *kgd,uint32_t pipe_id,uint32_t hpd_size,uint64_t hpd_gpu_addr); +static int kgd_hqd_load (struct kgd_dev *kgd,void *mqd,uint32_t pipe_id,uint32_t queue_id,uint32_t __user *wptr); +static bool kgd_hqd_is_occupies (struct kgd_dev *kgd,uint64_t queue_address,uint32_t pipe_id,uint32_t queue_id); +static int kgd_hqd_destroy (struct kgd_dev *kgd,bool is_reset,unsigned int timeout, +uint32_t pipe_id,uint32_t queue_id); + +static const struct kfd2kgd_calls kfd2kgd = { + .init_sa_manager = init_sa_manager, + .fini_sa_manager = fini_sa_manager, + .allocate_mem = allocate_mem, + .free_mem = free_mem, + .get_vmem_size = get_vmem_size, + .get_gpu_clock_counter = get_gpu_clock_counter, + .get_max_engine_clock_in_mhz = get_max_engine_clock_in_mhz, + .program_sh_mem_settings = kgd_program_sh_mem_settings, + .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping, + .init_memory = kgd_init_memory, + .init_pipeline = kgd_init_pipeline, + .hqd_load = kgd_hqd_load, + .hqd_is_occupies = kgd_hqd_is_occupies, + .hqd_destroy = kgd_hqd_destroy, +}; + +static const struct kgd2kfd_calls *kgd2kfd; + +bool radeon_kfd_init (void ) +{ +bool (*kgd2kfd_init_p)(unsigned ,const struct kfd2kgd_calls *, +const struct kgd2kfd_calls **); + + kgd2kfd_init_p =symbol_request (kgd2kfd_init); + +if (kgd2kfd_init_p ==NULL ) +return false; + +if (!kgd2kfd_init_p (KFD_INTERFACE_VERSION , &kfd2kgd, &kgd2kfd)) { +symbol_put (kgd2kfd_init); + kgd2kfd =NULL ; + +return false; + } + +return true; +} + +void radeon_kfd_fini (void ) +{ +if (kgd2kfd) { + kgd2kfd->exit (); +symbol_put (kgd2kfd_init); + } +} + +void radeon_kfd_device_probe (struct radeon_device *rdev) +{ +if (kgd2kfd) + rdev->kfd = kgd2kfd->probe ((struct kgd_dev *)rdev, rdev->pdev); +} + +void radeon_kfd_device_init (struct radeon_device *rdev) +{ +if (rdev->kfd) { +struct kgd2kfd_shared_resources gpu_resources = { + .compute_vmid_bitmap =0xFF00 , + + .first_compute_pipe =1 , + .compute_pipe_count =8 -1 , + }; + +radeon_doorbell_get_kfd_info (rdev, + &gpu_resources.doorbell_physical_address, + &gpu_resources.doorbell_aperture_size, + &gpu_resources.doorbell_start_offset); + + kgd2kfd->device_init (rdev->kfd, &gpu_resources); + } +} + +void radeon_kfd_device_fini (struct radeon_device *rdev) +{ +if (rdev->kfd) { + kgd2kfd->device_exit (rdev->kfd); + rdev->kfd =NULL ; + } +} + +void radeon_kfd_interrupt (struct radeon_device *rdev,const void *ih_ring_entry) +{ +if (rdev->kfd) + kgd2kfd->interrupt (rdev->kfd, ih_ring_entry); +} + +void radeon_kfd_suspend (struct radeon_device *rdev) +{ +if (rdev->kfd) + kgd2kfd->suspend (rdev->kfd); +} + +int radeon_kfd_resume (struct radeon_device *rdev) +{ +int r =0 ; + +if (rdev->kfd) + r = kgd2kfd->resume (rdev->kfd); + +return r; +} + +static u32 pool_to_domain (enum kgd_memory_pool p) +{ +switch (p) { +case KGD_POOL_FRAMEBUFFER :return RADEON_GEM_DOMAIN_VRAM ; +default :return RADEON_GEM_DOMAIN_GTT ; + } +} + +static int init_sa_manager (struct kgd_dev *kgd,unsigned int size) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; +u64 max_offset[4 ]; +int r, i; + +BUG_ON (kgd ==NULL ); + + r =radeon_sa_bo_manager_init (rdev, &rdev->kfd_bo, + size, +RADEON_GPU_PAGE_SIZE , +RADEON_GEM_DOMAIN_GTT , +RADEON_GEM_GTT_WC ); + +if (r) +return r; + +/* Try to pin buffer in first 8MB, 16MB or 64MB of GART */ + max_offset[0 ] =roundup (size,8 *1024 *1024 ); + max_offset[1 ] =roundup (size,16 *1024 *1024 ); + max_offset[2 ] =roundup (size,64 *1024 *1024 ); + max_offset[3 ] =0 ; + +for (i =0 ; i <4 ; i++) { +
drivers/gpu/drm/radeon/radeon_kfd.c line 211
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_kfd.c new file +10
-0+ r =radeon_sa_bo_manager_start (rdev, &rdev->kfd_bo, + max_offset[i]); +if (!r) +return r; + } + +radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo); + +return r; +}
Due to a merging error on my part, the init_sa_manager function here is not correct (and doesn't compile at this stage, but only after applying patch 10/23). I have moved the fix from patch 10/23 to this patch in my tree (new branch amdkfd-v5-wip), but I wanted to put a note here with the correct function:
static int init_sa_manager(struct kgd_dev *kgd, unsigned int size)
{
struct radeon_device *rdev = (struct radeon_device *)kgd;
int r;
BUG_ON(kgd == NULL);
r = radeon_sa_bo_manager_init(rdev, &rdev->kfd_bo,
size,
RADEON_GPU_PAGE_SIZE,
RADEON_GEM_DOMAIN_GTT,
RADEON_GEM_GTT_WC);
if (r)
return r;
r = radeon_sa_bo_manager_start(rdev, &rdev->kfd_bo);
if (r)
radeon_sa_bo_manager_fini(rdev, &rdev->kfd_bo);
return r;
}Quoted 543 lines
drivers/gpu/drm/radeon/radeon_kfd.c new file +327
-0+ +static void fini_sa_manager (struct kgd_dev *kgd) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; + +BUG_ON (kgd ==NULL ); + +radeon_sa_bo_manager_suspend (rdev, &rdev->kfd_bo); +radeon_sa_bo_manager_fini (rdev, &rdev->kfd_bo); +} + +static int allocate_mem (struct kgd_dev *kgd,size_t size,size_t alignment, +enum kgd_memory_pool pool,struct kgd_mem **mem) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; +u32 domain; +int r; + +BUG_ON (kgd ==NULL ); + + domain =pool_to_domain (pool); +if (domain !=RADEON_GEM_DOMAIN_GTT ) { +dev_err (rdev->dev, +"Only allowed to allocate gart memory for kfd\n" ); +return -EINVAL ; + } + + *mem =kmalloc (sizeof (struct kgd_mem ),GFP_KERNEL ); +if ((*mem) ==NULL ) +return -ENOMEM ; + + r =radeon_sa_bo_new (rdev, &rdev->kfd_bo, &(*mem)->sa_bo, size, alignment); +if (r) { +dev_err (rdev->dev,"failed to get memory for kfd (%d)\n" , r); +return r; + } + + (*mem)->ptr =radeon_sa_bo_cpu_addr ((*mem)->sa_bo); + (*mem)->gpu_addr =radeon_sa_bo_gpu_addr ((*mem)->sa_bo); + +return 0 ; +} + +static void free_mem (struct kgd_dev *kgd,struct kgd_mem *mem) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; + +BUG_ON (kgd ==NULL ); + +radeon_sa_bo_free (rdev, &mem->sa_bo,NULL ); +kfree (mem); +} + +static uint64_t get_vmem_size (struct kgd_dev *kgd) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; + +BUG_ON (kgd ==NULL ); + +return rdev->mc.real_vram_size; +} + +static uint64_t get_gpu_clock_counter (struct kgd_dev *kgd) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; + +return rdev->asic->get_gpu_clock_counter (rdev); +} + +static uint32_t get_max_engine_clock_in_mhz (struct kgd_dev *kgd) +{ +struct radeon_device *rdev = (struct radeon_device *)kgd; + +/* The sclk is in quantas of 10kHz */ +return rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk /100 ; +} + +static inline struct radeon_device *get_radeon_device (struct kgd_dev *kgd) +{ +return (struct radeon_device *)kgd; +} + +static void write_register (struct kgd_dev *kgd,uint32_t offset,uint32_t value) +{ +struct radeon_device *rdev =get_radeon_device (kgd); + +writel (value, (void __iomem *)(rdev->rmmio + offset)); +} + +static uint32_t read_register (struct kgd_dev *kgd,uint32_t offset) +{ +struct radeon_device *rdev =get_radeon_device (kgd); + +return readl ((void __iomem *)(rdev->rmmio + offset)); +} + +static void lock_srbm (struct kgd_dev *kgd,uint32_t mec,uint32_t pipe,uint32_t queue,uint32_t vmid) +{ +struct radeon_device *rdev =get_radeon_device (kgd); +uint32_t value =PIPEID (pipe) |MEID (mec) |VMID (vmid) |QUEUEID (queue); + +mutex_lock (&rdev->srbm_mutex); +write_register (kgd,SRBM_GFX_CNTL , value); +} + +static void unlock_srbm (struct kgd_dev *kgd) +{ +struct radeon_device *rdev =get_radeon_device (kgd); + +write_register (kgd,SRBM_GFX_CNTL ,0 ); +mutex_unlock (&rdev->srbm_mutex); +} + +static void acquire_queue (struct kgd_dev *kgd,uint32_t pipe_id,uint32_t queue_id) +{ +uint32_t mec = (++pipe_id /CIK_PIPE_PER_MEC ) +1 ; +uint32_t pipe = (pipe_id %CIK_PIPE_PER_MEC ); + +lock_srbm (kgd, mec, pipe, queue_id,0 ); +} + +static void release_queue (struct kgd_dev *kgd) +{ +unlock_srbm (kgd); +} + +static void kgd_program_sh_mem_settings (struct kgd_dev *kgd,uint32_t vmid,uint32_t sh_mem_config, +uint32_t sh_mem_ape1_base,uint32_t sh_mem_ape1_limit,uint32_t sh_mem_bases) +{ +lock_srbm (kgd,0 ,0 ,0 , vmid); + +write_register (kgd,SH_MEM_CONFIG , sh_mem_config); +write_register (kgd,SH_MEM_APE1_BASE , sh_mem_ape1_base); +write_register (kgd,SH_MEM_APE1_LIMIT , sh_mem_ape1_limit); +write_register (kgd,SH_MEM_BASES , sh_mem_bases); + +unlock_srbm (kgd); +} + +static int kgd_set_pasid_vmid_mapping (struct kgd_dev *kgd,unsigned int pasid,unsigned int vmid) +{ +/* +* We have to assume that there is no outstanding mapping. +* The ATC_VMID_PASID_MAPPING_UPDATE_STATUS bit could be 0 because a mapping +* is in progress or because a mapping finished and the SW cleared it. +* So the protocol is to always wait & clear. +*/ +uint32_t pasid_mapping = (pasid ==0 ) ?0 : (uint32_t )pasid |ATC_VMID_PASID_MAPPING_VALID ; + +write_register (kgd,ATC_VMID0_PASID_MAPPING + vmid*sizeof (uint32_t ), pasid_mapping); + +while (!(read_register (kgd,ATC_VMID_PASID_MAPPING_UPDATE_STATUS ) & (1U << vmid))) +cpu_relax (); +write_register (kgd,ATC_VMID_PASID_MAPPING_UPDATE_STATUS ,1U << vmid); + +return 0 ; +} + +static int kgd_init_memory (struct kgd_dev *kgd) +{ +/* +* Configure apertures: +* LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB) +* Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB) +* GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB) +*/ +int i; +uint32_t sh_mem_bases =PRIVATE_BASE (0x6000 ) |SHARED_BASE (0x6000 ); + +for (i =8 ; i <16 ; i++) { +uint32_t sh_mem_config; + +lock_srbm (kgd,0 ,0 ,0 , i); + + sh_mem_config =ALIGNMENT_MODE (SH_MEM_ALIGNMENT_MODE_UNALIGNED ); + sh_mem_config |=DEFAULT_MTYPE (MTYPE_NONCACHED ); + +write_register (kgd,SH_MEM_CONFIG , sh_mem_config); + +write_register (kgd,SH_MEM_BASES , sh_mem_bases); + +/* Scratch aperture is not supported for now. */ +write_register (kgd,SH_STATIC_MEM_CONFIG ,0 ); + +/* APE1 disabled for now. */ +write_register (kgd,SH_MEM_APE1_BASE ,1 ); +write_register (kgd,SH_MEM_APE1_LIMIT ,0 ); + +unlock_srbm (kgd); + } + +return 0 ; +} + +static int kgd_init_pipeline (struct kgd_dev *kgd,uint32_t pipe_id,uint32_t hpd_size,uint64_t hpd_gpu_addr) +{ +uint32_t mec = (++pipe_id /CIK_PIPE_PER_MEC ) +1 ; +uint32_t pipe = (pipe_id %CIK_PIPE_PER_MEC ); + +lock_srbm (kgd, mec, pipe,0 ,0 ); +write_register (kgd,CP_HPD_EOP_BASE_ADDR ,lower_32_bits (hpd_gpu_addr >>8 )); +write_register (kgd,CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (hpd_gpu_addr >>8 )); +write_register (kgd,CP_HPD_EOP_VMID ,0 ); +write_register (kgd,CP_HPD_EOP_CONTROL , hpd_size); +unlock_srbm (kgd); + +return 0 ; +} + +static inline struct cik_mqd *get_mqd (void *mqd) +{ +return (struct cik_mqd *)mqd; +} + +static int kgd_hqd_load (struct kgd_dev *kgd,void *mqd,uint32_t pipe_id,uint32_t queue_id,uint32_t __user *wptr) +{ +uint32_t wptr_shadow, is_wptr_shadow_valid; +struct cik_mqd *m; + + m =get_mqd (mqd); + + is_wptr_shadow_valid = !get_user (wptr_shadow, wptr); + +acquire_queue (kgd, pipe_id, queue_id); +write_register (kgd,CP_MQD_BASE_ADDR , m->queue_state.cp_mqd_base_addr); +write_register (kgd,CP_MQD_BASE_ADDR_HI , m->queue_state.cp_mqd_base_addr_hi); +write_register (kgd,CP_MQD_CONTROL , m->queue_state.cp_mqd_control); + +write_register (kgd,CP_HQD_PQ_BASE , m->queue_state.cp_hqd_pq_base); +write_register (kgd,CP_HQD_PQ_BASE_HI , m->queue_state.cp_hqd_pq_base_hi); +write_register (kgd,CP_HQD_PQ_CONTROL , m->queue_state.cp_hqd_pq_control); + +write_register (kgd,CP_HQD_IB_CONTROL , m->queue_state.cp_hqd_ib_control); +write_register (kgd,CP_HQD_IB_BASE_ADDR , m->queue_state.cp_hqd_ib_base_addr); +write_register (kgd,CP_HQD_IB_BASE_ADDR_HI , m->queue_state.cp_hqd_ib_base_addr_hi); + +write_register (kgd,CP_HQD_IB_RPTR , m->queue_state.cp_hqd_ib_rptr); + +write_register (kgd,CP_HQD_PERSISTENT_STATE , m->queue_state.cp_hqd_persistent_state); +write_register (kgd,CP_HQD_SEMA_CMD , m->queue_state.cp_hqd_sema_cmd); +write_register (kgd,CP_HQD_MSG_TYPE , m->queue_state.cp_hqd_msg_type); + +write_register (kgd,CP_HQD_ATOMIC0_PREOP_LO , m->queue_state.cp_hqd_atomic0_preop_lo); +write_register (kgd,CP_HQD_ATOMIC0_PREOP_HI , m->queue_state.cp_hqd_atomic0_preop_hi); +write_register (kgd,CP_HQD_ATOMIC1_PREOP_LO , m->queue_state.cp_hqd_atomic1_preop_lo); +write_register (kgd,CP_HQD_ATOMIC1_PREOP_HI , m->queue_state.cp_hqd_atomic1_preop_hi); + +write_register (kgd,CP_HQD_PQ_RPTR_REPORT_ADDR , m->queue_state.cp_hqd_pq_rptr_report_addr); +write_register (kgd,CP_HQD_PQ_RPTR_REPORT_ADDR_HI , m->queue_state.cp_hqd_pq_rptr_report_addr_hi); +write_register (kgd,CP_HQD_PQ_RPTR , m->queue_state.cp_hqd_pq_rptr); + +write_register (kgd,CP_HQD_PQ_WPTR_POLL_ADDR , m->queue_state.cp_hqd_pq_wptr_poll_addr); +write_register (kgd,CP_HQD_PQ_WPTR_POLL_ADDR_HI , m->queue_state.cp_hqd_pq_wptr_poll_addr_hi); + +write_register (kgd,CP_HQD_PQ_DOORBELL_CONTROL , m->queue_state.cp_hqd_pq_doorbell_control); + +write_register (kgd,CP_HQD_VMID , m->queue_state.cp_hqd_vmid); + +write_register (kgd,CP_HQD_QUANTUM , m->queue_state.cp_hqd_quantum); + +write_register (kgd,CP_HQD_PIPE_PRIORITY , m->queue_state.cp_hqd_pipe_priority); +write_register (kgd,CP_HQD_QUEUE_PRIORITY , m->queue_state.cp_hqd_queue_priority); + +write_register (kgd,CP_HQD_HQ_SCHEDULER0 , m->queue_state.cp_hqd_hq_scheduler0); +write_register (kgd,CP_HQD_HQ_SCHEDULER1 , m->queue_state.cp_hqd_hq_scheduler1); + +if (is_wptr_shadow_valid) +write_register (kgd,CP_HQD_PQ_WPTR , wptr_shadow); + +write_register (kgd,CP_HQD_ACTIVE , m->queue_state.cp_hqd_active); +release_queue (kgd); + +return 0 ; +} + +static bool kgd_hqd_is_occupies (struct kgd_dev *kgd,uint64_t queue_address,uint32_t pipe_id,uint32_t queue_id) +{ +uint32_t act; +bool retval = false; +uint32_t low, high; + +acquire_queue (kgd, pipe_id, queue_id); + act =read_register (kgd,CP_HQD_ACTIVE ); +if (act) { + low =lower_32_bits (queue_address >>8 ); + high =upper_32_bits (queue_address >>8 ); + +if (low ==read_register (kgd,CP_HQD_PQ_BASE ) && + high ==read_register (kgd,CP_HQD_PQ_BASE_HI )) + retval = true; + } +release_queue (kgd); +return retval; +} + +static int kgd_hqd_destroy (struct kgd_dev *kgd,bool is_reset, +unsigned int timeout,uint32_t pipe_id, +uint32_t queue_id) +{ +int status =0 ; +bool sync = (timeout >0 ) ? true : false; + +acquire_queue (kgd, pipe_id, queue_id); +write_register (kgd,CP_HQD_PQ_DOORBELL_CONTROL ,0 ); + +if (is_reset) +write_register (kgd,CP_HQD_DEQUEUE_REQUEST ,DEQUEUE_REQUEST_RESET ); +else +write_register (kgd,CP_HQD_DEQUEUE_REQUEST ,DEQUEUE_REQUEST_DRAIN ); + + +while (read_register (kgd,CP_HQD_ACTIVE ) !=0 ) { +if (sync && timeout <=0 ) { + status = -EBUSY ; +break ; + } +msleep (20 ); +if (sync) { +if (timeout >=20 ) + timeout -=20 ; +else + timeout =0 ; + } + } +release_queue (kgd); +return status; +}drivers/gpu/drm/radeon/radeon_kfd.h new file +177
-0@@ -0,0 +1,177 @@ +/* +* Copyright 2014 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* +* radeon_kfd.h defines the private interface between the +* AMD kernel graphics drivers and the AMD KFD. +*/ + +#ifndef RADEON_KFD_H_INCLUDED +#define RADEON_KFD_H_INCLUDED + +#include <linux/types.h> + +struct pci_dev ; + +#define KFD_INTERFACE_VERSION 1 + +struct kfd_dev ; +struct kgd_dev ; + +struct kgd_mem ; + +struct radeon_device ; + +enum kgd_memory_pool { +KGD_POOL_SYSTEM_CACHEABLE =1 , +KGD_POOL_SYSTEM_WRITECOMBINE =2 , +KGD_POOL_FRAMEBUFFER =3 , +}; + +struct kgd2kfd_shared_resources { +unsigned int compute_vmid_bitmap;/* Bit n == 1 means VMID n is available for KFD. */ + +unsigned int first_compute_pipe;/* Compute pipes are counted starting from MEC0/pipe0 as 0. */ +unsigned int compute_pipe_count;/* Number of MEC pipes available for KFD. */ + +phys_addr_t doorbell_physical_address;/* Base address of doorbell aperture. */ +size_t doorbell_aperture_size;/* Size in bytes of doorbell aperture. */ +size_t doorbell_start_offset;/* Number of bytes at start of aperture reserved for KGD. */ +}; + +/** +* struct kgd2kfd_calls +* +* @exit: Notifies amdkfd that radeon kernel module is unloaded +* +* @probe: Notifies amdkfd about a probe done on a device in the radeon driver. +* +* @device_init: Initialize the newly probed device (if it is a device that +* amdkfd supports) +* +* @device_exit: Notifies amdkfd about a removal of a radeon device +* +* @suspend: Notifies amdkfd about a suspend action done to a radeon device +* +* @resume: Notifies amdkfd about a resume action done to a radeon device +* +* This structure contains function callback pointers so the radeon driver +* will notify to the amdkfd about certain status changes. +* +*/ +struct kgd2kfd_calls { +void (*exit)(void ); +struct kfd_dev * (*probe)(struct kgd_dev *kgd,struct pci_dev *pdev); +bool (*device_init)(struct kfd_dev *kfd,const struct kgd2kfd_shared_resources *gpu_resources); +void (*device_exit)(struct kfd_dev *kfd); +void (*interrupt)(struct kfd_dev *kfd,const void *ih_ring_entry); +void (*suspend)(struct kfd_dev *kfd); +int (*resume)(struct kfd_dev *kfd); +}; + +/** +* struct kfd2kgd_calls +* +* @init_sa_manager: Initialize an instance of the sa manager, used by +* amdkfd for all system memory allocations that are mapped to the GART +* address space +* +* @fini_sa_manager: Releases all memory allocations for amdkfd that are +* handled by radeon sa manager +* +* @allocate_mem: Allocate a buffer from amdkfd's sa manager. The buffer can +* be used for mqds, hpds, kernel queue, fence and runlists +* +* @free_mem: Frees a buffer that was allocated by amdkfd's sa manager +* +* @get_vmem_size: Retrieves (physical) size of VRAM +* +* @get_gpu_clock_counter: Retrieves GPU clock counter +* +* @get_max_engine_clock_in_mhz: Retrieves maximum GPU clock in MHz +* +* @program_sh_mem_settings: A function that should initiate the memory +* properties such as main aperture memory type (cache / non cached) and +* secondary aperture base address, size and memory type. +* This function is used only for no cp scheduling mode. +* +* @set_pasid_vmid_mapping: Exposes pasid/vmid pair to the H/W for no cp +* scheduling mode. Only used for no cp scheduling mode. +* +* @init_memory: Initializes memory apertures to fixed base/limit address +* and non cached memory types. +* +* @init_pipeline: Initialized the compute pipelines. +* +* @hqd_load: Loads the mqd structure to a H/W hqd slot. used only for no cp +* sceduling mode. +* +* @hqd_is_occupies: Checks if a hqd slot is occupied. +* +* @hqd_destroy: Destructs and preempts the queue assigned to that hqd slot. +* +* This structure contains function pointers to services that the radeon driver +* provides to amdkfd driver. +* +*/ +struct kfd2kgd_calls { +/* Memory management. */ +int (*init_sa_manager)(struct kgd_dev *kgd,unsigned int size); +void (*fini_sa_manager)(struct kgd_dev *kgd); +int (*allocate_mem)(struct kgd_dev *kgd,size_t size,size_t alignment, +enum kgd_memory_pool pool,struct kgd_mem **mem); + +void (*free_mem)(struct kgd_dev *kgd,struct kgd_mem *mem); + +uint64_t (*get_vmem_size)(struct kgd_dev *kgd); +uint64_t (*get_gpu_clock_counter)(struct kgd_dev *kgd); + +uint32_t (*get_max_engine_clock_in_mhz)(struct kgd_dev *kgd); + +/* Register access functions */ +void (*program_sh_mem_settings)(struct kgd_dev *kgd,uint32_t vmid,uint32_t sh_mem_config, +uint32_t sh_mem_ape1_base,uint32_t sh_mem_ape1_limit,uint32_t sh_mem_bases); +int (*set_pasid_vmid_mapping)(struct kgd_dev *kgd,unsigned int pasid,unsigned int vmid); +int (*init_memory)(struct kgd_dev *kgd); +int (*init_pipeline)(struct kgd_dev *kgd,uint32_t pipe_id,uint32_t hpd_size,uint64_t hpd_gpu_addr); +int (*hqd_load)(struct kgd_dev *kgd,void *mqd,uint32_t pipe_id,uint32_t queue_id,uint32_t __user *wptr); +bool (*hqd_is_occupies)(struct kgd_dev *kgd,uint64_t queue_address,uint32_t pipe_id,uint32_t queue_id); +int (*hqd_destroy)(struct kgd_dev *kgd,bool is_reset,unsigned int timeout, +uint32_t pipe_id,uint32_t queue_id); +}; + +bool radeon_kfd_init (void ); +void radeon_kfd_fini (void ); +bool kgd2kfd_init (unsigned interface_version, +const struct kfd2kgd_calls *f2g, +const struct kgd2kfd_calls **g2f); + +void radeon_kfd_suspend (struct radeon_device *rdev); +int radeon_kfd_resume (struct radeon_device *rdev); +void radeon_kfd_interrupt (struct radeon_device *rdev, +const void *ih_ring_entry); +void radeon_kfd_device_probe (struct radeon_device *rdev); +void radeon_kfd_device_init (struct radeon_device *rdev); +void radeon_kfd_device_fini (struct radeon_device *rdev); + +#endif +drivers/gpu/drm/radeon/radeon_kms.c +7
-0@@ -34,6 +34,8 @@#include <linux/slab.h> #include <linux/pm_runtime.h> +#include "radeon_kfd.h" +#if defined(CONFIG_VGA_SWITCHEROO )bool radeon_has_atpx (void );#else @@ -63,6 +65,8 @@ int radeon_driver_unload_kms(struct drm_device *dev)pm_runtime_get_sync (dev->dev); +radeon_kfd_device_fini (rdev); +radeon_acpi_fini (rdev);radeon_modeset_fini (rdev);@@ -142,6 +146,9 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) "Error during ACPI methods call\n"); } +radeon_kfd_device_probe (rdev); +radeon_kfd_device_init (rdev); +if (radeon_is_px (dev)) {pm_runtime_use_autosuspend (dev->dev);pm_runtime_set_autosuspend_delay (dev->dev,5000 );
Re: [PATCH v4 01/23] drm/radeon: reduce number of free VMIDs and pipes in KV
In reply to Oded GabbayQuoted 10 lines · Oded Gabbay
To support HSA on KV, we need to limit the number of vmids and pipes that are available for radeon's use with KV.
This patch reserves VMIDs 8-15 for amdkfd (so radeon can only use VMIDs 0-7) and also makes radeon thinks that KV has only a single MEC with a single pipe in it
v3: Use define for static vmid allocation in radeon
Signed-off-by Oded Gabbay <[email protected]>
Quoted 104 lines
--- drivers/gpu/drm/radeon/cik.c | 48 +++++++++++++++++++++---------------------- drivers/gpu/drm/radeon/cikd.h | 2 ++ 2 files changed, 26 insertions(+), 24 deletions(-)drivers/gpu/drm/radeon/cik.c +24
-24@@ -4678,12 +4678,11 @@ static int cik_mec_init(struct radeon_device *rdev)/* * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total +* Nonetheless, we assign only 1 pipe because all other pipes will +* be handled by KFD */ -if (rdev->family ==CHIP_KAVERI ) - rdev->mec.num_mec =2 ; -else - rdev->mec.num_mec =1 ; - rdev->mec.num_pipe =4 ; + rdev->mec.num_mec =1 ; + rdev->mec.num_pipe =1 ; rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe *8 ;if (rdev->mec.hpd_eop_obj ==NULL ) {@@ -4825,28 +4824,24 @@ static int cik_cp_compute_resume(struct radeon_device *rdev)/* init the pipes */ mutex_lock (&rdev->srbm_mutex); -for (i =0 ; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) { -int me = (i <4 ) ?1 :2 ; -int pipe = (i <4 ) ? i : (i -4 ); - eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i *MEC_HPD_SIZE *2 ); + eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr; -cik_srbm_select (rdev, me, pipe,0 ,0 ); +cik_srbm_select (rdev,0 ,0 ,0 ,0 ); -/* write the EOP addr */ -WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); -WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); +/* write the EOP addr */ +WREG32 (CP_HPD_EOP_BASE_ADDR , eop_gpu_addr >>8 ); +WREG32 (CP_HPD_EOP_BASE_ADDR_HI ,upper_32_bits (eop_gpu_addr) >>8 ); -/* set the VMID assigned */ -WREG32 (CP_HPD_EOP_VMID ,0 ); +/* set the VMID assigned */ +WREG32 (CP_HPD_EOP_VMID ,0 ); + +/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ + tmp =RREG32 (CP_HPD_EOP_CONTROL ); + tmp &= ~EOP_SIZE_MASK ; + tmp |=order_base_2 (MEC_HPD_SIZE /8 ); +WREG32 (CP_HPD_EOP_CONTROL , tmp); -/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */ - tmp =RREG32 (CP_HPD_EOP_CONTROL ); - tmp &= ~EOP_SIZE_MASK ; - tmp |=order_base_2 (MEC_HPD_SIZE /8 ); -WREG32 (CP_HPD_EOP_CONTROL , tmp); - } -cik_srbm_select (rdev,0 ,0 ,0 ,0 );mutex_unlock (&rdev->srbm_mutex);/* init the queues. Just two for now. */ @@ -5900,8 +5895,13 @@ int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)*/ int cik_vm_init (struct radeon_device *rdev) { -/* number of VMs */ - rdev->vm_manager.nvm =16 ; +/* +* number of VMs +* VMID 0 is reserved for System +* radeon graphics/compute will use VMIDs 1-7 +* amdkfd will use VMIDs 8-15 +*/ + rdev->vm_manager.nvm =RADEON_NUM_OF_VMIDS ;/* base offset of vram pages */ if (rdev->flags &RADEON_IS_IGP ) {u64 tmp =RREG32 (MC_VM_FB_OFFSET );drivers/gpu/drm/radeon/cikd.h +2
-1@@ -30,6 +30,8 @@#define CIK_RB_BITMAP_WIDTH_PER_SH 2#define HAWAII_RB_BITMAP_WIDTH_PER_SH 4 +#define RADEON_NUM_OF_VMIDS 8 +/* DIDT IND registers */ #define DIDT_SQ_CTRL0 0x0# define DIDT_CTRL_EN (1 << 0) --1.9.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 02/23] drm/radeon/cik: Don't touch int of pipes 1-7
In reply to Oded GabbayQuoted 3 lines · Oded Gabbay
amdkfd should set interrupts for pipes 1-7.
Signed-off-by Oded Gabbay <[email protected]>
Quoted 121 lines
--- drivers/gpu/drm/radeon/cik.c | 71 +------------------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-)drivers/gpu/drm/radeon/cik.c +1
-71@@ -7291,8 +7291,7 @@ static int cik_irq_init(struct radeon_device *rdev)int cik_irq_set (struct radeon_device *rdev) {u32 cp_int_cntl; -u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3; -u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3; +u32 cp_m1p0;u32 crtc1 =0 , crtc2 =0 , crtc3 =0 , crtc4 =0 , crtc5 =0 , crtc6 =0 ;u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;u32 grbm_int_cntl =0 ;@@ -7326,13 +7325,6 @@ int cik_irq_set(struct radeon_device *rdev) dma_cntl1 =RREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET ) & ~TRAP_ENABLE ; cp_m1p0 =RREG32 (CP_ME1_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p1 =RREG32 (CP_ME1_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p2 =RREG32 (CP_ME1_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m1p3 =RREG32 (CP_ME1_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p0 =RREG32 (CP_ME2_PIPE0_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p1 =RREG32 (CP_ME2_PIPE1_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p2 =RREG32 (CP_ME2_PIPE2_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ; - cp_m2p3 =RREG32 (CP_ME2_PIPE3_INT_CNTL ) & ~TIME_STAMP_INT_ENABLE ;if (rdev->flags &RADEON_IS_IGP ) thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL) &@@ -7354,33 +7346,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp1 invalid pipe %d\n" , ring->pipe);break ;@@ -7397,33 +7362,6 @@ int cik_irq_set(struct radeon_device *rdev)case 0 : cp_m1p0 |=TIME_STAMP_INT_ENABLE ;break ; -case 1 : - cp_m1p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m1p2 |=TIME_STAMP_INT_ENABLE ; -break ; -default : -DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe); -break ; - } - }else if (ring->me ==2 ) { -switch (ring->pipe) { -case 0 : - cp_m2p0 |=TIME_STAMP_INT_ENABLE ; -break ; -case 1 : - cp_m2p1 |=TIME_STAMP_INT_ENABLE ; -break ; -case 2 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ; -case 3 : - cp_m2p2 |=TIME_STAMP_INT_ENABLE ; -break ;default :DRM_DEBUG ("si_irq_set: sw int cp2 invalid pipe %d\n" , ring->pipe);break ;@@ -7512,13 +7450,6 @@ int cik_irq_set(struct radeon_device *rdev)WREG32 (SDMA0_CNTL +SDMA1_REGISTER_OFFSET , dma_cntl1);WREG32 (CP_ME1_PIPE0_INT_CNTL , cp_m1p0); -WREG32 (CP_ME1_PIPE1_INT_CNTL , cp_m1p1); -WREG32 (CP_ME1_PIPE2_INT_CNTL , cp_m1p2); -WREG32 (CP_ME1_PIPE3_INT_CNTL , cp_m1p3); -WREG32 (CP_ME2_PIPE0_INT_CNTL , cp_m2p0); -WREG32 (CP_ME2_PIPE1_INT_CNTL , cp_m2p1); -WREG32 (CP_ME2_PIPE2_INT_CNTL , cp_m2p2); -WREG32 (CP_ME2_PIPE3_INT_CNTL , cp_m2p3);WREG32 (GRBM_INT_CNTL , grbm_int_cntl); --1.9.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 03/23] drm/radeon: Report doorbell configuration to amdkfd
In reply to Oded GabbayQuoted 6 lines · Oded Gabbay
radeon and amdkfd share the doorbell aperture.
radeon sets it up, takes the doorbells required for its own rings and reports the setup to amdkfd.
radeon reserved doorbells are at the start of the doorbell aperture.Signed-off-by Oded Gabbay <[email protected]>
Quoted 69 lines
--- drivers/gpu/drm/radeon/radeon.h | 4 ++++ drivers/gpu/drm/radeon/radeon_device.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)drivers/gpu/drm/radeon/radeon.h +4
-0@@ -697,6 +697,10 @@ struct radeon_doorbell {int radeon_doorbell_get (struct radeon_device *rdev,u32 *page);void radeon_doorbell_free (struct radeon_device *rdev,u32 doorbell); +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset);/* * IRQS. drivers/gpu/drm/radeon/radeon_device.c +31
-1@@ -373,6 +373,37 @@ void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell)__clear_bit (doorbell, rdev->doorbell.used); } +/** +* radeon_doorbell_get_kfd_info - Report doorbell configuration required to +* setup KFD +* +* @rdev: radeon_device pointer +* @aperture_base: output returning doorbell aperture base physical address +* @aperture_size: output returning doorbell aperture size in bytes +* @start_offset: output returning # of doorbell bytes reserved for radeon. +* +* Radeon and the KFD share the doorbell aperture. Radeon sets it up, +* takes doorbells required for its own rings and reports the setup to KFD. +* Radeon reserved doorbells are at the start of the doorbell aperture. +*/ +void radeon_doorbell_get_kfd_info (struct radeon_device *rdev, +phys_addr_t *aperture_base, +size_t *aperture_size, +size_t *start_offset) +{ +/* The first num_doorbells are used by radeon. +* KFD takes whatever's left in the aperture. */ +if (rdev->doorbell.size > rdev->doorbell.num_doorbells *sizeof (u32)) { + *aperture_base = rdev->doorbell.base; + *aperture_size = rdev->doorbell.size; + *start_offset = rdev->doorbell.num_doorbells *sizeof (u32); + }else { + *aperture_base =0 ; + *aperture_size =0 ; + *start_offset =0 ; + } +} +/* * radeon_wb_*() * Writeback is the the method by which the the GPU updates special pages -- 1.9.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 04/23] drm/radeon: adding synchronization for GRBM GFX
In reply to Oded GabbayQuoted 5 lines · Oded Gabbay
Implementing a lock for selecting and accessing shader engines and arrays. This lock will make sure that radeon and amdkfd are not colliding when accessing shader engines and arrays with
GRBM_GFX_INDEXregister.Signed-off-by Oded Gabbay <[email protected]>
Quoted 196 lines
--- drivers/gpu/drm/radeon/cik.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/radeon/radeon.h | 2 ++ drivers/gpu/drm/radeon/radeon_device.c | 1 + 3 files changed, 29 insertions(+)drivers/gpu/drm/radeon/cik.c +26
-0@@ -1563,6 +1563,8 @@ static const u32 godavari_golden_registers[] =static void cik_init_golden_registers (struct radeon_device *rdev) { +/* Some of the registers might be dependant on GRBM_GFX_INDEX */ +mutex_lock (&rdev->grbm_idx_mutex);switch (rdev->family) {case CHIP_BONAIRE : radeon_program_register_sequence(rdev,@@ -1637,6 +1639,7 @@ static void cik_init_golden_registers(struct radeon_device *rdev)default :break ; } +mutex_unlock (&rdev->grbm_idx_mutex); }/** @@ -3419,6 +3422,7 @@ static void cik_setup_rb(struct radeon_device *rdev,u32 disabled_rbs =0 ;u32 enabled_rbs =0 ; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {for (j =0 ; j < sh_per_se; j++) {cik_select_se_sh (rdev, i, j);@@ -3430,6 +3434,7 @@ static void cik_setup_rb(struct radeon_device *rdev, } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =1 ;for (i =0 ; i < max_rb_num_per_se * se_num; i++) {@@ -3440,6 +3445,7 @@ static void cik_setup_rb(struct radeon_device *rdev, rdev->config.cik.backend_enable_mask = enabled_rbs; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < se_num; i++) {cik_select_se_sh (rdev, i,0xffffffff ); data =0 ;@@ -3467,6 +3473,7 @@ static void cik_setup_rb(struct radeon_device *rdev,WREG32 (PA_SC_RASTER_CONFIG , data); }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); }/** @@ -3684,6 +3691,12 @@ static void cik_gpu_init(struct radeon_device *rdev)/* set HW defaults for 3D engine */ WREG32 (CP_MEQ_THRESHOLDS ,MEQ1_START (0x30 ) |MEQ2_START (0x60 )); +mutex_lock (&rdev->grbm_idx_mutex); +/* +* making sure that the following register writes will be broadcasted +* to all the shaders +*/ +cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (SX_DEBUG_1 ,0x20 );WREG32 (TA_CNTL_AUX ,0x00010000 );@@ -3739,6 +3752,7 @@ static void cik_gpu_init(struct radeon_device *rdev)WREG32 (PA_CL_ENHANCE ,CLIP_VTX_REORDER_ENA |NUM_CLIP_SEQ (3 ));WREG32 (PA_SC_ENHANCE ,ENABLE_PA_SC_OUT_OF_ORDER ); +mutex_unlock (&rdev->grbm_idx_mutex);udelay (50 ); }@@ -6062,6 +6076,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)u32 i, j, k;u32 mask; +mutex_lock (&rdev->grbm_idx_mutex);for (i =0 ; i < rdev->config.cik.max_shader_engines; i++) {for (j =0 ; j < rdev->config.cik.max_sh_per_se; j++) {cik_select_se_sh (rdev, i, j);@@ -6073,6 +6088,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev) } }cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); mask =SE_MASTER_BUSY_MASK |GC_MASTER_BUSY |TC0_MASTER_BUSY |TC1_MASTER_BUSY ;for (k =0 ; k < rdev->usec_timeout; k++) {@@ -6207,10 +6223,12 @@ static int cik_rlc_resume(struct radeon_device *rdev)WREG32 (RLC_LB_CNTR_INIT ,0 );WREG32 (RLC_LB_CNTR_MAX ,0x00008000 ); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_LB_INIT_CU_MASK ,0xffffffff );WREG32 (RLC_LB_PARAMS ,0x00600408 );WREG32 (RLC_LB_CNTL ,0x80000004 ); +mutex_unlock (&rdev->grbm_idx_mutex);WREG32 (RLC_MC_CNTL ,0 );WREG32 (RLC_UCODE_CNTL ,0 );@@ -6277,11 +6295,13 @@ static void cik_enable_cgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); tmp2 =BPM_ADDR_MASK |CGCG_OVERRIDE_0 |CGLS_ENABLE ;WREG32 (RLC_SERDES_WR_CTRL , tmp2); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);@@ -6323,11 +6343,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_0 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp);@@ -6371,11 +6393,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable) tmp =cik_halt_rlc (rdev); +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev,0xffffffff ,0xffffffff );WREG32 (RLC_SERDES_WR_CU_MASTER_MASK ,0xffffffff );WREG32 (RLC_SERDES_WR_NONCU_MASTER_MASK ,0xffffffff ); data =BPM_ADDR_MASK |MGCG_OVERRIDE_1 ;WREG32 (RLC_SERDES_WR_CTRL , data); +mutex_unlock (&rdev->grbm_idx_mutex);cik_update_rlc (rdev, tmp); }@@ -6804,10 +6828,12 @@ static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)u32 mask =0 , tmp, tmp1;int i; +mutex_lock (&rdev->grbm_idx_mutex);cik_select_se_sh (rdev, se, sh); tmp =RREG32 (CC_GC_SHADER_ARRAY_CONFIG ); tmp1 =RREG32 (GC_USER_SHADER_ARRAY_CONFIG );cik_select_se_sh (rdev,0xffffffff ,0xffffffff ); +mutex_unlock (&rdev->grbm_idx_mutex); tmp &=0xffff0000 ;drivers/gpu/drm/radeon/radeon.h +2
-0@@ -2386,6 +2386,8 @@ struct radeon_device {struct radeon_atcs atcs;/* srbm instance registers */ struct mutex srbm_mutex; +/* GRBM index mutex. Protects concurrents access to GRBM index */ +struct mutex grbm_idx_mutex;/* clock, powergating flags */ u32 cg_flags;u32 pg_flags;drivers/gpu/drm/radeon/radeon_device.c +1
-1@@ -1299,6 +1299,7 @@ int radeon_device_init(struct radeon_device *rdev,mutex_init (&rdev->pm.mutex);mutex_init (&rdev->gpu_clock_mutex);mutex_init (&rdev->srbm_mutex); +mutex_init (&rdev->grbm_idx_mutex);init_rwsem (&rdev->pm.mclk_lock);init_rwsem (&rdev->exclusive_lock);init_waitqueue_head (&rdev->irq.vblank_queue); --1.9.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel