vmwgfx_ioctl.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "vmwgfx_drv.h"
  28. #include "vmwgfx_drm.h"
  29. int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  30. struct drm_file *file_priv)
  31. {
  32. struct vmw_private *dev_priv = vmw_priv(dev);
  33. struct drm_vmw_getparam_arg *param =
  34. (struct drm_vmw_getparam_arg *)data;
  35. switch (param->param) {
  36. case DRM_VMW_PARAM_NUM_STREAMS:
  37. param->value = vmw_overlay_num_overlays(dev_priv);
  38. break;
  39. case DRM_VMW_PARAM_NUM_FREE_STREAMS:
  40. param->value = vmw_overlay_num_free_overlays(dev_priv);
  41. break;
  42. case DRM_VMW_PARAM_3D:
  43. param->value = vmw_fifo_have_3d(dev_priv) ? 1 : 0;
  44. break;
  45. case DRM_VMW_PARAM_HW_CAPS:
  46. param->value = dev_priv->capabilities;
  47. break;
  48. case DRM_VMW_PARAM_FIFO_CAPS:
  49. param->value = dev_priv->fifo.capabilities;
  50. break;
  51. case DRM_VMW_PARAM_MAX_FB_SIZE:
  52. param->value = dev_priv->vram_size;
  53. break;
  54. case DRM_VMW_PARAM_FIFO_HW_VERSION:
  55. {
  56. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  57. param->value = ioread32(fifo_mem + SVGA_FIFO_3D_HWVERSION);
  58. break;
  59. }
  60. default:
  61. DRM_ERROR("Illegal vmwgfx get param request: %d\n",
  62. param->param);
  63. return -EINVAL;
  64. }
  65. return 0;
  66. }
  67. int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  68. struct drm_file *file_priv)
  69. {
  70. struct drm_vmw_get_3d_cap_arg *arg =
  71. (struct drm_vmw_get_3d_cap_arg *) data;
  72. struct vmw_private *dev_priv = vmw_priv(dev);
  73. uint32_t size;
  74. __le32 __iomem *fifo_mem;
  75. void __user *buffer = (void __user *)((unsigned long)(arg->buffer));
  76. void *bounce;
  77. int ret;
  78. if (unlikely(arg->pad64 != 0)) {
  79. DRM_ERROR("Illegal GET_3D_CAP argument.\n");
  80. return -EINVAL;
  81. }
  82. size = (SVGA_FIFO_3D_CAPS_LAST - SVGA_FIFO_3D_CAPS + 1) << 2;
  83. if (arg->max_size < size)
  84. size = arg->max_size;
  85. bounce = vmalloc(size);
  86. if (unlikely(bounce == NULL)) {
  87. DRM_ERROR("Failed to allocate bounce buffer for 3D caps.\n");
  88. return -ENOMEM;
  89. }
  90. fifo_mem = dev_priv->mmio_virt;
  91. memcpy_fromio(bounce, &fifo_mem[SVGA_FIFO_3D_CAPS], size);
  92. ret = copy_to_user(buffer, bounce, size);
  93. vfree(bounce);
  94. if (unlikely(ret != 0))
  95. DRM_ERROR("Failed to report 3D caps info.\n");
  96. return ret;
  97. }