Newer
Older
* Unpins the display surface
*
* Returns 0 on success
*/
static void
vmw_stdu_primary_plane_cleanup_fb(struct drm_plane *plane,
struct drm_plane_state *old_state)
{
struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
if (vps->surf)
WARN_ON(!vps->pinned);
vmw_du_plane_cleanup_fb(plane, old_state);
vps->content_fb_type = SAME_AS_DISPLAY;
}
/**
* vmw_stdu_primary_plane_prepare_fb - Readies the display surface
*
* @plane: display plane
* @new_state: info on the new plane state, including the FB
*
* This function allocates a new display surface if the content is
* backed by a buffer object. The display surface is pinned here, and it'll
* be unpinned in .cleanup_fb()
*
* Returns 0 on success
*/
static int
vmw_stdu_primary_plane_prepare_fb(struct drm_plane *plane,
struct drm_plane_state *new_state)
{
struct vmw_private *dev_priv = vmw_priv(plane->dev);
struct drm_framebuffer *new_fb = new_state->fb;
struct vmw_framebuffer *vfb;
struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
enum stdu_content_type new_content_type;
struct vmw_framebuffer_surface *new_vfbs;
uint32_t hdisplay = new_state->crtc_w, vdisplay = new_state->crtc_h;
int ret;
/* No FB to prepare */
if (!new_fb) {
if (vps->surf) {
WARN_ON(vps->pinned != 0);
vmw_surface_unreference(&vps->surf);
}
return 0;
}
vfb = vmw_framebuffer_to_vfb(new_fb);
new_vfbs = (vfb->bo) ? NULL : vmw_framebuffer_to_vfbs(new_fb);
if (new_vfbs &&
new_vfbs->surface->metadata.base_size.width == hdisplay &&
new_vfbs->surface->metadata.base_size.height == vdisplay)
new_content_type = SAME_AS_DISPLAY;
else if (vfb->bo)
new_content_type = SEPARATE_BO;
else
new_content_type = SEPARATE_SURFACE;
if (new_content_type != SAME_AS_DISPLAY) {
struct vmw_surface_metadata metadata = {0};
* If content buffer is a buffer object, then we have to
* construct surface info
if (new_content_type == SEPARATE_BO) {
switch (new_fb->format->cpp[0]*8) {
case 32:
metadata.format = SVGA3D_X8R8G8B8;
break;
case 16:
metadata.format = SVGA3D_R5G6B5;
break;
case 8:
metadata.format = SVGA3D_P8;
break;
default:
DRM_ERROR("Invalid format\n");
return -EINVAL;
}
metadata.mip_levels[0] = 1;
metadata.num_sizes = 1;
metadata.scanout = true;
metadata = new_vfbs->surface->metadata;
metadata.base_size.width = hdisplay;
metadata.base_size.height = vdisplay;
metadata.base_size.depth = 1;
struct drm_vmw_size cur_base_size =
vps->surf->metadata.base_size;
if (cur_base_size.width != metadata.base_size.width ||
cur_base_size.height != metadata.base_size.height ||
vps->surf->metadata.format != metadata.format) {
WARN_ON(vps->pinned != 0);
vmw_surface_unreference(&vps->surf);
}
}
if (!vps->surf) {
ret = vmw_gb_surface_define(dev_priv, 0, &metadata,
&vps->surf);
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
if (ret != 0) {
DRM_ERROR("Couldn't allocate STDU surface.\n");
return ret;
}
}
} else {
/*
* prepare_fb and clean_fb should only take care of pinning
* and unpinning. References are tracked by state objects.
* The only time we add a reference in prepare_fb is if the
* state object doesn't have a reference to begin with
*/
if (vps->surf) {
WARN_ON(vps->pinned != 0);
vmw_surface_unreference(&vps->surf);
}
vps->surf = vmw_surface_reference(new_vfbs->surface);
}
if (vps->surf) {
/* Pin new surface before flipping */
ret = vmw_resource_pin(&vps->surf->res, false);
if (ret)
goto out_srf_unref;
vps->pinned++;
}
vps->content_fb_type = new_content_type;
* This should only happen if the buffer object is too large to create a
* proxy surface for.
* If we are a 2D VM with a buffer object then we have to use CPU blit
* so cache these mappings
*/
if (vps->content_fb_type == SEPARATE_BO &&

Thomas Hellstrom
committed
!(dev_priv->capabilities & SVGA_CAP_3D))
vps->cpp = new_fb->pitches[0] / new_fb->width;
return 0;
out_srf_unref:
vmw_surface_unreference(&vps->surf);
return ret;
}
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
static uint32_t vmw_stdu_bo_fifo_size(struct vmw_du_update_plane *update,
uint32_t num_hits)
{
return sizeof(struct vmw_stdu_dma) + sizeof(SVGA3dCopyBox) * num_hits +
sizeof(SVGA3dCmdSurfaceDMASuffix) +
sizeof(struct vmw_stdu_update);
}
static uint32_t vmw_stdu_bo_fifo_size_cpu(struct vmw_du_update_plane *update,
uint32_t num_hits)
{
return sizeof(struct vmw_stdu_update_gb_image) +
sizeof(struct vmw_stdu_update);
}
static uint32_t vmw_stdu_bo_populate_dma(struct vmw_du_update_plane *update,
void *cmd, uint32_t num_hits)
{
struct vmw_screen_target_display_unit *stdu;
struct vmw_framebuffer_bo *vfbbo;
struct vmw_stdu_dma *cmd_dma = cmd;
stdu = container_of(update->du, typeof(*stdu), base);
vfbbo = container_of(update->vfb, typeof(*vfbbo), base);
cmd_dma->header.id = SVGA_3D_CMD_SURFACE_DMA;
cmd_dma->header.size = sizeof(cmd_dma->body) +
sizeof(struct SVGA3dCopyBox) * num_hits +
sizeof(SVGA3dCmdSurfaceDMASuffix);
vmw_bo_get_guest_ptr(&vfbbo->buffer->base, &cmd_dma->body.guest.ptr);
cmd_dma->body.guest.pitch = update->vfb->base.pitches[0];
cmd_dma->body.host.sid = stdu->display_srf->res.id;
cmd_dma->body.host.face = 0;
cmd_dma->body.host.mipmap = 0;
cmd_dma->body.transfer = SVGA3D_WRITE_HOST_VRAM;
return sizeof(*cmd_dma);
}
static uint32_t vmw_stdu_bo_populate_clip(struct vmw_du_update_plane *update,
void *cmd, struct drm_rect *clip,
uint32_t fb_x, uint32_t fb_y)
{
struct SVGA3dCopyBox *box = cmd;
box->srcx = fb_x;
box->srcy = fb_y;
box->srcz = 0;
box->x = clip->x1;
box->y = clip->y1;
box->z = 0;
box->w = drm_rect_width(clip);
box->h = drm_rect_height(clip);
box->d = 1;
return sizeof(*box);
}
static uint32_t vmw_stdu_bo_populate_update(struct vmw_du_update_plane *update,
void *cmd, struct drm_rect *bb)
{
struct vmw_screen_target_display_unit *stdu;
struct vmw_framebuffer_bo *vfbbo;
SVGA3dCmdSurfaceDMASuffix *suffix = cmd;
stdu = container_of(update->du, typeof(*stdu), base);
vfbbo = container_of(update->vfb, typeof(*vfbbo), base);
suffix->suffixSize = sizeof(*suffix);
suffix->maximumOffset = vfbbo->buffer->base.base.size;
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
vmw_stdu_populate_update(&suffix[1], stdu->base.unit, bb->x1, bb->x2,
bb->y1, bb->y2);
return sizeof(*suffix) + sizeof(struct vmw_stdu_update);
}
static uint32_t vmw_stdu_bo_pre_clip_cpu(struct vmw_du_update_plane *update,
void *cmd, uint32_t num_hits)
{
struct vmw_du_update_plane_buffer *bo_update =
container_of(update, typeof(*bo_update), base);
bo_update->fb_left = INT_MAX;
bo_update->fb_top = INT_MAX;
return 0;
}
static uint32_t vmw_stdu_bo_clip_cpu(struct vmw_du_update_plane *update,
void *cmd, struct drm_rect *clip,
uint32_t fb_x, uint32_t fb_y)
{
struct vmw_du_update_plane_buffer *bo_update =
container_of(update, typeof(*bo_update), base);
bo_update->fb_left = min_t(int, bo_update->fb_left, fb_x);
bo_update->fb_top = min_t(int, bo_update->fb_top, fb_y);
return 0;
}
static uint32_t
vmw_stdu_bo_populate_update_cpu(struct vmw_du_update_plane *update, void *cmd,
struct drm_rect *bb)
{
struct vmw_du_update_plane_buffer *bo_update;
struct vmw_screen_target_display_unit *stdu;
struct vmw_framebuffer_bo *vfbbo;
struct vmw_diff_cpy diff = VMW_CPU_BLIT_DIFF_INITIALIZER(0);
struct vmw_stdu_update_gb_image *cmd_img = cmd;
struct vmw_stdu_update *cmd_update;
struct ttm_buffer_object *src_bo, *dst_bo;
u32 src_offset, dst_offset;
s32 src_pitch, dst_pitch;
s32 width, height;
bo_update = container_of(update, typeof(*bo_update), base);
stdu = container_of(update->du, typeof(*stdu), base);
vfbbo = container_of(update->vfb, typeof(*vfbbo), base);
width = bb->x2 - bb->x1;
height = bb->y2 - bb->y1;
diff.cpp = stdu->cpp;
dst_bo = &stdu->display_srf->res.backup->base;
dst_pitch = stdu->display_srf->metadata.base_size.width * stdu->cpp;
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
dst_offset = bb->y1 * dst_pitch + bb->x1 * stdu->cpp;
src_bo = &vfbbo->buffer->base;
src_pitch = update->vfb->base.pitches[0];
src_offset = bo_update->fb_top * src_pitch + bo_update->fb_left *
stdu->cpp;
(void) vmw_bo_cpu_blit(dst_bo, dst_offset, dst_pitch, src_bo,
src_offset, src_pitch, width * stdu->cpp, height,
&diff);
if (drm_rect_visible(&diff.rect)) {
SVGA3dBox *box = &cmd_img->body.box;
cmd_img->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE;
cmd_img->header.size = sizeof(cmd_img->body);
cmd_img->body.image.sid = stdu->display_srf->res.id;
cmd_img->body.image.face = 0;
cmd_img->body.image.mipmap = 0;
box->x = diff.rect.x1;
box->y = diff.rect.y1;
box->z = 0;
box->w = drm_rect_width(&diff.rect);
box->h = drm_rect_height(&diff.rect);
box->d = 1;
cmd_update = (struct vmw_stdu_update *)&cmd_img[1];
vmw_stdu_populate_update(cmd_update, stdu->base.unit,
diff.rect.x1, diff.rect.x2,
diff.rect.y1, diff.rect.y2);
return sizeof(*cmd_img) + sizeof(*cmd_update);
}
return 0;
}
/**
* vmw_stdu_plane_update_bo - Update display unit for bo backed fb.
* @dev_priv: device private.
* @plane: plane state.
* @old_state: old plane state.
* @vfb: framebuffer which is blitted to display unit.
* @out_fence: If non-NULL, will return a ref-counted pointer to vmw_fence_obj.
* The returned fence pointer may be NULL in which case the device
* has already synchronized.
*
* Return: 0 on success or a negative error code on failure.
*/
static int vmw_stdu_plane_update_bo(struct vmw_private *dev_priv,
struct drm_plane *plane,
struct drm_plane_state *old_state,
struct vmw_framebuffer *vfb,
struct vmw_fence_obj **out_fence)
{
struct vmw_du_update_plane_buffer bo_update;
memset(&bo_update, 0, sizeof(struct vmw_du_update_plane_buffer));
bo_update.base.plane = plane;
bo_update.base.old_state = old_state;
bo_update.base.dev_priv = dev_priv;
bo_update.base.du = vmw_crtc_to_du(plane->state->crtc);
bo_update.base.vfb = vfb;
bo_update.base.out_fence = out_fence;
bo_update.base.mutex = NULL;
bo_update.base.cpu_blit = !(dev_priv->capabilities & SVGA_CAP_3D);
bo_update.base.intr = false;
/*
* VM without 3D support don't have surface DMA command and framebuffer
* should be moved out of VRAM.
*/
if (bo_update.base.cpu_blit) {
bo_update.base.calc_fifo_size = vmw_stdu_bo_fifo_size_cpu;
bo_update.base.pre_clip = vmw_stdu_bo_pre_clip_cpu;
bo_update.base.clip = vmw_stdu_bo_clip_cpu;
bo_update.base.post_clip = vmw_stdu_bo_populate_update_cpu;
} else {
bo_update.base.calc_fifo_size = vmw_stdu_bo_fifo_size;
bo_update.base.pre_clip = vmw_stdu_bo_populate_dma;
bo_update.base.clip = vmw_stdu_bo_populate_clip;
bo_update.base.post_clip = vmw_stdu_bo_populate_update;
}
return vmw_du_helper_plane_update(&bo_update.base);
}
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
static uint32_t
vmw_stdu_surface_fifo_size_same_display(struct vmw_du_update_plane *update,
uint32_t num_hits)
{
struct vmw_framebuffer_surface *vfbs;
uint32_t size = 0;
vfbs = container_of(update->vfb, typeof(*vfbs), base);
if (vfbs->is_bo_proxy)
size += sizeof(struct vmw_stdu_update_gb_image) * num_hits;
size += sizeof(struct vmw_stdu_update);
return size;
}
static uint32_t vmw_stdu_surface_fifo_size(struct vmw_du_update_plane *update,
uint32_t num_hits)
{
struct vmw_framebuffer_surface *vfbs;
uint32_t size = 0;
vfbs = container_of(update->vfb, typeof(*vfbs), base);
if (vfbs->is_bo_proxy)
size += sizeof(struct vmw_stdu_update_gb_image) * num_hits;
size += sizeof(struct vmw_stdu_surface_copy) + sizeof(SVGA3dCopyBox) *
num_hits + sizeof(struct vmw_stdu_update);
return size;
}
static uint32_t
vmw_stdu_surface_update_proxy(struct vmw_du_update_plane *update, void *cmd)
{
struct vmw_framebuffer_surface *vfbs;
struct drm_plane_state *state = update->plane->state;
struct drm_plane_state *old_state = update->old_state;
struct vmw_stdu_update_gb_image *cmd_update = cmd;
struct drm_atomic_helper_damage_iter iter;
struct drm_rect clip;
uint32_t copy_size = 0;
vfbs = container_of(update->vfb, typeof(*vfbs), base);
/*
* proxy surface is special where a buffer object type fb is wrapped
* in a surface and need an update gb image command to sync with device.
*/
drm_atomic_helper_damage_iter_init(&iter, old_state, state);
drm_atomic_for_each_plane_damage(&iter, &clip) {
SVGA3dBox *box = &cmd_update->body.box;
cmd_update->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE;
cmd_update->header.size = sizeof(cmd_update->body);
cmd_update->body.image.sid = vfbs->surface->res.id;
cmd_update->body.image.face = 0;
cmd_update->body.image.mipmap = 0;
box->x = clip.x1;
box->y = clip.y1;
box->z = 0;
box->w = drm_rect_width(&clip);
box->h = drm_rect_height(&clip);
box->d = 1;
copy_size += sizeof(*cmd_update);
cmd_update++;
}
return copy_size;
}
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
static uint32_t
vmw_stdu_surface_populate_copy(struct vmw_du_update_plane *update, void *cmd,
uint32_t num_hits)
{
struct vmw_screen_target_display_unit *stdu;
struct vmw_framebuffer_surface *vfbs;
struct vmw_stdu_surface_copy *cmd_copy = cmd;
stdu = container_of(update->du, typeof(*stdu), base);
vfbs = container_of(update->vfb, typeof(*vfbs), base);
cmd_copy->header.id = SVGA_3D_CMD_SURFACE_COPY;
cmd_copy->header.size = sizeof(cmd_copy->body) + sizeof(SVGA3dCopyBox) *
num_hits;
cmd_copy->body.src.sid = vfbs->surface->res.id;
cmd_copy->body.dest.sid = stdu->display_srf->res.id;
return sizeof(*cmd_copy);
}
static uint32_t
vmw_stdu_surface_populate_clip(struct vmw_du_update_plane *update, void *cmd,
struct drm_rect *clip, uint32_t fb_x,
uint32_t fb_y)
{
struct SVGA3dCopyBox *box = cmd;
box->srcx = fb_x;
box->srcy = fb_y;
box->srcz = 0;
box->x = clip->x1;
box->y = clip->y1;
box->z = 0;
box->w = drm_rect_width(clip);
box->h = drm_rect_height(clip);
box->d = 1;
return sizeof(*box);
}
static uint32_t
vmw_stdu_surface_populate_update(struct vmw_du_update_plane *update, void *cmd,
struct drm_rect *bb)
{
vmw_stdu_populate_update(cmd, update->du->unit, bb->x1, bb->x2, bb->y1,
bb->y2);
return sizeof(struct vmw_stdu_update);
}
/**
* vmw_stdu_plane_update_surface - Update display unit for surface backed fb
* @dev_priv: Device private
* @plane: Plane state
* @old_state: Old plane state
* @vfb: Framebuffer which is blitted to display unit
* @out_fence: If non-NULL, will return a ref-counted pointer to vmw_fence_obj.
* The returned fence pointer may be NULL in which case the device
* has already synchronized.
*
* Return: 0 on success or a negative error code on failure.
*/
static int vmw_stdu_plane_update_surface(struct vmw_private *dev_priv,
struct drm_plane *plane,
struct drm_plane_state *old_state,
struct vmw_framebuffer *vfb,
struct vmw_fence_obj **out_fence)
{
struct vmw_du_update_plane srf_update;
struct vmw_screen_target_display_unit *stdu;
struct vmw_framebuffer_surface *vfbs;
stdu = vmw_crtc_to_stdu(plane->state->crtc);
vfbs = container_of(vfb, typeof(*vfbs), base);
memset(&srf_update, 0, sizeof(struct vmw_du_update_plane));
srf_update.plane = plane;
srf_update.old_state = old_state;
srf_update.dev_priv = dev_priv;
srf_update.du = vmw_crtc_to_du(plane->state->crtc);
srf_update.vfb = vfb;
srf_update.out_fence = out_fence;
srf_update.mutex = &dev_priv->cmdbuf_mutex;
srf_update.cpu_blit = false;
srf_update.intr = true;
if (vfbs->is_bo_proxy)
srf_update.post_prepare = vmw_stdu_surface_update_proxy;
if (vfbs->surface->res.id != stdu->display_srf->res.id) {
srf_update.calc_fifo_size = vmw_stdu_surface_fifo_size;
srf_update.pre_clip = vmw_stdu_surface_populate_copy;
srf_update.clip = vmw_stdu_surface_populate_clip;
} else {
srf_update.calc_fifo_size =
vmw_stdu_surface_fifo_size_same_display;
}
srf_update.post_clip = vmw_stdu_surface_populate_update;
return vmw_du_helper_plane_update(&srf_update);
}
/**
* vmw_stdu_primary_plane_atomic_update - formally switches STDU to new plane
* @plane: display plane
* @old_state: Only used to get crtc info
*
* Formally update stdu->display_srf to the new plane, and bind the new
* plane STDU. This function is called during the commit phase when
* all the preparation have been done and all the configurations have
* been checked.
*/
static void
vmw_stdu_primary_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
{
struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state);
struct drm_crtc *crtc = plane->state->crtc;
struct vmw_screen_target_display_unit *stdu;
struct drm_pending_vblank_event *event;
struct vmw_fence_obj *fence = NULL;
struct vmw_private *dev_priv;
/* If case of device error, maintain consistent atomic state */
if (crtc && plane->state->fb) {
struct vmw_framebuffer *vfb =
vmw_framebuffer_to_vfb(plane->state->fb);
stdu = vmw_crtc_to_stdu(crtc);
dev_priv = vmw_priv(crtc->dev);
stdu->display_srf = vps->surf;
stdu->content_fb_type = vps->content_fb_type;
stdu->cpp = vps->cpp;
ret = vmw_stdu_bind_st(dev_priv, stdu, &stdu->display_srf->res);
if (ret)
DRM_ERROR("Failed to bind surface to STDU.\n");
if (vfb->bo)
ret = vmw_stdu_plane_update_bo(dev_priv, plane,
old_state, vfb, &fence);
ret = vmw_stdu_plane_update_surface(dev_priv, plane,
old_state, vfb,
&fence);
if (ret)
DRM_ERROR("Failed to update STDU.\n");
} else {
crtc = old_state->crtc;
stdu = vmw_crtc_to_stdu(crtc);
dev_priv = vmw_priv(crtc->dev);
/* Blank STDU when fb and crtc are NULL */
if (!stdu->defined)
return;
ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
if (ret)
DRM_ERROR("Failed to blank STDU\n");
ret = vmw_stdu_update_st(dev_priv, stdu);
if (ret)
DRM_ERROR("Failed to update STDU.\n");
return;
}
/* In case of error, vblank event is send in vmw_du_crtc_atomic_flush */
event = crtc->state->event;
if (event && fence) {
struct drm_file *file_priv = event->base.file_priv;
ret = vmw_event_fence_action_queue(file_priv,
fence,
&event->base,
&event->event.vbl.tv_sec,
&event->event.vbl.tv_usec,
true);
if (ret)
DRM_ERROR("Failed to queue event on fence.\n");
else
crtc->state->event = NULL;
if (fence)
vmw_fence_obj_unreference(&fence);
static const struct drm_plane_funcs vmw_stdu_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = vmw_du_primary_plane_destroy,
.reset = vmw_du_plane_reset,
.atomic_duplicate_state = vmw_du_plane_duplicate_state,
.atomic_destroy_state = vmw_du_plane_destroy_state,
};
static const struct drm_plane_funcs vmw_stdu_cursor_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.destroy = vmw_du_cursor_plane_destroy,
.reset = vmw_du_plane_reset,
.atomic_duplicate_state = vmw_du_plane_duplicate_state,
.atomic_destroy_state = vmw_du_plane_destroy_state,
/*
* Atomic Helpers
*/
static const struct
drm_plane_helper_funcs vmw_stdu_cursor_plane_helper_funcs = {
.atomic_check = vmw_du_cursor_plane_atomic_check,
.atomic_update = vmw_du_cursor_plane_atomic_update,
.prepare_fb = vmw_du_cursor_plane_prepare_fb,
.cleanup_fb = vmw_du_plane_cleanup_fb,
};
static const struct
drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
.atomic_check = vmw_du_primary_plane_atomic_check,
.atomic_update = vmw_stdu_primary_plane_atomic_update,
.prepare_fb = vmw_stdu_primary_plane_prepare_fb,
.cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
};
static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
.prepare = vmw_stdu_crtc_helper_prepare,
.mode_set_nofb = vmw_stdu_crtc_mode_set_nofb,
.atomic_check = vmw_du_crtc_atomic_check,
.atomic_begin = vmw_du_crtc_atomic_begin,
.atomic_flush = vmw_du_crtc_atomic_flush,
.atomic_enable = vmw_stdu_crtc_atomic_enable,
.atomic_disable = vmw_stdu_crtc_atomic_disable,
/**
* vmw_stdu_init - Sets up a Screen Target Display Unit
*
* @dev_priv: VMW DRM device
* @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS
*
* This function is called once per CRTC, and allocates one Screen Target
* display unit to represent that CRTC. Since the SVGA device does not separate
* out encoder and connector, they are represented as part of the STDU as well.
*/
static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit)
{
struct vmw_screen_target_display_unit *stdu;
struct drm_device *dev = &dev_priv->drm;
struct drm_connector *connector;
struct drm_encoder *encoder;
struct drm_plane *primary, *cursor;
stdu = kzalloc(sizeof(*stdu), GFP_KERNEL);
if (!stdu)
return -ENOMEM;
stdu->base.unit = unit;
crtc = &stdu->base.crtc;
encoder = &stdu->base.encoder;
connector = &stdu->base.connector;
primary = &stdu->base.primary;
cursor = &stdu->base.cursor;
stdu->base.pref_active = (unit == 0);
stdu->base.pref_width = dev_priv->initial_width;
stdu->base.pref_height = dev_priv->initial_height;

Thomas Hellstrom
committed
stdu->base.is_implicit = false;
/* Initialize primary plane */
ret = drm_universal_plane_init(dev, primary,
0, &vmw_stdu_plane_funcs,
vmw_primary_plane_formats,
ARRAY_SIZE(vmw_primary_plane_formats),
NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
if (ret) {
DRM_ERROR("Failed to initialize primary plane");
goto err_free;
}
drm_plane_helper_add(primary, &vmw_stdu_primary_plane_helper_funcs);
drm_plane_enable_fb_damage_clips(primary);
/* Initialize cursor plane */
ret = drm_universal_plane_init(dev, cursor,
0, &vmw_stdu_cursor_funcs,
vmw_cursor_plane_formats,
ARRAY_SIZE(vmw_cursor_plane_formats),
NULL, DRM_PLANE_TYPE_CURSOR, NULL);
if (ret) {
DRM_ERROR("Failed to initialize cursor plane");
drm_plane_cleanup(&stdu->base.primary);
goto err_free;
}
drm_plane_helper_add(cursor, &vmw_stdu_cursor_plane_helper_funcs);
ret = drm_connector_init(dev, connector, &vmw_stdu_connector_funcs,
DRM_MODE_CONNECTOR_VIRTUAL);
if (ret) {
DRM_ERROR("Failed to initialize connector\n");
goto err_free;
}
drm_connector_helper_add(connector, &vmw_stdu_connector_helper_funcs);
connector->status = vmw_du_connector_detect(connector, false);
ret = drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs,
DRM_MODE_ENCODER_VIRTUAL, NULL);
if (ret) {
DRM_ERROR("Failed to initialize encoder\n");
goto err_free_connector;
}
(void) drm_connector_attach_encoder(connector, encoder);
encoder->possible_crtcs = (1 << unit);
encoder->possible_clones = 0;
ret = drm_connector_register(connector);
if (ret) {
DRM_ERROR("Failed to register connector\n");
goto err_free_encoder;
}
ret = drm_crtc_init_with_planes(dev, crtc, &stdu->base.primary,
&stdu->base.cursor,
&vmw_stdu_crtc_funcs, NULL);
if (ret) {
DRM_ERROR("Failed to initialize CRTC\n");
goto err_free_unregister;
}
drm_crtc_helper_add(crtc, &vmw_stdu_crtc_helper_funcs);
drm_mode_crtc_set_gamma_size(crtc, 256);
drm_object_attach_property(&connector->base,
dev_priv->hotplug_mode_update_property, 1);
drm_object_attach_property(&connector->base,
dev->mode_config.suggested_x_property, 0);
drm_object_attach_property(&connector->base,
dev->mode_config.suggested_y_property, 0);
err_free_unregister:
drm_connector_unregister(connector);
err_free_encoder:
drm_encoder_cleanup(encoder);
err_free_connector:
drm_connector_cleanup(connector);
err_free:
kfree(stdu);
return ret;
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
}
/**
* vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit
*
* @stdu: Screen Target Display Unit to be destroyed
*
* Clean up after vmw_stdu_init
*/
static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu)
{
vmw_du_cleanup(&stdu->base);
kfree(stdu);
}
/******************************************************************************
* Screen Target Display KMS Functions
*
* These functions are called by the common KMS code in vmwgfx_kms.c
*****************************************************************************/
/**
* vmw_kms_stdu_init_display - Initializes a Screen Target based display
*
* @dev_priv: VMW DRM device
*
* This function initialize a Screen Target based display device. It checks
* the capability bits to make sure the underlying hardware can support
* screen targets, and then creates the maximum number of CRTCs, a.k.a Display
* Units, as supported by the display hardware.
*
* RETURNS:
* 0 on success, error code otherwise
*/
int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
{
struct drm_device *dev = &dev_priv->drm;
int i, ret;
/* Do nothing if Screen Target support is turned off */
if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE || !dev_priv->has_mob)
if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS))
return -ENOSYS;
ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
if (unlikely(ret != 0))
return ret;
dev_priv->active_display_unit = vmw_du_screen_target;
for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) {
ret = vmw_stdu_init(dev_priv, i);
if (unlikely(ret != 0)) {
DRM_ERROR("Failed to initialize STDU %d", i);
drm_mode_config_reset(dev);
DRM_INFO("Screen Target Display device initialized\n");
return 0;
}