nv40.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2013 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 "nv40.h"
  25. static void
  26. nv40_perfctr_init(struct nvkm_pm *pm, struct nvkm_perfdom *dom,
  27. struct nvkm_perfctr *ctr)
  28. {
  29. struct nvkm_device *device = pm->engine.subdev.device;
  30. u32 log = ctr->logic_op;
  31. u32 src = 0x00000000;
  32. int i;
  33. for (i = 0; i < 4; i++)
  34. src |= ctr->signal[i] << (i * 8);
  35. nvkm_wr32(device, 0x00a7c0 + dom->addr, 0x00000001 | (dom->mode << 4));
  36. nvkm_wr32(device, 0x00a400 + dom->addr + (ctr->slot * 0x40), src);
  37. nvkm_wr32(device, 0x00a420 + dom->addr + (ctr->slot * 0x40), log);
  38. }
  39. static void
  40. nv40_perfctr_read(struct nvkm_pm *pm, struct nvkm_perfdom *dom,
  41. struct nvkm_perfctr *ctr)
  42. {
  43. struct nvkm_device *device = pm->engine.subdev.device;
  44. switch (ctr->slot) {
  45. case 0: ctr->ctr = nvkm_rd32(device, 0x00a700 + dom->addr); break;
  46. case 1: ctr->ctr = nvkm_rd32(device, 0x00a6c0 + dom->addr); break;
  47. case 2: ctr->ctr = nvkm_rd32(device, 0x00a680 + dom->addr); break;
  48. case 3: ctr->ctr = nvkm_rd32(device, 0x00a740 + dom->addr); break;
  49. }
  50. dom->clk = nvkm_rd32(device, 0x00a600 + dom->addr);
  51. }
  52. static void
  53. nv40_perfctr_next(struct nvkm_pm *pm, struct nvkm_perfdom *dom)
  54. {
  55. struct nvkm_device *device = pm->engine.subdev.device;
  56. struct nv40_pm *nv40pm = container_of(pm, struct nv40_pm, base);
  57. if (nv40pm->sequence != pm->sequence) {
  58. nvkm_wr32(device, 0x400084, 0x00000020);
  59. nv40pm->sequence = pm->sequence;
  60. }
  61. }
  62. const struct nvkm_funcdom
  63. nv40_perfctr_func = {
  64. .init = nv40_perfctr_init,
  65. .read = nv40_perfctr_read,
  66. .next = nv40_perfctr_next,
  67. };
  68. static const struct nvkm_pm_func
  69. nv40_pm_ = {
  70. };
  71. int
  72. nv40_pm_new_(const struct nvkm_specdom *doms, struct nvkm_device *device,
  73. int index, struct nvkm_pm **ppm)
  74. {
  75. struct nv40_pm *pm;
  76. int ret;
  77. if (!(pm = kzalloc(sizeof(*pm), GFP_KERNEL)))
  78. return -ENOMEM;
  79. *ppm = &pm->base;
  80. ret = nvkm_pm_ctor(&nv40_pm_, device, index, &pm->base);
  81. if (ret)
  82. return ret;
  83. return nvkm_perfdom_new(&pm->base, "pc", 0, 0, 0, 4, doms);
  84. }
  85. static const struct nvkm_specdom
  86. nv40_pm[] = {
  87. { 0x20, (const struct nvkm_specsig[]) {
  88. {}
  89. }, &nv40_perfctr_func },
  90. { 0x20, (const struct nvkm_specsig[]) {
  91. {}
  92. }, &nv40_perfctr_func },
  93. { 0x20, (const struct nvkm_specsig[]) {
  94. {}
  95. }, &nv40_perfctr_func },
  96. { 0x20, (const struct nvkm_specsig[]) {
  97. {}
  98. }, &nv40_perfctr_func },
  99. { 0x20, (const struct nvkm_specsig[]) {
  100. {}
  101. }, &nv40_perfctr_func },
  102. {}
  103. };
  104. int
  105. nv40_pm_new(struct nvkm_device *device, int index, struct nvkm_pm **ppm)
  106. {
  107. return nv40_pm_new_(nv40_pm, device, index, ppm);
  108. }