nouveau_display.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. if (fb->nvbo)
  36. drm_gem_object_unreference_unlocked(fb->nvbo->gem);
  37. drm_framebuffer_cleanup(drm_fb);
  38. kfree(fb);
  39. }
  40. static int
  41. nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
  42. struct drm_file *file_priv,
  43. unsigned int *handle)
  44. {
  45. struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
  46. return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle);
  47. }
  48. static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
  49. .destroy = nouveau_user_framebuffer_destroy,
  50. .create_handle = nouveau_user_framebuffer_create_handle,
  51. };
  52. int
  53. nouveau_framebuffer_init(struct drm_device *dev, struct nouveau_framebuffer *nouveau_fb,
  54. struct drm_mode_fb_cmd *mode_cmd, struct nouveau_bo *nvbo)
  55. {
  56. int ret;
  57. ret = drm_framebuffer_init(dev, &nouveau_fb->base, &nouveau_framebuffer_funcs);
  58. if (ret) {
  59. return ret;
  60. }
  61. drm_helper_mode_fill_fb_struct(&nouveau_fb->base, mode_cmd);
  62. nouveau_fb->nvbo = nvbo;
  63. return 0;
  64. }
  65. static struct drm_framebuffer *
  66. nouveau_user_framebuffer_create(struct drm_device *dev,
  67. struct drm_file *file_priv,
  68. struct drm_mode_fb_cmd *mode_cmd)
  69. {
  70. struct nouveau_framebuffer *nouveau_fb;
  71. struct drm_gem_object *gem;
  72. int ret;
  73. gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  74. if (!gem)
  75. return ERR_PTR(-ENOENT);
  76. nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
  77. if (!nouveau_fb)
  78. return ERR_PTR(-ENOMEM);
  79. ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
  80. if (ret) {
  81. drm_gem_object_unreference(gem);
  82. return ERR_PTR(ret);
  83. }
  84. return &nouveau_fb->base;
  85. }
  86. const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
  87. .fb_create = nouveau_user_framebuffer_create,
  88. .output_poll_changed = nouveau_fbcon_output_poll_changed,
  89. };