Skip to content

Commit 668b206

Browse files
committed
drm/vmwgfx: Stop using raw ttm_buffer_object's
Various bits of the driver used raw ttm_buffer_object instead of the driver specific vmw_bo object. All those places used to duplicate the mapped bo caching policy of vmw_bo. Instead of duplicating all of that code and special casing various functions to work both with vmw_bo and raw ttm_buffer_object's unify the buffer object handling code. As part of that work fix the naming of bo's, e.g. insted of generic backup use 'guest_memory' because that's what it really is. All of it makes the driver easier to maintain and the code easier to read. Saves 100+ loc as well. Signed-off-by: Zack Rusin <[email protected]> Reviewed-by: Martin Krastev <[email protected]> Reviewed-by: Maaz Mombasawala <[email protected]> Acked-by: Thomas Zimmermann <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 39985ee commit 668b206

27 files changed

+563
-688
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 57 additions & 141 deletions
Large diffs are not rendered by default.

drivers/gpu/drm/vmwgfx/vmwgfx_bo.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,54 +49,54 @@ enum vmw_bo_domain {
4949
VMW_BO_DOMAIN_MOB = BIT(4),
5050
};
5151

52+
struct vmw_bo_params {
53+
u32 domain;
54+
u32 busy_domain;
55+
enum ttm_bo_type bo_type;
56+
size_t size;
57+
bool pin;
58+
};
59+
5260
/**
5361
* struct vmw_bo - TTM buffer object with vmwgfx additions
54-
* @base: The TTM buffer object
62+
* @tbo: The TTM buffer object
63+
* @placement: The preferred placement for this buffer object
64+
* @places: The chosen places for the preferred placement.
65+
* @busy_places: Chosen busy places for the preferred placement
66+
* @map: Kmap object for semi-persistent mappings
5567
* @res_tree: RB tree of resources using this buffer object as a backing MOB
68+
* @res_prios: Eviction priority counts for attached resources
5669
* @cpu_writers: Number of synccpu write grabs. Protected by reservation when
5770
* increased. May be decreased without reservation.
5871
* @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
59-
* @map: Kmap object for semi-persistent mappings
60-
* @res_prios: Eviction priority counts for attached resources
6172
* @dirty: structure for user-space dirty-tracking
6273
*/
6374
struct vmw_bo {
64-
struct ttm_buffer_object base;
75+
struct ttm_buffer_object tbo;
6576

6677
struct ttm_placement placement;
6778
struct ttm_place places[5];
6879
struct ttm_place busy_places[5];
6980

81+
/* Protected by reservation */
82+
struct ttm_bo_kmap_obj map;
83+
7084
struct rb_root res_tree;
85+
u32 res_prios[TTM_MAX_BO_PRIORITY];
7186

7287
atomic_t cpu_writers;
7388
/* Not ref-counted. Protected by binding_mutex */
7489
struct vmw_resource *dx_query_ctx;
75-
/* Protected by reservation */
76-
struct ttm_bo_kmap_obj map;
77-
u32 res_prios[TTM_MAX_BO_PRIORITY];
7890
struct vmw_bo_dirty *dirty;
7991
};
8092

8193
void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain);
8294
void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo);
8395

84-
int vmw_bo_create_kernel(struct vmw_private *dev_priv,
85-
unsigned long size,
86-
struct ttm_placement *placement,
87-
struct ttm_buffer_object **p_bo);
8896
int vmw_bo_create(struct vmw_private *dev_priv,
89-
size_t size,
90-
u32 domain,
91-
u32 busy_domain,
92-
bool interruptible, bool pin,
97+
struct vmw_bo_params *params,
9398
struct vmw_bo **p_bo);
94-
int vmw_bo_init(struct vmw_private *dev_priv,
95-
struct vmw_bo *vmw_bo,
96-
size_t size,
97-
u32 domain,
98-
u32 busy_domain,
99-
bool interruptible, bool pin);
99+
100100
int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
101101
struct drm_file *file_priv);
102102

@@ -118,9 +118,6 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
118118
SVGAGuestPtr *ptr);
119119
int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
120120
struct drm_file *file_priv);
121-
int vmw_user_bo_lookup(struct drm_file *filp,
122-
uint32_t handle,
123-
struct vmw_bo **out);
124121
void vmw_bo_fence_single(struct ttm_buffer_object *bo,
125122
struct vmw_fence_obj *fence);
126123

@@ -131,6 +128,9 @@ void vmw_bo_move_notify(struct ttm_buffer_object *bo,
131128
struct ttm_resource *mem);
132129
void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
133130

