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