nouveau_display.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. static void
  32. nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
  33. {
  34. struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
  35. struct drm_device *dev = drm_fb->dev;
  36. if (drm_fb->fbdev)
  37. nouveau_fbcon_remove(dev, drm_fb);
  38. if (fb->nvbo) {
  39. mutex_lock(&dev->struct_mutex);
  40. drm_gem_object_unreference(fb->nvbo->gem);
  41. mutex_unlock(&dev->struct_mutex);
  42. }
  43. drm_framebuffer_cleanup(drm_fb);
  44. kfree(fb);
  45. }
  46. static int
  47. nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
  48. struct drm_file *file_priv,
  49. unsigned int *handle)
  50. {
  51. struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
  52. return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle);
  53. }
  54. static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
  55. .destroy = nouveau_user_framebuffer_destroy,
  56. .create_handle = nouveau_user_framebuffer_create_handle,
  57. };
  58. struct drm_framebuffer *
  59. nouveau_framebuffer_create(struct drm_device *dev, struct nouveau_bo *nvbo,
  60. struct drm_mode_fb_cmd *mode_cmd)
  61. {
  62. struct nouveau_framebuffer *fb;
  63. int ret;
  64. fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
  65. if (!fb)
  66. return NULL;
  67. ret = drm_framebuffer_init(dev, &fb->base, &nouveau_framebuffer_funcs);
  68. if (ret) {
  69. kfree(fb);
  70. return NULL;
  71. }
  72. drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
  73. fb->nvbo = nvbo;
  74. return &fb->base;
  75. }
  76. static struct drm_framebuffer *
  77. nouveau_user_framebuffer_create(struct drm_device *dev,
  78. struct drm_file *file_priv,
  79. struct drm_mode_fb_cmd *mode_cmd)
  80. {
  81. struct drm_framebuffer *fb;
  82. struct drm_gem_object *gem;
  83. gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  84. if (!gem)
  85. return NULL;
  86. fb = nouveau_framebuffer_create(dev, nouveau_gem_object(gem), mode_cmd);
  87. if (!fb) {
  88. drm_gem_object_unreference(gem);
  89. return NULL;
  90. }
  91. return fb;
  92. }
  93. const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
  94. .fb_create = nouveau_user_framebuffer_create,
  95. .fb_changed = nouveau_fbcon_probe,
  96. };