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
|
|
|
|
2013-12-23 01:08:00 +10:00
|
|
|
/******************************************************************************
|
|
|
|
|
* instmem object base implementation
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_nouveau_instobj_dtor(struct nouveau_object *object)
|
|
|
|
|
{
|
2014-12-05 11:54:50 +10:00
|
|
|
struct nouveau_instmem *imem = nouveau_instmem(object);
|
2013-12-23 01:08:00 +10:00
|
|
|
struct nouveau_instobj *iobj = (void *)object;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&nv_subdev(imem)->mutex);
|
|
|
|
|
list_del(&iobj->head);
|
|
|
|
|
mutex_unlock(&nv_subdev(imem)->mutex);
|
|
|
|
|
|
|
|
|
|
return nouveau_object_destroy(&iobj->base);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 19:09:17 +10:00
|
|
|
int
|
|
|
|
|
nouveau_instobj_create_(struct nouveau_object *parent,
|
|
|
|
|
struct nouveau_object *engine,
|
|
|
|
|
struct nouveau_oclass *oclass,
|
|
|
|
|
int length, void **pobject)
|
|
|
|
|
{
|
2014-12-05 11:54:50 +10:00
|
|
|
struct nouveau_instmem *imem = nouveau_instmem(parent);
|
2012-07-14 19:09:17 +10:00
|
|
|
struct nouveau_instobj *iobj;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = nouveau_object_create_(parent, engine, oclass, NV_MEMOBJ_CLASS,
|
|
|
|
|
length, pobject);
|
|
|
|
|
iobj = *pobject;
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2012-12-02 12:56:22 +01:00
|
|
|
mutex_lock(&imem->base.mutex);
|
2012-07-14 19:09:17 +10:00
|
|
|
list_add(&iobj->head, &imem->list);
|
2012-12-02 12:56:22 +01:00
|
|
|
mutex_unlock(&imem->base.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
|
|
|
|
|
nouveau_instmem_alloc(struct nouveau_instmem *imem,
|
|
|
|
|
struct nouveau_object *parent, u32 size, u32 align,
|
|
|
|
|
struct nouveau_object **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2014-12-05 11:54:50 +10:00
|
|
|
struct nouveau_instmem_impl *impl = (void *)imem->base.object.oclass;
|
2013-12-23 01:08:00 +10:00
|
|
|
struct nouveau_instobj_args args = { .size = size, .align = align };
|
2014-12-05 12:37:19 +10:00
|
|
|
return nouveau_object_ctor(parent, &parent->engine->subdev.object,
|
|
|
|
|
impl->instobj, &args, sizeof(args), pobject);
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-12-23 00:39:47 +10:00
|
|
|
_nouveau_instmem_fini(struct nouveau_object *object, bool suspend)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2013-12-23 00:39:47 +10:00
|
|
|
struct nouveau_instmem *imem = (void *)object;
|
2012-07-14 19:09:17 +10:00
|
|
|
struct nouveau_instobj *iobj;
|
2012-12-02 12:56:22 +01:00
|
|
|
int i, ret = 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
|
|
|
|
|
if (suspend) {
|
2012-12-02 12:56:22 +01:00
|
|
|
mutex_lock(&imem->base.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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < iobj->size; i += 4)
|
|
|
|
|
iobj->suspend[i / 4] = nv_ro32(iobj, i);
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
2012-12-02 12:56:22 +01:00
|
|
|
|
|
|
|
|
mutex_unlock(&imem->base.mutex);
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nouveau_subdev_fini(&imem->base, suspend);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_nouveau_instmem_init(struct nouveau_object *object)
|
|
|
|
|
{
|
|
|
|
|
struct nouveau_instmem *imem = (void *)object;
|
2013-12-23 00:39:47 +10:00
|
|
|
struct nouveau_instobj *iobj;
|
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
|
|
ret = nouveau_subdev_init(&imem->base);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&imem->base.mutex);
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(iobj, &imem->list, head) {
|
|
|
|
|
if (iobj->suspend) {
|
|
|
|
|
for (i = 0; i < iobj->size; i += 4)
|
|
|
|
|
nv_wo32(iobj, i, iobj->suspend[i / 4]);
|
|
|
|
|
vfree(iobj->suspend);
|
|
|
|
|
iobj->suspend = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutex_unlock(&imem->base.mutex);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-12-23 00:39:47 +10:00
|
|
|
nouveau_instmem_create_(struct nouveau_object *parent,
|
|
|
|
|
struct nouveau_object *engine,
|
|
|
|
|
struct nouveau_oclass *oclass,
|
|
|
|
|
int length, void **pobject)
|
2012-07-14 19:09:17 +10:00
|
|
|
{
|
2013-12-23 00:39:47 +10:00
|
|
|
struct nouveau_instmem *imem;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = nouveau_subdev_create_(parent, engine, oclass, 0,
|
|
|
|
|
"INSTMEM", "instmem", length, pobject);
|
|
|
|
|
imem = *pobject;
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&imem->list);
|
|
|
|
|
imem->alloc = nouveau_instmem_alloc;
|
|
|
|
|
return 0;
|
2012-07-14 19:09:17 +10:00
|
|
|
}
|