131+
int vmw_user_bo_lookup(struct drm_file *filp,
132+
u32 handle,
133+
struct vmw_bo **out);
134134
/**
135135
* vmw_bo_adjust_prio - Adjust the buffer object eviction priority
136136
* according to attached resources
@@ -142,12 +142,12 @@ static inline void vmw_bo_prio_adjust(struct vmw_bo *vbo)
142142

143143
while (i--) {
144144
if (vbo->res_prios[i]) {
145-
vbo->base.priority = i;
145+
vbo->tbo.priority = i;
146146
return;
147147
}
148148
}
149149

150-
vbo->base.priority = 3;
150+
vbo->tbo.priority = 3;
151151
}
152152

153153
/**
@@ -166,7 +166,7 @@ static inline void vmw_bo_prio_add(struct vmw_bo *vbo, int prio)
166166
}
167167

168168
/**
169-
* vmw_bo_prio_del - Notify a buffer object of a resource with a certain
169+
* vmw_bo_used_prio_del - Notify a buffer object of a resource with a certain
170170
* priority being removed
171171
* @vbo: The struct vmw_bo
172172
* @prio: The resource priority
@@ -186,18 +186,18 @@ static inline void vmw_bo_unreference(struct vmw_bo **buf)
186186

187187
*buf = NULL;
188188
if (tmp_buf)
189-
ttm_bo_put(&tmp_buf->base);
189+
ttm_bo_put(&tmp_buf->tbo);
190190
}
191191

192192
static inline struct vmw_bo *vmw_bo_reference(struct vmw_bo *buf)
193193
{
194-
ttm_bo_get(&buf->base);
194+
ttm_bo_get(&buf->tbo);
195195
return buf;
196196
}
197197

198198
static inline struct vmw_bo *to_vmw_bo(struct drm_gem_object *gobj)
199199
{
200-
return container_of((gobj), struct vmw_bo, base.base);
200+
return container_of((gobj), struct vmw_bo, tbo.base);
201201
}
202202

203203
#endif // VMWGFX_BO_H

drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static int vmw_cmd_emit_dummy_legacy_query(struct vmw_private *dev_priv,
567567
* without writing to the query result structure.
568568
*/
569569

