linux/drivers/gpu/drm/nouveau/core/core/parent.c
<<
>>
Prefs
   1/*
   2 * Copyright 2012 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
  23 */
  24
  25#include <core/object.h>
  26#include <core/parent.h>
  27
  28int
  29nouveau_parent_sclass(struct nouveau_object *parent, u16 handle,
  30                      struct nouveau_object **pengine,
  31                      struct nouveau_oclass **poclass)
  32{
  33        struct nouveau_sclass *sclass;
  34        struct nouveau_engine *engine;
  35        struct nouveau_oclass *oclass;
  36        u64 mask;
  37
  38        sclass = nv_parent(parent)->sclass;
  39        while (sclass) {
  40                if ((sclass->oclass->handle & 0xffff) == handle) {
  41                        *pengine = parent->engine;
  42                        *poclass = sclass->oclass;
  43                        return 0;
  44                }
  45
  46                sclass = sclass->sclass;
  47        }
  48
  49        mask = nv_parent(parent)->engine;
  50        while (mask) {
  51                int i = ffsll(mask) - 1;
  52
  53                if ((engine = nouveau_engine(parent, i))) {
  54                        oclass = engine->sclass;
  55                        while (oclass->ofuncs) {
  56                                if ((oclass->handle & 0xffff) == handle) {
  57                                        *pengine = nv_object(engine);
  58                                        *poclass = oclass;
  59                                        return 0;
  60                                }
  61                                oclass++;
  62                        }
  63                }
  64
  65                mask &= ~(1ULL << i);
  66        }
  67
  68        return -EINVAL;
  69}
  70
  71int
  72nouveau_parent_create_(struct nouveau_object *parent,
  73                       struct nouveau_object *engine,
  74                       struct nouveau_oclass *oclass, u32 pclass,
  75                       struct nouveau_oclass *sclass, u64 engcls,
  76                       int size, void **pobject)
  77{
  78        struct nouveau_parent *object;
  79        struct nouveau_sclass *nclass;
  80        int ret;
  81
  82        ret = nouveau_object_create_(parent, engine, oclass, pclass |
  83                                     NV_PARENT_CLASS, size, pobject);
  84        object = *pobject;
  85        if (ret)
  86                return ret;
  87
  88        while (sclass && sclass->ofuncs) {
  89                nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
  90                if (!nclass)
  91                        return -ENOMEM;
  92
  93                nclass->sclass = object->sclass;
  94                object->sclass = nclass;
  95                nclass->engine = engine ? nv_engine(engine) : NULL;
  96                nclass->oclass = sclass;
  97                sclass++;
  98        }
  99
 100        object->engine = engcls;
 101        return 0;
 102}
 103
 104void
 105nouveau_parent_destroy(struct nouveau_parent *parent)
 106{
 107        struct nouveau_sclass *sclass;
 108
 109        while ((sclass = parent->sclass)) {
 110                parent->sclass = sclass->sclass;
 111                kfree(sclass);
 112        }
 113
 114        nouveau_object_destroy(&parent->base);
 115}
 116
 117
 118void
 119_nouveau_parent_dtor(struct nouveau_object *object)
 120{
 121        nouveau_parent_destroy(nv_parent(object));
 122}
 123