1b4d3acaaSChris Wilson // SPDX-License-Identifier: MIT
2b4d3acaaSChris Wilson /*
3b4d3acaaSChris Wilson * Copyright © 2019 Intel Corporation
4b4d3acaaSChris Wilson */
5b4d3acaaSChris Wilson
6b4d3acaaSChris Wilson #include "i915_drv.h"
7b4d3acaaSChris Wilson #include "i915_vma.h"
8b4d3acaaSChris Wilson #include "intel_context.h"
9b4d3acaaSChris Wilson #include "intel_engine_pm.h"
10b4d3acaaSChris Wilson #include "intel_gpu_commands.h"
11a0d3fdb6SChris Wilson #include "intel_lrc.h"
12*dd4821baSJani Nikula #include "intel_lrc_reg.h"
13b4d3acaaSChris Wilson #include "intel_ring.h"
14b4d3acaaSChris Wilson #include "intel_sseu.h"
15b4d3acaaSChris Wilson
gen8_emit_rpcs_config(struct i915_request * rq,const struct intel_context * ce,const struct intel_sseu sseu)16b4d3acaaSChris Wilson static int gen8_emit_rpcs_config(struct i915_request *rq,
17b4d3acaaSChris Wilson const struct intel_context *ce,
18b4d3acaaSChris Wilson const struct intel_sseu sseu)
19b4d3acaaSChris Wilson {
20b4d3acaaSChris Wilson u64 offset;
21b4d3acaaSChris Wilson u32 *cs;
22b4d3acaaSChris Wilson
23b4d3acaaSChris Wilson cs = intel_ring_begin(rq, 4);
24b4d3acaaSChris Wilson if (IS_ERR(cs))
25b4d3acaaSChris Wilson return PTR_ERR(cs);
26b4d3acaaSChris Wilson
27b4d3acaaSChris Wilson offset = i915_ggtt_offset(ce->state) +
28b4892e44SMika Kuoppala LRC_STATE_OFFSET + CTX_R_PWR_CLK_STATE * 4;
29b4d3acaaSChris Wilson
30b4d3acaaSChris Wilson *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT;
31b4d3acaaSChris Wilson *cs++ = lower_32_bits(offset);
32b4d3acaaSChris Wilson *cs++ = upper_32_bits(offset);
330b6613c6SVenkata Sandeep Dhanalakota *cs++ = intel_sseu_make_rpcs(rq->engine->gt, &sseu);
34b4d3acaaSChris Wilson
35b4d3acaaSChris Wilson intel_ring_advance(rq, cs);
36b4d3acaaSChris Wilson
37b4d3acaaSChris Wilson return 0;
38b4d3acaaSChris Wilson }
39b4d3acaaSChris Wilson
40b4d3acaaSChris Wilson static int
gen8_modify_rpcs(struct intel_context * ce,const struct intel_sseu sseu)41b4d3acaaSChris Wilson gen8_modify_rpcs(struct intel_context *ce, const struct intel_sseu sseu)
42b4d3acaaSChris Wilson {
43b4d3acaaSChris Wilson struct i915_request *rq;
44b4d3acaaSChris Wilson int ret;
45b4d3acaaSChris Wilson
46b4d3acaaSChris Wilson lockdep_assert_held(&ce->pin_mutex);
47b4d3acaaSChris Wilson
48b4d3acaaSChris Wilson /*
49b4d3acaaSChris Wilson * If the context is not idle, we have to submit an ordered request to
50b4d3acaaSChris Wilson * modify its context image via the kernel context (writing to our own
51b4d3acaaSChris Wilson * image, or into the registers directory, does not stick). Pristine
52b4d3acaaSChris Wilson * and idle contexts will be configured on pinning.
53b4d3acaaSChris Wilson */
54b4d3acaaSChris Wilson if (!intel_context_pin_if_active(ce))
55b4d3acaaSChris Wilson return 0;
56b4d3acaaSChris Wilson
57b4d3acaaSChris Wilson rq = intel_engine_create_kernel_request(ce->engine);
58b4d3acaaSChris Wilson if (IS_ERR(rq)) {
59b4d3acaaSChris Wilson ret = PTR_ERR(rq);
60b4d3acaaSChris Wilson goto out_unpin;
61b4d3acaaSChris Wilson }
62b4d3acaaSChris Wilson
63b4d3acaaSChris Wilson /* Serialise with the remote context */
64b4d3acaaSChris Wilson ret = intel_context_prepare_remote_request(ce, rq);
65b4d3acaaSChris Wilson if (ret == 0)
66b4d3acaaSChris Wilson ret = gen8_emit_rpcs_config(rq, ce, sseu);
67b4d3acaaSChris Wilson
68b4d3acaaSChris Wilson i915_request_add(rq);
69b4d3acaaSChris Wilson out_unpin:
70b4d3acaaSChris Wilson intel_context_unpin(ce);
71b4d3acaaSChris Wilson return ret;
72b4d3acaaSChris Wilson }
73b4d3acaaSChris Wilson
74b4d3acaaSChris Wilson int
intel_context_reconfigure_sseu(struct intel_context * ce,const struct intel_sseu sseu)75b4d3acaaSChris Wilson intel_context_reconfigure_sseu(struct intel_context *ce,
76b4d3acaaSChris Wilson const struct intel_sseu sseu)
77b4d3acaaSChris Wilson {
78b4d3acaaSChris Wilson int ret;
79b4d3acaaSChris Wilson
80c816723bSLucas De Marchi GEM_BUG_ON(GRAPHICS_VER(ce->engine->i915) < 8);
81b4d3acaaSChris Wilson
82b4d3acaaSChris Wilson ret = intel_context_lock_pinned(ce);
83b4d3acaaSChris Wilson if (ret)
84b4d3acaaSChris Wilson return ret;
85b4d3acaaSChris Wilson
86b4d3acaaSChris Wilson /* Nothing to do if unmodified. */
87b4d3acaaSChris Wilson if (!memcmp(&ce->sseu, &sseu, sizeof(sseu)))
88b4d3acaaSChris Wilson goto unlock;
89b4d3acaaSChris Wilson
90b4d3acaaSChris Wilson ret = gen8_modify_rpcs(ce, sseu);
91b4d3acaaSChris Wilson if (!ret)
92b4d3acaaSChris Wilson ce->sseu = sseu;
93b4d3acaaSChris Wilson
94b4d3acaaSChris Wilson unlock:
95b4d3acaaSChris Wilson intel_context_unlock_pinned(ce);
96b4d3acaaSChris Wilson return ret;
97b4d3acaaSChris Wilson }
98