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 25*112ed2d3SChris Wilson #include "gt/mock_engine.h" 26*112ed2d3SChris Wilson 270daf0113SChris Wilson #include "mock_request.h" 280daf0113SChris Wilson 29e61e0f51SChris Wilson struct i915_request * 300daf0113SChris Wilson mock_request(struct intel_engine_cs *engine, 310daf0113SChris Wilson struct i915_gem_context *context, 320daf0113SChris Wilson unsigned long delay) 330daf0113SChris Wilson { 34e61e0f51SChris Wilson struct i915_request *request; 350daf0113SChris Wilson 360daf0113SChris Wilson /* NB the i915->requests slab cache is enlarged to fit mock_request */ 37e61e0f51SChris Wilson request = i915_request_alloc(engine, context); 385af9e672SDan Carpenter if (IS_ERR(request)) 390daf0113SChris Wilson return NULL; 400daf0113SChris Wilson 4132eb6bcfSChris Wilson request->mock.delay = delay; 4232eb6bcfSChris Wilson return request; 430daf0113SChris Wilson } 44591c0fb8SChris Wilson 45e61e0f51SChris Wilson bool mock_cancel_request(struct i915_request *request) 46591c0fb8SChris Wilson { 47591c0fb8SChris Wilson struct mock_engine *engine = 48591c0fb8SChris Wilson container_of(request->engine, typeof(*engine), base); 49591c0fb8SChris Wilson bool was_queued; 50591c0fb8SChris Wilson 51591c0fb8SChris Wilson spin_lock_irq(&engine->hw_lock); 5232eb6bcfSChris Wilson was_queued = !list_empty(&request->mock.link); 5332eb6bcfSChris Wilson list_del_init(&request->mock.link); 54591c0fb8SChris Wilson spin_unlock_irq(&engine->hw_lock); 55591c0fb8SChris Wilson 56591c0fb8SChris Wilson if (was_queued) 57e61e0f51SChris Wilson i915_request_unsubmit(request); 58591c0fb8SChris Wilson 59591c0fb8SChris Wilson return was_queued; 60591c0fb8SChris Wilson } 61