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