570-
struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->base;
570+
struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->tbo;
571571
struct {
572572
SVGA3dCmdHeader header;
573573
SVGA3dCmdWaitForQuery body;
@@ -613,7 +613,7 @@ static int vmw_cmd_emit_dummy_gb_query(struct vmw_private *dev_priv,
613613
* without writing to the query result structure.
614614
*/
615615

616-
struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->base;
616+
struct ttm_buffer_object *bo = &dev_priv->dummy_query_bo->tbo;
617617
struct {
618618
SVGA3dCmdHeader header;
619619
SVGA3dCmdWaitForGBQuery body;

drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct vmw_cmdbuf_context {
8080
* frees are protected by @lock.
8181
* @cmd_space: Buffer object for the command buffer space, unless we were
8282
* able to make a contigous coherent DMA memory allocation, @handle. Immutable.
83-
* @map_obj: Mapping state for @cmd_space. Immutable.
8483
* @map: Pointer to command buffer space. May be a mapped buffer object or
8584
* a contigous coherent DMA memory allocation. Immutable.
8685
* @cur: Command buffer for small kernel command submissions. Protected by
@@ -117,8 +116,7 @@ struct vmw_cmdbuf_man {
117116
struct vmw_cmdbuf_context ctx[SVGA_CB_CONTEXT_MAX];
118117
struct list_head error;
119118
struct drm_mm mm;
120-
struct ttm_buffer_object *cmd_space;
121-
struct ttm_bo_kmap_obj map_obj;
119+
struct vmw_bo *cmd_space;
122120
u8 *map;
123121
struct vmw_cmdbuf_header *cur;
124122
size_t cur_pos;
@@ -889,7 +887,7 @@ static int vmw_cmdbuf_space_pool(struct vmw_cmdbuf_man *man,
889887
header->cmd = man->map + offset;
890888
if (man->using_mob) {
891889
cb_hdr->flags = SVGA_CB_FLAG_MOB;
892-
cb_hdr->ptr.mob.mobid = man->cmd_space->resource->start;
890+
cb_hdr->ptr.mob.mobid = man->cmd_space->tbo.resource->start;
893891
cb_hdr->ptr.mob.mobOffset = offset;
894892
} else {
895893
cb_hdr->ptr.pa = (u64)man->handle + (u64)offset;
@@ -1222,7 +1220,6 @@ static int vmw_cmdbuf_startstop(struct vmw_cmdbuf_man *man, u32 context,
12221220
int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size)
12231221
{
12241222
struct vmw_private *dev_priv = man->dev_priv;
1225-
bool dummy;
12261223
int ret;
12271224

12281225
if (man->has_pool)
@@ -1235,6 +1232,13 @@ int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size)
12351232
if (man->map) {
12361233
man->using_mob = false;
12371234
} else {
1235+
struct vmw_bo_params bo_params = {
1236+
.domain = VMW_BO_DOMAIN_MOB,
1237+
.busy_domain = VMW_BO_DOMAIN_MOB,
1238+
.bo_type = ttm_bo_type_kernel,
1239+
.size = size,
1240+
.pin = true
1241+
};
12381242
/*
12391243
* DMA memory failed. If we can have command buffers in a
12401244
* MOB, try to use that instead. Note that this will
@@ -1245,19 +1249,12 @@ int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size)
12451249
!dev_priv->has_mob)
12461250
return -ENOMEM;
12471251

1248-
ret = vmw_bo_create_kernel(dev_priv, size,
1249-
&vmw_mob_placement,
1250-
&man->cmd_space);
1252+
ret = vmw_bo_create(dev_priv, &bo_params, &man->cmd_space);
12511253
if (ret)
12521254
return ret;
12531255

1254-
man->using_mob = true;
1255-
ret = ttm_bo_kmap(man->cmd_space, 0, size >> PAGE_SHIFT,
1256-
&man->map_obj);
1257-
if (ret)
1258-
goto out_no_map;
1259-
1260-
man->map = ttm_kmap_obj_virtual(&man->map_obj, &dummy);
1256+
man->map = vmw_bo_map_and_cache(man->cmd_space);
1257+
man->using_mob = man->map;
12611258
}
12621259

12631260
man->size = size;
@@ -1277,14 +1274,6 @@ int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size)
12771274
(man->using_mob) ? "MOB" : "DMA");
12781275

12791276
return 0;
1280-
1281-
out_no_map:
1282-
if (man->using_mob) {
1283-
ttm_bo_put(man->cmd_space);
1284-
man->cmd_space = NULL;
1285-
}
1286-
1287-
return ret;
12881277
}
12891278

12901279
/**
@@ -1383,14 +1372,11 @@ void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man)
13831372
man->has_pool = false;
13841373
man->default_size = VMW_CMDBUF_INLINE_SIZE;
13851374
(void) vmw_cmdbuf_idle(man, false, 10*HZ);
1386-
if (man->using_mob) {
1387-
(void) ttm_bo_kunmap(&man->map_obj);
1388-
ttm_bo_put(man->cmd_space);
1389-
man->cmd_space = NULL;
1390-
} else {
1375+
if (man->using_mob)
1376+
vmw_bo_unreference(&man->cmd_space);
1377+
else
13911378
dma_free_coherent(man->dev_priv->drm.dev,
13921379
man->size, man->map, man->handle);
1393-
}
13941380
}
13951381

13961382
/**

drivers/gpu/drm/vmwgfx/vmwgfx_context.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const struct vmw_user_resource_conv *user_context_converter =
7373

7474
static const struct vmw_res_func vmw_legacy_context_func = {
7575
.res_type = vmw_res_context,
76-
.needs_backup = false,
76+
.needs_guest_memory = false,
7777
.may_evict = false,
7878
.type_name = "legacy contexts",
7979
.domain = VMW_BO_DOMAIN_SYS,
@@ -86,7 +86,7 @@ static const struct vmw_res_func vmw_legacy_context_func = {
8686

8787
static const struct vmw_res_func vmw_gb_context_func = {
8888
.res_type = vmw_res_context,
89-
.needs_backup = true,
89+
.needs_guest_memory = true,
9090
.may_evict = true,
9191
.prio = 3,
9292
.dirty_prio = 3,
@@ -101,7 +101,7 @@ static const struct vmw_res_func vmw_gb_context_func = {
101101

102102
static const struct vmw_res_func vmw_dx_context_func = {
103103
.res_type = vmw_res_dx_context,
104-
.needs_backup = true,
104+
.needs_guest_memory = true,
105105
.may_evict = true,
106106
.prio = 3,
107107
.dirty_prio = 3,
@@ -186,7 +186,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
186186
struct vmw_user_context *uctx =
187187
container_of(res, struct vmw_user_context, res);
188188

189-
res->backup_size = (dx ? sizeof(SVGADXContextMobFormat) :
189+
res->guest_memory_size = (dx ? sizeof(SVGADXContextMobFormat) :
190190
sizeof(SVGAGBContextData));
191191
ret = vmw_resource_init(dev_priv, res, true,
192192
res_free,
@@ -358,8 +358,8 @@ static int vmw_gb_context_bind(struct vmw_resource *res,
358358
cmd->header.size = sizeof(cmd->body);
359359
cmd->body.cid = res->id;
360360
cmd->body.mobid = bo->resource->start;
361-
cmd->body.validContents = res->backup_dirty;
362-
res->backup_dirty = false;
361+
cmd->body.validContents = res->guest_memory_dirty;
362+
res->guest_memory_dirty = false;
363363
vmw_cmd_commit(dev_priv, sizeof(*cmd));
364364

365365
return 0;
@@ -525,8 +525,8 @@ static int vmw_dx_context_bind(struct vmw_resource *res,
525525
cmd->header.size = sizeof(cmd->body);
526526
cmd->body.cid = res->id;
527527
cmd->body.mobid = bo->resource->start;
528-
cmd->body.validContents = res->backup_dirty;
529-
res->backup_dirty = false;
528+
cmd->body.validContents = res->guest_memory_dirty;
529+
res->guest_memory_dirty = false;
530530
vmw_cmd_commit(dev_priv, sizeof(*cmd));
531531

532532

0 commit comments

Comments
 (0)