blob: 0b54261bdefe5609949c793f9bfe4eb7944061c2 [file] [log] [blame]
Ben Skeggsa04d0422014-08-10 04:10:21 +10001#ifndef __NVIF_OBJECT_H__
2#define __NVIF_OBJECT_H__
3
4#include <nvif/os.h>
5
Ben Skeggs41a63402015-08-20 14:54:16 +10006struct nvif_sclass {
7 s32 oclass;
8 int minver;
9 int maxver;
10};
11
Ben Skeggsa04d0422014-08-10 04:10:21 +100012struct nvif_object {
Ben Skeggsa01ca782015-08-20 14:54:15 +100013 struct nvif_client *client;
Ben Skeggsa04d0422014-08-10 04:10:21 +100014 u32 handle;
Ben Skeggs315a8b22015-08-20 14:54:16 +100015 s32 oclass;
Ben Skeggsa04d0422014-08-10 04:10:21 +100016 void *priv; /*XXX: hack */
Ben Skeggsa04d0422014-08-10 04:10:21 +100017 struct {
Al Viro3cfb2fa2014-08-31 15:06:09 -040018 void __iomem *ptr;
Ben Skeggs01326052017-11-01 03:56:19 +100019 u64 size;
Ben Skeggsa04d0422014-08-10 04:10:21 +100020 } map;
21};
22
Ben Skeggs315a8b22015-08-20 14:54:16 +100023int nvif_object_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32,
Ben Skeggsa04d0422014-08-10 04:10:21 +100024 struct nvif_object *);
25void nvif_object_fini(struct nvif_object *);
Ben Skeggsa04d0422014-08-10 04:10:21 +100026int nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
Ben Skeggs41a63402015-08-20 14:54:16 +100027int nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
28void nvif_object_sclass_put(struct nvif_sclass **);
Ben Skeggsa04d0422014-08-10 04:10:21 +100029u32 nvif_object_rd(struct nvif_object *, int, u64);
30void nvif_object_wr(struct nvif_object *, int, u64, u32);
31int nvif_object_mthd(struct nvif_object *, u32, void *, u32);
Ben Skeggs01326052017-11-01 03:56:19 +100032int nvif_object_map_handle(struct nvif_object *, void *, u32,
33 u64 *handle, u64 *length);
34void nvif_object_unmap_handle(struct nvif_object *);
35int nvif_object_map(struct nvif_object *, void *, u32);
Ben Skeggsa04d0422014-08-10 04:10:21 +100036void nvif_object_unmap(struct nvif_object *);
37
Ben Skeggsbf81df92015-08-20 14:54:16 +100038#define nvif_handle(a) (unsigned long)(void *)(a)
Ben Skeggsa04d0422014-08-10 04:10:21 +100039#define nvif_object(a) (a)->object
40
Ben Skeggsa01ca782015-08-20 14:54:15 +100041#define nvif_rd(a,f,b,c) ({ \
42 struct nvif_object *_object = (a); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100043 u32 _data; \
44 if (likely(_object->map.ptr)) \
Ben Skeggsa01ca782015-08-20 14:54:15 +100045 _data = f((u8 __iomem *)_object->map.ptr + (c)); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100046 else \
Ben Skeggsa01ca782015-08-20 14:54:15 +100047 _data = nvif_object_rd(_object, (b), (c)); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100048 _data; \
49})
Ben Skeggsa01ca782015-08-20 14:54:15 +100050#define nvif_wr(a,f,b,c,d) ({ \
51 struct nvif_object *_object = (a); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100052 if (likely(_object->map.ptr)) \
Ben Skeggsa01ca782015-08-20 14:54:15 +100053 f((d), (u8 __iomem *)_object->map.ptr + (c)); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100054 else \
Ben Skeggsa01ca782015-08-20 14:54:15 +100055 nvif_object_wr(_object, (b), (c), (d)); \
Ben Skeggsa04d0422014-08-10 04:10:21 +100056})
Ben Skeggsa01ca782015-08-20 14:54:15 +100057#define nvif_rd08(a,b) ({ ((u8)nvif_rd((a), ioread8, 1, (b))); })
58#define nvif_rd16(a,b) ({ ((u16)nvif_rd((a), ioread16_native, 2, (b))); })
59#define nvif_rd32(a,b) ({ ((u32)nvif_rd((a), ioread32_native, 4, (b))); })
60#define nvif_wr08(a,b,c) nvif_wr((a), iowrite8, 1, (b), (u8)(c))
61#define nvif_wr16(a,b,c) nvif_wr((a), iowrite16_native, 2, (b), (u16)(c))
62#define nvif_wr32(a,b,c) nvif_wr((a), iowrite32_native, 4, (b), (u32)(c))
Ben Skeggsa04d0422014-08-10 04:10:21 +100063#define nvif_mask(a,b,c,d) ({ \
Ben Skeggsa01ca782015-08-20 14:54:15 +100064 struct nvif_object *__object = (a); \
65 u32 _addr = (b), _data = nvif_rd32(__object, _addr); \
66 nvif_wr32(__object, _addr, (_data & ~(c)) | (d)); \
67 _data; \
Ben Skeggsa04d0422014-08-10 04:10:21 +100068})
69
Ben Skeggsa01ca782015-08-20 14:54:15 +100070#define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d))
Ben Skeggsa04d0422014-08-10 04:10:21 +100071
Ben Skeggsa3f8a412016-11-04 17:20:35 +100072struct nvif_mclass {
73 s32 oclass;
74 int version;
75};
76
77#define nvif_mclass(o,m) ({ \
78 struct nvif_object *object = (o); \
79 struct nvif_sclass *sclass; \
80 const typeof(m[0]) *mclass = (m); \
81 int ret = -ENODEV; \
82 int cnt, i, j; \
83 \
84 cnt = nvif_object_sclass_get(object, &sclass); \
85 if (cnt >= 0) { \
86 for (i = 0; ret < 0 && mclass[i].oclass; i++) { \
87 for (j = 0; j < cnt; j++) { \
88 if (mclass[i].oclass == sclass[j].oclass && \
89 mclass[i].version >= sclass[j].minver && \
90 mclass[i].version <= sclass[j].maxver) { \
91 ret = i; \
92 break; \
93 } \
94 } \
95 } \
96 nvif_object_sclass_put(&sclass); \
97 } \
98 ret; \
99})
100
Ben Skeggsa04d0422014-08-10 04:10:21 +1000101/*XXX*/
102#include <core/object.h>
Ben Skeggsa01ca782015-08-20 14:54:15 +1000103#define nvxx_object(a) ({ \
104 struct nvif_object *_object = (a); \
105 (struct nvkm_object *)_object->priv; \
106})
Ben Skeggsa04d0422014-08-10 04:10:21 +1000107#endif