11b13d190SFrançois Tigeot /*
21b13d190SFrançois Tigeot * Copyright © 2014 Intel Corporation
31b13d190SFrançois Tigeot *
41b13d190SFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
51b13d190SFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
61b13d190SFrançois Tigeot * to deal in the Software without restriction, including without limitation
71b13d190SFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81b13d190SFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
91b13d190SFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
101b13d190SFrançois Tigeot *
111b13d190SFrançois Tigeot * The above copyright notice and this permission notice (including the next
121b13d190SFrançois Tigeot * paragraph) shall be included in all copies or substantial portions of the
131b13d190SFrançois Tigeot * Software.
141b13d190SFrançois Tigeot *
151b13d190SFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161b13d190SFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171b13d190SFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
181b13d190SFrançois Tigeot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191b13d190SFrançois Tigeot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201b13d190SFrançois Tigeot * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211b13d190SFrançois Tigeot * DEALINGS IN THE SOFTWARE.
221b13d190SFrançois Tigeot */
231b13d190SFrançois Tigeot
241b13d190SFrançois Tigeot #ifndef _INTEL_LRC_H_
251b13d190SFrançois Tigeot #define _INTEL_LRC_H_
261b13d190SFrançois Tigeot
278621f407SFrançois Tigeot #include "intel_ringbuffer.h"
28*3f2dd94aSFrançois Tigeot #include "i915_gem_context.h"
298621f407SFrançois Tigeot
30a85cb24fSFrançois Tigeot #define GEN8_LR_CONTEXT_ALIGN I915_GTT_MIN_ALIGNMENT
312c9916cdSFrançois Tigeot
321b13d190SFrançois Tigeot /* Execlists regs */
3387df8fc6SFrançois Tigeot #define RING_ELSP(engine) _MMIO((engine)->mmio_base + 0x230)
3487df8fc6SFrançois Tigeot #define RING_EXECLIST_STATUS_LO(engine) _MMIO((engine)->mmio_base + 0x234)
3587df8fc6SFrançois Tigeot #define RING_EXECLIST_STATUS_HI(engine) _MMIO((engine)->mmio_base + 0x234 + 4)
3687df8fc6SFrançois Tigeot #define RING_CONTEXT_CONTROL(engine) _MMIO((engine)->mmio_base + 0x244)
37477eb7f9SFrançois Tigeot #define CTX_CTRL_INHIBIT_SYN_CTX_SWITCH (1 << 3)
38477eb7f9SFrançois Tigeot #define CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT (1 << 0)
39a05eeebfSFrançois Tigeot #define CTX_CTRL_RS_CTX_ENABLE (1 << 1)
4087df8fc6SFrançois Tigeot #define RING_CONTEXT_STATUS_BUF_BASE(engine) _MMIO((engine)->mmio_base + 0x370)
4187df8fc6SFrançois Tigeot #define RING_CONTEXT_STATUS_BUF_LO(engine, i) _MMIO((engine)->mmio_base + 0x370 + (i) * 8)
4287df8fc6SFrançois Tigeot #define RING_CONTEXT_STATUS_BUF_HI(engine, i) _MMIO((engine)->mmio_base + 0x370 + (i) * 8 + 4)
4387df8fc6SFrançois Tigeot #define RING_CONTEXT_STATUS_PTR(engine) _MMIO((engine)->mmio_base + 0x3a0)
441b13d190SFrançois Tigeot
45c0e85e96SFrançois Tigeot /* The docs specify that the write pointer wraps around after 5h, "After status
46c0e85e96SFrançois Tigeot * is written out to the last available status QW at offset 5h, this pointer
47c0e85e96SFrançois Tigeot * wraps to 0."
48c0e85e96SFrançois Tigeot *
49c0e85e96SFrançois Tigeot * Therefore, one must infer than even though there are 3 bits available, 6 and
50c0e85e96SFrançois Tigeot * 7 appear to be * reserved.
51c0e85e96SFrançois Tigeot */
52c0e85e96SFrançois Tigeot #define GEN8_CSB_ENTRIES 6
53c0e85e96SFrançois Tigeot #define GEN8_CSB_PTR_MASK 0x7
54c0e85e96SFrançois Tigeot #define GEN8_CSB_READ_PTR_MASK (GEN8_CSB_PTR_MASK << 8)
55c0e85e96SFrançois Tigeot #define GEN8_CSB_WRITE_PTR_MASK (GEN8_CSB_PTR_MASK << 0)
56c0e85e96SFrançois Tigeot #define GEN8_CSB_WRITE_PTR(csb_status) \
57c0e85e96SFrançois Tigeot (((csb_status) & GEN8_CSB_WRITE_PTR_MASK) >> 0)
58c0e85e96SFrançois Tigeot #define GEN8_CSB_READ_PTR(csb_status) \
59c0e85e96SFrançois Tigeot (((csb_status) & GEN8_CSB_READ_PTR_MASK) >> 8)
60c0e85e96SFrançois Tigeot
611487f786SFrançois Tigeot enum {
621487f786SFrançois Tigeot INTEL_CONTEXT_SCHEDULE_IN = 0,
631487f786SFrançois Tigeot INTEL_CONTEXT_SCHEDULE_OUT,
64*3f2dd94aSFrançois Tigeot INTEL_CONTEXT_SCHEDULE_PREEMPTED,
651487f786SFrançois Tigeot };
661487f786SFrançois Tigeot
671b13d190SFrançois Tigeot /* Logical Rings */
688621f407SFrançois Tigeot void intel_logical_ring_cleanup(struct intel_engine_cs *engine);
6987df8fc6SFrançois Tigeot int logical_render_ring_init(struct intel_engine_cs *engine);
7087df8fc6SFrançois Tigeot int logical_xcs_ring_init(struct intel_engine_cs *engine);
7187df8fc6SFrançois Tigeot
721b13d190SFrançois Tigeot /* Logical Ring Contexts */
73352ff8bdSFrançois Tigeot
74*3f2dd94aSFrançois Tigeot /*
75*3f2dd94aSFrançois Tigeot * We allocate a header at the start of the context image for our own
76*3f2dd94aSFrançois Tigeot * use, therefore the actual location of the logical state is offset
77*3f2dd94aSFrançois Tigeot * from the start of the VMA. The layout is
78*3f2dd94aSFrançois Tigeot *
79*3f2dd94aSFrançois Tigeot * | [guc] | [hwsp] [logical state] |
80*3f2dd94aSFrançois Tigeot * |<- our header ->|<- context image ->|
81*3f2dd94aSFrançois Tigeot *
82*3f2dd94aSFrançois Tigeot */
83*3f2dd94aSFrançois Tigeot /* The first page is used for sharing data with the GuC */
84352ff8bdSFrançois Tigeot #define LRC_GUCSHR_PN (0)
85*3f2dd94aSFrançois Tigeot #define LRC_GUCSHR_SZ (1)
86*3f2dd94aSFrançois Tigeot /* At the start of the context image is its per-process HWS page */
87*3f2dd94aSFrançois Tigeot #define LRC_PPHWSP_PN (LRC_GUCSHR_PN + LRC_GUCSHR_SZ)
88*3f2dd94aSFrançois Tigeot #define LRC_PPHWSP_SZ (1)
89*3f2dd94aSFrançois Tigeot /* Finally we have the logical state for the context */
90*3f2dd94aSFrançois Tigeot #define LRC_STATE_PN (LRC_PPHWSP_PN + LRC_PPHWSP_SZ)
91*3f2dd94aSFrançois Tigeot
92*3f2dd94aSFrançois Tigeot /*
93*3f2dd94aSFrançois Tigeot * Currently we include the PPHWSP in __intel_engine_context_size() so
94*3f2dd94aSFrançois Tigeot * the size of the header is synonymous with the start of the PPHWSP.
95*3f2dd94aSFrançois Tigeot */
96*3f2dd94aSFrançois Tigeot #define LRC_HEADER_PAGES LRC_PPHWSP_PN
97352ff8bdSFrançois Tigeot
98a85cb24fSFrançois Tigeot struct drm_i915_private;
991487f786SFrançois Tigeot struct i915_gem_context;
1001487f786SFrançois Tigeot
1011e12ee3bSFrançois Tigeot void intel_lr_context_resume(struct drm_i915_private *dev_priv);
102*3f2dd94aSFrançois Tigeot
103*3f2dd94aSFrançois Tigeot static inline uint64_t
intel_lr_context_descriptor(struct i915_gem_context * ctx,struct intel_engine_cs * engine)104*3f2dd94aSFrançois Tigeot intel_lr_context_descriptor(struct i915_gem_context *ctx,
105*3f2dd94aSFrançois Tigeot struct intel_engine_cs *engine)
106*3f2dd94aSFrançois Tigeot {
107*3f2dd94aSFrançois Tigeot return ctx->engine[engine->id].lrc_desc;
108*3f2dd94aSFrançois Tigeot }
109*3f2dd94aSFrançois Tigeot
110c0e85e96SFrançois Tigeot
1111b13d190SFrançois Tigeot /* Execlists */
1121487f786SFrançois Tigeot int intel_sanitize_enable_execlists(struct drm_i915_private *dev_priv,
1131487f786SFrançois Tigeot int enable_execlists);
1141b13d190SFrançois Tigeot
1151b13d190SFrançois Tigeot #endif /* _INTEL_LRC_H_ */
116