ARM: pmu: add support for interrupt-affinity property
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / core / subdev.c
blobc5fb3a79317412eab5b16594c7c03d51e0814eaf
1 /*
2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs
24 #include <core/subdev.h>
25 #include <core/device.h>
26 #include <core/option.h>
28 struct nvkm_subdev *
29 nvkm_subdev(void *obj, int idx)
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 || nv_subidx(nv_subdev(object)) != idx)
35 object = nv_device(obj)->subdev[idx];
36 return object ? nv_subdev(object) : NULL;
39 void
40 nvkm_subdev_reset(struct nvkm_object *subdev)
42 nv_trace(subdev, "resetting...\n");
43 nv_ofuncs(subdev)->fini(subdev, false);
44 nv_debug(subdev, "reset\n");
47 int
48 nvkm_subdev_init(struct nvkm_subdev *subdev)
50 int ret = nvkm_object_init(&subdev->object);
51 if (ret)
52 return ret;
54 nvkm_subdev_reset(&subdev->object);
55 return 0;
58 int
59 _nvkm_subdev_init(struct nvkm_object *object)
61 return nvkm_subdev_init(nv_subdev(object));
64 int
65 nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
67 if (subdev->unit) {
68 nv_mask(subdev, 0x000200, subdev->unit, 0x00000000);
69 nv_mask(subdev, 0x000200, subdev->unit, subdev->unit);
72 return nvkm_object_fini(&subdev->object, suspend);
75 int
76 _nvkm_subdev_fini(struct nvkm_object *object, bool suspend)
78 return nvkm_subdev_fini(nv_subdev(object), suspend);
81 void
82 nvkm_subdev_destroy(struct nvkm_subdev *subdev)
84 int subidx = nv_hclass(subdev) & 0xff;
85 nv_device(subdev)->subdev[subidx] = NULL;
86 nvkm_object_destroy(&subdev->object);
89 void
90 _nvkm_subdev_dtor(struct nvkm_object *object)
92 nvkm_subdev_destroy(nv_subdev(object));
95 int
96 nvkm_subdev_create_(struct nvkm_object *parent, struct nvkm_object *engine,
97 struct nvkm_oclass *oclass, u32 pclass,
98 const char *subname, const char *sysname,
99 int size, void **pobject)
101 struct nvkm_subdev *subdev;
102 int ret;
104 ret = nvkm_object_create_(parent, engine, oclass, pclass |
105 NV_SUBDEV_CLASS, size, pobject);
106 subdev = *pobject;
107 if (ret)
108 return ret;
110 __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key);
111 subdev->name = subname;
113 if (parent) {
114 struct nvkm_device *device = nv_device(parent);
115 subdev->debug = nvkm_dbgopt(device->dbgopt, subname);
116 subdev->mmio = nv_subdev(device)->mmio;
119 return 0;