Skip to content

Commit f4db23f

Browse files
Thomas Hellströmmatt-auld
authored andcommitted
drm/i915/ttm: Embed a ttm buffer object in the i915 gem object
Embed a struct ttm_buffer_object into the i915 gem object, making sure we alias the gem object part. It's a bit unfortunate that the struct ttm_buffer_ojbect embeds a gem object since we otherwise could make the TTM part private to the TTM backend, and use the usual i915 gem object for the other backends. To make this a bit more storage efficient for the other backends, we'd have to use a pointer for the gem object which would require a lot of changes in the driver. We postpone that for later. Signed-off-by: Thomas Hellström <[email protected]> Acked-by: Maarten Lankhorst <[email protected]> Signed-off-by: Matthew Auld <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent d148738 commit f4db23f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

drivers/gpu/drm/i915/gem/i915_gem_object.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
6262
const struct drm_i915_gem_object_ops *ops,
6363
struct lock_class_key *key, unsigned flags)
6464
{
65+
/*
66+
* A gem object is embedded both in a struct ttm_buffer_object :/ and
67+
* in a drm_i915_gem_object. Make sure they are aliased.
68+
*/
69+
BUILD_BUG_ON(offsetof(typeof(*obj), base) !=
70+
offsetof(typeof(*obj), __do_not_access.base));
71+
6572
spin_lock_init(&obj->vma.lock);
6673
INIT_LIST_HEAD(&obj->vma.list);
6774

drivers/gpu/drm/i915/gem/i915_gem_object_types.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/mmu_notifier.h>
1111

1212
#include <drm/drm_gem.h>
13+
#include <drm/ttm/ttm_bo_api.h>
1314
#include <uapi/drm/i915_drm.h>
1415

1516
#include "i915_active.h"
@@ -99,7 +100,16 @@ struct i915_gem_object_page_iter {
99100
};
100101

101102
struct drm_i915_gem_object {
102-
struct drm_gem_object base;
103+
/*
104+
* We might have reason to revisit the below since it wastes
105+
* a lot of space for non-ttm gem objects.
106+
* In any case, always use the accessors for the ttm_buffer_object
107+
* when accessing it.
108+
*/
109+
union {
110+
struct drm_gem_object base;
111+
struct ttm_buffer_object __do_not_access;
112+
};
103113

104114
const struct drm_i915_gem_object_ops *ops;
105115

0 commit comments

Comments
 (0)