Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 11:36:57 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/i915: i915_perf.c i915_perf_types.h
        src/sys/external/bsd/drm2/drm: drm_sysctl.c
        src/sys/external/bsd/drm2/include/linux: hrtimer.h math64.h ratelimit.h
            uuid.h

Log Message:
i915: Adapt i915_perf.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c
cvs rdiff -u -r1.5 -r1.6 \
    src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/drm/drm_sysctl.c
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/hrtimer.h \
    src/sys/external/bsd/drm2/include/linux/ratelimit.h
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/include/linux/math64.h
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/include/linux/uuid.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c:1.4 src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c:1.4	Sun Dec 19 11:33:49 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_perf.c	Sun Dec 19 11:36:56 2021
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: i915_perf.c,
 #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_oa_config_bo {
 	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 @@ static u32 gen7_oa_hw_tail_read(struct i
 }
 
 /**
- * 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 @@ static u32 gen7_oa_hw_tail_read(struct i
  *
  * 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 @@ static bool oa_buffer_check_unlocked(str
 	 * 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 @@ static bool oa_buffer_check_unlocked(str
 		}
 	}
 
-	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 @@ static bool oa_buffer_check_unlocked(str
  * 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 @@ static int append_oa_status(struct i915_
 	(*offset) += header.size;
 
 	return 0;
+#endif
 }
 
 /**
@@ -625,9 +639,15 @@ static int append_oa_status(struct i915_
  * 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 @@ static int append_oa_sample(struct i915_
 	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 @@ static int append_oa_sample(struct i915_
 	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 @@ static int append_oa_sample(struct i915_
  *
  * 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 @@ static int gen8_append_oa_reports(struct
 		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 @@ static int gen8_append_oa_reports(struct
  *
  * 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 @@ static int gen8_oa_read(struct i915_perf
  *
  * 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 @@ static int gen7_append_oa_reports(struct
 		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 @@ static int gen7_append_oa_reports(struct
  *
  * 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 gen7_oa_read(struct i915_perf
  */
 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,
+	    oa_buffer_check(stream));
+	spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
+
+	return ret;
 }
 
 /**
@@ -1210,12 +1298,14 @@ static int i915_oa_wait_unlocked(struct 
  * this starts a poll_wait with the wait queue that our hrtimer callback wakes
  * when it sees data ready to read in the circular OA buffer.
  */
+#ifndef __NetBSD__
 static void i915_oa_poll_wait(struct i915_perf_stream *stream,
 			      struct file *file,
 			      poll_table *wait)
 {
 	poll_wait(file, &stream->poll_wq, wait);
 }
+#endif
 
 /**
  * i915_oa_read - just calls through to &i915_oa_ops->read
@@ -1229,10 +1319,17 @@ static void i915_oa_poll_wait(struct i91
  *
  * Returns: zero on success or a negative error code
  */
+#ifdef __NetBSD__
+static int i915_oa_read(struct i915_perf_stream *stream,
+			struct uio *buf,
+			kauth_cred_t count,   /* XXX dummy */
+			int offset)	      /* XXX dummy */
+#else
 static int i915_oa_read(struct i915_perf_stream *stream,
 			char __user *buf,
 			size_t count,
 			size_t *offset)
+#endif
 {
 	return stream->perf->ops.read(stream, buf, count, offset);
 }
