@@ -109,8 +109,8 @@ void intel_vgt_deballoon(struct drm_i915_private *dev_priv)
DRM_DEBUG("VGT deballoon.\n");
for (i = 0; i < 4; i++) {
- if (bl_info.space[i].allocated)
- drm_mm_remove_node(&bl_info.space[i]);
+ dev_priv->ggtt.base.reserved -= bl_info.space[i].size;
+ drm_mm_remove_node(&bl_info.space[i]);
}
memset(&bl_info, 0, sizeof(bl_info));
@@ -120,6 +120,7 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt,
struct drm_mm_node *node,
unsigned long start, unsigned long end)
{
+ int ret;
unsigned long size = end - start;
if (start >= end)
@@ -127,9 +128,12 @@ static int vgt_balloon_space(struct i915_ggtt *ggtt,
DRM_INFO("balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",
start, end, size / 1024);
- return i915_gem_gtt_reserve(&ggtt->base, node,
+ ret = i915_gem_gtt_reserve(&ggtt->base, node,
size, start, I915_COLOR_UNEVICTABLE,
0);
+ if (!ret)
+ ggtt->base.reserved += size;
+ return ret;
}
/**
@@ -215,14 +219,14 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv)
ggtt->mappable_end, unmappable_base);
if (ret)
- goto err;
+ goto out_err;
}
if (unmappable_end < ggtt_end) {
ret = vgt_balloon_space(ggtt, &bl_info.space[3],
unmappable_end, ggtt_end);
if (ret)
- goto err;
+ goto deballoon_upon_mappable;
}
/* Mappable graphic memory ballooning */
@@ -231,7 +235,7 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv)
0, mappable_base);
if (ret)
- goto err;
+ goto deballoon_upon_unmappable;
}
if (mappable_end < ggtt->mappable_end) {
@@ -239,14 +243,23 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv)
mappable_end, ggtt->mappable_end);
if (ret)
- goto err;
+ goto deballoon_below_mappable;
}
DRM_INFO("VGT balloon successfully\n");
return 0;
-err:
+deballoon_below_mappable:
+ ggtt->base.reserved -= bl_info.space[0].size;
+ drm_mm_remove_node(&bl_info.space[0]);
+deballoon_upon_unmappable:
+ ggtt->base.reserved -= bl_info.space[3].size;
+ drm_mm_remove_node(&bl_info.space[3]);
+deballoon_upon_mappable:
+ ggtt->base.reserved -= bl_info.space[2].size;
+ drm_mm_remove_node(&bl_info.space[2]);
+out_err:
DRM_ERROR("VGT balloon fail\n");
- intel_vgt_deballoon(dev_priv);
+ memset(&bl_info, 0, sizeof(bl_info));
return ret;
}