nouveau_display.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "drm_crtc_helper.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_fb.h"
  30. #include "nouveau_fbcon.h"
  31. #include "nouveau_hw.h"
  32. static void
  33. nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
  34. {
  35. struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
  36. if (fb->nvbo)
  37. drm_gem_object_unreference_unlocked(fb->nvbo->gem);
  38. drm_framebuffer_cleanup(drm_fb);
  39. kfree(fb);
  40. }
  41. static int
  42. nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
  43. struct drm_file *file_priv,
  44. unsigned int *handle)
  45. {
  46. struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
  47. return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle);
  48. }
  49. static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
  50. .destroy = nouveau_user_framebuffer_destroy,
  51. .create_handle = nouveau_user_framebuffer_create_handle,
  52. };
  53. int
  54. nouveau_framebuffer_init(struct drm_device *dev, struct nouveau_framebuffer *nouveau_fb,
  55. struct drm_mode_fb_cmd *mode_cmd, struct nouveau_bo *nvbo)
  56. {
  57. int ret;
  58. ret = drm_framebuffer_init(dev, &nouveau_fb->base, &nouveau_framebuffer_funcs);
  59. if (ret) {
  60. return ret;
  61. }
  62. drm_helper_mode_fill_fb_struct(&nouveau_fb->base, mode_cmd);
  63. nouveau_fb->nvbo = nvbo;
  64. return 0;
  65. }
  66. static struct drm_framebuffer *
  67. nouveau_user_framebuffer_create(struct drm_device *dev,
  68. struct drm_file *file_priv,
  69. struct drm_mode_fb_cmd *mode_cmd)
  70. {
  71. struct nouveau_framebuffer *nouveau_fb;
  72. struct drm_gem_object *gem;
  73. int ret;
  74. gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  75. if (!gem)
  76. return ERR_PTR(-ENOENT);
  77. nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
  78. if (!nouveau_fb)
  79. return ERR_PTR(-ENOMEM);
  80. ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
  81. if (ret) {
  82. drm_gem_object_unreference(gem);
  83. return ERR_PTR(ret);
  84. }
  85. return &nouveau_fb->base;
  86. }
  87. const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
  88. .fb_create = nouveau_user_framebuffer_create,
  89. .output_poll_changed = nouveau_fbcon_output_poll_changed,
  90. };
  91. int
  92. nouveau_vblank_enable(struct drm_device *dev, int crtc)
  93. {
  94. struct drm_nouveau_private *dev_priv = dev->dev_private;
  95. if (dev_priv->card_type >= NV_50)
  96. nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0,
  97. NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc));
  98. else
  99. NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0,
  100. NV_PCRTC_INTR_0_VBLANK);
  101. return 0;
  102. }
  103. void
  104. nouveau_vblank_disable(struct drm_device *dev, int crtc)
  105. {
  106. struct drm_nouveau_private *dev_priv = dev->dev_private;
  107. if (dev_priv->card_type >= NV_50)
  108. nv_mask(dev, NV50_PDISPLAY_INTR_EN_1,
  109. NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0);
  110. else
  111. NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0);
  112. }