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

2021-08-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  2 23:14:15 UTC 2021

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

Log Message:
drm: Plug another fence leak.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.13 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.14
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.13	Mon Aug  2 20:20:54 2021
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug  2 23:14:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.13 2021/08/02 20:20:54 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.14 2021/08/02 23:14:15 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.13 2021/08/02 20:20:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.14 2021/08/02 23:14:15 riastradh Exp $");
 
 #include 
 #include 
@@ -1003,6 +1003,7 @@ top:
 		 * assume the event is not ready.
 		 */
 		if (!claimed || callback) {
+			fence_put(fence);
 			revents = 0;
 			break;
 		}



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

2021-08-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  2 20:20:54 UTC 2021

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

Log Message:
drm: Release fence if we're about to return too.

Should fix another fence leak.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.12 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.13
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.12	Sun Jun 27 08:10:36 2021
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug  2 20:20:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.12 2021/06/27 08:10:36 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.13 2021/08/02 20:20:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.12 2021/06/27 08:10:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.13 2021/08/02 20:20:54 riastradh Exp $");
 
 #include 
 #include 
@@ -794,9 +794,9 @@ wait:
 	KASSERT(fence != NULL);
 	rcu_read_unlock();
 	ret = fence_wait_timeout(fence, intr, timeout);
+	fence_put(fence);
 	if (ret <= 0)
 		return ret;
-	fence_put(fence);
 	KASSERT(ret <= timeout);
 	timeout = ret;
 	goto top;



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

2021-07-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 21 06:34:52 UTC 2021

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

Log Message:
need  for COHERENCY_UNIT


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_rcu.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_rcu.c
diff -u src/sys/external/bsd/drm2/linux/linux_rcu.c:1.4 src/sys/external/bsd/drm2/linux/linux_rcu.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_rcu.c:1.4	Mon Aug 27 15:07:59 2018
+++ src/sys/external/bsd/drm2/linux/linux_rcu.c	Wed Jul 21 06:34:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.4 2018/08/27 15:07:59 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.5 2021/07/21 06:34:52 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,8 +30,9 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.4 2018/08/27 15:07:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.5 2021/07/21 06:34:52 skrll Exp $");
 
+#include 
 #include 
 #include 
 #include 



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

2021-06-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 27 08:10:36 UTC 2021

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

Log Message:
drm: Release fence after use.

May plug the dreaded radeon kmem memory leak.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 \
src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.11 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.12
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.11	Mon Sep  3 18:02:11 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Sun Jun 27 08:10:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.11 2018/09/03 18:02:11 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.12 2021/06/27 08:10:36 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.11 2018/09/03 18:02:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.12 2021/06/27 08:10:36 riastradh Exp $");
 
 #include 
 #include 
@@ -796,6 +796,7 @@ wait:
 	ret = fence_wait_timeout(fence, intr, timeout);
 	if (ret <= 0)
 		return ret;
+	fence_put(fence);
 	KASSERT(ret <= timeout);
 	timeout = ret;
 	goto top;



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

2020-02-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Feb 12 18:35:02 UTC 2020

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

Log Message:
re-enable MSI - this actually enables MSI only for intel/radeon/generic
which are reported to work fine, while nouveau (which breaks with
MSI) still uses INTx

see the thread
http://mail-index.netbsd.org/current-users/2020/02/06/msg037661.html


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.9 src/sys/external/bsd/drm2/linux/linux_pci.c:1.10
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.9	Fri Feb  7 18:13:33 2020
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Wed Feb 12 18:35:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.9 2020/02/07 18:13:33 jmcneill Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.10 2020/02/12 18:35:01 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.9 2020/02/07 18:13:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.10 2020/02/12 18:35:01 jdolecek Exp $");
 
 #include 
 
