xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/i915/selftests/mock_request.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1*41ec0267Sriastradh /*	$NetBSD: mock_request.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
24e390cabSriastradh 
34e390cabSriastradh /*
44e390cabSriastradh  * Copyright © 2016 Intel Corporation
54e390cabSriastradh  *
64e390cabSriastradh  * Permission is hereby granted, free of charge, to any person obtaining a
74e390cabSriastradh  * copy of this software and associated documentation files (the "Software"),
84e390cabSriastradh  * to deal in the Software without restriction, including without limitation
94e390cabSriastradh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
104e390cabSriastradh  * and/or sell copies of the Software, and to permit persons to whom the
114e390cabSriastradh  * Software is furnished to do so, subject to the following conditions:
124e390cabSriastradh  *
134e390cabSriastradh  * The above copyright notice and this permission notice (including the next
144e390cabSriastradh  * paragraph) shall be included in all copies or substantial portions of the
154e390cabSriastradh  * Software.
164e390cabSriastradh  *
174e390cabSriastradh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184e390cabSriastradh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194e390cabSriastradh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
204e390cabSriastradh  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
214e390cabSriastradh  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
224e390cabSriastradh  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
234e390cabSriastradh  * IN THE SOFTWARE.
244e390cabSriastradh  *
254e390cabSriastradh  */
264e390cabSriastradh 
274e390cabSriastradh #include <sys/cdefs.h>
28*41ec0267Sriastradh __KERNEL_RCSID(0, "$NetBSD: mock_request.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $");
294e390cabSriastradh 
304e390cabSriastradh #include "gem/selftests/igt_gem_utils.h"
314e390cabSriastradh #include "gt/mock_engine.h"
324e390cabSriastradh 
334e390cabSriastradh #include "mock_request.h"
344e390cabSriastradh 
354e390cabSriastradh struct i915_request *
mock_request(struct intel_context * ce,unsigned long delay)364e390cabSriastradh mock_request(struct intel_context *ce, unsigned long delay)
374e390cabSriastradh {
384e390cabSriastradh 	struct i915_request *request;
394e390cabSriastradh 
404e390cabSriastradh 	/* NB the i915->requests slab cache is enlarged to fit mock_request */
414e390cabSriastradh 	request = intel_context_create_request(ce);
424e390cabSriastradh 	if (IS_ERR(request))
434e390cabSriastradh 		return NULL;
444e390cabSriastradh 
454e390cabSriastradh 	request->mock.delay = delay;
464e390cabSriastradh 	return request;
474e390cabSriastradh }
484e390cabSriastradh 
mock_cancel_request(struct i915_request * request)494e390cabSriastradh bool mock_cancel_request(struct i915_request *request)
504e390cabSriastradh {
514e390cabSriastradh 	struct mock_engine *engine =
524e390cabSriastradh 		container_of(request->engine, typeof(*engine), base);
534e390cabSriastradh 	bool was_queued;
544e390cabSriastradh 
554e390cabSriastradh 	spin_lock_irq(&engine->hw_lock);
564e390cabSriastradh 	was_queued = !list_empty(&request->mock.link);
574e390cabSriastradh 	list_del_init(&request->mock.link);
584e390cabSriastradh 	spin_unlock_irq(&engine->hw_lock);
594e390cabSriastradh 
604e390cabSriastradh 	if (was_queued)
614e390cabSriastradh 		i915_request_unsubmit(request);
624e390cabSriastradh 
634e390cabSriastradh 	return was_queued;
644e390cabSriastradh }
65