Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
client.c
Go to the documentation of this file.
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);
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,
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  nouveau_namedb_destroy(&client->base);
71  return ret;
72  }
73 
74  /* prevent init/fini being called, os in in charge of this */
75  atomic_set(&nv_object(client)->usecount, 2);
76 
77  nouveau_object_ref(device, &client->device);
78  snprintf(client->name, sizeof(client->name), "%s", name);
79  client->debug = nouveau_dbgopt(dbg, "CLIENT");
80  return 0;
81 }
82 
83 int
85 {
86  int ret;
87  nv_debug(client, "init running\n");
88  ret = nouveau_handle_init(client->root);
89  nv_debug(client, "init completed with %d\n", ret);
90  return ret;
91 }
92 
93 int
95 {
96  const char *name[2] = { "fini", "suspend" };
97  int ret;
98 
99  nv_debug(client, "%s running\n", name[suspend]);
100  ret = nouveau_handle_fini(client->root, suspend);
101  nv_debug(client, "%s completed with %d\n", name[suspend], ret);
102  return ret;
103 }