Skip to content

Commit

Permalink
drm/i915: Compare GGTT view structs instead of types
Browse files Browse the repository at this point in the history
To allow for views where the view type is not defined by the view type only,
like it is in stereo or rotated 90 degree view, change the semantic to require
the whole view structure for comparison when we match a GGTT view.

This allows including parameters like offset to be included in the view which
is useful for eg. partial views.

v3:
- Rely on ggtt_view type being 0 for non-GGTT vma's, which equals to
  I915_GGTT_VIEW_NORMAL. (Daniel Vetter)
- Do not use potentially slower comparison when we only want to know if
  something is or is not a normal view.
- Rebase on top of rotated view patches. Add rotated view singleton.
- If one view is missing in comparison they're equal only if both are missing.

v4:
- Use comparison helper in obj_to_ggtt_view too. (Tvrtko Ursulin)
- Do WARN_ON if one view is NULL. (Tvrtko Ursulin)

Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  • Loading branch information
Joonas Lahtinen authored and Daniel Vetter committed Mar 27, 2015
1 parent 2f2cf68 commit 9abc464
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
8 changes: 4 additions & 4 deletions drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2795,19 +2795,19 @@ void i915_gem_restore_fences(struct drm_device *dev);

unsigned long
i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
enum i915_ggtt_view_type view);
const struct i915_ggtt_view *view);
unsigned long
i915_gem_obj_offset(struct drm_i915_gem_object *o,
struct i915_address_space *vm);
static inline unsigned long
i915_gem_obj_ggtt_offset(struct drm_i915_gem_object *o)
{
return i915_gem_obj_ggtt_offset_view(o, I915_GGTT_VIEW_NORMAL);
return i915_gem_obj_ggtt_offset_view(o, &i915_ggtt_view_normal);
}

bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o);
bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
enum i915_ggtt_view_type view);
const struct i915_ggtt_view *view);
bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
struct i915_address_space *vm);

Expand Down Expand Up @@ -2855,7 +2855,7 @@ i915_vm_to_ppgtt(struct i915_address_space *vm)

static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
{
return i915_gem_obj_ggtt_bound_view(obj, I915_GGTT_VIEW_NORMAL);
return i915_gem_obj_ggtt_bound_view(obj, &i915_ggtt_view_normal);
}

static inline unsigned long
Expand Down
16 changes: 9 additions & 7 deletions drivers/gpu/drm/i915/i915_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -4129,7 +4129,7 @@ i915_gem_object_do_pin(struct drm_i915_gem_object *obj,

if (i915_vma_misplaced(vma, alignment, flags)) {
unsigned long offset;
offset = ggtt_view ? i915_gem_obj_ggtt_offset_view(obj, ggtt_view->type) :
offset = ggtt_view ? i915_gem_obj_ggtt_offset_view(obj, ggtt_view) :
i915_gem_obj_offset(obj, vm);
WARN(vma->pin_count,
"bo is already pinned in %s with incorrect alignment:"
Expand Down Expand Up @@ -4228,7 +4228,7 @@ i915_gem_object_ggtt_unpin_view(struct drm_i915_gem_object *obj,

BUG_ON(!vma);
WARN_ON(vma->pin_count == 0);
WARN_ON(!i915_gem_obj_ggtt_bound_view(obj, view->type));
WARN_ON(!i915_gem_obj_ggtt_bound_view(obj, view));

if (--vma->pin_count == 0 && view->type == I915_GGTT_VIEW_NORMAL)
obj->pin_mappable = false;
Expand Down Expand Up @@ -4550,7 +4550,8 @@ struct i915_vma *i915_gem_obj_to_ggtt_view(struct drm_i915_gem_object *obj,
return ERR_PTR(-EINVAL);

list_for_each_entry(vma, &obj->vma_list, vma_link)
if (vma->vm == ggtt && vma->ggtt_view.type == view->type)
if (vma->vm == ggtt &&
i915_ggtt_view_equal(&vma->ggtt_view, view))
return vma;
return NULL;
}
Expand Down Expand Up @@ -5107,13 +5108,14 @@ i915_gem_obj_offset(struct drm_i915_gem_object *o,

unsigned long
i915_gem_obj_ggtt_offset_view(struct drm_i915_gem_object *o,
enum i915_ggtt_view_type view)
const struct i915_ggtt_view *view)
{
struct i915_address_space *ggtt = i915_obj_to_ggtt(o);
struct i915_vma *vma;

list_for_each_entry(vma, &o->vma_list, vma_link)
if (vma->vm == ggtt && vma->ggtt_view.type == view)
if (vma->vm == ggtt &&
i915_ggtt_view_equal(&vma->ggtt_view, view))
return vma->node.start;

WARN(1, "global vma for this object not found.\n");
Expand All @@ -5137,14 +5139,14 @@ bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
}

bool i915_gem_obj_ggtt_bound_view(struct drm_i915_gem_object *o,
enum i915_ggtt_view_type view)
const struct i915_ggtt_view *view)
{
struct i915_address_space *ggtt = i915_obj_to_ggtt(o);
struct i915_vma *vma;

list_for_each_entry(vma, &o->vma_list, vma_link)
if (vma->vm == ggtt &&
vma->ggtt_view.type == view &&
i915_ggtt_view_equal(&vma->ggtt_view, view) &&
drm_mm_node_allocated(&vma->node))
return true;

Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/i915/i915_gem_gtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
*/

const struct i915_ggtt_view i915_ggtt_view_normal;
const struct i915_ggtt_view i915_ggtt_view_rotated = {
.type = I915_GGTT_VIEW_ROTATED
};

static void bdw_setup_private_ppat(struct drm_i915_private *dev_priv);
static void chv_setup_private_ppat(struct drm_i915_private *dev_priv);
Expand Down
11 changes: 11 additions & 0 deletions drivers/gpu/drm/i915/i915_gem_gtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct i915_ggtt_view {
};

extern const struct i915_ggtt_view i915_ggtt_view_normal;
extern const struct i915_ggtt_view i915_ggtt_view_rotated;

enum i915_cache_level;

Expand Down Expand Up @@ -424,4 +425,14 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev);
int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);

static inline bool
i915_ggtt_view_equal(const struct i915_ggtt_view *a,
const struct i915_ggtt_view *b)
{
if (WARN_ON(!a || !b))
return false;

return a->type == b->type;
}

#endif
8 changes: 3 additions & 5 deletions drivers/gpu/drm/i915/intel_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -2322,8 +2322,6 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
const struct drm_plane_state *plane_state)
{
struct intel_rotation_info *info = &view->rotation_info;
static const struct i915_ggtt_view rotated_view =
{ .type = I915_GGTT_VIEW_ROTATED };

*view = i915_ggtt_view_normal;

Expand All @@ -2333,7 +2331,7 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
if (!intel_rotation_90_or_270(plane_state->rotation))
return 0;

*view = rotated_view;
*view = i915_ggtt_view_rotated;

info->height = fb->height;
info->pixel_format = fb->pixel_format;
Expand Down Expand Up @@ -2930,10 +2928,10 @@ u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier,
unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane,
struct drm_i915_gem_object *obj)
{
enum i915_ggtt_view_type view = I915_GGTT_VIEW_NORMAL;
const struct i915_ggtt_view *view = &i915_ggtt_view_normal;

if (intel_rotation_90_or_270(intel_plane->base.state->rotation))
view = I915_GGTT_VIEW_ROTATED;
view = &i915_ggtt_view_rotated;

return i915_gem_obj_ggtt_offset_view(obj, view);
}
Expand Down

0 comments on commit 9abc464

Please sign in to comment.