ARM: pmu: add support for interrupt-affinity property
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / subdev / instmem / base.c
blobd16358cc6cbba50ff5e5e9848349ae928107d152
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 "priv.h"
26 #include <core/engine.h>
28 /******************************************************************************
29 * instmem object base implementation
30 *****************************************************************************/
32 void
33 _nvkm_instobj_dtor(struct nvkm_object *object)
35 struct nvkm_instmem *imem = nvkm_instmem(object);
36 struct nvkm_instobj *iobj = (void *)object;
38 mutex_lock(&nv_subdev(imem)->mutex);
39 list_del(&iobj->head);
40 mutex_unlock(&nv_subdev(imem)->mutex);
42 return nvkm_object_destroy(&iobj->base);
45 int
46 nvkm_instobj_create_(struct nvkm_object *parent, struct nvkm_object *engine,
47 struct nvkm_oclass *oclass, int length, void **pobject)
49 struct nvkm_instmem *imem = nvkm_instmem(parent);
50 struct nvkm_instobj *iobj;
51 int ret;
53 ret = nvkm_object_create_(parent, engine, oclass, NV_MEMOBJ_CLASS,
54 length, pobject);
55 iobj = *pobject;
56 if (ret)
57 return ret;
59 mutex_lock(&imem->base.mutex);
60 list_add(&iobj->head, &imem->list);
61 mutex_unlock(&imem->base.mutex);
62 return 0;
65 /******************************************************************************
66 * instmem subdev base implementation
67 *****************************************************************************/
69 static int
70 nvkm_instmem_alloc(struct nvkm_instmem *imem, struct nvkm_object *parent,
71 u32 size, u32 align, struct nvkm_object **pobject)
73 struct nvkm_instmem_impl *impl = (void *)imem->base.object.oclass;
74 struct nvkm_instobj_args args = { .size = size, .align = align };
75 return nvkm_object_ctor(parent, &parent->engine->subdev.object,
76 impl->instobj, &args, sizeof(args), pobject);
79 int
80 _nvkm_instmem_fini(struct nvkm_object *object, bool suspend)
82 struct nvkm_instmem *imem = (void *)object;
83 struct nvkm_instobj *iobj;
84 int i, ret = 0;
86 if (suspend) {
87 mutex_lock(&imem->base.mutex);
88 list_for_each_entry(iobj, &imem->list, head) {
89 iobj->suspend = vmalloc(iobj->size);
90 if (!iobj->suspend) {
91 ret = -ENOMEM;
92 break;
95 for (i = 0; i < iobj->size; i += 4)
96 iobj->suspend[i / 4] = nv_ro32(iobj, i);
98 mutex_unlock(&imem->base.mutex);
99 if (ret)
100 return ret;
103 return nvkm_subdev_fini(&imem->base, suspend);
107 _nvkm_instmem_init(struct nvkm_object *object)
109 struct nvkm_instmem *imem = (void *)object;
110 struct nvkm_instobj *iobj;
111 int ret, i;
113 ret = nvkm_subdev_init(&imem->base);
114 if (ret)
115 return ret;
117 mutex_lock(&imem->base.mutex);
118 list_for_each_entry(iobj, &imem->list, head) {
119 if (iobj->suspend) {
120 for (i = 0; i < iobj->size; i += 4)
121 nv_wo32(iobj, i, iobj->suspend[i / 4]);
122 vfree(iobj->suspend);
123 iobj->suspend = NULL;
126 mutex_unlock(&imem->base.mutex);
127 return 0;
131 nvkm_instmem_create_(struct nvkm_object *parent, struct nvkm_object *engine,
132 struct nvkm_oclass *oclass, int length, void **pobject)
134 struct nvkm_instmem *imem;
135 int ret;
137 ret = nvkm_subdev_create_(parent, engine, oclass, 0, "INSTMEM",
138 "instmem", length, pobject);
139 imem = *pobject;
140 if (ret)
141 return ret;
143 INIT_LIST_HEAD(&imem->list);
144 imem->alloc = nvkm_instmem_alloc;
145 return 0;