object.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NVIF_OBJECT_H__
  3. #define __NVIF_OBJECT_H__
  4. #include <nvif/os.h>
  5. struct nvif_sclass {
  6. s32 oclass;
  7. int minver;
  8. int maxver;
  9. };
  10. struct nvif_object {
  11. struct nvif_client *client;
  12. u32 handle;
  13. s32 oclass;
  14. void *priv; /*XXX: hack */
  15. struct {
  16. void __iomem *ptr;
  17. u64 size;
  18. } map;
  19. };
  20. int nvif_object_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32,
  21. struct nvif_object *);
  22. void nvif_object_fini(struct nvif_object *);
  23. int nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
  24. int nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
  25. void nvif_object_sclass_put(struct nvif_sclass **);
  26. u32 nvif_object_rd(struct nvif_object *, int, u64);
  27. void nvif_object_wr(struct nvif_object *, int, u64, u32);
  28. int nvif_object_mthd(struct nvif_object *, u32, void *, u32);
  29. int nvif_object_map_handle(struct nvif_object *, void *, u32,
  30. u64 *handle, u64 *length);
  31. void nvif_object_unmap_handle(struct nvif_object *);
  32. int nvif_object_map(struct nvif_object *, void *, u32);
  33. void nvif_object_unmap(struct nvif_object *);
  34. #define nvif_handle(a) (unsigned long)(void *)(a)
  35. #define nvif_object(a) (a)->object
  36. #define nvif_rd(a,f,b,c) ({ \
  37. struct nvif_object *_object = (a); \
  38. u32 _data; \
  39. if (likely(_object->map.ptr)) \
  40. _data = f((u8 __iomem *)_object->map.ptr + (c)); \
  41. else \
  42. _data = nvif_object_rd(_object, (b), (c)); \
  43. _data; \
  44. })
  45. #define nvif_wr(a,f,b,c,d) ({ \
  46. struct nvif_object *_object = (a); \
  47. if (likely(_object->map.ptr)) \
  48. f((d), (u8 __iomem *)_object->map.ptr + (c)); \
  49. else \
  50. nvif_object_wr(_object, (b), (c), (d)); \
  51. })
  52. #define nvif_rd08(a,b) ({ ((u8)nvif_rd((a), ioread8, 1, (b))); })
  53. #define nvif_rd16(a,b) ({ ((u16)nvif_rd((a), ioread16_native, 2, (b))); })
  54. #define nvif_rd32(a,b) ({ ((u32)nvif_rd((a), ioread32_native, 4, (b))); })
  55. #define nvif_wr08(a,b,c) nvif_wr((a), iowrite8, 1, (b), (u8)(c))
  56. #define nvif_wr16(a,b,c) nvif_wr((a), iowrite16_native, 2, (b), (u16)(c))
  57. #define nvif_wr32(a,b,c) nvif_wr((a), iowrite32_native, 4, (b), (u32)(c))
  58. #define nvif_mask(a,b,c,d) ({ \
  59. struct nvif_object *__object = (a); \
  60. u32 _addr = (b), _data = nvif_rd32(__object, _addr); \
  61. nvif_wr32(__object, _addr, (_data & ~(c)) | (d)); \
  62. _data; \
  63. })
  64. #define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d))
  65. struct nvif_mclass {
  66. s32 oclass;
  67. int version;
  68. };
  69. #define nvif_mclass(o,m) ({ \
  70. struct nvif_object *object = (o); \
  71. struct nvif_sclass *sclass; \
  72. const typeof(m[0]) *mclass = (m); \
  73. int ret = -ENODEV; \
  74. int cnt, i, j; \
  75. \
  76. cnt = nvif_object_sclass_get(object, &sclass); \
  77. if (cnt >= 0) { \
  78. for (i = 0; ret < 0 && mclass[i].oclass; i++) { \
  79. for (j = 0; j < cnt; j++) { \
  80. if (mclass[i].oclass == sclass[j].oclass && \
  81. mclass[i].version >= sclass[j].minver && \
  82. mclass[i].version <= sclass[j].maxver) { \
  83. ret = i; \
  84. break; \
  85. } \
  86. } \
  87. } \
  88. nvif_object_sclass_put(&sclass); \
  89. } \
  90. ret; \
  91. })
  92. /*XXX*/
  93. #include <core/object.h>
  94. #define nvxx_object(a) ({ \
  95. struct nvif_object *_object = (a); \
  96. (struct nvkm_object *)_object->priv; \
  97. })
  98. #endif