Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2013 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs <bskeggs@redhat.com>
0023  */
0024 
0025 #include <nvif/client.h>
0026 #include <nvif/driver.h>
0027 #include <nvif/ioctl.h>
0028 
0029 #include <nvif/class.h>
0030 #include <nvif/if0000.h>
0031 
0032 int
0033 nvif_client_ioctl(struct nvif_client *client, void *data, u32 size)
0034 {
0035     return client->driver->ioctl(client->object.priv, data, size, NULL);
0036 }
0037 
0038 int
0039 nvif_client_suspend(struct nvif_client *client)
0040 {
0041     return client->driver->suspend(client->object.priv);
0042 }
0043 
0044 int
0045 nvif_client_resume(struct nvif_client *client)
0046 {
0047     return client->driver->resume(client->object.priv);
0048 }
0049 
0050 void
0051 nvif_client_dtor(struct nvif_client *client)
0052 {
0053     nvif_object_dtor(&client->object);
0054     if (client->driver) {
0055         if (client->driver->fini)
0056             client->driver->fini(client->object.priv);
0057         client->driver = NULL;
0058     }
0059 }
0060 
0061 int
0062 nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
0063          struct nvif_client *client)
0064 {
0065     struct nvif_client_v0 args = { .device = device };
0066     struct {
0067         struct nvif_ioctl_v0 ioctl;
0068         struct nvif_ioctl_nop_v0 nop;
0069     } nop = {};
0070     int ret;
0071 
0072     strncpy(args.name, name, sizeof(args.name));
0073     ret = nvif_object_ctor(parent != client ? &parent->object : NULL,
0074                    name ? name : "nvifClient", 0,
0075                    NVIF_CLASS_CLIENT, &args, sizeof(args),
0076                    &client->object);
0077     if (ret)
0078         return ret;
0079 
0080     client->object.client = client;
0081     client->object.handle = ~0;
0082     client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
0083     client->driver = parent->driver;
0084 
0085     if (ret == 0) {
0086         ret = nvif_client_ioctl(client, &nop, sizeof(nop));
0087         client->version = nop.nop.version;
0088     }
0089 
0090     if (ret)
0091         nvif_client_dtor(client);
0092     return ret;
0093 }