1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2013 Red Hat Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun * all copies or substantial portions of the Software.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Authors: Ben Skeggs <bskeggs@redhat.com>
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include <nvif/client.h>
26*4882a593Smuzhiyun #include <nvif/driver.h>
27*4882a593Smuzhiyun #include <nvif/ioctl.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include <nvif/class.h>
30*4882a593Smuzhiyun #include <nvif/if0000.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun int
nvif_client_ioctl(struct nvif_client * client,void * data,u32 size)33*4882a593Smuzhiyun nvif_client_ioctl(struct nvif_client *client, void *data, u32 size)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun return client->driver->ioctl(client->object.priv, client->super, data, size, NULL);
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun int
nvif_client_suspend(struct nvif_client * client)39*4882a593Smuzhiyun nvif_client_suspend(struct nvif_client *client)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun return client->driver->suspend(client->object.priv);
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun int
nvif_client_resume(struct nvif_client * client)45*4882a593Smuzhiyun nvif_client_resume(struct nvif_client *client)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun return client->driver->resume(client->object.priv);
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun void
nvif_client_dtor(struct nvif_client * client)51*4882a593Smuzhiyun nvif_client_dtor(struct nvif_client *client)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun nvif_object_dtor(&client->object);
54*4882a593Smuzhiyun if (client->driver) {
55*4882a593Smuzhiyun if (client->driver->fini)
56*4882a593Smuzhiyun client->driver->fini(client->object.priv);
57*4882a593Smuzhiyun client->driver = NULL;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun int
nvif_client_ctor(struct nvif_client * parent,const char * name,u64 device,struct nvif_client * client)62*4882a593Smuzhiyun nvif_client_ctor(struct nvif_client *parent, const char *name, u64 device,
63*4882a593Smuzhiyun struct nvif_client *client)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun struct nvif_client_v0 args = { .device = device };
66*4882a593Smuzhiyun struct {
67*4882a593Smuzhiyun struct nvif_ioctl_v0 ioctl;
68*4882a593Smuzhiyun struct nvif_ioctl_nop_v0 nop;
69*4882a593Smuzhiyun } nop = {};
70*4882a593Smuzhiyun int ret;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun strncpy(args.name, name, sizeof(args.name));
73*4882a593Smuzhiyun ret = nvif_object_ctor(parent != client ? &parent->object : NULL,
74*4882a593Smuzhiyun name ? name : "nvifClient", 0,
75*4882a593Smuzhiyun NVIF_CLASS_CLIENT, &args, sizeof(args),
76*4882a593Smuzhiyun &client->object);
77*4882a593Smuzhiyun if (ret)
78*4882a593Smuzhiyun return ret;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun client->object.client = client;
81*4882a593Smuzhiyun client->object.handle = ~0;
82*4882a593Smuzhiyun client->route = NVIF_IOCTL_V0_ROUTE_NVIF;
83*4882a593Smuzhiyun client->super = true;
84*4882a593Smuzhiyun client->driver = parent->driver;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun if (ret == 0) {
87*4882a593Smuzhiyun ret = nvif_client_ioctl(client, &nop, sizeof(nop));
88*4882a593Smuzhiyun client->version = nop.nop.version;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun if (ret)
92*4882a593Smuzhiyun nvif_client_dtor(client);
93*4882a593Smuzhiyun return ret;
94*4882a593Smuzhiyun }
95