]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/core/client.c
Merge remote-tracking branch 'regulator/topic/max8997' into regulator-next
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / core / client.c
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24
25 #include <core/object.h>
26 #include <core/client.h>
27 #include <core/handle.h>
28 #include <core/option.h>
29
30 #include <subdev/device.h>
31
32 static void
33 nouveau_client_dtor(struct nouveau_object *object)
34 {
35         struct nouveau_client *client = (void *)object;
36         nouveau_object_ref(NULL, &client->device);
37         nouveau_handle_destroy(client->root);
38         nouveau_namedb_destroy(&client->base);
39 }
40
41 static struct nouveau_oclass
42 nouveau_client_oclass = {
43         .ofuncs = &(struct nouveau_ofuncs) {
44                 .dtor = nouveau_client_dtor,
45         },
46 };
47
48 int
49 nouveau_client_create_(const char *name, u64 devname, const char *cfg,
50                        const char *dbg, int length, void **pobject)
51 {
52         struct nouveau_object *device;
53         struct nouveau_client *client;
54         int ret;
55
56         device = (void *)nouveau_device_find(devname);
57         if (!device)
58                 return -ENODEV;
59
60         ret = nouveau_namedb_create_(NULL, NULL, &nouveau_client_oclass,
61                                      NV_CLIENT_CLASS, nouveau_device_sclass,
62                                      0, length, pobject);
63         client = *pobject;
64         if (ret)
65                 return ret;
66
67         ret = nouveau_handle_create(nv_object(client), ~0, ~0,
68                                     nv_object(client), &client->root);
69         if (ret)
70                 return ret;
71
72         /* prevent init/fini being called, os in in charge of this */
73         atomic_set(&nv_object(client)->usecount, 2);
74
75         nouveau_object_ref(device, &client->device);
76         snprintf(client->name, sizeof(client->name), "%s", name);
77         client->debug = nouveau_dbgopt(dbg, "CLIENT");
78         return 0;
79 }
80
81 int
82 nouveau_client_init(struct nouveau_client *client)
83 {
84         int ret;
85         nv_debug(client, "init running\n");
86         ret = nouveau_handle_init(client->root);
87         nv_debug(client, "init completed with %d\n", ret);
88         return ret;
89 }
90
91 int
92 nouveau_client_fini(struct nouveau_client *client, bool suspend)
93 {
94         const char *name[2] = { "fini", "suspend" };
95         int ret;
96
97         nv_debug(client, "%s running\n", name[suspend]);
98         ret = nouveau_handle_fini(client->root, suspend);
99         nv_debug(client, "%s completed with %d\n", name[suspend], ret);
100         return ret;
101 }