CVS commit: src/sys/external/bsd/drm2/linux

2024-04-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 28 15:35:39 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/linux: linux_sync_file.c

Log Message:
linux_sync_file: Fix missing init/fini steps.

Noted by rjs@.

PR kern/58210


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_sync_file.c

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



CVS commit: src/sys/external/bsd/drm2/linux

2024-04-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 28 15:35:39 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/linux: linux_sync_file.c

Log Message:
linux_sync_file: Fix missing init/fini steps.

Noted by rjs@.

PR kern/58210


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_sync_file.c

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/linux/linux_sync_file.c
diff -u src/sys/external/bsd/drm2/linux/linux_sync_file.c:1.2 src/sys/external/bsd/drm2/linux/linux_sync_file.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_sync_file.c:1.2	Sat Feb 12 15:51:29 2022
+++ src/sys/external/bsd/drm2/linux/linux_sync_file.c	Sun Apr 28 15:35:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_sync_file.c,v 1.2 2022/02/12 15:51:29 thorpej Exp $	*/
+/*	$NetBSD: linux_sync_file.c,v 1.3 2024/04/28 15:35:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_sync_file.c,v 1.2 2022/02/12 15:51:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_sync_file.c,v 1.3 2024/04/28 15:35:39 riastradh Exp $");
 
 #include 
 #include 
@@ -51,15 +51,17 @@ sync_file_create(struct dma_fence *fence
 
 	sf = kmem_zalloc(sizeof(*sf), KM_SLEEP);
 	sf->file = fp;
-	sf->sf_fence = dma_fence_get(fence);
+
 	mutex_init(>sf_lock, MUTEX_DEFAULT, IPL_VM);
 	selinit(>sf_selq);
 	sf->sf_polling = false;
 	sf->sf_signalled = false;
+	sf->sf_fence = dma_fence_get(fence);
 
 	fp->f_type = DTYPE_MISC;
 	fp->f_flag = FREAD | FWRITE;
 	fp->f_ops = _file_ops;
+	fp->f_data = sf;
 
 	return sf;
 }
@@ -73,6 +75,8 @@ sync_file_close(struct file *fp)
 		dma_fence_remove_callback(sf->sf_fence, >sf_fcb);
 	dma_fence_put(sf->sf_fence);
 	sf->sf_fence = NULL;
+	seldestroy(>sf_selq);
+	mutex_destroy(>sf_lock);
 
 	kmem_free(sf, sizeof(*sf));
 



CVS commit: src/sys/external/bsd/drm2/dist/drm

2024-04-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 21 03:02:51 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm: drm_ioctl.c

Log Message:
drm: Allow DRM_IOCTL_GET_UNIQUE on render nodes.

On NetBSD, libdrm uses this to discover what kind of bus the device
is on, without which it refuses to expose the render node at all,
rendering it useless.  With this change, libdrm is able to use render
nodes on NetBSD.

Since this is just reading out information about the bus type and
bus/dev/func numbers, I don't think it's problematic to expose to
render nodes.

This requires tweaking the access path to the master.

PR kern/58180


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c

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/drm_ioctl.c
diff -u src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.24 src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.25
--- src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c:1.24	Sat Oct 15 15:19:28 2022
+++ src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c	Sun Apr 21 03:02:51 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_ioctl.c,v 1.24 2022/10/15 15:19:28 riastradh Exp $	*/
+/*	$NetBSD: drm_ioctl.c,v 1.25 2024/04/21 03:02:51 riastradh Exp $	*/
 
 /*
  * Created: Fri Jan  8 09:01:26 1999 by fa...@valinux.com
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.24 2022/10/15 15:19:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_ioctl.c,v 1.25 2024/04/21 03:02:51 riastradh Exp $");
 
 #include 
 #include 
@@ -129,19 +129,35 @@ int drm_getunique(struct drm_device *dev
 		  struct drm_file *file_priv)
 {
 	struct drm_unique *u = data;
-	struct drm_master *master = file_priv->master;
+	struct drm_master *master;
+	int ret;
 
-	mutex_lock(>dev->master_mutex);
-	if (u->unique_len >= master->unique_len) {
-		if (copy_to_user(u->unique, master->unique, master->unique_len)) {
-			mutex_unlock(>dev->master_mutex);
-			return -EFAULT;
-		}
+	mutex_lock(>master_mutex);
+	master = dev->master;
+	if (master == NULL) {
+		ret = -ENXIO;
+		goto out;
+	}
+
+	/*
+	 * Copy out only if the user allocated enough space.  Either
+	 * way, on success, report the actual size -- so the user can
+	 * allocate enough space if they didn't before, or so they know
+	 * exactly how much we copied out.
+	 */
+	if (u->unique_len < master->unique_len) {
+		ret = 0;
+	} else {
+		ret = copy_to_user(u->unique, master->unique,
+		master->unique_len);
+		if (ret)
+			goto out;
 	}
 	u->unique_len = master->unique_len;
-	mutex_unlock(>dev->master_mutex);
 
-	return 0;
+out:	mutex_unlock(>master_mutex);
+
+	return ret;
 }
 
 static void
@@ -597,7 +613,7 @@ EXPORT_SYMBOL(drm_ioctl_permit);
 /* Ioctl table */
 static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_RENDER_ALLOW),
-	DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
+	DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
 



CVS commit: src/sys/external/bsd/drm2/dist/drm

2024-04-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 21 03:02:51 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm: drm_ioctl.c

Log Message:
drm: Allow DRM_IOCTL_GET_UNIQUE on render nodes.

On NetBSD, libdrm uses this to discover what kind of bus the device
is on, without which it refuses to expose the render node at all,
rendering it useless.  With this change, libdrm is able to use render
nodes on NetBSD.

Since this is just reading out information about the bus type and
bus/dev/func numbers, I don't think it's problematic to expose to
render nodes.

This requires tweaking the access path to the master.

PR kern/58180


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/dist/drm/drm_ioctl.c

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



CVS commit: src/sys/external/bsd/drm2/drm

2024-04-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 21 03:02:39 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/drm: drm_cdevsw.c

Log Message:
drm(4): Fix st_rdev in stat.

dminor->index already has the 64*type adjustment, as allocated in
drm_minor_alloc.

PR kern/58180


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/external/bsd/drm2/drm/drm_cdevsw.c

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/drm/drm_cdevsw.c
diff -u src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.30 src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.31
--- src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.30	Wed Jul  6 01:12:45 2022
+++ src/sys/external/bsd/drm2/drm/drm_cdevsw.c	Sun Apr 21 03:02:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_cdevsw.c,v 1.30 2022/07/06 01:12:45 riastradh Exp $	*/
+/*	$NetBSD: drm_cdevsw.c,v 1.31 2024/04/21 03:02:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.30 2022/07/06 01:12:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.31 2024/04/21 03:02:39 riastradh Exp $");
 
 #include 
 #include 
@@ -496,7 +496,7 @@ drm_stat(struct file *fp, struct stat *s
 	struct drm_file *const file = fp->f_data;
 	struct drm_minor *const dminor = file->minor;
 	const dev_t devno = makedev(cdevsw_lookup_major(_cdevsw),
-	64*dminor->type + dminor->index);
+	dminor->index);
 
 	(void)memset(st, 0, sizeof(*st));
 



CVS commit: src/sys/external/bsd/drm2/drm

2024-04-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 21 03:02:39 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/drm: drm_cdevsw.c

Log Message:
drm(4): Fix st_rdev in stat.

dminor->index already has the 64*type adjustment, as allocated in
drm_minor_alloc.

PR kern/58180


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/external/bsd/drm2/drm/drm_cdevsw.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/radeon

2024-04-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr 18 23:33:15 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_acpi.c

Log Message:
radeon_acpi.c: ifdef out unused function on NetBSD.

Should fix syzkaller build.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c

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/radeon/radeon_acpi.c
diff -u src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c:1.5 src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c:1.6
--- src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c:1.5	Tue Apr 16 14:34:02 2024
+++ src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c	Thu Apr 18 23:33:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_acpi.c,v 1.5 2024/04/16 14:34:02 riastradh Exp $	*/
+/*	$NetBSD: radeon_acpi.c,v 1.6 2024/04/18 23:33:15 riastradh Exp $	*/
 
 /*
  * Copyright 2012 Advanced Micro Devices, Inc.
@@ -24,7 +24,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeon_acpi.c,v 1.5 2024/04/16 14:34:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_acpi.c,v 1.6 2024/04/18 23:33:15 riastradh Exp $");
 
 #include 
 #include 
@@ -50,11 +50,13 @@ ACPI_MODULE_NAME("radeon_acpi")
 #include 
 #endif
 
+#ifndef __NetBSD__		/* XXX radeon acpi */
 #if defined(CONFIG_VGA_SWITCHEROO)
 bool radeon_atpx_dgpu_req_power_for_displays(void);
 #else
 static inline bool radeon_atpx_dgpu_req_power_for_displays(void) { return false; }
 #endif
+#endif
 
 #define ACPI_AC_CLASS   "ac_adapter"
 



CVS commit: src/sys/external/bsd/drm2/dist/drm/radeon

2024-04-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr 18 23:33:15 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_acpi.c

Log Message:
radeon_acpi.c: ifdef out unused function on NetBSD.

Should fix syzkaller build.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c

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



CVS commit: src/sys/external/bsd/drm2/nouveau

2024-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Apr 16 14:26:53 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/nouveau: nouveau2netbsd

Log Message:
nouveau: Rework nouveau2netbsd hack to get ACPI stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/nouveau/nouveau2netbsd

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/nouveau/nouveau2netbsd
diff -u src/sys/external/bsd/drm2/nouveau/nouveau2netbsd:1.5 src/sys/external/bsd/drm2/nouveau/nouveau2netbsd:1.6
--- src/sys/external/bsd/drm2/nouveau/nouveau2netbsd:1.5	Mon Aug 27 00:46:21 2018
+++ src/sys/external/bsd/drm2/nouveau/nouveau2netbsd	Tue Apr 16 14:26:53 2024
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-#	$NetBSD: nouveau2netbsd,v 1.5 2018/08/27 00:46:21 riastradh Exp $
+#	$NetBSD: nouveau2netbsd,v 1.6 2024/04/16 14:26:53 riastradh Exp $
 #
 # $ /path/to/nouveau2netbsd > /path/to/files.nouveau.new
 #
@@ -32,9 +32,13 @@ filemap="$(mktemp -t ${0##*/})"
 
 cat Kbuild\
 | sed -e 's,^include \(.*\)$,.include "\1",'\
-| sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY][eE][sS]),'		\
+| sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY]),'			\
 | sed -e 's,^endif$,.endif,'		\
-| make -f /dev/stdin -V '$(nouveau-y)' src=.\
+| env	\
+	env CONFIG_ACPI=y		\
+	env CONFIG_X86=y		\
+	env src=.			\
+	make -f /dev/stdin -V '$(nouveau-y)'\
 | tr ' ' '\n'\
 | sed -e 's,^$,,'			\
 | sort -u\



CVS commit: src/sys/external/bsd/drm2/nouveau

2024-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Apr 16 14:26:53 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/nouveau: nouveau2netbsd

Log Message:
nouveau: Rework nouveau2netbsd hack to get ACPI stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/nouveau/nouveau2netbsd

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:24:38 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_stolen.c

Log Message:
i915_gem_stolen: Fill sg_pgs, with size/PAGE_SIZE entries.

Use sg_alloc_table_from_bus_dmamem to do this.

i915_gem_mman.c vm_fault_cpu and i915_gem_object_release_mmap_offset
both rely on sg_pgs to be a page array, so providing a table with
only one entry doesn't work (except by accident, if the object is
page-sized anyway).  And they rely on the sg_pgs entries to be
initialized, which we weren't doing before, and which
sg_alloc_table_from_bus_dmamem does for us.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c

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/gem/i915_gem_stolen.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.6 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.7
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.6	Fri Jan 19 22:24:27 2024
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c	Fri Jan 19 22:24:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_stolen.c,v 1.6 2024/01/19 22:24:27 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_stolen.c,v 1.7 2024/01/19 22:24:38 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.6 2024/01/19 22:24:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.7 2024/01/19 22:24:38 riastradh Exp $");
 
 #include 
 #include 
