Add alignment to all aperture allocation requests.

When pinning buffers, or using execbuffer, allow the application to specify
the necessary aperture allocation alignment constraints.
main
Keith Packard 2008-05-01 20:41:55 -07:00
parent 30efad5113
commit 0d547c9ed9
2 changed files with 21 additions and 10 deletions

View File

@ -96,21 +96,26 @@ i915_gem_object_unbind(struct drm_device *dev, struct drm_gem_object *obj)
* Finds free space in the GTT aperture and binds the object there. * Finds free space in the GTT aperture and binds the object there.
*/ */
static int static int
i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj) i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj, unsigned alignment)
{ {
drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_i915_gem_object *obj_priv = obj->driver_private; struct drm_i915_gem_object *obj_priv = obj->driver_private;
struct drm_memrange_node *free_space; struct drm_memrange_node *free_space;
int page_count, i; int page_count, i;
if (alignment == 0)
alignment = PAGE_SIZE;
if (alignment & (PAGE_SIZE - 1))
return -EINVAL;
free_space = drm_memrange_search_free(&dev_priv->mm.gtt_space, free_space = drm_memrange_search_free(&dev_priv->mm.gtt_space,
obj->size, obj->size,
PAGE_SIZE, 0); alignment, 0);
if (free_space == NULL) if (free_space == NULL)
return -ENOMEM; return -ENOMEM;
obj_priv->gtt_space = drm_memrange_get_block(free_space, obj_priv->gtt_space = drm_memrange_get_block(free_space,
obj->size, obj->size,
PAGE_SIZE); alignment);
if (obj_priv->gtt_space == NULL) if (obj_priv->gtt_space == NULL)
return -ENOMEM; return -ENOMEM;
@ -173,7 +178,7 @@ i915_gem_reloc_and_validate_object(struct drm_device *dev,
/* Choose the GTT offset for our buffer and put it there. */ /* Choose the GTT offset for our buffer and put it there. */
if (obj_priv->gtt_space == NULL) { if (obj_priv->gtt_space == NULL) {
i915_gem_object_bind_to_gtt(dev, obj); i915_gem_object_bind_to_gtt(dev, obj, (unsigned) entry->alignment);
if (obj_priv->gtt_space == NULL) if (obj_priv->gtt_space == NULL)
return -ENOMEM; return -ENOMEM;
} }
@ -367,7 +372,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
return -EINVAL; return -EINVAL;
} }
ret = i915_gem_object_bind_to_gtt(dev, obj); ret = i915_gem_object_bind_to_gtt(dev, obj, (unsigned) args->alignment);
if (ret != 0) { if (ret != 0) {
DRM_ERROR("Failure to bind in i915_gem_pin_ioctl(): %d\n", DRM_ERROR("Failure to bind in i915_gem_pin_ioctl(): %d\n",
ret); ret);

View File

@ -451,15 +451,18 @@ struct drm_i915_gem_validate_entry {
* operation. * operation.
*/ */
uint32_t buffer_handle; uint32_t buffer_handle;
/** List of relocations to be performed on this buffer */
uint32_t relocation_count;
uint64_t relocs_ptr; /* struct drm_i915_gem_relocation_entry *relocs */
/** Required alignment in graphics aperture */
uint64_t alignment;
/** /**
* Returned value of the updated offset of the buffer, for future * Returned value of the updated offset of the buffer, for future
* presumed_offset writes. * presumed_offset writes.
*/ */
uint32_t buffer_offset; uint64_t buffer_offset;
/** List of relocations to be performed on this buffer */
uint64_t relocs_ptr; /* struct drm_i915_gem_relocation_entry *relocs */
uint32_t relocation_count;
uint32_t pad;
}; };
struct drm_i915_gem_execbuffer { struct drm_i915_gem_execbuffer {
@ -489,6 +492,9 @@ struct drm_i915_gem_pin {
uint32_t handle; uint32_t handle;
uint32_t pad; uint32_t pad;
/** alignment required within the aperture */
uint64_t alignment;
/** Returned GTT offset of the buffer. */ /** Returned GTT offset of the buffer. */
uint64_t offset; uint64_t offset;
}; };