drm/i915: Fix locking around GuC firmware load
[linux-2.6-block.git] / drivers / gpu / drm / i915 / intel_guc_loader.c
index f87d833aa5ca86ac62528794543779dac4659a66..3541f76c65a7ab8ce1559bd34d14acb04ea47858 100644 (file)
@@ -383,7 +383,6 @@ int intel_guc_ucode_load(struct drm_device *dev)
                intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
 
        direct_interrupts_to_host(dev_priv);
-       i915_guc_submission_disable(dev);
 
        if (guc_fw->guc_fw_fetch_status == GUC_FIRMWARE_NONE)
                return 0;
@@ -433,6 +432,9 @@ int intel_guc_ucode_load(struct drm_device *dev)
                intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
 
        if (i915.enable_guc_submission) {
+               /* The execbuf_client will be recreated. Release it first. */
+               i915_guc_submission_disable(dev);
+
                err = i915_guc_submission_enable(dev);
                if (err)
                        goto fail;
@@ -502,7 +504,9 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
                        guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found,
                        guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
 
+       mutex_lock(&dev->struct_mutex);
        obj = i915_gem_object_create_from_data(dev, fw->data, fw->size);
+       mutex_unlock(&dev->struct_mutex);
        if (IS_ERR_OR_NULL(obj)) {
                err = obj ? PTR_ERR(obj) : -ENOMEM;
                goto fail;
@@ -538,8 +542,6 @@ fail:
  * @dev:       drm device
  *
  * Called early during driver load, but after GEM is initialised.
- * The device struct_mutex must be held by the caller, as we're
- * going to allocate a GEM object to hold the firmware image.
  *
  * The firmware will be transferred to the GuC's memory later,
  * when intel_guc_ucode_load() is called.
@@ -596,9 +598,11 @@ void intel_guc_ucode_fini(struct drm_device *dev)
        direct_interrupts_to_host(dev_priv);
        i915_guc_submission_fini(dev);
 
+       mutex_lock(&dev->struct_mutex);
        if (guc_fw->guc_fw_obj)
                drm_gem_object_unreference(&guc_fw->guc_fw_obj->base);
        guc_fw->guc_fw_obj = NULL;
+       mutex_unlock(&dev->struct_mutex);
 
        guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE;
 }