2014-08-09 18:10:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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 <bskeggs@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2015-01-13 12:13:14 +00:00
|
|
|
#include <nvif/object.h>
|
|
|
|
#include <nvif/client.h>
|
|
|
|
#include <nvif/driver.h>
|
|
|
|
#include <nvif/ioctl.h>
|
2014-08-09 18:10:21 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
|
|
|
|
{
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nvif_client *client = object->client;
|
2014-08-09 18:10:21 +00:00
|
|
|
union {
|
|
|
|
struct nvif_ioctl_v0 v0;
|
|
|
|
} *args = data;
|
|
|
|
|
|
|
|
if (size >= sizeof(*args) && args->v0.version == 0) {
|
2015-08-20 04:54:16 +00:00
|
|
|
if (object != &client->object)
|
|
|
|
args->v0.object = nvif_handle(object);
|
|
|
|
else
|
|
|
|
args->v0.object = 0;
|
2014-08-09 18:10:21 +00:00
|
|
|
args->v0.owner = NVIF_IOCTL_V0_OWNER_ANY;
|
|
|
|
} else
|
|
|
|
return -ENOSYS;
|
|
|
|
|
2015-08-20 04:54:15 +00:00
|
|
|
return client->driver->ioctl(client->object.priv, client->super,
|
|
|
|
data, size, hack);
|
2014-08-09 18:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-08-20 04:54:16 +00:00
|
|
|
nvif_object_sclass(struct nvif_object *object, s32 *oclass, int count)
|
2014-08-09 18:10:21 +00:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_sclass_v0 sclass;
|
|
|
|
} *args;
|
|
|
|
u32 size = count * sizeof(args->sclass.oclass[0]);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
|
|
|
|
return -ENOMEM;
|
|
|
|
args->ioctl.version = 0;
|
|
|
|
args->ioctl.type = NVIF_IOCTL_V0_SCLASS;
|
|
|
|
args->sclass.version = 0;
|
|
|
|
args->sclass.count = count;
|
|
|
|
|
|
|
|
ret = nvif_object_ioctl(object, args, sizeof(*args) + size, NULL);
|
|
|
|
ret = ret ? ret : args->sclass.count;
|
|
|
|
memcpy(oclass, args->sclass.oclass, size);
|
|
|
|
kfree(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32
|
|
|
|
nvif_object_rd(struct nvif_object *object, int size, u64 addr)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_rd_v0 rd;
|
|
|
|
} args = {
|
|
|
|
.ioctl.type = NVIF_IOCTL_V0_RD,
|
|
|
|
.rd.size = size,
|
|
|
|
.rd.addr = addr,
|
|
|
|
};
|
|
|
|
int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
|
|
|
|
if (ret) {
|
|
|
|
/*XXX: warn? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return args.rd.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvif_object_wr(struct nvif_object *object, int size, u64 addr, u32 data)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_wr_v0 wr;
|
|
|
|
} args = {
|
|
|
|
.ioctl.type = NVIF_IOCTL_V0_WR,
|
|
|
|
.wr.size = size,
|
|
|
|
.wr.addr = addr,
|
|
|
|
.wr.data = data,
|
|
|
|
};
|
|
|
|
int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
|
|
|
|
if (ret) {
|
|
|
|
/*XXX: warn? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_mthd_v0 mthd;
|
|
|
|
} *args;
|
|
|
|
u8 stack[128];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (sizeof(*args) + size > sizeof(stack)) {
|
|
|
|
if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL)))
|
|
|
|
return -ENOMEM;
|
|
|
|
} else {
|
|
|
|
args = (void *)stack;
|
|
|
|
}
|
|
|
|
args->ioctl.version = 0;
|
|
|
|
args->ioctl.type = NVIF_IOCTL_V0_MTHD;
|
|
|
|
args->mthd.version = 0;
|
|
|
|
args->mthd.method = mthd;
|
|
|
|
|
|
|
|
memcpy(args->mthd.data, data, size);
|
|
|
|
ret = nvif_object_ioctl(object, args, sizeof(*args) + size, NULL);
|
|
|
|
memcpy(data, args->mthd.data, size);
|
|
|
|
if (args != (void *)stack)
|
|
|
|
kfree(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvif_object_unmap(struct nvif_object *object)
|
|
|
|
{
|
|
|
|
if (object->map.size) {
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nvif_client *client = object->client;
|
2014-08-09 18:10:21 +00:00
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_unmap unmap;
|
|
|
|
} args = {
|
|
|
|
.ioctl.type = NVIF_IOCTL_V0_UNMAP,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (object->map.ptr) {
|
|
|
|
client->driver->unmap(client, object->map.ptr,
|
|
|
|
object->map.size);
|
|
|
|
object->map.ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvif_object_ioctl(object, &args, sizeof(args), NULL);
|
|
|
|
object->map.size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nvif_object_map(struct nvif_object *object)
|
|
|
|
{
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nvif_client *client = object->client;
|
2014-08-09 18:10:21 +00:00
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_map_v0 map;
|
|
|
|
} args = {
|
|
|
|
.ioctl.type = NVIF_IOCTL_V0_MAP,
|
|
|
|
};
|
|
|
|
int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
|
|
|
|
if (ret == 0) {
|
|
|
|
object->map.size = args.map.length;
|
|
|
|
object->map.ptr = client->driver->map(client, args.map.handle,
|
|
|
|
object->map.size);
|
|
|
|
if (ret = -ENOMEM, object->map.ptr)
|
|
|
|
return 0;
|
|
|
|
nvif_object_unmap(object);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvif_object_fini(struct nvif_object *object)
|
|
|
|
{
|
2015-08-20 04:54:15 +00:00
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_del del;
|
|
|
|
} args = {
|
|
|
|
.ioctl.type = NVIF_IOCTL_V0_DEL,
|
|
|
|
};
|
2014-08-09 18:10:21 +00:00
|
|
|
|
2015-08-20 04:54:15 +00:00
|
|
|
if (!object->client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nvif_object_unmap(object);
|
|
|
|
nvif_object_ioctl(object, &args, sizeof(args), NULL);
|
|
|
|
object->client = NULL;
|
2014-08-09 18:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-08-20 04:54:16 +00:00
|
|
|
nvif_object_init(struct nvif_object *parent, u32 handle, s32 oclass,
|
2015-08-20 04:54:15 +00:00
|
|
|
void *data, u32 size, struct nvif_object *object)
|
2014-08-09 18:10:21 +00:00
|
|
|
{
|
2015-08-20 04:54:15 +00:00
|
|
|
struct {
|
|
|
|
struct nvif_ioctl_v0 ioctl;
|
|
|
|
struct nvif_ioctl_new_v0 new;
|
|
|
|
} *args;
|
2014-08-09 18:10:21 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2015-08-20 04:54:15 +00:00
|
|
|
object->client = NULL;
|
2014-08-09 18:10:21 +00:00
|
|
|
object->handle = handle;
|
|
|
|
object->oclass = oclass;
|
|
|
|
object->map.ptr = NULL;
|
|
|
|
object->map.size = 0;
|
|
|
|
|
2015-08-20 04:54:16 +00:00
|
|
|
if (parent) {
|
2015-08-20 04:54:15 +00:00
|
|
|
if (!(args = kmalloc(sizeof(*args) + size, GFP_KERNEL))) {
|
2014-08-09 18:10:21 +00:00
|
|
|
nvif_object_fini(object);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:15 +00:00
|
|
|
args->ioctl.version = 0;
|
|
|
|
args->ioctl.type = NVIF_IOCTL_V0_NEW;
|
|
|
|
args->new.version = 0;
|
|
|
|
args->new.route = parent->client->route;
|
2015-08-20 04:54:16 +00:00
|
|
|
args->new.token = nvif_handle(object);
|
|
|
|
args->new.object = nvif_handle(object);
|
2015-08-20 04:54:15 +00:00
|
|
|
args->new.handle = handle;
|
|
|
|
args->new.oclass = oclass;
|
|
|
|
|
|
|
|
memcpy(args->new.data, data, size);
|
|
|
|
ret = nvif_object_ioctl(parent, args, sizeof(*args) + size,
|
|
|
|
&object->priv);
|
|
|
|
memcpy(data, args->new.data, size);
|
|
|
|
kfree(args);
|
|
|
|
if (ret == 0)
|
|
|
|
object->client = parent->client;
|
2014-08-09 18:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
nvif_object_fini(object);
|
|
|
|
return ret;
|
|
|
|
}
|