object.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef __NVIF_OBJECT_H__
  2. #define __NVIF_OBJECT_H__
  3. #include <nvif/os.h>
  4. struct nvif_object {
  5. struct nvif_object *parent;
  6. struct nvif_object *object; /*XXX: hack for nvif_object() */
  7. struct kref refcount;
  8. u32 handle;
  9. u32 oclass;
  10. void *data;
  11. u32 size;
  12. void *priv; /*XXX: hack */
  13. void (*dtor)(struct nvif_object *);
  14. struct {
  15. void __iomem *ptr;
  16. u32 size;
  17. } map;
  18. };
  19. int nvif_object_init(struct nvif_object *, void (*dtor)(struct nvif_object *),
  20. u32 handle, u32 oclass, void *, u32,
  21. struct nvif_object *);
  22. void nvif_object_fini(struct nvif_object *);
  23. int nvif_object_new(struct nvif_object *, u32 handle, u32 oclass,
  24. void *, u32, struct nvif_object **);
  25. void nvif_object_ref(struct nvif_object *, struct nvif_object **);
  26. int nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
  27. int nvif_object_sclass(struct nvif_object *, u32 *, int);
  28. u32 nvif_object_rd(struct nvif_object *, int, u64);
  29. void nvif_object_wr(struct nvif_object *, int, u64, u32);
  30. int nvif_object_mthd(struct nvif_object *, u32, void *, u32);
  31. int nvif_object_map(struct nvif_object *);
  32. void nvif_object_unmap(struct nvif_object *);
  33. #define nvif_object(a) (a)->object
  34. #define ioread8_native ioread8
  35. #define iowrite8_native iowrite8
  36. #define nvif_rd(a,b,c) ({ \
  37. struct nvif_object *_object = nvif_object(a); \
  38. u32 _data; \
  39. if (likely(_object->map.ptr)) \
  40. _data = ioread##b##_native((u8 __iomem *)_object->map.ptr + (c)); \
  41. else \
  42. _data = nvif_object_rd(_object, (b) / 8, (c)); \
  43. _data; \
  44. })
  45. #define nvif_wr(a,b,c,d) ({ \
  46. struct nvif_object *_object = nvif_object(a); \
  47. if (likely(_object->map.ptr)) \
  48. iowrite##b##_native((d), (u8 __iomem *)_object->map.ptr + (c)); \
  49. else \
  50. nvif_object_wr(_object, (b) / 8, (c), (d)); \
  51. })
  52. #define nvif_rd08(a,b) ({ u8 _v = nvif_rd((a), 8, (b)); _v; })
  53. #define nvif_rd16(a,b) ({ u16 _v = nvif_rd((a), 16, (b)); _v; })
  54. #define nvif_rd32(a,b) ({ u32 _v = nvif_rd((a), 32, (b)); _v; })
  55. #define nvif_wr08(a,b,c) nvif_wr((a), 8, (b), (u8)(c))
  56. #define nvif_wr16(a,b,c) nvif_wr((a), 16, (b), (u16)(c))
  57. #define nvif_wr32(a,b,c) nvif_wr((a), 32, (b), (u32)(c))
  58. #define nvif_mask(a,b,c,d) ({ \
  59. u32 _v = nvif_rd32(nvif_object(a), (b)); \
  60. nvif_wr32(nvif_object(a), (b), (_v & ~(c)) | (d)); \
  61. _v; \
  62. })
  63. #define nvif_mthd(a,b,c,d) nvif_object_mthd(nvif_object(a), (b), (c), (d))
  64. /*XXX*/
  65. #include <core/object.h>
  66. #define nvkm_object(a) ((struct nouveau_object *)nvif_object(a)->priv)
  67. #endif