object.h 4.6 KB

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