drm/nouveau/core: wrap direct use of object accessor functions
authorBen Skeggs <bskeggs@redhat.com>
Thu, 20 Aug 2015 04:54:14 +0000 (14:54 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 28 Aug 2015 02:40:29 +0000 (12:40 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/core/object.h
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c
drivers/gpu/drm/nouveau/nvkm/core/object.c

index 696fb62e8a0aca96f5957b5c5ab0606ce4007bf6..15caf553501b2c36ae830c6a0b681eb869a4de0d 100644 (file)
@@ -26,6 +26,13 @@ struct nvkm_object {
 #endif
 };
 
+int nvkm_object_rd08(struct nvkm_object *, u64 addr, u8  *data);
+int nvkm_object_rd16(struct nvkm_object *, u64 addr, u16 *data);
+int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
+int nvkm_object_wr08(struct nvkm_object *, u64 addr, u8   data);
+int nvkm_object_wr16(struct nvkm_object *, u64 addr, u16  data);
+int nvkm_object_wr32(struct nvkm_object *, u64 addr, u32  data);
+
 static inline struct nvkm_object *
 nv_object(void *obj)
 {
index 8a0d291d5f5f00cada272c540d42ee0d0c5a97df..7434958846f7b428cc08b183c7f59f7b61c40147 100644 (file)
@@ -224,10 +224,14 @@ static int
 nvkm_ioctl_rd(struct nvkm_handle *handle, void *data, u32 size)
 {
        struct nvkm_object *object = handle->object;
-       struct nvkm_ofuncs *ofuncs = object->oclass->ofuncs;
        union {
                struct nvif_ioctl_rd_v0 v0;
        } *args = data;
+       union {
+               u8  b08;
+               u16 b16;
+               u32 b32;
+       } v;
        int ret;
 
        nvif_ioctl(object, "rd size %d\n", size);
@@ -236,22 +240,16 @@ nvkm_ioctl_rd(struct nvkm_handle *handle, void *data, u32 size)
                           args->v0.version, args->v0.size, args->v0.addr);
                switch (args->v0.size) {
                case 1:
-                       if (ret = -ENODEV, ofuncs->rd08) {
-                               args->v0.data = nv_ro08(object, args->v0.addr);
-                               ret = 0;
-                       }
+                       ret = nvkm_object_rd08(object, args->v0.addr, &v.b08);
+                       args->v0.data = v.b08;
                        break;
                case 2:
-                       if (ret = -ENODEV, ofuncs->rd16) {
-                               args->v0.data = nv_ro16(object, args->v0.addr);
-                               ret = 0;
-                       }
+                       ret = nvkm_object_rd16(object, args->v0.addr, &v.b16);
+                       args->v0.data = v.b16;
                        break;
                case 4:
-                       if (ret = -ENODEV, ofuncs->rd32) {
-                               args->v0.data = nv_ro32(object, args->v0.addr);
-                               ret = 0;
-                       }
+                       ret = nvkm_object_rd32(object, args->v0.addr, &v.b32);
+                       args->v0.data = v.b32;
                        break;
                default:
                        ret = -EINVAL;
@@ -266,7 +264,6 @@ static int
 nvkm_ioctl_wr(struct nvkm_handle *handle, void *data, u32 size)
 {
        struct nvkm_object *object = handle->object;
-       struct nvkm_ofuncs *ofuncs = object->oclass->ofuncs;
        union {
                struct nvif_ioctl_wr_v0 v0;
        } *args = data;
@@ -278,32 +275,18 @@ nvkm_ioctl_wr(struct nvkm_handle *handle, void *data, u32 size)
                           "wr vers %d size %d addr %016llx data %08x\n",
                           args->v0.version, args->v0.size, args->v0.addr,
                           args->v0.data);
-               switch (args->v0.size) {
-               case 1:
-                       if (ret = -ENODEV, ofuncs->wr08) {
-                               nv_wo08(object, args->v0.addr, args->v0.data);
-                               ret = 0;
-                       }
-                       break;
-               case 2:
-                       if (ret = -ENODEV, ofuncs->wr16) {
-                               nv_wo16(object, args->v0.addr, args->v0.data);
-                               ret = 0;
-                       }
-                       break;
-               case 4:
-                       if (ret = -ENODEV, ofuncs->wr32) {
-                               nv_wo32(object, args->v0.addr, args->v0.data);
-                               ret = 0;
-                       }
-                       break;
-               default:
-                       ret = -EINVAL;
-                       break;
-               }
+       } else
+               return ret;
+
+       switch (args->v0.size) {
+       case 1: return nvkm_object_wr08(object, args->v0.addr, args->v0.data);
+       case 2: return nvkm_object_wr16(object, args->v0.addr, args->v0.data);
+       case 4: return nvkm_object_wr32(object, args->v0.addr, args->v0.data);
+       default:
+               break;
        }
 
-       return ret;
+       return -EINVAL;
 }
 
 static int
index b690a3898732eafec03a2e436c9274353548e57f..b32a041636a403fb51f1f65971eeda4f5971f17a 100644 (file)
 #include <core/object.h>
 #include <core/engine.h>
 
+int
+nvkm_object_rd08(struct nvkm_object *object, u64 addr, u8 *data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->rd08) {
+               *data = oclass->ofuncs->rd08(object, addr);
+               return 0;
+       }
+       *data = 0x00;
+       return -ENODEV;
+}
+
+int
+nvkm_object_rd16(struct nvkm_object *object, u64 addr, u16 *data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->rd16) {
+               *data = oclass->ofuncs->rd16(object, addr);
+               return 0;
+       }
+       *data = 0x0000;
+       return -ENODEV;
+}
+
+int
+nvkm_object_rd32(struct nvkm_object *object, u64 addr, u32 *data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->rd32) {
+               *data = oclass->ofuncs->rd32(object, addr);
+               return 0;
+       }
+       *data = 0x0000;
+       return -ENODEV;
+}
+
+int
+nvkm_object_wr08(struct nvkm_object *object, u64 addr, u8 data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->wr08) {
+               oclass->ofuncs->wr08(object, addr, data);
+               return 0;
+       }
+       return -ENODEV;
+}
+
+int
+nvkm_object_wr16(struct nvkm_object *object, u64 addr, u16 data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->wr16) {
+               oclass->ofuncs->wr16(object, addr, data);
+               return 0;
+       }
+       return -ENODEV;
+}
+
+int
+nvkm_object_wr32(struct nvkm_object *object, u64 addr, u32 data)
+{
+       const struct nvkm_oclass *oclass = object->oclass;
+       if (oclass->ofuncs && oclass->ofuncs->wr32) {
+               oclass->ofuncs->wr32(object, addr, data);
+               return 0;
+       }
+       return -ENODEV;
+}
+
 int
 nvkm_object_create_(struct nvkm_object *parent, struct nvkm_object *engine,
                    struct nvkm_oclass *oclass, u32 pclass,