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.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Ben Widawsky <ben@bwidawsk.net>
|
|
|
|
* Michel Thierry <michel.thierry@intel.com>
|
|
|
|
* Thomas Daniel <thomas.daniel@intel.com>
|
|
|
|
* Oscar Mateo <oscar.mateo@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GEN8 brings an expansion of the HW contexts: "Logical Ring Contexts".
|
|
|
|
* These expanded contexts enable a number of new abilities, especially
|
|
|
|
* "Execlists" (also implemented in this file).
|
|
|
|
*
|
|
|
|
* Execlists are the new method by which, on gen8+ hardware, workloads are
|
|
|
|
* submitted for execution (as opposed to the legacy, ringbuffer-based, method).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/i915_drm.h>
|
|
|
|
#include "i915_drv.h"
|
2014-07-24 16:04:11 +00:00
|
|
|
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
#define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
|
|
|
|
#define GEN8_LR_CONTEXT_OTHER_SIZE (2 * PAGE_SIZE)
|
|
|
|
|
|
|
|
#define GEN8_LR_CONTEXT_ALIGN 4096
|
|
|
|
|
2014-07-24 16:04:11 +00:00
|
|
|
int intel_sanitize_enable_execlists(struct drm_device *dev, int enable_execlists)
|
|
|
|
{
|
2014-08-11 13:57:57 +00:00
|
|
|
WARN_ON(i915.enable_ppgtt == -1);
|
|
|
|
|
2014-07-24 16:04:11 +00:00
|
|
|
if (enable_execlists == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (HAS_LOGICAL_RING_CONTEXTS(dev) && USES_PPGTT(dev))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-24 16:04:12 +00:00
|
|
|
|
|
|
|
void intel_lr_context_free(struct intel_context *ctx)
|
|
|
|
{
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < I915_NUM_RINGS; i++) {
|
|
|
|
struct drm_i915_gem_object *ctx_obj = ctx->engine[i].state;
|
2014-07-24 16:04:15 +00:00
|
|
|
struct intel_ringbuffer *ringbuf = ctx->engine[i].ringbuf;
|
|
|
|
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
if (ctx_obj) {
|
2014-07-24 16:04:15 +00:00
|
|
|
intel_destroy_ringbuffer_obj(ringbuf);
|
|
|
|
kfree(ringbuf);
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
i915_gem_object_ggtt_unpin(ctx_obj);
|
|
|
|
drm_gem_object_unreference(&ctx_obj->base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t get_lr_context_size(struct intel_engine_cs *ring)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
WARN_ON(INTEL_INFO(ring->dev)->gen != 8);
|
|
|
|
|
|
|
|
switch (ring->id) {
|
|
|
|
case RCS:
|
|
|
|
ret = GEN8_LR_CONTEXT_RENDER_SIZE;
|
|
|
|
break;
|
|
|
|
case VCS:
|
|
|
|
case BCS:
|
|
|
|
case VECS:
|
|
|
|
case VCS2:
|
|
|
|
ret = GEN8_LR_CONTEXT_OTHER_SIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2014-07-24 16:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int intel_lr_context_deferred_create(struct intel_context *ctx,
|
|
|
|
struct intel_engine_cs *ring)
|
|
|
|
{
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
struct drm_device *dev = ring->dev;
|
|
|
|
struct drm_i915_gem_object *ctx_obj;
|
|
|
|
uint32_t context_size;
|
2014-07-24 16:04:15 +00:00
|
|
|
struct intel_ringbuffer *ringbuf;
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
int ret;
|
|
|
|
|
2014-07-24 16:04:12 +00:00
|
|
|
WARN_ON(ctx->legacy_hw_ctx.rcs_state != NULL);
|
|
|
|
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
context_size = round_up(get_lr_context_size(ring), 4096);
|
|
|
|
|
|
|
|
ctx_obj = i915_gem_alloc_context_obj(dev, context_size);
|
|
|
|
if (IS_ERR(ctx_obj)) {
|
|
|
|
ret = PTR_ERR(ctx_obj);
|
|
|
|
DRM_DEBUG_DRIVER("Alloc LRC backing obj failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = i915_gem_obj_ggtt_pin(ctx_obj, GEN8_LR_CONTEXT_ALIGN, 0);
|
|
|
|
if (ret) {
|
|
|
|
DRM_DEBUG_DRIVER("Pin LRC backing obj failed: %d\n", ret);
|
|
|
|
drm_gem_object_unreference(&ctx_obj->base);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-24 16:04:15 +00:00
|
|
|
ringbuf = kzalloc(sizeof(*ringbuf), GFP_KERNEL);
|
|
|
|
if (!ringbuf) {
|
|
|
|
DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s\n",
|
|
|
|
ring->name);
|
|
|
|
i915_gem_object_ggtt_unpin(ctx_obj);
|
|
|
|
drm_gem_object_unreference(&ctx_obj->base);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-11 14:17:44 +00:00
|
|
|
ringbuf->ring = ring;
|
2014-07-24 16:04:15 +00:00
|
|
|
ringbuf->size = 32 * PAGE_SIZE;
|
|
|
|
ringbuf->effective_size = ringbuf->size;
|
|
|
|
ringbuf->head = 0;
|
|
|
|
ringbuf->tail = 0;
|
|
|
|
ringbuf->space = ringbuf->size;
|
|
|
|
ringbuf->last_retired_head = -1;
|
|
|
|
|
|
|
|
/* TODO: For now we put this in the mappable region so that we can reuse
|
|
|
|
* the existing ringbuffer code which ioremaps it. When we start
|
|
|
|
* creating many contexts, this will no longer work and we must switch
|
|
|
|
* to a kmapish interface.
|
|
|
|
*/
|
|
|
|
ret = intel_alloc_ringbuffer_obj(dev, ringbuf);
|
|
|
|
if (ret) {
|
|
|
|
DRM_DEBUG_DRIVER("Failed to allocate ringbuffer obj %s: %d\n",
|
|
|
|
ring->name, ret);
|
|
|
|
kfree(ringbuf);
|
|
|
|
i915_gem_object_ggtt_unpin(ctx_obj);
|
|
|
|
drm_gem_object_unreference(&ctx_obj->base);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->engine[ring->id].ringbuf = ringbuf;
|
drm/i915/bdw: A bit more advanced LR context alloc/free
Now that we have the ability to allocate our own context backing objects
and we have multiplexed one of them per engine inside the context structs,
we can finally allocate and free them correctly.
Regarding the context size, reading the register to calculate the sizes
can work, I think, however the docs are very clear about the actual
context sizes on GEN8, so just hardcode that and use it.
v2: Rebased on top of the Full PPGTT series. It is important to notice
that at this point we have one global default context per engine, all
of them using the aliasing PPGTT (as opposed to the single global
default context we have with legacy HW contexts).
v3:
- Go back to one single global default context, this time with multiple
backing objects inside.
- Use different context sizes for non-render engines, as suggested by
Damien (still hardcoded, since the information about the context size
registers in the BSpec is, well, *lacking*).
- Render ctx size is 20 (or 19) pages, but not 21 (caught by Damien).
- Move default context backing object creation to intel_init_ring (so
that we don't waste memory in rings that might not get initialized).
v4:
- Reuse the HW legacy context init/fini.
- Create a separate free function.
- Rename the functions with an intel_ preffix.
v5: Several rebases to account for the changes in the previous patches.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net> (v1)
Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-07-24 16:04:14 +00:00
|
|
|
ctx->engine[ring->id].state = ctx_obj;
|
2014-07-24 16:04:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|