via_map.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial portions
  14. * of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <drm/drmP.h>
  25. #include <drm/via_drm.h>
  26. #include "via_drv.h"
  27. static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init)
  28. {
  29. drm_via_private_t *dev_priv = dev->dev_private;
  30. DRM_DEBUG("\n");
  31. dev_priv->sarea = drm_legacy_getsarea(dev);
  32. if (!dev_priv->sarea) {
  33. DRM_ERROR("could not find sarea!\n");
  34. dev->dev_private = (void *)dev_priv;
  35. via_do_cleanup_map(dev);
  36. return -EINVAL;
  37. }
  38. dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset);
  39. if (!dev_priv->fb) {
  40. DRM_ERROR("could not find framebuffer!\n");
  41. dev->dev_private = (void *)dev_priv;
  42. via_do_cleanup_map(dev);
  43. return -EINVAL;
  44. }
  45. dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset);
  46. if (!dev_priv->mmio) {
  47. DRM_ERROR("could not find mmio region!\n");
  48. dev->dev_private = (void *)dev_priv;
  49. via_do_cleanup_map(dev);
  50. return -EINVAL;
  51. }
  52. dev_priv->sarea_priv =
  53. (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
  54. init->sarea_priv_offset);
  55. dev_priv->agpAddr = init->agpAddr;
  56. via_init_futex(dev_priv);
  57. via_init_dmablit(dev);
  58. dev->dev_private = (void *)dev_priv;
  59. return 0;
  60. }
  61. int via_do_cleanup_map(struct drm_device *dev)
  62. {
  63. via_dma_cleanup(dev);
  64. return 0;
  65. }
  66. int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
  67. {
  68. drm_via_init_t *init = data;
  69. DRM_DEBUG("\n");
  70. switch (init->func) {
  71. case VIA_INIT_MAP:
  72. return via_do_init_map(dev, init);
  73. case VIA_CLEANUP_MAP:
  74. return via_do_cleanup_map(dev);
  75. }
  76. return -EINVAL;
  77. }
  78. int via_driver_load(struct drm_device *dev, unsigned long chipset)
  79. {
  80. drm_via_private_t *dev_priv;
  81. int ret = 0;
  82. dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL);
  83. if (dev_priv == NULL)
  84. return -ENOMEM;
  85. idr_init(&dev_priv->object_idr);
  86. dev->dev_private = (void *)dev_priv;
  87. dev_priv->chipset = chipset;
  88. pci_set_master(dev->pdev);
  89. ret = drm_vblank_init(dev, 1);
  90. if (ret) {
  91. kfree(dev_priv);
  92. return ret;
  93. }
  94. return 0;
  95. }
  96. int via_driver_unload(struct drm_device *dev)
  97. {
  98. drm_via_private_t *dev_priv = dev->dev_private;
  99. idr_destroy(&dev_priv->object_idr);
  100. kfree(dev_priv);
  101. return 0;
  102. }