drm/nouveau/nvif: helper to match against supported class list
authorBen Skeggs <bskeggs@redhat.com>
Fri, 4 Nov 2016 07:20:35 +0000 (17:20 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Mon, 7 Nov 2016 04:04:41 +0000 (14:04 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvif/object.h

index 8d815967767fc7ff776ba1f5b8e19b576a7638f7..9e58b305b020380ac3f033d535e216485c09d05a 100644 (file)
@@ -66,6 +66,35 @@ void nvif_object_unmap(struct nvif_object *);
 
 #define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d))
 
+struct nvif_mclass {
+       s32 oclass;
+       int version;
+};
+
+#define nvif_mclass(o,m) ({                                                    \
+       struct nvif_object *object = (o);                                      \
+       struct nvif_sclass *sclass;                                            \
+       const typeof(m[0]) *mclass = (m);                                      \
+       int ret = -ENODEV;                                                     \
+       int cnt, i, j;                                                         \
+                                                                               \
+       cnt = nvif_object_sclass_get(object, &sclass);                         \
+       if (cnt >= 0) {                                                        \
+               for (i = 0; ret < 0 && mclass[i].oclass; i++) {                \
+                       for (j = 0; j < cnt; j++) {                            \
+                               if (mclass[i].oclass  == sclass[j].oclass &&   \
+                                   mclass[i].version >= sclass[j].minver &&   \
+                                   mclass[i].version <= sclass[j].maxver) {   \
+                                       ret = i;                               \
+                                       break;                                 \
+                               }                                              \
+                       }                                                      \
+               }                                                              \
+               nvif_object_sclass_put(&sclass);                               \
+       }                                                                      \
+       ret;                                                                   \
+})
+
 /*XXX*/
 #include <core/object.h>
 #define nvxx_object(a) ({                                                      \