pan/bit: Submit a WRITE_VALUE job as a sanity check
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 24 Mar 2020 18:08:16 +0000 (14:08 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 31 Mar 2020 01:12:26 +0000 (01:12 +0000)
If this fails, everything else probably will too.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4382>

src/panfrost/bifrost/cmdline.c
src/panfrost/bifrost/test/bi_submit.c
src/panfrost/bifrost/test/bit.h

index f2a0848f8054fd07a0dc483a76cc6ca6c5f4f0b1..1d7d3d4a0a501118678c7844fe4a723cac730d76 100644 (file)
@@ -96,7 +96,8 @@ static void
 test(void)
 {
         void *memctx = NULL; /* TODO */
-        bit_initialize(memctx);
+        struct panfrost_device *dev = bit_initialize(memctx);
+        bit_sanity_check(dev);
 }
 
 int
index b098f2aa542b93b69ac7dd93a62e2fdbb4f30178..470ba8dd982c664b7886c59d6633246a0cc389c9 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "bit.h"
 #include "panfrost/pandecode/decode.h"
+#include "drm-uapi/panfrost_drm.h"
 
 /* Standalone compiler tests submitting jobs directly to the hardware. Uses the
  * `bit` prefix for `BIfrost Tests` and because bit sounds wicked cool. */
@@ -54,3 +55,67 @@ bit_initialize(void *memctx)
 
         return dev;
 }
+
+static bool
+bit_submit(struct panfrost_device *dev,
+                enum mali_job_type T,
+                void *payload, size_t payload_size,
+                struct panfrost_bo *bos, size_t bo_count)
+{
+        struct mali_job_descriptor_header header = {
+                .job_descriptor_size = MALI_JOB_64,
+                .job_type = T,
+                .job_index = 1
+        };
+
+        struct panfrost_bo *job = bit_bo_create(dev, 4096);
+        memcpy(job->cpu, &header, sizeof(header));
+        memcpy(job->cpu + sizeof(header), payload, payload_size);
+
+        uint32_t *bo_handles = calloc(sizeof(uint32_t), bo_count);
+
+        for (unsigned i = 0; i < bo_count; ++i)
+                bo_handles[i] = bos[i].gem_handle;
+
+        uint32_t syncobj = 0;
+        int ret = 0;
+
+        ret = drmSyncobjCreate(dev->fd, DRM_SYNCOBJ_CREATE_SIGNALED, &syncobj);
+        assert(!ret);
+
+        struct drm_panfrost_submit submit = {
+                .jc = job->gpu,
+                .bo_handles = (uintptr_t) bo_handles,
+                .bo_handle_count = bo_count,
+                .out_sync = syncobj,
+        };
+
+        ret = drmIoctl(dev->fd, DRM_IOCTL_PANFROST_SUBMIT, &submit);
+        assert(!ret);
+        free(bo_handles);
+
+        drmSyncobjWait(dev->fd, &syncobj, 1, INT64_MAX, 0, NULL);
+        pandecode_jc(submit.jc, true, dev->gpu_id, false);
+        return true;
+}
+
+/* Checks that the device is alive and responding to basic jobs as a sanity
+ * check - prerequisite to running code on the device. We test this via a
+ * WRITE_VALUE job */
+
+bool
+bit_sanity_check(struct panfrost_device *dev)
+{
+        struct panfrost_bo *scratch = bit_bo_create(dev, 4096);
+        ((uint32_t *) scratch->cpu)[0] = 0xAA;
+
+        struct mali_payload_write_value payload = {
+                .address = scratch->gpu,
+                .value_descriptor = MALI_WRITE_VALUE_ZERO
+        };
+
+        bool success = bit_submit(dev, JOB_TYPE_WRITE_VALUE,
+                        &payload, sizeof(payload), scratch, 1);
+
+        return success && (((uint8_t *) scratch->cpu)[0] == 0x0);
+}
index 6838da7c9eb24899e818708f53c624feb70fd8a5..8328c5f318c776b763edeea8a02ffa28780f21eb 100644 (file)
@@ -34,6 +34,8 @@
 struct panfrost_device *
 bit_initialize(void *memctx);
 
+bool bit_sanity_check(struct panfrost_device *dev);
+
 #endif