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.
26 #include <core/engine.h>
28 /******************************************************************************
29 * instmem object base implementation
30 *****************************************************************************/
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
);
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
;
53 ret
= nvkm_object_create_(parent
, engine
, oclass
, NV_MEMOBJ_CLASS
,
59 mutex_lock(&imem
->base
.mutex
);
60 list_add(&iobj
->head
, &imem
->list
);
61 mutex_unlock(&imem
->base
.mutex
);
65 /******************************************************************************
66 * instmem subdev base implementation
67 *****************************************************************************/
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
);
80 _nvkm_instmem_fini(struct nvkm_object
*object
, bool suspend
)
82 struct nvkm_instmem
*imem
= (void *)object
;
83 struct nvkm_instobj
*iobj
;
87 mutex_lock(&imem
->base
.mutex
);
88 list_for_each_entry(iobj
, &imem
->list
, head
) {
89 iobj
->suspend
= vmalloc(iobj
->size
);
95 for (i
= 0; i
< iobj
->size
; i
+= 4)
96 iobj
->suspend
[i
/ 4] = nv_ro32(iobj
, i
);
98 mutex_unlock(&imem
->base
.mutex
);
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
;
113 ret
= nvkm_subdev_init(&imem
->base
);
117 mutex_lock(&imem
->base
.mutex
);
118 list_for_each_entry(iobj
, &imem
->list
, head
) {
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
);
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
;
137 ret
= nvkm_subdev_create_(parent
, engine
, oclass
, 0, "INSTMEM",
138 "instmem", length
, pobject
);
143 INIT_LIST_HEAD(&imem
->list
);
144 imem
->alloc
= nvkm_instmem_alloc
;