2012-07-14 19:09:17 +10:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
*/
|
2013-12-23 00:39:47 +10:00
|
|
|
#include "priv.h"
|
2012-07-14 19:09:17 +10:00
|
|
|
|
2015-01-14 15:05:26 +10:00
|
|
|
#include <core/engine.h>
|
|
|
|
|
2013-12-23 01:08:00 +10:00
|
|
|
/******************************************************************************
|
|
|
|
* instmem object base implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
void
|
2015-01-14 15:05:26 +10:00
|
|
|
_nvkm_instobj_dtor(struct nvkm_object *object)
|
2013-12-23 01:08:00 +10:00
|
|
|
{
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instmem *imem = nvkm_instmem(object);
|
|
|
|
struct nvkm_instobj *iobj = (void *)object;
|
2013-12-23 01:08:00 +10:00
|
|
|
|
|
|
|
mutex_lock(&nv_subdev(imem)->mutex);
|
|
|
|
list_del(&iobj->head);
|
|
|
|
mutex_unlock(&nv_subdev(imem)->mutex);
|
|
|
|
|
2015-08-20 14:54:14 +10:00
|
|
|
return nvkm_object_destroy(&iobj->object);
|
2013-12-23 01:08:00 +10:00
|
|
|
}
|
|
|
|
|
2012-07-14 19:09:17 +10:00
|
|
|
int
|
2015-01-14 15:05:26 +10:00
|
|
|
nvkm_instobj_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, int length, void **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instmem *imem = nvkm_instmem(parent);
|
|
|
|
struct nvkm_instobj *iobj;
|
2012-07-14 19:09:17 +10:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 15:05:26 +10:00
|
|
|
ret = nvkm_object_create_(parent, engine, oclass, NV_MEMOBJ_CLASS,
|
|
|
|
length, pobject);
|
2012-07-14 19:09:17 +10:00
|
|
|
iobj = *pobject;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_lock(&imem->subdev.mutex);
|
2012-07-14 19:09:17 +10:00
|
|
|
list_add(&iobj->head, &imem->list);
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_unlock(&imem->subdev.mutex);
|
2012-07-14 19:09:17 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-23 00:39:47 +10:00
|
|
|
/******************************************************************************
|
|
|
|
* instmem subdev base implementation
|
|
|
|
*****************************************************************************/
|
2012-07-14 19:09:17 +10:00
|
|
|
|
2013-12-23 00:39:47 +10:00
|
|
|
static int
|
2015-01-14 15:05:26 +10:00
|
|
|
nvkm_instmem_alloc(struct nvkm_instmem *imem, struct nvkm_object *parent,
|
|
|
|
u32 size, u32 align, struct nvkm_object **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nvkm_instmem_impl *impl = (void *)imem->subdev.object.oclass;
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instobj_args args = { .size = size, .align = align };
|
2015-08-20 14:54:16 +10:00
|
|
|
return nvkm_object_old(parent, &parent->engine->subdev.object,
|
2015-01-14 15:05:26 +10:00
|
|
|
impl->instobj, &args, sizeof(args), pobject);
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 15:05:26 +10:00
|
|
|
_nvkm_instmem_fini(struct nvkm_object *object, bool suspend)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instmem *imem = (void *)object;
|
|
|
|
struct nvkm_instobj *iobj;
|
2012-12-02 12:56:22 +01:00
|
|
|
int i, ret = 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
|
|
|
|
if (suspend) {
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_lock(&imem->subdev.mutex);
|
2012-07-14 19:09:17 +10:00
|
|
|
list_for_each_entry(iobj, &imem->list, head) {
|
|
|
|
iobj->suspend = vmalloc(iobj->size);
|
2012-12-02 12:56:22 +01:00
|
|
|
if (!iobj->suspend) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:14 +10:00
|
|
|
for (i = 0; i < iobj->size; i += 4) {
|
|
|
|
nvkm_object_rd32(&iobj->object, i, (u32 *)
|
|
|
|
&iobj->suspend[i/4]);
|
|
|
|
}
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_unlock(&imem->subdev.mutex);
|
2012-12-02 12:56:22 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:16 +10:00
|
|
|
return nvkm_subdev_fini_old(&imem->subdev, suspend);
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 15:05:26 +10:00
|
|
|
_nvkm_instmem_init(struct nvkm_object *object)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instmem *imem = (void *)object;
|
|
|
|
struct nvkm_instobj *iobj;
|
2013-12-23 00:39:47 +10:00
|
|
|
int ret, i;
|
|
|
|
|
2015-08-20 14:54:16 +10:00
|
|
|
ret = nvkm_subdev_init_old(&imem->subdev);
|
2013-12-23 00:39:47 +10:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_lock(&imem->subdev.mutex);
|
2013-12-23 00:39:47 +10:00
|
|
|
list_for_each_entry(iobj, &imem->list, head) {
|
|
|
|
if (iobj->suspend) {
|
2015-08-20 14:54:14 +10:00
|
|
|
for (i = 0; i < iobj->size; i += 4) {
|
|
|
|
nvkm_object_wr32(&iobj->object, i, *(u32 *)
|
|
|
|
&iobj->suspend[i/4]);
|
|
|
|
}
|
2013-12-23 00:39:47 +10:00
|
|
|
vfree(iobj->suspend);
|
|
|
|
iobj->suspend = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 14:54:06 +10:00
|
|
|
mutex_unlock(&imem->subdev.mutex);
|
2013-12-23 00:39:47 +10:00
|
|
|
return 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 15:05:26 +10:00
|
|
|
nvkm_instmem_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, int length, void **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2015-01-14 15:05:26 +10:00
|
|
|
struct nvkm_instmem *imem;
|
2013-12-23 00:39:47 +10:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 15:05:26 +10:00
|
|
|
ret = nvkm_subdev_create_(parent, engine, oclass, 0, "INSTMEM",
|
|
|
|
"instmem", length, pobject);
|
2013-12-23 00:39:47 +10:00
|
|
|
imem = *pobject;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&imem->list);
|
2015-01-14 15:05:26 +10:00
|
|
|
imem->alloc = nvkm_instmem_alloc;
|
2013-12-23 00:39:47 +10:00
|
|
|
return 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|