Commit e7465473 authored by Oscar Mateo's avatar Oscar Mateo Committed by Joonas Lahtinen

drm/i915/guc: Break out the GuC log extras into their own "runtime" struct

When initializing the GuC log struct, there is an object we need to
allocate always, since the GuC needs its address at fw load time.
The rest is only needed during runtime, in the sense that we only
create if we actually enable GuC logging. Make that distinction
explicit by subdividing further the intel_guc_log struct.

v2: Call the new struct "runtime", instead of "extras" (Joonas)

v3: Check indent (Joonas)
Signed-off-by: default avatarOscar Mateo <oscar.mateo@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
parent 0704df2b
...@@ -1741,8 +1741,8 @@ static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir) ...@@ -1741,8 +1741,8 @@ static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
I915_WRITE(SOFT_SCRATCH(15), msg & ~flush); I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
/* Handle flush interrupt in bottom half */ /* Handle flush interrupt in bottom half */
queue_work(dev_priv->guc.log.flush_wq, queue_work(dev_priv->guc.log.runtime.flush_wq,
&dev_priv->guc.log.flush_work); &dev_priv->guc.log.runtime.flush_work);
dev_priv->guc.log.flush_interrupt_count++; dev_priv->guc.log.flush_interrupt_count++;
} else { } else {
......
...@@ -166,7 +166,7 @@ static int guc_log_relay_file_create(struct intel_guc *guc) ...@@ -166,7 +166,7 @@ static int guc_log_relay_file_create(struct intel_guc *guc)
return -ENODEV; return -ENODEV;
} }
ret = relay_late_setup_files(guc->log.relay_chan, "guc_log", log_dir); ret = relay_late_setup_files(guc->log.runtime.relay_chan, "guc_log", log_dir);
if (ret < 0 && ret != -EEXIST) { if (ret < 0 && ret != -EEXIST) {
DRM_ERROR("Couldn't associate relay chan with file %d\n", ret); DRM_ERROR("Couldn't associate relay chan with file %d\n", ret);
return ret; return ret;
...@@ -183,15 +183,15 @@ static void guc_move_to_next_buf(struct intel_guc *guc) ...@@ -183,15 +183,15 @@ static void guc_move_to_next_buf(struct intel_guc *guc)
smp_wmb(); smp_wmb();
/* All data has been written, so now move the offset of sub buffer. */ /* All data has been written, so now move the offset of sub buffer. */
relay_reserve(guc->log.relay_chan, guc->log.vma->obj->base.size); relay_reserve(guc->log.runtime.relay_chan, guc->log.vma->obj->base.size);
/* Switch to the next sub buffer */ /* Switch to the next sub buffer */
relay_flush(guc->log.relay_chan); relay_flush(guc->log.runtime.relay_chan);
} }
static void *guc_get_write_buffer(struct intel_guc *guc) static void *guc_get_write_buffer(struct intel_guc *guc)
{ {
if (!guc->log.relay_chan) if (!guc->log.runtime.relay_chan)
return NULL; return NULL;
/* Just get the base address of a new sub buffer and copy data into it /* Just get the base address of a new sub buffer and copy data into it
...@@ -202,7 +202,7 @@ static void *guc_get_write_buffer(struct intel_guc *guc) ...@@ -202,7 +202,7 @@ static void *guc_get_write_buffer(struct intel_guc *guc)
* done without using relay_reserve() along with relay_write(). So its * done without using relay_reserve() along with relay_write(). So its
* better to use relay_reserve() alone. * better to use relay_reserve() alone.
*/ */
return relay_reserve(guc->log.relay_chan, 0); return relay_reserve(guc->log.runtime.relay_chan, 0);
} }
static bool guc_check_log_buf_overflow(struct intel_guc *guc, static bool guc_check_log_buf_overflow(struct intel_guc *guc,
...@@ -253,11 +253,11 @@ static void guc_read_update_log_buffer(struct intel_guc *guc) ...@@ -253,11 +253,11 @@ static void guc_read_update_log_buffer(struct intel_guc *guc)
void *src_data, *dst_data; void *src_data, *dst_data;
bool new_overflow; bool new_overflow;
if (WARN_ON(!guc->log.buf_addr)) if (WARN_ON(!guc->log.runtime.buf_addr))
return; return;
/* Get the pointer to shared GuC log buffer */ /* Get the pointer to shared GuC log buffer */
log_buf_state = src_data = guc->log.buf_addr; log_buf_state = src_data = guc->log.runtime.buf_addr;
/* Get the pointer to local buffer to store the logs */ /* Get the pointer to local buffer to store the logs */
log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc); log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc);
...@@ -343,17 +343,17 @@ static void guc_read_update_log_buffer(struct intel_guc *guc) ...@@ -343,17 +343,17 @@ static void guc_read_update_log_buffer(struct intel_guc *guc)
static void capture_logs_work(struct work_struct *work) static void capture_logs_work(struct work_struct *work)
{ {
struct intel_guc *guc = struct intel_guc *guc =
container_of(work, struct intel_guc, log.flush_work); container_of(work, struct intel_guc, log.runtime.flush_work);
guc_log_capture_logs(guc); guc_log_capture_logs(guc);
} }
static bool guc_log_has_extras(struct intel_guc *guc) static bool guc_log_has_runtime(struct intel_guc *guc)
{ {
return guc->log.buf_addr != NULL; return guc->log.runtime.buf_addr != NULL;
} }
static int guc_log_create_extras(struct intel_guc *guc) static int guc_log_runtime_create(struct intel_guc *guc)
{ {
struct drm_i915_private *dev_priv = guc_to_i915(guc); struct drm_i915_private *dev_priv = guc_to_i915(guc);
void *vaddr; void *vaddr;
...@@ -363,7 +363,7 @@ static int guc_log_create_extras(struct intel_guc *guc) ...@@ -363,7 +363,7 @@ static int guc_log_create_extras(struct intel_guc *guc)
lockdep_assert_held(&dev_priv->drm.struct_mutex); lockdep_assert_held(&dev_priv->drm.struct_mutex);
GEM_BUG_ON(guc_log_has_extras(guc)); GEM_BUG_ON(guc_log_has_runtime(guc));
/* Create a WC (Uncached for read) vmalloc mapping of log /* Create a WC (Uncached for read) vmalloc mapping of log
* buffer pages, so that we can directly get the data * buffer pages, so that we can directly get the data
...@@ -375,7 +375,7 @@ static int guc_log_create_extras(struct intel_guc *guc) ...@@ -375,7 +375,7 @@ static int guc_log_create_extras(struct intel_guc *guc)
return PTR_ERR(vaddr); return PTR_ERR(vaddr);
} }
guc->log.buf_addr = vaddr; guc->log.runtime.buf_addr = vaddr;
/* Keep the size of sub buffers same as shared log buffer */ /* Keep the size of sub buffers same as shared log buffer */
subbuf_size = guc->log.vma->obj->base.size; subbuf_size = guc->log.vma->obj->base.size;
...@@ -401,9 +401,9 @@ static int guc_log_create_extras(struct intel_guc *guc) ...@@ -401,9 +401,9 @@ static int guc_log_create_extras(struct intel_guc *guc)
} }
GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size); GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size);
guc->log.relay_chan = guc_log_relay_chan; guc->log.runtime.relay_chan = guc_log_relay_chan;
INIT_WORK(&guc->log.flush_work, capture_logs_work); INIT_WORK(&guc->log.runtime.flush_work, capture_logs_work);
/* /*
* GuC log buffer flush work item has to do register access to * GuC log buffer flush work item has to do register access to
...@@ -416,9 +416,9 @@ static int guc_log_create_extras(struct intel_guc *guc) ...@@ -416,9 +416,9 @@ static int guc_log_create_extras(struct intel_guc *guc)
* or scheduled later on resume. This way the handling of work * or scheduled later on resume. This way the handling of work
* item can be kept same between system suspend & rpm suspend. * item can be kept same between system suspend & rpm suspend.
*/ */
guc->log.flush_wq = alloc_ordered_workqueue("i915-guc_log", guc->log.runtime.flush_wq = alloc_ordered_workqueue("i915-guc_log",
WQ_HIGHPRI | WQ_FREEZABLE); WQ_HIGHPRI | WQ_FREEZABLE);
if (!guc->log.flush_wq) { if (!guc->log.runtime.flush_wq) {
DRM_ERROR("Couldn't allocate the wq for GuC logging\n"); DRM_ERROR("Couldn't allocate the wq for GuC logging\n");
ret = -ENOMEM; ret = -ENOMEM;
goto err_relaychan; goto err_relaychan;
...@@ -427,26 +427,26 @@ static int guc_log_create_extras(struct intel_guc *guc) ...@@ -427,26 +427,26 @@ static int guc_log_create_extras(struct intel_guc *guc)
return 0; return 0;
err_relaychan: err_relaychan:
relay_close(guc->log.relay_chan); relay_close(guc->log.runtime.relay_chan);
err_vaddr: err_vaddr:
i915_gem_object_unpin_map(guc->log.vma->obj); i915_gem_object_unpin_map(guc->log.vma->obj);
guc->log.buf_addr = NULL; guc->log.runtime.buf_addr = NULL;
return ret; return ret;
} }
static void guc_log_destroy_extras(struct intel_guc *guc) static void guc_log_runtime_destroy(struct intel_guc *guc)
{ {
/* /*
* It's possible that extras were never allocated because guc_log_level * It's possible that the runtime stuff was never allocated because
* was < 0 at the time * guc_log_level was < 0 at the time
**/ **/
if (!guc_log_has_extras(guc)) if (!guc_log_has_runtime(guc))
return; return;
destroy_workqueue(guc->log.flush_wq); destroy_workqueue(guc->log.runtime.flush_wq);
relay_close(guc->log.relay_chan); relay_close(guc->log.runtime.relay_chan);
i915_gem_object_unpin_map(guc->log.vma->obj); i915_gem_object_unpin_map(guc->log.vma->obj);
guc->log.buf_addr = NULL; guc->log.runtime.buf_addr = NULL;
} }
static int guc_log_late_setup(struct intel_guc *guc) static int guc_log_late_setup(struct intel_guc *guc)
...@@ -456,24 +456,24 @@ static int guc_log_late_setup(struct intel_guc *guc) ...@@ -456,24 +456,24 @@ static int guc_log_late_setup(struct intel_guc *guc)
lockdep_assert_held(&dev_priv->drm.struct_mutex); lockdep_assert_held(&dev_priv->drm.struct_mutex);
if (!guc_log_has_extras(guc)) { if (!guc_log_has_runtime(guc)) {
/* If log_level was set as -1 at boot time, then setup needed to /* If log_level was set as -1 at boot time, then setup needed to
* handle log buffer flush interrupts would not have been done yet, * handle log buffer flush interrupts would not have been done yet,
* so do that now. * so do that now.
*/ */
ret = guc_log_create_extras(guc); ret = guc_log_runtime_create(guc);
if (ret) if (ret)
goto err; goto err;
} }
ret = guc_log_relay_file_create(guc); ret = guc_log_relay_file_create(guc);
if (ret) if (ret)
goto err_extras; goto err_runtime;
return 0; return 0;
err_extras: err_runtime:
guc_log_destroy_extras(guc); guc_log_runtime_destroy(guc);
err: err:
/* logging will remain off */ /* logging will remain off */
i915.guc_log_level = -1; i915.guc_log_level = -1;
...@@ -507,7 +507,7 @@ static void guc_flush_logs(struct intel_guc *guc) ...@@ -507,7 +507,7 @@ static void guc_flush_logs(struct intel_guc *guc)
/* Before initiating the forceful flush, wait for any pending/ongoing /* Before initiating the forceful flush, wait for any pending/ongoing
* flush to complete otherwise forceful flush may not actually happen. * flush to complete otherwise forceful flush may not actually happen.
*/ */
flush_work(&guc->log.flush_work); flush_work(&guc->log.runtime.flush_work);
/* Ask GuC to update the log buffer state */ /* Ask GuC to update the log buffer state */
guc_log_flush(guc); guc_log_flush(guc);
...@@ -552,7 +552,7 @@ int intel_guc_log_create(struct intel_guc *guc) ...@@ -552,7 +552,7 @@ int intel_guc_log_create(struct intel_guc *guc)
guc->log.vma = vma; guc->log.vma = vma;
if (i915.guc_log_level >= 0) { if (i915.guc_log_level >= 0) {
ret = guc_log_create_extras(guc); ret = guc_log_runtime_create(guc);
if (ret < 0) if (ret < 0)
goto err_vma; goto err_vma;
} }
...@@ -578,7 +578,7 @@ int intel_guc_log_create(struct intel_guc *guc) ...@@ -578,7 +578,7 @@ int intel_guc_log_create(struct intel_guc *guc)
void intel_guc_log_destroy(struct intel_guc *guc) void intel_guc_log_destroy(struct intel_guc *guc)
{ {
guc_log_destroy_extras(guc); guc_log_runtime_destroy(guc);
i915_vma_unpin_and_release(&guc->log.vma); i915_vma_unpin_and_release(&guc->log.vma);
} }
...@@ -653,6 +653,6 @@ void i915_guc_log_unregister(struct drm_i915_private *dev_priv) ...@@ -653,6 +653,6 @@ void i915_guc_log_unregister(struct drm_i915_private *dev_priv)
mutex_lock(&dev_priv->drm.struct_mutex); mutex_lock(&dev_priv->drm.struct_mutex);
/* GuC logging is currently the only user of Guc2Host interrupts */ /* GuC logging is currently the only user of Guc2Host interrupts */
gen9_disable_guc_interrupts(dev_priv); gen9_disable_guc_interrupts(dev_priv);
guc_log_destroy_extras(&dev_priv->guc); guc_log_runtime_destroy(&dev_priv->guc);
mutex_unlock(&dev_priv->drm.struct_mutex); mutex_unlock(&dev_priv->drm.struct_mutex);
} }
...@@ -132,11 +132,13 @@ struct intel_uc_fw { ...@@ -132,11 +132,13 @@ struct intel_uc_fw {
struct intel_guc_log { struct intel_guc_log {
uint32_t flags; uint32_t flags;
struct i915_vma *vma; struct i915_vma *vma;
/* The runtime stuff gets created only when GuC logging gets enabled */
struct {
void *buf_addr; void *buf_addr;
struct workqueue_struct *flush_wq; struct workqueue_struct *flush_wq;
struct work_struct flush_work; struct work_struct flush_work;
struct rchan *relay_chan; struct rchan *relay_chan;
} runtime;
/* logging related stats */ /* logging related stats */
u32 capture_miss_count; u32 capture_miss_count;
u32 flush_interrupt_count; u32 flush_interrupt_count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment