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.
25 #include <subdev/instmem.h>
28 nouveau_instobj_create_(struct nouveau_object *parent,
29 struct nouveau_object *engine,
30 struct nouveau_oclass *oclass,
31 int length, void **pobject)
33 struct nouveau_instmem *imem = (void *)engine;
34 struct nouveau_instobj *iobj;
37 ret = nouveau_object_create_(parent, engine, oclass, NV_MEMOBJ_CLASS,
43 mutex_lock(&imem->base.mutex);
44 list_add(&iobj->head, &imem->list);
45 mutex_unlock(&imem->base.mutex);
50 nouveau_instobj_destroy(struct nouveau_instobj *iobj)
52 struct nouveau_subdev *subdev = nv_subdev(iobj->base.engine);
54 mutex_lock(&subdev->mutex);
55 list_del(&iobj->head);
56 mutex_unlock(&subdev->mutex);
58 return nouveau_object_destroy(&iobj->base);
62 _nouveau_instobj_dtor(struct nouveau_object *object)
64 struct nouveau_instobj *iobj = (void *)object;
65 return nouveau_instobj_destroy(iobj);
69 nouveau_instmem_create_(struct nouveau_object *parent,
70 struct nouveau_object *engine,
71 struct nouveau_oclass *oclass,
72 int length, void **pobject)
74 struct nouveau_instmem *imem;
77 ret = nouveau_subdev_create_(parent, engine, oclass, 0,
78 "INSTMEM", "instmem", length, pobject);
83 INIT_LIST_HEAD(&imem->list);
88 nouveau_instmem_init(struct nouveau_instmem *imem)
90 struct nouveau_instobj *iobj;
93 ret = nouveau_subdev_init(&imem->base);
97 mutex_lock(&imem->base.mutex);
99 list_for_each_entry(iobj, &imem->list, head) {
101 for (i = 0; i < iobj->size; i += 4)
102 nv_wo32(iobj, i, iobj->suspend[i / 4]);
103 vfree(iobj->suspend);
104 iobj->suspend = NULL;
108 mutex_unlock(&imem->base.mutex);
114 nouveau_instmem_fini(struct nouveau_instmem *imem, bool suspend)
116 struct nouveau_instobj *iobj;
120 mutex_lock(&imem->base.mutex);
122 list_for_each_entry(iobj, &imem->list, head) {
123 iobj->suspend = vmalloc(iobj->size);
124 if (!iobj->suspend) {
129 for (i = 0; i < iobj->size; i += 4)
130 iobj->suspend[i / 4] = nv_ro32(iobj, i);
133 mutex_unlock(&imem->base.mutex);
139 return nouveau_subdev_fini(&imem->base, suspend);
143 _nouveau_instmem_init(struct nouveau_object *object)
145 struct nouveau_instmem *imem = (void *)object;
146 return nouveau_instmem_init(imem);
150 _nouveau_instmem_fini(struct nouveau_object *object, bool suspend)
152 struct nouveau_instmem *imem = (void *)object;
153 return nouveau_instmem_fini(imem, suspend);