linux/drivers/gpu/drm/nouveau/nvkm/core/oproxy.c
<<
>>
Prefs
   1/*
   2 * Copyright 2015 Red Hat Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 * Authors: Ben Skeggs <bskeggs@redhat.com>
  23 */
  24#include <core/oproxy.h>
  25
  26static int
  27nvkm_oproxy_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
  28{
  29        return nvkm_object_mthd(nvkm_oproxy(object)->object, mthd, data, size);
  30}
  31
  32static int
  33nvkm_oproxy_ntfy(struct nvkm_object *object, u32 mthd,
  34                 struct nvkm_event **pevent)
  35{
  36        return nvkm_object_ntfy(nvkm_oproxy(object)->object, mthd, pevent);
  37}
  38
  39static int
  40nvkm_oproxy_map(struct nvkm_object *object, u64 *addr, u32 *size)
  41{
  42        return nvkm_object_map(nvkm_oproxy(object)->object, addr, size);
  43}
  44
  45static int
  46nvkm_oproxy_rd08(struct nvkm_object *object, u64 addr, u8 *data)
  47{
  48        return nvkm_object_rd08(nvkm_oproxy(object)->object, addr, data);
  49}
  50
  51static int
  52nvkm_oproxy_rd16(struct nvkm_object *object, u64 addr, u16 *data)
  53{
  54        return nvkm_object_rd16(nvkm_oproxy(object)->object, addr, data);
  55}
  56
  57static int
  58nvkm_oproxy_rd32(struct nvkm_object *object, u64 addr, u32 *data)
  59{
  60        return nvkm_object_rd32(nvkm_oproxy(object)->object, addr, data);
  61}
  62
  63static int
  64nvkm_oproxy_wr08(struct nvkm_object *object, u64 addr, u8 data)
  65{
  66        return nvkm_object_wr08(nvkm_oproxy(object)->object, addr, data);
  67}
  68
  69static int
  70nvkm_oproxy_wr16(struct nvkm_object *object, u64 addr, u16 data)
  71{
  72        return nvkm_object_wr16(nvkm_oproxy(object)->object, addr, data);
  73}
  74
  75static int
  76nvkm_oproxy_wr32(struct nvkm_object *object, u64 addr, u32 data)
  77{
  78        return nvkm_object_wr32(nvkm_oproxy(object)->object, addr, data);
  79}
  80
  81static int
  82nvkm_oproxy_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  83                 int align, struct nvkm_gpuobj **pgpuobj)
  84{
  85        return nvkm_object_bind(nvkm_oproxy(object)->object,
  86                                parent, align, pgpuobj);
  87}
  88
  89static int
  90nvkm_oproxy_sclass(struct nvkm_object *object, int index,
  91                   struct nvkm_oclass *oclass)
  92{
  93        struct nvkm_oproxy *oproxy = nvkm_oproxy(object);
  94        oclass->parent = oproxy->object;
  95        if (!oproxy->object->func->sclass)
  96                return -ENODEV;
  97        return oproxy->object->func->sclass(oproxy->object, index, oclass);
  98}
  99
 100static int
 101nvkm_oproxy_fini(struct nvkm_object *object, bool suspend)
 102{
 103        struct nvkm_oproxy *oproxy = nvkm_oproxy(object);
 104        int ret;
 105
 106        if (oproxy->func->fini[0]) {
 107                ret = oproxy->func->fini[0](oproxy, suspend);
 108                if (ret && suspend)
 109                        return ret;
 110        }
 111
 112        if (oproxy->object->func->fini) {
 113                ret = oproxy->object->func->fini(oproxy->object, suspend);
 114                if (ret && suspend)
 115                        return ret;
 116        }
 117
 118        if (oproxy->func->fini[1]) {
 119                ret = oproxy->func->fini[1](oproxy, suspend);
 120                if (ret && suspend)
 121                        return ret;
 122        }
 123
 124        return 0;
 125}
 126
 127static int
 128nvkm_oproxy_init(struct nvkm_object *object)
 129{
 130        struct nvkm_oproxy *oproxy = nvkm_oproxy(object);
 131        int ret;
 132
 133        if (oproxy->func->init[0]) {
 134                ret = oproxy->func->init[0](oproxy);
 135                if (ret)
 136                        return ret;
 137        }
 138
 139        if (oproxy->object->func->init) {
 140                ret = oproxy->object->func->init(oproxy->object);
 141                if (ret)
 142                        return ret;
 143        }
 144
 145        if (oproxy->func->init[1]) {
 146                ret = oproxy->func->init[1](oproxy);
 147                if (ret)
 148                        return ret;
 149        }
 150
 151        return 0;
 152}
 153
 154static void *
 155nvkm_oproxy_dtor(struct nvkm_object *object)
 156{
 157        struct nvkm_oproxy *oproxy = nvkm_oproxy(object);
 158        if (oproxy->func->dtor[0])
 159                oproxy->func->dtor[0](oproxy);
 160        nvkm_object_del(&oproxy->object);
 161        if (oproxy->func->dtor[1])
 162                oproxy->func->dtor[1](oproxy);
 163        return oproxy;
 164}
 165
 166static const struct nvkm_object_func
 167nvkm_oproxy_func = {
 168        .dtor = nvkm_oproxy_dtor,
 169        .init = nvkm_oproxy_init,
 170        .fini = nvkm_oproxy_fini,
 171        .mthd = nvkm_oproxy_mthd,
 172        .ntfy = nvkm_oproxy_ntfy,
 173        .map = nvkm_oproxy_map,
 174        .rd08 = nvkm_oproxy_rd08,
 175        .rd16 = nvkm_oproxy_rd16,
 176        .rd32 = nvkm_oproxy_rd32,
 177        .wr08 = nvkm_oproxy_wr08,
 178        .wr16 = nvkm_oproxy_wr16,
 179        .wr32 = nvkm_oproxy_wr32,
 180        .bind = nvkm_oproxy_bind,
 181        .sclass = nvkm_oproxy_sclass,
 182};
 183
 184void
 185nvkm_oproxy_ctor(const struct nvkm_oproxy_func *func,
 186                 const struct nvkm_oclass *oclass, struct nvkm_oproxy *oproxy)
 187{
 188        nvkm_object_ctor(&nvkm_oproxy_func, oclass, &oproxy->base);
 189        oproxy->func = func;
 190}
 191
 192int
 193nvkm_oproxy_new_(const struct nvkm_oproxy_func *func,
 194                 const struct nvkm_oclass *oclass, struct nvkm_oproxy **poproxy)
 195{
 196        if (!(*poproxy = kzalloc(sizeof(**poproxy), GFP_KERNEL)))
 197                return -ENOMEM;
 198        nvkm_oproxy_ctor(func, oclass, *poproxy);
 199        return 0;
 200}
 201