drm/amdkfd: Expose HDP registers to user space
authorOak Zeng <Oak.Zeng@amd.com>
Thu, 11 Apr 2019 19:43:39 +0000 (14:43 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 24 May 2019 17:20:47 +0000 (12:20 -0500)
Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) and
expose mmio page of HDP registers to user space through this new
memory type.

v2: moved remapped hdp regs to adev struct
v3: rename the new memory type to ALLOC_MEM_FLAGS_MMIO_REMAP
v4: use more generic function name
v5: Fail remapped mmio allocation for asics before gfx9

Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
drivers/gpu/drm/amd/include/kgd_kfd_interface.h
include/uapi/linux/kfd_ioctl.h

index aeead072fa7957c5080fbeef02f41e5f159c6631..401edb605fdd522bf984ef1ee96f5f3babc1e609 100644 (file)
@@ -519,6 +519,13 @@ uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)
        return adev->gmc.xgmi.hive_id;
 }
 
+uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
+{
+       struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+
+       return adev->rmmio_remap.bus_addr;
+}
+
 int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine,
                                uint32_t vmid, uint64_t gpu_addr,
                                uint32_t *ib_cmd, uint32_t ib_len)
index 4e37fa7e85b1b01f22c82600904ffbc430fcea99..ea1f141db3ff93217719a4700c05e38810ce3423 100644 (file)
@@ -169,6 +169,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
                                  uint32_t *flags);
 uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd);
 uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd);
+uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd);
 
 #define read_user_wptr(mmptr, wptr, dst)                               \
        ({                                                              \
index a6e5184d436c9339008e0c62d55dd44c75282181..00e013581a7035a913880f92382636b63eb25a88 100644 (file)
@@ -1109,7 +1109,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
                if (!offset || !*offset)
                        return -EINVAL;
                user_addr = *offset;
-       } else if (flags & ALLOC_MEM_FLAGS_DOORBELL) {
+       } else if (flags & (ALLOC_MEM_FLAGS_DOORBELL |
+                       ALLOC_MEM_FLAGS_MMIO_REMAP)) {
                domain = AMDGPU_GEM_DOMAIN_GTT;
                alloc_domain = AMDGPU_GEM_DOMAIN_CPU;
                bo_type = ttm_bo_type_sg;
@@ -1294,8 +1295,8 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
        /* Free the sync object */
        amdgpu_sync_free(&mem->sync);
 
-       /* If the SG is not NULL, it's one we created for a doorbell
-        * BO. We need to free it.
+       /* If the SG is not NULL, it's one we created for a doorbell or mmio
+        * remap BO. We need to free it.
         */
        if (mem->bo->tbo.sg) {
                sg_free_table(mem->bo->tbo.sg);
index 083bd8114db1bb8d4950b3856fa224e44e21a76f..d795e50182708238148afa7c9c10f1a9b26b16a2 100644 (file)
@@ -1272,6 +1272,12 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
                if (args->size != kfd_doorbell_process_slice(dev))
                        return -EINVAL;
                offset = kfd_get_process_doorbells(dev, p);
+       } else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {
+               if (args->size != PAGE_SIZE)
+                       return -EINVAL;
+               offset = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+               if (!offset)
+                       return -ENOMEM;
        }
 
        mutex_lock(&p->mutex);
index b897aca9b4c92778155a3dde87a1fcdbd4eb5743..98b9533e672ba9a3e876fe4cbe11e8f9d23d4c0a 100644 (file)
@@ -174,6 +174,7 @@ struct tile_config {
 #define ALLOC_MEM_FLAGS_GTT            (1 << 1)
 #define ALLOC_MEM_FLAGS_USERPTR                (1 << 2)
 #define ALLOC_MEM_FLAGS_DOORBELL       (1 << 3)
+#define ALLOC_MEM_FLAGS_MMIO_REMAP     (1 << 4)
 
 /*
  * Allocation flags attributes/access options.
index bb1b4280f53d256368a9932e0306b9435625e611..1e7d5f3376b03bca993ffc18bb54b63eb6b5b15e 100644 (file)
@@ -338,6 +338,7 @@ struct kfd_ioctl_acquire_vm_args {
 #define KFD_IOC_ALLOC_MEM_FLAGS_GTT            (1 << 1)
 #define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR                (1 << 2)
 #define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL       (1 << 3)
+#define KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP     (1 << 4)
 /* Allocation flags: attributes/access options */
 #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE       (1 << 31)
 #define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE     (1 << 30)