nv30_fb.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2010 Francisco Jerez.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_drm.h"
  30. void
  31. nv30_fb_init_tile_region(struct drm_device *dev, int i, uint32_t addr,
  32. uint32_t size, uint32_t pitch, uint32_t flags)
  33. {
  34. struct drm_nouveau_private *dev_priv = dev->dev_private;
  35. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  36. tile->addr = addr | 1;
  37. tile->limit = max(1u, addr + size) - 1;
  38. tile->pitch = pitch;
  39. }
  40. void
  41. nv30_fb_free_tile_region(struct drm_device *dev, int i)
  42. {
  43. struct drm_nouveau_private *dev_priv = dev->dev_private;
  44. struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i];
  45. tile->addr = tile->limit = tile->pitch = 0;
  46. }
  47. static int
  48. calc_bias(struct drm_device *dev, int k, int i, int j)
  49. {
  50. struct drm_nouveau_private *dev_priv = dev->dev_private;
  51. int b = (dev_priv->chipset > 0x30 ?
  52. nv_rd32(dev, 0x122c + 0x10 * k + 0x4 * j) >> (4 * (i ^ 1)) :
  53. 0) & 0xf;
  54. return 2 * (b & 0x8 ? b - 0x10 : b);
  55. }
  56. static int
  57. calc_ref(struct drm_device *dev, int l, int k, int i)
  58. {
  59. int j, x = 0;
  60. for (j = 0; j < 4; j++) {
  61. int m = (l >> (8 * i) & 0xff) + calc_bias(dev, k, i, j);
  62. x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j);
  63. }
  64. return x;
  65. }
  66. int
  67. nv30_fb_init(struct drm_device *dev)
  68. {
  69. struct drm_nouveau_private *dev_priv = dev->dev_private;
  70. struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
  71. int i, j;
  72. pfb->num_tiles = NV10_PFB_TILE__SIZE;
  73. /* Turn all the tiling regions off. */
  74. for (i = 0; i < pfb->num_tiles; i++)
  75. pfb->set_tile_region(dev, i);
  76. /* Init the memory timing regs at 0x10037c/0x1003ac */
  77. if (dev_priv->chipset == 0x30 ||
  78. dev_priv->chipset == 0x31 ||
  79. dev_priv->chipset == 0x35) {
  80. /* Related to ROP count */
  81. int n = (dev_priv->chipset == 0x31 ? 2 : 4);
  82. int l = nv_rd32(dev, 0x1003d0);
  83. for (i = 0; i < n; i++) {
  84. for (j = 0; j < 3; j++)
  85. nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j,
  86. calc_ref(dev, l, 0, j));
  87. for (j = 0; j < 2; j++)
  88. nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j,
  89. calc_ref(dev, l, 1, j));
  90. }
  91. }
  92. return 0;
  93. }
  94. void
  95. nv30_fb_takedown(struct drm_device *dev)
  96. {
  97. }