linux/drivers/gpu/drm/nouveau/core/core/subdev.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/subdev.h>
  27#include <core/device.h>
  28#include <core/option.h>
  29
  30void
  31nouveau_subdev_reset(struct nouveau_object *subdev)
  32{
  33        nv_trace(subdev, "resetting...\n");
  34        nv_ofuncs(subdev)->fini(subdev, false);
  35        nv_debug(subdev, "reset\n");
  36}
  37
  38int
  39nouveau_subdev_init(struct nouveau_subdev *subdev)
  40{
  41        int ret = nouveau_object_init(&subdev->base);
  42        if (ret)
  43                return ret;
  44
  45        nouveau_subdev_reset(&subdev->base);
  46        return 0;
  47}
  48
  49int
  50_nouveau_subdev_init(struct nouveau_object *object)
  51{
  52        return nouveau_subdev_init(nv_subdev(object));
  53}
  54
  55int
  56nouveau_subdev_fini(struct nouveau_subdev *subdev, bool suspend)
  57{
  58        if (subdev->unit) {
  59                nv_mask(subdev, 0x000200, subdev->unit, 0x00000000);
  60                nv_mask(subdev, 0x000200, subdev->unit, subdev->unit);
  61        }
  62
  63        return nouveau_object_fini(&subdev->base, suspend);
  64}
  65
  66int
  67_nouveau_subdev_fini(struct nouveau_object *object, bool suspend)
  68{
  69        return nouveau_subdev_fini(nv_subdev(object), suspend);
  70}
  71
  72void
  73nouveau_subdev_destroy(struct nouveau_subdev *subdev)
  74{
  75        int subidx = nv_hclass(subdev) & 0xff;
  76        nv_device(subdev)->subdev[subidx] = NULL;
  77        nouveau_object_destroy(&subdev->base);
  78}
  79
  80void
  81_nouveau_subdev_dtor(struct nouveau_object *object)
  82{
  83        nouveau_subdev_destroy(nv_subdev(object));
  84}
  85
  86int
  87nouveau_subdev_create_(struct nouveau_object *parent,
  88                       struct nouveau_object *engine,
  89                       struct nouveau_oclass *oclass, u32 pclass,
  90                       const char *subname, const char *sysname,
  91                       int size, void **pobject)
  92{
  93        struct nouveau_subdev *subdev;
  94        int ret;
  95
  96        ret = nouveau_object_create_(parent, engine, oclass, pclass |
  97                                     NV_SUBDEV_CLASS, size, pobject);
  98        subdev = *pobject;
  99        if (ret)
 100                return ret;
 101
 102        __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key);
 103        subdev->name = subname;
 104
 105        if (parent) {
 106                struct nouveau_device *device = nv_device(parent);
 107                int subidx = nv_hclass(subdev) & 0xff;
 108
 109                subdev->debug = nouveau_dbgopt(device->dbgopt, subname);
 110                subdev->mmio  = nv_subdev(device)->mmio;
 111                device->subdev[subidx] = *pobject;
 112        }
 113
 114        return 0;
 115}
 116