xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/conn.c (revision 773eb04d)
1 /*
2  * Copyright 2021 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 #include <nvif/conn.h>
23 #include <nvif/disp.h>
24 #include <nvif/printf.h>
25 
26 #include <nvif/class.h>
27 #include <nvif/if0011.h>
28 
29 int
nvif_conn_event_ctor(struct nvif_conn * conn,const char * name,nvif_event_func func,u8 types,struct nvif_event * event)30 nvif_conn_event_ctor(struct nvif_conn *conn, const char *name, nvif_event_func func, u8 types,
31 		     struct nvif_event *event)
32 {
33 	struct {
34 		struct nvif_event_v0 base;
35 		struct nvif_conn_event_v0 conn;
36 	} args;
37 	int ret;
38 
39 	args.conn.version = 0;
40 	args.conn.types = types;
41 
42 	ret = nvif_event_ctor_(&conn->object, name ?: "nvifConnHpd", nvif_conn_id(conn),
43 			       func, true, &args.base, sizeof(args), false, event);
44 	NVIF_DEBUG(&conn->object, "[NEW EVENT:HPD types:%02x]", types);
45 	return ret;
46 }
47 
48 int
nvif_conn_hpd_status(struct nvif_conn * conn)49 nvif_conn_hpd_status(struct nvif_conn *conn)
50 {
51 	struct nvif_conn_hpd_status_v0 args;
52 	int ret;
53 
54 	args.version = 0;
55 
56 	ret = nvif_mthd(&conn->object, NVIF_CONN_V0_HPD_STATUS, &args, sizeof(args));
57 	NVIF_ERRON(ret, &conn->object, "[HPD_STATUS] support:%d present:%d",
58 		   args.support, args.present);
59 	return ret ? ret : !!args.support + !!args.present;
60 }
61 
62 void
nvif_conn_dtor(struct nvif_conn * conn)63 nvif_conn_dtor(struct nvif_conn *conn)
64 {
65 	nvif_object_dtor(&conn->object);
66 }
67 
68 int
nvif_conn_ctor(struct nvif_disp * disp,const char * name,int id,struct nvif_conn * conn)69 nvif_conn_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_conn *conn)
70 {
71 	struct nvif_conn_v0 args;
72 	int ret;
73 
74 	args.version = 0;
75 	args.id = id;
76 
77 	ret = nvif_object_ctor(&disp->object, name ?: "nvifConn", id, NVIF_CLASS_CONN,
78 			       &args, sizeof(args), &conn->object);
79 	NVIF_ERRON(ret, &disp->object, "[NEW conn id:%d]", id);
80 	return ret;
81 }
82