32 #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1)
51 for (i = 0, k = 0; i < num_rects; i++) {
52 int x1 =
max_t(
int, clip.
x1, rects[i].
x1);
53 int y1 =
max_t(
int, clip.
y1, rects[i].
y1);
54 int x2 =
min_t(
int, clip.
x2, rects[i].
x2);
55 int y2 =
min_t(
int, clip.
y2, rects[i].
y2);
62 out_rects[
k].
left = x1;
63 out_rects[
k].
top = y1;
89 u32 hotspotX,
u32 hotspotY)
103 DRM_ERROR(
"Fifo reserve failed.\n");
126 u32 hotspotX,
u32 hotspotY)
129 unsigned long kmap_offset;
130 unsigned long kmap_num;
140 DRM_ERROR(
"reserve failed\n");
148 virtual = ttm_kmap_obj_virtual(&map, &dummy);
161 bool show,
int x,
int y)
184 if (handle && (width != 64 || height != 64))
189 handle, &surface, &dmabuf);
191 DRM_ERROR(
"failed to find surface or dmabuf: %i\n", ret);
197 if (surface && !surface->
snooper.image) {
198 DRM_ERROR(
"surface not suitable for cursor\n");
199 vmw_surface_unreference(&surface);
260 unsigned long kmap_offset;
261 unsigned long kmap_num;
278 if (
cmd->dma.host.face != 0 ||
cmd->dma.host.mipmap != 0) {
279 DRM_ERROR(
"face and mipmap for cursors should never != 0\n");
283 if (
cmd->header.size < 64) {
284 DRM_ERROR(
"at least one full copy box must be given\n");
293 box->
x != 0 || box->
y != 0 || box->
z != 0 ||
295 box->
d != 1 || box_count != 1) {
299 DRM_ERROR(
"Cant snoop dma request for cursor!\n");
300 DRM_ERROR(
"(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n",
302 box->
x, box->
y, box->
z,
303 box->
w, box->
h, box->
d, box_count,
304 cmd->dma.guest.ptr.offset);
313 DRM_ERROR(
"reserve failed\n");
317 ret =
ttm_bo_kmap(bo, kmap_offset, kmap_num, &map);
321 virtual = ttm_kmap_obj_virtual(&map, &dummy);
323 if (box->
w == 64 &&
cmd->dma.guest.pitch == 64*4) {
327 for (i = 0; i < box->
h; i++)
329 virtual + i *
cmd->dma.guest.pitch,
377 struct drm_file *file_priv,
390 #define vmw_framebuffer_to_vfbs(x) \
391 container_of(x, struct vmw_framebuffer_surface, base.base)
414 vmw_surface_unreference(&vfbs->
surface);
421 struct drm_file *file_priv,
425 unsigned num_clips,
int inc,
446 if (crtc->
fb != &framebuffer->
base)
451 BUG_ON(!clips || !num_clips);
453 tmp = kzalloc(
sizeof(*tmp) * num_clips,
GFP_KERNEL);
455 DRM_ERROR(
"Temporary cliprect memory alloc failed.\n");
462 DRM_ERROR(
"Temporary fifo memory alloc failed.\n");
477 for (i = 1, clips_ptr = clips + inc;
478 i < num_clips; i++, clips_ptr +=
inc) {
479 left =
min_t(
int, left, (
int)clips_ptr->x1);
480 right =
max_t(
int, right, (
int)clips_ptr->x2);
481 top =
min_t(
int, top, (
int)clips_ptr->y1);
482 bottom =
max_t(
int, bottom, (
int)clips_ptr->y2);
487 cmd->header.size =
cpu_to_le32(fifo_size -
sizeof(cmd->header));
489 cmd->body.srcRect.left =
left;
490 cmd->body.srcRect.right =
right;
491 cmd->body.srcRect.top =
top;
492 cmd->body.srcRect.bottom =
bottom;
495 for (i = 0; i < num_clips; i++, clips_ptr +=
inc) {
496 tmp[
i].
x1 = clips_ptr->x1 -
left;
497 tmp[
i].
x2 = clips_ptr->x2 -
left;
498 tmp[
i].
y1 = clips_ptr->y1 -
top;
499 tmp[
i].
y2 = clips_ptr->y2 -
top;
503 for (i = 0; i < num_units; i++) {
508 clip.x1 = left - unit->
crtc.x;
509 clip.y1 = top - unit->
crtc.y;
510 clip.x2 = right - unit->
crtc.x;
511 clip.y2 = bottom - unit->
crtc.y;
514 if (clip.x1 >= unit->
crtc.mode.hdisplay ||
515 clip.y1 >= unit->
crtc.mode.vdisplay ||
516 clip.x2 <= 0 || clip.y2 <= 0)
523 cmd->body.destRect.left = clip.x1;
524 cmd->body.destRect.right = clip.x2;
525 cmd->body.destRect.top = clip.y1;
526 cmd->body.destRect.bottom = clip.y2;
529 clip.x2 = unit->
crtc.mode.hdisplay - clip.x1;
530 clip.y2 = unit->
crtc.mode.vdisplay - clip.y1;
531 clip.x1 = 0 - clip.x1;
532 clip.y1 = 0 - clip.y1;
536 cmd->body.destScreenId = unit->
unit;
546 if (out_fence && *out_fence)
551 cmd->header.size =
cpu_to_le32(fifo_size -
sizeof(cmd->header));
553 fifo_size, 0,
NULL, out_fence);
568 struct drm_file *file_priv,
569 unsigned flags,
unsigned color,
594 norect.
x1 = norect.
y1 = 0;
595 norect.
x2 = framebuffer->
width;
602 ret = do_surface_dirty_sou(dev_priv, file_priv, &vfbs->
base,
604 clips, num_clips, inc,
NULL);
616 static int vmw_kms_new_framebuffer_surface(
struct vmw_private *dev_priv,
617 struct drm_file *file_priv,
646 surface->
sizes[0].depth != 1)) {
647 DRM_ERROR(
"Incompatible surface dimensions "
648 "for requested mode.\n");
652 switch (mode_cmd->
depth) {
669 DRM_ERROR(
"Invalid color depth: %d\n", mode_cmd->
depth);
674 DRM_ERROR(
"Invalid surface format for requested mode.\n");
685 &vmw_framebuffer_surface_funcs);
689 if (!vmw_surface_reference(surface)) {
690 DRM_ERROR(
"failed to reference surface %p\n", surface);
695 vfbs->
base.base.bits_per_pixel = mode_cmd->
bpp;
696 vfbs->
base.base.pitches[0] = mode_cmd->
pitch;
724 #define vmw_framebuffer_to_vfbd(x) \
725 container_of(x, struct vmw_framebuffer_dmabuf, base.base)
738 vmw_dmabuf_unreference(&vfbd->
buffer);
744 static int do_dmabuf_dirty_ldu(
struct vmw_private *dev_priv,
746 unsigned flags,
unsigned color,
748 unsigned num_clips,
int increment)
758 fifo_size =
sizeof(*cmd) * num_clips;
761 DRM_ERROR(
"Fifo reserve failed.\n");
765 memset(cmd, 0, fifo_size);
766 for (i = 0; i < num_clips; i++, clips += increment) {
771 cmd[
i].body.height =
cpu_to_le32(clips->y2 - clips->y1);
778 static int do_dmabuf_define_gmrfb(
struct drm_file *file_priv,
798 fifo_size =
sizeof(*cmd);
801 DRM_ERROR(
"Failed to allocate temporary cmd buffer.\n");
805 memset(cmd, 0, fifo_size);
807 cmd->body.format.bitsPerPixel = framebuffer->
base.bits_per_pixel;
808 cmd->body.format.colorDepth =
depth;
809 cmd->body.format.reserved = 0;
810 cmd->body.bytesPerLine = framebuffer->
base.pitches[0];
812 cmd->body.ptr.offset = 0;
822 static int do_dmabuf_dirty_sou(
struct drm_file *file_priv,
825 unsigned flags,
unsigned color,
827 unsigned num_clips,
int increment,
832 int i,
k, num_units,
ret;
841 ret = do_dmabuf_define_gmrfb(file_priv, dev_priv, framebuffer);
845 fifo_size =
sizeof(*blits) * num_clips;
848 DRM_ERROR(
"Failed to allocate temporary cmd buffer.\n");
854 if (crtc->
fb != &framebuffer->
base)
859 for (k = 0; k < num_units; k++) {
864 for (i = 0; i < num_clips; i++, clips_ptr += increment) {
865 int clip_x1 = clips_ptr->
x1 - unit->
crtc.x;
866 int clip_y1 = clips_ptr->y1 - unit->
crtc.y;
867 int clip_x2 = clips_ptr->x2 - unit->
crtc.x;
868 int clip_y2 = clips_ptr->y2 - unit->
crtc.y;
872 if (clip_x1 >= unit->
crtc.mode.hdisplay ||
873 clip_y1 >= unit->
crtc.mode.vdisplay ||
874 clip_x2 <= 0 || clip_y2 <= 0)
878 clip_x2 =
min_t(
int, clip_x2, unit->
crtc.mode.hdisplay);
879 clip_y2 =
min_t(
int, clip_y2, unit->
crtc.mode.vdisplay);
882 move_x =
min_t(
int, clip_x1, 0);
883 move_y =
min_t(
int, clip_y1, 0);
887 blits[hit_num].body.destScreenId = unit->
unit;
888 blits[hit_num].body.srcOrigin.x = clips_ptr->x1 - move_x;
889 blits[hit_num].body.srcOrigin.y = clips_ptr->y1 - move_y;
890 blits[hit_num].body.destRect.
left = clip_x1 - move_x;
891 blits[hit_num].body.destRect.
top = clip_y1 - move_y;
892 blits[hit_num].body.destRect.
right = clip_x2;
893 blits[hit_num].body.destRect.
bottom = clip_y2;
902 if (out_fence && *out_fence)
905 fifo_size =
sizeof(*blits) * hit_num;
907 fifo_size, 0,
NULL, out_fence);
919 struct drm_file *file_priv,
920 unsigned flags,
unsigned color,
929 int ret, increment = 1;
938 norect.
x1 = norect.
y1 = 0;
939 norect.
x2 = framebuffer->
width;
947 ret = do_dmabuf_dirty_ldu(dev_priv, &vfbd->
base,
949 clips, num_clips, increment);
951 ret = do_dmabuf_dirty_sou(file_priv, dev_priv, &vfbd->
base,
953 clips, num_clips, increment,
NULL);
1004 static int vmw_kms_new_framebuffer_dmabuf(
struct vmw_private *dev_priv,
1013 unsigned int requested_size;
1016 requested_size = mode_cmd->
height * mode_cmd->
pitch;
1018 DRM_ERROR(
"Screen buffer object size is too small "
1019 "for requested mode.\n");
1025 switch (mode_cmd->
depth) {
1029 if (mode_cmd->
bpp == 32)
1032 DRM_ERROR(
"Invalid color depth/bbp: %d %d\n",
1038 if (mode_cmd->
bpp == 16)
1041 DRM_ERROR(
"Invalid color depth/bbp: %d %d\n",
1045 DRM_ERROR(
"Invalid color depth: %d\n", mode_cmd->
depth);
1057 &vmw_framebuffer_dmabuf_funcs);
1061 if (!vmw_dmabuf_reference(dmabuf)) {
1062 DRM_ERROR(
"failed to reference dmabuf %p\n", dmabuf);
1066 vfbd->
base.base.bits_per_pixel = mode_cmd->
bpp;
1067 vfbd->
base.base.pitches[0] = mode_cmd->
pitch;
1068 vfbd->
base.base.depth = mode_cmd->
depth;
1069 vfbd->
base.base.width = mode_cmd->
width;
1072 vfbd->
base.pin = vmw_framebuffer_dmabuf_pin;
1073 vfbd->
base.unpin = vmw_framebuffer_dmabuf_unpin;
1075 vfbd->
base.dmabuf =
true;
1095 struct drm_file *file_priv,
1123 DRM_ERROR(
"VRAM size is too small for requested mode.\n");
1138 DRM_ERROR(
"Could not locate requested kms frame buffer.\n");
1155 ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
1158 ret = vmw_kms_new_framebuffer_surface(dev_priv, file_priv,
1159 surface, &vfb, &mode_cmd);
1166 vmw_dmabuf_unreference(&bo);
1168 vmw_surface_unreference(&surface);
1171 DRM_ERROR(
"failed to create vmw_framebuffer: %i\n", ret);
1173 return ERR_PTR(ret);
1181 .fb_create = vmw_kms_fb_create,
1185 struct drm_file *file_priv,
1197 int i,
k, num_units;
1209 if (crtc->
fb != &vfb->
base)
1215 BUG_ON(!clips || !num_clips);
1217 tmp = kzalloc(
sizeof(*tmp) * num_clips,
GFP_KERNEL);
1219 DRM_ERROR(
"Temporary cliprect memory alloc failed.\n");
1226 DRM_ERROR(
"Failed to allocate temporary fifo memory.\n");
1232 right = clips->
x + clips->
w;
1234 bottom = clips->
y + clips->
h;
1236 for (i = 1; i < num_clips; i++) {
1237 left =
min_t(
int, left, (
int)clips[i].
x);
1238 right =
max_t(
int, right, (
int)clips[i].x + clips[i].
w);
1239 top =
min_t(
int, top, (
int)clips[i].
y);
1240 bottom =
max_t(
int, bottom, (
int)clips[i].y + clips[i].
h);
1244 memset(cmd, 0, fifo_size);
1249 cmd->body.srcRect.left =
left;
1250 cmd->body.srcRect.right =
right;
1251 cmd->body.srcRect.top =
top;
1252 cmd->body.srcRect.bottom =
bottom;
1254 for (i = 0; i < num_clips; i++) {
1261 for (k = 0; k < num_units; k++) {
1266 clip.
x1 = left + destX - unit->
crtc.x;
1267 clip.
y1 = top + destY - unit->
crtc.y;
1268 clip.
x2 = right + destX - unit->
crtc.x;
1269 clip.
y2 = bottom + destY - unit->
crtc.y;
1272 if (clip.
x1 >= unit->
crtc.mode.hdisplay ||
1273 clip.
y1 >= unit->
crtc.mode.vdisplay ||
1274 clip.
x2 <= 0 || clip.
y2 <= 0)
1281 cmd->body.destRect.left = clip.
x1;
1282 cmd->body.destRect.right = clip.
x2;
1283 cmd->body.destRect.top = clip.
y1;
1284 cmd->body.destRect.bottom = clip.
y2;
1287 clip.
x2 = unit->
crtc.mode.hdisplay - clip.
x1;
1288 clip.
y2 = unit->
crtc.mode.vdisplay - clip.
y1;
1289 clip.
x1 = 0 - clip.
x1;
1290 clip.
y1 = 0 - clip.
y1;
1293 cmd->body.srcImage.sid =
sid;
1294 cmd->body.destScreenId = unit->
unit;
1305 cmd->header.size =
cpu_to_le32(fifo_size -
sizeof(cmd->header));
1321 struct drm_file *file_priv,
1333 int i,
k,
ret, num_units, blits_pos;
1346 if (crtc->
fb != &vfb->
base)
1352 BUG_ON(!clips || !num_clips);
1355 fifo_size =
sizeof(*cmd) +
sizeof(*blits) * num_clips * num_units;
1358 DRM_ERROR(
"Failed to allocate temporary fifo memory.\n");
1362 memset(cmd, 0, fifo_size);
1364 cmd->body.format.bitsPerPixel = vfb->
base.bits_per_pixel;
1365 cmd->body.format.colorDepth = vfb->
base.depth;
1366 cmd->body.format.reserved = 0;
1367 cmd->body.bytesPerLine = vfb->
base.pitches[0];
1369 cmd->body.ptr.offset = 0;
1371 blits = (
void *)&cmd[1];
1373 for (i = 0; i < num_units; i++) {
1375 for (k = 0; k < num_clips; k++, c++) {
1377 int clip_x1 = c->
x - units[
i]->
crtc.x;
1378 int clip_x2 = c->
x - units[
i]->
crtc.x + c->
w;
1379 int clip_y1 = c->
y - units[
i]->
crtc.y;
1380 int clip_y2 = c->
y - units[
i]->
crtc.y + c->
h;
1393 clip_x1 =
max(clip_x1, 0);
1394 clip_y1 =
max(clip_y1, 0);
1395 clip_x2 =
min(clip_x2, units[i]->crtc.
mode.hdisplay);
1396 clip_y2 =
min(clip_y2, units[i]->crtc.
mode.vdisplay);
1399 if (clip_x1 >= units[i]->crtc.
mode.hdisplay ||
1400 clip_y1 >= units[i]->
crtc.mode.vdisplay ||
1401 clip_x2 <= 0 || clip_y2 <= 0)
1405 blits[blits_pos].body.srcScreenId = units[
i]->
unit;
1406 blits[blits_pos].body.destOrigin.x = dest_x;
1407 blits[blits_pos].body.destOrigin.y = dest_y;
1409 blits[blits_pos].body.srcRect.
left = clip_x1;
1410 blits[blits_pos].body.srcRect.
top = clip_y1;
1411 blits[blits_pos].body.srcRect.
right = clip_x2;
1412 blits[blits_pos].body.srcRect.
bottom = clip_y2;
1417 fifo_size =
sizeof(*cmd) +
sizeof(*blits) * blits_pos;
1420 0, user_fence_rep,
NULL);
1433 dev->mode_config.funcs = &vmw_kms_funcs;
1434 dev->mode_config.min_width = 1;
1435 dev->mode_config.min_height = 1;
1437 dev->mode_config.max_width = 8192;
1438 dev->mode_config.max_height = 8192;
1463 struct drm_file *file_priv)
1505 unsigned bpp,
unsigned depth)
1516 DRM_ERROR(
"Invalid depth %u for %u bpp, host expects %u\n",
1654 DRM_INFO(
"%s: new layout ", __func__);
1655 for (i = 0; i < num; i++)
1656 DRM_INFO(
"(%i, %i %ux%u) ", rects[i].
x, rects[i].
y,
1657 rects[i].
w, rects[i].
h);
1664 if (num > du->
unit) {
1685 struct drm_pending_vblank_event *
event)
1690 struct drm_file *file_priv ;
1702 file_priv =
event->base.file_priv;
1709 clips.
x1 = clips.
y1 = 0;
1714 ret = do_dmabuf_dirty_sou(file_priv, dev_priv, vfb,
1715 0, 0, &clips, 1, 1, &fence);
1717 ret = do_surface_dirty_sou(dev_priv, file_priv, vfb,
1718 0, 0, &clips, 1, 1, &fence);
1730 &event->event.tv_sec,
1731 &event->event.tv_usec,
1766 for (i = 0; i <
size; i++) {
1767 DRM_DEBUG(
"%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i,
1807 752, 800, 0, 480, 489, 492, 525, 0,
1811 968, 1056, 0, 600, 601, 605, 628, 0,
1815 1184, 1344, 0, 768, 771, 777, 806, 0,
1819 1344, 1600, 0, 864, 865, 868, 900, 0,
1823 1472, 1664, 0, 768, 771, 778, 798, 0,
1827 1480, 1680, 0, 800, 803, 809, 831, 0,
1831 1488, 1800, 0, 960, 961, 964, 1000, 0,
1835 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
1839 1536, 1792, 0, 768, 771, 777, 795, 0,
1843 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
1847 1672, 1904, 0, 900, 903, 909, 934, 0,
1851 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
1855 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
1859 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
1863 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
1867 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
1871 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
1875 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
1878 {
DRM_MODE(
"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) },
1913 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1925 vmw_guess_mode_timing(mode);
1944 for (i = 0; vmw_kms_connector_builtin[
i].
type != 0; i++) {
1945 bmode = &vmw_kms_connector_builtin[
i];
1980 struct drm_file *file_priv)
1988 unsigned rects_size;
2011 user_rects = (
void __user *)(
unsigned long)arg->
rects;
2014 DRM_ERROR(
"Failed to get rects.\n");
2020 if (rects[i].
x < 0 ||
2022 rects[i].
x + rects[i].
w > mode_config->
max_width ||
2024 DRM_ERROR(
"Invalid GUI layout.\n");