Up to this point, those functions are all the same for all ASICs, so
no need to call them by functions pointers. Removing the function
pointers will greatly increase the code readablity. If there is ever
need for those function pointers, we can add it back then.

Change-Id: I9515fdece70110067cda66e2d24d6768b4846c2f
Signed-off-by: Yong Zhao <yong.z...@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c       |  8 ++---
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 30 ++++++++--------
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.h | 34 +++++--------------
 .../gpu/drm/amd/amdkfd/kfd_packet_manager.c   | 28 +++++++--------
 4 files changed, 41 insertions(+), 59 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c
index 1d33c4f25263..27bcc5b472f6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c
@@ -72,11 +72,11 @@ static int dbgdev_diq_submit_ib(struct kfd_dbgdev *dbgdev,
         * The receive packet buff will be sitting on the Indirect Buffer
         * and in the PQ we put the IB packet + sync packet(s).
         */
-       status = kq->ops.acquire_packet_buffer(kq,
+       status = kq_acquire_packet_buffer(kq,
                                pq_packets_size_in_bytes / sizeof(uint32_t),
                                &ib_packet_buff);
        if (status) {
-               pr_err("acquire_packet_buffer failed\n");
+               pr_err("kq_acquire_packet_buffer failed\n");
                return status;
        }
 
@@ -115,7 +115,7 @@ static int dbgdev_diq_submit_ib(struct kfd_dbgdev *dbgdev,
 
        if (status) {
                pr_err("Failed to allocate GART memory\n");
-               kq->ops.rollback_packet(kq);
+               kq_rollback_packet(kq);
                return status;
        }
 
@@ -151,7 +151,7 @@ static int dbgdev_diq_submit_ib(struct kfd_dbgdev *dbgdev,
 
        rm_packet->data_lo = QUEUESTATE__ACTIVE;
 
-       kq->ops.submit_packet(kq);
+       kq_submit_packet(kq);
 
        /* Wait till CP writes sync code: */
        status = amdkfd_fence_wait_timeout(
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c
index 59ee9053498c..2d56dc534459 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c
@@ -34,7 +34,10 @@
 
 #define PM4_COUNT_ZERO (((1 << 15) - 1) << 16)
 
-static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev,
+/* Initialize a kernel queue, including allocations of GART memory
+ * needed for the queue.
+ */
+static bool kq_initialize(struct kernel_queue *kq, struct kfd_dev *dev,
                enum kfd_queue_type type, unsigned int queue_size)
 {
        struct queue_properties prop;
@@ -88,7 +91,7 @@ static bool initialize(struct kernel_queue *kq, struct 
kfd_dev *dev,
        kq->pq_gpu_addr = kq->pq->gpu_addr;
 
        /* For CIK family asics, kq->eop_mem is not needed */
-       if (dev->device_info->asic_family > CHIP_HAWAII) {
+       if (dev->device_info->asic_family > CHIP_MULLINS) {
                retval = kfd_gtt_sa_allocate(dev, PAGE_SIZE, &kq->eop_mem);
                if (retval != 0)
                        goto err_eop_allocate_vidmem;
@@ -191,7 +194,8 @@ static bool initialize(struct kernel_queue *kq, struct 
kfd_dev *dev,
 
 }
 
-static void uninitialize(struct kernel_queue *kq)
+/* Uninitialize a kernel queue and free all its memory usages. */
+static void kq_uninitialize(struct kernel_queue *kq)
 {
        if (kq->queue->properties.type == KFD_QUEUE_TYPE_HIQ)
                kq->mqd_mgr->destroy_mqd(kq->mqd_mgr,
@@ -220,7 +224,7 @@ static void uninitialize(struct kernel_queue *kq)
        uninit_queue(kq->queue);
 }
 
-static int acquire_packet_buffer(struct kernel_queue *kq,
+int kq_acquire_packet_buffer(struct kernel_queue *kq,
                size_t packet_size_in_dwords, unsigned int **buffer_ptr)
 {
        size_t available_size;
@@ -281,7 +285,7 @@ static int acquire_packet_buffer(struct kernel_queue *kq,
        return -ENOMEM;
 }
 
-static void submit_packet(struct kernel_queue *kq)
+void kq_submit_packet(struct kernel_queue *kq)
 {
 #ifdef DEBUG
        int i;
@@ -304,7 +308,7 @@ static void submit_packet(struct kernel_queue *kq)
        }
 }
 
-static void rollback_packet(struct kernel_queue *kq)
+void kq_rollback_packet(struct kernel_queue *kq)
 {
        if (kq->dev->device_info->doorbell_size == 8) {
                kq->pending_wptr64 = *kq->wptr64_kernel;
@@ -324,13 +328,7 @@ struct kernel_queue *kernel_queue_init(struct kfd_dev *dev,
        if (!kq)
                return NULL;
 
-       kq->ops.initialize = initialize;
-       kq->ops.uninitialize = uninitialize;
-       kq->ops.acquire_packet_buffer = acquire_packet_buffer;
-       kq->ops.submit_packet = submit_packet;
-       kq->ops.rollback_packet = rollback_packet;
-
-       if (kq->ops.initialize(kq, dev, type, KFD_KERNEL_QUEUE_SIZE))
+       if (kq_initialize(kq, dev, type, KFD_KERNEL_QUEUE_SIZE))
                return kq;
 
        pr_err("Failed to init kernel queue\n");
@@ -341,7 +339,7 @@ struct kernel_queue *kernel_queue_init(struct kfd_dev *dev,
 
 void kernel_queue_uninit(struct kernel_queue *kq)
 {
-       kq->ops.uninitialize(kq);
+       kq_uninitialize(kq);
        kfree(kq);
 }
 
@@ -361,7 +359,7 @@ static __attribute__((unused)) void test_kq(struct kfd_dev 
*dev)
                return;
        }
 
-       retval = kq->ops.acquire_packet_buffer(kq, 5, &buffer);
+       retval = kq_acquire_packet_buffer(kq, 5, &buffer);
        if (unlikely(retval != 0)) {
                pr_err("  Failed to acquire packet buffer\n");
                pr_err("Kernel queue test failed\n");
@@ -369,7 +367,7 @@ static __attribute__((unused)) void test_kq(struct kfd_dev 
*dev)
        }
        for (i = 0; i < 5; i++)
                buffer[i] = kq->nop_packet;
-       kq->ops.submit_packet(kq);
+       kq_submit_packet(kq);
 
        pr_err("Ending kernel queue test\n");
 }
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.h
index 475e9499c0af..f4cfe9f1871c 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.h
@@ -29,44 +29,28 @@
 #include "kfd_priv.h"
 
 /**
- * struct kernel_queue_ops
- *
- * @initialize: Initialize a kernel queue, including allocations of GART memory
- * needed for the queue.
- *
- * @uninitialize: Uninitialize a kernel queue and free all its memory usages.
- *
- * @acquire_packet_buffer: Returns a pointer to the location in the kernel
+ * kq_acquire_packet_buffer: Returns a pointer to the location in the kernel
  * queue ring buffer where the calling function can write its packet. It is
  * Guaranteed that there is enough space for that packet. It also updates the
  * pending write pointer to that location so subsequent calls to
  * acquire_packet_buffer will get a correct write pointer
  *
- * @submit_packet: Update the write pointer and doorbell of a kernel queue.
- *
- * @sync_with_hw: Wait until the write pointer and the read pointer of a kernel
- * queue are equal, which means the CP has read all the submitted packets.
+ * kq_submit_packet: Update the write pointer and doorbell of a kernel queue.
  *
- * @rollback_packet: This routine is called if we failed to build an acquired
+ * kq_rollback_packet: This routine is called if we failed to build an acquired
  * packet for some reason. It just overwrites the pending wptr with the current
  * one
  *
  */
-struct kernel_queue_ops {
-       bool    (*initialize)(struct kernel_queue *kq, struct kfd_dev *dev,
-                       enum kfd_queue_type type, unsigned int queue_size);
-       void    (*uninitialize)(struct kernel_queue *kq);
-       int     (*acquire_packet_buffer)(struct kernel_queue *kq,
-                                       size_t packet_size_in_dwords,
-                                       unsigned int **buffer_ptr);
 
-       void    (*submit_packet)(struct kernel_queue *kq);
-       void    (*rollback_packet)(struct kernel_queue *kq);
-};
+int kq_acquire_packet_buffer(struct kernel_queue *kq,
+                               size_t packet_size_in_dwords,
+                               unsigned int **buffer_ptr);
+void kq_submit_packet(struct kernel_queue *kq);
+void kq_rollback_packet(struct kernel_queue *kq);
 
-struct kernel_queue {
-       struct kernel_queue_ops ops;
 
+struct kernel_queue {
        /* data */
        struct kfd_dev          *dev;
        struct mqd_manager      *mqd_mgr;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index 700be4f80867..6cabed06ef5d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -278,7 +278,7 @@ int pm_send_set_resources(struct packet_manager *pm,
 
        size = pm->pmf->set_resources_size;
        mutex_lock(&pm->lock);
-       pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
+       kq_acquire_packet_buffer(pm->priv_queue,
                                        size / sizeof(uint32_t),
                                        (unsigned int **)&buffer);
        if (!buffer) {
@@ -289,9 +289,9 @@ int pm_send_set_resources(struct packet_manager *pm,
 
        retval = pm->pmf->set_resources(pm, buffer, res);
        if (!retval)
-               pm->priv_queue->ops.submit_packet(pm->priv_queue);
+               kq_submit_packet(pm->priv_queue);
        else
-               pm->priv_queue->ops.rollback_packet(pm->priv_queue);
+               kq_rollback_packet(pm->priv_queue);
 
 out:
        mutex_unlock(&pm->lock);
@@ -316,7 +316,7 @@ int pm_send_runlist(struct packet_manager *pm, struct 
list_head *dqm_queues)
        packet_size_dwords = pm->pmf->runlist_size / sizeof(uint32_t);
        mutex_lock(&pm->lock);
 
-       retval = pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
+       retval = kq_acquire_packet_buffer(pm->priv_queue,
                                        packet_size_dwords, &rl_buffer);
        if (retval)
                goto fail_acquire_packet_buffer;
@@ -326,14 +326,14 @@ int pm_send_runlist(struct packet_manager *pm, struct 
list_head *dqm_queues)
        if (retval)
                goto fail_create_runlist;
 
-       pm->priv_queue->ops.submit_packet(pm->priv_queue);
+       kq_submit_packet(pm->priv_queue);
 
        mutex_unlock(&pm->lock);
 
        return retval;
 
 fail_create_runlist:
-       pm->priv_queue->ops.rollback_packet(pm->priv_queue);
+       kq_rollback_packet(pm->priv_queue);
 fail_acquire_packet_buffer:
        mutex_unlock(&pm->lock);
 fail_create_runlist_ib:
@@ -352,7 +352,7 @@ int pm_send_query_status(struct packet_manager *pm, 
uint64_t fence_address,
 
        size = pm->pmf->query_status_size;
        mutex_lock(&pm->lock);
-       pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
+       kq_acquire_packet_buffer(pm->priv_queue,
                        size / sizeof(uint32_t), (unsigned int **)&buffer);
        if (!buffer) {
                pr_err("Failed to allocate buffer on kernel queue\n");
@@ -362,9 +362,9 @@ int pm_send_query_status(struct packet_manager *pm, 
uint64_t fence_address,
 
        retval = pm->pmf->query_status(pm, buffer, fence_address, fence_value);
        if (!retval)
-               pm->priv_queue->ops.submit_packet(pm->priv_queue);
+               kq_submit_packet(pm->priv_queue);
        else
-               pm->priv_queue->ops.rollback_packet(pm->priv_queue);
+               kq_rollback_packet(pm->priv_queue);
 
 out:
        mutex_unlock(&pm->lock);
@@ -381,7 +381,7 @@ int pm_send_unmap_queue(struct packet_manager *pm, enum 
kfd_queue_type type,
 
        size = pm->pmf->unmap_queues_size;
        mutex_lock(&pm->lock);
-       pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
+       kq_acquire_packet_buffer(pm->priv_queue,
                        size / sizeof(uint32_t), (unsigned int **)&buffer);
        if (!buffer) {
                pr_err("Failed to allocate buffer on kernel queue\n");
@@ -392,9 +392,9 @@ int pm_send_unmap_queue(struct packet_manager *pm, enum 
kfd_queue_type type,
        retval = pm->pmf->unmap_queues(pm, buffer, type, filter, filter_param,
                                       reset, sdma_engine);
        if (!retval)
-               pm->priv_queue->ops.submit_packet(pm->priv_queue);
+               kq_submit_packet(pm->priv_queue);
        else
-               pm->priv_queue->ops.rollback_packet(pm->priv_queue);
+               kq_rollback_packet(pm->priv_queue);
 
 out:
        mutex_unlock(&pm->lock);
@@ -439,7 +439,7 @@ int pm_debugfs_hang_hws(struct packet_manager *pm)
 
        size = pm->pmf->query_status_size;
        mutex_lock(&pm->lock);
-       pm->priv_queue->ops.acquire_packet_buffer(pm->priv_queue,
+       kq_acquire_packet_buffer(pm->priv_queue,
                        size / sizeof(uint32_t), (unsigned int **)&buffer);
        if (!buffer) {
                pr_err("Failed to allocate buffer on kernel queue\n");
@@ -447,7 +447,7 @@ int pm_debugfs_hang_hws(struct packet_manager *pm)
                goto out;
        }
        memset(buffer, 0x55, size);
-       pm->priv_queue->ops.submit_packet(pm->priv_queue);
+       kq_submit_packet(pm->priv_queue);
 
        pr_info("Submitting %x %x %x %x %x %x %x to HIQ to hang the HWS.",
                buffer[0], buffer[1], buffer[2], buffer[3],
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to