static ssize_t i915_l3_read(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t offset, size_t count) { struct device *dev = kobj_to_dev(kobj); struct drm_minor *dminor = dev_to_drm_minor(dev); struct drm_device *drm_dev = dminor->dev; struct drm_i915_private *dev_priv = drm_dev->dev_private; int slice = (int)(uintptr_t)attr->private; int ret; count = round_down(count, 4); ret = l3_access_valid(drm_dev, offset); if (ret) return ret; count = min_t(size_t, GEN7_L3LOG_SIZE - offset, count); ret = i915_mutex_lock_interruptible(drm_dev); if (ret) return ret; if (dev_priv->l3_parity.remap_info[slice]) memcpy(buf, dev_priv->l3_parity.remap_info[slice] + (offset/4), count); else memset(buf, 0, count); mutex_unlock(&drm_dev->struct_mutex); return count; }
static ssize_t i915_l3_write(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t offset, size_t count) { struct device *dev = kobj_to_dev(kobj); struct drm_minor *dminor = dev_to_drm_minor(dev); struct drm_device *drm_dev = dminor->dev; struct drm_i915_private *dev_priv = drm_dev->dev_private; struct intel_context *ctx; u32 *temp = NULL; /* Just here to make handling failures easy */ int slice = (int)(uintptr_t)attr->private; int ret; if (!HAS_HW_CONTEXTS(drm_dev)) return -ENXIO; ret = l3_access_valid(drm_dev, offset); if (ret) return ret; ret = i915_mutex_lock_interruptible(drm_dev); if (ret) return ret; if (!dev_priv->l3_parity.remap_info[slice]) { temp = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL); if (!temp) { mutex_unlock(&drm_dev->struct_mutex); return -ENOMEM; } } ret = i915_gpu_idle(drm_dev); if (ret) { kfree(temp); mutex_unlock(&drm_dev->struct_mutex); return ret; } /* TODO: Ideally we really want a GPU reset here to make sure errors * aren't propagated. Since I cannot find a stable way to reset the GPU * at this point it is left as a TODO. */ if (temp) dev_priv->l3_parity.remap_info[slice] = temp; memcpy(dev_priv->l3_parity.remap_info[slice] + (offset/4), buf, count); /* NB: We defer the remapping until we switch to the context */ list_for_each_entry(ctx, &dev_priv->context_list, link) ctx->remap_slice |= (1<<slice); mutex_unlock(&drm_dev->struct_mutex); return count; }
static ssize_t i915_l3_write(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t offset, size_t count) { struct device *kdev = kobj_to_dev(kobj); struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); struct drm_device *dev = &dev_priv->drm; struct i915_gem_context *ctx; int slice = (int)(uintptr_t)attr->private; u32 **remap_info; int ret; ret = l3_access_valid(dev_priv, offset); if (ret) return ret; ret = i915_mutex_lock_interruptible(dev); if (ret) return ret; remap_info = &dev_priv->l3_parity.remap_info[slice]; if (!*remap_info) { *remap_info = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL); if (!*remap_info) { ret = -ENOMEM; goto out; } } /* TODO: Ideally we really want a GPU reset here to make sure errors * aren't propagated. Since I cannot find a stable way to reset the GPU * at this point it is left as a TODO. */ memcpy(*remap_info + (offset/4), buf, count); /* NB: We defer the remapping until we switch to the context */ list_for_each_entry(ctx, &dev_priv->context_list, link) ctx->remap_slice |= (1<<slice); ret = count; out: mutex_unlock(&dev->struct_mutex); return ret; }