drm/nouveau/device: decouple from engine machinery
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nvkm / core / subdev.c
CommitLineData
9274f4a9
BS
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 */
9274f4a9
BS
24#include <core/subdev.h>
25#include <core/device.h>
26#include <core/option.h>
27
5025407b
BS
28struct nvkm_subdev *
29nvkm_subdev(void *obj, int idx)
a38f37a7 30{
5025407b 31 struct nvkm_object *object = nv_object(obj);
490d595f
BS
32 while (object && !nv_iclass(object, NV_SUBDEV_CLASS))
33 object = object->parent;
a1e88736 34 if (object == NULL || !object->parent || nv_subidx(nv_subdev(object)) != idx)
490d595f
BS
35 object = nv_device(obj)->subdev[idx];
36 return object ? nv_subdev(object) : NULL;
a38f37a7
BS
37}
38
9274f4a9 39void
53003941 40nvkm_subdev_reset(struct nvkm_object *obj)
9274f4a9 41{
53003941
BS
42 struct nvkm_subdev *subdev = container_of(obj, typeof(*subdev), object);
43 nvkm_trace(subdev, "resetting...\n");
44 nv_ofuncs(subdev)->fini(&subdev->object, false);
45 nvkm_trace(subdev, "reset\n");
9274f4a9
BS
46}
47
48int
5025407b 49nvkm_subdev_init(struct nvkm_subdev *subdev)
9274f4a9 50{
5025407b 51 int ret = nvkm_object_init(&subdev->object);
9274f4a9
BS
52 if (ret)
53 return ret;
54
5025407b 55 nvkm_subdev_reset(&subdev->object);
9274f4a9
BS
56 return 0;
57}
58
59int
5025407b 60_nvkm_subdev_init(struct nvkm_object *object)
9274f4a9 61{
5025407b 62 return nvkm_subdev_init(nv_subdev(object));
9274f4a9
BS
63}
64
65int
5025407b 66nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
9274f4a9 67{
94bab102
BS
68 struct nvkm_device *device = subdev->device;
69
9274f4a9 70 if (subdev->unit) {
94bab102
BS
71 nvkm_mask(device, 0x000200, subdev->unit, 0x00000000);
72 nvkm_mask(device, 0x000200, subdev->unit, subdev->unit);
9274f4a9
BS
73 }
74
5025407b 75 return nvkm_object_fini(&subdev->object, suspend);
9274f4a9
BS
76}
77
78int
5025407b 79_nvkm_subdev_fini(struct nvkm_object *object, bool suspend)
9274f4a9 80{
5025407b 81 return nvkm_subdev_fini(nv_subdev(object), suspend);
9274f4a9
BS
82}
83
84void
5025407b 85nvkm_subdev_destroy(struct nvkm_subdev *subdev)
9274f4a9
BS
86{
87 int subidx = nv_hclass(subdev) & 0xff;
88 nv_device(subdev)->subdev[subidx] = NULL;
5025407b 89 nvkm_object_destroy(&subdev->object);
9274f4a9
BS
90}
91
92void
5025407b 93_nvkm_subdev_dtor(struct nvkm_object *object)
9274f4a9 94{
5025407b 95 nvkm_subdev_destroy(nv_subdev(object));
9274f4a9
BS
96}
97
98int
5025407b
BS
99nvkm_subdev_create_(struct nvkm_object *parent, struct nvkm_object *engine,
100 struct nvkm_oclass *oclass, u32 pclass,
101 const char *subname, const char *sysname,
102 int size, void **pobject)
9274f4a9 103{
5025407b 104 struct nvkm_subdev *subdev;
9274f4a9
BS
105 int ret;
106
5025407b
BS
107 ret = nvkm_object_create_(parent, engine, oclass, pclass |
108 NV_SUBDEV_CLASS, size, pobject);
9274f4a9
BS
109 subdev = *pobject;
110 if (ret)
111 return ret;
112
5f97ab91 113 __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key);
9274f4a9 114 subdev->name = subname;
6594363b 115 subdev->sname = sysname;
9274f4a9
BS
116
117 if (parent) {
5025407b
BS
118 struct nvkm_device *device = nv_device(parent);
119 subdev->debug = nvkm_dbgopt(device->dbgopt, subname);
d351b856
BS
120 subdev->device = device;
121 } else {
122 subdev->device = nv_device(subdev);
9274f4a9
BS
123 }
124
125 return 0;
126}
This page took 0.189624 seconds and 5 git commands to generate.