@@ -1395,6 +1492,11 @@ static void i915_oa_stream_destroy(struc
 
 	BUG_ON(stream != perf->exclusive_stream);
 
+	spin_lock_destroy(&stream->oa_buffer.ptr_lock);
+	seldestroy(&stream->poll_selq);
+	DRM_DESTROY_WAITQUEUE(&stream->poll_wq);
+	hrtimer_cancel(&stream->poll_check_timer);
+
 	/*
 	 * Unset exclusive_stream first, it will be checked while disabling
 	 * the metric set on gen8+.
@@ -2699,7 +2801,9 @@ static const struct i915_perf_stream_ops
 	.enable = i915_oa_stream_enable,
 	.disable = i915_oa_stream_disable,
 	.wait_unlocked = i915_oa_wait_unlocked,
+#ifndef __NetBSD__
 	.poll_wait = i915_oa_poll_wait,
+#endif
 	.read = i915_oa_read,
 };
 
@@ -2848,7 +2952,8 @@ static int i915_oa_stream_init(struct i9
 	hrtimer_init(&stream->poll_check_timer,
 		     CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	stream->poll_check_timer.function = oa_poll_check_timer_cb;
-	init_waitqueue_head(&stream->poll_wq);
+	DRM_INIT_WAITQUEUE(&stream->poll_wq, "i915perf");
+	selinit(&stream->poll_selq);
 	spin_lock_init(&stream->oa_buffer.ptr_lock);
 
 	return 0;
@@ -2919,6 +3024,16 @@ void i915_oa_init_reg_state(const struct
  *
  * Returns: The number of bytes copied or a negative error code on failure.
  */
+#ifdef __NetBSD__
+static int i915_perf_read_locked(struct i915_perf_stream *stream,
+				     struct file *file,
+				     struct uio *buf,
+				     kauth_cred_t count, /* XXX dummy */
+				     int ppos)		 /* XXX dummy */
+{
+	return stream->ops->read(stream, buf, count, ppos);
+}
+#else
 static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream,
 				     struct file *file,
 				     char __user *buf,
@@ -2936,6 +3051,7 @@ static ssize_t i915_perf_read_locked(str
 
 	return offset ?: (ret ?: -EAGAIN);
 }
+#endif
 
 /**
  * i915_perf_read - handles read() FOP for i915 perf stream FDs
@@ -2955,12 +3071,24 @@ static ssize_t i915_perf_read_locked(str
  *
  * Returns: The number of bytes copied or a negative error code on failure.
  */
+#ifdef __NetBSD__
+static int i915_perf_read(struct file *file,
+			  off_t *offset,
+			  struct uio *buf,
+			  kauth_cred_t count, /* XXX dummy */
+			  int ppos)	      /* XXX dummy */
+#else
 static ssize_t i915_perf_read(struct file *file,
 			      char __user *buf,
 			      size_t count,
 			      loff_t *ppos)
+#endif
 {
+#ifdef __NetBSD__
+	struct i915_perf_stream *stream = file->f_data;
+#else
 	struct i915_perf_stream *stream = file->private_data;
+#endif
 	struct i915_perf *perf = stream->perf;
 	ssize_t ret;
 
@@ -2971,7 +3099,13 @@ static ssize_t i915_perf_read(struct fil
 	if (!stream->enabled)
 		return -EIO;
 
-	if (!(file->f_flags & O_NONBLOCK)) {
+#ifdef __NetBSD__
+	buf->uio_offset = *offset;
+	if (!(file->f_flag & FNONBLOCK))
+#else
+	if (!(file->f_flags & O_NONBLOCK))
+#endif
+	{
 		/* There's the small chance of false positives from
 		 * stream->ops->wait_unlocked.
 		 *
@@ -3017,17 +3151,43 @@ static enum hrtimer_restart oa_poll_chec
 {
 	struct i915_perf_stream *stream =
 		container_of(hrtimer, typeof(*stream), poll_check_timer);
+	unsigned long flags;
 
-	if (oa_buffer_check_unlocked(stream)) {
+	spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
+	if (oa_buffer_check(stream)) {
 		stream->pollin = true;
-		wake_up(&stream->poll_wq);
+		DRM_SPIN_WAKEUP_ONE(&stream->poll_wq,
+		    &stream->oa_buffer.ptr_lock);
+		selnotify(&stream->poll_selq, POLLIN|POLLRDNORM, NOTE_SUBMIT);
 	}
+	spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
 
 	hrtimer_forward_now(hrtimer, ns_to_ktime(POLL_PERIOD));
 
 	return HRTIMER_RESTART;
 }
 
+#ifdef __NetBSD__
+
+static int
+i915_perf_poll(struct file *fp, int events)
+{
+	struct i915_perf_stream *stream = fp->f_data;
+	unsigned long flags;
+	int revents = 0;
+
+	spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
+	if (stream->pollin)
+		revents |= events & (POLLIN|POLLRDNORM);
+	else
+		selrecord(curlwp, &stream->poll_selq);
+	spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
+
+	return revents;
+}
+
+#else
+
 /**
  * i915_perf_poll_locked - poll_wait() with a suitable wait queue for stream
  * @stream: An i915 perf stream
@@ -3089,6 +3249,8 @@ static __poll_t i915_perf_poll(struct fi
 	return ret;
 }
 
+#endif	/* __NetBSD__ */
+
 /**
  * i915_perf_enable_locked - handle `I915_PERF_IOCTL_ENABLE` ioctl
  * @stream: A disabled i915 perf stream
@@ -3218,11 +3380,22 @@ static long i915_perf_ioctl_locked(struc
  * Returns: zero on success or a negative error code. Returns -EINVAL for
  * an unknown ioctl request.
  */
+#ifdef __NetBSD__
+static int i915_perf_ioctl(struct file *file,
+			    unsigned long cmd,
+			    void *cookie)
+#else
 static long i915_perf_ioctl(struct file *file,
 			    unsigned int cmd,
 			    unsigned long arg)
+#endif
 {
+#ifdef __NetBSD__
+	unsigned long arg = (unsigned long)(uintptr_t)cookie;
+	struct i915_perf_stream *stream = file->f_data;
+#else
 	struct i915_perf_stream *stream = file->private_data;
+#endif
 	struct i915_perf *perf = stream->perf;
 	long ret;
 
@@ -3268,6 +3441,22 @@ static void i915_perf_destroy_locked(str
  *
  * Returns: zero on success or a negative error code.
  */
+#ifdef __NetBSD__
+static int i915_perf_close(struct file *fp)
+{
+	struct i915_perf_stream *stream = fp->f_data;
+	struct i915_perf *perf = stream->perf;
+
+	mutex_lock(&perf->lock);
+	i915_perf_destroy_locked(stream);
+	mutex_unlock(&perf->lock);
+
+	/* Release the reference the perf stream kept on the driver. */
+	drm_dev_put(&perf->i915->drm);
+
+	return 0;
+}
+#else
 static int i915_perf_release(struct inode *inode, struct file *file)
 {
 	struct i915_perf_stream *stream = file->private_data;
@@ -3282,8 +3471,41 @@ static int i915_perf_release(struct inod
 
 	return 0;
 }
+#endif
 
 
+#ifdef __NetBSD__
+static int
+i915_perf_stat(struct file *fp, struct stat *st)
+{
+	const dev_t devno = 0;	/* XXX */
+
+	memset(st, 0, sizeof(*st));
+
+	st->st_dev = devno;	/* XXX */
+	st->st_ino = 0;		/* XXX */
+	st->st_uid = kauth_cred_geteuid(fp->f_cred);
+	st->st_gid = kauth_cred_getegid(fp->f_cred);
+	st->st_mode = S_IFCHR;
+	st->st_rdev = devno;
+
+	return 0;
+}
+
+static const struct fileops fops = {
+	.fo_name = "i915perf",
+	.fo_read = i915_perf_read,
+	.fo_write = fbadop_write,
+	.fo_ioctl = i915_perf_ioctl,
+	.fo_fcntl = fnullop_fcntl,
+	.fo_poll = i915_perf_poll,
+	.fo_stat = i915_perf_stat,
+	.fo_close = i915_perf_close,
+	.fo_kqfilter = fnullop_kqfilter,	/* XXX */
+	.fo_restart = fnullop_restart,
+	.fo_mmap = NULL,
+};
+#else
 static const struct file_operations fops = {
 	.owner		= THIS_MODULE,
 	.llseek		= no_llseek,
@@ -3296,6 +3518,7 @@ static const struct file_operations fops
 	 */
 	.compat_ioctl   = i915_perf_ioctl,
 };
+#endif
 
 
 /**
@@ -3421,11 +3644,30 @@ i915_perf_open_ioctl_locked(struct i915_
 	if (param->flags & I915_PERF_FLAG_FD_NONBLOCK)
 		f_flags |= O_NONBLOCK;
 
+#ifdef __NetBSD__
+	struct file *fp;
+
+	/* XXX errno NetBSD->Linux */
+	ret = -fd_allocfile(&fp, &stream_fd);
+	if (ret)
+		goto err_flags;
+
+	fp->f_type = DTYPE_MISC;
+	fp->f_flag = FREAD;
+	if (f_flags & O_NONBLOCK)
+		fp->f_flag |= FNONBLOCK;
+	if (f_flags & O_CLOEXEC)
+		fd_set_exclose(curlwp, stream_fd, true);
+	fp->f_ops = &fops;
+
+	fd_affix(curproc, fp, stream_fd);
+#else
 	stream_fd = anon_inode_getfd("[i915_perf]", &fops, stream, f_flags);
 	if (stream_fd < 0) {
 		ret = stream_fd;
 		goto err_flags;
 	}
+#endif
 
 	if (!(param->flags & I915_PERF_FLAG_DISABLED))
 		i915_perf_enable_locked(stream);
@@ -3541,12 +3783,12 @@ static int read_properties_unlocked(stru
 			break;
 		case DRM_I915_PERF_PROP_OA_FORMAT:
 			if (value == 0 || value >= I915_OA_FORMAT_MAX) {
-				DRM_DEBUG("Out-of-range OA report format %llu\n",
+				DRM_DEBUG("Out-of-range OA report format %"PRIu64"\n",
 					  value);
 				return -EINVAL;
 			}
 			if (!perf->oa_formats[value].size) {
-				DRM_DEBUG("Unsupported OA report format %llu\n",
+				DRM_DEBUG("Unsupported OA report format %"PRIu64"\n",
 					  value);
 				return -EINVAL;
 			}
@@ -3583,7 +3825,7 @@ static int read_properties_unlocked(stru
 
 			if (oa_freq_hz > i915_oa_max_sample_rate &&
 			    !capable(CAP_SYS_ADMIN)) {
-				DRM_DEBUG("OA exponent would exceed the max sampling frequency (sysctl dev.i915.oa_max_sample_rate) %uHz without root privileges\n",
+				DRM_DEBUG("OA exponent would exceed the max sampling frequency (sysctl hw.drm2.i915.oa_max_sample_rate) %uHz without root privileges\n",
 					  i915_oa_max_sample_rate);
 				return -EACCES;
 			}
@@ -3676,7 +3918,9 @@ int i915_perf_open_ioctl(struct drm_devi
 void i915_perf_register(struct drm_i915_private *i915)
 {
 	struct i915_perf *perf = &i915->perf;
+#ifndef __NetBSD__
 	int ret;
+#endif
 
 	if (!perf->i915)
 		return;
@@ -3687,6 +3931,7 @@ void i915_perf_register(struct drm_i915_
 	 */
 	mutex_lock(&perf->lock);
 
+#ifndef __NetBSD__
 	perf->metrics_kobj =
 		kobject_create_and_add("metrics",
 				       &i915->drm.primary->kdev->kobj);
@@ -3694,6 +3939,7 @@ void i915_perf_register(struct drm_i915_
 		goto exit;
 
 	sysfs_attr_init(&perf->test_config.sysfs_metric_id.attr);
+#endif
 
 	if (IS_TIGERLAKE(i915)) {
 		i915_perf_load_test_config_tgl(i915);
@@ -3733,10 +3979,12 @@ void i915_perf_register(struct drm_i915_
 	if (perf->test_config.id == 0)
 		goto sysfs_error;
 
+#ifndef __NetBSD__		/* XXX i915 sysfs */
 	ret = sysfs_create_group(perf->metrics_kobj,
 				 &perf->test_config.sysfs_metric);
 	if (ret)
 		goto sysfs_error;
+#endif
 
 	perf->test_config.perf = perf;
 	kref_init(&perf->test_config.ref);
@@ -3744,8 +3992,10 @@ void i915_perf_register(struct drm_i915_
 	goto exit;
 
 sysfs_error:
+#ifndef __NetBSD__
 	kobject_put(perf->metrics_kobj);
 	perf->metrics_kobj = NULL;
+#endif
 
 exit:
 	mutex_unlock(&perf->lock);
@@ -3762,6 +4012,7 @@ exit:
  */
 void i915_perf_unregister(struct drm_i915_private *i915)
 {
+#ifndef __NetBSD__
 	struct i915_perf *perf = &i915->perf;
 
 	if (!perf->metrics_kobj)
@@ -3772,6 +4023,7 @@ void i915_perf_unregister(struct drm_i91
 
 	kobject_put(perf->metrics_kobj);
 	perf->metrics_kobj = NULL;
+#endif
 }
 
 static bool gen8_is_valid_flex_addr(struct i915_perf *perf, u32 addr)
@@ -3943,6 +4195,7 @@ addr_err:
 	return ERR_PTR(err);
 }
 
+#ifndef __NetBSD__		/* XXX i915 sysfs */
 static ssize_t show_dynamic_id(struct device *dev,
 			       struct device_attribute *attr,
 			       char *buf)
@@ -3952,10 +4205,14 @@ static ssize_t show_dynamic_id(struct de
 
 	return sprintf(buf, "%d\n", oa_config->id);
 }
+#endif
 
 static int create_dynamic_oa_sysfs_entry(struct i915_perf *perf,
 					 struct i915_oa_config *oa_config)
 {
+#ifdef __NetBSD__		/* XXX i915 sysfs */
+	return 0;
+#else
 	sysfs_attr_init(&oa_config->sysfs_metric_id.attr);
 	oa_config->sysfs_metric_id.attr.name = "id";
 	oa_config->sysfs_metric_id.attr.mode = S_IRUGO;
@@ -3970,6 +4227,7 @@ static int create_dynamic_oa_sysfs_entry
 
 	return sysfs_create_group(perf->metrics_kobj,
 				  &oa_config->sysfs_metric);
+#endif
 }
 
 /**
@@ -4172,7 +4430,9 @@ int i915_perf_remove_config_ioctl(struct
 
 	GEM_BUG_ON(*arg != oa_config->id);
 
+#ifndef __NetBSD__
 	sysfs_remove_group(perf->metrics_kobj, &oa_config->sysfs_metric);
+#endif
 
 	idr_remove(&perf->metrics_idr, *arg);
 
@@ -4189,6 +4449,8 @@ err_unlock:
 	return ret;
 }
 
+#ifndef __NetBSD__		/* XXX i915 perf sysctl */
+
 static struct ctl_table oa_table[] = {
 	{
 	 .procname = "perf_stream_paranoid",
@@ -4231,6 +4493,8 @@ static struct ctl_table dev_root[] = {
 	{}
 };
 
+#endif	/* __NetBSD__ */
+
 /**
  * i915_perf_init - initialize i915-perf state on module bind
  * @i915: i915 device instance
@@ -4386,12 +4650,16 @@ static int destroy_config(int id, void *
 
 void i915_perf_sysctl_register(void)
 {
+#ifndef __NetBSD__		/* XXX i915 perf sysctl */
 	sysctl_header = register_sysctl_table(dev_root);
+#endif
 }
 
 void i915_perf_sysctl_unregister(void)
 {
+#ifndef __NetBSD__		/* XXX i915 perf sysctl */
 	unregister_sysctl_table(sysctl_header);
+#endif
 }
 
 /**

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h:1.5 src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h:1.6
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h:1.5	Sun Dec 19 11:11:51 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_perf_types.h	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_perf_types.h,v 1.5 2021/12/19 11:11:51 riastradh Exp $	*/
+/*	$NetBSD: i915_perf_types.h,v 1.6 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /* SPDX-License-Identifier: MIT */
 /*
@@ -82,7 +82,7 @@ struct i915_perf_stream_ops {
 	 */
 	void (*disable)(struct i915_perf_stream *stream);
 
-#ifdef notyet
+#ifndef __NetBSD__
 	/**
 	 * @poll_wait: Call poll_wait, passing a wait queue that will be woken
 	 * once there is something ready to read() for the stream
@@ -117,10 +117,17 @@ struct i915_perf_stream_ops {
 	 * -%ENOSPC or -%EFAULT, even though these may be squashed before
 	 * returning to userspace.
 	 */
+#ifdef __NetBSD__
+	int (*read)(struct i915_perf_stream *stream,
+		    struct uio *buf,
+		    kauth_cred_t count, /* XXX dummy */
+		    int offset);	/* XXX dummy */
+#else
 	int (*read)(struct i915_perf_stream *stream,
 		    char __user *buf,
 		    size_t count,
 		    size_t *offset);
+#endif
 
 	/**
 	 * @destroy: Cleanup any stream specific resources.
@@ -227,10 +234,11 @@ struct i915_perf_stream {
 	 * @poll_wq: The wait queue that hrtimer callback wakes when it
 	 * sees data ready to read in the circular OA buffer.
 	 */
-#ifdef __linux__
-	wait_queue_head_t poll_wq;
-#else
+#ifdef __NetBSD__
 	drm_waitqueue_t poll_wq;
+	struct selinfo poll_selq;
+#else
+	wait_queue_head_t poll_wq;
 #endif
 
 	/**
@@ -371,10 +379,17 @@ struct i915_oa_ops {
 	 * @read: Copy data from the circular OA buffer into a given userspace
 	 * buffer.
 	 */
+#ifdef __NetBSD__
+	int (*read)(struct i915_perf_stream *stream,
+		    struct uio *buf,
+		    kauth_cred_t count, /* XXX dummy */
+		    int offset);	/* XXX dummy */
+#else
 	int (*read)(struct i915_perf_stream *stream,
 		    char __user *buf,
 		    size_t count,
 		    size_t *offset);
+#endif
 
 	/**
 	 * @oa_hw_tail_read: read the OA tail pointer register

Index: src/sys/external/bsd/drm2/drm/drm_sysctl.c
diff -u src/sys/external/bsd/drm2/drm/drm_sysctl.c:1.7 src/sys/external/bsd/drm2/drm/drm_sysctl.c:1.8
--- src/sys/external/bsd/drm2/drm/drm_sysctl.c:1.7	Mon Aug 27 13:57:24 2018
+++ src/sys/external/bsd/drm2/drm/drm_sysctl.c	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_sysctl.c,v 1.7 2018/08/27 13:57:24 riastradh Exp $	*/
+/*	$NetBSD: drm_sysctl.c,v 1.8 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_sysctl.c,v 1.7 2018/08/27 13:57:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_sysctl.c,v 1.8 2021/12/19 11:36:57 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -122,7 +122,6 @@ drm_sysctl_node(const char *name, const 
 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, name, NULL,
 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
 }
-	
 
 void
 drm_sysctl_init(struct drm_sysctl_def *def)
@@ -155,7 +154,6 @@ drm_sysctl_init(struct drm_sysctl_def *d
 				continue;
 			}
 		}
-			
 	        if ((error = sysctl_createv(&def->log, 0, &cnode,
 		    &cnode, p->mode == 0600 ? CTLFLAG_READWRITE : 0,
 		    drm_sysctl_get_type(p), n,

Index: src/sys/external/bsd/drm2/include/linux/hrtimer.h
diff -u src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.4 src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.5
--- src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.4	Sun Dec 19 11:23:51 2021
+++ src/sys/external/bsd/drm2/include/linux/hrtimer.h	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hrtimer.h,v 1.4 2021/12/19 11:23:51 riastradh Exp $	*/
+/*	$NetBSD: hrtimer.h,v 1.5 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -48,6 +48,7 @@ struct hrtimer {
 enum hrtimer_mode {
 	HRTIMER_MODE_ABS,
 	HRTIMER_MODE_REL,
+	HRTIMER_MODE_REL_PINNED,
 };
 
 enum hrtimer_restart {
Index: src/sys/external/bsd/drm2/include/linux/ratelimit.h
diff -u src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.4 src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.5
--- src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.4	Sun Dec 19 01:20:08 2021
+++ src/sys/external/bsd/drm2/include/linux/ratelimit.h	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ratelimit.h,v 1.4 2021/12/19 01:20:08 riastradh Exp $	*/
+/*	$NetBSD: ratelimit.h,v 1.5 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -39,12 +39,18 @@
 #define	ratelimit_state	linux_ratelimit_state
 
 struct ratelimit_state {
+	volatile int		missed;
+
 	volatile unsigned	rl_lock;
 	struct timeval		rl_lasttime;
 	int			rl_curpps;
 	unsigned		rl_maxpps;
 };
 
+enum {
+	RATELIMIT_MSG_ON_RELEASE,
+};
+
 /*
  * XXX Assumes hz=100 so this works in static initializers, and/or
  * hopes the caller just uses DEFAULT_RATELIMIT_INTERVAL and doesn't
@@ -55,24 +61,42 @@ struct ratelimit_state {
 
 #define	DEFINE_RATELIMIT_STATE(n, i, b)					      \
 	struct ratelimit_state n = {					      \
+		.missed = 0,						      \
 		.rl_lock = 0,						      \
 		.rl_lasttime = { .tv_sec = 0, .tv_usec = 0 },		      \
 		.rl_curpps = 0,						      \
 		.rl_maxpps = (b)/((i)/100),				      \
 	}
 
+static inline void
+ratelimit_state_init(struct ratelimit_state *r, int interval, int burst)
+{
+
+	memset(r, 0, sizeof(*r));
+	r->rl_maxpps = burst/(interval/hz);
+}
+
+static inline void
+ratelimit_set_flags(struct ratelimit_state *r, unsigned long flags)
+{
+}
+
 static inline bool
 __ratelimit(struct ratelimit_state *r)
 {
 	int ok;
 
-	if (atomic_cas_uint(&r->rl_lock, 0, 1))
-		return false;
+	if (atomic_cas_uint(&r->rl_lock, 0, 1)) {
+		ok = false;
+		goto out;
+	}
 	membar_enter();
 	ok = ppsratecheck(&r->rl_lasttime, &r->rl_curpps, r->rl_maxpps);
 	membar_exit();
 	r->rl_lock = 0;
 
+out:	if (!ok)
+		atomic_store_relaxed(&r->missed, 1);
 	return ok;
 }
 

Index: src/sys/external/bsd/drm2/include/linux/math64.h
diff -u src/sys/external/bsd/drm2/include/linux/math64.h:1.10 src/sys/external/bsd/drm2/include/linux/math64.h:1.11
--- src/sys/external/bsd/drm2/include/linux/math64.h:1.10	Sun Dec 19 11:23:09 2021
+++ src/sys/external/bsd/drm2/include/linux/math64.h	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: math64.h,v 1.10 2021/12/19 11:23:09 riastradh Exp $	*/
+/*	$NetBSD: math64.h,v 1.11 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -56,6 +56,12 @@ div64_s64(int64_t dividend, int64_t divi
 	return dividend / divisor;
 }
 
+static inline uint64_t
+DIV64_U64_ROUND_UP(uint64_t dividend, uint64_t divisor)
+{
+	return (dividend + (divisor - 1))/divisor;
+}
+
 static inline int64_t
 div_s64(int64_t dividend, int32_t divisor)
 {

Index: src/sys/external/bsd/drm2/include/linux/uuid.h
diff -u src/sys/external/bsd/drm2/include/linux/uuid.h:1.2 src/sys/external/bsd/drm2/include/linux/uuid.h:1.3
--- src/sys/external/bsd/drm2/include/linux/uuid.h:1.2	Sun Dec 19 01:20:15 2021
+++ src/sys/external/bsd/drm2/include/linux/uuid.h	Sun Dec 19 11:36:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uuid.h,v 1.2 2021/12/19 01:20:15 riastradh Exp $	*/
+/*	$NetBSD: uuid.h,v 1.3 2021/12/19 11:36:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -34,4 +34,32 @@
 
 #define	UUID_STRING_LEN		36
 
+static inline int
+uuid_is_valid(const char uuid[static 36])
+{
+	unsigned i;
+
+	for (i = 0; i < 36; i++) {
+		switch (i) {
+		case 8:		/* xxxxxxxx[-]xxxx-xxxx-xxxx-xxxxxxxxxxxx */
+		case 12 + 1:	/* xxxxxxxx-xxxx[-]xxxx-xxxx-xxxxxxxxxxxx */
+		case 16 + 2:	/* xxxxxxxx-xxxx-xxxx[-]xxxx-xxxxxxxxxxxx */
+		case 20 + 3:	/* xxxxxxxx-xxxx-xxxx-xxxx[-]xxxxxxxxxxxx */
+			if (uuid[i] == '-')
+				continue;
+			return 0;
+		default:
+			if ('0' <= uuid[i] && uuid[i] <= '9')
+				continue;
+			if ('a' <= uuid[i] && uuid[i] <= 'f')
+				continue;
+			if ('A' <= uuid[i] && uuid[i] <= 'F')
+				continue;
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
 #endif  /* _LINUX_UUID_H_ */

Reply via email to