Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/include/linux i915: Adapt i915_perf.c.



details:   https://anonhg.NetBSD.org/src/rev/61925e83e901
branches:  trunk
changeset: 1028659:61925e83e901
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:36:56 2021 +0000

description:
i915: Adapt i915_perf.c.

diffstat:

 sys/external/bsd/drm2/dist/drm/i915/i915_perf.c       |  312 ++++++++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h |   25 +-
 sys/external/bsd/drm2/drm/drm_sysctl.c                |    6 +-
 sys/external/bsd/drm2/include/linux/hrtimer.h         |    3 +-
 sys/external/bsd/drm2/include/linux/math64.h          |    8 +-
 sys/external/bsd/drm2/include/linux/ratelimit.h       |   30 +-
 sys/external/bsd/drm2/include/linux/uuid.h            |   30 +-
 7 files changed, 377 insertions(+), 37 deletions(-)

diffs (truncated from 1045 to 300 lines):

diff -r b7d54b803125 -r 61925e83e901 sys/external/bsd/drm2/dist/drm/i915/i915_perf.c
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c   Sun Dec 19 11:36:48 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c   Sun Dec 19 11:36:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_perf.c,v 1.4 2021/12/19 11:33:49 riastradh Exp $  */
+/*     $NetBSD: i915_perf.c,v 1.5 2021/12/19 11:36:56 riastradh Exp $  */
 
 /*
  * Copyright © 2015-2016 Intel Corporation
@@ -194,7 +194,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_perf.c,v 1.4 2021/12/19 11:33:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_perf.c,v 1.5 2021/12/19 11:36:56 riastradh Exp $");
 
 #include <linux/anon_inodes.h>
 #include <linux/sizes.h>
@@ -225,7 +225,12 @@
 #include "oa/i915_oa_icl.h"
 #include "oa/i915_oa_tgl.h"
 
+#ifdef __NetBSD__
+#include <sys/filedesc.h>
+#include <sys/poll.h>
+#include <sys/select.h>
 #include <linux/nbsd-namespace.h>
+#endif
 
 /* HW requires this to be a power of two, between 128k and 16M, though driver
  * is currently generally designed assuming the largest 16M size is used such
@@ -394,7 +399,9 @@
        struct i915_vma *vma;
 };
 
+#ifndef __NetBSD__             /* XXX i915 perf sysctl */
 static struct ctl_table_header *sysctl_header;
+#endif
 
 static enum hrtimer_restart oa_poll_check_timer_cb(struct hrtimer *hrtimer);
 
@@ -458,7 +465,7 @@
 }
 
 /**
- * oa_buffer_check_unlocked - check for data and update tail ptr state
+ * oa_buffer_check - check for data and update tail ptr state
  * @stream: i915 stream instance
  *
  * This is either called via fops (for blocking reads in user ctx) or the poll
@@ -481,10 +488,9 @@
  *
  * Returns: %true if the OA buffer contains data, else %false
  */
