Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 01:51:27 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/dist/drm: drm_mm.c
        src/sys/external/bsd/drm2/dist/drm/i915: i915_request.c
        src/sys/external/bsd/drm2/drm: files.drmkms
        src/sys/external/bsd/drm2/i915drm: files.i915drmkms
        src/sys/external/bsd/drm2/include/linux: interval_tree_generic.h
            sched.h

Log Message:
misc drm hacks


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/drm2/dist/drm/drm_mm.c
cvs rdiff -u -r1.3 -r1.4 \
    src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c
cvs rdiff -u -r1.46 -r1.47 src/sys/external/bsd/drm2/drm/files.drmkms
cvs rdiff -u -r1.52 -r1.53 src/sys/external/bsd/drm2/i915drm/files.i915drmkms
cvs rdiff -u -r1.1 -r1.2 \
    src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h
cvs rdiff -u -r1.16 -r1.17 src/sys/external/bsd/drm2/include/linux/sched.h

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

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/drm_mm.c
diff -u src/sys/external/bsd/drm2/dist/drm/drm_mm.c:1.7 src/sys/external/bsd/drm2/dist/drm/drm_mm.c:1.8
--- src/sys/external/bsd/drm2/dist/drm/drm_mm.c:1.7	Sat Dec 18 23:44:57 2021
+++ src/sys/external/bsd/drm2/dist/drm/drm_mm.c	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_mm.c,v 1.7 2021/12/18 23:44:57 riastradh Exp $	*/
+/*	$NetBSD: drm_mm.c,v 1.8 2021/12/19 01:51:27 riastradh Exp $	*/
 
 /**************************************************************************
  *
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_mm.c,v 1.7 2021/12/18 23:44:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_mm.c,v 1.8 2021/12/19 01:51:27 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/interval_tree_generic.h>
@@ -217,6 +217,7 @@ static void drm_mm_interval_tree_add_nod
 				   &drm_mm_interval_tree_augment);
 }
 
+#ifndef __NetBSD__
 #define RB_INSERT(root, member, expr) do { \
 	struct rb_node **link = &root.rb_node, *rb = NULL; \
 	u64 x = expr(node); \
@@ -230,6 +231,7 @@ static void drm_mm_interval_tree_add_nod
 	rb_link_node(&node->member, rb, link); \
 	rb_insert_color(&node->member, &root); \
 } while (0)
+#endif
 
 #define HOLE_SIZE(NODE) ((NODE)->hole_size)
 #define HOLE_ADDR(NODE) (__drm_mm_hole_node_start(NODE))
@@ -269,7 +271,12 @@ static void add_hole(struct drm_mm_node 
 	DRM_MM_BUG_ON(!drm_mm_hole_follows(node));
 
 	insert_hole_size(&mm->holes_size, node);
+#ifdef __NetBSD__
+	struct rb_node *collision __diagused;
+	collision = rb_tree_insert_node(&mm->holes_addr
+#else
 	RB_INSERT(mm->holes_addr, rb_hole_addr, HOLE_ADDR);
+#endif
 
 	list_add(&node->hole_stack, &mm->hole_stack);
 }

Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c
diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c:1.3 src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c:1.4
--- src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c:1.3	Sun Dec 19 01:24:26 2021
+++ src/sys/external/bsd/drm2/dist/drm/i915/i915_request.c	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i915_request.c,v 1.3 2021/12/19 01:24:26 riastradh Exp $	*/
+/*	$NetBSD: i915_request.c,v 1.4 2021/12/19 01:51:27 riastradh Exp $	*/
 
 /*
  * Copyright © 2008-2015 Intel Corporation
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_request.c,v 1.3 2021/12/19 01:24:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_request.c,v 1.4 2021/12/19 01:51:27 riastradh Exp $");
 
 #include <linux/dma-fence-array.h>
 #include <linux/irq_work.h>
@@ -121,6 +121,9 @@ static void i915_fence_release(struct dm
 	i915_sw_fence_fini(&rq->submit);
 	i915_sw_fence_fini(&rq->semaphore);
 
+	DRM_DESTROY_WAITQUEUE(&rq->execute);
+	dma_fence_destroy(&rq->fence);
+	spin_lock_destroy(&rq->lock);
 	kmem_cache_free(global.slab_requests, rq);
 }
 
@@ -1196,10 +1199,10 @@ void i915_request_skip(struct i915_reque
 	 */
 	head = rq->infix;
 	if (rq->postfix < head) {
-		memset(vaddr + head, 0, rq->ring->size - head);
+		memset((char *)vaddr + head, 0, rq->ring->size - head);
 		head = 0;
 	}