@@ -506,14 +506,13 @@ i915_pages_create_for_stolen(struct drm_
 {
 	struct drm_i915_private *i915 = to_i915(dev);
 	struct sg_table *st;
+	struct scatterlist *sg;
 #ifdef __NetBSD__
 	bus_dma_tag_t dmat = i915->drm.dmat;
 	bus_dma_segment_t *seg = NULL;
 	int nseg = 0, i;
 	bool loaded = false;
 	int ret;
-#else
-	struct scatterlist *sg;
 #endif
 
 	GEM_BUG_ON(range_overflows(offset, size, resource_size(>dsm)));
@@ -527,11 +526,6 @@ i915_pages_create_for_stolen(struct drm_
 	if (st == NULL)
 		return ERR_PTR(-ENOMEM);
 
-	if (sg_alloc_table(st, 1, GFP_KERNEL)) {
-		kfree(st);
-		return ERR_PTR(-ENOMEM);
-	}
-
 #ifdef __NetBSD__
 	KASSERT((size % PAGE_SIZE) == 0);
 	nseg = size / PAGE_SIZE;
@@ -548,6 +542,17 @@ i915_pages_create_for_stolen(struct drm_
 		seg[i].ds_len = PAGE_SIZE;
 	}
 
+	sg = NULL;
+
+	ret = sg_alloc_table_from_bus_dmamem(st, dmat, seg, nseg, GFP_KERNEL);
+	if (ret) {
+		DRM_ERROR("failed to alloc sg table for stolen object: %d\n",
+		ret);
+		ret = -ENOMEM;
+		goto out;
+	}
+	sg = st->sgl;
+
 	/* XXX errno NetBSD->Linux */
 	ret = -bus_dmamap_create(dmat, size, nseg, PAGE_SIZE, 0,
 	BUS_DMA_WAITOK, >sgl->sg_dmamap);
@@ -573,11 +578,19 @@ out:	kmem_free(seg, nseg * sizeof(seg[0]
 	if (ret) {
 		if (loaded)
 			bus_dmamap_unload(dmat, st->sgl->sg_dmamap);
-		sg_free_table(st);
+		if (sg && sg->sg_dmamap)
+			bus_dmamap_destroy(dmat, sg->sg_dmamap);
+		if (sg)
+			sg_free_table(st);
 		kfree(st);
 		return ERR_PTR(ret);
 	}
 #else
+	if (sg_alloc_table(st, 1, GFP_KERNEL)) {
+		kfree(st);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	sg = st->sgl;
 	sg->offset = 0;
 	sg->length = size;



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:24:38 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_stolen.c

Log Message:
i915_gem_stolen: Fill sg_pgs, with size/PAGE_SIZE entries.

Use sg_alloc_table_from_bus_dmamem to do this.

i915_gem_mman.c vm_fault_cpu and i915_gem_object_release_mmap_offset
both rely on sg_pgs to be a page array, so providing a table with
only one entry doesn't work (except by accident, if the object is
page-sized anyway).  And they rely on the sg_pgs entries to be
initialized, which we weren't doing before, and which
sg_alloc_table_from_bus_dmamem does for us.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:24:27 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_stolen.c

Log Message:
i915_gem_stolen: Fix memory leak.

Found while trying to address the PR 57833 class of problems.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c

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/gem/i915_gem_stolen.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.5 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.6
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c:1.5	Sun Dec 19 12:10:42 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c	Fri Jan 19 22:24:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_stolen.c,v 1.5 2021/12/19 12:10:42 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_stolen.c,v 1.6 2024/01/19 22:24:27 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.5 2021/12/19 12:10:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.6 2024/01/19 22:24:27 riastradh Exp $");
 
 #include 
 #include 
@@ -569,7 +569,8 @@ i915_pages_create_for_stolen(struct drm_
 	}
 	loaded = true;
 
-out:	if (ret) {
+out:	kmem_free(seg, nseg * sizeof(seg[0]));
+	if (ret) {
 		if (loaded)
 			bus_dmamap_unload(dmat, st->sgl->sg_dmamap);
 		sg_free_table(st);



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:24:27 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_stolen.c

Log Message:
i915_gem_stolen: Fix memory leak.

Found while trying to address the PR 57833 class of problems.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_stolen.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:23:19 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_region.c

Log Message:
i915_gem_region: Fill sg_pgs, with size/PAGE_SIZE entries.

Use sg_alloc_table_from_bus_dmamem to do this.

i915_gem_mman.c vm_fault_cpu and i915_gem_object_release_mmap_offset
both rely on sg_pgs to be a page array, so using something else like
size >> ilog2(mem->mm.chunk_size) entries doesn't work.  And they
rely on the sg_pgs entries to be initialized, which we weren't doing
before, and which sg_alloc_table_from_bus_dmamem does for us.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:23:19 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_region.c

Log Message:
i915_gem_region: Fill sg_pgs, with size/PAGE_SIZE entries.

Use sg_alloc_table_from_bus_dmamem to do this.

i915_gem_mman.c vm_fault_cpu and i915_gem_object_release_mmap_offset
both rely on sg_pgs to be a page array, so using something else like
size >> ilog2(mem->mm.chunk_size) entries doesn't work.  And they
rely on the sg_pgs entries to be initialized, which we weren't doing
before, and which sg_alloc_table_from_bus_dmamem does for us.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c

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/gem/i915_gem_region.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.5 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.6
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.5	Fri Jan 19 22:22:27 2024
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c	Fri Jan 19 22:23:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_region.c,v 1.5 2024/01/19 22:22:27 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_region.c,v 1.6 2024/01/19 22:23:19 riastradh Exp $	*/
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_region.c,v 1.5 2024/01/19 22:22:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_region.c,v 1.6 2024/01/19 22:23:19 riastradh Exp $");
 
 #include "intel_memory_region.h"
 #include "i915_gem_region.h"
@@ -45,10 +45,12 @@ i915_gem_object_get_pages_buddy(struct d
 	if (!st)
 		return -ENOMEM;
 
+#ifndef __NetBSD__
 	if (sg_alloc_table(st, size >> ilog2(mem->mm.chunk_size), GFP_KERNEL)) {
 		kfree(st);
 		return -ENOMEM;
 	}
+#endif
 
 	flags = I915_ALLOC_MIN_PAGE_SIZE;
 	if (obj->flags & I915_BO_ALLOC_CONTIGUOUS)
@@ -60,7 +62,6 @@ i915_gem_object_get_pages_buddy(struct d
 
 	GEM_BUG_ON(list_empty(blocks));
 
-	sg = st->sgl;
 #ifdef __NetBSD__
 	__USE(prev_end);
 	bus_dma_tag_t dmat = obj->base.dev->dmat;
@@ -68,6 +69,8 @@ i915_gem_object_get_pages_buddy(struct d
 	int i = 0, nsegs = 0;
 	bool loaded = false;
 
+	sg = NULL;
+
 	list_for_each_entry(block, blocks, link) {
 		if (nsegs >= INT_MAX ||
 		nsegs >= SIZE_MAX/sizeof(segs[0]))
@@ -84,7 +87,15 @@ i915_gem_object_get_pages_buddy(struct d
 
 		segs[i].ds_addr = mem->region.start + offset;
 		segs[i].ds_len = block_size;
+		i++;
 	}
+	KASSERT(i == nsegs);
+
+	ret = sg_alloc_table_from_bus_dmamem(st, dmat, segs, nsegs,
+	GFP_KERNEL);
+	if (ret)
+		goto err;
+	sg = st->sgl;
 
 	/* XXX errno NetBSD->Linux */
 	ret = -bus_dmamap_create(dmat, size, nsegs, size, 0, BUS_DMA_WAITOK,
@@ -107,6 +118,7 @@ i915_gem_object_get_pages_buddy(struct d
 
 	sg_page_sizes = i915_sg_page_sizes(sg);
 #else
+	sg = st->sgl;
 	st->nents = 0;
 	sg_page_sizes = 0;
 	prev_end = (resource_size_t)-1;
@@ -154,6 +166,8 @@ i915_gem_object_get_pages_buddy(struct d
 err:
 	if (loaded)
 		bus_dmamap_unload(dmat, st->sgl->sg_dmamap);
+	if (sg && sg->sg_dmamap)
+		bus_dmamap_destroy(dmat, sg->sg_dmamap);
 	if (segs)
 		kmem_free(segs, nsegs * sizeof(segs[0]));
 	__intel_memory_region_put_pages_buddy(mem, blocks);



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:23:04 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_phys.c

Log Message:
i915_gem_phys: Fill sg_pgs.

This is needed by i915 gem fault, which maps user virtual addresses
to those pages, and by i915 gem object destruction, which does
pmap_page_protect on the pages to remove any of those user virtual
mappings.

This needs pmap_kenter_pa rather than pmap_enter(pmap_kernel(), ...)
in order to preserve the _kernel's_ mapping of the pages after
pmap_page_protect.

But bus_dmamem_map currently uses pmap_enter(pmap_kernel(), ...)
instead which creates a mapping that is removed by pmap_page_protect.

So we use a variant of bus_dmamem_map that uses pmap_kenter_pa
instead.  Perhaps bus_dmamem_map should do this itself, but this
change is less risky to pull up than a change to bus_dmamem_map
itself.

PR kern/57833: kernel panic on xorg exit

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c

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/gem/i915_gem_phys.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c:1.8 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c:1.9
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c:1.8	Sun Dec 19 12:45:43 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c	Fri Jan 19 22:23:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_phys.c,v 1.8 2021/12/19 12:45:43 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_phys.c,v 1.9 2024/01/19 22:23:04 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,91 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_phys.c,v 1.8 2021/12/19 12:45:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_phys.c,v 1.9 2024/01/19 22:23:04 riastradh Exp $");
+
+#ifdef __NetBSD__
+/*
+ * Make sure this block comes before any linux includes, so we don't
+ * get mixed up by the PAGE_MASK complementation.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include  /* kvtopte, pmap_pte_clearbits */
+
+/*
+ * Version of bus_dmamem_map that uses pmap_kenter_pa, not pmap_enter,
+ * so that it isn't affected by pmap_page_protect on the physical
+ * address.  Adapted from sys/arch/x86/x86/bus_dma.c.
+ */
+static int
+bus_dmamem_kmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
+size_t size, void **kvap, int flags)
+{
+	vaddr_t va;
+	bus_addr_t addr;
+	int curseg;
+	const uvm_flag_t kmflags =
+	(flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
+	u_int pmapflags = PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE;
+
+	size = round_page(size);
+	if (flags & BUS_DMA_NOCACHE)
+		pmapflags |= PMAP_NOCACHE;
+
+	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
+
+	if (va == 0)
+		return ENOMEM;
+
+	*kvap = (void *)va;
+
+	for (curseg = 0; curseg < nsegs; curseg++) {
+		for (addr = segs[curseg].ds_addr;
+		addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
+		addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
+			if (size == 0)
+panic("bus_dmamem_kmap: size botch");
+			pmap_kenter_pa(va, addr,
+			VM_PROT_READ | VM_PROT_WRITE,
+			pmapflags);
+		}
+	}
+	pmap_update(pmap_kernel());
+
+	return 0;
+}
+
+static void
+bus_dmamem_kunmap(bus_dma_tag_t t, void *kva, size_t size)
+{
+	pt_entry_t *pte, opte;
+	vaddr_t va, sva, eva;
+
+	KASSERTMSG(((uintptr_t)kva & PGOFSET) == 0, "kva=%p", kva);
+
+	size = round_page(size);
+	sva = (vaddr_t)kva;
+	eva = sva + size;
+
+	/*
+	 * mark pages cacheable again.
+	 */
+	for (va = sva; va < eva; va += PAGE_SIZE) {
+		pte = kvtopte(va);
+		opte = *pte;
+		if ((opte & PTE_PCD) != 0)
+			pmap_pte_clearbits(pte, PTE_PCD);
+	}
+	pmap_kremove((vaddr_t)kva, size);
+	pmap_update(pmap_kernel());
+	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+}
+
+#endif
 
 #include 
 #include 
@@ -65,7 +149,7 @@ static int i915_gem_object_get_pages_phy
 	if (ret)
 		return -ENOMEM;
 	KASSERT(rsegs == 1);
-	ret = -bus_dmamem_map(dmat, >mm.u.phys.seg, 1,
+	ret = -bus_dmamem_kmap(dmat, >mm.u.phys.seg, 1,
 	roundup_pow_of_two(obj->base.size), ,
 	BUS_DMA_WAITOK|BUS_DMA_COHERENT);
 	if (ret)
@@ -83,7 +167,12 @@ static int i915_gem_object_get_pages_phy
 	if (!st)
 		goto err_pci;
 
+#ifdef __NetBSD__
+	if (sg_alloc_table_from_bus_dmamem(st, dmat, >mm.u.phys.seg, 1,
+		GFP_KERNEL))
+#else
 	if (sg_alloc_table(st, 1, GFP_KERNEL))
+#endif
 		goto err_st;
 
 	sg = st->sgl;
@@ -151,7 +240,7 @@ err_st:
 err_pci:
 #ifdef __NetBSD__
 	if (vaddr) {
-		bus_dmamem_unmap(dmat, vaddr,
+		bus_dmamem_kunmap(dmat, vaddr,
 		roundup_pow_of_two(obj->base.size));
 	}
 	obj->mm.u.phys.kva = NULL;
@@ -225,7 +314,7 @@ i915_gem_object_put_pages_phys(struct dr
 	kfree(pages);
 
 #ifdef __NetBSD__
-	bus_dmamem_unmap(dmat, 

CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:23:04 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_phys.c

Log Message:
i915_gem_phys: Fill sg_pgs.

This is needed by i915 gem fault, which maps user virtual addresses
to those pages, and by i915 gem object destruction, which does
pmap_page_protect on the pages to remove any of those user virtual
mappings.

This needs pmap_kenter_pa rather than pmap_enter(pmap_kernel(), ...)
in order to preserve the _kernel's_ mapping of the pages after
pmap_page_protect.

But bus_dmamem_map currently uses pmap_enter(pmap_kernel(), ...)
instead which creates a mapping that is removed by pmap_page_protect.

So we use a variant of bus_dmamem_map that uses pmap_kenter_pa
instead.  Perhaps bus_dmamem_map should do this itself, but this
change is less risky to pull up than a change to bus_dmamem_map
itself.

PR kern/57833: kernel panic on xorg exit

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_phys.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:54 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_pages.c

Log Message:
i915_gem: Assert page array size.

Let's detect the bug of sg_npgs failing to match
obj->base.size/PAGE_SIZE earlier.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c

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/gem/i915_gem_pages.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c:1.6 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c:1.7
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c:1.6	Sun Dec 19 12:00:57 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c	Fri Jan 19 22:22:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_pages.c,v 1.6 2021/12/19 12:00:57 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_pages.c,v 1.7 2024/01/19 22:22:54 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_pages.c,v 1.6 2021/12/19 12:00:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_pages.c,v 1.7 2024/01/19 22:22:54 riastradh Exp $");
 
 #include "i915_drv.h"
 #include "i915_gem_object.h"
@@ -42,6 +42,18 @@ void __i915_gem_object_set_pages(struct 
 	}
 
 #ifndef __NetBSD__
+	/*
+	 * Paranoia: In NetBSD, a scatterlist is just an array of
+	 * pages, not an array of segments that might be larger than
+	 * pages, so the number of entries must exactly match the size
+	 * of the object (which should also be page-aligned).
+	 *
+	 * Both vm_fault_cpu and i915_gem_object_release_mmap_offset in
+	 * i915_gem_mman.c rely on this page array as such.
+	 */
+	KASSERTMSG(pages->sgl->sg_npgs == obj->base.size >> PAGE_SHIFT,
+	"npgs=%zu size=%zu", pages->sgl->sg_npgs, obj->base.size);
+
 	obj->mm.get_page.sg_pos = pages->sgl;
 	obj->mm.get_page.sg_idx = 0;
 #endif



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:54 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_pages.c

Log Message:
i915_gem: Assert page array size.

Let's detect the bug of sg_npgs failing to match
obj->base.size/PAGE_SIZE earlier.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_pages.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:40 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_mman.c

Log Message:
i915_gem: Avoid walking off end of sg_pgs.

sg_npgs currently fails to match obj->base.size/PAGE_SIZE only due to
bugs in the construction of sg_pgs in various i915 gem object types,
which we should also fix, but let's avoid compounding it here.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:40 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_mman.c

Log Message:
i915_gem: Avoid walking off end of sg_pgs.

sg_npgs currently fails to match obj->base.size/PAGE_SIZE only due to
bugs in the construction of sg_pgs in various i915 gem object types,
which we should also fix, but let's avoid compounding it here.

Related to PR kern/57833.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c

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/gem/i915_gem_mman.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c:1.21 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c:1.22
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c:1.21	Sun Dec 19 12:26:55 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c	Fri Jan 19 22:22:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_mman.c,v 1.21 2021/12/19 12:26:55 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_mman.c,v 1.22 2024/01/19 22:22:40 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_mman.c,v 1.21 2021/12/19 12:26:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_mman.c,v 1.22 2024/01/19 22:22:40 riastradh Exp $");
 
 #include 
 #include 
@@ -675,7 +675,7 @@ void i915_gem_object_release_mmap_offset
 
 	if (!i915_gem_object_has_pages(obj))
 		return;
-	for (i = 0; i < obj->base.size >> PAGE_SHIFT; i++) {
+	for (i = 0; i < obj->mm.pages->sgl->sg_npgs; i++) {
 		page = obj->mm.pages->sgl->sg_pgs[i];
 		vm_page = >p_vmp;
 		pmap_page_protect(vm_page, VM_PROT_NONE);



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:27 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_region.c

Log Message:
i915_gem_region: Reduce diff from upstream a little.

No functional change intended.

Prompted by upcoming nearby changes related to PR kern/57833.

XXX pullup-10 (to make subsequent pullups easier)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c

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/gem/i915_gem_region.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.4 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c:1.4	Sun Dec 19 12:10:42 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c	Fri Jan 19 22:22:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_region.c,v 1.4 2021/12/19 12:10:42 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_region.c,v 1.5 2024/01/19 22:22:27 riastradh Exp $	*/
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_region.c,v 1.4 2021/12/19 12:10:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_region.c,v 1.5 2024/01/19 22:22:27 riastradh Exp $");
 
 #include "intel_memory_region.h"
 #include "i915_gem_region.h"
@@ -63,7 +63,6 @@ i915_gem_object_get_pages_buddy(struct d
 	sg = st->sgl;
 #ifdef __NetBSD__
 	__USE(prev_end);
-	__USE(sg_page_sizes);
 	bus_dma_tag_t dmat = obj->base.dev->dmat;
 	bus_dma_segment_t *segs = NULL;
 	int i = 0, nsegs = 0;
@@ -106,7 +105,7 @@ i915_gem_object_get_pages_buddy(struct d
 	kmem_free(segs, nsegs * sizeof(segs[0]));
 	segs = NULL;
 
-	__i915_gem_object_set_pages(obj, st, i915_sg_page_sizes(sg));
+	sg_page_sizes = i915_sg_page_sizes(sg);
 #else
 	st->nents = 0;
 	sg_page_sizes = 0;
@@ -145,9 +144,9 @@ i915_gem_object_get_pages_buddy(struct d
 	sg_page_sizes |= sg->length;
 	sg_mark_end(sg);
 	i915_sg_trim(st);
+#endif
 
 	__i915_gem_object_set_pages(obj, st, sg_page_sizes);
-#endif
 
 	return 0;
 



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2024-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jan 19 22:22:27 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_region.c

Log Message:
i915_gem_region: Reduce diff from upstream a little.

No functional change intended.

Prompted by upcoming nearby changes related to PR kern/57833.

XXX pullup-10 (to make subsequent pullups easier)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_region.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915

2024-01-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jan 14 22:15:15 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915: i915_pci.c

Log Message:
i915: Backport change to downgrade gen7/vlv to aliasing-ppggtt.

PR kern/57268

XXX pullup-10

commit 4fbe112a569526e46fa2accb5763c069f78cb431
Author: Chris Wilson 
Date:   Mon Feb 24 10:11:20 2020 +

drm/i915/gtt: Downgrade gen7 (ivb, byt, hsw) back to aliasing-ppgtt

Full-ppgtt on gen7 is proving to be highly unstable and not robust.

Closes: https://gitlab.freedesktop.org/drm/intel/issues/694
Fixes: 3cd6e8860ecd ("drm/i915/gen7: Re-enable full-ppgtt for ivb & hsw")
Signed-off-by: Chris Wilson 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: Jani Nikula 
Cc: Dave Airlie 
Acked-by: Rodrigo Vivi 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20200224101120.4024481-1-ch...@chris-wilson.co.uk


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c

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_pci.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c:1.4 src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c:1.4	Sun Dec 19 01:44:49 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c	Sun Jan 14 22:15:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_pci.c,v 1.4 2021/12/19 01:44:49 riastradh Exp $	*/
+/*	$NetBSD: i915_pci.c,v 1.5 2024/01/14 22:15:15 riastradh Exp $	*/
 
 /*
  * Copyright © 2016 Intel Corporation
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_pci.c,v 1.4 2021/12/19 01:44:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_pci.c,v 1.5 2024/01/14 22:15:15 riastradh Exp $");
 
 #include 
 #include 
@@ -442,7 +442,7 @@ static const struct intel_device_info sn
 	.has_rc6 = 1, \
 	.has_rc6p = 1, \
 	.has_rps = true, \
-	.ppgtt_type = INTEL_PPGTT_FULL, \
+	.ppgtt_type = INTEL_PPGTT_ALIASING, \
 	.ppgtt_size = 31, \
 	IVB_PIPE_OFFSETS, \
 	IVB_CURSOR_OFFSETS, \
@@ -499,7 +499,7 @@ static const struct intel_device_info vl
 	.has_rps = true,
 	.display.has_gmch = 1,
 	.display.has_hotplug = 1,
-	.ppgtt_type = INTEL_PPGTT_FULL,
+	.ppgtt_type = INTEL_PPGTT_ALIASING,
 	.ppgtt_size = 31,
 	.has_snoop = true,
 	.has_coherent_ggtt = false,



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915

2024-01-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jan 14 22:15:15 UTC 2024

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915: i915_pci.c

Log Message:
i915: Backport change to downgrade gen7/vlv to aliasing-ppggtt.

PR kern/57268

XXX pullup-10

commit 4fbe112a569526e46fa2accb5763c069f78cb431
Author: Chris Wilson 
Date:   Mon Feb 24 10:11:20 2020 +

drm/i915/gtt: Downgrade gen7 (ivb, byt, hsw) back to aliasing-ppgtt

Full-ppgtt on gen7 is proving to be highly unstable and not robust.

Closes: https://gitlab.freedesktop.org/drm/intel/issues/694
Fixes: 3cd6e8860ecd ("drm/i915/gen7: Re-enable full-ppgtt for ivb & hsw")
Signed-off-by: Chris Wilson 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: Jani Nikula 
Cc: Dave Airlie 
Acked-by: Rodrigo Vivi 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20200224101120.4024481-1-ch...@chris-wilson.co.uk


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/dist/drm/i915/i915_pci.c

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-12-29 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Dec 29 22:58:24 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: smp.h

Log Message:
drm: put_cpu() should enable preemption, not disable it again


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/smp.h

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-12-29 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Dec 29 22:58:24 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: smp.h

Log Message:
drm: put_cpu() should enable preemption, not disable it again


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/smp.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/include/linux/smp.h
diff -u src/sys/external/bsd/drm2/include/linux/smp.h:1.4 src/sys/external/bsd/drm2/include/linux/smp.h:1.5
--- src/sys/external/bsd/drm2/include/linux/smp.h:1.4	Sun Dec 19 11:49:12 2021
+++ src/sys/external/bsd/drm2/include/linux/smp.h	Fri Dec 29 22:58:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: smp.h,v 1.4 2021/12/19 11:49:12 riastradh Exp $	*/
+/*	$NetBSD: smp.h,v 1.5 2023/12/29 22:58:23 chs Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@ static inline void
 put_cpu(void)
 {
 
-	kpreempt_disable();
+	kpreempt_enable();
 }
 
 static inline void



CVS commit: src/sys/external/bsd/drm2/dist/drm/radeon

2023-11-06 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Mon Nov  6 14:33:51 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_bios.c

Log Message:
radeon: fix and enable ACPI methods for getting ROM BIOS

The hacky way of getting the BIOS mapped only works on x86. ACPI
should be preferred if available. Makes BIOS reading though VFCT
work on aarch64 with EDK2. (But only if EDK2 has POSTed the GPU.)

XXX amdgpu should get the same treatment.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c

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/radeon/radeon_bios.c
diff -u src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c:1.12 src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c:1.13
--- src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c:1.12	Sat May 28 01:07:47 2022
+++ src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c	Mon Nov  6 14:33:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_bios.c,v 1.12 2022/05/28 01:07:47 manu Exp $	*/
+/*	$NetBSD: radeon_bios.c,v 1.13 2023/11/06 14:33:51 tnn Exp $	*/
 
 /*
  * Copyright 2008 Advanced Micro Devices, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeon_bios.c,v 1.12 2022/05/28 01:07:47 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_bios.c,v 1.13 2023/11/06 14:33:51 tnn Exp $");
 
 #include 
 #include 
@@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: radeon_bios.
 #include "radeon_reg.h"
 
 #if defined(__NetBSD__) && NACPICA > 0
+#define CONFIG_ACPI
 #include 
 #define	_COMPONENT	ACPI_DISPLAY_COMPONENT
 ACPI_MODULE_NAME("radeon_acpi")
@@ -252,10 +253,15 @@ static bool radeon_atrm_get_bios(struct 
 	if (rdev->flags & RADEON_IS_IGP)
 		return false;
 
-	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
 #ifdef __NetBSD__
+	pdev = rdev->pdev;
+	while (pdev != NULL) {
 		dhandle = (pdev->pd_ad ? pdev->pd_ad->ad_handle : NULL);
+		pdev = NULL;
+		if (rdev->pdev->class != PCI_CLASS_DISPLAY_VGA)
+			continue;
 #else
+	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
 		dhandle = ACPI_HANDLE(>dev);
 #endif
 		if (!dhandle)
@@ -269,11 +275,16 @@ static bool radeon_atrm_get_bios(struct 
 	}
 
 	if (!found) {
-		while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
 #ifdef __NetBSD__
+		pdev = rdev->pdev;
+		while (pdev != NULL) {
 			dhandle = (pdev->pd_ad ? pdev->pd_ad->ad_handle
 			: NULL);
+			pdev = NULL;
+			if (rdev->pdev->class != PCI_CLASS_DISPLAY_OTHER)
+continue;
 #else
+		while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
 			dhandle = ACPI_HANDLE(>dev);
 #endif
 			if (!dhandle)



CVS commit: src/sys/external/bsd/drm2/dist/drm/radeon

2023-11-06 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Mon Nov  6 14:33:51 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_bios.c

Log Message:
radeon: fix and enable ACPI methods for getting ROM BIOS

The hacky way of getting the BIOS mapped only works on x86. ACPI
should be preferred if available. Makes BIOS reading though VFCT
work on aarch64 with EDK2. (But only if EDK2 has POSTed the GPU.)

XXX amdgpu should get the same treatment.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c

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



CVS commit: src/sys/external/bsd/drm2

2023-09-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep 30 10:46:46 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_cik.c
amdgpu_device.c amdgpu_si.c amdgpu_vi.c
src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci:
nouveau_nvkm_subdev_pci_pcie.c
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_ci_dpm.c radeon_cik.c
radeon_evergreen.c radeon_r600.c radeon_rv770.c radeon_si.c
radeon_si_dpm.c
src/sys/external/bsd/drm2/include/linux: pci.h
src/sys/external/bsd/drm2/linux: linux_pci.c

Log Message:
drm: enable almost all PCIe functionality

linux_pci.c revisions 1.24 and 1.25 implemented most of the remaining
missing PCIe backends, but only enabled them for some amdgpu portions.

this enables all code marked with "XXX amdgpu pcie", "XXX radeon pcie",
and "XXX pcie speed".  for most of it, simply removing #ifndefs __NetBSD__
to enable compliation was required, once the new "bus->max_bus_speed"
member was added to struct pci_bus.  add an "always fails" backend for
pci_enable_atomic_ops_to_root() which seems to only be necessary
for virtual GPU functionality (and could be implemented if needed.)

tested on radeon 5450, 7750, R7 240 [radeon], and RX 550 [amdgpu], and
nvidia 750 and 1030 [nouveau].

this still does not quite work on nvidia cards.  there are two problems
that remain:

- the call to set the link speed is skipped because the speed is set
  to the default value of "-1".  nvkm_pcie_set_link() will actually
  determine the right value for this and for some cards, calling this
  function if the current speed is -1 helps set the link speed.  it
  may be that on linux other paths we don't have enabled properly
  would set this (there's one via debugfs, and a jetson specific one,
  though perhaps setting either AC or DC speed values as boot options
  (after hooking up these for netbsd) would currently work.

- worse, cards newer than kepler - geforce 900, 1000, and newer, are
  all lacking the backing support to set pcie link speed.  the GT 1030
  card i have been testing with remains at pcie 1.0.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c
cvs rdiff -u -r1.19 -r1.20 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c
cvs rdiff -u -r1.4 -r1.5 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_si.c
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_vi.c
cvs rdiff -u -r1.4 -r1.5 \

src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_ci_dpm.c \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_r600.c
cvs rdiff -u -r1.7 -r1.8 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_cik.c
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_evergreen.c \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_si.c
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_rv770.c
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_si_dpm.c
cvs rdiff -u -r1.56 -r1.57 src/sys/external/bsd/drm2/include/linux/pci.h
cvs rdiff -u -r1.26 -r1.27 src/sys/external/bsd/drm2/linux/linux_pci.c

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



CVS commit: src/sys/external/bsd/drm2

2023-09-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep 30 10:46:46 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_cik.c
amdgpu_device.c amdgpu_si.c amdgpu_vi.c
src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci:
nouveau_nvkm_subdev_pci_pcie.c
src/sys/external/bsd/drm2/dist/drm/radeon: radeon_ci_dpm.c radeon_cik.c
radeon_evergreen.c radeon_r600.c radeon_rv770.c radeon_si.c
radeon_si_dpm.c
src/sys/external/bsd/drm2/include/linux: pci.h
src/sys/external/bsd/drm2/linux: linux_pci.c

Log Message:
drm: enable almost all PCIe functionality

linux_pci.c revisions 1.24 and 1.25 implemented most of the remaining
missing PCIe backends, but only enabled them for some amdgpu portions.

this enables all code marked with "XXX amdgpu pcie", "XXX radeon pcie",
and "XXX pcie speed".  for most of it, simply removing #ifndefs __NetBSD__
to enable compliation was required, once the new "bus->max_bus_speed"
member was added to struct pci_bus.  add an "always fails" backend for
pci_enable_atomic_ops_to_root() which seems to only be necessary
for virtual GPU functionality (and could be implemented if needed.)

tested on radeon 5450, 7750, R7 240 [radeon], and RX 550 [amdgpu], and
nvidia 750 and 1030 [nouveau].

this still does not quite work on nvidia cards.  there are two problems
that remain:

- the call to set the link speed is skipped because the speed is set
  to the default value of "-1".  nvkm_pcie_set_link() will actually
  determine the right value for this and for some cards, calling this
  function if the current speed is -1 helps set the link speed.  it
  may be that on linux other paths we don't have enabled properly
  would set this (there's one via debugfs, and a jetson specific one,
  though perhaps setting either AC or DC speed values as boot options
  (after hooking up these for netbsd) would currently work.

- worse, cards newer than kepler - geforce 900, 1000, and newer, are
  all lacking the backing support to set pcie link speed.  the GT 1030
  card i have been testing with remains at pcie 1.0.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c
cvs rdiff -u -r1.19 -r1.20 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c
cvs rdiff -u -r1.4 -r1.5 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_si.c
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_vi.c
cvs rdiff -u -r1.4 -r1.5 \

src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_ci_dpm.c \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_r600.c
cvs rdiff -u -r1.7 -r1.8 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_cik.c
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_evergreen.c \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_si.c
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_rv770.c
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/radeon/radeon_si_dpm.c
cvs rdiff -u -r1.56 -r1.57 src/sys/external/bsd/drm2/include/linux/pci.h
cvs rdiff -u -r1.26 -r1.27 src/sys/external/bsd/drm2/linux/linux_pci.c

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/amd/amdgpu/amdgpu_cik.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c:1.6 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c:1.7
--- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c:1.6	Mon Oct 17 03:05:32 2022
+++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c	Sat Sep 30 10:46:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_cik.c,v 1.6 2022/10/17 03:05:32 mrg Exp $	*/
+/*	$NetBSD: amdgpu_cik.c,v 1.7 2023/09/30 10:46:45 mrg Exp $	*/
 
 /*
  * Copyright 2012 Advanced Micro Devices, Inc.
@@ -24,7 +24,7 @@
  * Authors: Alex Deucher
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_cik.c,v 1.6 2022/10/17 03:05:32 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_cik.c,v 1.7 2023/09/30 10:46:45 mrg Exp $");
 
 #include 
 #include 
@@ -1733,9 +1733,6 @@ static void cik_program_aspm(struct amdg
 WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, data);
 
 			if (!disable_clkreq) {
-#ifdef __NetBSD__		/* XXX amdgpu pcie */
-clk_req_support = false;
-#else
 struct pci_dev *root = adev->pdev->bus->self;
 u32 lnkcap;
 
@@ -1743,7 +1740,6 @@ static void cik_program_aspm(struct amdg
 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, );
 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
 	clk_req_support = true;
-#endif
 			} else {
 clk_req_support = false;
 			}

Index: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c
diff -u 

CVS commit: src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci

2023-09-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep 30 10:38:31 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci:
nouveau_nvkm_subdev_pci_pcie.c

Log Message:
avoid an unlikely array bounds issue picked up by GCC 12.

nvkm_pcie_speed() can return -1, which is then used as an array index,
so make this default return PCIe 1.0 speeds.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \

src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c

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/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c:1.3 src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c:1.3	Sun Dec 19 10:51:58 2021
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c	Sat Sep 30 10:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_nvkm_subdev_pci_pcie.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $	*/
+/*	$NetBSD: nouveau_nvkm_subdev_pci_pcie.c,v 1.4 2023/09/30 10:38:31 mrg Exp $	*/
 
 /*
  * Copyright 2015 Karol Herbst 
@@ -24,7 +24,7 @@
  * Authors: Karol Herbst 
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_pci_pcie.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_pci_pcie.c,v 1.4 2023/09/30 10:38:31 mrg Exp $");
 
 #include "priv.h"
 
@@ -48,7 +48,7 @@ nvkm_pcie_speed(enum pci_bus_speed speed
 		/* XXX 0x16 is 8_0, assume 0x17 will be 16_0 for now */
 		if (speed == 0x17)
 			return NVKM_PCIE_SPEED_8_0;
-		return -1;
+		return NVKM_PCIE_SPEED_2_5;
 	}
 }
 



CVS commit: src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci

2023-09-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Sep 30 10:38:31 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci:
nouveau_nvkm_subdev_pci_pcie.c

Log Message:
avoid an unlikely array bounds issue picked up by GCC 12.

nvkm_pcie_speed() can return -1, which is then used as an array index,
so make this default return PCIe 1.0 speeds.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \

src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c

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



CVS commit: src/sys/external/bsd/drm2

2023-09-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  5 20:15:10 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/drm: drm_module.c
src/sys/external/bsd/drm2/pci: files.drmkms_pci

Log Message:
drm: Fix conditionals around drmkms_pci and agp.

Kernel should build now with all pci drm drivers stripped out but
DRM_LEGACY still enabled.  (Might not be very useful, but it'll
build.  Maybe we should also have DRM_LEGACY_PCI so those drivers can
be modloaded later.)


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/external/bsd/drm2/drm/drm_module.c
cvs rdiff -u -r1.17 -r1.18 src/sys/external/bsd/drm2/pci/files.drmkms_pci

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



CVS commit: src/sys/external/bsd/drm2

2023-09-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep  5 20:15:10 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/drm: drm_module.c
src/sys/external/bsd/drm2/pci: files.drmkms_pci

Log Message:
drm: Fix conditionals around drmkms_pci and agp.

Kernel should build now with all pci drm drivers stripped out but
DRM_LEGACY still enabled.  (Might not be very useful, but it'll
build.  Maybe we should also have DRM_LEGACY_PCI so those drivers can
be modloaded later.)


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/external/bsd/drm2/drm/drm_module.c
cvs rdiff -u -r1.17 -r1.18 src/sys/external/bsd/drm2/pci/files.drmkms_pci

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/drm/drm_module.c
diff -u src/sys/external/bsd/drm2/drm/drm_module.c:1.31 src/sys/external/bsd/drm2/drm/drm_module.c:1.32
--- src/sys/external/bsd/drm2/drm/drm_module.c:1.31	Tue Jul 19 22:24:47 2022
+++ src/sys/external/bsd/drm2/drm/drm_module.c	Tue Sep  5 20:15:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_module.c,v 1.31 2022/07/19 22:24:47 riastradh Exp $	*/
+/*	$NetBSD: drm_module.c,v 1.32 2023/09/05 20:15:10 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.31 2022/07/19 22:24:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.32 2023/09/05 20:15:10 riastradh Exp $");
 
 #include 
 #include 
@@ -89,6 +89,7 @@ __KERNEL_RCSID(0, "$NetBSD: drm_module.c
  */
 #if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__)
 #include "agp.h"
+#include "drmkms_pci.h"
 #endif
 
 /*
@@ -114,7 +115,7 @@ drm_init(void)
 	drm_core_init_complete = true;
 
 	drm_agp_hooks_init();
-#if NAGP > 0
+#if NDRMKMS_PCI > 0 && NAGP > 0
 	extern int drmkms_agp_guarantee_initialized(void);
 	error = drmkms_agp_guarantee_initialized();
 	if (error) {

Index: src/sys/external/bsd/drm2/pci/files.drmkms_pci
diff -u src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.17 src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.18
--- src/sys/external/bsd/drm2/pci/files.drmkms_pci:1.17	Tue Jul 19 23:19:07 2022
+++ src/sys/external/bsd/drm2/pci/files.drmkms_pci	Tue Sep  5 20:15:10 2023
@@ -1,11 +1,11 @@
-#	$NetBSD: files.drmkms_pci,v 1.17 2022/07/19 23:19:07 riastradh Exp $
+#	$NetBSD: files.drmkms_pci,v 1.18 2023/09/05 20:15:10 riastradh Exp $
 
 define	drmkms_pci: drmkms
 
 makeoptions	drmkms_pci	"CPPFLAGS.drmkms_pci"+="${CPPFLAGS.drmkms}"
 
 #file	external/bsd/drm2/dist/drm/ati_pcigart.c	drmkms_pci
-file	external/bsd/drm2/dist/drm/drm_agpsupport.c	drmkms_pci & agp
+file	external/bsd/drm2/dist/drm/drm_agpsupport.c	drmkms_pci & agp	needs-flag
 file	external/bsd/drm2/pci/drm_pci.c			drmkms_pci
 file	external/bsd/drm2/pci/drm_pci_module.c		drmkms_pci
 



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-09-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep  5 06:08:02 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: files.i915drmkms

Log Message:
match warnings with the module build, fixes i386 with GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/external/bsd/drm2/i915drm/files.i915drmkms

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



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-09-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep  5 06:08:02 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: files.i915drmkms

Log Message:
match warnings with the module build, fixes i386 with GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/external/bsd/drm2/i915drm/files.i915drmkms

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/i915drm/files.i915drmkms
diff -u src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.90 src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.91
--- src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.90	Sat Jun  3 21:31:46 2023
+++ src/sys/external/bsd/drm2/i915drm/files.i915drmkms	Tue Sep  5 06:08:02 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i915drmkms,v 1.90 2023/06/03 21:31:46 lukem Exp $
+#	$NetBSD: files.i915drmkms,v 1.91 2023/09/05 06:08:02 mrg Exp $
 
 version	20180827
 
@@ -44,17 +44,19 @@ makeoptions	i915drmkms	"CWARNFLAGS.i915d
 makeoptions	i915drmkms	"CWARNFLAGS.i915drmkms"+="-Wno-pointer-arith"
 makeoptions	i915drmkms	"CWARNFLAGS.i915drmkms"+="-Wno-shadow"
 
+makeoptions 	i915drmkms 	"CWARNFLAGS.i915_irq.c"+="${CC_WNO_MAYBE_UNINITIALIZED}"
 makeoptions 	i915drmkms 	"CWARNFLAGS.i915_pci.c"+="${${ACTIVE_CC} == gcc:? -Wno-override-init :}"
 makeoptions 	i915drmkms 	"CWARNFLAGS.i915_pci.c"+="${${ACTIVE_CC} == clang:? -Wno-initializer-overrides :}"
 makeoptions	i915drmkms	"CWARNFLAGS.i915_sw_fence.c"+="${${ACTIVE_CC} == clang :? -Wno-unused-function :}"
 
-makeoptions 	i915drmkms 	"CWARNFLAGS.intel_sprite.c"+="${CC_WNO_MAYBE_UNINITIALIZED}"
-
-makeoptions 	i915drmkms 	"CWARNFLAGS.intel_ddi.c"+="${CC_WNO_MAYBE_UNINITIALIZED} ${CC_WNO_IMPLICIT_FALLTHROUGH}"
-makeoptions 	i915drmkms 	"CWARNFLAGS.intel_display.c"+="${CC_WNO_IMPLICIT_FALLTHROUGH}"
 makeoptions	i915drmkms	"CWARNFLAGS.intel_guc_submission.c"+="${${ACTIVE_CC} == clang :? -Wno-unused-function :}"
 makeoptions	i915drmkms	"CWARNFLAGS.intel_hdmi.c"+="${${ACTIVE_CC} == clang :? -Wno-unused-function :}"
+makeoptions 	i915drmkms 	"CWARNFLAGS.intel_ddi.c"+="${CC_WNO_MAYBE_UNINITIALIZED} ${CC_WNO_IMPLICIT_FALLTHROUGH}"
+makeoptions 	i915drmkms 	"CWARNFLAGS.intel_display.c"+="${CC_WNO_IMPLICIT_FALLTHROUGH}"
+makeoptions 	i915drmkms 	"CWARNFLAGS.intel_dp.c"+="${CC_WNO_STRINGOP_OVERREAD}"
+makeoptions 	i915drmkms 	"CWARNFLAGS.intel_pm.c"+="${CC_WNO_STRINGOP_OVERREAD} ${CC_WNO_STRINGOP_OVERFLOW}"
 makeoptions 	i915drmkms 	"CWARNFLAGS.intel_sdvo.c"+="${CC_WNO_IMPLICIT_FALLTHROUGH}"
+makeoptions 	i915drmkms 	"CWARNFLAGS.intel_sprite.c"+="${CC_WNO_MAYBE_UNINITIALIZED}"
 
 makeoptions	intelfb		"CPPFLAGS.intelfb"+="${CPPFLAGS.i915drmkms}"
 makeoptions	intelfb		"CWARNFLAGS.intelfb"+="${CWARNFLAGS.i915drmkms}"



CVS commit: src/sys/external/bsd/drm2/linux

2023-09-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  4 21:31:58 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_pci.c

Log Message:
convert a KASSERT() into an if () panic() sequence to appease GCC 12.

OK riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/external/bsd/drm2/linux/linux_pci.c

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



CVS commit: src/sys/external/bsd/drm2/linux

2023-09-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  4 21:31:58 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_pci.c

Log Message:
convert a KASSERT() into an if () panic() sequence to appease GCC 12.

OK riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/external/bsd/drm2/linux/linux_pci.c

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/linux/linux_pci.c
diff -u src/sys/external/bsd/drm2/linux/linux_pci.c:1.25 src/sys/external/bsd/drm2/linux/linux_pci.c:1.26
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.25	Mon Oct 17 03:05:32 2022
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Sep  4 21:31:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.25 2022/10/17 03:05:32 mrg Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.26 2023/09/04 21:31:58 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.25 2022/10/17 03:05:32 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.26 2023/09/04 21:31:58 mrg Exp $");
 
 #if NACPICA > 0
 #include 
@@ -790,7 +790,8 @@ bus_addr_t
 pci_resource_start(struct pci_dev *pdev, unsigned i)
 {
 
-	KASSERT(i < PCI_NUM_RESOURCES);
+	if (i >= PCI_NUM_RESOURCES)
+		panic("resource %d >= max %d", i, PCI_NUM_RESOURCES);
 	return pdev->pd_resources[i].addr;
 }
 
@@ -798,7 +799,8 @@ bus_size_t
 pci_resource_len(struct pci_dev *pdev, unsigned i)
 {
 
-	KASSERT(i < PCI_NUM_RESOURCES);
+	if (i >= PCI_NUM_RESOURCES)
+		panic("resource %d >= max %d", i, PCI_NUM_RESOURCES);
 	return pdev->pd_resources[i].size;
 }
 
@@ -813,7 +815,8 @@ int
 pci_resource_flags(struct pci_dev *pdev, unsigned i)
 {
 
-	KASSERT(i < PCI_NUM_RESOURCES);
+	if (i >= PCI_NUM_RESOURCES)
+		panic("resource %d >= max %d", i, PCI_NUM_RESOURCES);
 	return pdev->pd_resources[i].flags;
 }
 



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core

2023-08-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug 15 05:01:58 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core:
amdgpu_dc_stream.c

Log Message:
avoid a GCC 12 warning.

there's a 1-element long array and a loop conditional that tries to see
if indexes for it are not identical.  as these indexes will always both
be 0, the only valid index, the condition is always false.  GCC 12
triggers a strange warning on this code that can never run (see below),
so simply assert the array size is 1 and comment the rest.

amdgpu_dc_stream.c:470:55: error: array subscript [0, 0] is outside array 
bounds of 'struct dc_writeback_info[1]' [-Werror=array-bounds]
  470 | stream->writeback_info[j] = 
stream->writeback_info[i];


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core

2023-08-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug 15 05:01:58 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core:
amdgpu_dc_stream.c

Log Message:
avoid a GCC 12 warning.

there's a 1-element long array and a loop conditional that tries to see
if indexes for it are not identical.  as these indexes will always both
be 0, the only valid index, the condition is always false.  GCC 12
triggers a strange warning on this code that can never run (see below),
so simply assert the array size is 1 and comment the rest.

amdgpu_dc_stream.c:470:55: error: array subscript [0, 0] is outside array 
bounds of 'struct dc_writeback_info[1]' [-Werror=array-bounds]
  470 | stream->writeback_info[j] = 
stream->writeback_info[i];


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c

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/amd/display/dc/core/amdgpu_dc_stream.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c:1.2 src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c:1.2	Sat Dec 18 23:45:02 2021
+++ src/sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c	Tue Aug 15 05:01:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_dc_stream.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_dc_stream.c,v 1.3 2023/08/15 05:01:57 mrg Exp $	*/
 
 /*
  * Copyright 2012-15 Advanced Micro Devices, Inc.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_dc_stream.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_dc_stream.c,v 1.3 2023/08/15 05:01:57 mrg Exp $");
 
 #include 
 #include 
@@ -465,9 +465,18 @@ bool dc_stream_remove_writeback(struct d
 	/* remove writeback info for disabled writeback pipes from stream */
 	for (i = 0, j = 0; i < stream->num_wb_info; i++) {
 		if (stream->writeback_info[i].wb_enabled) {
+#ifdef __NetBSD__
+			/*
+			 * XXXGCC12
+			 * The array is only 1 entry long, so i and j must
+			 * always be 0 here, so the below test fails.
+			 */
+			CTASSERT(ARRAY_SIZE(stream->writeback_info) == 1);
+#else
 			if (i != j)
 /* trim the array */
 stream->writeback_info[j] = stream->writeback_info[i];
+#endif
 			j++;
 		}
 	}



CVS commit: src/sys/external/bsd/drm2/drm

2023-08-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug 15 04:57:36 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/drm: drm_gem_cma_helper.c

Log Message:
avoid uninitialised variable usage in drm_gem_cma_create_internal().

in the case nothing has returned 'error', 'nsegs' and the dma info
are (potentially) uninitialised, so consider this an error.

found by GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c

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/drm/drm_gem_cma_helper.c
diff -u src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c:1.14 src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c:1.15
--- src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c:1.14	Sat Jul  2 00:26:07 2022
+++ src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c	Tue Aug 15 04:57:36 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: drm_gem_cma_helper.c,v 1.14 2022/07/02 00:26:07 riastradh Exp $ */
+/* $NetBSD: drm_gem_cma_helper.c,v 1.15 2023/08/15 04:57:36 mrg Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_gem_cma_helper.c,v 1.14 2022/07/02 00:26:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_gem_cma_helper.c,v 1.15 2023/08/15 04:57:36 mrg Exp $");
 
 #include 
 
@@ -44,7 +44,7 @@ drm_gem_cma_create_internal(struct drm_d
 struct sg_table *sgt)
 {
 	struct drm_gem_cma_object *obj;
-	int error, nsegs;
+	int error = EINVAL, nsegs;
 
 	obj = kmem_zalloc(sizeof(*obj), KM_SLEEP);
 	obj->dmat = ddev->dmat;



CVS commit: src/sys/external/bsd/drm2/drm

2023-08-14 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug 15 04:57:36 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/drm: drm_gem_cma_helper.c

Log Message:
avoid uninitialised variable usage in drm_gem_cma_create_internal().

in the case nothing has returned 'error', 'nsegs' and the dma info
are (potentially) uninitialised, so consider this an error.

found by GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/drm/drm_gem_cma_helper.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915

2023-08-08 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug  8 06:59:41 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915: i915_gem.h

Log Message:
nix the NetBSD specific GEM_BUG_ON().

avoids GCC 12 warnings, and matches upstream closer.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.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_gem.h
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.h:1.7 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.h:1.8
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.h:1.7	Mon Dec 20 19:54:07 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.h	Tue Aug  8 06:59:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem.h,v 1.7 2021/12/20 19:54:07 riastradh Exp $	*/
+/*	$NetBSD: i915_gem.h,v 1.8 2023/08/08 06:59:40 mrg Exp $	*/
 
 /*
  * Copyright © 2016 Intel Corporation
@@ -41,13 +41,6 @@ struct drm_i915_private;
 
 #define GEM_SHOW_DEBUG() drm_debug_enabled(DRM_UT_DRIVER)
 
-#ifdef __NetBSD__
-#ifdef DIAGNOSTIC
-#define	GEM_BUG_ON(condition)	KASSERT(!(condition))
-#else
-#define	GEM_BUG_ON(condition)	BUILD_BUG_ON_INVALID(condition)
-#endif
-#else
 #define GEM_BUG_ON(condition) do { if (unlikely((condition))) {	\
 		GEM_TRACE_ERR("%s:%d GEM_BUG_ON(%s)\n", \
 			  __func__, __LINE__, __stringify(condition)); \
@@ -55,7 +48,6 @@ struct drm_i915_private;
 		BUG(); \
 		} \
 	} while(0)
-#endif
 #define GEM_WARN_ON(expr) WARN_ON(expr)
 
 #define GEM_DEBUG_DECL(var) var



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915

2023-08-08 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug  8 06:59:41 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915: i915_gem.h

Log Message:
nix the NetBSD specific GEM_BUG_ON().

avoids GCC 12 warnings, and matches upstream closer.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem.h

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



CVS commit: src/sys/external/bsd/drm2/dist/drm

2023-08-08 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug  8 06:58:20 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm: drm_dp_helper.c

Log Message:
comment a function that has a clear overbounds read but it isn't used.

found by GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c

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/drm_dp_helper.c
diff -u src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c:1.16 src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c:1.17
--- src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c:1.16	Sun Dec 19 12:41:54 2021
+++ src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c	Tue Aug  8 06:58:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_dp_helper.c,v 1.16 2021/12/19 12:41:54 riastradh Exp $	*/
+/*	$NetBSD: drm_dp_helper.c,v 1.17 2023/08/08 06:58:20 mrg Exp $	*/
 
 /*
  * Copyright © 2009 Keith Packard
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_dp_helper.c,v 1.16 2021/12/19 12:41:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_dp_helper.c,v 1.17 2023/08/08 06:58:20 mrg Exp $");
 
 #include 
 #include 
@@ -128,6 +128,13 @@ u8 drm_dp_get_adjust_request_pre_emphasi
 }
 EXPORT_SYMBOL(drm_dp_get_adjust_request_pre_emphasis);
 
+#ifndef __NetBSD__
+/*
+ * XXXGCC12
+ * this unused function is bad.  DP_LINK_STATUS_SIZE is 6, and
+ * DP_ADJUST_REQUEST_POST_CURSOR2 triggers an offset of 10 into link_status[].
+ * fortunately, it is not used.
+ */
 u8 drm_dp_get_adjust_request_post_cursor(const u8 link_status[DP_LINK_STATUS_SIZE],
 	 unsigned int lane)
 {
@@ -137,6 +144,7 @@ u8 drm_dp_get_adjust_request_post_cursor
 	return (value >> (lane << 1)) & 0x3;
 }
 EXPORT_SYMBOL(drm_dp_get_adjust_request_post_cursor);
+#endif
 
 void drm_dp_link_train_clock_recovery_delay(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
 {



CVS commit: src/sys/external/bsd/drm2/dist/drm

2023-08-08 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Aug  8 06:58:20 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm: drm_dp_helper.c

Log Message:
comment a function that has a clear overbounds read but it isn't used.

found by GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/external/bsd/drm2/dist/drm/drm_dp_helper.c

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



CVS commit: src/sys/external/bsd/drm2/radeon

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:35:06 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
radeon: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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



CVS commit: src/sys/external/bsd/drm2/radeon

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:35:06 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
radeon: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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/radeon/radeon_pci.c
diff -u src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.23 src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.24
--- src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.23	Tue Mar  7 20:23:00 2023
+++ src/sys/external/bsd/drm2/radeon/radeon_pci.c	Mon Aug  7 16:35:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_pci.c,v 1.23 2023/03/07 20:23:00 mrg Exp $	*/
+/*	$NetBSD: radeon_pci.c,v 1.24 2023/08/07 16:35:06 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.23 2023/03/07 20:23:00 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.24 2023/08/07 16:35:06 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "genfb.h"
@@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: radeon_pci.c
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if NGENFB > 0
@@ -366,6 +367,8 @@ radeon_do_suspend(device_t self, const p
 	int ret;
 	bool is_console = true; /* XXX */
 
+	drm_suspend_ioctl(dev);
+
 	ret = radeon_suspend_kms(dev, true, is_console, false);
 	if (ret)
 		return false;
@@ -383,9 +386,10 @@ radeon_do_resume(device_t self, const pm
 
 	ret = radeon_resume_kms(dev, true, is_console);
 	if (ret)
-		return false;
+		goto out;
 
-	return true;
+out:	drm_resume_ioctl(dev);
+	return ret == 0;
 }
 
 static void



CVS commit: src/sys/external/bsd/drm2/nouveau

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:34:57 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/nouveau: nouveau_pci.c

Log Message:
nouveau: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c

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/nouveau/nouveau_pci.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.37 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.38
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.37	Wed Mar  1 08:42:34 2023
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.c	Mon Aug  7 16:34:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_pci.c,v 1.37 2023/03/01 08:42:34 riastradh Exp $	*/
+/*	$NetBSD: nouveau_pci.c,v 1.38 2023/08/07 16:34:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.37 2023/03/01 08:42:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.38 2023/08/07 16:34:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "genfb.h"
@@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: nouveau_pci.
 #include 
 #endif
 
+#include 
 #include 
 
 #include 
@@ -316,16 +317,31 @@ static bool
 nouveau_pci_suspend(device_t self, const pmf_qual_t *qual __unused)
 {
 	struct nouveau_pci_softc *const sc = device_private(self);
+	struct drm_device *const dev = sc->sc_drm_dev;
+	int ret;
+
+	drm_suspend_ioctl(dev);
+
+	ret = nouveau_pmops_suspend(dev);
+	if (ret)
+		return false;
 
-	return nouveau_pmops_suspend(sc->sc_drm_dev) == 0;
+	return true;
 }
 
 static bool
 nouveau_pci_resume(device_t self, const pmf_qual_t *qual)
 {
 	struct nouveau_pci_softc *const sc = device_private(self);
+	struct drm_device *const dev = sc->sc_drm_dev;
+	int ret;
+
+	ret = nouveau_pmops_resume(sc->sc_drm_dev);
+	if (ret)
+		goto out;
 
-	return nouveau_pmops_resume(sc->sc_drm_dev) == 0;
+out:	drm_resume_ioctl(dev);
+	return ret == 0;
 }
 
 static void



CVS commit: src/sys/external/bsd/drm2/nouveau

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:34:57 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/nouveau: nouveau_pci.c

Log Message:
nouveau: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c

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



CVS commit: src/sys/external/bsd/drm2/amdgpu

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:34:47 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/amdgpu: amdgpu_pci.c

Log Message:
amdgpu: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c

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/amdgpu/amdgpu_pci.c
diff -u src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c:1.11 src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c:1.12
--- src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c:1.11	Mon Jul 18 23:34:02 2022
+++ src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c	Mon Aug  7 16:34:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_pci.c,v 1.11 2022/07/18 23:34:02 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_pci.c,v 1.12 2023/08/07 16:34:47 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_pci.c,v 1.11 2022/07/18 23:34:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_pci.c,v 1.12 2023/08/07 16:34:47 riastradh Exp $");
 
 #include 
 #include 
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: amdgpu_pci.c
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -260,6 +261,8 @@ amdgpu_do_suspend(device_t self, const p
 	struct drm_device *const dev = sc->sc_drm_dev;
 	int ret;
 
+	drm_suspend_ioctl(dev);
+
 	ret = amdgpu_device_suspend(dev, /*fbcon*/true);
 	if (ret)
 		return false;
@@ -276,9 +279,10 @@ amdgpu_do_resume(device_t self, const pm
 
 	ret = amdgpu_device_resume(dev, /*fbcon*/true);
 	if (ret)
-		return false;
+		goto out;
 
-	return true;
+out:	drm_resume_ioctl(dev);
+	return ret == 0;
 }
 
 static void



CVS commit: src/sys/external/bsd/drm2/amdgpu

2023-08-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  7 16:34:47 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/amdgpu: amdgpu_pci.c

Log Message:
amdgpu: Suspend ioctls while device is suspended.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/amdgpu/amdgpu_pci.c

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



CVS commit: src/sys/external/bsd/drm2/linux

2023-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 29 23:50:03 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_ww_mutex.c

Log Message:
drm/linux_ww_mutex: Fix ww acquire context ordering.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c

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/linux/linux_ww_mutex.c
diff -u src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.15 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.16
--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.15	Sat Jul 29 22:43:56 2023
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c	Sat Jul 29 23:50:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $	*/
+/*	$NetBSD: linux_ww_mutex.c,v 1.16 2023/07/29 23:50:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.16 2023/07/29 23:50:03 riastradh Exp $");
 
 #include 
 #include 
@@ -62,7 +62,7 @@ ww_acquire_ctx_compare(void *cookie __un
 	if (ctx_a->wwx_ticket < ctx_b->wwx_ticket)
 		return -1;
 	if (ctx_a->wwx_ticket > ctx_b->wwx_ticket)
-		return -1;
+		return +1;
 	return 0;
 }
 
@@ -76,7 +76,7 @@ ww_acquire_ctx_compare_key(void *cookie 
 	if (ctx->wwx_ticket < ticket)
 		return -1;
 	if (ctx->wwx_ticket > ticket)
-		return -1;
+		return +1;
 	return 0;
 }
 



CVS commit: src/sys/external/bsd/drm2/linux

2023-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 29 23:50:03 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_ww_mutex.c

Log Message:
drm/linux_ww_mutex: Fix ww acquire context ordering.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c

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



CVS commit: src/sys/external/bsd/drm2/linux

2023-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 29 22:43:56 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_ww_mutex.c

Log Message:
drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock.  It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c

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/linux/linux_ww_mutex.c
diff -u src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.14 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.15
--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.14	Fri Mar 18 23:33:41 2022
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c	Sat Jul 29 22:43:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ww_mutex.c,v 1.14 2022/03/18 23:33:41 riastradh Exp $	*/
+/*	$NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.14 2022/03/18 23:33:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $");
 
 #include 
 #include 
@@ -286,8 +286,14 @@ ww_mutex_state_wait(struct ww_mutex *mut
 
 	KASSERT(mutex_owned(>wwm_lock));
 	KASSERT(mutex->wwm_state == state);
-	do cv_wait(>wwm_cv, >wwm_lock);
-	while (mutex->wwm_state == state);
+
+	for (;;) {
+		cv_wait(>wwm_cv, >wwm_lock);
+		if (mutex->wwm_state != state)
+			break;
+	}
+
+	KASSERT(mutex->wwm_state != state);
 }
 
 /*
@@ -310,18 +316,26 @@ ww_mutex_state_wait_sig(struct ww_mutex 
 
 	KASSERT(mutex_owned(>wwm_lock));
 	KASSERT(mutex->wwm_state == state);
-	do {
+
+	for (;;) {
 		/* XXX errno NetBSD->Linux */
 		ret = -cv_wait_sig(>wwm_cv, >wwm_lock);
+		if (mutex->wwm_state != state) {
+			ret = 0;
+			break;
+		}
 		if (ret) {
 			KASSERTMSG((ret == -EINTR || ret == -ERESTART),
 			"ret=%d", ret);
 			ret = -EINTR;
 			break;
 		}
-	} while (mutex->wwm_state == state);
+	}
 
 	KASSERTMSG((ret == 0 || ret == -EINTR), "ret=%d", ret);
+	KASSERTMSG(ret != 0 || mutex->wwm_state != state,
+	"ret=%d mutex=%p mutex->wwm_state=%d state=%d",
+	ret, mutex, mutex->wwm_state, state);
 	return ret;
 }
 
@@ -363,12 +377,18 @@ ww_mutex_lock_wait(struct ww_mutex *mute
 	"ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
 	ctx->wwx_ticket, ctx, collision->wwx_ticket, collision);
 
-	do cv_wait(>wwm_cv, >wwm_lock);
-	while (!(((mutex->wwm_state == WW_CTX) ||
-		(mutex->wwm_state == WW_WANTOWN)) &&
-		 (mutex->wwm_u.ctx == ctx)));
+	for (;;) {
+		cv_wait(>wwm_cv, >wwm_lock);
+		if ((mutex->wwm_state == WW_CTX ||
+			mutex->wwm_state == WW_WANTOWN) &&
+		mutex->wwm_u.ctx == ctx)
+			break;
+	}
 
 	rb_tree_remove_node(>wwm_waiters, ctx);
+
+	KASSERT(mutex->wwm_state == WW_CTX || mutex->wwm_state == WW_WANTOWN);
+	KASSERT(mutex->wwm_u.ctx == ctx);
 }
 
 /*
@@ -411,21 +431,29 @@ ww_mutex_lock_wait_sig(struct ww_mutex *
 	"ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
 	ctx->wwx_ticket, ctx, collision->wwx_ticket, collision);
 
-	do {
+	for (;;) {
 		/* XXX errno NetBSD->Linux */
 		ret = -cv_wait_sig(>wwm_cv, >wwm_lock);
+		if ((mutex->wwm_state == WW_CTX ||
+			mutex->wwm_state == WW_WANTOWN) &&
+		mutex->wwm_u.ctx == ctx) {
+			ret = 0;
+			break;
+		}
 		if (ret) {
 			KASSERTMSG((ret == -EINTR || ret == -ERESTART),
 			"ret=%d", ret);
 			ret = -EINTR;
-			goto out;
+			break;
 		}
-	} while (!(((mutex->wwm_state == WW_CTX) ||
-		(mutex->wwm_state == WW_WANTOWN)) &&
-		(mutex->wwm_u.ctx == ctx)));
+	}
+
+	rb_tree_remove_node(>wwm_waiters, ctx);
 
-out:	rb_tree_remove_node(>wwm_waiters, ctx);
 	KASSERTMSG((ret == 0 || ret == -EINTR), "ret=%d", ret);
+	KASSERT(ret != 0 ||
+	mutex->wwm_state == WW_CTX || mutex->wwm_state == WW_WANTOWN);
+	KASSERT(ret != 0 || mutex->wwm_u.ctx == ctx);
 	return ret;
 }
 



CVS commit: src/sys/external/bsd/drm2/linux

2023-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 29 22:43:56 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_ww_mutex.c

Log Message:
drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock.  It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/display/dc

2023-07-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jul 20 21:48:49 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs:
amdgpu_dcn_calcs.c
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20:
amdgpu_dcn20_resource.c

Log Message:
amdgpu: Mark float-dependent variables volatile.

This way they are computed -- using FP instructions -- before
DC_FP_END, after which point FP instructions will trap or behave
unpredictably.

This is a workaround, not a proper solution -- really, the
DC_FP_START/END calls should happen in a separate compilation unit
built without -mhard-float or whatever, but that's a lot more work to
make happen for now.

PR kern/57059

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c
cvs rdiff -u -r1.4 -r1.5 \

src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c

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/amd/display/dc/calcs/amdgpu_dcn_calcs.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c:1.3 src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c:1.3	Sun Dec 19 11:35:07 2021
+++ src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c	Thu Jul 20 21:48:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_dcn_calcs.c,v 1.3 2021/12/19 11:35:07 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_dcn_calcs.c,v 1.4 2023/07/20 21:48:49 riastradh Exp $	*/
 
 /*
  * Copyright 2017 Advanced Micro Devices, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_dcn_calcs.c,v 1.3 2021/12/19 11:35:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_dcn_calcs.c,v 1.4 2023/07/20 21:48:49 riastradh Exp $");
 
 #include "dm_services.h"
 #include "dc.h"
@@ -626,7 +626,7 @@ static void calc_wm_sets_and_perf_params
 
 static bool dcn_bw_apply_registry_override(struct dc *dc)
 {
-	bool updated = false;
+	volatile bool updated = false;
 
 	DC_FP_START();
 	if ((int)(dc->dcn_soc->sr_exit_time * 1000) != dc->debug.sr_exit_time_ns
@@ -733,7 +733,7 @@ bool dcn_validate_bandwidth(
 	struct dcn_bw_internal_vars *v = >dcn_bw_vars;
 	int i, input_idx, k;
 	int vesa_sync_start, asic_blank_end, asic_blank_start;
-	bool bw_limit_pass;
+	volatile bool bw_limit_pass;
 	float bw_limit;
 
 	PERFORMANCE_TRACE_START();
@@ -1502,7 +1502,7 @@ void dcn_bw_notify_pplib_of_wm_ranges(st
 {
 	struct pp_smu_funcs_rv *pp = NULL;
 	struct pp_smu_wm_range_sets ranges = {0};
-	int min_fclk_khz, min_dcfclk_khz, socclk_khz;
+	volatile int min_fclk_khz, min_dcfclk_khz, socclk_khz;
 	const int overdrive = 500; /* 5 GHz to cover Overdrive */
 
 	if (dc->res_pool->pp_smu)

Index: src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c:1.4 src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c:1.4	Sun Dec 19 11:59:31 2021
+++ src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c	Thu Jul 20 21:48:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_dcn20_resource.c,v 1.4 2021/12/19 11:59:31 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_dcn20_resource.c,v 1.5 2023/07/20 21:48:49 riastradh Exp $	*/
 
 /*
 * Copyright 2016 Advanced Micro Devices, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_dcn20_resource.c,v 1.4 2021/12/19 11:59:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_dcn20_resource.c,v 1.5 2023/07/20 21:48:49 riastradh Exp $");
 
 #include 
 
@@ -2932,7 +2932,7 @@ validate_out:
 bool dcn20_validate_bandwidth(struct dc *dc, struct dc_state *context,
 		bool fast_validate)
 {
-	bool voltage_supported = false;
+	volatile bool voltage_supported = false;
 	bool full_pstate_supported = false;
 	bool dummy_pstate_supported = false;
 	double p_state_latency_us;



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/display/dc

2023-07-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jul 20 21:48:49 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs:
amdgpu_dcn_calcs.c
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20:
amdgpu_dcn20_resource.c

Log Message:
amdgpu: Mark float-dependent variables volatile.

This way they are computed -- using FP instructions -- before
DC_FP_END, after which point FP instructions will trap or behave
unpredictably.

This is a workaround, not a proper solution -- really, the
DC_FP_START/END calls should happen in a separate compilation unit
built without -mhard-float or whatever, but that's a lot more work to
make happen for now.

PR kern/57059

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/amd/display/dc/calcs/amdgpu_dcn_calcs.c
cvs rdiff -u -r1.4 -r1.5 \

src/sys/external/bsd/drm2/dist/drm/amd/display/dc/dcn20/amdgpu_dcn20_resource.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-07-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jul 20 18:02:45 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_fence.c

Log Message:
avoid calling drm_sched_fini() for AMDGPU_RING_TYPE_KIQ rings.

drm_sched_init() is not called for these rings, and we'd panic trying
to mutex_destroy() a mutex that wasn't initialised.

this seems like a general bug, not a bug in netbsd port.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c

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/amd/amdgpu/amdgpu_fence.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.10 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.11
--- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.10	Sun Dec 19 12:02:39 2021
+++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c	Thu Jul 20 18:02:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_fence.c,v 1.10 2021/12/19 12:02:39 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_fence.c,v 1.11 2023/07/20 18:02:45 mrg Exp $	*/
 
 /*
  * Copyright 2009 Jerome Glisse.
@@ -31,7 +31,7 @@
  *Dave Airlie
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_fence.c,v 1.10 2021/12/19 12:02:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_fence.c,v 1.11 2023/07/20 18:02:45 mrg Exp $");
 
 #include 
 #include 
@@ -541,7 +541,9 @@ void amdgpu_fence_driver_fini(struct amd
 		}
 		amdgpu_irq_put(adev, ring->fence_drv.irq_src,
 			   ring->fence_drv.irq_type);
-		drm_sched_fini(>sched);
+		if (ring->funcs->type != AMDGPU_RING_TYPE_KIQ) {
+			drm_sched_fini(>sched);
+		}
 		del_timer_sync(>fence_drv.fallback_timer);
 		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
 			dma_fence_put(ring->fence_drv.fences[j]);



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-07-20 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jul 20 18:02:45 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_fence.c

Log Message:
avoid calling drm_sched_fini() for AMDGPU_RING_TYPE_KIQ rings.

drm_sched_init() is not called for these rings, and we'd panic trying
to mutex_destroy() a mutex that wasn't initialised.

this seems like a general bug, not a bug in netbsd port.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-07-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 11 10:42:36 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: idr.h

Log Message:
linux/idr.h: Need  for kmutex_t.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/include/linux/idr.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/include/linux/idr.h
diff -u src/sys/external/bsd/drm2/include/linux/idr.h:1.10 src/sys/external/bsd/drm2/include/linux/idr.h:1.11
--- src/sys/external/bsd/drm2/include/linux/idr.h:1.10	Tue Oct 25 23:36:32 2022
+++ src/sys/external/bsd/drm2/include/linux/idr.h	Tue Jul 11 10:42:36 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: idr.h,v 1.10 2022/10/25 23:36:32 riastradh Exp $	*/
+/*	$NetBSD: idr.h,v 1.11 2023/07/11 10:42:36 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -33,6 +33,7 @@
 #define _LINUX_IDR_H_
 
 #include 
+#include 
 #include 
 
 #include 



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-07-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 11 10:42:36 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: idr.h

Log Message:
linux/idr.h: Need  for kmutex_t.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/include/linux/idr.h

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gt

2023-07-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul  9 20:24:06 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gt: intel_ggtt.c

Log Message:
i915: Fail gracefully, don't panic, with unsupported ggtt views.

Workaround for part of PR kern/56648.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c

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/gt/intel_ggtt.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c:1.15 src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c:1.16
--- src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c:1.15	Sun Dec 19 12:35:13 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c	Sun Jul  9 20:24:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: intel_ggtt.c,v 1.15 2021/12/19 12:35:13 riastradh Exp $	*/
+/*	$NetBSD: intel_ggtt.c,v 1.16 2023/07/09 20:24:06 riastradh Exp $	*/
 
 // SPDX-License-Identifier: MIT
 /*
@@ -6,7 +6,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intel_ggtt.c,v 1.15 2021/12/19 12:35:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intel_ggtt.c,v 1.16 2023/07/09 20:24:06 riastradh Exp $");
 
 #include 
 
@@ -1772,17 +1772,23 @@ i915_get_ggtt_vma_pages(struct i915_vma 
 		vma->pages = vma->obj->mm.pages;
 		return 0;
 
-#ifndef __NetBSD__
 	case I915_GGTT_VIEW_ROTATED:
+#ifdef __NetBSD__
+		vma->pages = ERR_PTR(-ENODEV);
+#else
 		vma->pages =
 			intel_rotate_pages(>ggtt_view.rotated, vma->obj);
+#endif
 		break;
 
 	case I915_GGTT_VIEW_REMAPPED:
+#ifdef __NetBSD__
+		vma->pages = ERR_PTR(-ENODEV);
+#else
 		vma->pages =
 			intel_remap_pages(>ggtt_view.remapped, vma->obj);
-		break;
 #endif
+		break;
 
 	case I915_GGTT_VIEW_PARTIAL:
 		vma->pages = intel_partial_pages(>ggtt_view, vma->obj);



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gt

2023-07-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul  9 20:24:06 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gt: intel_ggtt.c

Log Message:
i915: Fail gracefully, don't panic, with unsupported ggtt views.

Workaround for part of PR kern/56648.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
src/sys/external/bsd/drm2/dist/drm/i915/gt/intel_ggtt.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-05-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 25 12:07:43 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_device.c

Log Message:
amdgpu: Fix mostly harmless merge botch.

Avoids confusing error message that should have been confined to an
error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-05-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 25 12:07:43 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_device.c

Log Message:
amdgpu: Fix mostly harmless merge botch.

Avoids confusing error message that should have been confined to an
error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c

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/amd/amdgpu/amdgpu_device.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.18 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.19
--- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.18	Tue Feb 21 11:39:39 2023
+++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c	Thu May 25 12:07:43 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_device.c,v 1.18 2023/02/21 11:39:39 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_device.c,v 1.19 2023/05/25 12:07:43 riastradh Exp $	*/
 
 /*
  * Copyright 2008 Advanced Micro Devices, Inc.
@@ -28,7 +28,7 @@
  *  Jerome Glisse
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.18 2023/02/21 11:39:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.19 2023/05/25 12:07:43 riastradh Exp $");
 
 #include 
 #include 
@@ -3085,7 +3085,6 @@ int amdgpu_device_init(struct amdgpu_dev
 	}
 #ifdef __NetBSD__
 	if (i == DEVICE_COUNT_RESOURCE)
-		DRM_ERROR("Unable to find PCI I/O BAR\n");
 #else
 	if (adev->rio_mem == NULL)
 #endif



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-05-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon May 22 22:36:53 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: intelfb.c

Log Message:
Use the offset in mmap calculations.

It fixes wsfb(4) when used with intelfb(4).

Ok riastradh@

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/i915drm/intelfb.c

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/i915drm/intelfb.c
diff -u src/sys/external/bsd/drm2/i915drm/intelfb.c:1.24 src/sys/external/bsd/drm2/i915drm/intelfb.c:1.25
--- src/sys/external/bsd/drm2/i915drm/intelfb.c:1.24	Mon Jul 18 23:34:02 2022
+++ src/sys/external/bsd/drm2/i915drm/intelfb.c	Mon May 22 22:36:53 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: intelfb.c,v 1.24 2022/07/18 23:34:02 riastradh Exp $	*/
+/*	$NetBSD: intelfb.c,v 1.25 2023/05/22 22:36:53 nat Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.24 2022/07/18 23:34:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.25 2023/05/22 22:36:53 nat Exp $");
 
 #include 
 #include 
@@ -181,8 +181,8 @@ intelfb_drmfb_mmapfb(struct drmfb_softc 
 	KASSERT(0 <= offset);
 	KASSERT(offset < vma->node.size);
 
-	return bus_space_mmap(dev->bst, ggtt->gmadr.start, vma->node.start,
-	prot, BUS_SPACE_MAP_PREFETCHABLE);
+	return bus_space_mmap(dev->bst, ggtt->gmadr.start,
+	vma->node.start + offset, prot, BUS_SPACE_MAP_PREFETCHABLE);
 }
 
 static void



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-05-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon May 22 22:36:53 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: intelfb.c

Log Message:
Use the offset in mmap calculations.

It fixes wsfb(4) when used with intelfb(4).

Ok riastradh@

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/i915drm/intelfb.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2023-05-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri May 12 10:13:37 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_busy.c

Log Message:
i915: Avoid dereferencing null fence if resv has changed.

PR kern/57402

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/i915/gem

2023-05-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri May 12 10:13:37 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/i915/gem: i915_gem_busy.c

Log Message:
i915: Avoid dereferencing null fence if resv has changed.

PR kern/57402

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c

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/gem/i915_gem_busy.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c:1.3 src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c:1.3	Sun Dec 19 11:20:25 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_busy.c	Fri May 12 10:13:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_gem_busy.c,v 1.3 2021/12/19 11:20:25 riastradh Exp $	*/
+/*	$NetBSD: i915_gem_busy.c,v 1.4 2023/05/12 10:13:37 riastradh Exp $	*/
 
 /*
  * SPDX-License-Identifier: MIT
@@ -7,7 +7,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i915_gem_busy.c,v 1.3 2021/12/19 11:20:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_gem_busy.c,v 1.4 2023/05/12 10:13:37 riastradh Exp $");
 
 #include "gt/intel_engine.h"
 
@@ -130,6 +130,8 @@ retry:
 			struct dma_fence *fence =
 rcu_dereference(list->shared[i]);
 
+			if (read_seqcount_retry(>base.resv->seq, seq))
+goto retry;
 			args->busy |= busy_check_reader(fence);
 		}
 	}



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-05-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  1 09:41:55 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: interval_tree.h

Log Message:
drm: KASSERT(A && B) -> KASSERT(A); KASSERT(B)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/sys/external/bsd/drm2/include/linux/interval_tree.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/include/linux/interval_tree.h
diff -u src/sys/external/bsd/drm2/include/linux/interval_tree.h:1.13 src/sys/external/bsd/drm2/include/linux/interval_tree.h:1.14
--- src/sys/external/bsd/drm2/include/linux/interval_tree.h:1.13	Sun Feb 27 14:18:25 2022
+++ src/sys/external/bsd/drm2/include/linux/interval_tree.h	Mon May  1 09:41:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: interval_tree.h,v 1.13 2022/02/27 14:18:25 riastradh Exp $	*/
+/*	$NetBSD: interval_tree.h,v 1.14 2023/05/01 09:41:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -120,7 +120,8 @@ interval_tree_iter_first(struct rb_root_
 		return NULL;
 	if (last < node->start)
 		return NULL;
-	KASSERT(node->start <= last && node->last >= start);
+	KASSERT(node->start <= last);
+	KASSERT(node->last >= start);
 
 	return node;
 }
@@ -142,7 +143,8 @@ interval_tree_iter_next(struct rb_root_c
 		return NULL;
 	if (last < next->start)
 		return NULL;
-	KASSERT(next->start <= last && next->last >= start);
+	KASSERT(next->start <= last);
+	KASSERT(next->last >= start);
 
 	return next;
 }



CVS commit: src/sys/external/bsd/drm2/include/linux

2023-05-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  1 09:41:55 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/include/linux: interval_tree.h

Log Message:
drm: KASSERT(A && B) -> KASSERT(A); KASSERT(B)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/sys/external/bsd/drm2/include/linux/interval_tree.h

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



CVS commit: src/sys/external/bsd/drm2/radeon

2023-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar  7 20:23:00 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
remove "nouveau" from a comment.  noted by jmcneill.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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/radeon/radeon_pci.c
diff -u src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.22 src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.23
--- src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.22	Tue Mar  7 09:47:48 2023
+++ src/sys/external/bsd/drm2/radeon/radeon_pci.c	Tue Mar  7 20:23:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_pci.c,v 1.22 2023/03/07 09:47:48 mrg Exp $	*/
+/*	$NetBSD: radeon_pci.c,v 1.23 2023/03/07 20:23:00 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.22 2023/03/07 09:47:48 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.23 2023/03/07 20:23:00 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "genfb.h"
@@ -285,7 +285,7 @@ radeon_attach_real(device_t self)
 	 * with a firmware-provided framebuffer address, we may have to
 	 * turn it off early, before we are ready to switch the console
 	 * over -- something goes wrong if we're still writing to the
-	 * firmware-provided framebuffer during nouveau initialization.
+	 * firmware-provided framebuffer during initialization.
 	 */
 {
 	bool is_console;



CVS commit: src/sys/external/bsd/drm2/radeon

2023-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar  7 20:23:00 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
remove "nouveau" from a comment.  noted by jmcneill.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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



CVS commit: src/sys/external/bsd/drm2/radeon

2023-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar  7 09:47:48 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
radeon: Kick out genfb on firmware framebuffer before initializing.

this is the same change as nouveau_pci.c:1.37, and should fix at
least PR#56714 and i thought at least another PR i can't find right
now.  it fixes at least 2 different radeon cards for me on UEFI
booted system.

XXX: pullup-10 also include the original change:
   http://mail-index.netbsd.org/source-changes/2023/03/01/msg143606.html


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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/radeon/radeon_pci.c
diff -u src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.21 src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.22
--- src/sys/external/bsd/drm2/radeon/radeon_pci.c:1.21	Mon Jul 18 23:34:03 2022
+++ src/sys/external/bsd/drm2/radeon/radeon_pci.c	Tue Mar  7 09:47:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeon_pci.c,v 1.21 2022/07/18 23:34:03 riastradh Exp $	*/
+/*	$NetBSD: radeon_pci.c,v 1.22 2023/03/07 09:47:48 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,9 +30,10 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.21 2022/07/18 23:34:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeon_pci.c,v 1.22 2023/03/07 09:47:48 mrg Exp $");
 
 #ifdef _KERNEL_OPT
+#include "genfb.h"
 #include "vga.h"
 #if defined(__arm__) || defined(__aarch64__)
 #include "opt_fdt.h"
@@ -73,6 +74,11 @@ __KERNEL_RCSID(0, "$NetBSD: radeon_pci.c
 #include 
 #include 
 
+#if NGENFB > 0
+#include 
+#include 
+#endif
+
 #include 
 #include "radeon_drv.h"
 #include "radeon_task.h"
@@ -273,6 +279,24 @@ radeon_attach_real(device_t self)
 	}
 	sc->sc_pci_attached = true;
 
+#if NGENFB > 0
+	/*
+	 * If MD initialization has selected this as the console device
+	 * with a firmware-provided framebuffer address, we may have to
+	 * turn it off early, before we are ready to switch the console
+	 * over -- something goes wrong if we're still writing to the
+	 * firmware-provided framebuffer during nouveau initialization.
+	 */
+{
+	bool is_console;
+	if (prop_dictionary_get_bool(device_properties(self), "is_console",
+		_console) &&
+	is_console &&
+	genfb_is_console())
+		wsdisplay_predetach();
+}
+#endif
+
 	/* XXX errno Linux->NetBSD */
 	error = -drm_dev_register(sc->sc_drm_dev, flags);
 	if (error) {



CVS commit: src/sys/external/bsd/drm2/radeon

2023-03-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Mar  7 09:47:48 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/radeon: radeon_pci.c

Log Message:
radeon: Kick out genfb on firmware framebuffer before initializing.

this is the same change as nouveau_pci.c:1.37, and should fix at
least PR#56714 and i thought at least another PR i can't find right
now.  it fixes at least 2 different radeon cards for me on UEFI
booted system.

XXX: pullup-10 also include the original change:
   http://mail-index.netbsd.org/source-changes/2023/03/01/msg143606.html


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/external/bsd/drm2/radeon/radeon_pci.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:14:13 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_gart.c

Log Message:
amdgpu: Fix bogus loop invariant assertions in amdgpu_gart_map.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c

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/amd/amdgpu/amdgpu_gart.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c:1.10 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c:1.11
--- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c:1.10	Sat Jul 30 17:12:39 2022
+++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c	Wed Mar  1 08:14:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_gart.c,v 1.10 2022/07/30 17:12:39 riastradh Exp $	*/
+/*	$NetBSD: amdgpu_gart.c,v 1.11 2023/03/01 08:14:13 riastradh Exp $	*/
 
 /*
  * Copyright 2008 Advanced Micro Devices, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_gart.c,v 1.10 2022/07/30 17:12:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_gart.c,v 1.11 2023/03/01 08:14:13 riastradh Exp $");
 
 #include 
 #include 
@@ -440,8 +440,9 @@ int amdgpu_gart_map(struct amdgpu_device
 	t = gpu_start / AMDGPU_GPU_PAGE_SIZE;
 
 	for (i = 0; npages --> 0;) {
-		KASSERT(i < dmamap->dm_nsegs);
 		for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++) {
+			KASSERT(i < dmamap->dm_nsegs);
+			KASSERT(seg_off < dmamap->dm_segs[i].ds_len);
 			amdgpu_gmc_set_pte_pde(adev, dst, t,
 			dmamap->dm_segs[i].ds_addr + seg_off, flags);
 			seg_off += AMDGPU_GPU_PAGE_SIZE;
@@ -449,7 +450,6 @@ int amdgpu_gart_map(struct amdgpu_device
 i++;
 seg_off = 0;
 			}
-			KASSERT(seg_off < dmamap->dm_segs[i].ds_len);
 		}
 	}
 



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:14:13 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_gart.c

Log Message:
amdgpu: Fix bogus loop invariant assertions in amdgpu_gart_map.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c

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



CVS commit: src/sys/external/bsd/drm2/linux

2023-02-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 21 11:40:13 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_dma_buf.c

Log Message:
drm: Teach dmabuf to handle lseek.

Needed by libdrm_amdgpu.

Based on patch from Jeff Frasca -- thanks!

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_dma_buf.c

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/linux/linux_dma_buf.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.15 src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.16
--- src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.15	Sat Apr  9 23:44:44 2022
+++ src/sys/external/bsd/drm2/linux/linux_dma_buf.c	Tue Feb 21 11:40:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_buf.c,v 1.15 2022/04/09 23:44:44 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_buf.c,v 1.16 2023/02/21 11:40:13 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.15 2022/04/09 23:44:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.16 2023/02/21 11:40:13 riastradh Exp $");
 
 #include 
 #include 
@@ -48,6 +48,8 @@ static int	dmabuf_fop_close(struct file 
 static int	dmabuf_fop_kqfilter(struct file *, struct knote *);
 static int	dmabuf_fop_mmap(struct file *, off_t *, size_t, int, int *,
 		int *, struct uvm_object **, int *);
+static int	dmabuf_fop_seek(struct file *fp, off_t delta, int whence,
+		off_t *newoffp, int flags);
 
 static const struct fileops dmabuf_fileops = {
 	.fo_name = "dmabuf",
@@ -61,6 +63,7 @@ static const struct fileops dmabuf_fileo
 	.fo_kqfilter = dmabuf_fop_kqfilter,
 	.fo_restart = fnullop_restart,
 	.fo_mmap = dmabuf_fop_mmap,
+	.fo_seek = dmabuf_fop_seek,
 };
 
 struct dma_buf *
@@ -288,3 +291,54 @@ dmabuf_fop_mmap(struct file *file, off_t
 	return dmabuf->ops->mmap(dmabuf, offp, size, prot, flagsp, advicep,
 	uobjp, maxprotp);
 }
+
+/*
+ * We don't actually do anything with the file offset; this is just how
+ * libdrm_amdgpu expects to find the size of the DMA buf.  (Why it
+ * doesn't use fstat is unclear, but it doesn't really matter.)
+ */
+static int
+dmabuf_fop_seek(struct file *fp, off_t delta, int whence, off_t *newoffp,
+int flags)
+{
+	const off_t OFF_MAX = __type_max(off_t);
+	struct dma_buf *dmabuf = fp->f_data;
+	off_t base, newoff;
+	int error;
+
+	mutex_enter(>f_lock);
+
+	switch (whence) {
+	case SEEK_CUR:
+		base = fp->f_offset;
+		break;
+	case SEEK_END:
+		base = dmabuf->size;
+		break;
+	case SEEK_SET:
+		base = 0;
+		break;
+	default:
+		error = EINVAL;
+		goto out;
+	}
+
+	/* Check for arithmetic overflow and reject negative offsets.  */
+	if (base < 0 || delta > OFF_MAX - base || base + delta < 0) {
+		error = EINVAL;
+		goto out;
+	}
+
+	/* Compute the new offset.  */
+	newoff = base + delta;
+
+	/* Success!  */
+	if (newoffp)
+		*newoffp = newoff;
+	if (flags & FOF_UPDATE_OFFSET)
+		fp->f_offset = newoff;
+	error = 0;
+
+out:	mutex_exit(>f_lock);
+	return error;
+}



CVS commit: src/sys/external/bsd/drm2/linux

2023-02-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 21 11:40:13 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/linux: linux_dma_buf.c

Log Message:
drm: Teach dmabuf to handle lseek.

Needed by libdrm_amdgpu.

Based on patch from Jeff Frasca -- thanks!

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_dma_buf.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-02-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 21 11:39:39 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_device.c

Log Message:
amdgpu: Fix scale factor for 64-bit doorbell indexing.

The register is 64 bits wide, but the indexing is for 32-bit
quantities (and presumably index must be even here).

Found by Jeff Frasca -- thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c

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/amd/amdgpu/amdgpu_device.c
diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.17 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.18
--- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c:1.17	Tue Sep 20 23:01:42 2022
+++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c	Tue Feb 21 11:39:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amdgpu_device.c,v 1.17 2022/09/20 23:01:42 mrg Exp $	*/
+/*	$NetBSD: amdgpu_device.c,v 1.18 2023/02/21 11:39:39 riastradh Exp $	*/
 
 /*
  * Copyright 2008 Advanced Micro Devices, Inc.
@@ -28,7 +28,7 @@
  *  Jerome Glisse
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.17 2022/09/20 23:01:42 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdgpu_device.c,v 1.18 2023/02/21 11:39:39 riastradh Exp $");
 
 #include 
 #include 
@@ -483,19 +483,19 @@ u64 amdgpu_mm_rdoorbell64(struct amdgpu_
 #ifdef __NetBSD__
 #ifdef _LP64
 		return bus_space_read_8(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index);
+		4*index);
 #else
 		uint64_t lo, hi;
 #if _BYTE_ORDER == _LITTLE_ENDIAN
 		lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index);
+		4*index);
 		hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index + 4);
+		4*index + 4);
 #else
 		hi = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index);
+		4*index);
 		lo = bus_space_read_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index + 4);
+		4*index + 4);
 #endif
 		return lo | (hi << 32);
 #endif
@@ -524,21 +524,21 @@ void amdgpu_mm_wdoorbell64(struct amdgpu
 #ifdef __NetBSD__
 #ifdef _LP64
 		bus_space_write_8(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index, v);
+		4*index, v);
 #else
 		/*
 		 * XXX This might not be as atomic as one might hope...
 		 */
 #if _BYTE_ORDER == _LITTLE_ENDIAN
 		bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index, v & 0xU);
+		4*index, v & 0xU);
 		bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index + 4, v >> 32);
+		4*index + 4, v >> 32);
 #else
 		bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index, v >> 32);
+		4*index, v >> 32);
 		bus_space_write_4(adev->doorbell.bst, adev->doorbell.bsh,
-		8*index + 4, v & 0xU);
+		4*index + 4, v & 0xU);
 #endif
 #endif
 #else



CVS commit: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu

2023-02-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Feb 21 11:39:39 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_device.c

Log Message:
amdgpu: Fix scale factor for 64-bit doorbell indexing.

The register is 64 bits wide, but the indexing is for 32-bit
quantities (and presumably index must be even here).

Found by Jeff Frasca -- thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 \
src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c

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



re: CVS commit: src/sys/external/bsd/drm2/pci

2022-10-28 Thread matthew green
> Modified Files:
>   src/sys/external/bsd/drm2/pci: drm_pci.c
>
> Log Message:
> drm(4): Mark PCI interrupt handlers as MP-safe.

i tested this recently and on one of nvidia or radeon
it wasn't working for me.  i can confirm again next
weekend...


.mrg.


CVS commit: src/sys/external/bsd/drm2/pci

2022-10-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Oct 28 21:58:48 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/pci: drm_pci.c

Log Message:
drm(4): Mark PCI interrupt handlers as MP-safe.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/external/bsd/drm2/pci/drm_pci.c

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



CVS commit: src/sys/external/bsd/drm2/pci

2022-10-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Oct 28 21:58:48 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/pci: drm_pci.c

Log Message:
drm(4): Mark PCI interrupt handlers as MP-safe.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/external/bsd/drm2/pci/drm_pci.c

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/pci/drm_pci.c
diff -u src/sys/external/bsd/drm2/pci/drm_pci.c:1.47 src/sys/external/bsd/drm2/pci/drm_pci.c:1.48
--- src/sys/external/bsd/drm2/pci/drm_pci.c:1.47	Sun Dec 19 11:54:32 2021
+++ src/sys/external/bsd/drm2/pci/drm_pci.c	Fri Oct 28 21:58:48 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_pci.c,v 1.47 2021/12/19 11:54:32 riastradh Exp $	*/
+/*	$NetBSD: drm_pci.c,v 1.48 2022/10/28 21:58:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.47 2021/12/19 11:54:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.48 2022/10/28 21:58:48 riastradh Exp $");
 
 #include 
 #include 
@@ -188,6 +188,8 @@ drm_pci_request_irq(struct drm_device *d
 		}
 	}
 
+	pci_intr_setattr(pa->pa_pc, _cookie->intr_handles[0],
+	PCI_INTR_MPSAFE, true);
 	intrstr = pci_intr_string(pa->pa_pc, irq_cookie->intr_handles[0],
 	intrbuf, sizeof(intrbuf));
 	irq_cookie->ih_cookie = pci_intr_establish_xname(pa->pa_pc,



CVS commit: src/sys/external/bsd/drm2/dist/drm/vmwgfx

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:39:13 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/dist/drm/vmwgfx: vmwgfx_bo.c

Log Message:
vmwgfx(4): Partially adapt rbtree.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c

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/vmwgfx/vmwgfx_bo.c
diff -u src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c:1.2 src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c:1.3
--- src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c:1.2	Sat Dec 18 23:45:45 2021
+++ src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c	Tue Oct 25 23:39:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmwgfx_bo.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $	*/
+/*	$NetBSD: vmwgfx_bo.c,v 1.3 2022/10/25 23:39:13 riastradh Exp $	*/
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**
@@ -29,7 +29,7 @@
  **/
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_bo.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_bo.c,v 1.3 2022/10/25 23:39:13 riastradh Exp $");
 
 #include 
 
@@ -490,6 +490,9 @@ static void vmw_user_bo_destroy(struct t
 	ttm_prime_object_kfree(vmw_user_bo, prime);
 }
 
+#ifdef __NetBSD__
+extern rb_tree_ops_t vmwgfx_res_rb_ops;
+#endif
 
 /**
  * vmw_bo_init - Initialize a vmw buffer object
@@ -521,7 +524,11 @@ int vmw_bo_init(struct vmw_private *dev_
 	memset(vmw_bo, 0, sizeof(*vmw_bo));
 	BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3);
 	vmw_bo->base.priority = 3;
+#ifdef __NetBSD__
+	rb_tree_init(_bo->res_tree.rbr_tree, _res_rb_ops);
+#else
 	vmw_bo->res_tree = RB_ROOT;
+#endif
 
 	ret = ttm_bo_init(bdev, _bo->base, size,
 			  ttm_bo_type_device, placement,



CVS commit: src/sys/external/bsd/drm2/dist/drm/vmwgfx

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:39:13 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/dist/drm/vmwgfx: vmwgfx_bo.c

Log Message:
vmwgfx(4): Partially adapt rbtree.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_bo.c

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:37:24 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: suspend.h

Log Message:
linux/suspend.h: Stubs for (un)register_pm_notifier.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/include/linux/suspend.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/include/linux/suspend.h
diff -u src/sys/external/bsd/drm2/include/linux/suspend.h:1.3 src/sys/external/bsd/drm2/include/linux/suspend.h:1.4
--- src/sys/external/bsd/drm2/include/linux/suspend.h:1.3	Sun Dec 19 12:00:24 2021
+++ src/sys/external/bsd/drm2/include/linux/suspend.h	Tue Oct 25 23:37:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: suspend.h,v 1.3 2021/12/19 12:00:24 riastradh Exp $	*/
+/*	$NetBSD: suspend.h,v 1.4 2022/10/25 23:37:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -36,4 +36,7 @@
 
 #define	ksys_sync_helper()	__nothing
 
+#define	register_pm_notifier(n)		__nothing
+#define	unregister_pm_notifier(n)	__nothing
+
 #endif  /* _LINUX_SUSPEND_H_ */



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:37:24 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: suspend.h

Log Message:
linux/suspend.h: Stubs for (un)register_pm_notifier.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/include/linux/suspend.h

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:37:07 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: pci.h

Log Message:
linux/pci.h: Stubs for pci_request/release_region(s).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/external/bsd/drm2/include/linux/pci.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/include/linux/pci.h
diff -u src/sys/external/bsd/drm2/include/linux/pci.h:1.55 src/sys/external/bsd/drm2/include/linux/pci.h:1.56
--- src/sys/external/bsd/drm2/include/linux/pci.h:1.55	Mon Oct 17 03:05:32 2022
+++ src/sys/external/bsd/drm2/include/linux/pci.h	Tue Oct 25 23:37:06 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci.h,v 1.55 2022/10/17 03:05:32 mrg Exp $	*/
+/*	$NetBSD: pci.h,v 1.56 2022/10/25 23:37:06 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -266,6 +266,10 @@ enum pcie_link_width {
 #define	pci_read_config_byte		linux_pci_read_config_byte
 #define	pci_read_config_dword		linux_pci_read_config_dword
 #define	pci_read_config_word		linux_pci_read_config_word
+#define	pci_release_region		linux_pci_release_region
+#define	pci_release_regions		linux_pci_release_regions
+#define	pci_request_region		linux_pci_request_region
+#define	pci_request_regions		linux_pci_request_regions
 #define	pci_resource_end		linux_pci_resource_end
 #define	pci_resource_flags		linux_pci_resource_flags
 #define	pci_resource_len		linux_pci_resource_len
@@ -362,6 +366,11 @@ void		pci_unmap_rom(struct pci_dev *, vo
 int		pci_enable_rom(struct pci_dev *);
 void		pci_disable_rom(struct pci_dev *);
 
+int		pci_request_regions(struct pci_dev *, const char *);
+void		pci_release_regions(struct pci_dev *);
+int		pci_request_region(struct pci_dev *, int, const char *);
+void		pci_release_region(struct pci_dev *, int);
+
 bus_addr_t	pci_resource_start(struct pci_dev *, unsigned);
 bus_size_t	pci_resource_len(struct pci_dev *, unsigned);
 bus_addr_t	pci_resource_end(struct pci_dev *, unsigned);



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:37:07 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: pci.h

Log Message:
linux/pci.h: Stubs for pci_request/release_region(s).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/external/bsd/drm2/include/linux/pci.h

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



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:32 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: idr.h

Log Message:
linux/idr.h: Update ida_* API.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/include/linux/idr.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/include/linux/idr.h
diff -u src/sys/external/bsd/drm2/include/linux/idr.h:1.9 src/sys/external/bsd/drm2/include/linux/idr.h:1.10
--- src/sys/external/bsd/drm2/include/linux/idr.h:1.9	Sun Dec 19 01:15:21 2021
+++ src/sys/external/bsd/drm2/include/linux/idr.h	Tue Oct 25 23:36:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: idr.h,v 1.9 2021/12/19 01:15:21 riastradh Exp $	*/
+/*	$NetBSD: idr.h,v 1.10 2022/10/25 23:36:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@ ida_destroy(struct ida *ida)
 }
 
 static inline void
-ida_remove(struct ida *ida, int id)
+ida_free(struct ida *ida, int id)
 {
 
 	idr_remove(>ida_idr, id);
@@ -118,12 +118,19 @@ ida_simple_get(struct ida *ida, unsigned
 	return id;
 }
 
+static inline int
+ida_alloc_max(struct ida *ida, unsigned max, gfp_t gfp)
+{
+
+	return ida_simple_get(ida, 0, max + 1, gfp);
+}
+
 static inline void
 ida_simple_remove(struct ida *ida, unsigned int id)
 {
 
 	KASSERT((int)id >= 0);
-	ida_remove(ida, id);
+	ida_free(ida, id);
 }
 
 #endif  /* _LINUX_IDR_H_ */



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:32 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: idr.h

Log Message:
linux/idr.h: Update ida_* API.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/include/linux/idr.h

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/vmwgfx

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:21 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/dist/drm/vmwgfx: vmwgfx_drv.h vmwgfx_irq.c

Log Message:
vmwgfx(4): Hand-cruft threaded irq with a workqueue(9).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/vmwgfx

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:21 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/dist/drm/vmwgfx: vmwgfx_drv.h vmwgfx_irq.c

Log Message:
vmwgfx(4): Hand-cruft threaded irq with a workqueue(9).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c

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/vmwgfx/vmwgfx_drv.h
diff -u src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h:1.8 src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h:1.9
--- src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h:1.8	Tue Oct 25 23:35:43 2022
+++ src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h	Tue Oct 25 23:36:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmwgfx_drv.h,v 1.8 2022/10/25 23:35:43 riastradh Exp $	*/
+/*	$NetBSD: vmwgfx_drv.h,v 1.9 2022/10/25 23:36:21 riastradh Exp $	*/
 
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /**
@@ -30,6 +30,10 @@
 #ifndef _VMWGFX_DRV_H_
 #define _VMWGFX_DRV_H_
 
+#ifdef __NetBSD__
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -629,6 +633,11 @@ struct vmw_private {
 
 	struct vmw_cmdbuf_man *cman;
 	DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
+#ifdef __NetBSD__
+	struct workqueue *irqthread_wq;
+	struct work irqthread_work;
+	volatile unsigned irqthread_scheduled;
+#endif
 
 	/* Validation memory reservation */
 	struct vmw_validation_mem vvm;

Index: src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c
diff -u src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c:1.5 src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c:1.6
--- src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c:1.5	Tue Oct 25 23:35:43 2022
+++ src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c	Tue Oct 25 23:36:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmwgfx_irq.c,v 1.5 2022/10/25 23:35:43 riastradh Exp $	*/
+/*	$NetBSD: vmwgfx_irq.c,v 1.6 2022/10/25 23:36:21 riastradh Exp $	*/
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**
@@ -28,7 +28,7 @@
  **/
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_irq.c,v 1.5 2022/10/25 23:35:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_irq.c,v 1.6 2022/10/25 23:36:21 riastradh Exp $");
 
 #include 
 
@@ -49,12 +49,21 @@ __KERNEL_RCSID(0, "$NetBSD: vmwgfx_irq.c
  * vmw_irq_handler has returned with IRQ_WAKE_THREAD.
  *
  */
+#ifdef __NetBSD__
+static void
+vmw_thread_fn(struct work *work, void *arg)
+#else
 static irqreturn_t vmw_thread_fn(int irq, void *arg)
+#endif
 {
 	struct drm_device *dev = (struct drm_device *)arg;
 	struct vmw_private *dev_priv = vmw_priv(dev);
 	irqreturn_t ret = IRQ_NONE;
 
+#ifdef __NetBSD__
+	atomic_store_relaxed(_priv->irqthread_scheduled, false);
+#endif
+
 	if (test_and_clear_bit(VMW_IRQTHREAD_FENCE,
 			   dev_priv->irqthread_pending)) {
 		spin_lock(_priv->fence_lock);
@@ -71,7 +80,9 @@ static irqreturn_t vmw_thread_fn(int irq
 		ret = IRQ_HANDLED;
 	}
 
+#ifndef __NetBSD__
 	return ret;
+#endif
 }
 
 /**
@@ -129,6 +140,16 @@ static irqreturn_t vmw_irq_handler(int i
 			  dev_priv->irqthread_pending))
 		ret = IRQ_WAKE_THREAD;
 
+#ifdef __NetBSD__
+	if (ret == IRQ_WAKE_THREAD) {
+		if (atomic_swap_uint(_priv->irqthread_scheduled, 1) == 0) {
+			workqueue_enqueue(dev_priv->irqthread_wq,
+			_priv->irqthread_work, NULL);
+		}
+		ret = IRQ_HANDLED;
+	}
+#endif
+
 	return ret;
 }
 
@@ -450,7 +471,13 @@ void vmw_irq_uninstall(struct drm_device
 #endif
 
 	dev->irq_enabled = false;
+#ifdef __NetBSD__
+	int ret = drm_irq_uninstall(dev);
+	KASSERT(ret == 0);
+	workqueue_destroy(dev_priv->irqthread_wq);
+#else
 	free_irq(dev->irq, dev);
+#endif
 }
 
 /**
@@ -469,8 +496,21 @@ int vmw_irq_install(struct drm_device *d
 
 	vmw_irq_preinstall(dev);
 
+#ifdef __NetBSD__
+	/* XXX errno NetBSD->Linux */
+	ret = -workqueue_create(_priv(dev)->irqthread_wq, "vmwgfirq",
+	vmw_thread_fn, dev, PRI_NONE, IPL_DRM, WQ_MPSAFE);
+	if (ret < 0)
+		return ret;
+	ret = drm_irq_install(dev);
+	if (ret < 0) {
+		workqueue_destroy(vmw_priv(dev)->irqthread_wq);
+		vmw_priv(dev)->irqthread_wq = NULL;
+	}
+#else
 	ret = request_threaded_irq(irq, vmw_irq_handler, vmw_thread_fn,
    IRQF_SHARED, VMWGFX_DRIVER_NAME, dev);
+#endif
 	if (ret < 0)
 		return ret;
 



CVS commit: src/sys/external/bsd/drm2/include/drm

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:09 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/drm: drm_irq_netbsd.h

Log Message:
drm: New IRQ_WAKE_THREAD constant.

Not really wired up to anything but helps reduce diffs -- driver is
responsible for making decisions based on it, corresponding to
Linux's built-in `threaded irq'.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.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/include/drm/drm_irq_netbsd.h
diff -u src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.h:1.6 src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.h:1.7
--- src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.h:1.6	Sun Dec 19 12:10:58 2021
+++ src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.h	Tue Oct 25 23:36:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_irq_netbsd.h,v 1.6 2021/12/19 12:10:58 riastradh Exp $	*/
+/*	$NetBSD: drm_irq_netbsd.h,v 1.7 2022/10/25 23:36:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@ typedef int irqreturn_t;
 enum irqreturn {
 	IRQ_NONE = 0x0,
 	IRQ_HANDLED = 0x1,
+	IRQ_WAKE_THREAD = 0x2,	/* XXX requires manual workqueue setup */
 };
 
 #define	DRM_IRQ_ARGS	void *arg



CVS commit: src/sys/external/bsd/drm2/include/drm

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:36:09 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/drm: drm_irq_netbsd.h

Log Message:
drm: New IRQ_WAKE_THREAD constant.

Not really wired up to anything but helps reduce diffs -- driver is
responsible for making decisions based on it, corresponding to
Linux's built-in `threaded irq'.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/drm2/include/drm/drm_irq_netbsd.h

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



CVS commit: src/sys/external/bsd/drm2/dist/drm/vmwgfx

2022-10-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Oct 25 23:35:57 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/dist/drm/vmwgfx: vmwgfx_execbuf.c

Log Message:
vmwgfx(4): Port fd creation.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c

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/vmwgfx/vmwgfx_execbuf.c
diff -u src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c:1.4 src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c:1.5
--- src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c:1.4	Tue Oct 25 23:34:05 2022
+++ src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c	Tue Oct 25 23:35:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmwgfx_execbuf.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $	*/
+/*	$NetBSD: vmwgfx_execbuf.c,v 1.5 2022/10/25 23:35:57 riastradh Exp $	*/
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**
@@ -27,10 +27,14 @@
  *
  **/
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_execbuf.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_execbuf.c,v 1.5 2022/10/25 23:35:57 riastradh Exp $");
 
 #include 
 
+#ifdef __NetBSD__
+#include 
+#endif
+
 #include "vmwgfx_drv.h"
 #include "vmwgfx_reg.h"
 #include 
@@ -3466,6 +3470,10 @@ vmw_execbuf_copy_fence_user(struct vmw_p
 	 * handle.
 	 */
 	if (unlikely(ret != 0) && (fence_rep.error == 0)) {
+#ifdef __NetBSD__
+		if (fd_getfile(fence_rep.fd))
+			(void)fd_close(fence_rep.fd);
+#else
 		if (sync_file)
 			fput(sync_file->file);
 
@@ -3473,6 +3481,7 @@ vmw_execbuf_copy_fence_user(struct vmw_p
 			put_unused_fd(fence_rep.fd);
 			fence_rep.fd = -1;
 		}
+#endif
 
 		ttm_ref_object_base_unref(vmw_fp->tfile, fence_handle,
 	  TTM_REF_USAGE);
@@ -3655,18 +3664,29 @@ int vmw_execbuf_process(struct drm_file 
 	struct vmw_cmdbuf_header *header;
 	uint32_t handle = 0;
 	int ret;
+#ifdef __NetBSD__
+	int out_fence_fd = -1;
+	struct file *out_fence_fp = NULL;
+#else
 	int32_t out_fence_fd = -1;
+#endif
 	struct sync_file *sync_file = NULL;
 	DECLARE_VAL_CONTEXT(val_ctx, _context->res_ht, 1);
 
 	vmw_validation_set_val_mem(_ctx, _priv->vvm);
 
 	if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) {
+#ifdef __NetBSD__
+		ret = -fd_allocfile(_fence_fp, _fence_fd);
+		if (ret)
+			return ret;
+#else
 		out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
 		if (out_fence_fd < 0) {
 			VMW_DEBUG_USER("Failed to get a fence fd.\n");
 			return out_fence_fd;
 		}
+#endif
 	}
 
 	if (throttle_us) {
@@ -3813,17 +3833,30 @@ int vmw_execbuf_process(struct drm_file 
 	 */
 	if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) {
 
+#ifdef __NetBSD__
+		sync_file = sync_file_create(>base, out_fence_fp);
+#else
 		sync_file = sync_file_create(>base);
+#endif
 		if (!sync_file) {
 			VMW_DEBUG_USER("Sync file create failed for fence\n");
+#ifdef __NetBSD__
+			fd_abort(curproc, out_fence_fp, out_fence_fd);
+			out_fence_fp = NULL;
+#else
 			put_unused_fd(out_fence_fd);
+#endif
 			out_fence_fd = -1;
 
 			(void) vmw_fence_obj_wait(fence, false, false,
 		  VMW_FENCE_WAIT_TIMEOUT);
 		} else {
 			/* Link the fence with the FD created earlier */
+#ifdef __NetBSD__
+			fd_affix(curproc, out_fence_fp, out_fence_fd);
+#else
 			fd_install(out_fence_fd, sync_file->file);
+#endif
 		}
 	}
 
@@ -3877,7 +3910,11 @@ out_free_header:
 		vmw_cmdbuf_header_free(header);
 out_free_fence_fd:
 	if (out_fence_fd >= 0)
+#ifdef __NetBSD__
+		fd_abort(curproc, out_fence_fp, out_fence_fd);
+#else
 		put_unused_fd(out_fence_fd);
+#endif
 
 	return ret;
 }



  1   2   3   4   5   6   7   8   9   10   >