xref: /netbsd-src/sys/external/bsd/drm2/i915drm/i915_gem_userptr.c (revision 16f9b7f63b3c548e0c894863911cfa8cc4f5ab9e)
1*16f9b7f6Sriastradh /*	$NetBSD: i915_gem_userptr.c,v 1.5 2021/12/19 12:10:34 riastradh Exp $	*/
208f96d08Sriastradh 
308f96d08Sriastradh /*-
408f96d08Sriastradh  * Copyright (c) 2018 The NetBSD Foundation, Inc.
508f96d08Sriastradh  * All rights reserved.
608f96d08Sriastradh  *
708f96d08Sriastradh  * This code is derived from software contributed to The NetBSD Foundation
808f96d08Sriastradh  * by Taylor R. Campbell.
908f96d08Sriastradh  *
1008f96d08Sriastradh  * Redistribution and use in source and binary forms, with or without
1108f96d08Sriastradh  * modification, are permitted provided that the following conditions
1208f96d08Sriastradh  * are met:
1308f96d08Sriastradh  * 1. Redistributions of source code must retain the above copyright
1408f96d08Sriastradh  *    notice, this list of conditions and the following disclaimer.
1508f96d08Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
1608f96d08Sriastradh  *    notice, this list of conditions and the following disclaimer in the
1708f96d08Sriastradh  *    documentation and/or other materials provided with the distribution.
1808f96d08Sriastradh  *
1908f96d08Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2008f96d08Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2108f96d08Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2208f96d08Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2308f96d08Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2408f96d08Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2508f96d08Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2608f96d08Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2708f96d08Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2808f96d08Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2908f96d08Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
3008f96d08Sriastradh  */
3108f96d08Sriastradh 
3208f96d08Sriastradh #include <sys/cdefs.h>
33*16f9b7f6Sriastradh __KERNEL_RCSID(0, "$NetBSD: i915_gem_userptr.c,v 1.5 2021/12/19 12:10:34 riastradh Exp $");
3408f96d08Sriastradh 
3508f96d08Sriastradh #include "i915_drv.h"
36983296bcSriastradh #include "../dist/drm/i915/gem/i915_gem_ioctls.h"
3708f96d08Sriastradh 
38*16f9b7f6Sriastradh #include <linux/nbsd-namespace.h>
39*16f9b7f6Sriastradh 
40*16f9b7f6Sriastradh /*
41*16f9b7f6Sriastradh  * XXX this file is dumb and maybe shouldn't exist; it exists because
42*16f9b7f6Sriastradh  * riastradh is a lazybones
43*16f9b7f6Sriastradh  */
44*16f9b7f6Sriastradh 
4508f96d08Sriastradh int
i915_gem_init_userptr(struct drm_i915_private * dev_priv)46*16f9b7f6Sriastradh i915_gem_init_userptr(struct drm_i915_private *dev_priv)
4708f96d08Sriastradh {
48*16f9b7f6Sriastradh 	mutex_init(&dev_priv->mm_lock);
49*16f9b7f6Sriastradh 	hash_init(dev_priv->mm_structs);
50*16f9b7f6Sriastradh 
51*16f9b7f6Sriastradh 	dev_priv->mm.userptr_wq =
52*16f9b7f6Sriastradh 		alloc_workqueue("i915-userptr-acquire",
53*16f9b7f6Sriastradh 				WQ_HIGHPRI | WQ_UNBOUND,
54*16f9b7f6Sriastradh 				0);
55*16f9b7f6Sriastradh 	if (!dev_priv->mm.userptr_wq)
56*16f9b7f6Sriastradh 		return -ENOMEM;
57*16f9b7f6Sriastradh 
5808f96d08Sriastradh 	return 0;
5908f96d08Sriastradh }
6008f96d08Sriastradh 
619c351cd5Sriastradh void
i915_gem_cleanup_userptr(struct drm_i915_private * dev_priv)62*16f9b7f6Sriastradh i915_gem_cleanup_userptr(struct drm_i915_private *dev_priv)
639c351cd5Sriastradh {
64*16f9b7f6Sriastradh 	destroy_workqueue(dev_priv->mm.userptr_wq);
65*16f9b7f6Sriastradh 	mutex_destroy(&dev_priv->mm_lock);
669c351cd5Sriastradh }
679c351cd5Sriastradh 
6808f96d08Sriastradh int
i915_gem_userptr_ioctl(struct drm_device * dev,void * data,struct drm_file * file)6908f96d08Sriastradh i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
7008f96d08Sriastradh     struct drm_file *file)
7108f96d08Sriastradh {
7208f96d08Sriastradh 	return -ENODEV;
7308f96d08Sriastradh }
74