linux/drivers/gpu/drm/nouveau/core/engine/dmaobj/nvd0.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/device.h>
  26#include <core/gpuobj.h>
  27#include <core/class.h>
  28
  29#include <subdev/fb.h>
  30#include <engine/dmaobj.h>
  31
  32struct nvd0_dmaeng_priv {
  33        struct nouveau_dmaeng base;
  34};
  35
  36static int
  37nvd0_dmaobj_bind(struct nouveau_dmaeng *dmaeng,
  38                 struct nouveau_object *parent,
  39                 struct nouveau_dmaobj *dmaobj,
  40                 struct nouveau_gpuobj **pgpuobj)
  41{
  42        u32 flags0 = 0x00000000;
  43        int ret;
  44
  45        if (!nv_iclass(parent, NV_ENGCTX_CLASS)) {
  46                switch (nv_mclass(parent->parent)) {
  47                case NVD0_DISP_MAST_CLASS:
  48                case NVD0_DISP_SYNC_CLASS:
  49                case NVD0_DISP_OVLY_CLASS:
  50                case NVE0_DISP_MAST_CLASS:
  51                case NVE0_DISP_SYNC_CLASS:
  52                case NVE0_DISP_OVLY_CLASS:
  53                        break;
  54                default:
  55                        return -EINVAL;
  56                }
  57        } else
  58                return 0;
  59
  60        if (!(dmaobj->conf0 & NVD0_DMA_CONF0_ENABLE)) {
  61                if (dmaobj->target == NV_MEM_TARGET_VM) {
  62                        dmaobj->conf0 |= NVD0_DMA_CONF0_TYPE_VM;
  63                        dmaobj->conf0 |= NVD0_DMA_CONF0_PAGE_LP;
  64                } else {
  65                        dmaobj->conf0 |= NVD0_DMA_CONF0_TYPE_LINEAR;
  66                        dmaobj->conf0 |= NVD0_DMA_CONF0_PAGE_SP;
  67                }
  68        }
  69
  70        flags0 |= (dmaobj->conf0 & NVD0_DMA_CONF0_TYPE) << 20;
  71        flags0 |= (dmaobj->conf0 & NVD0_DMA_CONF0_PAGE) >> 4;
  72
  73        switch (dmaobj->target) {
  74        case NV_MEM_TARGET_VRAM:
  75                flags0 |= 0x00000009;
  76                break;
  77        default:
  78                return -EINVAL;
  79                break;
  80        }
  81
  82        ret = nouveau_gpuobj_new(parent, parent, 24, 32, 0, pgpuobj);
  83        if (ret == 0) {
  84                nv_wo32(*pgpuobj, 0x00, flags0);
  85                nv_wo32(*pgpuobj, 0x04, dmaobj->start >> 8);
  86                nv_wo32(*pgpuobj, 0x08, dmaobj->limit >> 8);
  87                nv_wo32(*pgpuobj, 0x0c, 0x00000000);
  88                nv_wo32(*pgpuobj, 0x10, 0x00000000);
  89                nv_wo32(*pgpuobj, 0x14, 0x00000000);
  90        }
  91
  92        return ret;
  93}
  94
  95static int
  96nvd0_dmaeng_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
  97                 struct nouveau_oclass *oclass, void *data, u32 size,
  98                 struct nouveau_object **pobject)
  99{
 100        struct nvd0_dmaeng_priv *priv;
 101        int ret;
 102
 103        ret = nouveau_dmaeng_create(parent, engine, oclass, &priv);
 104        *pobject = nv_object(priv);
 105        if (ret)
 106                return ret;
 107
 108        nv_engine(priv)->sclass = nouveau_dmaobj_sclass;
 109        priv->base.bind = nvd0_dmaobj_bind;
 110        return 0;
 111}
 112
 113struct nouveau_oclass
 114nvd0_dmaeng_oclass = {
 115        .handle = NV_ENGINE(DMAOBJ, 0xd0),
 116        .ofuncs = &(struct nouveau_ofuncs) {
 117                .ctor = nvd0_dmaeng_ctor,
 118                .dtor = _nouveau_dmaeng_dtor,
 119                .init = _nouveau_dmaeng_init,
 120                .fini = _nouveau_dmaeng_fini,
 121        },
 122};
 123