10daf0113SChris Wilson /*
20daf0113SChris Wilson * Copyright © 2016 Intel Corporation
30daf0113SChris Wilson *
40daf0113SChris Wilson * Permission is hereby granted, free of charge, to any person obtaining a
50daf0113SChris Wilson * copy of this software and associated documentation files (the "Software"),
60daf0113SChris Wilson * to deal in the Software without restriction, including without limitation
70daf0113SChris Wilson * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80daf0113SChris Wilson * and/or sell copies of the Software, and to permit persons to whom the
90daf0113SChris Wilson * Software is furnished to do so, subject to the following conditions:
100daf0113SChris Wilson *
110daf0113SChris Wilson * The above copyright notice and this permission notice (including the next
120daf0113SChris Wilson * paragraph) shall be included in all copies or substantial portions of the
130daf0113SChris Wilson * Software.
140daf0113SChris Wilson *
150daf0113SChris Wilson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
160daf0113SChris Wilson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
170daf0113SChris Wilson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
180daf0113SChris Wilson * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
190daf0113SChris Wilson * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
200daf0113SChris Wilson * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
210daf0113SChris Wilson * IN THE SOFTWARE.
220daf0113SChris Wilson *
230daf0113SChris Wilson */
240daf0113SChris Wilson
2510be98a7SChris Wilson #include "gem/selftests/igt_gem_utils.h"
26112ed2d3SChris Wilson #include "gt/mock_engine.h"
27112ed2d3SChris Wilson
280daf0113SChris Wilson #include "mock_request.h"
290daf0113SChris Wilson
30e61e0f51SChris Wilson struct i915_request *
mock_request(struct intel_context * ce,unsigned long delay)31*ca883c30SChris Wilson mock_request(struct intel_context *ce, unsigned long delay)
320daf0113SChris Wilson {
33e61e0f51SChris Wilson struct i915_request *request;
340daf0113SChris Wilson
350daf0113SChris Wilson /* NB the i915->requests slab cache is enlarged to fit mock_request */
36*ca883c30SChris Wilson request = intel_context_create_request(ce);
375af9e672SDan Carpenter if (IS_ERR(request))
380daf0113SChris Wilson return NULL;
390daf0113SChris Wilson
4032eb6bcfSChris Wilson request->mock.delay = delay;
4132eb6bcfSChris Wilson return request;
420daf0113SChris Wilson }
43591c0fb8SChris Wilson
mock_cancel_request(struct i915_request * request)44e61e0f51SChris Wilson bool mock_cancel_request(struct i915_request *request)
45591c0fb8SChris Wilson {
46591c0fb8SChris Wilson struct mock_engine *engine =
47591c0fb8SChris Wilson container_of(request->engine, typeof(*engine), base);
48591c0fb8SChris Wilson bool was_queued;
49591c0fb8SChris Wilson
50591c0fb8SChris Wilson spin_lock_irq(&engine->hw_lock);
5132eb6bcfSChris Wilson was_queued = !list_empty(&request->mock.link);
5232eb6bcfSChris Wilson list_del_init(&request->mock.link);
53591c0fb8SChris Wilson spin_unlock_irq(&engine->hw_lock);
54591c0fb8SChris Wilson
55591c0fb8SChris Wilson if (was_queued)
56e61e0f51SChris Wilson i915_request_unsubmit(request);
57591c0fb8SChris Wilson
58591c0fb8SChris Wilson return was_queued;
59591c0fb8SChris Wilson }
60