-static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream)
+static bool oa_buffer_check(struct i915_perf_stream *stream)
 {
        int report_size = stream->oa_buffer.format_size;
-       unsigned long flags;
        unsigned int aged_idx;
        u32 head, hw_tail, aged_tail, aging_tail;
        u64 now;
@@ -493,7 +499,6 @@
         * could result in an OA buffer reset which might reset the head,
         * tails[] and aged_tail state.
         */
-       spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
 
        /* NB: The head we observe here might effectively be a little out of
         * date (between head and tails[aged_idx].offset if there is currently
@@ -567,8 +572,6 @@
                }
        }
 
-       spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
-
        return aged_tail == INVALID_TAIL_PTR ?
                false : OA_TAKEN(aged_tail, head) >= report_size;
 }
@@ -589,13 +592,23 @@
  * Returns: 0 on success, negative error code on failure.
  */
 static int append_oa_status(struct i915_perf_stream *stream,
+#ifdef __NetBSD__
+                           struct uio *buf,
+                           kauth_cred_t count, /* XXX dummy */
+                           int offset,         /* XXX dummy */
+#else
                            char __user *buf,
                            size_t count,
                            size_t *offset,
+#endif
                            enum drm_i915_perf_record_type type)
 {
        struct drm_i915_perf_record_header header = { type, 0, sizeof(header) };
 
+#ifdef __NetBSD__
+       /* XXX errno NetBSD->Linux */
+       return -uiomove(&header, sizeof(header), buf);
+#else
        if ((count - *offset) < header.size)
                return -ENOSPC;
 
@@ -605,6 +618,7 @@
        (*offset) += header.size;
 
        return 0;
+#endif
 }
 
 /**
@@ -625,9 +639,15 @@
  * Returns: 0 on success, negative error code on failure.
  */
 static int append_oa_sample(struct i915_perf_stream *stream,
+#ifdef __NetBSD__
+                           struct uio *buf,
+                           kauth_cred_t count, /* XXX dummy */
+                           int offset,         /* XXX dummy */
+#else
                            char __user *buf,
                            size_t count,
                            size_t *offset,
+#endif
                            const u8 *report)
 {
        int report_size = stream->oa_buffer.format_size;
@@ -638,6 +658,12 @@
        header.pad = 0;
        header.size = stream->sample_size;
 
+#ifdef __NetBSD__
+       /* XXX errno NetBSD->Linux */
+       int ret = -uiomove(&header, sizeof(header), buf);
+       if (ret)
+               return ret;
+#else
        if ((count - *offset) < header.size)
                return -ENOSPC;
 
@@ -645,13 +671,22 @@
        if (copy_to_user(buf, &header, sizeof(header)))
                return -EFAULT;
        buf += sizeof(header);
+#endif
 
        if (sample_flags & SAMPLE_OA_REPORT) {
+#ifdef __NetBSD__
+               ret = -uiomove(__UNCONST(report), report_size, buf);
+               if (ret)
+                       return ret;
+#else
                if (copy_to_user(buf, report, report_size))
                        return -EFAULT;
+#endif
        }
 
+#ifndef __NetBSD__             /* done by uiomove */
        (*offset) += header.size;
+#endif
 
        return 0;
 }
@@ -676,17 +711,28 @@
  *
  * Returns: 0 on success, negative error code on failure.
  */
+#ifdef __NetBSD__
+static int gen8_append_oa_reports(struct i915_perf_stream *stream,
+                                 struct uio *buf,
+                                 kauth_cred_t count, /* XXX dummy */
+                                 int offset)         /* XXX dummy */
+#else
 static int gen8_append_oa_reports(struct i915_perf_stream *stream,
                                  char __user *buf,
                                  size_t count,
                                  size_t *offset)
+#endif
 {
        struct intel_uncore *uncore = stream->uncore;
        int report_size = stream->oa_buffer.format_size;
        u8 *oa_buf_base = stream->oa_buffer.vaddr;
        u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
        u32 mask = (OA_BUFFER_SIZE - 1);
+#ifdef __NetBSD__
+       size_t start_offset = buf->uio_offset;
+#else
        size_t start_offset = *offset;
+#endif
        unsigned long flags;
        unsigned int aged_tail_idx;
        u32 head, tail;
@@ -850,7 +896,12 @@
                report32[0] = 0;
        }
 
-       if (start_offset != *offset) {
+#ifdef __NetBSD__
+       if (start_offset != buf->uio_offset)
+#else
+       if (start_offset != *offset)
+#endif
+       {
                i915_reg_t oaheadptr;
 
                oaheadptr = IS_GEN(stream->perf->i915, 12) ?
@@ -893,10 +944,17 @@
  *
  * Returns: zero on success or a negative error code
  */
+#ifdef __NetBSD__
+static int gen8_oa_read(struct i915_perf_stream *stream,
+                       struct uio *buf,
+                       kauth_cred_t count,   /* XXX dummy */
+                       int offset)           /* XXX dummy */
+#else
 static int gen8_oa_read(struct i915_perf_stream *stream,
                        char __user *buf,
                        size_t count,
                        size_t *offset)
+#endif
 {
        struct intel_uncore *uncore = stream->uncore;
        u32 oastatus;
@@ -976,17 +1034,28 @@
  *
  * Returns: 0 on success, negative error code on failure.
  */
+#ifdef __NetBSD__
+static int gen7_append_oa_reports(struct i915_perf_stream *stream,
+                                 struct uio *buf,
+                                 kauth_cred_t count, /* XXX dummy */
+                                 int offset)         /* XXX dummy */
+#else
 static int gen7_append_oa_reports(struct i915_perf_stream *stream,
                                  char __user *buf,
                                  size_t count,
                                  size_t *offset)
+#endif
 {
        struct intel_uncore *uncore = stream->uncore;
        int report_size = stream->oa_buffer.format_size;
        u8 *oa_buf_base = stream->oa_buffer.vaddr;
        u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
        u32 mask = (OA_BUFFER_SIZE - 1);
+#ifdef __NetBSD__
+       size_t start_offset = buf->uio_offset;
+#else
        size_t start_offset = *offset;
+#endif
        unsigned long flags;
        unsigned int aged_tail_idx;
        u32 head, tail;
@@ -1073,7 +1142,12 @@
                report32[0] = 0;
        }
 
-       if (start_offset != *offset) {
+#ifdef __NetBSD__
+       if (start_offset != buf->uio_offset)
+#else
+       if (start_offset != *offset)
+#endif
+       {
                spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
 
                /* We removed the gtt_offset for the copy loop above, indexing
@@ -1108,10 +1182,17 @@
  *
  * Returns: zero on success or a negative error code
  */
+#ifdef __NetBSD__
+static int gen7_oa_read(struct i915_perf_stream *stream,
+                       struct uio *buf,
+                       kauth_cred_t count,   /* XXX dummy */
+                       int offset)           /* XXX dummy */
+#else
 static int gen7_oa_read(struct i915_perf_stream *stream,
                        char __user *buf,
                        size_t count,
                        size_t *offset)
+#endif
 {
        struct intel_uncore *uncore = stream->uncore;
        u32 oastatus1;
@@ -1192,12 +1273,19 @@
  */
 static int i915_oa_wait_unlocked(struct i915_perf_stream *stream)
 {
+       unsigned long flags;
+       int ret;
+
        /* We would wait indefinitely if periodic sampling is not enabled */
        if (!stream->periodic)
                return -EIO;
 
-       return wait_event_interruptible(stream->poll_wq,
-                                       oa_buffer_check_unlocked(stream));
+       spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
+       DRM_SPIN_WAIT_UNTIL(ret, &stream->poll_wq, &stream->oa_buffer.ptr_lock,



Home | Main Index | Thread Index | Old Index