Commit d52ddc95 authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/imem: separate suspend/resume backup handling into their own functions

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 71370e62
...@@ -28,6 +28,36 @@ ...@@ -28,6 +28,36 @@
/****************************************************************************** /******************************************************************************
* instmem object base implementation * instmem object base implementation
*****************************************************************************/ *****************************************************************************/
static void
nvkm_instobj_load(struct nvkm_instobj *iobj)
{
struct nvkm_memory *memory = &iobj->memory;
const u64 size = nvkm_memory_size(memory);
int i;
for (i = 0; i < size; i += 4)
nvkm_wo32(memory, i, iobj->suspend[i / 4]);
vfree(iobj->suspend);
iobj->suspend = NULL;
}
static int
nvkm_instobj_save(struct nvkm_instobj *iobj)
{
struct nvkm_memory *memory = &iobj->memory;
const u64 size = nvkm_memory_size(memory);
int i;
iobj->suspend = vmalloc(size);
if (!iobj->suspend)
return -ENOMEM;
for (i = 0; i < size; i += 4)
iobj->suspend[i / 4] = nvkm_ro32(memory, i);
return 0;
}
void void
nvkm_instobj_dtor(struct nvkm_instmem *imem, struct nvkm_instobj *iobj) nvkm_instobj_dtor(struct nvkm_instmem *imem, struct nvkm_instobj *iobj)
{ {
...@@ -104,34 +134,18 @@ nvkm_instmem_fini(struct nvkm_subdev *subdev, bool suspend) ...@@ -104,34 +134,18 @@ nvkm_instmem_fini(struct nvkm_subdev *subdev, bool suspend)
{ {
struct nvkm_instmem *imem = nvkm_instmem(subdev); struct nvkm_instmem *imem = nvkm_instmem(subdev);
struct nvkm_instobj *iobj; struct nvkm_instobj *iobj;
int i;
if (imem->func->fini)
imem->func->fini(imem);
if (suspend) { if (suspend) {
list_for_each_entry(iobj, &imem->list, head) { list_for_each_entry(iobj, &imem->list, head) {
struct nvkm_memory *memory = &iobj->memory; int ret = nvkm_instobj_save(iobj);
u64 size = nvkm_memory_size(memory); if (ret)
return ret;
iobj->suspend = vmalloc(size);
if (!iobj->suspend)
return -ENOMEM;
for (i = 0; i < size; i += 4)
iobj->suspend[i / 4] = nvkm_ro32(memory, i);
} }
} }
return 0; if (imem->func->fini)
} imem->func->fini(imem);
static int
nvkm_instmem_oneinit(struct nvkm_subdev *subdev)
{
struct nvkm_instmem *imem = nvkm_instmem(subdev);
if (imem->func->oneinit)
return imem->func->oneinit(imem);
return 0; return 0;
} }
...@@ -140,22 +154,24 @@ nvkm_instmem_init(struct nvkm_subdev *subdev) ...@@ -140,22 +154,24 @@ nvkm_instmem_init(struct nvkm_subdev *subdev)
{ {
struct nvkm_instmem *imem = nvkm_instmem(subdev); struct nvkm_instmem *imem = nvkm_instmem(subdev);
struct nvkm_instobj *iobj; struct nvkm_instobj *iobj;
int i;
list_for_each_entry(iobj, &imem->list, head) { list_for_each_entry(iobj, &imem->list, head) {
if (iobj->suspend) { if (iobj->suspend)
struct nvkm_memory *memory = &iobj->memory; nvkm_instobj_load(iobj);
u64 size = nvkm_memory_size(memory);
for (i = 0; i < size; i += 4)
nvkm_wo32(memory, i, iobj->suspend[i / 4]);
vfree(iobj->suspend);
iobj->suspend = NULL;
}
} }
return 0; return 0;
} }
static int
nvkm_instmem_oneinit(struct nvkm_subdev *subdev)
{
struct nvkm_instmem *imem = nvkm_instmem(subdev);
if (imem->func->oneinit)
return imem->func->oneinit(imem);
return 0;
}
static void * static void *
nvkm_instmem_dtor(struct nvkm_subdev *subdev) nvkm_instmem_dtor(struct nvkm_subdev *subdev)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment