ast_mm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sub license, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  15. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  16. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. *
  20. * The above copyright notice and this permission notice (including the
  21. * next paragraph) shall be included in all copies or substantial portions
  22. * of the Software.
  23. *
  24. */
  25. /*
  26. * Authors: Dave Airlie <airlied@redhat.com>
  27. */
  28. #include <linux/pci.h>
  29. #include <drm/drm_managed.h>
  30. #include <drm/drm_print.h>
  31. #include "ast_drv.h"
  32. static u32 ast_get_vram_size(struct ast_device *ast)
  33. {
  34. u8 jreg;
  35. u32 vram_size;
  36. vram_size = AST_VIDMEM_DEFAULT_SIZE;
  37. jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xaa, 0xff);
  38. switch (jreg & 3) {
  39. case 0:
  40. vram_size = AST_VIDMEM_SIZE_8M;
  41. break;
  42. case 1:
  43. vram_size = AST_VIDMEM_SIZE_16M;
  44. break;
  45. case 2:
  46. vram_size = AST_VIDMEM_SIZE_32M;
  47. break;
  48. case 3:
  49. vram_size = AST_VIDMEM_SIZE_64M;
  50. break;
  51. }
  52. jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0x99, 0xff);
  53. switch (jreg & 0x03) {
  54. case 1:
  55. vram_size -= 0x100000;
  56. break;
  57. case 2:
  58. vram_size -= 0x200000;
  59. break;
  60. case 3:
  61. vram_size -= 0x400000;
  62. break;
  63. }
  64. return vram_size;
  65. }
  66. int ast_mm_init(struct ast_device *ast)
  67. {
  68. struct drm_device *dev = &ast->base;
  69. struct pci_dev *pdev = to_pci_dev(dev->dev);
  70. resource_size_t base, size;
  71. u32 vram_size;
  72. base = pci_resource_start(pdev, 0);
  73. size = pci_resource_len(pdev, 0);
  74. /* Don't fail on errors, but performance might be reduced. */
  75. devm_arch_io_reserve_memtype_wc(dev->dev, base, size);
  76. devm_arch_phys_wc_add(dev->dev, base, size);
  77. vram_size = ast_get_vram_size(ast);
  78. ast->vram = devm_ioremap_wc(dev->dev, base, vram_size);
  79. if (!ast->vram)
  80. return -ENOMEM;
  81. ast->vram_base = base;
  82. ast->vram_size = vram_size;
  83. ast->vram_fb_available = vram_size;
  84. return 0;
  85. }