-	memset(vaddr + head, 0, rq->postfix - head);
+	memset((char *)vaddr + head, 0, rq->postfix - head);
 	rq->infix = rq->postfix;
 }
 
@@ -1354,9 +1357,17 @@ void i915_request_add(struct i915_reques
 	if (list_empty(&rq->sched.signalers_list))
 		attr.priority |= I915_PRIORITY_WAIT;
 
+#ifdef __NetBSD__
+	int s = splsoftserial();
+#else
 	local_bh_disable();
+#endif
 	__i915_request_queue(rq, &attr);
+#ifdef __NetBSD__
+	splx(s);
+#else
 	local_bh_enable(); /* Kick the execlists tasklet if just scheduled */
+#endif
 
 	/*
 	 * In typical scenarios, we do not expect the previous request on

Index: src/sys/external/bsd/drm2/drm/files.drmkms
diff -u src/sys/external/bsd/drm2/drm/files.drmkms:1.46 src/sys/external/bsd/drm2/drm/files.drmkms:1.47
--- src/sys/external/bsd/drm2/drm/files.drmkms:1.46	Sun Dec 19 01:46:39 2021
+++ src/sys/external/bsd/drm2/drm/files.drmkms	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.drmkms,v 1.46 2021/12/19 01:46:39 riastradh Exp $
+#	$NetBSD: files.drmkms,v 1.47 2021/12/19 01:51:27 riastradh Exp $
 
 version	20180827
 
@@ -103,7 +103,7 @@ file	external/bsd/drm2/dist/drm/drm_irq.
 file	external/bsd/drm2/drm/drm_lease.c	drmkms
 file	external/bsd/drm2/drm/drm_lock.c	drmkms
 file	external/bsd/drm2/drm/drm_memory.c	drmkms
-file	external/bsd/drm2/dist/drm/drm_mm.c	drmkms
+#file	external/bsd/drm2/dist/drm/drm_mm.c	drmkms
 file	external/bsd/drm2/dist/drm/drm_mode_config.c	drmkms
 file	external/bsd/drm2/dist/drm/drm_mode_object.c	drmkms
 file	external/bsd/drm2/dist/drm/drm_modes.c	drmkms

Index: src/sys/external/bsd/drm2/i915drm/files.i915drmkms
diff -u src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.52 src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.53
--- src/sys/external/bsd/drm2/i915drm/files.i915drmkms:1.52	Sun Dec 19 01:42:48 2021
+++ src/sys/external/bsd/drm2/i915drm/files.i915drmkms	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i915drmkms,v 1.52 2021/12/19 01:42:48 riastradh Exp $
+#	$NetBSD: files.i915drmkms,v 1.53 2021/12/19 01:51:27 riastradh Exp $
 
 version	20180827
 
@@ -184,7 +184,7 @@ file	external/bsd/drm2/dist/drm/i915/i91
 file	external/bsd/drm2/dist/drm/i915/i915_gem_gtt.c	i915drmkms
 file	external/bsd/drm2/dist/drm/i915/i915_getparam.c	i915drmkms
 file	external/bsd/drm2/dist/drm/i915/i915_globals.c	i915drmkms
-file	external/bsd/drm2/dist/drm/i915/i915_irq.c	i915drmkms
+#file	external/bsd/drm2/dist/drm/i915/i915_irq.c	i915drmkms
 file	external/bsd/drm2/dist/drm/i915/i915_memcpy.c	i915drmkms
 #file	external/bsd/drm2/dist/drm/i915/i915_mm.c	i915drmkms
 file	external/bsd/drm2/dist/drm/i915/i915_params.c	i915drmkms

Index: src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h
diff -u src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h:1.1 src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h:1.2
--- src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h:1.1	Sun Dec 19 00:28:55 2021
+++ src/sys/external/bsd/drm2/include/linux/interval_tree_generic.h	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: interval_tree_generic.h,v 1.1 2021/12/19 00:28:55 riastradh Exp $	*/
+/*	$NetBSD: interval_tree_generic.h,v 1.2 2021/12/19 01:51:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,4 +32,82 @@
 #ifndef	_LINUX_INTERVAL_TREE_GENERIC_H_
 #define	_LINUX_INTERVAL_TREE_GENERIC_H_
 
+#define	INTERVAL_TREE_DEFINE(T, F, KT, KLAST, NSTART, NLAST, QUAL, PREFIX)    \
+									      \
+static inline int							      \
+PREFIX##__compare_nodes(void *__cookie, const void *__va, const void *__vb)   \
+{									      \
+	const T *__na = __va;						      \
+	const T *__nb = __vb;						      \
+	const KT __astart = START(__na), __alast = LAST(__na);		      \
+	const KT __bstart = START(__nb), __blast = LAST(__nb);		      \
+									      \
+	if (__astart < __bstart)					      \
+		return -1;						      \
+	if (__astart > __bstart)					      \
+		return +1;						      \
+	if (__alast < __blast)						      \
+		return -1;						      \
+	if (__alast > __blast)						      \
+		return -1;						      \
+	return 0;		       					      \
+}									      \
+									      \
+static inline int							      \
+PREFIX##__compare_key(void *__cookie, const void *__vn, const void *__vk)     \
+{									      \
+	const T *__n = __vn;						      \
+	const T *__k = __vk;						      \
+	const KT __nstart = START(__n), __nlast = LAST(__n);		      \
+									      \
+	if (__nlast < *__k)						      \
+		return -1;						      \
+	if (*__k < __nstart)						      \
+		return +1;						      \
+	return 0;							      \
+}									      \
+									      \
+static const rb_tree_ops_t PREFIX##__rbtree_ops = {			      \
+	.rbto_compare_nodes = PREFIX##__compare_nodes,			      \
+	.rbto_compare_key = PREFIX##__compare_key,			      \
+	.rbto_node_offset = offsetof(T, F),				      \
+};									      \
+									      \
+/* Not in Linux API, needed for us.  */					      \
+QUAL void								      \
+PREFIX##_init(struct rb_root_cached *__root)				      \
+{									      \
+	rb_tree_init(&__root->rbrc_tree, &PREFIX##__rbtree_ops);	      \
+}									      \
+									      \
+QUAL void								      \
+PREFIX##_insert(T *__node, struct rb_root_cached *__root)		      \
+{									      \
+	T *__collision __diagused;					      \
+									      \
+	__collision = rb_tree_insert_node(&__root->rbrc_tree, __node);	      \
+	KASSERT(__collision == __node);					      \
+}									      \
+									      \
+QUAL void								      \
+PREFIX##_remove(T *__node, struct rb_root_cached *__root)		      \
+{									      \
+	rb_tree_remove_node(&__root->rbrc_tree, __node);		      \
+}									      \
+									      \
+QUAL T *								      \
+PREFIX##_iter_first(struct rb_root_cached *__root, KT __start, KT __last)     \
+{									      \
+	T *__node;							      \
+									      \
+	__node = rb_tree_find_node_geq(&__root->rbrc_tree, &__start);	      \
+	if (__node == NULL)						      \
+		return NULL;						      \
+	KASSERT(START(__node) <= __start);				      \
+	if (__last < START(__node))					      \
+		return NULL;						      \
+									      \
+	return __node;							      \
+}
+
 #endif	/* _LINUX_INTERVAL_TREE_GENERIC_H_ */

Index: src/sys/external/bsd/drm2/include/linux/sched.h
diff -u src/sys/external/bsd/drm2/include/linux/sched.h:1.16 src/sys/external/bsd/drm2/include/linux/sched.h:1.17
--- src/sys/external/bsd/drm2/include/linux/sched.h:1.16	Sun Dec 19 01:22:44 2021
+++ src/sys/external/bsd/drm2/include/linux/sched.h	Sun Dec 19 01:51:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched.h,v 1.16 2021/12/19 01:22:44 riastradh Exp $	*/
+/*	$NetBSD: sched.h,v 1.17 2021/12/19 01:51:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -101,4 +101,14 @@ cond_resched(void)
 	preempt_point();
 }
 
+static inline bool
+signal_pending_state(int state, struct proc *p)
+{
+
+	KASSERT(p == current);
+	if (state & TASK_UNINTERRUPTIBLE)
+		return false;
+	return sigispending(curlwp, 0);
+}
+
 #endif  /* _LINUX_SCHED_H_ */

Reply via email to