@@ -266,7 +266,6 @@ pci_bus_write_config_byte(struct pci_bus
 int
 pci_enable_msi(struct pci_dev *pdev)
 {
-#ifdef notyet
 	const struct pci_attach_args *const pa = &pdev->pd_pa;
 
 	if (pci_msi_alloc_exact(pa, &pdev->pd_intr_handles, 1))
@@ -274,9 +273,6 @@ pci_enable_msi(struct pci_dev *pdev)
 
 	pdev->msi_enabled = 1;
 	return 0;
-#else
-	return -ENOSYS;
-#endif
 }
 
 void



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

2020-02-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb  3 16:22:52 UTC 2020

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

Log Message:
Re-enable PCI MSI for DRM devices


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/sys/external/bsd/drm2/linux/linux_pci.c:1.8
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.7	Sat Jan 18 02:59:42 2020
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Feb  3 16:22:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.7 2020/01/18 02:59:42 jmcneill Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.8 2020/02/03 16:22:52 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.7 2020/01/18 02:59:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.8 2020/02/03 16:22:52 jmcneill Exp $");
 
 #include 
 
@@ -266,7 +266,6 @@ pci_bus_write_config_byte(struct pci_bus
 int
 pci_enable_msi(struct pci_dev *pdev)
 {
-#ifdef notyet
 	const struct pci_attach_args *const pa = &pdev->pd_pa;
 
 	if (pci_msi_alloc_exact(pa, &pdev->pd_intr_handles, 1))
@@ -274,9 +273,6 @@ pci_enable_msi(struct pci_dev *pdev)
 
 	pdev->msi_enabled = 1;
 	return 0;
-#else
-	return -ENOSYS;
-#endif
 }
 
 void



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

2020-01-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 18 02:59:42 UTC 2020

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

Log Message:
Use pci_get_segment if available


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.6 src/sys/external/bsd/drm2/linux/linux_pci.c:1.7
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.6	Tue Aug 28 03:41:39 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Sat Jan 18 02:59:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.6 2018/08/28 03:41:39 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.7 2020/01/18 02:59:42 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -29,8 +29,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef _KERNEL_OPT
+#include "opt_pci.h"
+#endif
+
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.6 2018/08/28 03:41:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.7 2020/01/18 02:59:42 jmcneill Exp $");
 
 #include 
 
@@ -66,7 +70,12 @@ linux_pci_dev_init(struct pci_dev *pdev,
 	pdev->pd_rom_vaddr = NULL;
 	pdev->pd_dev = dev;
 #if (NACPICA > 0)
-	pdev->pd_ad = acpi_pcidev_find(0 /*XXX segment*/, pa->pa_bus,
+#ifdef __HAVE_PCI_GET_SEGMENT
+	const int seg = pci_get_segment(pa->pa_pc);
+#else
+	const int seg = 0;
+#endif
+	pdev->pd_ad = acpi_pcidev_find(seg, pa->pa_bus,
 	pa->pa_device, pa->pa_function);
 #else
 	pdev->pd_ad = NULL;



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

2019-01-05 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Jan  5 22:24:24 UTC 2019

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

Log Message:
fence_referenced_p(): mark as __diagused


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.13 src/sys/external/bsd/drm2/linux/linux_fence.c:1.14
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.13	Sat Sep  1 22:28:04 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Sat Jan  5 22:24:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.13 2018/09/01 22:28:04 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.14 2019/01/05 22:24:24 tnn Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.13 2018/09/01 22:28:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.14 2019/01/05 22:24:24 tnn Exp $");
 
 #include 
 #include 
@@ -58,7 +58,7 @@ int	linux_fence_trace = 0;
  *	True if fence has a positive reference count.  True after
  *	fence_init; after the last fence_put, this becomes false.
  */
-static inline bool
+static inline bool __diagused
 fence_referenced_p(struct fence *fence)
 {
 



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

2019-01-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Fri Jan  4 23:03:02 UTC 2019

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

Log Message:
dma_buf_fd(): fd_putfile() does not belong here

PR kern/53834 ok riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.4	Mon Aug 27 15:25:13 2018
+++ src/sys/external/bsd/drm2/linux/linux_dma_buf.c	Fri Jan  4 23:03:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_buf.c,v 1.4 2018/08/27 15:25:13 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_buf.c,v 1.5 2019/01/04 23:03:02 tnn Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.4 2018/08/27 15:25:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.5 2019/01/04 23:03:02 tnn Exp $");
 
 #include 
 #include 
@@ -119,7 +119,6 @@ dma_buf_fd(struct dma_buf *dmabuf, int f
 	fd_set_exclose(curlwp, fd, (flags & O_CLOEXEC) != 0);
 	fd_affix(curproc, file, fd);
 
-	fd_putfile(fd);
 	ret = fd;
 out0:	return ret;
 }



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

2018-09-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Sep  3 18:02:11 UTC 2018

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

Log Message:
Preserve signedness to return failure from fence_wait_timeout.

>From mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.10 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.11
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.10	Mon Aug 27 15:28:27 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Sep  3 18:02:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.10 2018/08/27 15:28:27 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.11 2018/09/03 18:02:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.10 2018/08/27 15:28:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.11 2018/09/03 18:02:11 riastradh Exp $");
 
 #include 
 #include 
@@ -711,6 +711,7 @@ reservation_object_wait_timeout_rcu(stru
 	struct reservation_object_list *list;
 	struct fence *fence;
 	uint32_t i, shared_count;
+	long ret;
 
 	if (timeout == 0)
 		return reservation_object_test_signaled_rcu(robj, shared);
@@ -792,9 +793,11 @@ wait:
 	 */
 	KASSERT(fence != NULL);
 	rcu_read_unlock();
-	timeout = fence_wait_timeout(fence, intr, timeout);
-	if (timeout <= 0)
-		return timeout;
+	ret = fence_wait_timeout(fence, intr, timeout);
+	if (ret <= 0)
+		return ret;
+	KASSERT(ret <= timeout);
+	timeout = ret;
 	goto top;
 }
 



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

2018-09-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Sep  1 22:28:04 UTC 2018

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

Log Message:
Allow fence_get(NULL).

This is kind of silly: if the caller has exclusive access to the
fence, they should be able to guarantee it's there, so this could
serve to suppress legitimate bugs.  But better to preserve Linux
semantics here than to be picky about API design.

Bug by me, fix from Tobias Ulmer in PR kern/53565.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.12 src/sys/external/bsd/drm2/linux/linux_fence.c:1.13
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.12	Tue Aug 28 15:04:02 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Sat Sep  1 22:28:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.12 2018/08/28 15:04:02 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.13 2018/09/01 22:28:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.12 2018/08/28 15:04:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.13 2018/09/01 22:28:04 riastradh Exp $");
 
 #include 
 #include 
@@ -179,7 +179,8 @@ struct fence *
 fence_get(struct fence *fence)
 {
 
-	kref_get(&fence->refcount);
+	if (fence)
+		kref_get(&fence->refcount);
 	return fence;
 }
 



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

2018-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 28 15:04:02 UTC 2018

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

Log Message:
Issue __insn_barrier after loading hardclock_ticks.

For some reason this isn't volatile...


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.11 src/sys/external/bsd/drm2/linux/linux_fence.c:1.12
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.11	Tue Aug 28 15:03:39 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Tue Aug 28 15:04:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.11 2018/08/28 15:03:39 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.12 2018/08/28 15:04:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.11 2018/08/28 15:03:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.12 2018/08/28 15:04:02 riastradh Exp $");
 
 #include 
 #include 
@@ -543,6 +543,7 @@ fence_wait_any_timeout(struct fence **fe
 	mutex_enter(&common.lock);
 	while (timeout > 0 && !common.done) {
 		start = hardclock_ticks;
+		__insn_barrier();
 		if (intr) {
 			if (timeout != MAX_SCHEDULE_TIMEOUT) {
 ret = -cv_timedwait_sig(&common.cv,
@@ -562,6 +563,7 @@ fence_wait_any_timeout(struct fence **fe
 			}
 		}
 		end = hardclock_ticks;
+		__insn_barrier();
 		if (ret)
 			break;
 		timeout -= MIN(timeout, (unsigned)end - (unsigned)start);
@@ -672,6 +674,7 @@ fence_default_wait(struct fence *fence, 
 	/* Find out what our deadline is so we can handle spurious wakeup.  */
 	if (timeout < MAX_SCHEDULE_TIMEOUT) {
 		now = hardclock_ticks;
+		__insn_barrier();
 		starttime = now;
 		deadline = starttime + timeout;
 	}
@@ -684,6 +687,7 @@ fence_default_wait(struct fence *fence, 
 		 */
 		if (timeout < MAX_SCHEDULE_TIMEOUT) {
 			now = hardclock_ticks;
+			__insn_barrier();
 			if (deadline <= now)
 break;
 		}



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

2018-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 28 15:03:39 UTC 2018

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

Log Message:
Assert EWOULDBLOCK happens only with timeout.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.10 src/sys/external/bsd/drm2/linux/linux_fence.c:1.11
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.10	Tue Aug 28 14:23:02 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Tue Aug 28 15:03:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.10 2018/08/28 14:23:02 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.11 2018/08/28 15:03:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.10 2018/08/28 14:23:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.11 2018/08/28 15:03:39 riastradh Exp $");
 
 #include 
 #include 
@@ -713,8 +713,11 @@ out:
 	spin_unlock(fence->lock);
 
 	/* If cv_timedwait gave up, return 0 meaning timeout.  */
-	if (ret == -EWOULDBLOCK)
+	if (ret == -EWOULDBLOCK) {
+		/* Only cv_timedwait and cv_timedwait_sig can return this.  */
+		KASSERT(timeout < MAX_SCHEDULE_TIMEOUT);
 		return 0;
+	}
 
 	/* If there was a timeout and the deadline passed, return 0.  */
 	if (timeout < MAX_SCHEDULE_TIMEOUT) {



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

2018-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 28 14:23:03 UTC 2018

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

Log Message:
With no timeout, fence_default_wait must return 1 on success, never 0.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.9 src/sys/external/bsd/drm2/linux/linux_fence.c:1.10
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.9	Mon Aug 27 14:40:44 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Tue Aug 28 14:23:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.9 2018/08/27 14:40:44 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.10 2018/08/28 14:23:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.9 2018/08/27 14:40:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.10 2018/08/28 14:23:02 riastradh Exp $");
 
 #include 
 #include 
@@ -641,7 +641,7 @@ fence_wait(struct fence *fence, bool int
  *
  *	Default implementation of fence wait callback using a condition
  *	variable.  If the fence is already signalled, return timeout,
- *	or 0 if no timeout.  If the enable signalling callback hasn't
+ *	or 1 if no timeout.  If the enable signalling callback hasn't
  *	been called, call it, and if it fails, act as if the fence had
  *	been signalled.  Otherwise, wait on the internal condvar.  If
  *	timeout is MAX_SCHEDULE_TIMEOUT, treat it as no timeout.
@@ -659,7 +659,7 @@ fence_default_wait(struct fence *fence, 
 
 	/* Optimistically try to skip the lock if it's already signalled.  */
 	if (fence->flags & (1u << FENCE_FLAG_SIGNALED_BIT))
-		return (timeout < MAX_SCHEDULE_TIMEOUT ? timeout : 0);
+		return (timeout < MAX_SCHEDULE_TIMEOUT ? timeout : 1);
 
 	/* Acquire the lock.  */
 	spin_lock(fence->lock);
@@ -731,8 +731,8 @@ out:
 		return ret;
 
 	/*
-	 * Success!  Return the number of ticks left, at least 1, or 0
+	 * Success!  Return the number of ticks left, at least 1, or 1
 	 * if no timeout.
 	 */
-	return (timeout < MAX_SCHEDULE_TIMEOUT ? MIN(deadline - now, 1) : 0);
+	return (timeout < MAX_SCHEDULE_TIMEOUT ? MIN(deadline - now, 1) : 1);
 }



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:28:53 UTC 2018

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

Log Message:
Ifdef out label used only by !__HAVE_MM_MD_DIRECT_MAPPED_PHYS.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.15 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.16
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.15	Mon Aug 27 15:13:17 2018
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Mon Aug 27 15:28:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.15 2018/08/27 15:13:17 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.16 2018/08/27 15:28:53 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.15 2018/08/27 15:13:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.16 2018/08/27 15:28:53 riastradh Exp $");
 
 #include 
 #include 
@@ -166,7 +166,10 @@ kmap_atomic(struct page *page)
 	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
-out:	SDT_PROBE2(sdt, linux, kmap, map__atomic,  paddr, vaddr);
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+out:
+#endif
+	SDT_PROBE2(sdt, linux, kmap, map__atomic,  paddr, vaddr);
 	return (void *)vaddr;
 }
 
@@ -231,7 +234,10 @@ kmap(struct page *page)
 	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
-out:	SDT_PROBE2(sdt, linux, kmap, map,  paddr, vaddr);
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+out:
+#endif
+	SDT_PROBE2(sdt, linux, kmap, map,  paddr, vaddr);
 	return (void *)vaddr;
 }
 
@@ -265,5 +271,8 @@ kunmap(struct page *page)
 
 	uvm_km_free(kernel_map, vaddr, PAGE_SIZE, UVM_KMF_VAONLY);
 
-out:	SDT_PROBE2(sdt, linux, kmap, unmap,  paddr, vaddr);
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+out:
+#endif
+	SDT_PROBE2(sdt, linux, kmap, unmap,  paddr, vaddr);
 }



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:28:27 UTC 2018

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

Log Message:
Expand docstring for reservation_object_poll.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.9 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.10
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.9	Mon Aug 27 15:28:16 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 15:28:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.9 2018/08/27 15:28:16 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.10 2018/08/27 15:28:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.9 2018/08/27 15:28:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.10 2018/08/27 15:28:27 riastradh Exp $");
 
 #include 
 #include 
@@ -851,8 +851,15 @@ reservation_poll_cb(struct fence *fence,
 /*
  * reservation_object_poll(robj, events, rpoll)
  *
- *	POLLOUT		wait for all fences shared and exclusive
- *	POLLIN		wait for the exclusive fence
+ *	Poll for reservation object events using the reservation poll
+ *	state in rpoll:
+ *
+ *	- POLLOUT	wait for all fences shared and exclusive
+ *	- POLLIN	wait for the exclusive fence
+ *
+ *	Return the subset of events in events that are ready.  If any
+ *	are requested but not ready, arrange to be notified with
+ *	selnotify when they are.
  */
 int
 reservation_object_poll(struct reservation_object *robj, int events,



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:28:16 UTC 2018

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

Log Message:
Let's try not to step on each others' toes, shall we?


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.8 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.9
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.8	Mon Aug 27 15:25:14 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 15:28:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.8 2018/08/27 15:25:14 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.9 2018/08/27 15:28:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.8 2018/08/27 15:25:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.9 2018/08/27 15:28:16 riastradh Exp $");
 
 #include 
 #include 
@@ -1035,7 +1035,7 @@ record:
 	rcu_read_unlock();
 	mutex_enter(&rpoll->rp_lock);
 	selrecord(curlwp, &rpoll->rp_selq);
-	if (rpoll->rp_claimed)
+	if (!rpoll->rp_claimed)
 		claimed = rpoll->rp_claimed = true;
 	mutex_exit(&rpoll->rp_lock);
 	recorded = true;



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:24:53 UTC 2018

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

Log Message:
sdt probe naming style.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/linux/linux_idr.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_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.11 src/sys/external/bsd/drm2/linux/linux_idr.c:1.12
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.11	Mon Aug 27 15:07:29 2018
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Mon Aug 27 15:24:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.11 2018/08/27 15:07:29 riastradh Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.12 2018/08/27 15:24:53 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.11 2018/08/27 15:07:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.12 2018/08/27 15:24:53 riastradh Exp $");
 
 #include 
 #include 
@@ -68,7 +68,7 @@ SDT_PROBE_DEFINE4(sdt, linux, idr, repla
 SDT_PROBE_DEFINE3(sdt, linux, idr, remove,
 "struct idr *"/*idr*/, "int"/*id*/, "void *"/*data*/);
 SDT_PROBE_DEFINE0(sdt, linux, idr, preload);
-SDT_PROBE_DEFINE0(sdt, linux, idr, preload_end);
+SDT_PROBE_DEFINE0(sdt, linux, idr, preload__end);
 SDT_PROBE_DEFINE3(sdt, linux, idr, alloc,
 "struct idr *"/*idr*/, "int"/*id*/, "void *"/*data*/);
 
@@ -374,7 +374,7 @@ idr_preload_end(void)
 {
 	struct idr_cache *cache;
 
-	SDT_PROBE0(sdt, linux, idr, preload_end);
+	SDT_PROBE0(sdt, linux, idr, preload__end);
 
 	/* Get the cache, or bail if it's not there.  */
 	cache = lwp_getspecific(idr_cache_key);



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:24:40 UTC 2018

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

Log Message:
Simplify.  Destroy the mutex too.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.2	Mon Aug 27 15:24:11 2018
+++ src/sys/external/bsd/drm2/linux/linux_dma_buf.c	Mon Aug 27 15:24:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_buf.c,v 1.2 2018/08/27 15:24:11 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_buf.c,v 1.3 2018/08/27 15:24:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.2 2018/08/27 15:24:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.3 2018/08/27 15:24:40 riastradh Exp $");
 
 #include 
 #include 
@@ -167,9 +167,9 @@ dma_buf_put(struct dma_buf *dmabuf)
 	if (atomic_dec_uint_nv(&dmabuf->db_refcnt) != 0)
 		return;
 
-	if (dmabuf->resv == &dmabuf->db_resv_int[0])
-		reservation_object_fini(dmabuf->resv);
+	mutex_destroy(&dmabuf->db_lock);
 	if (dmabuf->resv == &dmabuf->db_resv_int[0]) {
+		reservation_object_fini(dmabuf->resv);
 		kmem_free(dmabuf, offsetof(struct dma_buf, db_resv_int[1]));
 	} else {
 		kmem_free(dmabuf, sizeof(*dmabuf));



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:24:11 UTC 2018

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

Log Message:
Return the fd we just allocated.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.2
--- src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.1	Mon Aug 27 15:22:54 2018
+++ src/sys/external/bsd/drm2/linux/linux_dma_buf.c	Mon Aug 27 15:24:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_buf.c,v 1.1 2018/08/27 15:22:54 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_buf.c,v 1.2 2018/08/27 15:24:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.1 2018/08/27 15:22:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.2 2018/08/27 15:24:11 riastradh Exp $");
 
 #include 
 #include 
@@ -119,6 +119,7 @@ dma_buf_fd(struct dma_buf *dmabuf, int f
 	fd_affix(curproc, file, fd);
 
 	fd_putfile(fd);
+	ret = fd;
 out0:	return ret;
 }
 



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:12:21 UTC 2018

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

Log Message:
Try agp_i810_borrow only if CONFIG_AGP is enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/external/bsd/drm2/linux/linux_pci.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.4	Mon Aug 27 14:19:59 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Aug 27 15:12:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.4 2018/08/27 14:19:59 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.5 2018/08/27 15:12:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,10 +30,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.4 2018/08/27 14:19:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.5 2018/08/27 15:12:21 riastradh Exp $");
 
 #include 
 
+#include 
+
 device_t
 pci_dev_dev(struct pci_dev *pdev)
 {
@@ -606,10 +608,14 @@ pci_iomap(struct pci_dev *pdev, unsigned
 	size, BUS_SPACE_MAP_LINEAR | pdev->pd_resources[i].flags,
 	&pdev->pd_resources[i].bsh);
 	if (error) {
+#ifdef CONFIG_AGP
 		/* Horrible hack: try asking the fake AGP device.  */
 		if (!agp_i810_borrow(pdev->pd_resources[i].addr, size,
 			&pdev->pd_resources[i].bsh))
 			return NULL;
+#else
+		return NULL;
+#endif
 	}
 	pdev->pd_resources[i].bst = pdev->pd_pa.pa_memt;
 	pdev->pd_resources[i].kva = bus_space_vaddr(pdev->pd_resources[i].bst,



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:09:59 UTC 2018

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

Log Message:
Work around a namespacing clash between dtrace and linux symbol.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.13 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.14
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.13	Mon Aug 27 15:07:11 2018
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Mon Aug 27 15:09:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.13 2018/08/27 15:07:11 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.14 2018/08/27 15:09:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.13 2018/08/27 15:07:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.14 2018/08/27 15:09:58 riastradh Exp $");
 
 #include 
 #include 
@@ -46,6 +46,8 @@ __KERNEL_RCSID(0, "$NetBSD: linux_kmap.c
 
 #include 
 
+#undef	linux_kmap		/* symbol vs trace point namespace clash */
+
 SDT_PROBE_DEFINE2(sdt, linux, kmap, map,
 "paddr_t"/*paddr*/, "vaddr_t"/*vaddr*/);
 SDT_PROBE_DEFINE2(sdt, linux, kmap, unmap,
@@ -200,7 +202,7 @@ kunmap_atomic(void *addr)
 }
 
 void *
-kmap(struct page *page)
+linux_kmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
 	vaddr_t vaddr;



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:07:12 UTC 2018

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

Log Message:
sdt dtrace probes for linux kmap.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.12 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.13
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.12	Thu Jan  1 01:15:43 2015
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Mon Aug 27 15:07:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.12 2015/01/01 01:15:43 mrg Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.13 2018/08/27 15:07:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.12 2015/01/01 01:15:43 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.13 2018/08/27 15:07:11 riastradh Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 #include 
@@ -45,6 +46,15 @@ __KERNEL_RCSID(0, "$NetBSD: linux_kmap.c
 
 #include 
 
+SDT_PROBE_DEFINE2(sdt, linux, kmap, map,
+"paddr_t"/*paddr*/, "vaddr_t"/*vaddr*/);
+SDT_PROBE_DEFINE2(sdt, linux, kmap, unmap,
+"paddr_t"/*paddr*/, "vaddr_t"/*vaddr*/);
+SDT_PROBE_DEFINE2(sdt, linux, kmap, map__atomic,
+"paddr_t"/*paddr*/, "vaddr_t"/*vaddr*/);
+SDT_PROBE_DEFINE2(sdt, linux, kmap, unmap__atomic,
+"paddr_t"/*paddr*/, "vaddr_t"/*vaddr*/);
+
 /*
  * XXX Kludgerific implementation of Linux kmap_atomic, which is
  * required not to fail.  To accomodate this, we reserve one page of
@@ -146,7 +156,7 @@ kmap_atomic(struct page *page)
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 	if (mm_md_direct_mapped_phys(paddr, &vaddr))
-		return (void *)vaddr;
+		goto out;
 #endif
 
 	mutex_spin_enter(&linux_kmap_atomic_lock);
@@ -156,6 +166,7 @@ kmap_atomic(struct page *page)
 	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
+out:	SDT_PROBE2(sdt, linux, kmap, map__atomic,  paddr, vaddr);
 	return (void *)vaddr;
 }
 
@@ -163,15 +174,17 @@ void
 kunmap_atomic(void *addr)
 {
 	const vaddr_t vaddr = (vaddr_t)addr;
-
-#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
-{
 	paddr_t paddr;
-	vaddr_t vaddr1;
 	bool ok __diagused;
 
 	ok = pmap_extract(pmap_kernel(), vaddr, &paddr);
 	KASSERT(ok);
+
+	SDT_PROBE2(sdt, linux, kmap, unmap__atomic,  paddr, vaddr);
+
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+{
+	vaddr_t vaddr1;
 	if (mm_md_direct_mapped_phys(paddr, &vaddr1) && vaddr1 == vaddr)
 		return;
 }
@@ -179,7 +192,6 @@ kunmap_atomic(void *addr)
 
 	KASSERT(mutex_owned(&linux_kmap_atomic_lock));
 	KASSERT(linux_kmap_atomic_vaddr == vaddr);
-	KASSERT(pmap_extract(pmap_kernel(), vaddr, NULL));
 
 	pmap_kremove(vaddr, PAGE_SIZE);
 	pmap_update(pmap_kernel());
@@ -197,7 +209,7 @@ kmap(struct page *page)
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 	if (mm_md_direct_mapped_phys(paddr, &vaddr))
-		return (void *)vaddr;
+		goto out;
 #endif
 
 	vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
@@ -219,6 +231,7 @@ kmap(struct page *page)
 	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
+out:	SDT_PROBE2(sdt, linux, kmap, map,  paddr, vaddr);
 	return (void *)vaddr;
 }
 
@@ -226,16 +239,13 @@ void
 kunmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
+	vaddr_t vaddr;
 
 	ASSERT_SLEEPABLE();
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
-{
-	vaddr_t vaddr1;
-
-	if (mm_md_direct_mapped_phys(paddr, &vaddr1))
-		return;
-}
+	if (mm_md_direct_mapped_phys(paddr, &vaddr))
+		goto out;
 #endif
 
 	mutex_enter(&linux_kmap_lock);
@@ -245,7 +255,7 @@ kunmap(struct page *page)
 	rb_tree_remove_node(&linux_kmap_entries, lke);
 	mutex_exit(&linux_kmap_lock);
 
-	const vaddr_t vaddr = lke->lke_vaddr;
+	vaddr = lke->lke_vaddr;
 	kmem_free(lke, sizeof(*lke));
 
 	KASSERT(pmap_extract(pmap_kernel(), vaddr, NULL));
@@ -254,4 +264,6 @@ kunmap(struct page *page)
 	pmap_update(pmap_kernel());
 
 	uvm_km_free(kernel_map, vaddr, PAGE_SIZE, UVM_KMF_VAONLY);
+
+out:	SDT_PROBE2(sdt, linux, kmap, unmap,  paddr, vaddr);
 }



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:07:29 UTC 2018

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

Log Message:
Work around broken empty expansion of SDT_PROBE* if !KDTRACE_HOOKS.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/linux/linux_idr.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_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.10 src/sys/external/bsd/drm2/linux/linux_idr.c:1.11
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.10	Mon Aug 27 15:06:54 2018
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Mon Aug 27 15:07:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.10 2018/08/27 15:06:54 riastradh Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.11 2018/08/27 15:07:29 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.10 2018/08/27 15:06:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.11 2018/08/27 15:07:29 riastradh Exp $");
 
 #include 
 #include 
@@ -361,10 +361,11 @@ idr_alloc(struct idr *idr, void *data, i
 out:	mutex_spin_exit(&idr->idr_lock);
 
 	/* Discard the node on failure.  */
-	if (id < 0)
+	if (id < 0) {
 		cache->ic_node = node;
-	else
+	} else {
 		SDT_PROBE3(sdt, linux, idr, alloc,  idr, id, data);
+	}
 	return id;
 }
 



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:07:59 UTC 2018

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

Log Message:
dtrace sdt probes for linux rcu.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_rcu.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_rcu.c
diff -u src/sys/external/bsd/drm2/linux/linux_rcu.c:1.3 src/sys/external/bsd/drm2/linux/linux_rcu.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_rcu.c:1.3	Mon Aug 27 14:14:54 2018
+++ src/sys/external/bsd/drm2/linux/linux_rcu.c	Mon Aug 27 15:07:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.3 2018/08/27 14:14:54 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.4 2018/08/27 15:07:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,16 +30,28 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.3 2018/08/27 14:14:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.4 2018/08/27 15:07:59 riastradh Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
 
+SDT_PROBE_DEFINE0(sdt, linux, rcu, synchronize__start);
+SDT_PROBE_DEFINE1(sdt, linux, rcu, synchronize__cpu, "unsigned"/*cpu*/);
+SDT_PROBE_DEFINE0(sdt, linux, rcu, synchronize__done);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__queue,
+"struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__run,
+"struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__done,
+"struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+
 static struct {
 	kmutex_t	lock;
 	kcondvar_t	cv;
@@ -49,15 +61,19 @@ static struct {
 } gc __cacheline_aligned;
 
 static void
-rcu_xc(void *a, void *b)
+synchronize_rcu_xc(void *a, void *b)
 {
+
+	SDT_PROBE1(sdt, linux, rcu, synchronize__cpu,  cpu_index(curcpu()));
 }
 
 void
 synchronize_rcu(void)
 {
 
-	xc_wait(xc_broadcast(0, &rcu_xc, NULL, NULL));
+	SDT_PROBE0(sdt, linux, rcu, synchronize__start);
+	xc_wait(xc_broadcast(0, &synchronize_rcu_xc, NULL, NULL));
+	SDT_PROBE0(sdt, linux, rcu, synchronize__done);
 }
 
 void
@@ -70,6 +86,7 @@ call_rcu(struct rcu_head *head, void (*c
 	head->rcuh_next = gc.first;
 	gc.first = head;
 	cv_signal(&gc.cv);
+	SDT_PROBE2(sdt, linux, rcu, call__queue,  head, callback);
 	mutex_exit(&gc.lock);
 }
 
@@ -77,6 +94,7 @@ static void
 gc_thread(void *cookie)
 {
 	struct rcu_head *head, *next;
+	void (*callback)(struct rcu_head *);
 
 	mutex_enter(&gc.lock);
 	for (;;) {
@@ -95,7 +113,16 @@ gc_thread(void *cookie)
 			/* It is now safe to call the callbacks.  */
 			for (; head != NULL; head = next) {
 next = head->rcuh_next;
-(*head->rcuh_callback)(head);
+callback = head->rcuh_callback;
+SDT_PROBE2(sdt, linux, rcu, call__run,
+head, callback);
+(*callback)(head);
+/*
+ * Can't dereference head or invoke
+ * callback after this point.
+ */
+SDT_PROBE2(sdt, linux, rcu, call__done,
+head, callback);
 			}
 
 			mutex_enter(&gc.lock);



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 15:06:54 UTC 2018

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

Log Message:
sdt dtrace probes for linux idr.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/linux/linux_idr.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_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.9 src/sys/external/bsd/drm2/linux/linux_idr.c:1.10
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.9	Mon Aug 27 14:15:45 2018
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Mon Aug 27 15:06:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.9 2018/08/27 14:15:45 riastradh Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.10 2018/08/27 15:06:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,11 +30,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.9 2018/08/27 14:15:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.10 2018/08/27 15:06:54 riastradh Exp $");
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -59,6 +60,18 @@ struct idr_cache {
 	void			*ic_where;
 };
 
+SDT_PROBE_DEFINE0(sdt, linux, idr, leak);
+SDT_PROBE_DEFINE1(sdt, linux, idr, init, "struct idr *"/*idr*/);
+SDT_PROBE_DEFINE1(sdt, linux, idr, destroy, "struct idr *"/*idr*/);
+SDT_PROBE_DEFINE4(sdt, linux, idr, replace,
+"struct idr *"/*idr*/, "int"/*id*/, "void *"/*odata*/, "void *"/*ndata*/);
+SDT_PROBE_DEFINE3(sdt, linux, idr, remove,
+"struct idr *"/*idr*/, "int"/*id*/, "void *"/*data*/);
+SDT_PROBE_DEFINE0(sdt, linux, idr, preload);
+SDT_PROBE_DEFINE0(sdt, linux, idr, preload_end);
+SDT_PROBE_DEFINE3(sdt, linux, idr, alloc,
+"struct idr *"/*idr*/, "int"/*id*/, "void *"/*data*/);
+
 static specificdata_key_t idr_cache_key __read_mostly;
 
 static void
@@ -92,6 +105,7 @@ idr_cache_dtor(void *cookie)
 	struct idr_cache *cache = cookie;
 
 	if (cache->ic_node) {
+		SDT_PROBE0(sdt, linux, idr, leak);
 		idr_cache_warning(cache);
 		kmem_free(cache->ic_node, sizeof(*cache->ic_node));
 	}
@@ -161,12 +175,14 @@ idr_init(struct idr *idr)
 
 	mutex_init(&idr->idr_lock, MUTEX_DEFAULT, IPL_VM);
 	rb_tree_init(&idr->idr_tree, &idr_rb_ops);
+	SDT_PROBE1(sdt, linux, idr, init,  idr);
 }
 
 void
 idr_destroy(struct idr *idr)
 {
 
+	SDT_PROBE1(sdt, linux, idr, destroy,  idr);
 #if 0/* XXX No rb_tree_destroy?  */
 	rb_tree_destroy(&idr->idr_tree);
 #endif
@@ -226,6 +242,8 @@ idr_replace(struct idr *idr, void *repla
 	} else {
 		result = node->in_data;
 		node->in_data = replacement;
+		SDT_PROBE4(sdt, linux, idr, replace,
+		idr, id, result, replacement);
 	}
 	mutex_spin_exit(&idr->idr_lock);
 
@@ -240,6 +258,7 @@ idr_remove(struct idr *idr, int id)
 	mutex_spin_enter(&idr->idr_lock);
 	node = rb_tree_find_node(&idr->idr_tree, &id);
 	KASSERTMSG((node != NULL), "idr %p has no entry for id %d", idr, id);
+	SDT_PROBE3(sdt, linux, idr, remove,  idr, id, node->in_data);
 	rb_tree_remove_node(&idr->idr_tree, node);
 	mutex_spin_exit(&idr->idr_lock);
 
@@ -253,6 +272,8 @@ idr_preload(gfp_t gfp)
 	struct idr_node *node;
 	km_flag_t kmflag = ISSET(gfp, __GFP_WAIT) ? KM_SLEEP : KM_NOSLEEP;
 
+	SDT_PROBE0(sdt, linux, idr, preload);
+
 	/* If caller asked to wait, we had better be sleepable.  */
 	if (ISSET(gfp, __GFP_WAIT))
 		ASSERT_SLEEPABLE();
@@ -342,6 +363,8 @@ out:	mutex_spin_exit(&idr->idr_lock);
 	/* Discard the node on failure.  */
 	if (id < 0)
 		cache->ic_node = node;
+	else
+		SDT_PROBE3(sdt, linux, idr, alloc,  idr, id, data);
 	return id;
 }
 
@@ -350,6 +373,8 @@ idr_preload_end(void)
 {
 	struct idr_cache *cache;
 
+	SDT_PROBE0(sdt, linux, idr, preload_end);
+
 	/* Get the cache, or bail if it's not there.  */
 	cache = lwp_getspecific(idr_cache_key);
 	if (cache == NULL)



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:42:23 UTC 2018

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

Log Message:
KASSERT -> KASSERTMSG


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/linux/linux_writecomb.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_writecomb.c
diff -u src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.7 src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.8
--- src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.7	Mon Aug 27 06:49:52 2018
+++ src/sys/external/bsd/drm2/linux/linux_writecomb.c	Mon Aug 27 14:42:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_writecomb.c,v 1.7 2018/08/27 06:49:52 riastradh Exp $	*/
+/*	$NetBSD: linux_writecomb.c,v 1.8 2018/08/27 14:42:23 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.7 2018/08/27 06:49:52 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.8 2018/08/27 14:42:23 riastradh Exp $");
 
 #if defined(__i386__) || defined(__x86_64__)
 #define HAS_MTRR 1
@@ -112,8 +112,8 @@ fail1:	KASSERT(id < 0);
 	mtrr->flags = 0;
 	/* XXX errno NetBSD->Linux */
 	ret = -mtrr_set(mtrr, &n, NULL, MTRR_GETSET_KERNEL);
-	KASSERT(ret == 0);
-	KASSERT(n == 1);
+	KASSERTMSG(ret == 0, "mtrr_set failed to delete: %d", -ret);
+	KASSERTMSG(n == 1, "mtrr_set returned wrong number: %d", n);
 	ret = id;
 fail0:	KASSERT(ret < 0);
 	kmem_free(mtrr, sizeof(*mtrr));
@@ -143,8 +143,8 @@ arch_phys_wc_del(int id)
 		mtrr->flags = 0;
 		/* XXX errno NetBSD->Linux */
 		ret = -mtrr_set(mtrr, &n, NULL, MTRR_GETSET_KERNEL);
-		KASSERT(ret == 0);
-		KASSERT(n == 1);
+		KASSERTMSG(ret == 0, "mtrr_set failed to delete: %d", -ret);
+		KASSERTMSG(n == 1, "mtrr_set returned wrong number: %d", n);
 		kmem_free(mtrr, sizeof(*mtrr));
 	}
 #endif



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:40:44 UTC 2018

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

Log Message:
KASSERT -> KASSERTMSG, to help debug panic observed by mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.8 src/sys/external/bsd/drm2/linux/linux_fence.c:1.9
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.8	Mon Aug 27 14:40:13 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Mon Aug 27 14:40:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.8 2018/08/27 14:40:13 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.9 2018/08/27 14:40:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.8 2018/08/27 14:40:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.9 2018/08/27 14:40:44 riastradh Exp $");
 
 #include 
 #include 
@@ -654,8 +654,8 @@ fence_default_wait(struct fence *fence, 
 	long ret = 0;
 
 	KASSERT(fence_referenced_p(fence));
-	KASSERT(timeout >= 0);
-	KASSERT(timeout <= MAX_SCHEDULE_TIMEOUT);
+	KASSERTMSG(timeout >= 0, "timeout %ld", timeout);
+	KASSERTMSG(timeout <= MAX_SCHEDULE_TIMEOUT, "timeout %ld", timeout);
 
 	/* Optimistically try to skip the lock if it's already signalled.  */
 	if (fence->flags & (1u << FENCE_FLAG_SIGNALED_BIT))



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:40:13 UTC 2018

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

Log Message:
Linux fence_put accepts NULL as noop.  Match this.

>From mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.7 src/sys/external/bsd/drm2/linux/linux_fence.c:1.8
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.7	Mon Aug 27 14:20:41 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Mon Aug 27 14:40:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.7 2018/08/27 14:20:41 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.8 2018/08/27 14:40:13 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.7 2018/08/27 14:20:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.8 2018/08/27 14:40:13 riastradh Exp $");
 
 #include 
 #include 
@@ -222,6 +222,8 @@ void
 fence_put(struct fence *fence)
 {
 
+	if (fence == NULL)
+		return;
 	KASSERT(fence_referenced_p(fence));
 	kref_put(&fence->refcount, &fence_release);
 }



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:19:59 UTC 2018

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

Log Message:
Treat pre-enabled devices as 1 enablecnt.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 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.3 src/sys/external/bsd/drm2/linux/linux_pci.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.3	Mon Aug 27 14:17:04 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Aug 27 14:19:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.3 2018/08/27 14:17:04 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.4 2018/08/27 14:19:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.3 2018/08/27 14:17:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.4 2018/08/27 14:19:59 riastradh Exp $");
 
 #include 
 
@@ -711,6 +711,9 @@ linux_pci_enable_device(struct pci_dev *
 
 	s = splhigh();
 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
+	/* If someone else (firmware) already enabled it, credit them.  */
+	if (csr & (PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE))
+		pdev->pd_enablecnt++;
 	csr |= PCI_COMMAND_IO_ENABLE;
 	csr |= PCI_COMMAND_MEM_ENABLE;
 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, csr);



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:17:05 UTC 2018

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

Log Message:
Zero the whole thing for good measure.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/external/bsd/drm2/linux/linux_pci.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.2	Mon Aug 27 14:16:52 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Aug 27 14:17:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.2 2018/08/27 14:16:52 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.3 2018/08/27 14:17:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.2 2018/08/27 14:16:52 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.3 2018/08/27 14:17:04 riastradh Exp $");
 
 #include 
 
@@ -57,6 +57,8 @@ linux_pci_dev_init(struct pci_dev *pdev,
 	PCI_SUBSYS_ID_REG);
 	unsigned i;
 
+	memset(pdev, 0, sizeof(*pdev)); /* paranoia */
+
 	pdev->pd_pa = *pa;
 	pdev->pd_kludges = kludges;
 	pdev->pd_rom_vaddr = NULL;



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:16:52 UTC 2018

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

Log Message:
Make sure the resources are marked unmapped initially.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 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.1 src/sys/external/bsd/drm2/linux/linux_pci.c:1.2
--- src/sys/external/bsd/drm2/linux/linux_pci.c:1.1	Mon Aug 27 14:16:38 2018
+++ src/sys/external/bsd/drm2/linux/linux_pci.c	Mon Aug 27 14:16:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_pci.c,v 1.1 2018/08/27 14:16:38 riastradh Exp $	*/
+/*	$NetBSD: linux_pci.c,v 1.2 2018/08/27 14:16:52 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.1 2018/08/27 14:16:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pci.c,v 1.2 2018/08/27 14:16:52 riastradh Exp $");
 
 #include 
 
@@ -97,6 +97,7 @@ linux_pci_dev_init(struct pci_dev *pdev,
 			pdev->pd_resources[i].flags = 0;
 		}
 		pdev->pd_resources[i].kva = NULL;
+		pdev->pd_resources[i].mapped = false;
 	}
 }
 



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:15:46 UTC 2018

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

Log Message:
Zero-initialize idr cache.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/linux/linux_idr.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_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.8 src/sys/external/bsd/drm2/linux/linux_idr.c:1.9
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.8	Mon Aug 27 14:14:42 2018
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Mon Aug 27 14:15:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.8 2018/08/27 14:14:42 riastradh Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.9 2018/08/27 14:15:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.8 2018/08/27 14:14:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.9 2018/08/27 14:15:45 riastradh Exp $");
 
 #include 
 #include 
@@ -265,7 +265,7 @@ idr_preload(gfp_t gfp)
 		/* lwp_setspecific must be sleepable.  */
 		if (!ISSET(gfp, __GFP_WAIT))
 			return;
-		cache = kmem_alloc(sizeof(*cache), kmflag);
+		cache = kmem_zalloc(sizeof(*cache), kmflag);
 		if (cache == NULL)
 			return;
 		lwp_setspecific(idr_cache_key, cache);



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:14:54 UTC 2018

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

Log Message:
Make gc static.  No need to use this private state elsewhere.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_rcu.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_rcu.c
diff -u src/sys/external/bsd/drm2/linux/linux_rcu.c:1.2 src/sys/external/bsd/drm2/linux/linux_rcu.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_rcu.c:1.2	Mon Aug 27 13:39:48 2018
+++ src/sys/external/bsd/drm2/linux/linux_rcu.c	Mon Aug 27 14:14:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.2 2018/08/27 13:39:48 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.3 2018/08/27 14:14:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.2 2018/08/27 13:39:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.3 2018/08/27 14:14:54 riastradh Exp $");
 
 #include 
 #include 
@@ -40,7 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,
 
 #include 
 
-struct {
+static struct {
 	kmutex_t	lock;
 	kcondvar_t	cv;
 	struct rcu_head	*first;



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:13:46 UTC 2018

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

Log Message:
There may not be an old list.

Nihil ex nihilo -- don't dereference null.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.5 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.5	Mon Aug 27 14:13:00 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 14:13:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $");
 
 #include 
 #include 
@@ -411,13 +411,15 @@ reservation_object_add_shared_fence(stru
 		/* Commit the update.  */
 		reservation_object_write_commit(robj, &ticket);
 	} else {
-		KASSERT(list->shared_count < prealloc->shared_max);
+		uint32_t shared_count = (list == NULL? 0 : list->shared_count);
+
+		KASSERT(shared_count < prealloc->shared_max);
 
 		/*
 		 * Copy the fences over, but replace if we find one
 		 * with the same context number.
 		 */
-		for (i = 0; i < list->shared_count; i++) {
+		for (i = 0; i < shared_count; i++) {
 			if (replace == NULL &&
 			list->shared[i]->context == fence->context) {
 replace = list->shared[i];
@@ -426,7 +428,7 @@ reservation_object_add_shared_fence(stru
 prealloc->shared[i] = list->shared[i];
 			}
 		}
-		prealloc->shared_count = list->shared_count;
+		prealloc->shared_count = shared_count;
 
 		/* If we didn't find one, add it at the end.  */
 		if (replace == NULL)
@@ -443,11 +445,12 @@ reservation_object_add_shared_fence(stru
 		reservation_object_write_commit(robj, &ticket);
 
 		/*
-		 * Free the old list when it is convenient.  (We are
-		 * not in a position at this point to sleep waiting for
-		 * activity on all CPUs.)
+		 * If there is an old list, free it when convenient.
+		 * (We are not in a position at this point to sleep
+		 * waiting for activity on all CPUs.)
 		 */
-		objlist_defer_free(list);
+		if (list != NULL)
+			objlist_defer_free(list);
 	}
 
 	/* Release a fence if we replaced it.  */



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:13:16 UTC 2018

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

Log Message:
Lotsa kasserts about referencedness of frences.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.5 src/sys/external/bsd/drm2/linux/linux_fence.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.5	Mon Aug 27 14:01:01 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Mon Aug 27 14:13:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.5 2018/08/27 14:01:01 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.6 2018/08/27 14:13:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.5 2018/08/27 14:01:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.6 2018/08/27 14:13:16 riastradh Exp $");
 
 #include 
 #include 
@@ -44,6 +44,19 @@ __KERNEL_RCSID(0, "$NetBSD: linux_fence.
 #include 
 
 /*
+ * fence_referenced_p(fence)
+ *
+ *	True if fence has a positive reference count.  True after
+ *	fence_init; after the last fence_put, this becomes false.
+ */
+static inline bool
+fence_referenced_p(struct fence *fence)
+{
+
+	return kref_referenced_p(&fence->refcount);
+}
+
+/*
  * fence_init(fence, ops, lock, context, seqno)
  *
  *	Initialize fence.  Caller should call fence_destroy when done,
@@ -74,6 +87,8 @@ void
 fence_destroy(struct fence *fence)
 {
 
+	KASSERT(!fence_referenced_p(fence));
+
 	KASSERT(TAILQ_EMPTY(&fence->f_callbacks));
 	cv_destroy(&fence->f_cv);
 }
@@ -83,6 +98,8 @@ fence_free_cb(struct rcu_head *rcu)
 {
 	struct fence *fence = container_of(rcu, struct fence, f_rcu);
 
+	KASSERT(!fence_referenced_p(fence));
+
 	fence_destroy(fence);
 	kfree(fence);
 }
@@ -103,6 +120,8 @@ void
 fence_free(struct fence *fence)
 {
 
+	KASSERT(!fence_referenced_p(fence));
+
 	call_rcu(&fence->f_rcu, &fence_free_cb);
 }
 
@@ -176,6 +195,8 @@ fence_release(struct kref *refcount)
 {
 	struct fence *fence = container_of(refcount, struct fence, refcount);
 
+	KASSERT(!fence_referenced_p(fence));
+
 	if (fence->ops->release)
 		(*fence->ops->release)(fence);
 	else
@@ -192,6 +213,7 @@ void
 fence_put(struct fence *fence)
 {
 
+	KASSERT(fence_referenced_p(fence));
 	kref_put(&fence->refcount, &fence_release);
 }
 
@@ -210,6 +232,7 @@ static int
 fence_ensure_signal_enabled(struct fence *fence)
 {
 
+	KASSERT(fence_referenced_p(fence));
 	KASSERT(spin_is_locked(fence->lock));
 
 	/* If the fence was already signalled, fail with -ENOENT.  */
@@ -251,6 +274,8 @@ fence_add_callback(struct fence *fence, 
 {
 	int ret;
 
+	KASSERT(fence_referenced_p(fence));
+
 	/* Optimistically try to skip the lock if it's already signalled.  */
 	if (fence->flags & (1u << FENCE_FLAG_SIGNALED_BIT)) {
 		ret = -ENOENT;
@@ -288,6 +313,8 @@ fence_remove_callback(struct fence *fenc
 {
 	bool onqueue;
 
+	KASSERT(fence_referenced_p(fence));
+
 	spin_lock(fence->lock);
 	onqueue = fcb->fcb_onqueue;
 	if (onqueue) {
@@ -311,6 +338,8 @@ void
 fence_enable_sw_signaling(struct fence *fence)
 {
 
+	KASSERT(fence_referenced_p(fence));
+
 	spin_lock(fence->lock);
 	(void)fence_ensure_signal_enabled(fence);
 	spin_unlock(fence->lock);
@@ -330,6 +359,8 @@ fence_is_signaled(struct fence *fence)
 {
 	bool signaled;
 
+	KASSERT(fence_referenced_p(fence));
+
 	spin_lock(fence->lock);
 	signaled = fence_is_signaled_locked(fence);
 	spin_unlock(fence->lock);
@@ -347,6 +378,7 @@ bool
 fence_is_signaled_locked(struct fence *fence)
 {
 
+	KASSERT(fence_referenced_p(fence));
 	KASSERT(spin_is_locked(fence->lock));
 
 	/* Check whether we already set the signalled bit.  */
@@ -383,6 +415,8 @@ fence_signal(struct fence *fence)
 {
 	int ret;
 
+	KASSERT(fence_referenced_p(fence));
+
 	spin_lock(fence->lock);
 	ret = fence_signal_locked(fence);
 	spin_unlock(fence->lock);
@@ -401,6 +435,7 @@ fence_signal_locked(struct fence *fence)
 {
 	struct fence_cb *fcb, *next;
 
+	KASSERT(fence_referenced_p(fence));
 	KASSERT(spin_is_locked(fence->lock));
 
 	/* If it's been signalled, fail; otherwise set the signalled bit.  */
@@ -435,6 +470,8 @@ wait_any_cb(struct fence *fence, struct 
 {
 	struct wait_any *cb = container_of(fcb, struct wait_any, fcb);
 
+	KASSERT(fence_referenced_p(fence));
+
 	mutex_enter(&cb->common->lock);
 	cb->common->done = true;
 	cv_broadcast(&cb->common->cv);
@@ -472,6 +509,7 @@ fence_wait_any_timeout(struct fence **fe
 	/* Add a callback to each of the fences, or stop here if we can't.  */
 	for (i = 0; i < nfences; i++) {
 		cb[i].common = &common;
+		KASSERT(fence_referenced_p(fences[i]));
 		ret = fence_add_callback(fences[i], &cb[i].fcb, &wait_any_

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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:14:13 UTC 2018

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

Log Message:
Clarify with comments and assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.6 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.7
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.6	Mon Aug 27 14:13:46 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 14:14:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.7 2018/08/27 14:14:13 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.6 2018/08/27 14:13:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.7 2018/08/27 14:14:13 riastradh Exp $");
 
 #include 
 #include 
@@ -390,6 +390,11 @@ reservation_object_add_shared_fence(stru
 
 	/* Check for a preallocated replacement list.  */
 	if (prealloc == NULL) {
+		/*
+		 * If there is no preallocated replacement list, then
+		 * there must be room in the current list.
+		 */
+		KASSERT(list != NULL);
 		KASSERT(list->shared_count < list->shared_max);
 
 		/* Begin an update.  */
@@ -411,8 +416,14 @@ reservation_object_add_shared_fence(stru
 		/* Commit the update.  */
 		reservation_object_write_commit(robj, &ticket);
 	} else {
+		/*
+		 * There is a preallocated replacement list.  There may
+		 * not be a current list.  If not, treat it as a zero-
+		 * length list.
+		 */
 		uint32_t shared_count = (list == NULL? 0 : list->shared_count);
 
+		/* There had better be room in the preallocated list.  */
 		KASSERT(shared_count < prealloc->shared_max);
 
 		/*



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:13:00 UTC 2018

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

Log Message:
Acquire references in add_shared/excl.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.4 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.4	Mon Aug 27 14:01:14 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 14:13:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.4 2018/08/27 14:01:14 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.4 2018/08/27 14:01:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.5 2018/08/27 14:13:00 riastradh Exp $");
 
 #include 
 #include 
@@ -311,9 +311,9 @@ reservation_object_read_valid(struct res
 /*
  * reservation_object_add_excl_fence(robj, fence)
  *
- *	Replace robj's exclusive fence, if any, by fence, and empty its
- *	list of shared fences.  The old exclusive fence and all old
- *	shared fences are released.
+ *	Empty and release all of robj's shared fences, and clear and
+ *	release its exclusive fence.  If fence is nonnull, acquire a
+ *	reference to it and save it as robj's exclusive fence.
  *
  *	Caller must have robj locked.
  */
@@ -328,6 +328,13 @@ reservation_object_add_excl_fence(struct
 
 	KASSERT(reservation_object_held(robj));
 
+	/*
+	 * If we are setting rather than just removing a fence, acquire
+	 * a reference for ourselves.
+	 */
+	if (fence)
+		(void)fence_get(fence);
+
 	/* If there are any shared fences, remember how many.  */
 	if (old_list)
 		old_shared_count = old_list->shared_count;
@@ -357,9 +364,9 @@ reservation_object_add_excl_fence(struct
 /*
  * reservation_object_add_shared_fence(robj, fence)
  *
- *	Add a shared fence to robj.  If any fence was already added
- *	with the same context number, release it and replace it by this
- *	one.
+ *	Acquire a reference to fence and add it to robj's shared list.
+ *	If any fence was already added with the same context number,
+ *	release it and replace it by this one.
  *
  *	Caller must have robj locked, and must have preceded with a
  *	call to reservation_object_reserve_shared for each shared fence
@@ -377,6 +384,10 @@ reservation_object_add_shared_fence(stru
 
 	KASSERT(reservation_object_held(robj));
 
+	/* Acquire a reference to the fence.  */
+	KASSERT(fence != NULL);
+	(void)fence_get(fence);
+
 	/* Check for a preallocated replacement list.  */
 	if (prealloc == NULL) {
 		KASSERT(list->shared_count < list->shared_max);



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 14:00:46 UTC 2018

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

Log Message:
Fix prototype of function in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.3 src/sys/external/bsd/drm2/linux/linux_fence.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.3	Mon Aug 27 13:56:34 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Mon Aug 27 14:00:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.3 2018/08/27 13:56:34 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.4 2018/08/27 14:00:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.3 2018/08/27 13:56:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.4 2018/08/27 14:00:46 riastradh Exp $");
 
 #include 
 #include 
@@ -423,7 +423,7 @@ fence_wait_timeout(struct fence *fence, 
 }
 
 /*
- * fence_wait_timeout(fence, intr, timeout)
+ * fence_wait(fence, intr)
  *
  *	Wait until fence is signalled; or until interrupt, if intr is
  *	true.  Return -ERESTARTSYS if interrupted, negative error code



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 13:56:34 UTC 2018

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

Log Message:
Fence release callback may be absent; default to fence_free.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_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/linux/linux_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_fence.c:1.2 src/sys/external/bsd/drm2/linux/linux_fence.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_fence.c:1.2	Mon Aug 27 13:36:53 2018
+++ src/sys/external/bsd/drm2/linux/linux_fence.c	Mon Aug 27 13:56:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_fence.c,v 1.2 2018/08/27 13:36:53 riastradh Exp $	*/
+/*	$NetBSD: linux_fence.c,v 1.3 2018/08/27 13:56:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.2 2018/08/27 13:36:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_fence.c,v 1.3 2018/08/27 13:56:34 riastradh Exp $");
 
 #include 
 #include 
@@ -155,7 +155,10 @@ fence_release(struct kref *refcount)
 {
 	struct fence *fence = container_of(refcount, struct fence, refcount);
 
-	(*fence->ops->release)(fence);
+	if (fence->ops->release)
+		(*fence->ops->release)(fence);
+	else
+		fence_free(fence);
 }
 
 /*



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 13:45:20 UTC 2018

Modified Files:
src/sys/external/bsd/drm2/linux: files.drmkms_linux

Log Message:
Sort.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/linux/files.drmkms_linux

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/files.drmkms_linux
diff -u src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.13 src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.14
--- src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.13	Mon Aug 27 13:33:59 2018
+++ src/sys/external/bsd/drm2/linux/files.drmkms_linux	Mon Aug 27 13:45:20 2018
@@ -1,9 +1,9 @@
-#   $NetBSD: files.drmkms_linux,v 1.13 2018/08/27 13:33:59 riastradh Exp $
+#   $NetBSD: files.drmkms_linux,v 1.14 2018/08/27 13:45:20 riastradh Exp $
 
 define	drmkms_linux: i2cexec, i2c_bitbang
 
-makeoptions 	drmkms_linux	CPPFLAGS+="-I$S/external/bsd/drm2/include"
 makeoptions 	drmkms_linux	CPPFLAGS+="-I$S/external/bsd/common/include"
+makeoptions 	drmkms_linux	CPPFLAGS+="-I$S/external/bsd/drm2/include"
 
 file	external/bsd/drm2/linux/linux_dmi.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_fence.c		drmkms_linux



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 13:39:48 UTC 2018

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

Log Message:
Don't forget to call kthread_exit.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/drm2/linux/linux_rcu.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_rcu.c
diff -u src/sys/external/bsd/drm2/linux/linux_rcu.c:1.1 src/sys/external/bsd/drm2/linux/linux_rcu.c:1.2
--- src/sys/external/bsd/drm2/linux/linux_rcu.c:1.1	Mon Aug 27 13:31:37 2018
+++ src/sys/external/bsd/drm2/linux/linux_rcu.c	Mon Aug 27 13:39:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.1 2018/08/27 13:31:37 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.2 2018/08/27 13:39:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.1 2018/08/27 13:31:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.2 2018/08/27 13:39:48 riastradh Exp $");
 
 #include 
 #include 
@@ -106,6 +106,8 @@ gc_thread(void *cookie)
 			break;
 	}
 	mutex_exit(&gc.lock);
+
+	kthread_exit(0);
 }
 
 int



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 13:35:35 UTC 2018

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

Log Message:
Wait for the read to be valid!


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/drm2/linux/linux_reservation.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_reservation.c
diff -u src/sys/external/bsd/drm2/linux/linux_reservation.c:1.1 src/sys/external/bsd/drm2/linux/linux_reservation.c:1.2
--- src/sys/external/bsd/drm2/linux/linux_reservation.c:1.1	Mon Aug 27 13:33:59 2018
+++ src/sys/external/bsd/drm2/linux/linux_reservation.c	Mon Aug 27 13:35:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_reservation.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $	*/
+/*	$NetBSD: linux_reservation.c,v 1.2 2018/08/27 13:35:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.1 2018/08/27 13:33:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_reservation.c,v 1.2 2018/08/27 13:35:35 riastradh Exp $");
 
 #include 
 #include 
@@ -281,7 +281,8 @@ reservation_object_read_begin(struct res
 struct reservation_object_read_ticket *ticket)
 {
 
-	ticket->version = robj->robj_version;
+	while ((ticket->version = robj->robj_version) & 1)
+		SPINLOCK_BACKOFF_HOOK;
 	membar_consumer();
 }
 



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 07:57:56 UTC 2018

Modified Files:
src/sys/external/bsd/drm2/linux: files.drmkms_linux

Log Message:
Sort in the standard English alphabetical order, please.


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

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/files.drmkms_linux
diff -u src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.10 src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.11
--- src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.10	Mon Aug 27 07:56:47 2018
+++ src/sys/external/bsd/drm2/linux/files.drmkms_linux	Mon Aug 27 07:57:56 2018
@@ -1,4 +1,4 @@
-#   $NetBSD: files.drmkms_linux,v 1.10 2018/08/27 07:56:47 riastradh Exp $
+#   $NetBSD: files.drmkms_linux,v 1.11 2018/08/27 07:57:56 riastradh Exp $
 
 define	drmkms_linux: i2cexec, i2c_bitbang
 
@@ -7,8 +7,8 @@ makeoptions 	drmkms_linux	CPPFLAGS+="-I$
 
 file	external/bsd/drm2/linux/linux_dmi.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_i2c.c		drmkms_linux
-file	external/bsd/drm2/linux/linux_kmap.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_idr.c		drmkms_linux
+file	external/bsd/drm2/linux/linux_kmap.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_list_sort.c	drmkms_linux
 file	external/bsd/drm2/linux/linux_module.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_writecomb.c	drmkms_linux



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 07:56:47 UTC 2018

Modified Files:
src/sys/external/bsd/drm2/linux: files.drmkms_linux

Log Message:
Sort.


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

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/files.drmkms_linux
diff -u src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.9 src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.10
--- src/sys/external/bsd/drm2/linux/files.drmkms_linux:1.9	Wed Feb 24 22:04:15 2016
+++ src/sys/external/bsd/drm2/linux/files.drmkms_linux	Mon Aug 27 07:56:47 2018
@@ -1,4 +1,4 @@
-#   $NetBSD: files.drmkms_linux,v 1.9 2016/02/24 22:04:15 skrll Exp $
+#   $NetBSD: files.drmkms_linux,v 1.10 2018/08/27 07:56:47 riastradh Exp $
 
 define	drmkms_linux: i2cexec, i2c_bitbang
 
@@ -6,8 +6,8 @@ makeoptions 	drmkms_linux	CPPFLAGS+="-I$
 makeoptions 	drmkms_linux	CPPFLAGS+="-I$S/external/bsd/common/include"
 
 file	external/bsd/drm2/linux/linux_dmi.c		drmkms_linux
-file	external/bsd/drm2/linux/linux_kmap.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_i2c.c		drmkms_linux
+file	external/bsd/drm2/linux/linux_kmap.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_idr.c		drmkms_linux
 file	external/bsd/drm2/linux/linux_list_sort.c	drmkms_linux
 file	external/bsd/drm2/linux/linux_module.c		drmkms_linux



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

2018-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug 27 06:45:44 UTC 2018

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

Log Message:
Implement dmi_match.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/drm2/linux/linux_dmi.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_dmi.c
diff -u src/sys/external/bsd/drm2/linux/linux_dmi.c:1.1 src/sys/external/bsd/drm2/linux/linux_dmi.c:1.2
--- src/sys/external/bsd/drm2/linux/linux_dmi.c:1.1	Fri Apr 25 23:54:59 2014
+++ src/sys/external/bsd/drm2/linux/linux_dmi.c	Mon Aug 27 06:45:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dmi.c,v 1.1 2014/04/25 23:54:59 riastradh Exp $	*/
+/*	$NetBSD: linux_dmi.c,v 1.2 2018/08/27 06:45:44 riastradh Exp $	*/
 
 /*-
  * Copyright (C) 2014 NONAKA Kimihiro 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dmi.c,v 1.1 2014/04/25 23:54:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dmi.c,v 1.2 2018/08/27 06:45:44 riastradh Exp $");
 
 #include 
 #include 
@@ -34,70 +34,80 @@ __KERNEL_RCSID(0, "$NetBSD: linux_dmi.c,
 
 #include 
 
+bool
+dmi_match(enum dmi_field slot, const char *text)
+{
+	const char *p = NULL;
+
+	switch (slot) {
+	case DMI_NONE:
+		aprint_error("%s: dmi_match on none makes no sense", __func__);
+		return false;
+	case DMI_BIOS_VENDOR:
+		p = pmf_get_platform("bios-vendor");
+		break;
+	case DMI_BIOS_VERSION:
+		p = pmf_get_platform("bios-version");
+		break;
+	case DMI_BIOS_DATE:
+		p = pmf_get_platform("bios-date");
+		break;
+	case DMI_SYS_VENDOR:
+		p = pmf_get_platform("system-vendor");
+		break;
+	case DMI_PRODUCT_NAME:
+		p = pmf_get_platform("system-product");
+		break;
+	case DMI_PRODUCT_VERSION:
+		p = pmf_get_platform("system-version");
+		break;
+	case DMI_PRODUCT_SERIAL:
+		p = pmf_get_platform("system-serial");
+		break;
+	case DMI_PRODUCT_UUID:
+		p = pmf_get_platform("system-uuid");
+		break;
+	case DMI_BOARD_VENDOR:
+		p = pmf_get_platform("board-vendor");
+		break;
+	case DMI_BOARD_NAME:
+		p = pmf_get_platform("board-product");
+		break;
+	case DMI_BOARD_VERSION:
+		p = pmf_get_platform("board-version");
+		break;
+	case DMI_BOARD_SERIAL:
+		p = pmf_get_platform("board-serial");
+		break;
+	case DMI_BOARD_ASSET_TAG:
+		p = pmf_get_platform("board-asset-tag");
+		break;
+	case DMI_CHASSIS_VENDOR:
+	case DMI_CHASSIS_TYPE:
+	case DMI_CHASSIS_VERSION:
+	case DMI_CHASSIS_SERIAL:
+	case DMI_CHASSIS_ASSET_TAG:
+		return false;
+	case DMI_STRING_MAX:
+	default:
+		aprint_error("%s: unknown DMI field(%d)\n", __func__, slot);
+		return false;
+	}
+	if (p == NULL || strcmp(p, text))
+		return false;
+
+	return true;
+}
+
 static bool
 dmi_found(const struct dmi_system_id *dsi)
 {
-	const char *p;
-	int i, slot;
+	int i;
 
 	for (i = 0; i < __arraycount(dsi->matches); i++) {
-		p = NULL;
-		slot = dsi->matches[i].slot;
-		switch (slot) {
-		case DMI_NONE:
-			continue;
-		case DMI_BIOS_VENDOR:
-			p = pmf_get_platform("bios-vendor");
-			break;
-		case DMI_BIOS_VERSION:
-			p = pmf_get_platform("bios-version");
-			break;
-		case DMI_BIOS_DATE:
-			p = pmf_get_platform("bios-date");
-			break;
-		case DMI_SYS_VENDOR:
-			p = pmf_get_platform("system-vendor");
-			break;
-		case DMI_PRODUCT_NAME:
-			p = pmf_get_platform("system-product");
+		if (dsi->matches[i].slot == DMI_NONE)
 			break;
-		case DMI_PRODUCT_VERSION:
-			p = pmf_get_platform("system-version");
-			break;
-		case DMI_PRODUCT_SERIAL:
-			p = pmf_get_platform("system-serial");
-			break;
-		case DMI_PRODUCT_UUID:
-			p = pmf_get_platform("system-uuid");
-			break;
-		case DMI_BOARD_VENDOR:
-			p = pmf_get_platform("board-vendor");
-			break;
-		case DMI_BOARD_NAME:
-			p = pmf_get_platform("board-product");
-			break;
-		case DMI_BOARD_VERSION:
-			p = pmf_get_platform("board-version");
-			break;
-		case DMI_BOARD_SERIAL:
-			p = pmf_get_platform("board-serial");
-			break;
-		case DMI_BOARD_ASSET_TAG:
-			p = pmf_get_platform("board-asset-tag");
-			break;
-		case DMI_CHASSIS_VENDOR:
-		case DMI_CHASSIS_TYPE:
-		case DMI_CHASSIS_VERSION:
-		case DMI_CHASSIS_SERIAL:
-		case DMI_CHASSIS_ASSET_TAG:
-			return false;
-		case DMI_STRING_MAX:
-		default:
-			aprint_error("%s: unknown DMI field(%d)\n", __func__,
-			slot);
-			return false;
-		}
-		if (p == NULL || strcmp(p, dsi->matches[i].substr))
+		if (!dmi_match(dsi->matches[i].slot, dsi->matches[i].substr))
 			return false;
 	}
 	return true;



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

2018-08-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 14 14:53:11 UTC 2018

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

Log Message:
Exit, don't reenter, the mutex...!@#*@$!&.

>From mrg@.

XXX pullup-7
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_writecomb.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_writecomb.c
diff -u src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.4 src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.4	Sat Oct 17 21:06:42 2015
+++ src/sys/external/bsd/drm2/linux/linux_writecomb.c	Tue Aug 14 14:53:11 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_writecomb.c,v 1.4 2015/10/17 21:06:42 jmcneill Exp $	*/
+/*	$NetBSD: linux_writecomb.c,v 1.5 2018/08/14 14:53:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.4 2015/10/17 21:06:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.5 2018/08/14 14:53:11 riastradh Exp $");
 
 #if defined(__i386__) || defined(__x86_64__)
 #define HAS_MTRR 1
@@ -136,7 +136,7 @@ arch_phys_wc_del(int id)
 	mutex_spin_enter(&linux_writecomb.lock);
 	mtrr = idr_find(&linux_writecomb.idr, id);
 	idr_remove(&linux_writecomb.idr, id);
-	mutex_spin_enter(&linux_writecomb.lock);
+	mutex_spin_exit(&linux_writecomb.lock);
 
 	if (mtrr != NULL) {
 		mtrr->type = 0;



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

2018-08-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Aug 14 14:53:21 UTC 2018

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

Log Message:
Initialize n before mtrr_set in arch_phys_wc_del.

>From mrg@.

XXX pullup-7
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_writecomb.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_writecomb.c
diff -u src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.5 src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.5	Tue Aug 14 14:53:11 2018
+++ src/sys/external/bsd/drm2/linux/linux_writecomb.c	Tue Aug 14 14:53:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_writecomb.c,v 1.5 2018/08/14 14:53:11 riastradh Exp $	*/
+/*	$NetBSD: linux_writecomb.c,v 1.6 2018/08/14 14:53:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.5 2018/08/14 14:53:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.6 2018/08/14 14:53:21 riastradh Exp $");
 
 #if defined(__i386__) || defined(__x86_64__)
 #define HAS_MTRR 1
@@ -128,7 +128,7 @@ arch_phys_wc_del(int id)
 {
 #if defined(MTRR)
 	struct mtrr *mtrr;
-	int n;
+	int n = 1;
 	int ret __diagused;
 
 	KASSERT(0 <= id);



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

2017-09-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Sep 16 23:56:42 UTC 2017

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

Log Message:
more const


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 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.3 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.3	Fri Aug 25 10:14:44 2017
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c	Sat Sep 16 19:56:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ww_mutex.c,v 1.3 2017/08/25 14:14:44 riastradh Exp $	*/
+/*	$NetBSD: linux_ww_mutex.c,v 1.4 2017/09/16 23:56:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.3 2017/08/25 14:14:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.4 2017/09/16 23:56:42 christos Exp $");
 
 #include 
 #include 
@@ -122,9 +122,9 @@ ww_acquire_fini(struct ww_acquire_ctx *c
 
 #ifdef LOCKDEBUG
 static void
-ww_dump(volatile void *cookie)
+ww_dump(const volatile void *cookie)
 {
-	volatile struct ww_mutex *mutex = cookie;
+	const volatile struct ww_mutex *mutex = cookie;
 
 	printf_nolog("%-13s: ", "state");
 	switch (mutex->wwm_state) {
@@ -135,7 +135,7 @@ ww_dump(volatile void *cookie)
 		printf_nolog("owned by lwp\n");
 		printf_nolog("%-13s: %p\n", "owner", mutex->wwm_u.owner);
 		printf_nolog("%-13s: %s\n", "waiters",
-		cv_has_waiters(__UNVOLATILE(&mutex->wwm_cv))
+		cv_has_waiters((void *)(intptr_t)&mutex->wwm_cv)
 			? "yes" : "no");
 		break;
 	case WW_CTX:
@@ -144,7 +144,7 @@ ww_dump(volatile void *cookie)
 		printf_nolog("%-13s: %p\n", "lwp",
 		mutex->wwm_u.ctx->wwx_owner);
 		printf_nolog("%-13s: %s\n", "waiters",
-		cv_has_waiters(__UNVOLATILE(&mutex->wwm_cv))
+		cv_has_waiters((void *)(intptr_t)&mutex->wwm_cv)
 			? "yes" : "no");
 		break;
 	case WW_WANTOWN:



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

2017-08-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 25 14:14:44 UTC 2017

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

Log Message:
Fix lockdebug_locked annotations.

When thread A grants ownership to thread B waiting with a context,
thread B needs to assert lockdebug_locked; otherwise, when it
releases, lockdebug_unlocked thinks it's releasing an unlocked
ww_mutex.

Fixes LOCKDEBUG failure with radeon noticed by martin@.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 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.2 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.2	Thu May 21 21:55:55 2015
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c	Fri Aug 25 14:14:44 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ww_mutex.c,v 1.2 2015/05/21 21:55:55 riastradh Exp $	*/
+/*	$NetBSD: linux_ww_mutex.c,v 1.3 2017/08/25 14:14:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.2 2015/05/21 21:55:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.3 2017/08/25 14:14:44 riastradh Exp $");
 
 #include 
 #include 
@@ -334,7 +334,6 @@ retry:	switch (mutex->wwm_state) {
 	case WW_UNLOCKED:
 		mutex->wwm_state = WW_OWNED;
 		mutex->wwm_u.owner = curlwp;
-		WW_LOCKED(mutex);
 		break;
 	case WW_OWNED:
 		KASSERTMSG((mutex->wwm_u.owner != curlwp),
@@ -356,6 +355,7 @@ retry:	switch (mutex->wwm_state) {
 	}
 	KASSERT(mutex->wwm_state == WW_OWNED);
 	KASSERT(mutex->wwm_u.owner == curlwp);
+	WW_LOCKED(mutex);
 	mutex_exit(&mutex->wwm_lock);
 }
 
@@ -369,7 +369,6 @@ retry:	switch (mutex->wwm_state) {
 	case WW_UNLOCKED:
 		mutex->wwm_state = WW_OWNED;
 		mutex->wwm_u.owner = curlwp;
-		WW_LOCKED(mutex);
 		break;
 	case WW_OWNED:
 		KASSERTMSG((mutex->wwm_u.owner != curlwp),
@@ -395,6 +394,7 @@ retry:	switch (mutex->wwm_state) {
 	}
 	KASSERT(mutex->wwm_state == WW_OWNED);
 	KASSERT(mutex->wwm_u.owner == curlwp);
+	WW_LOCKED(mutex);
 	ret = 0;
 out:	mutex_exit(&mutex->wwm_lock);
 	return ret;
@@ -433,7 +433,6 @@ retry:	switch (mutex->wwm_state) {
 		WW_WANTLOCK(mutex);
 		mutex->wwm_state = WW_CTX;
 		mutex->wwm_u.ctx = ctx;
-		WW_LOCKED(mutex);
 		goto locked;
 	case WW_OWNED:
 		WW_WANTLOCK(mutex);
@@ -490,10 +489,11 @@ retry:	switch (mutex->wwm_state) {
 	 */
 	ww_mutex_lock_wait(mutex, ctx);
 
-locked:	ctx->wwx_acquired++;
-	KASSERT((mutex->wwm_state == WW_CTX) ||
+locked:	KASSERT((mutex->wwm_state == WW_CTX) ||
 	(mutex->wwm_state == WW_WANTOWN));
 	KASSERT(mutex->wwm_u.ctx == ctx);
+	WW_LOCKED(mutex);
+	ctx->wwx_acquired++;
 	mutex_exit(&mutex->wwm_lock);
 	return 0;
 }
@@ -531,7 +531,6 @@ retry:	switch (mutex->wwm_state) {
 		WW_WANTLOCK(mutex);
 		mutex->wwm_state = WW_CTX;
 		mutex->wwm_u.ctx = ctx;
-		WW_LOCKED(mutex);
 		goto locked;
 	case WW_OWNED:
 		WW_WANTLOCK(mutex);
@@ -597,6 +596,7 @@ retry:	switch (mutex->wwm_state) {
 locked:	KASSERT((mutex->wwm_state == WW_CTX) ||
 	(mutex->wwm_state == WW_WANTOWN));
 	KASSERT(mutex->wwm_u.ctx == ctx);
+	WW_LOCKED(mutex);
 	ctx->wwx_acquired++;
 	ret = 0;
 out:	mutex_exit(&mutex->wwm_lock);
@@ -634,7 +634,6 @@ retry:	switch (mutex->wwm_state) {
 	case WW_UNLOCKED:
 		mutex->wwm_state = WW_CTX;
 		mutex->wwm_u.ctx = ctx;
-		WW_LOCKED(mutex);
 		goto locked;
 	case WW_OWNED:
 		KASSERTMSG((mutex->wwm_u.owner != curlwp),
@@ -665,6 +664,7 @@ retry:	switch (mutex->wwm_state) {
 locked:	KASSERT((mutex->wwm_state == WW_CTX) ||
 	(mutex->wwm_state == WW_WANTOWN));
 	KASSERT(mutex->wwm_u.ctx == ctx);
+	WW_LOCKED(mutex);
 	ctx->wwx_acquired++;
 	mutex_exit(&mutex->wwm_lock);
 }
@@ -699,7 +699,6 @@ retry:	switch (mutex->wwm_state) {
 	case WW_UNLOCKED:
 		mutex->wwm_state = WW_CTX;
 		mutex->wwm_u.ctx = ctx;
-		WW_LOCKED(mutex);
 		goto locked;
 	case WW_OWNED:
 		KASSERTMSG((mutex->wwm_u.owner != curlwp),
@@ -736,6 +735,7 @@ retry:	switch (mutex->wwm_state) {
 locked:	KASSERT((mutex->wwm_state == WW_CTX) ||
 	(mutex->wwm_state == WW_WANTOWN));
 	KASSERT(mutex->wwm_u.ctx == ctx);
+	WW_LOCKED(mutex);
 	ctx->wwx_acquired++;
 	ret = 0;
 out:	mutex_exit(&mutex->wwm_lock);



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

2017-07-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 26 03:40:40 UTC 2017

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

Log Message:
Tweak slightly sketchy logic in linux_idr.

1. idr_preload can fail if you don't set __GFP_WAIT.
2. If idr_preload fails, it is wrong for idr_alloc to assert.
3. There is no way for idr_alloc to know what flags idr_preload got.

Probably won't *fix* any bugs, but if there is a bug with a missing
__GFP_WAIT, then we will learn about a trifle sooner.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_idr.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_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.5 src/sys/external/bsd/drm2/linux/linux_idr.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.5	Thu Jan  1 01:15:43 2015
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Wed Jul 26 03:40:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.5 2015/01/01 01:15:43 mrg Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.6 2017/07/26 03:40:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.5 2015/01/01 01:15:43 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.6 2017/07/26 03:40:39 riastradh Exp $");
 
 #include 
 #include 
@@ -191,6 +191,7 @@ idr_preload(gfp_t gfp)
 		ASSERT_SLEEPABLE();
 
 	node = kmalloc(sizeof(*node), gfp);
+	KASSERT(node != NULL || !ISSET(gfp, __GFP_WAIT));
 	if (node == NULL)
 		return;
 
@@ -216,8 +217,10 @@ idr_alloc(struct idr *idr, void *data, i
 
 	/* Grab a node allocated by idr_preload.  */
 	mutex_spin_enter(&idr_cache.lock);
-	KASSERTMSG(!SIMPLEQ_EMPTY(&idr_cache.preloaded_nodes),
-	"missing call to idr_preload");
+	if (SIMPLEQ_EMPTY(&idr_cache.preloaded_nodes)) {
+		mutex_spin_exit(&idr_cache.lock);
+		return -ENOMEM;
+	}
 	node = SIMPLEQ_FIRST(&idr_cache.preloaded_nodes);
 	SIMPLEQ_REMOVE_HEAD(&idr_cache.preloaded_nodes, in_list);
 	mutex_spin_exit(&idr_cache.lock);



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

2015-11-15 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Nov 15 22:56:24 UTC 2015

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

Log Message:
Avoid NULL dereference in linux_worker_intr() in WORK_DELAYED_CANCELLED case.

Potentially fixes PR#49560.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.11 src/sys/external/bsd/drm2/linux/linux_work.c:1.12
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.11	Sat Oct 17 15:57:32 2015
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Sun Nov 15 22:56:24 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.11 2015/10/17 15:57:32 jmcneill Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.12 2015/11/15 22:56:24 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.11 2015/10/17 15:57:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.12 2015/11/15 22:56:24 jakllsch Exp $");
 
 #include 
 #include 
@@ -850,7 +850,7 @@ linux_worker_intr(void *arg)
 	}
 
 	/* Either way, the callout is done.  */
-	TAILQ_REMOVE(&dw->work.w_wq->wq_delayed, dw, dw_entry);
+	TAILQ_REMOVE(&wq->wq_delayed, dw, dw_entry);
 	callout_destroy(&dw->dw_callout);
 
 	mutex_exit(&wq->wq_lock);



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

2015-10-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Oct 17 21:06:42 UTC 2015

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

Log Message:
only use mtrr api if options MTRR is present and we are on x86


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_writecomb.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_writecomb.c
diff -u src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.3 src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_writecomb.c:1.3	Thu Jan  1 01:15:43 2015
+++ src/sys/external/bsd/drm2/linux/linux_writecomb.c	Sat Oct 17 21:06:42 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_writecomb.c,v 1.3 2015/01/01 01:15:43 mrg Exp $	*/
+/*	$NetBSD: linux_writecomb.c,v 1.4 2015/10/17 21:06:42 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,16 +30,22 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.3 2015/01/01 01:15:43 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_writecomb.c,v 1.4 2015/10/17 21:06:42 jmcneill Exp $");
 
-#ifdef _KERNEL_OPT
+#if defined(__i386__) || defined(__x86_64__)
+#define HAS_MTRR 1
+#endif
+
+#if defined(_KERNEL_OPT) && defined(HAS_MTRR)
 #include "opt_mtrr.h"
 #endif
 
 #include 
 #include 
 
+#if defined(MTRR)
 #include 
+#endif
 
 #include 
 #include 
@@ -71,6 +77,7 @@ linux_writecomb_fini(void)
 int
 arch_phys_wc_add(unsigned long base, unsigned long size)
 {
+#if defined(MTRR)
 	struct mtrr *mtrr;
 	int n = 1;
 	int id;
@@ -111,11 +118,15 @@ fail1:	KASSERT(id < 0);
 fail0:	KASSERT(ret < 0);
 	kmem_free(mtrr, sizeof(*mtrr));
 	return ret;
+#else
+	return -1;
+#endif
 }
 
 void
 arch_phys_wc_del(int id)
 {
+#if defined(MTRR)
 	struct mtrr *mtrr;
 	int n;
 	int ret __diagused;
@@ -136,6 +147,7 @@ arch_phys_wc_del(int id)
 		KASSERT(n == 1);
 		kmem_free(mtrr, sizeof(*mtrr));
 	}
+#endif
 }
 
 int



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

2015-10-17 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Oct 17 15:57:33 UTC 2015

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

Log Message:
include sys/cpu.h for CPU_INFO_ITERATOR


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.10 src/sys/external/bsd/drm2/linux/linux_work.c:1.11
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.10	Thu Jan  1 01:15:43 2015
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Sat Oct 17 15:57:32 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.10 2015/01/01 01:15:43 mrg Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.11 2015/10/17 15:57:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.10 2015/01/01 01:15:43 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.11 2015/10/17 15:57:32 jmcneill Exp $");
 
 #include 
 #include 
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_work.c
 #include 
 #include 
 #include 
+#include 
 
 #include 
 



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

2014-11-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Nov 11 02:37:17 UTC 2014

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

Log Message:
finalize the idr code.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_module.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_module.c
diff -u src/sys/external/bsd/drm2/linux/linux_module.c:1.4 src/sys/external/bsd/drm2/linux/linux_module.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_module.c:1.4	Wed Jul 16 16:59:58 2014
+++ src/sys/external/bsd/drm2/linux/linux_module.c	Mon Nov 10 21:37:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_module.c,v 1.4 2014/07/16 20:59:58 riastradh Exp $	*/
+/*	$NetBSD: linux_module.c,v 1.5 2014/11/11 02:37:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.4 2014/07/16 20:59:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.5 2014/11/11 02:37:17 christos Exp $");
 
 #include 
 #ifndef _MODULE
@@ -108,6 +108,7 @@ linux_fini(void)
 	linux_writecomb_fini();
 	linux_workqueue_fini();
 	linux_kmap_fini();
+	linux_idr_module_fini();
 }
 
 static int



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

2014-08-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 29 15:22:18 UTC 2014

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

Log Message:
Don't forget to lock wq_lock around handling wq_delayed.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.7 src/sys/external/bsd/drm2/linux/linux_work.c:1.8
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.7	Tue Jul 29 17:36:06 2014
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Fri Aug 29 15:22:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.7 2014/07/29 17:36:06 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.8 2014/08/29 15:22:18 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.7 2014/07/29 17:36:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.8 2014/08/29 15:22:18 riastradh Exp $");
 
 #include 
 #include 
@@ -577,7 +577,9 @@ queue_delayed_work(struct workqueue_stru
 			&linux_worker_intr, dw);
 			dw->work.w_state = WORK_DELAYED;
 			dw->work.w_wq = wq;
+			mutex_enter(&wq->wq_lock);
 			TAILQ_INSERT_HEAD(&wq->wq_delayed, dw, dw_entry);
+			mutex_exit(&wq->wq_lock);
 		}
 		newly_queued = true;
 		break;
@@ -636,7 +638,9 @@ mod_delayed_work(struct workqueue_struct
 			&linux_worker_intr, dw);
 			dw->work.w_state = WORK_DELAYED;
 			dw->work.w_wq = wq;
+			mutex_enter(&wq->wq_lock);
 			TAILQ_INSERT_HEAD(&wq->wq_delayed, dw, dw_entry);
+			mutex_exit(&wq->wq_lock);
 		}
 		timer_modified = false;
 		break;



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:41:50 UTC 2014

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

Log Message:
Use direct map if available in linux_kmap.

Yields 20% increase in glxgears framerate.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.9 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.10
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.9	Wed Aug 27 16:19:54 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:41:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.9 2014/08/27 16:19:54 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.10 2014/08/27 16:41:50 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,13 +30,17 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.9 2014/08/27 16:19:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.10 2014/08/27 16:41:50 riastradh Exp $");
 
 #include 
 #include 
 #include 
 #include 
 
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+#include 
+#endif
+
 #include 
 
 #include 
@@ -48,12 +52,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux_kmap.c
  * use at a time.
  */
 
-/*
- * XXX Use direct-mapped physical pages where available, e.g. amd64.
- *
- * XXX ...or add an abstraction to uvm for this.  (uvm_emap?)
- */
-
 static kmutex_t linux_kmap_atomic_lock;
 static vaddr_t linux_kmap_atomic_vaddr;
 
@@ -146,6 +144,11 @@ kmap_atomic(struct page *page)
 	const paddr_t paddr = uvm_vm_page_to_phys(&page->p_vmp);
 	vaddr_t vaddr;
 
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+	if (mm_md_direct_mapped_phys(paddr, &vaddr))
+		return (void *)vaddr;
+#endif
+
 	mutex_spin_enter(&linux_kmap_atomic_lock);
 	KASSERT(linux_kmap_atomic_vaddr != 0);
 	KASSERT(!pmap_extract(pmap_kernel(), linux_kmap_atomic_vaddr, NULL));
@@ -161,6 +164,19 @@ kunmap_atomic(void *addr)
 {
 	const vaddr_t vaddr = (vaddr_t)addr;
 
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+{
+	paddr_t paddr;
+	vaddr_t vaddr1;
+	bool ok __diagused;
+
+	ok = pmap_extract(pmap_kernel(), vaddr, &paddr);
+	KASSERT(ok);
+	if (mm_md_direct_mapped_phys(paddr, &vaddr1) && vaddr1 == vaddr)
+		return;
+}
+#endif
+
 	KASSERT(mutex_owned(&linux_kmap_atomic_lock));
 	KASSERT(linux_kmap_atomic_vaddr == vaddr);
 	KASSERT(pmap_extract(pmap_kernel(), vaddr, NULL));
@@ -179,6 +195,11 @@ kmap(struct page *page)
 
 	ASSERT_SLEEPABLE();
 
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+	if (mm_md_direct_mapped_phys(paddr, &vaddr))
+		return (void *)vaddr;
+#endif
+
 	vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 	(UVM_KMF_VAONLY | UVM_KMF_WAITVA));
 	KASSERT(vaddr != 0);
@@ -208,6 +229,15 @@ kunmap(struct page *page)
 
 	ASSERT_SLEEPABLE();
 
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+{
+	vaddr_t vaddr1;
+
+	if (mm_md_direct_mapped_phys(paddr, &vaddr1))
+		return;
+}
+#endif
+
 	mutex_enter(&linux_kmap_lock);
 	struct linux_kmap_entry *const lke =
 	rb_tree_find_node(&linux_kmap_entries, &paddr);



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:19:54 UTC 2014

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

Log Message:
Tweak style.

No functional change intended.  Assembly differences appear to be
only related to kassert line numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.8 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.9
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.8	Wed Aug 27 16:11:24 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:19:54 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.8 2014/08/27 16:11:24 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.9 2014/08/27 16:19:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.8 2014/08/27 16:11:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.9 2014/08/27 16:19:54 riastradh Exp $");
 
 #include 
 #include 
@@ -144,16 +144,13 @@ void *
 kmap_atomic(struct page *page)
 {
 	const paddr_t paddr = uvm_vm_page_to_phys(&page->p_vmp);
+	vaddr_t vaddr;
 
 	mutex_spin_enter(&linux_kmap_atomic_lock);
-
 	KASSERT(linux_kmap_atomic_vaddr != 0);
 	KASSERT(!pmap_extract(pmap_kernel(), linux_kmap_atomic_vaddr, NULL));
-
-	const vaddr_t vaddr = linux_kmap_atomic_vaddr;
-	const int prot = (VM_PROT_READ | VM_PROT_WRITE);
-	const int flags = 0;
-	pmap_kenter_pa(vaddr, paddr, prot, flags);
+	vaddr = linux_kmap_atomic_vaddr;
+	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
 	return (void *)vaddr;
@@ -178,10 +175,11 @@ void *
 kmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
+	vaddr_t vaddr;
 
 	ASSERT_SLEEPABLE();
 
-	const vaddr_t vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
+	vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 	(UVM_KMF_VAONLY | UVM_KMF_WAITVA));
 	KASSERT(vaddr != 0);
 
@@ -197,9 +195,7 @@ kmap(struct page *page)
 	mutex_exit(&linux_kmap_lock);
 
 	KASSERT(!pmap_extract(pmap_kernel(), vaddr, NULL));
-	const int prot = (VM_PROT_READ | VM_PROT_WRITE);
-	const int flags = 0;
-	pmap_kenter_pa(vaddr, paddr, prot, flags);
+	pmap_kenter_pa(vaddr, paddr, (VM_PROT_READ | VM_PROT_WRITE), 0);
 	pmap_update(pmap_kernel());
 
 	return (void *)vaddr;



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:11:24 UTC 2014

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

Log Message:
__diagused, not __unused.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.7 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.8
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.7	Wed Aug 27 16:09:16 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:11:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.7 2014/08/27 16:09:16 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.8 2014/08/27 16:11:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.7 2014/08/27 16:09:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.8 2014/08/27 16:11:24 riastradh Exp $");
 
 #include 
 #include 
@@ -191,7 +191,7 @@ kmap(struct page *page)
 	lke->lke_vaddr = vaddr;
 
 	mutex_enter(&linux_kmap_lock);
-	struct linux_kmap_entry *const collision __unused =
+	struct linux_kmap_entry *const collision __diagused =
 	rb_tree_insert_node(&linux_kmap_entries, lke);
 	KASSERT(collision == lke);
 	mutex_exit(&linux_kmap_lock);



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:09:16 UTC 2014

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

Log Message:
Assert sleepable in Linux kmap/kunmap.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.6 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.7
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.6	Wed Aug 27 16:06:38 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:09:16 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.6 2014/08/27 16:06:38 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.7 2014/08/27 16:09:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.6 2014/08/27 16:06:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.7 2014/08/27 16:09:16 riastradh Exp $");
 
 #include 
 #include 
@@ -178,6 +178,9 @@ void *
 kmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
+
+	ASSERT_SLEEPABLE();
+
 	const vaddr_t vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 	(UVM_KMF_VAONLY | UVM_KMF_WAITVA));
 	KASSERT(vaddr != 0);
@@ -207,6 +210,8 @@ kunmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
 
+	ASSERT_SLEEPABLE();
+
 	mutex_enter(&linux_kmap_lock);
 	struct linux_kmap_entry *const lke =
 	rb_tree_find_node(&linux_kmap_entries, &paddr);



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:06:38 UTC 2014

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

Log Message:
Simplify empty test for linux_kmap_entries.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.5 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.5	Wed Aug 27 16:05:38 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:06:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.5 2014/08/27 16:05:38 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.6 2014/08/27 16:06:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.5 2014/08/27 16:05:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.6 2014/08/27 16:06:38 riastradh Exp $");
 
 #include 
 #include 
@@ -125,9 +125,8 @@ void
 linux_kmap_fini(void)
 {
 
-	KASSERT(rb_tree_iterate(&linux_kmap_entries, NULL, RB_DIR_RIGHT) ==
-	NULL);
-#if 0/* XXX no rb_tree_destroy*/
+	KASSERT(RB_TREE_MIN(&linux_kmap_entries) == NULL);
+#if 0/* XXX no rb_tree_destroy */
 	rb_tree_destroy(&linux_kmap_entries);
 #endif
 	mutex_destroy(&linux_kmap_lock);



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

2014-08-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 27 16:05:38 UTC 2014

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

Log Message:
Convert linux_kmap_lock to an adaptive lock.

kmap/kunmap can't be used in interrupt context anyway, so there is no
need for this to be a spin lock.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.4 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.4	Fri Mar 28 23:22:27 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Wed Aug 27 16:05:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.4 2014/03/28 23:22:27 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.5 2014/08/27 16:05:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.4 2014/03/28 23:22:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.5 2014/08/27 16:05:38 riastradh Exp $");
 
 #include 
 #include 
@@ -106,7 +106,7 @@ int
 linux_kmap_init(void)
 {
 
-	/* IPL_VM is needed to block pmap_kenter_pa.  */
+	/* IPL_VM since interrupt handlers use kmap_atomic.  */
 	mutex_init(&linux_kmap_atomic_lock, MUTEX_DEFAULT, IPL_VM);
 
 	linux_kmap_atomic_vaddr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
@@ -115,7 +115,7 @@ linux_kmap_init(void)
 	KASSERT(linux_kmap_atomic_vaddr != 0);
 	KASSERT(!pmap_extract(pmap_kernel(), linux_kmap_atomic_vaddr, NULL));
 
-	mutex_init(&linux_kmap_lock, MUTEX_DEFAULT, IPL_VM);
+	mutex_init(&linux_kmap_lock, MUTEX_DEFAULT, IPL_NONE);
 	rb_tree_init(&linux_kmap_entries, &linux_kmap_entry_ops);
 
 	return 0;
@@ -188,11 +188,11 @@ kmap(struct page *page)
 	lke->lke_paddr = paddr;
 	lke->lke_vaddr = vaddr;
 
-	mutex_spin_enter(&linux_kmap_lock);
+	mutex_enter(&linux_kmap_lock);
 	struct linux_kmap_entry *const collision __unused =
 	rb_tree_insert_node(&linux_kmap_entries, lke);
 	KASSERT(collision == lke);
-	mutex_spin_exit(&linux_kmap_lock);
+	mutex_exit(&linux_kmap_lock);
 
 	KASSERT(!pmap_extract(pmap_kernel(), vaddr, NULL));
 	const int prot = (VM_PROT_READ | VM_PROT_WRITE);
@@ -208,12 +208,12 @@ kunmap(struct page *page)
 {
 	const paddr_t paddr = VM_PAGE_TO_PHYS(&page->p_vmp);
 
-	mutex_spin_enter(&linux_kmap_lock);
+	mutex_enter(&linux_kmap_lock);
 	struct linux_kmap_entry *const lke =
 	rb_tree_find_node(&linux_kmap_entries, &paddr);
 	KASSERT(lke != NULL);
 	rb_tree_remove_node(&linux_kmap_entries, lke);
-	mutex_spin_exit(&linux_kmap_lock);
+	mutex_exit(&linux_kmap_lock);
 
 	const vaddr_t vaddr = lke->lke_vaddr;
 	kmem_free(lke, sizeof(*lke));



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

2014-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 29 17:36:06 UTC 2014

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

Log Message:
Linux wq locks are taken with spin locks held, so need IPL_VM.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.6 src/sys/external/bsd/drm2/linux/linux_work.c:1.7
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.6	Sun Jul 27 14:02:48 2014
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Tue Jul 29 17:36:06 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.7 2014/07/29 17:36:06 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.7 2014/07/29 17:36:06 riastradh Exp $");
 
 #include 
 #include 
@@ -129,7 +129,7 @@ alloc_ordered_workqueue(const char *name
 		return NULL;
 	}
 
-	mutex_init(&wq->wq_lock, MUTEX_DEFAULT, IPL_NONE);
+	mutex_init(&wq->wq_lock, MUTEX_DEFAULT, IPL_VM);
 	cv_init(&wq->wq_cv, name);
 	TAILQ_INIT(&wq->wq_delayed);
 	wq->wq_current_work = NULL;



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

2014-07-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 27 14:02:48 UTC 2014

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

Log Message:
Linux work is queued in intr context, so block intrs when locking.

(Yes, this getting out of hand.)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.5 src/sys/external/bsd/drm2/linux/linux_work.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.5	Fri Jul 25 16:15:12 2014
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Sun Jul 27 14:02:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.6 2014/07/27 14:02:48 riastradh Exp $");
 
 #include 
 #include 
@@ -281,24 +281,49 @@ linux_wq_barrier(struct work_struct *wor
  *
  * We use __cpu_simple_lock(9) rather than mutex(9) because Linux code
  * does not destroy work, so there is nowhere to call mutex_destroy.
+ *
+ * XXX This is getting out of hand...  Really, work items shouldn't
+ * have locks in them at all; instead the workqueues should.
  */
 
 static void
 linux_work_lock_init(struct work_struct *work)
 {
+
 	__cpu_simple_lock_init(&work->w_lock);
 }
 
 static void
 linux_work_lock(struct work_struct *work)
 {
+	struct cpu_info *ci;
+	int cnt, s;
+
+	/* XXX Copypasta of MUTEX_SPIN_SPLRAISE.  */
+	s = splvm();
+	ci = curcpu();
+	cnt = ci->ci_mtx_count--;
+	__insn_barrier();
+	if (cnt == 0)
+		ci->ci_mtx_oldspl = s;
+
 	__cpu_simple_lock(&work->w_lock);
 }
 
 static void
 linux_work_unlock(struct work_struct *work)
 {
+	struct cpu_info *ci;
+	int s;
+
 	__cpu_simple_unlock(&work->w_lock);
+
+	/* XXX Copypasta of MUTEX_SPIN_SPLRESTORE.  */
+	ci = curcpu();
+	s = ci->ci_mtx_oldspl;
+	__insn_barrier();
+	if (++ci->ci_mtx_count == 0)
+		splx(s);
 }
 
 static bool __diagused



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

2014-07-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Jul 25 16:15:12 UTC 2014

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

Log Message:
This case is not supposed to fall through!


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/linux/linux_work.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_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.4 src/sys/external/bsd/drm2/linux/linux_work.c:1.5
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.4	Wed Jul 16 20:59:58 2014
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Fri Jul 25 16:15:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.4 2014/07/16 20:59:58 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.4 2014/07/16 20:59:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.5 2014/07/25 16:15:12 riastradh Exp $");
 
 #include 
 #include 
@@ -703,6 +703,7 @@ cancel_delayed_work_sync(struct delayed_
 		dw->work.w_state = WORK_CANCELLED;
 		linux_wait_for_cancelled_work(&dw->work);
 		cancelled_p = true;
+		break;
 
 	case WORK_INVOKED:
 		linux_wait_for_invoked_work(&dw->work);



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

2014-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 28 23:22:27 UTC 2014

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

Log Message:
Don't leak KVA by forgetting to call uvm_km_free...oops!

>From rmind@.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.3 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.3	Fri Mar 28 23:19:41 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Fri Mar 28 23:22:27 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.3 2014/03/28 23:19:41 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.4 2014/03/28 23:22:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.3 2014/03/28 23:19:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.4 2014/03/28 23:22:27 riastradh Exp $");
 
 #include 
 #include 
@@ -222,4 +222,6 @@ kunmap(struct page *page)
 
 	pmap_kremove(vaddr, PAGE_SIZE);
 	pmap_update(pmap_kernel());
+
+	uvm_km_free(kernel_map, vaddr, PAGE_SIZE, UVM_KMF_VAONLY);
 }



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

2014-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 28 23:19:41 UTC 2014

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

Log Message:
Remove needless splvm/splx calls.

>From rmind@, who explained that the pmap(9) man page is wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_kmap.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_kmap.c
diff -u src/sys/external/bsd/drm2/linux/linux_kmap.c:1.2 src/sys/external/bsd/drm2/linux/linux_kmap.c:1.3
--- src/sys/external/bsd/drm2/linux/linux_kmap.c:1.2	Tue Mar 18 18:20:43 2014
+++ src/sys/external/bsd/drm2/linux/linux_kmap.c	Fri Mar 28 23:19:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_kmap.c,v 1.2 2014/03/18 18:20:43 riastradh Exp $	*/
+/*	$NetBSD: linux_kmap.c,v 1.3 2014/03/28 23:19:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.2 2014/03/18 18:20:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_kmap.c,v 1.3 2014/03/28 23:19:41 riastradh Exp $");
 
 #include 
 #include 
@@ -194,16 +194,12 @@ kmap(struct page *page)
 	KASSERT(collision == lke);
 	mutex_spin_exit(&linux_kmap_lock);
 
-	const int s = splvm();
-
 	KASSERT(!pmap_extract(pmap_kernel(), vaddr, NULL));
 	const int prot = (VM_PROT_READ | VM_PROT_WRITE);
 	const int flags = 0;
 	pmap_kenter_pa(vaddr, paddr, prot, flags);
 	pmap_update(pmap_kernel());
 
-	splx(s);
-
 	return (void *)vaddr;
 }
 
@@ -222,12 +218,8 @@ kunmap(struct page *page)
 	const vaddr_t vaddr = lke->lke_vaddr;
 	kmem_free(lke, sizeof(*lke));
 
-	const int s = splvm();
-
 	KASSERT(pmap_extract(pmap_kernel(), vaddr, NULL));
 
 	pmap_kremove(vaddr, PAGE_SIZE);
 	pmap_update(pmap_kernel());
-
-	splx(s);
 }