nvc0_vram.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (likely(!(tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)))
  31. return true;
  32. return false;
  33. }
  34. int
  35. nvc0_vram_new(struct drm_device *dev, u64 size, u32 align, u32 ncmin,
  36. u32 type, struct nouveau_vram **pvram)
  37. {
  38. struct drm_nouveau_private *dev_priv = dev->dev_private;
  39. struct ttm_bo_device *bdev = &dev_priv->ttm.bdev;
  40. struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_VRAM];
  41. struct nouveau_mm *mm = man->priv;
  42. struct nouveau_mm_node *r;
  43. struct nouveau_vram *vram;
  44. int ret;
  45. size >>= 12;
  46. align >>= 12;
  47. ncmin >>= 12;
  48. vram = kzalloc(sizeof(*vram), GFP_KERNEL);
  49. if (!vram)
  50. return -ENOMEM;
  51. INIT_LIST_HEAD(&vram->regions);
  52. vram->dev = dev_priv->dev;
  53. vram->memtype = type;
  54. vram->size = size;
  55. mutex_lock(&mm->mutex);
  56. do {
  57. ret = nouveau_mm_get(mm, 1, size, ncmin, align, &r);
  58. if (ret) {
  59. mutex_unlock(&mm->mutex);
  60. nv50_vram_del(dev, &vram);
  61. return ret;
  62. }
  63. list_add_tail(&r->rl_entry, &vram->regions);
  64. size -= r->length;
  65. } while (size);
  66. mutex_unlock(&mm->mutex);
  67. r = list_first_entry(&vram->regions, struct nouveau_mm_node, rl_entry);
  68. vram->offset = (u64)r->offset << 12;
  69. *pvram = vram;
  70. return 0;
  71. }
  72. int
  73. nvc0_vram_init(struct drm_device *dev)
  74. {
  75. struct drm_nouveau_private *dev_priv = dev->dev_private;
  76. dev_priv->vram_size = nv_rd32(dev, 0x10f20c) << 20;
  77. dev_priv->vram_size *= nv_rd32(dev, 0x121c74);
  78. dev_priv->vram_rblock_size = 4096;
  79. return 0;
  80. }