nvc0_vram.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2010 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 "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_mm.h"
  27. bool
  28. nvc0_vram_flags_valid(struct drm_device *dev, u32 tile_flags)
  29. {
  30. switch (tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK) {
  31. case 0x0000:
  32. case 0xfe00:
  33. case 0xdb00:
  34. case 0x1100:
  35. return true;
  36. default:
  37. break;
  38. }
  39. return false;
  40. }
  41. int
  42. nvc0_vram_new(struct drm_device *dev, u64 size, u32 align, u32 ncmin,
  43. u32 type, struct nouveau_vram **pvram)
  44. {
  45. struct drm_nouveau_private *dev_priv = dev->dev_private;
  46. struct ttm_bo_device *bdev = &dev_priv->ttm.bdev;
  47. struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_VRAM];
  48. struct nouveau_mm *mm = man->priv;
  49. struct nouveau_mm_node *r;
  50. struct nouveau_vram *vram;
  51. int ret;
  52. size >>= 12;
  53. align >>= 12;
  54. ncmin >>= 12;
  55. vram = kzalloc(sizeof(*vram), GFP_KERNEL);
  56. if (!vram)
  57. return -ENOMEM;
  58. INIT_LIST_HEAD(&vram->regions);
  59. vram->dev = dev_priv->dev;
  60. vram->memtype = type;
  61. vram->size = size;
  62. mutex_lock(&mm->mutex);
  63. do {
  64. ret = nouveau_mm_get(mm, 1, size, ncmin, align, &r);
  65. if (ret) {
  66. mutex_unlock(&mm->mutex);
  67. nv50_vram_del(dev, &vram);
  68. return ret;
  69. }
  70. list_add_tail(&r->rl_entry, &vram->regions);
  71. size -= r->length;
  72. } while (size);
  73. mutex_unlock(&mm->mutex);
  74. r = list_first_entry(&vram->regions, struct nouveau_mm_node, rl_entry);
  75. vram->offset = (u64)r->offset << 12;
  76. *pvram = vram;
  77. return 0;
  78. }
  79. int
  80. nvc0_vram_init(struct drm_device *dev)
  81. {
  82. struct drm_nouveau_private *dev_priv = dev->dev_private;
  83. dev_priv->vram_size = nv_rd32(dev, 0x10f20c) << 20;
  84. dev_priv->vram_size *= nv_rd32(dev, 0x121c74);
  85. dev_priv->vram_rblock_size = 4096;
  86. return 0;
  87. }