xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/conn.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
195983aeaSBen Skeggs /*
295983aeaSBen Skeggs  * Copyright 2021 Red Hat Inc.
395983aeaSBen Skeggs  *
495983aeaSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
595983aeaSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
695983aeaSBen Skeggs  * to deal in the Software without restriction, including without limitation
795983aeaSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
895983aeaSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
995983aeaSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
1095983aeaSBen Skeggs  *
1195983aeaSBen Skeggs  * The above copyright notice and this permission notice shall be included in
1295983aeaSBen Skeggs  * all copies or substantial portions of the Software.
1395983aeaSBen Skeggs  *
1495983aeaSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1595983aeaSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1695983aeaSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1795983aeaSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1895983aeaSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1995983aeaSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2095983aeaSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
2195983aeaSBen Skeggs  */
2295983aeaSBen Skeggs #include <nvif/conn.h>
2395983aeaSBen Skeggs #include <nvif/disp.h>
2495983aeaSBen Skeggs #include <nvif/printf.h>
2595983aeaSBen Skeggs 
2695983aeaSBen Skeggs #include <nvif/class.h>
2795983aeaSBen Skeggs #include <nvif/if0011.h>
2895983aeaSBen Skeggs 
2932dd9236SBen Skeggs int
nvif_conn_event_ctor(struct nvif_conn * conn,const char * name,nvif_event_func func,u8 types,struct nvif_event * event)30*773eb04dSBen Skeggs nvif_conn_event_ctor(struct nvif_conn *conn, const char *name, nvif_event_func func, u8 types,
31*773eb04dSBen Skeggs 		     struct nvif_event *event)
32*773eb04dSBen Skeggs {
33*773eb04dSBen Skeggs 	struct {
34*773eb04dSBen Skeggs 		struct nvif_event_v0 base;
35*773eb04dSBen Skeggs 		struct nvif_conn_event_v0 conn;
36*773eb04dSBen Skeggs 	} args;
37*773eb04dSBen Skeggs 	int ret;
38*773eb04dSBen Skeggs 
39*773eb04dSBen Skeggs 	args.conn.version = 0;
40*773eb04dSBen Skeggs 	args.conn.types = types;
41*773eb04dSBen Skeggs 
42*773eb04dSBen Skeggs 	ret = nvif_event_ctor_(&conn->object, name ?: "nvifConnHpd", nvif_conn_id(conn),
43*773eb04dSBen Skeggs 			       func, true, &args.base, sizeof(args), false, event);
44*773eb04dSBen Skeggs 	NVIF_DEBUG(&conn->object, "[NEW EVENT:HPD types:%02x]", types);
45*773eb04dSBen Skeggs 	return ret;
46*773eb04dSBen Skeggs }
47*773eb04dSBen Skeggs 
48*773eb04dSBen Skeggs int
nvif_conn_hpd_status(struct nvif_conn * conn)4932dd9236SBen Skeggs nvif_conn_hpd_status(struct nvif_conn *conn)
5032dd9236SBen Skeggs {
5132dd9236SBen Skeggs 	struct nvif_conn_hpd_status_v0 args;
5232dd9236SBen Skeggs 	int ret;
5332dd9236SBen Skeggs 
5432dd9236SBen Skeggs 	args.version = 0;
5532dd9236SBen Skeggs 
5632dd9236SBen Skeggs 	ret = nvif_mthd(&conn->object, NVIF_CONN_V0_HPD_STATUS, &args, sizeof(args));
5732dd9236SBen Skeggs 	NVIF_ERRON(ret, &conn->object, "[HPD_STATUS] support:%d present:%d",
5832dd9236SBen Skeggs 		   args.support, args.present);
5932dd9236SBen Skeggs 	return ret ? ret : !!args.support + !!args.present;
6032dd9236SBen Skeggs }
6132dd9236SBen Skeggs 
6295983aeaSBen Skeggs void
nvif_conn_dtor(struct nvif_conn * conn)6395983aeaSBen Skeggs nvif_conn_dtor(struct nvif_conn *conn)
6495983aeaSBen Skeggs {
6595983aeaSBen Skeggs 	nvif_object_dtor(&conn->object);
6695983aeaSBen Skeggs }
6795983aeaSBen Skeggs 
6895983aeaSBen Skeggs int
nvif_conn_ctor(struct nvif_disp * disp,const char * name,int id,struct nvif_conn * conn)6995983aeaSBen Skeggs nvif_conn_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_conn *conn)
7095983aeaSBen Skeggs {
7195983aeaSBen Skeggs 	struct nvif_conn_v0 args;
7295983aeaSBen Skeggs 	int ret;
7395983aeaSBen Skeggs 
7495983aeaSBen Skeggs 	args.version = 0;
7595983aeaSBen Skeggs 	args.id = id;
7695983aeaSBen Skeggs 
7795983aeaSBen Skeggs 	ret = nvif_object_ctor(&disp->object, name ?: "nvifConn", id, NVIF_CLASS_CONN,
7895983aeaSBen Skeggs 			       &args, sizeof(args), &conn->object);
7995983aeaSBen Skeggs 	NVIF_ERRON(ret, &disp->object, "[NEW conn id:%d]", id);
8095983aeaSBen Skeggs 	return ret;
8195983aeaSBen Skeggs }
82