18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright © 2016 Intel Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 218c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "gem/selftests/igt_gem_utils.h" 268c2ecf20Sopenharmony_ci#include "gt/mock_engine.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "mock_request.h" 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct i915_request * 318c2ecf20Sopenharmony_cimock_request(struct intel_context *ce, unsigned long delay) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci struct i915_request *request; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* NB the i915->requests slab cache is enlarged to fit mock_request */ 368c2ecf20Sopenharmony_ci request = intel_context_create_request(ce); 378c2ecf20Sopenharmony_ci if (IS_ERR(request)) 388c2ecf20Sopenharmony_ci return NULL; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci request->mock.delay = delay; 418c2ecf20Sopenharmony_ci return request; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cibool mock_cancel_request(struct i915_request *request) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci struct mock_engine *engine = 478c2ecf20Sopenharmony_ci container_of(request->engine, typeof(*engine), base); 488c2ecf20Sopenharmony_ci bool was_queued; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci spin_lock_irq(&engine->hw_lock); 518c2ecf20Sopenharmony_ci was_queued = !list_empty(&request->mock.link); 528c2ecf20Sopenharmony_ci list_del_init(&request->mock.link); 538c2ecf20Sopenharmony_ci spin_unlock_irq(&engine->hw_lock); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci if (was_queued) 568c2ecf20Sopenharmony_ci i915_request_unsubmit(request); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci return was_queued; 598c2ecf20Sopenharmony_ci} 60