linux/drivers/gpu/drm/nouveau/core/engine/dmaobj/base.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/class.h>
  27
  28#include <subdev/fb.h>
  29#include <engine/dmaobj.h>
  30
  31static int
  32nouveau_dmaobj_ctor(struct nouveau_object *parent,
  33                    struct nouveau_object *engine,
  34                    struct nouveau_oclass *oclass, void *data, u32 size,
  35                    struct nouveau_object **pobject)
  36{
  37        struct nouveau_dmaeng *dmaeng = (void *)engine;
  38        struct nouveau_dmaobj *dmaobj;
  39        struct nouveau_gpuobj *gpuobj;
  40        struct nv_dma_class *args = data;
  41        int ret;
  42
  43        if (size < sizeof(*args))
  44                return -EINVAL;
  45
  46        ret = nouveau_object_create(parent, engine, oclass, 0, &dmaobj);
  47        *pobject = nv_object(dmaobj);
  48        if (ret)
  49                return ret;
  50
  51        switch (args->flags & NV_DMA_TARGET_MASK) {
  52        case NV_DMA_TARGET_VM:
  53                dmaobj->target = NV_MEM_TARGET_VM;
  54                break;
  55        case NV_DMA_TARGET_VRAM:
  56                dmaobj->target = NV_MEM_TARGET_VRAM;
  57                break;
  58        case NV_DMA_TARGET_PCI:
  59                dmaobj->target = NV_MEM_TARGET_PCI;
  60                break;
  61        case NV_DMA_TARGET_PCI_US:
  62        case NV_DMA_TARGET_AGP:
  63                dmaobj->target = NV_MEM_TARGET_PCI_NOSNOOP;
  64                break;
  65        default:
  66                return -EINVAL;
  67        }
  68
  69        switch (args->flags & NV_DMA_ACCESS_MASK) {
  70        case NV_DMA_ACCESS_VM:
  71                dmaobj->access = NV_MEM_ACCESS_VM;
  72                break;
  73        case NV_DMA_ACCESS_RD:
  74                dmaobj->access = NV_MEM_ACCESS_RO;
  75                break;
  76        case NV_DMA_ACCESS_WR:
  77                dmaobj->access = NV_MEM_ACCESS_WO;
  78                break;
  79        case NV_DMA_ACCESS_RDWR:
  80                dmaobj->access = NV_MEM_ACCESS_RW;
  81                break;
  82        default:
  83                return -EINVAL;
  84        }
  85
  86        dmaobj->start = args->start;
  87        dmaobj->limit = args->limit;
  88        dmaobj->conf0 = args->conf0;
  89
  90        switch (nv_mclass(parent)) {
  91        case NV_DEVICE_CLASS:
  92                /* delayed, or no, binding */
  93                break;
  94        default:
  95                ret = dmaeng->bind(dmaeng, *pobject, dmaobj, &gpuobj);
  96                if (ret == 0) {
  97                        nouveau_object_ref(NULL, pobject);
  98                        *pobject = nv_object(gpuobj);
  99                }
 100                break;
 101        }
 102
 103        return ret;
 104}
 105
 106static struct nouveau_ofuncs
 107nouveau_dmaobj_ofuncs = {
 108        .ctor = nouveau_dmaobj_ctor,
 109        .dtor = nouveau_object_destroy,
 110        .init = nouveau_object_init,
 111        .fini = nouveau_object_fini,
 112};
 113
 114struct nouveau_oclass
 115nouveau_dmaobj_sclass[] = {
 116        { NV_DMA_FROM_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
 117        { NV_DMA_TO_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
 118        { NV_DMA_IN_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
 119        {}
 120};
 121