Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 1 | #ifndef __NVIF_OBJECT_H__ |
| 2 | #define __NVIF_OBJECT_H__ |
| 3 | |
| 4 | #include <nvif/os.h> |
| 5 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 6 | struct nvif_sclass { |
| 7 | s32 oclass; |
| 8 | int minver; |
| 9 | int maxver; |
| 10 | }; |
| 11 | |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 12 | struct nvif_object { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 13 | struct nvif_client *client; |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 14 | u32 handle; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 15 | s32 oclass; |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 16 | void *priv; /*XXX: hack */ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 17 | struct { |
Al Viro | 3cfb2fa | 2014-08-31 15:06:09 -0400 | [diff] [blame] | 18 | void __iomem *ptr; |
Ben Skeggs | 0132605 | 2017-11-01 03:56:19 +1000 | [diff] [blame] | 19 | u64 size; |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 20 | } map; |
| 21 | }; |
| 22 | |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 23 | int nvif_object_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32, |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 24 | struct nvif_object *); |
| 25 | void nvif_object_fini(struct nvif_object *); |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 26 | int nvif_object_ioctl(struct nvif_object *, void *, u32, void **); |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 27 | int nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **); |
| 28 | void nvif_object_sclass_put(struct nvif_sclass **); |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 29 | u32 nvif_object_rd(struct nvif_object *, int, u64); |
| 30 | void nvif_object_wr(struct nvif_object *, int, u64, u32); |
| 31 | int nvif_object_mthd(struct nvif_object *, u32, void *, u32); |
Ben Skeggs | 0132605 | 2017-11-01 03:56:19 +1000 | [diff] [blame] | 32 | int nvif_object_map_handle(struct nvif_object *, void *, u32, |
| 33 | u64 *handle, u64 *length); |
| 34 | void nvif_object_unmap_handle(struct nvif_object *); |
| 35 | int nvif_object_map(struct nvif_object *, void *, u32); |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 36 | void nvif_object_unmap(struct nvif_object *); |
| 37 | |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 38 | #define nvif_handle(a) (unsigned long)(void *)(a) |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 39 | #define nvif_object(a) (a)->object |
| 40 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 41 | #define nvif_rd(a,f,b,c) ({ \ |
| 42 | struct nvif_object *_object = (a); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 43 | u32 _data; \ |
| 44 | if (likely(_object->map.ptr)) \ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 45 | _data = f((u8 __iomem *)_object->map.ptr + (c)); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 46 | else \ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 47 | _data = nvif_object_rd(_object, (b), (c)); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 48 | _data; \ |
| 49 | }) |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 50 | #define nvif_wr(a,f,b,c,d) ({ \ |
| 51 | struct nvif_object *_object = (a); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 52 | if (likely(_object->map.ptr)) \ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 53 | f((d), (u8 __iomem *)_object->map.ptr + (c)); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 54 | else \ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 55 | nvif_object_wr(_object, (b), (c), (d)); \ |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 56 | }) |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 57 | #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 Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 63 | #define nvif_mask(a,b,c,d) ({ \ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 64 | 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 Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 68 | }) |
| 69 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 70 | #define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d)) |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 71 | |
Ben Skeggs | a3f8a41 | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 72 | struct 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 Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 101 | /*XXX*/ |
| 102 | #include <core/object.h> |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 103 | #define nvxx_object(a) ({ \ |
| 104 | struct nvif_object *_object = (a); \ |
| 105 | (struct nvkm_object *)_object->priv; \ |
| 106 | }) |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 107 | #endif |