via_map.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "drmP.h"
  25. #include "via_drm.h"
  26. #include "via_drv.h"
  27. static int via_do_init_map(drm_device_t * dev, drm_via_init_t * init)
  28. {
  29. drm_via_private_t *dev_priv;
  30. DRM_DEBUG("%s\n", __FUNCTION__);
  31. dev_priv = drm_alloc(sizeof(drm_via_private_t), DRM_MEM_DRIVER);
  32. if (dev_priv == NULL)
  33. return -ENOMEM;
  34. memset(dev_priv, 0, sizeof(drm_via_private_t));
  35. DRM_GETSAREA();
  36. if (!dev_priv->sarea) {
  37. DRM_ERROR("could not find sarea!\n");
  38. dev->dev_private = (void *)dev_priv;
  39. via_do_cleanup_map(dev);
  40. return -EINVAL;
  41. }
  42. dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
  43. if (!dev_priv->fb) {
  44. DRM_ERROR("could not find framebuffer!\n");
  45. dev->dev_private = (void *)dev_priv;
  46. via_do_cleanup_map(dev);
  47. return -EINVAL;
  48. }
  49. dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
  50. if (!dev_priv->mmio) {
  51. DRM_ERROR("could not find mmio region!\n");
  52. dev->dev_private = (void *)dev_priv;
  53. via_do_cleanup_map(dev);
  54. return -EINVAL;
  55. }
  56. dev_priv->sarea_priv =
  57. (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
  58. init->sarea_priv_offset);
  59. dev_priv->agpAddr = init->agpAddr;
  60. via_init_futex( dev_priv );
  61. dev_priv->pro_group_a = (dev->pdev->device == 0x3118);
  62. dev->dev_private = (void *)dev_priv;
  63. return 0;
  64. }
  65. int via_do_cleanup_map(drm_device_t * dev)
  66. {
  67. if (dev->dev_private) {
  68. drm_via_private_t *dev_priv = dev->dev_private;
  69. via_dma_cleanup(dev);
  70. drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
  71. dev->dev_private = NULL;
  72. }
  73. return 0;
  74. }
  75. int via_map_init(DRM_IOCTL_ARGS)
  76. {
  77. DRM_DEVICE;
  78. drm_via_init_t init;
  79. DRM_DEBUG("%s\n", __FUNCTION__);
  80. DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t __user *) data,
  81. sizeof(init));
  82. switch (init.func) {
  83. case VIA_INIT_MAP:
  84. return via_do_init_map(dev, &init);
  85. case VIA_CLEANUP_MAP:
  86. return via_do_cleanup_map(dev);
  87. }
  88. return -EINVAL;
  89. }