124edb884SFrançois Tigeot /*
224edb884SFrançois Tigeot  * Copyright © 2014 Red Hat.
324edb884SFrançois Tigeot  *
424edb884SFrançois Tigeot  * Permission to use, copy, modify, distribute, and sell this software and its
524edb884SFrançois Tigeot  * documentation for any purpose is hereby granted without fee, provided that
624edb884SFrançois Tigeot  * the above copyright notice appear in all copies and that both that copyright
724edb884SFrançois Tigeot  * notice and this permission notice appear in supporting documentation, and
824edb884SFrançois Tigeot  * that the name of the copyright holders not be used in advertising or
924edb884SFrançois Tigeot  * publicity pertaining to distribution of the software without specific,
1024edb884SFrançois Tigeot  * written prior permission.  The copyright holders make no representations
1124edb884SFrançois Tigeot  * about the suitability of this software for any purpose.  It is provided "as
1224edb884SFrançois Tigeot  * is" without express or implied warranty.
1324edb884SFrançois Tigeot  *
1424edb884SFrançois Tigeot  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1524edb884SFrançois Tigeot  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1624edb884SFrançois Tigeot  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1724edb884SFrançois Tigeot  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1824edb884SFrançois Tigeot  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1924edb884SFrançois Tigeot  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2024edb884SFrançois Tigeot  * OF THIS SOFTWARE.
2124edb884SFrançois Tigeot  */
2224edb884SFrançois Tigeot #ifndef _DRM_DP_MST_HELPER_H_
2324edb884SFrançois Tigeot #define _DRM_DP_MST_HELPER_H_
2424edb884SFrançois Tigeot 
2524edb884SFrançois Tigeot #include <linux/types.h>
2624edb884SFrançois Tigeot #include <drm/drm_dp_helper.h>
27*3f2dd94aSFrançois Tigeot #include <drm/drm_atomic.h>
2824edb884SFrançois Tigeot 
2924edb884SFrançois Tigeot struct drm_dp_mst_branch;
3024edb884SFrançois Tigeot 
3124edb884SFrançois Tigeot /**
322c9916cdSFrançois Tigeot  * struct drm_dp_vcpi - Virtual Channel Payload Identifier
3324edb884SFrançois Tigeot  * @vcpi: Virtual channel ID.
3424edb884SFrançois Tigeot  * @pbn: Payload Bandwidth Number for this channel
3524edb884SFrançois Tigeot  * @aligned_pbn: PBN aligned with slot size
3624edb884SFrançois Tigeot  * @num_slots: number of slots for this PBN
3724edb884SFrançois Tigeot  */
3824edb884SFrançois Tigeot struct drm_dp_vcpi {
3924edb884SFrançois Tigeot 	int vcpi;
4024edb884SFrançois Tigeot 	int pbn;
4124edb884SFrançois Tigeot 	int aligned_pbn;
4224edb884SFrançois Tigeot 	int num_slots;
4324edb884SFrançois Tigeot };
4424edb884SFrançois Tigeot 
4524edb884SFrançois Tigeot /**
4624edb884SFrançois Tigeot  * struct drm_dp_mst_port - MST port
4724edb884SFrançois Tigeot  * @kref: reference count for this port.
4824edb884SFrançois Tigeot  * @port_num: port number
4924edb884SFrançois Tigeot  * @input: if this port is an input port.
5024edb884SFrançois Tigeot  * @mcs: message capability status - DP 1.2 spec.
5124edb884SFrançois Tigeot  * @ddps: DisplayPort Device Plug Status - DP 1.2
5224edb884SFrançois Tigeot  * @pdt: Peer Device Type
5324edb884SFrançois Tigeot  * @ldps: Legacy Device Plug Status
5424edb884SFrançois Tigeot  * @dpcd_rev: DPCD revision of device on this port
5524edb884SFrançois Tigeot  * @num_sdp_streams: Number of simultaneous streams
5624edb884SFrançois Tigeot  * @num_sdp_stream_sinks: Number of stream sinks
5724edb884SFrançois Tigeot  * @available_pbn: Available bandwidth for this port.
5824edb884SFrançois Tigeot  * @next: link to next port on this branch device
5924edb884SFrançois Tigeot  * @mstb: branch device attach below this port
6024edb884SFrançois Tigeot  * @aux: i2c aux transport to talk to device connected to this port.
6124edb884SFrançois Tigeot  * @parent: branch device parent of this port
6224edb884SFrançois Tigeot  * @vcpi: Virtual Channel Payload info for this port.
6324edb884SFrançois Tigeot  * @connector: DRM connector this port is connected to.
6424edb884SFrançois Tigeot  * @mgr: topology manager this port lives under.
6524edb884SFrançois Tigeot  *
6624edb884SFrançois Tigeot  * This structure represents an MST port endpoint on a device somewhere
6724edb884SFrançois Tigeot  * in the MST topology.
6824edb884SFrançois Tigeot  */
6924edb884SFrançois Tigeot struct drm_dp_mst_port {
7024edb884SFrançois Tigeot 	struct kref kref;
7124edb884SFrançois Tigeot 
7224edb884SFrançois Tigeot 	u8 port_num;
7324edb884SFrançois Tigeot 	bool input;
7424edb884SFrançois Tigeot 	bool mcs;
7524edb884SFrançois Tigeot 	bool ddps;
7624edb884SFrançois Tigeot 	u8 pdt;
7724edb884SFrançois Tigeot 	bool ldps;
7824edb884SFrançois Tigeot 	u8 dpcd_rev;
7924edb884SFrançois Tigeot 	u8 num_sdp_streams;
8024edb884SFrançois Tigeot 	u8 num_sdp_stream_sinks;
8124edb884SFrançois Tigeot 	uint16_t available_pbn;
8224edb884SFrançois Tigeot 	struct list_head next;
8324edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mstb; /* pointer to an mstb if this port has one */
8424edb884SFrançois Tigeot 	struct drm_dp_aux aux; /* i2c bus for this port? */
8524edb884SFrançois Tigeot 	struct drm_dp_mst_branch *parent;
8624edb884SFrançois Tigeot 
8724edb884SFrançois Tigeot 	struct drm_dp_vcpi vcpi;
8824edb884SFrançois Tigeot 	struct drm_connector *connector;
8924edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
902c9916cdSFrançois Tigeot 
911dedbd3bSFrançois Tigeot 	/**
921dedbd3bSFrançois Tigeot 	 * @cached_edid: for DP logical ports - make tiling work by ensuring
931dedbd3bSFrançois Tigeot 	 * that the EDID for all connectors is read immediately.
941dedbd3bSFrançois Tigeot 	 */
951dedbd3bSFrançois Tigeot 	struct edid *cached_edid;
961dedbd3bSFrançois Tigeot 	/**
971dedbd3bSFrançois Tigeot 	 * @has_audio: Tracks whether the sink connector to this port is
981dedbd3bSFrançois Tigeot 	 * audio-capable.
991dedbd3bSFrançois Tigeot 	 */
100aee94f86SFrançois Tigeot 	bool has_audio;
10124edb884SFrançois Tigeot };
10224edb884SFrançois Tigeot 
10324edb884SFrançois Tigeot /**
10424edb884SFrançois Tigeot  * struct drm_dp_mst_branch - MST branch device.
10524edb884SFrançois Tigeot  * @kref: reference count for this port.
10624edb884SFrançois Tigeot  * @rad: Relative Address to talk to this branch device.
10724edb884SFrançois Tigeot  * @lct: Link count total to talk to this branch device.
10824edb884SFrançois Tigeot  * @num_ports: number of ports on the branch.
10924edb884SFrançois Tigeot  * @msg_slots: one bit per transmitted msg slot.
11024edb884SFrançois Tigeot  * @ports: linked list of ports on this branch.
11124edb884SFrançois Tigeot  * @port_parent: pointer to the port parent, NULL if toplevel.
11224edb884SFrançois Tigeot  * @mgr: topology manager for this branch device.
11324edb884SFrançois Tigeot  * @tx_slots: transmission slots for this device.
11424edb884SFrançois Tigeot  * @last_seqno: last sequence number used to talk to this.
11524edb884SFrançois Tigeot  * @link_address_sent: if a link address message has been sent to this device yet.
116aee94f86SFrançois Tigeot  * @guid: guid for DP 1.2 branch device. port under this branch can be
117aee94f86SFrançois Tigeot  * identified by port #.
11824edb884SFrançois Tigeot  *
11924edb884SFrançois Tigeot  * This structure represents an MST branch device, there is one
120aee94f86SFrançois Tigeot  * primary branch device at the root, along with any other branches connected
121aee94f86SFrançois Tigeot  * to downstream port of parent branches.
12224edb884SFrançois Tigeot  */
12324edb884SFrançois Tigeot struct drm_dp_mst_branch {
12424edb884SFrançois Tigeot 	struct kref kref;
12524edb884SFrançois Tigeot 	u8 rad[8];
12624edb884SFrançois Tigeot 	u8 lct;
12724edb884SFrançois Tigeot 	int num_ports;
12824edb884SFrançois Tigeot 
12924edb884SFrançois Tigeot 	int msg_slots;
13024edb884SFrançois Tigeot 	struct list_head ports;
13124edb884SFrançois Tigeot 
13224edb884SFrançois Tigeot 	/* list of tx ops queue for this port */
13324edb884SFrançois Tigeot 	struct drm_dp_mst_port *port_parent;
13424edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
13524edb884SFrançois Tigeot 
13624edb884SFrançois Tigeot 	/* slots are protected by mstb->mgr->qlock */
13724edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_tx *tx_slots[2];
13824edb884SFrançois Tigeot 	int last_seqno;
13924edb884SFrançois Tigeot 	bool link_address_sent;
140aee94f86SFrançois Tigeot 
141aee94f86SFrançois Tigeot 	/* global unique identifier to identify branch devices */
142aee94f86SFrançois Tigeot 	u8 guid[16];
14324edb884SFrançois Tigeot };
14424edb884SFrançois Tigeot 
14524edb884SFrançois Tigeot 
14624edb884SFrançois Tigeot /* sideband msg header - not bit struct */
14724edb884SFrançois Tigeot struct drm_dp_sideband_msg_hdr {
14824edb884SFrançois Tigeot 	u8 lct;
14924edb884SFrançois Tigeot 	u8 lcr;
15024edb884SFrançois Tigeot 	u8 rad[8];
15124edb884SFrançois Tigeot 	bool broadcast;
15224edb884SFrançois Tigeot 	bool path_msg;
15324edb884SFrançois Tigeot 	u8 msg_len;
15424edb884SFrançois Tigeot 	bool somt;
15524edb884SFrançois Tigeot 	bool eomt;
15624edb884SFrançois Tigeot 	bool seqno;
15724edb884SFrançois Tigeot };
15824edb884SFrançois Tigeot 
15924edb884SFrançois Tigeot struct drm_dp_nak_reply {
16024edb884SFrançois Tigeot 	u8 guid[16];
16124edb884SFrançois Tigeot 	u8 reason;
16224edb884SFrançois Tigeot 	u8 nak_data;
16324edb884SFrançois Tigeot };
16424edb884SFrançois Tigeot 
16524edb884SFrançois Tigeot struct drm_dp_link_address_ack_reply {
16624edb884SFrançois Tigeot 	u8 guid[16];
16724edb884SFrançois Tigeot 	u8 nports;
16824edb884SFrançois Tigeot 	struct drm_dp_link_addr_reply_port {
16924edb884SFrançois Tigeot 		bool input_port;
17024edb884SFrançois Tigeot 		u8 peer_device_type;
17124edb884SFrançois Tigeot 		u8 port_number;
17224edb884SFrançois Tigeot 		bool mcs;
17324edb884SFrançois Tigeot 		bool ddps;
17424edb884SFrançois Tigeot 		bool legacy_device_plug_status;
17524edb884SFrançois Tigeot 		u8 dpcd_revision;
17624edb884SFrançois Tigeot 		u8 peer_guid[16];
17724edb884SFrançois Tigeot 		u8 num_sdp_streams;
17824edb884SFrançois Tigeot 		u8 num_sdp_stream_sinks;
17924edb884SFrançois Tigeot 	} ports[16];
18024edb884SFrançois Tigeot };
18124edb884SFrançois Tigeot 
18224edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read_ack_reply {
18324edb884SFrançois Tigeot 	u8 port_number;
18424edb884SFrançois Tigeot 	u8 num_bytes;
18524edb884SFrançois Tigeot 	u8 bytes[255];
18624edb884SFrançois Tigeot };
18724edb884SFrançois Tigeot 
18824edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_ack_reply {
18924edb884SFrançois Tigeot 	u8 port_number;
19024edb884SFrançois Tigeot };
19124edb884SFrançois Tigeot 
19224edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_nak_reply {
19324edb884SFrançois Tigeot 	u8 port_number;
19424edb884SFrançois Tigeot 	u8 reason;
19524edb884SFrançois Tigeot 	u8 bytes_written_before_failure;
19624edb884SFrançois Tigeot };
19724edb884SFrançois Tigeot 
19824edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_ack_reply {
19924edb884SFrançois Tigeot 	u8 port_number;
20024edb884SFrançois Tigeot 	u8 num_bytes;
20124edb884SFrançois Tigeot 	u8 bytes[255];
20224edb884SFrançois Tigeot };
20324edb884SFrançois Tigeot 
20424edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_nak_reply {
20524edb884SFrançois Tigeot 	u8 port_number;
20624edb884SFrançois Tigeot 	u8 nak_reason;
20724edb884SFrançois Tigeot 	u8 i2c_nak_transaction;
20824edb884SFrançois Tigeot };
20924edb884SFrançois Tigeot 
21024edb884SFrançois Tigeot struct drm_dp_remote_i2c_write_ack_reply {
21124edb884SFrançois Tigeot 	u8 port_number;
21224edb884SFrançois Tigeot };
21324edb884SFrançois Tigeot 
21424edb884SFrançois Tigeot 
21524edb884SFrançois Tigeot struct drm_dp_sideband_msg_rx {
21624edb884SFrançois Tigeot 	u8 chunk[48];
21724edb884SFrançois Tigeot 	u8 msg[256];
21824edb884SFrançois Tigeot 	u8 curchunk_len;
21924edb884SFrançois Tigeot 	u8 curchunk_idx; /* chunk we are parsing now */
22024edb884SFrançois Tigeot 	u8 curchunk_hdrlen;
22124edb884SFrançois Tigeot 	u8 curlen; /* total length of the msg */
22224edb884SFrançois Tigeot 	bool have_somt;
22324edb884SFrançois Tigeot 	bool have_eomt;
22424edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_hdr initial_hdr;
22524edb884SFrançois Tigeot };
22624edb884SFrançois Tigeot 
227aee94f86SFrançois Tigeot #define DRM_DP_MAX_SDP_STREAMS 16
22824edb884SFrançois Tigeot struct drm_dp_allocate_payload {
22924edb884SFrançois Tigeot 	u8 port_number;
23024edb884SFrançois Tigeot 	u8 number_sdp_streams;
23124edb884SFrançois Tigeot 	u8 vcpi;
23224edb884SFrançois Tigeot 	u16 pbn;
233aee94f86SFrançois Tigeot 	u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
23424edb884SFrançois Tigeot };
23524edb884SFrançois Tigeot 
23624edb884SFrançois Tigeot struct drm_dp_allocate_payload_ack_reply {
23724edb884SFrançois Tigeot 	u8 port_number;
23824edb884SFrançois Tigeot 	u8 vcpi;
23924edb884SFrançois Tigeot 	u16 allocated_pbn;
24024edb884SFrançois Tigeot };
24124edb884SFrançois Tigeot 
24224edb884SFrançois Tigeot struct drm_dp_connection_status_notify {
24324edb884SFrançois Tigeot 	u8 guid[16];
24424edb884SFrançois Tigeot 	u8 port_number;
24524edb884SFrançois Tigeot 	bool legacy_device_plug_status;
24624edb884SFrançois Tigeot 	bool displayport_device_plug_status;
24724edb884SFrançois Tigeot 	bool message_capability_status;
24824edb884SFrançois Tigeot 	bool input_port;
24924edb884SFrançois Tigeot 	u8 peer_device_type;
25024edb884SFrançois Tigeot };
25124edb884SFrançois Tigeot 
25224edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read {
25324edb884SFrançois Tigeot 	u8 port_number;
25424edb884SFrançois Tigeot 	u32 dpcd_address;
25524edb884SFrançois Tigeot 	u8 num_bytes;
25624edb884SFrançois Tigeot };
25724edb884SFrançois Tigeot 
25824edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write {
25924edb884SFrançois Tigeot 	u8 port_number;
26024edb884SFrançois Tigeot 	u32 dpcd_address;
26124edb884SFrançois Tigeot 	u8 num_bytes;
26224edb884SFrançois Tigeot 	u8 *bytes;
26324edb884SFrançois Tigeot };
26424edb884SFrançois Tigeot 
2650e1ba51bSFrançois Tigeot #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
26624edb884SFrançois Tigeot struct drm_dp_remote_i2c_read {
26724edb884SFrançois Tigeot 	u8 num_transactions;
26824edb884SFrançois Tigeot 	u8 port_number;
26924edb884SFrançois Tigeot 	struct {
27024edb884SFrançois Tigeot 		u8 i2c_dev_id;
27124edb884SFrançois Tigeot 		u8 num_bytes;
27224edb884SFrançois Tigeot 		u8 *bytes;
27324edb884SFrançois Tigeot 		u8 no_stop_bit;
27424edb884SFrançois Tigeot 		u8 i2c_transaction_delay;
2750e1ba51bSFrançois Tigeot 	} transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
27624edb884SFrançois Tigeot 	u8 read_i2c_device_id;
27724edb884SFrançois Tigeot 	u8 num_bytes_read;
27824edb884SFrançois Tigeot };
27924edb884SFrançois Tigeot 
28024edb884SFrançois Tigeot struct drm_dp_remote_i2c_write {
28124edb884SFrançois Tigeot 	u8 port_number;
28224edb884SFrançois Tigeot 	u8 write_i2c_device_id;
28324edb884SFrançois Tigeot 	u8 num_bytes;
28424edb884SFrançois Tigeot 	u8 *bytes;
28524edb884SFrançois Tigeot };
28624edb884SFrançois Tigeot 
28724edb884SFrançois Tigeot /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
28824edb884SFrançois Tigeot struct drm_dp_port_number_req {
28924edb884SFrançois Tigeot 	u8 port_number;
29024edb884SFrançois Tigeot };
29124edb884SFrançois Tigeot 
29224edb884SFrançois Tigeot struct drm_dp_enum_path_resources_ack_reply {
29324edb884SFrançois Tigeot 	u8 port_number;
29424edb884SFrançois Tigeot 	u16 full_payload_bw_number;
29524edb884SFrançois Tigeot 	u16 avail_payload_bw_number;
29624edb884SFrançois Tigeot };
29724edb884SFrançois Tigeot 
29824edb884SFrançois Tigeot /* covers POWER_DOWN_PHY, POWER_UP_PHY */
29924edb884SFrançois Tigeot struct drm_dp_port_number_rep {
30024edb884SFrançois Tigeot 	u8 port_number;
30124edb884SFrançois Tigeot };
30224edb884SFrançois Tigeot 
30324edb884SFrançois Tigeot struct drm_dp_query_payload {
30424edb884SFrançois Tigeot 	u8 port_number;
30524edb884SFrançois Tigeot 	u8 vcpi;
30624edb884SFrançois Tigeot };
30724edb884SFrançois Tigeot 
30824edb884SFrançois Tigeot struct drm_dp_resource_status_notify {
30924edb884SFrançois Tigeot 	u8 port_number;
31024edb884SFrançois Tigeot 	u8 guid[16];
31124edb884SFrançois Tigeot 	u16 available_pbn;
31224edb884SFrançois Tigeot };
31324edb884SFrançois Tigeot 
31424edb884SFrançois Tigeot struct drm_dp_query_payload_ack_reply {
31524edb884SFrançois Tigeot 	u8 port_number;
31624edb884SFrançois Tigeot 	u8 allocated_pbn;
31724edb884SFrançois Tigeot };
31824edb884SFrançois Tigeot 
31924edb884SFrançois Tigeot struct drm_dp_sideband_msg_req_body {
32024edb884SFrançois Tigeot 	u8 req_type;
32124edb884SFrançois Tigeot 	union ack_req {
32224edb884SFrançois Tigeot 		struct drm_dp_connection_status_notify conn_stat;
32324edb884SFrançois Tigeot 		struct drm_dp_port_number_req port_num;
32424edb884SFrançois Tigeot 		struct drm_dp_resource_status_notify resource_stat;
32524edb884SFrançois Tigeot 
32624edb884SFrançois Tigeot 		struct drm_dp_query_payload query_payload;
32724edb884SFrançois Tigeot 		struct drm_dp_allocate_payload allocate_payload;
32824edb884SFrançois Tigeot 
32924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read dpcd_read;
33024edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write dpcd_write;
33124edb884SFrançois Tigeot 
33224edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read i2c_read;
33324edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write i2c_write;
33424edb884SFrançois Tigeot 	} u;
33524edb884SFrançois Tigeot };
33624edb884SFrançois Tigeot 
33724edb884SFrançois Tigeot struct drm_dp_sideband_msg_reply_body {
33824edb884SFrançois Tigeot 	u8 reply_type;
33924edb884SFrançois Tigeot 	u8 req_type;
34024edb884SFrançois Tigeot 	union ack_replies {
34124edb884SFrançois Tigeot 		struct drm_dp_nak_reply nak;
34224edb884SFrançois Tigeot 		struct drm_dp_link_address_ack_reply link_addr;
34324edb884SFrançois Tigeot 		struct drm_dp_port_number_rep port_number;
34424edb884SFrançois Tigeot 
34524edb884SFrançois Tigeot 		struct drm_dp_enum_path_resources_ack_reply path_resources;
34624edb884SFrançois Tigeot 		struct drm_dp_allocate_payload_ack_reply allocate_payload;
34724edb884SFrançois Tigeot 		struct drm_dp_query_payload_ack_reply query_payload;
34824edb884SFrançois Tigeot 
34924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
35024edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
35124edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
35224edb884SFrançois Tigeot 
35324edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
35424edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
35524edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
35624edb884SFrançois Tigeot 	} u;
35724edb884SFrançois Tigeot };
35824edb884SFrançois Tigeot 
35924edb884SFrançois Tigeot /* msg is queued to be put into a slot */
36024edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_QUEUED 0
36124edb884SFrançois Tigeot /* msg has started transmitting on a slot - still on msgq */
36224edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_START_SEND 1
36324edb884SFrançois Tigeot /* msg has finished transmitting on a slot - removed from msgq only in slot */
36424edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_SENT 2
36524edb884SFrançois Tigeot /* msg has received a response - removed from slot */
36624edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_RX 3
36724edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
36824edb884SFrançois Tigeot 
36924edb884SFrançois Tigeot struct drm_dp_sideband_msg_tx {
37024edb884SFrançois Tigeot 	u8 msg[256];
37124edb884SFrançois Tigeot 	u8 chunk[48];
37224edb884SFrançois Tigeot 	u8 cur_offset;
37324edb884SFrançois Tigeot 	u8 cur_len;
37424edb884SFrançois Tigeot 	struct drm_dp_mst_branch *dst;
37524edb884SFrançois Tigeot 	struct list_head next;
37624edb884SFrançois Tigeot 	int seqno;
37724edb884SFrançois Tigeot 	int state;
37824edb884SFrançois Tigeot 	bool path_msg;
37924edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_reply_body reply;
38024edb884SFrançois Tigeot };
38124edb884SFrançois Tigeot 
38224edb884SFrançois Tigeot /* sideband msg handler */
38324edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr;
38424edb884SFrançois Tigeot struct drm_dp_mst_topology_cbs {
38524edb884SFrançois Tigeot 	/* create a connector for a port */
3862c9916cdSFrançois Tigeot 	struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
3870e1ba51bSFrançois Tigeot 	void (*register_connector)(struct drm_connector *connector);
38824edb884SFrançois Tigeot 	void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
38924edb884SFrançois Tigeot 				  struct drm_connector *connector);
39024edb884SFrançois Tigeot 	void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
39124edb884SFrançois Tigeot 
39224edb884SFrançois Tigeot };
39324edb884SFrançois Tigeot 
39424edb884SFrançois Tigeot #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
39524edb884SFrançois Tigeot 
39624edb884SFrançois Tigeot #define DP_PAYLOAD_LOCAL 1
39724edb884SFrançois Tigeot #define DP_PAYLOAD_REMOTE 2
39824edb884SFrançois Tigeot #define DP_PAYLOAD_DELETE_LOCAL 3
39924edb884SFrançois Tigeot 
40024edb884SFrançois Tigeot struct drm_dp_payload {
40124edb884SFrançois Tigeot 	int payload_state;
40224edb884SFrançois Tigeot 	int start_slot;
40324edb884SFrançois Tigeot 	int num_slots;
4042c9916cdSFrançois Tigeot 	int vcpi;
40524edb884SFrançois Tigeot };
40624edb884SFrançois Tigeot 
407*3f2dd94aSFrançois Tigeot #define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
408*3f2dd94aSFrançois Tigeot 
409*3f2dd94aSFrançois Tigeot struct drm_dp_mst_topology_state {
410*3f2dd94aSFrançois Tigeot 	struct drm_private_state base;
411*3f2dd94aSFrançois Tigeot 	int avail_slots;
412*3f2dd94aSFrançois Tigeot 	struct drm_atomic_state *state;
413*3f2dd94aSFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
414*3f2dd94aSFrançois Tigeot };
415*3f2dd94aSFrançois Tigeot 
416*3f2dd94aSFrançois Tigeot #define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
417*3f2dd94aSFrançois Tigeot 
41824edb884SFrançois Tigeot /**
41924edb884SFrançois Tigeot  * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
42024edb884SFrançois Tigeot  *
42124edb884SFrançois Tigeot  * This struct represents the toplevel displayport MST topology manager.
42224edb884SFrançois Tigeot  * There should be one instance of this for every MST capable DP connector
42324edb884SFrançois Tigeot  * on the GPU.
42424edb884SFrançois Tigeot  */
42524edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr {
4261dedbd3bSFrançois Tigeot 	/**
427*3f2dd94aSFrançois Tigeot 	 * @base: Base private object for atomic
428*3f2dd94aSFrançois Tigeot 	 */
429*3f2dd94aSFrançois Tigeot 	struct drm_private_obj base;
430*3f2dd94aSFrançois Tigeot 
431*3f2dd94aSFrançois Tigeot 	/**
4321dedbd3bSFrançois Tigeot 	 * @dev: device pointer for adding i2c devices etc.
4331dedbd3bSFrançois Tigeot 	 */
434a85cb24fSFrançois Tigeot 	struct drm_device *dev;
4351dedbd3bSFrançois Tigeot 	/**
4361dedbd3bSFrançois Tigeot 	 * @cbs: callbacks for connector addition and destruction.
4371dedbd3bSFrançois Tigeot 	 */
438aee94f86SFrançois Tigeot 	const struct drm_dp_mst_topology_cbs *cbs;
4391dedbd3bSFrançois Tigeot 	/**
4401dedbd3bSFrançois Tigeot 	 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
4411dedbd3bSFrançois Tigeot 	 * in one go.
4421dedbd3bSFrançois Tigeot 	 */
44324edb884SFrançois Tigeot 	int max_dpcd_transaction_bytes;
4441dedbd3bSFrançois Tigeot 	/**
4451dedbd3bSFrançois Tigeot 	 * @aux: AUX channel for the DP MST connector this topolgy mgr is
4461dedbd3bSFrançois Tigeot 	 * controlling.
4471dedbd3bSFrançois Tigeot 	 */
4481dedbd3bSFrançois Tigeot 	struct drm_dp_aux *aux;
4491dedbd3bSFrançois Tigeot 	/**
4501dedbd3bSFrançois Tigeot 	 * @max_payloads: maximum number of payloads the GPU can generate.
4511dedbd3bSFrançois Tigeot 	 */
45224edb884SFrançois Tigeot 	int max_payloads;
4531dedbd3bSFrançois Tigeot 	/**
4541dedbd3bSFrançois Tigeot 	 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
4551dedbd3bSFrançois Tigeot 	 * to build the MST connector path value.
4561dedbd3bSFrançois Tigeot 	 */
45724edb884SFrançois Tigeot 	int conn_base_id;
45824edb884SFrançois Tigeot 
4591dedbd3bSFrançois Tigeot 	/**
4601dedbd3bSFrançois Tigeot 	 * @down_rep_recv: Message receiver state for down replies. This and
4611dedbd3bSFrançois Tigeot 	 * @up_req_recv are only ever access from the work item, which is
4621dedbd3bSFrançois Tigeot 	 * serialised.
4631dedbd3bSFrançois Tigeot 	 */
46424edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx down_rep_recv;
4651dedbd3bSFrançois Tigeot 	/**
4661dedbd3bSFrançois Tigeot 	 * @up_req_recv: Message receiver state for up requests. This and
4671dedbd3bSFrançois Tigeot 	 * @down_rep_recv are only ever access from the work item, which is
4681dedbd3bSFrançois Tigeot 	 * serialised.
4691dedbd3bSFrançois Tigeot 	 */
47024edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx up_req_recv;
47124edb884SFrançois Tigeot 
4721dedbd3bSFrançois Tigeot 	/**
4731dedbd3bSFrançois Tigeot 	 * @lock: protects mst state, primary, dpcd.
4741dedbd3bSFrançois Tigeot 	 */
4751dedbd3bSFrançois Tigeot 	struct lock lock;
47624edb884SFrançois Tigeot 
4771dedbd3bSFrançois Tigeot 	/**
4781dedbd3bSFrançois Tigeot 	 * @mst_state: If this manager is enabled for an MST capable port. False
4791dedbd3bSFrançois Tigeot 	 * if no MST sink/branch devices is connected.
4801dedbd3bSFrançois Tigeot 	 */
48124edb884SFrançois Tigeot 	bool mst_state;
4821dedbd3bSFrançois Tigeot 	/**
4831dedbd3bSFrançois Tigeot 	 * @mst_primary: Pointer to the primary/first branch device.
4841dedbd3bSFrançois Tigeot 	 */
48524edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mst_primary;
486aee94f86SFrançois Tigeot 
4871dedbd3bSFrançois Tigeot 	/**
4881dedbd3bSFrançois Tigeot 	 * @dpcd: Cache of DPCD for primary port.
4891dedbd3bSFrançois Tigeot 	 */
49024edb884SFrançois Tigeot 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
4911dedbd3bSFrançois Tigeot 	/**
4921dedbd3bSFrançois Tigeot 	 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
4931dedbd3bSFrançois Tigeot 	 */
49424edb884SFrançois Tigeot 	u8 sink_count;
4951dedbd3bSFrançois Tigeot 	/**
4961dedbd3bSFrançois Tigeot 	 * @pbn_div: PBN to slots divisor.
4971dedbd3bSFrançois Tigeot 	 */
49824edb884SFrançois Tigeot 	int pbn_div;
49924edb884SFrançois Tigeot 
5001dedbd3bSFrançois Tigeot 	/**
501*3f2dd94aSFrançois Tigeot 	 * @state: State information for topology manager
502*3f2dd94aSFrançois Tigeot 	 */
503*3f2dd94aSFrançois Tigeot 	struct drm_dp_mst_topology_state *state;
504*3f2dd94aSFrançois Tigeot 
505*3f2dd94aSFrançois Tigeot 	/**
506*3f2dd94aSFrançois Tigeot 	 * @funcs: Atomic helper callbacks
507*3f2dd94aSFrançois Tigeot 	 */
508*3f2dd94aSFrançois Tigeot 	const struct drm_private_state_funcs *funcs;
509*3f2dd94aSFrançois Tigeot 
510*3f2dd94aSFrançois Tigeot 	/**
511a85cb24fSFrançois Tigeot 	 * @qlock: protects @tx_msg_downq, the &drm_dp_mst_branch.txslost and
512a85cb24fSFrançois Tigeot 	 * &drm_dp_sideband_msg_tx.state once they are queued
5131dedbd3bSFrançois Tigeot 	 */
51424edb884SFrançois Tigeot 	struct lock qlock;
5151dedbd3bSFrançois Tigeot 	/**
5161dedbd3bSFrançois Tigeot 	 * @tx_msg_downq: List of pending down replies.
5171dedbd3bSFrançois Tigeot 	 */
51824edb884SFrançois Tigeot 	struct list_head tx_msg_downq;
51924edb884SFrançois Tigeot 
5201dedbd3bSFrançois Tigeot 	/**
5211dedbd3bSFrançois Tigeot 	 * @payload_lock: Protect payload information.
5221dedbd3bSFrançois Tigeot 	 */
52324edb884SFrançois Tigeot 	struct lock payload_lock;
5241dedbd3bSFrançois Tigeot 	/**
5251dedbd3bSFrançois Tigeot 	 * @proposed_vcpis: Array of pointers for the new VCPI allocation. The
526a85cb24fSFrançois Tigeot 	 * VCPI structure itself is &drm_dp_mst_port.vcpi.
5271dedbd3bSFrançois Tigeot 	 */
52824edb884SFrançois Tigeot 	struct drm_dp_vcpi **proposed_vcpis;
5291dedbd3bSFrançois Tigeot 	/**
5301dedbd3bSFrançois Tigeot 	 * @payloads: Array of payloads.
5311dedbd3bSFrançois Tigeot 	 */
53224edb884SFrançois Tigeot 	struct drm_dp_payload *payloads;
5331dedbd3bSFrançois Tigeot 	/**
5341dedbd3bSFrançois Tigeot 	 * @payload_mask: Elements of @payloads actually in use. Since
5351dedbd3bSFrançois Tigeot 	 * reallocation of active outputs isn't possible gaps can be created by
5361dedbd3bSFrançois Tigeot 	 * disabling outputs out of order compared to how they've been enabled.
5371dedbd3bSFrançois Tigeot 	 */
53824edb884SFrançois Tigeot 	unsigned long payload_mask;
5391dedbd3bSFrançois Tigeot 	/**
5401dedbd3bSFrançois Tigeot 	 * @vcpi_mask: Similar to @payload_mask, but for @proposed_vcpis.
5411dedbd3bSFrançois Tigeot 	 */
5422c9916cdSFrançois Tigeot 	unsigned long vcpi_mask;
54324edb884SFrançois Tigeot 
5441dedbd3bSFrançois Tigeot 	/**
5451dedbd3bSFrançois Tigeot 	 * @tx_waitq: Wait to queue stall for the tx worker.
5461dedbd3bSFrançois Tigeot 	 */
54724edb884SFrançois Tigeot 	wait_queue_head_t tx_waitq;
5481dedbd3bSFrançois Tigeot 	/**
5491dedbd3bSFrançois Tigeot 	 * @work: Probe work.
5501dedbd3bSFrançois Tigeot 	 */
55124edb884SFrançois Tigeot 	struct work_struct work;
5521dedbd3bSFrançois Tigeot 	/**
5531dedbd3bSFrançois Tigeot 	 * @tx_work: Sideband transmit worker. This can nest within the main
5541dedbd3bSFrançois Tigeot 	 * @work worker for each transaction @work launches.
5551dedbd3bSFrançois Tigeot 	 */
55624edb884SFrançois Tigeot 	struct work_struct tx_work;
5570e1ba51bSFrançois Tigeot 
5581dedbd3bSFrançois Tigeot 	/**
5591dedbd3bSFrançois Tigeot 	 * @destroy_connector_list: List of to be destroyed connectors.
5601dedbd3bSFrançois Tigeot 	 */
5610e1ba51bSFrançois Tigeot 	struct list_head destroy_connector_list;
5621dedbd3bSFrançois Tigeot 	/**
5631dedbd3bSFrançois Tigeot 	 * @destroy_connector_lock: Protects @connector_list.
5641dedbd3bSFrançois Tigeot 	 */
5650e1ba51bSFrançois Tigeot 	struct lock destroy_connector_lock;
5661dedbd3bSFrançois Tigeot 	/**
5671dedbd3bSFrançois Tigeot 	 * @destroy_connector_work: Work item to destroy connectors. Needed to
5681dedbd3bSFrançois Tigeot 	 * avoid locking inversion.
5691dedbd3bSFrançois Tigeot 	 */
5700e1ba51bSFrançois Tigeot 	struct work_struct destroy_connector_work;
57124edb884SFrançois Tigeot };
57224edb884SFrançois Tigeot 
573a85cb24fSFrançois Tigeot int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
574a85cb24fSFrançois Tigeot 				 struct drm_device *dev, struct drm_dp_aux *aux,
575a85cb24fSFrançois Tigeot 				 int max_dpcd_transaction_bytes,
576a85cb24fSFrançois Tigeot 				 int max_payloads, int conn_base_id);
57724edb884SFrançois Tigeot 
57824edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
57924edb884SFrançois Tigeot 
58024edb884SFrançois Tigeot 
58124edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
58224edb884SFrançois Tigeot 
58324edb884SFrançois Tigeot 
58424edb884SFrançois Tigeot int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
58524edb884SFrançois Tigeot 
58624edb884SFrançois Tigeot 
5872c9916cdSFrançois Tigeot enum drm_connector_status drm_dp_mst_detect_port(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
58824edb884SFrançois Tigeot 
589aee94f86SFrançois Tigeot bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
590aee94f86SFrançois Tigeot 					struct drm_dp_mst_port *port);
59124edb884SFrançois Tigeot struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
59224edb884SFrançois Tigeot 
59324edb884SFrançois Tigeot 
59424edb884SFrançois Tigeot int drm_dp_calc_pbn_mode(int clock, int bpp);
59524edb884SFrançois Tigeot 
59624edb884SFrançois Tigeot 
597a85cb24fSFrançois Tigeot bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
598a85cb24fSFrançois Tigeot 			      struct drm_dp_mst_port *port, int pbn, int slots);
59924edb884SFrançois Tigeot 
600477eb7f9SFrançois Tigeot int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
601477eb7f9SFrançois Tigeot 
60224edb884SFrançois Tigeot 
60324edb884SFrançois Tigeot void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
60424edb884SFrançois Tigeot 
60524edb884SFrançois Tigeot 
60624edb884SFrançois Tigeot void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
60724edb884SFrançois Tigeot 				struct drm_dp_mst_port *port);
60824edb884SFrançois Tigeot 
60924edb884SFrançois Tigeot 
61024edb884SFrançois Tigeot int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
61124edb884SFrançois Tigeot 			   int pbn);
61224edb884SFrançois Tigeot 
61324edb884SFrançois Tigeot 
61424edb884SFrançois Tigeot int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
61524edb884SFrançois Tigeot 
61624edb884SFrançois Tigeot 
61724edb884SFrançois Tigeot int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
61824edb884SFrançois Tigeot 
61924edb884SFrançois Tigeot int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
62024edb884SFrançois Tigeot 
62124edb884SFrançois Tigeot void drm_dp_mst_dump_topology(struct seq_file *m,
62224edb884SFrançois Tigeot 			      struct drm_dp_mst_topology_mgr *mgr);
62324edb884SFrançois Tigeot 
62424edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
62524edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
626*3f2dd94aSFrançois Tigeot struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
627*3f2dd94aSFrançois Tigeot 								    struct drm_dp_mst_topology_mgr *mgr);
628*3f2dd94aSFrançois Tigeot int drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
629*3f2dd94aSFrançois Tigeot 				  struct drm_dp_mst_topology_mgr *mgr,
630*3f2dd94aSFrançois Tigeot 				  struct drm_dp_mst_port *port, int pbn);
631*3f2dd94aSFrançois Tigeot int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
632*3f2dd94aSFrançois Tigeot 				     struct drm_dp_mst_topology_mgr *mgr,
633*3f2dd94aSFrançois Tigeot 				     int slots);
634*3f2dd94aSFrançois Tigeot int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
635*3f2dd94aSFrançois Tigeot 				 struct drm_dp_mst_port *port, bool power_up);
636*3f2dd94aSFrançois Tigeot 
63724edb884SFrançois Tigeot #endif
638