gp100.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "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. #define gp100_mc(p) container_of((p), struct gp100_mc, base)
  25. #include "priv.h"
  26. struct gp100_mc {
  27. struct nvkm_mc base;
  28. spinlock_t lock;
  29. bool intr;
  30. u32 mask;
  31. };
  32. static void
  33. gp100_mc_intr_update(struct gp100_mc *mc)
  34. {
  35. struct nvkm_device *device = mc->base.subdev.device;
  36. u32 mask = mc->intr ? mc->mask : 0, i;
  37. for (i = 0; i < 2; i++) {
  38. nvkm_wr32(device, 0x000180 + (i * 0x04), ~mask);
  39. nvkm_wr32(device, 0x000160 + (i * 0x04), mask);
  40. }
  41. }
  42. static void
  43. gp100_mc_intr_unarm(struct nvkm_mc *base)
  44. {
  45. struct gp100_mc *mc = gp100_mc(base);
  46. unsigned long flags;
  47. spin_lock_irqsave(&mc->lock, flags);
  48. mc->intr = false;
  49. gp100_mc_intr_update(mc);
  50. spin_unlock_irqrestore(&mc->lock, flags);
  51. }
  52. static void
  53. gp100_mc_intr_rearm(struct nvkm_mc *base)
  54. {
  55. struct gp100_mc *mc = gp100_mc(base);
  56. unsigned long flags;
  57. spin_lock_irqsave(&mc->lock, flags);
  58. mc->intr = true;
  59. gp100_mc_intr_update(mc);
  60. spin_unlock_irqrestore(&mc->lock, flags);
  61. }
  62. static void
  63. gp100_mc_intr_mask(struct nvkm_mc *base, u32 mask, u32 intr)
  64. {
  65. struct gp100_mc *mc = gp100_mc(base);
  66. unsigned long flags;
  67. spin_lock_irqsave(&mc->lock, flags);
  68. mc->mask = (mc->mask & ~mask) | intr;
  69. gp100_mc_intr_update(mc);
  70. spin_unlock_irqrestore(&mc->lock, flags);
  71. }
  72. static const struct nvkm_mc_func
  73. gp100_mc = {
  74. .init = nv50_mc_init,
  75. .intr = gk104_mc_intr,
  76. .intr_unarm = gp100_mc_intr_unarm,
  77. .intr_rearm = gp100_mc_intr_rearm,
  78. .intr_mask = gp100_mc_intr_mask,
  79. .intr_stat = gf100_mc_intr_stat,
  80. .reset = gk104_mc_reset,
  81. };
  82. int
  83. gp100_mc_new(struct nvkm_device *device, int index, struct nvkm_mc **pmc)
  84. {
  85. struct gp100_mc *mc;
  86. if (!(mc = kzalloc(sizeof(*mc), GFP_KERNEL)))
  87. return -ENOMEM;
  88. nvkm_mc_ctor(&gp100_mc, device, index, &mc->base);
  89. *pmc = &mc->base;
  90. spin_lock_init(&mc->lock);
  91. mc->intr = false;
  92. mc->mask = 0x7fffffff;
  93. return 0;
  94. }