2014-07-24 16:04:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INTEL_LRC_H_
|
|
|
|
#define _INTEL_LRC_H_
|
|
|
|
|
2016-04-13 16:35:01 +00:00
|
|
|
#include "intel_ringbuffer.h"
|
2017-09-12 21:49:05 +00:00
|
|
|
#include "i915_gem_context.h"
|
2016-04-13 16:35:01 +00:00
|
|
|
|
2017-01-10 14:47:34 +00:00
|
|
|
#define GEN8_LR_CONTEXT_ALIGN I915_GTT_MIN_ALIGNMENT
|
drm/i915/bdw: Pin the context backing objects to GGTT on-demand
Up until now, we have pinned every logical ring context backing object
during creation, and left it pinned until destruction. This made my life
easier, but it's a harmful thing to do, because we cause fragmentation
of the GGTT (and, eventually, we would run out of space).
This patch makes the pinning on-demand: the backing objects of the two
contexts that are written to the ELSP are pinned right before submission
and unpinned once the hardware is done with them. The only context that
is still pinned regardless is the global default one, so that the HWS can
still be accessed in the same way (ring->status_page).
v2: In the early version of this patch, we were pinning the context as
we put it into the ELSP: on the one hand, this is very efficient because
only a maximum two contexts are pinned at any given time, but on the other
hand, we cannot really pin in interrupt time :(
v3: Use a mutex rather than atomic_t to protect pin count to avoid races.
Do not unpin default context in free_request.
v4: Break out pin and unpin into functions. Fix style problems reported
by checkpatch
v5: Remove unpin_lock as all pinning and unpinning is done with the struct
mutex already locked. Add WARN_ONs to make sure this is the case in future.
Issue: VIZ-4277
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Signed-off-by: Thomas Daniel <thomas.daniel@intel.com>
Reviewed-by: Akash Goel <akash.goels@gmail.com>
Reviewed-by: Deepak S<deepak.s@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-11-13 10:28:10 +00:00
|
|
|
|
2014-08-07 12:23:20 +00:00
|
|
|
/* Execlists regs */
|
2016-07-20 17:16:05 +00:00
|
|
|
#define RING_ELSP(engine) _MMIO((engine)->mmio_base + 0x230)
|
|
|
|
#define RING_EXECLIST_STATUS_LO(engine) _MMIO((engine)->mmio_base + 0x234)
|
|
|
|
#define RING_EXECLIST_STATUS_HI(engine) _MMIO((engine)->mmio_base + 0x234 + 4)
|
|
|
|
#define RING_CONTEXT_CONTROL(engine) _MMIO((engine)->mmio_base + 0x244)
|
2015-02-10 09:11:36 +00:00
|
|
|
#define CTX_CTRL_INHIBIT_SYN_CTX_SWITCH (1 << 3)
|
|
|
|
#define CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT (1 << 0)
|
2015-06-16 10:39:42 +00:00
|
|
|
#define CTX_CTRL_RS_CTX_ENABLE (1 << 1)
|
2018-01-23 21:04:12 +00:00
|
|
|
#define CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT (1 << 2)
|
2016-07-20 17:16:05 +00:00
|
|
|
#define RING_CONTEXT_STATUS_BUF_BASE(engine) _MMIO((engine)->mmio_base + 0x370)
|
|
|
|
#define RING_CONTEXT_STATUS_BUF_LO(engine, i) _MMIO((engine)->mmio_base + 0x370 + (i) * 8)
|
|
|
|
#define RING_CONTEXT_STATUS_BUF_HI(engine, i) _MMIO((engine)->mmio_base + 0x370 + (i) * 8 + 4)
|
|
|
|
#define RING_CONTEXT_STATUS_PTR(engine) _MMIO((engine)->mmio_base + 0x3a0)
|
2018-03-02 16:14:59 +00:00
|
|
|
#define RING_EXECLIST_SQ_CONTENTS(engine) _MMIO((engine)->mmio_base + 0x510)
|
|
|
|
#define RING_EXECLIST_CONTROL(engine) _MMIO((engine)->mmio_base + 0x550)
|
|
|
|
#define EL_CTRL_LOAD (1 << 0)
|
2014-08-07 12:23:20 +00:00
|
|
|
|
2016-01-05 18:30:05 +00:00
|
|
|
/* The docs specify that the write pointer wraps around after 5h, "After status
|
|
|
|
* is written out to the last available status QW at offset 5h, this pointer
|
|
|
|
* wraps to 0."
|
|
|
|
*
|
|
|
|
* Therefore, one must infer than even though there are 3 bits available, 6 and
|
|
|
|
* 7 appear to be * reserved.
|
|
|
|
*/
|
|
|
|
#define GEN8_CSB_ENTRIES 6
|
|
|
|
#define GEN8_CSB_PTR_MASK 0x7
|
|
|
|
#define GEN8_CSB_READ_PTR_MASK (GEN8_CSB_PTR_MASK << 8)
|
|
|
|
#define GEN8_CSB_WRITE_PTR_MASK (GEN8_CSB_PTR_MASK << 0)
|
|
|
|
#define GEN8_CSB_WRITE_PTR(csb_status) \
|
|
|
|
(((csb_status) & GEN8_CSB_WRITE_PTR_MASK) >> 0)
|
|
|
|
#define GEN8_CSB_READ_PTR(csb_status) \
|
|
|
|
(((csb_status) & GEN8_CSB_READ_PTR_MASK) >> 8)
|
|
|
|
|
2016-06-16 12:07:03 +00:00
|
|
|
enum {
|
|
|
|
INTEL_CONTEXT_SCHEDULE_IN = 0,
|
|
|
|
INTEL_CONTEXT_SCHEDULE_OUT,
|
2017-10-03 20:34:47 +00:00
|
|
|
INTEL_CONTEXT_SCHEDULE_PREEMPTED,
|
2016-06-16 12:07:03 +00:00
|
|
|
};
|
|
|
|
|
2014-07-24 16:04:22 +00:00
|
|
|
/* Logical Rings */
|
2016-03-16 11:00:37 +00:00
|
|
|
void intel_logical_ring_cleanup(struct intel_engine_cs *engine);
|
2016-07-13 15:03:40 +00:00
|
|
|
int logical_render_ring_init(struct intel_engine_cs *engine);
|
|
|
|
int logical_xcs_ring_init(struct intel_engine_cs *engine);
|
|
|
|
|
2014-07-24 16:04:12 +00:00
|
|
|
/* Logical Ring Contexts */
|
drm/i915: Integrate GuC-based command submission
GuC-based submission is mostly the same as execlist mode, up to
intel_logical_ring_advance_and_submit(), where the context being
dispatched would be added to the execlist queue; at this point
we submit the context to the GuC backend instead.
There are, however, a few other changes also required, notably:
1. Contexts must be pinned at GGTT addresses accessible by the GuC
i.e. NOT in the range [0..WOPCM_SIZE), so we have to add the
PIN_OFFSET_BIAS flag to the relevant GGTT-pinning calls.
2. The GuC's TLB must be invalidated after a context is pinned at
a new GGTT address.
3. GuC firmware uses the one page before Ring Context as shared data.
Therefore, whenever driver wants to get base address of LRC, we
will offset one page for it. LRC_PPHWSP_PN is defined as the page
number of LRCA.
4. In the work queue used to pass requests to the GuC, the GuC
firmware requires the ring-tail-offset to be represented as an
11-bit value, expressed in QWords. Therefore, the ringbuffer
size must be reduced to the representable range (4 pages).
v2:
Defer adding #defines until needed [Chris Wilson]
Rationalise type declarations [Chris Wilson]
v4:
Squashed kerneldoc patch into here [Daniel Vetter]
v5:
Update request->tail in code common to both GuC and execlist modes.
Add a private version of lr_context_update(), as sharing the
execlist version leads to race conditions when the CPU and
the GuC both update TAIL in the context image.
Conversion of error-captured HWS page to string must account
for offset from start of object to actual HWS (LRC_PPHWSP_PN).
Issue: VIZ-4884
Signed-off-by: Alex Dai <yu.dai@intel.com>
Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
Reviewed-by: Tom O'Rourke <Tom.O'Rourke@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-08-12 14:43:43 +00:00
|
|
|
|
2017-09-13 08:56:00 +00:00
|
|
|
/*
|
|
|
|
* We allocate a header at the start of the context image for our own
|
|
|
|
* use, therefore the actual location of the logical state is offset
|
|
|
|
* from the start of the VMA. The layout is
|
|
|
|
*
|
|
|
|
* | [guc] | [hwsp] [logical state] |
|
|
|
|
* |<- our header ->|<- context image ->|
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/* The first page is used for sharing data with the GuC */
|
drm/i915: Integrate GuC-based command submission
GuC-based submission is mostly the same as execlist mode, up to
intel_logical_ring_advance_and_submit(), where the context being
dispatched would be added to the execlist queue; at this point
we submit the context to the GuC backend instead.
There are, however, a few other changes also required, notably:
1. Contexts must be pinned at GGTT addresses accessible by the GuC
i.e. NOT in the range [0..WOPCM_SIZE), so we have to add the
PIN_OFFSET_BIAS flag to the relevant GGTT-pinning calls.
2. The GuC's TLB must be invalidated after a context is pinned at
a new GGTT address.
3. GuC firmware uses the one page before Ring Context as shared data.
Therefore, whenever driver wants to get base address of LRC, we
will offset one page for it. LRC_PPHWSP_PN is defined as the page
number of LRCA.
4. In the work queue used to pass requests to the GuC, the GuC
firmware requires the ring-tail-offset to be represented as an
11-bit value, expressed in QWords. Therefore, the ringbuffer
size must be reduced to the representable range (4 pages).
v2:
Defer adding #defines until needed [Chris Wilson]
Rationalise type declarations [Chris Wilson]
v4:
Squashed kerneldoc patch into here [Daniel Vetter]
v5:
Update request->tail in code common to both GuC and execlist modes.
Add a private version of lr_context_update(), as sharing the
execlist version leads to race conditions when the CPU and
the GuC both update TAIL in the context image.
Conversion of error-captured HWS page to string must account
for offset from start of object to actual HWS (LRC_PPHWSP_PN).
Issue: VIZ-4884
Signed-off-by: Alex Dai <yu.dai@intel.com>
Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
Reviewed-by: Tom O'Rourke <Tom.O'Rourke@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-08-12 14:43:43 +00:00
|
|
|
#define LRC_GUCSHR_PN (0)
|
2017-09-13 08:56:00 +00:00
|
|
|
#define LRC_GUCSHR_SZ (1)
|
|
|
|
/* At the start of the context image is its per-process HWS page */
|
|
|
|
#define LRC_PPHWSP_PN (LRC_GUCSHR_PN + LRC_GUCSHR_SZ)
|
|
|
|
#define LRC_PPHWSP_SZ (1)
|
|
|
|
/* Finally we have the logical state for the context */
|
|
|
|
#define LRC_STATE_PN (LRC_PPHWSP_PN + LRC_PPHWSP_SZ)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently we include the PPHWSP in __intel_engine_context_size() so
|
|
|
|
* the size of the header is synonymous with the start of the PPHWSP.
|
|
|
|
*/
|
|
|
|
#define LRC_HEADER_PAGES LRC_PPHWSP_PN
|
drm/i915: Integrate GuC-based command submission
GuC-based submission is mostly the same as execlist mode, up to
intel_logical_ring_advance_and_submit(), where the context being
dispatched would be added to the execlist queue; at this point
we submit the context to the GuC backend instead.
There are, however, a few other changes also required, notably:
1. Contexts must be pinned at GGTT addresses accessible by the GuC
i.e. NOT in the range [0..WOPCM_SIZE), so we have to add the
PIN_OFFSET_BIAS flag to the relevant GGTT-pinning calls.
2. The GuC's TLB must be invalidated after a context is pinned at
a new GGTT address.
3. GuC firmware uses the one page before Ring Context as shared data.
Therefore, whenever driver wants to get base address of LRC, we
will offset one page for it. LRC_PPHWSP_PN is defined as the page
number of LRCA.
4. In the work queue used to pass requests to the GuC, the GuC
firmware requires the ring-tail-offset to be represented as an
11-bit value, expressed in QWords. Therefore, the ringbuffer
size must be reduced to the representable range (4 pages).
v2:
Defer adding #defines until needed [Chris Wilson]
Rationalise type declarations [Chris Wilson]
v4:
Squashed kerneldoc patch into here [Daniel Vetter]
v5:
Update request->tail in code common to both GuC and execlist modes.
Add a private version of lr_context_update(), as sharing the
execlist version leads to race conditions when the CPU and
the GuC both update TAIL in the context image.
Conversion of error-captured HWS page to string must account
for offset from start of object to actual HWS (LRC_PPHWSP_PN).
Issue: VIZ-4884
Signed-off-by: Alex Dai <yu.dai@intel.com>
Signed-off-by: Dave Gordon <david.s.gordon@intel.com>
Reviewed-by: Tom O'Rourke <Tom.O'Rourke@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-08-12 14:43:43 +00:00
|
|
|
|
drm/i915: Unify active context tracking between legacy/execlists/guc
The requests conversion introduced a nasty bug where we could generate a
new request in the middle of constructing a request if we needed to idle
the system in order to evict space for a context. The request to idle
would be executed (and waited upon) before the current one, creating a
minor havoc in the seqno accounting, as we will consider the current
request to already be completed (prior to deferred seqno assignment) but
ring->last_retired_head would have been updated and still could allow
us to overwrite the current request before execution.
We also employed two different mechanisms to track the active context
until it was switched out. The legacy method allowed for waiting upon an
active context (it could forcibly evict any vma, including context's),
but the execlists method took a step backwards by pinning the vma for
the entire active lifespan of the context (the only way to evict was to
idle the entire GPU, not individual contexts). However, to circumvent
the tricky issue of locking (i.e. we cannot take struct_mutex at the
time of i915_gem_request_submit(), where we would want to move the
previous context onto the active tracker and unpin it), we take the
execlists approach and keep the contexts pinned until retirement.
The benefit of the execlists approach, more important for execlists than
legacy, was the reduction in work in pinning the context for each
request - as the context was kept pinned until idle, it could short
circuit the pinning for all active contexts.
We introduce new engine vfuncs to pin and unpin the context
respectively. The context is pinned at the start of the request, and
only unpinned when the following request is retired (this ensures that
the context is idle and coherent in main memory before we unpin it). We
move the engine->last_context tracking into the retirement itself
(rather than during request submission) in order to allow the submission
to be reordered or unwound without undue difficultly.
And finally an ulterior motive for unifying context handling was to
prepare for mock requests.
v2: Rename to last_retired_context, split out legacy_context tracking
for MI_SET_CONTEXT.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161218153724.8439-3-chris@chris-wilson.co.uk
2016-12-18 15:37:20 +00:00
|
|
|
struct drm_i915_private;
|
2016-05-24 13:53:34 +00:00
|
|
|
struct i915_gem_context;
|
|
|
|
|
2016-09-09 13:11:53 +00:00
|
|
|
void intel_lr_context_resume(struct drm_i915_private *dev_priv);
|
2017-09-12 21:49:05 +00:00
|
|
|
|
2018-07-17 20:29:32 +00:00
|
|
|
void intel_execlists_set_default_submission(struct intel_engine_cs *engine);
|
|
|
|
|
2014-07-24 16:04:10 +00:00
|
|
|
#endif /* _INTEL_LRC_H_ */
|