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>
2724edb884SFrançois Tigeot 
2824edb884SFrançois Tigeot struct drm_dp_mst_branch;
2924edb884SFrançois Tigeot 
3024edb884SFrançois Tigeot /**
312c9916cdSFrançois Tigeot  * struct drm_dp_vcpi - Virtual Channel Payload Identifier
3224edb884SFrançois Tigeot  * @vcpi: Virtual channel ID.
3324edb884SFrançois Tigeot  * @pbn: Payload Bandwidth Number for this channel
3424edb884SFrançois Tigeot  * @aligned_pbn: PBN aligned with slot size
3524edb884SFrançois Tigeot  * @num_slots: number of slots for this PBN
3624edb884SFrançois Tigeot  */
3724edb884SFrançois Tigeot struct drm_dp_vcpi {
3824edb884SFrançois Tigeot 	int vcpi;
3924edb884SFrançois Tigeot 	int pbn;
4024edb884SFrançois Tigeot 	int aligned_pbn;
4124edb884SFrançois Tigeot 	int num_slots;
4224edb884SFrançois Tigeot };
4324edb884SFrançois Tigeot 
4424edb884SFrançois Tigeot /**
4524edb884SFrançois Tigeot  * struct drm_dp_mst_port - MST port
4624edb884SFrançois Tigeot  * @kref: reference count for this port.
4724edb884SFrançois Tigeot  * @port_num: port number
4824edb884SFrançois Tigeot  * @input: if this port is an input port.
4924edb884SFrançois Tigeot  * @mcs: message capability status - DP 1.2 spec.
5024edb884SFrançois Tigeot  * @ddps: DisplayPort Device Plug Status - DP 1.2
5124edb884SFrançois Tigeot  * @pdt: Peer Device Type
5224edb884SFrançois Tigeot  * @ldps: Legacy Device Plug Status
5324edb884SFrançois Tigeot  * @dpcd_rev: DPCD revision of device on this port
5424edb884SFrançois Tigeot  * @num_sdp_streams: Number of simultaneous streams
5524edb884SFrançois Tigeot  * @num_sdp_stream_sinks: Number of stream sinks
5624edb884SFrançois Tigeot  * @available_pbn: Available bandwidth for this port.
5724edb884SFrançois Tigeot  * @next: link to next port on this branch device
5824edb884SFrançois Tigeot  * @mstb: branch device attach below this port
5924edb884SFrançois Tigeot  * @aux: i2c aux transport to talk to device connected to this port.
6024edb884SFrançois Tigeot  * @parent: branch device parent of this port
6124edb884SFrançois Tigeot  * @vcpi: Virtual Channel Payload info for this port.
6224edb884SFrançois Tigeot  * @connector: DRM connector this port is connected to.
6324edb884SFrançois Tigeot  * @mgr: topology manager this port lives under.
6424edb884SFrançois Tigeot  *
6524edb884SFrançois Tigeot  * This structure represents an MST port endpoint on a device somewhere
6624edb884SFrançois Tigeot  * in the MST topology.
6724edb884SFrançois Tigeot  */
6824edb884SFrançois Tigeot struct drm_dp_mst_port {
6924edb884SFrançois Tigeot 	struct kref kref;
7024edb884SFrançois Tigeot 
7124edb884SFrançois Tigeot 	u8 port_num;
7224edb884SFrançois Tigeot 	bool input;
7324edb884SFrançois Tigeot 	bool mcs;
7424edb884SFrançois Tigeot 	bool ddps;
7524edb884SFrançois Tigeot 	u8 pdt;
7624edb884SFrançois Tigeot 	bool ldps;
7724edb884SFrançois Tigeot 	u8 dpcd_rev;
7824edb884SFrançois Tigeot 	u8 num_sdp_streams;
7924edb884SFrançois Tigeot 	u8 num_sdp_stream_sinks;
8024edb884SFrançois Tigeot 	uint16_t available_pbn;
8124edb884SFrançois Tigeot 	struct list_head next;
8224edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mstb; /* pointer to an mstb if this port has one */
8324edb884SFrançois Tigeot 	struct drm_dp_aux aux; /* i2c bus for this port? */
8424edb884SFrançois Tigeot 	struct drm_dp_mst_branch *parent;
8524edb884SFrançois Tigeot 
8624edb884SFrançois Tigeot 	struct drm_dp_vcpi vcpi;
8724edb884SFrançois Tigeot 	struct drm_connector *connector;
8824edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
892c9916cdSFrançois Tigeot 
90*1dedbd3bSFrançois Tigeot 	/**
91*1dedbd3bSFrançois Tigeot 	 * @cached_edid: for DP logical ports - make tiling work by ensuring
92*1dedbd3bSFrançois Tigeot 	 * that the EDID for all connectors is read immediately.
93*1dedbd3bSFrançois Tigeot 	 */
94*1dedbd3bSFrançois Tigeot 	struct edid *cached_edid;
95*1dedbd3bSFrançois Tigeot 	/**
96*1dedbd3bSFrançois Tigeot 	 * @has_audio: Tracks whether the sink connector to this port is
97*1dedbd3bSFrançois Tigeot 	 * audio-capable.
98*1dedbd3bSFrançois Tigeot 	 */
99aee94f86SFrançois Tigeot 	bool has_audio;
10024edb884SFrançois Tigeot };
10124edb884SFrançois Tigeot 
10224edb884SFrançois Tigeot /**
10324edb884SFrançois Tigeot  * struct drm_dp_mst_branch - MST branch device.
10424edb884SFrançois Tigeot  * @kref: reference count for this port.
10524edb884SFrançois Tigeot  * @rad: Relative Address to talk to this branch device.
10624edb884SFrançois Tigeot  * @lct: Link count total to talk to this branch device.
10724edb884SFrançois Tigeot  * @num_ports: number of ports on the branch.
10824edb884SFrançois Tigeot  * @msg_slots: one bit per transmitted msg slot.
10924edb884SFrançois Tigeot  * @ports: linked list of ports on this branch.
11024edb884SFrançois Tigeot  * @port_parent: pointer to the port parent, NULL if toplevel.
11124edb884SFrançois Tigeot  * @mgr: topology manager for this branch device.
11224edb884SFrançois Tigeot  * @tx_slots: transmission slots for this device.
11324edb884SFrançois Tigeot  * @last_seqno: last sequence number used to talk to this.
11424edb884SFrançois Tigeot  * @link_address_sent: if a link address message has been sent to this device yet.
115aee94f86SFrançois Tigeot  * @guid: guid for DP 1.2 branch device. port under this branch can be
116aee94f86SFrançois Tigeot  * identified by port #.
11724edb884SFrançois Tigeot  *
11824edb884SFrançois Tigeot  * This structure represents an MST branch device, there is one
119aee94f86SFrançois Tigeot  * primary branch device at the root, along with any other branches connected
120aee94f86SFrançois Tigeot  * to downstream port of parent branches.
12124edb884SFrançois Tigeot  */
12224edb884SFrançois Tigeot struct drm_dp_mst_branch {
12324edb884SFrançois Tigeot 	struct kref kref;
12424edb884SFrançois Tigeot 	u8 rad[8];
12524edb884SFrançois Tigeot 	u8 lct;
12624edb884SFrançois Tigeot 	int num_ports;
12724edb884SFrançois Tigeot 
12824edb884SFrançois Tigeot 	int msg_slots;
12924edb884SFrançois Tigeot 	struct list_head ports;
13024edb884SFrançois Tigeot 
13124edb884SFrançois Tigeot 	/* list of tx ops queue for this port */
13224edb884SFrançois Tigeot 	struct drm_dp_mst_port *port_parent;
13324edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
13424edb884SFrançois Tigeot 
13524edb884SFrançois Tigeot 	/* slots are protected by mstb->mgr->qlock */
13624edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_tx *tx_slots[2];
13724edb884SFrançois Tigeot 	int last_seqno;
13824edb884SFrançois Tigeot 	bool link_address_sent;
139aee94f86SFrançois Tigeot 
140aee94f86SFrançois Tigeot 	/* global unique identifier to identify branch devices */
141aee94f86SFrançois Tigeot 	u8 guid[16];
14224edb884SFrançois Tigeot };
14324edb884SFrançois Tigeot 
14424edb884SFrançois Tigeot 
14524edb884SFrançois Tigeot /* sideband msg header - not bit struct */
14624edb884SFrançois Tigeot struct drm_dp_sideband_msg_hdr {
14724edb884SFrançois Tigeot 	u8 lct;
14824edb884SFrançois Tigeot 	u8 lcr;
14924edb884SFrançois Tigeot 	u8 rad[8];
15024edb884SFrançois Tigeot 	bool broadcast;
15124edb884SFrançois Tigeot 	bool path_msg;
15224edb884SFrançois Tigeot 	u8 msg_len;
15324edb884SFrançois Tigeot 	bool somt;
15424edb884SFrançois Tigeot 	bool eomt;
15524edb884SFrançois Tigeot 	bool seqno;
15624edb884SFrançois Tigeot };
15724edb884SFrançois Tigeot 
15824edb884SFrançois Tigeot struct drm_dp_nak_reply {
15924edb884SFrançois Tigeot 	u8 guid[16];
16024edb884SFrançois Tigeot 	u8 reason;
16124edb884SFrançois Tigeot 	u8 nak_data;
16224edb884SFrançois Tigeot };
16324edb884SFrançois Tigeot 
16424edb884SFrançois Tigeot struct drm_dp_link_address_ack_reply {
16524edb884SFrançois Tigeot 	u8 guid[16];
16624edb884SFrançois Tigeot 	u8 nports;
16724edb884SFrançois Tigeot 	struct drm_dp_link_addr_reply_port {
16824edb884SFrançois Tigeot 		bool input_port;
16924edb884SFrançois Tigeot 		u8 peer_device_type;
17024edb884SFrançois Tigeot 		u8 port_number;
17124edb884SFrançois Tigeot 		bool mcs;
17224edb884SFrançois Tigeot 		bool ddps;
17324edb884SFrançois Tigeot 		bool legacy_device_plug_status;
17424edb884SFrançois Tigeot 		u8 dpcd_revision;
17524edb884SFrançois Tigeot 		u8 peer_guid[16];
17624edb884SFrançois Tigeot 		u8 num_sdp_streams;
17724edb884SFrançois Tigeot 		u8 num_sdp_stream_sinks;
17824edb884SFrançois Tigeot 	} ports[16];
17924edb884SFrançois Tigeot };
18024edb884SFrançois Tigeot 
18124edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read_ack_reply {
18224edb884SFrançois Tigeot 	u8 port_number;
18324edb884SFrançois Tigeot 	u8 num_bytes;
18424edb884SFrançois Tigeot 	u8 bytes[255];
18524edb884SFrançois Tigeot };
18624edb884SFrançois Tigeot 
18724edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_ack_reply {
18824edb884SFrançois Tigeot 	u8 port_number;
18924edb884SFrançois Tigeot };
19024edb884SFrançois Tigeot 
19124edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_nak_reply {
19224edb884SFrançois Tigeot 	u8 port_number;
19324edb884SFrançois Tigeot 	u8 reason;
19424edb884SFrançois Tigeot 	u8 bytes_written_before_failure;
19524edb884SFrançois Tigeot };
19624edb884SFrançois Tigeot 
19724edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_ack_reply {
19824edb884SFrançois Tigeot 	u8 port_number;
19924edb884SFrançois Tigeot 	u8 num_bytes;
20024edb884SFrançois Tigeot 	u8 bytes[255];
20124edb884SFrançois Tigeot };
20224edb884SFrançois Tigeot 
20324edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_nak_reply {
20424edb884SFrançois Tigeot 	u8 port_number;
20524edb884SFrançois Tigeot 	u8 nak_reason;
20624edb884SFrançois Tigeot 	u8 i2c_nak_transaction;
20724edb884SFrançois Tigeot };
20824edb884SFrançois Tigeot 
20924edb884SFrançois Tigeot struct drm_dp_remote_i2c_write_ack_reply {
21024edb884SFrançois Tigeot 	u8 port_number;
21124edb884SFrançois Tigeot };
21224edb884SFrançois Tigeot 
21324edb884SFrançois Tigeot 
21424edb884SFrançois Tigeot struct drm_dp_sideband_msg_rx {
21524edb884SFrançois Tigeot 	u8 chunk[48];
21624edb884SFrançois Tigeot 	u8 msg[256];
21724edb884SFrançois Tigeot 	u8 curchunk_len;
21824edb884SFrançois Tigeot 	u8 curchunk_idx; /* chunk we are parsing now */
21924edb884SFrançois Tigeot 	u8 curchunk_hdrlen;
22024edb884SFrançois Tigeot 	u8 curlen; /* total length of the msg */
22124edb884SFrançois Tigeot 	bool have_somt;
22224edb884SFrançois Tigeot 	bool have_eomt;
22324edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_hdr initial_hdr;
22424edb884SFrançois Tigeot };
22524edb884SFrançois Tigeot 
226aee94f86SFrançois Tigeot #define DRM_DP_MAX_SDP_STREAMS 16
22724edb884SFrançois Tigeot struct drm_dp_allocate_payload {
22824edb884SFrançois Tigeot 	u8 port_number;
22924edb884SFrançois Tigeot 	u8 number_sdp_streams;
23024edb884SFrançois Tigeot 	u8 vcpi;
23124edb884SFrançois Tigeot 	u16 pbn;
232aee94f86SFrançois Tigeot 	u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
23324edb884SFrançois Tigeot };
23424edb884SFrançois Tigeot 
23524edb884SFrançois Tigeot struct drm_dp_allocate_payload_ack_reply {
23624edb884SFrançois Tigeot 	u8 port_number;
23724edb884SFrançois Tigeot 	u8 vcpi;
23824edb884SFrançois Tigeot 	u16 allocated_pbn;
23924edb884SFrançois Tigeot };
24024edb884SFrançois Tigeot 
24124edb884SFrançois Tigeot struct drm_dp_connection_status_notify {
24224edb884SFrançois Tigeot 	u8 guid[16];
24324edb884SFrançois Tigeot 	u8 port_number;
24424edb884SFrançois Tigeot 	bool legacy_device_plug_status;
24524edb884SFrançois Tigeot 	bool displayport_device_plug_status;
24624edb884SFrançois Tigeot 	bool message_capability_status;
24724edb884SFrançois Tigeot 	bool input_port;
24824edb884SFrançois Tigeot 	u8 peer_device_type;
24924edb884SFrançois Tigeot };
25024edb884SFrançois Tigeot 
25124edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read {
25224edb884SFrançois Tigeot 	u8 port_number;
25324edb884SFrançois Tigeot 	u32 dpcd_address;
25424edb884SFrançois Tigeot 	u8 num_bytes;
25524edb884SFrançois Tigeot };
25624edb884SFrançois Tigeot 
25724edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write {
25824edb884SFrançois Tigeot 	u8 port_number;
25924edb884SFrançois Tigeot 	u32 dpcd_address;
26024edb884SFrançois Tigeot 	u8 num_bytes;
26124edb884SFrançois Tigeot 	u8 *bytes;
26224edb884SFrançois Tigeot };
26324edb884SFrançois Tigeot 
2640e1ba51bSFrançois Tigeot #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
26524edb884SFrançois Tigeot struct drm_dp_remote_i2c_read {
26624edb884SFrançois Tigeot 	u8 num_transactions;
26724edb884SFrançois Tigeot 	u8 port_number;
26824edb884SFrançois Tigeot 	struct {
26924edb884SFrançois Tigeot 		u8 i2c_dev_id;
27024edb884SFrançois Tigeot 		u8 num_bytes;
27124edb884SFrançois Tigeot 		u8 *bytes;
27224edb884SFrançois Tigeot 		u8 no_stop_bit;
27324edb884SFrançois Tigeot 		u8 i2c_transaction_delay;
2740e1ba51bSFrançois Tigeot 	} transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
27524edb884SFrançois Tigeot 	u8 read_i2c_device_id;
27624edb884SFrançois Tigeot 	u8 num_bytes_read;
27724edb884SFrançois Tigeot };
27824edb884SFrançois Tigeot 
27924edb884SFrançois Tigeot struct drm_dp_remote_i2c_write {
28024edb884SFrançois Tigeot 	u8 port_number;
28124edb884SFrançois Tigeot 	u8 write_i2c_device_id;
28224edb884SFrançois Tigeot 	u8 num_bytes;
28324edb884SFrançois Tigeot 	u8 *bytes;
28424edb884SFrançois Tigeot };
28524edb884SFrançois Tigeot 
28624edb884SFrançois Tigeot /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
28724edb884SFrançois Tigeot struct drm_dp_port_number_req {
28824edb884SFrançois Tigeot 	u8 port_number;
28924edb884SFrançois Tigeot };
29024edb884SFrançois Tigeot 
29124edb884SFrançois Tigeot struct drm_dp_enum_path_resources_ack_reply {
29224edb884SFrançois Tigeot 	u8 port_number;
29324edb884SFrançois Tigeot 	u16 full_payload_bw_number;
29424edb884SFrançois Tigeot 	u16 avail_payload_bw_number;
29524edb884SFrançois Tigeot };
29624edb884SFrançois Tigeot 
29724edb884SFrançois Tigeot /* covers POWER_DOWN_PHY, POWER_UP_PHY */
29824edb884SFrançois Tigeot struct drm_dp_port_number_rep {
29924edb884SFrançois Tigeot 	u8 port_number;
30024edb884SFrançois Tigeot };
30124edb884SFrançois Tigeot 
30224edb884SFrançois Tigeot struct drm_dp_query_payload {
30324edb884SFrançois Tigeot 	u8 port_number;
30424edb884SFrançois Tigeot 	u8 vcpi;
30524edb884SFrançois Tigeot };
30624edb884SFrançois Tigeot 
30724edb884SFrançois Tigeot struct drm_dp_resource_status_notify {
30824edb884SFrançois Tigeot 	u8 port_number;
30924edb884SFrançois Tigeot 	u8 guid[16];
31024edb884SFrançois Tigeot 	u16 available_pbn;
31124edb884SFrançois Tigeot };
31224edb884SFrançois Tigeot 
31324edb884SFrançois Tigeot struct drm_dp_query_payload_ack_reply {
31424edb884SFrançois Tigeot 	u8 port_number;
31524edb884SFrançois Tigeot 	u8 allocated_pbn;
31624edb884SFrançois Tigeot };
31724edb884SFrançois Tigeot 
31824edb884SFrançois Tigeot struct drm_dp_sideband_msg_req_body {
31924edb884SFrançois Tigeot 	u8 req_type;
32024edb884SFrançois Tigeot 	union ack_req {
32124edb884SFrançois Tigeot 		struct drm_dp_connection_status_notify conn_stat;
32224edb884SFrançois Tigeot 		struct drm_dp_port_number_req port_num;
32324edb884SFrançois Tigeot 		struct drm_dp_resource_status_notify resource_stat;
32424edb884SFrançois Tigeot 
32524edb884SFrançois Tigeot 		struct drm_dp_query_payload query_payload;
32624edb884SFrançois Tigeot 		struct drm_dp_allocate_payload allocate_payload;
32724edb884SFrançois Tigeot 
32824edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read dpcd_read;
32924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write dpcd_write;
33024edb884SFrançois Tigeot 
33124edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read i2c_read;
33224edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write i2c_write;
33324edb884SFrançois Tigeot 	} u;
33424edb884SFrançois Tigeot };
33524edb884SFrançois Tigeot 
33624edb884SFrançois Tigeot struct drm_dp_sideband_msg_reply_body {
33724edb884SFrançois Tigeot 	u8 reply_type;
33824edb884SFrançois Tigeot 	u8 req_type;
33924edb884SFrançois Tigeot 	union ack_replies {
34024edb884SFrançois Tigeot 		struct drm_dp_nak_reply nak;
34124edb884SFrançois Tigeot 		struct drm_dp_link_address_ack_reply link_addr;
34224edb884SFrançois Tigeot 		struct drm_dp_port_number_rep port_number;
34324edb884SFrançois Tigeot 
34424edb884SFrançois Tigeot 		struct drm_dp_enum_path_resources_ack_reply path_resources;
34524edb884SFrançois Tigeot 		struct drm_dp_allocate_payload_ack_reply allocate_payload;
34624edb884SFrançois Tigeot 		struct drm_dp_query_payload_ack_reply query_payload;
34724edb884SFrançois Tigeot 
34824edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
34924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
35024edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
35124edb884SFrançois Tigeot 
35224edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
35324edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
35424edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
35524edb884SFrançois Tigeot 	} u;
35624edb884SFrançois Tigeot };
35724edb884SFrançois Tigeot 
35824edb884SFrançois Tigeot /* msg is queued to be put into a slot */
35924edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_QUEUED 0
36024edb884SFrançois Tigeot /* msg has started transmitting on a slot - still on msgq */
36124edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_START_SEND 1
36224edb884SFrançois Tigeot /* msg has finished transmitting on a slot - removed from msgq only in slot */
36324edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_SENT 2
36424edb884SFrançois Tigeot /* msg has received a response - removed from slot */
36524edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_RX 3
36624edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
36724edb884SFrançois Tigeot 
36824edb884SFrançois Tigeot struct drm_dp_sideband_msg_tx {
36924edb884SFrançois Tigeot 	u8 msg[256];
37024edb884SFrançois Tigeot 	u8 chunk[48];
37124edb884SFrançois Tigeot 	u8 cur_offset;
37224edb884SFrançois Tigeot 	u8 cur_len;
37324edb884SFrançois Tigeot 	struct drm_dp_mst_branch *dst;
37424edb884SFrançois Tigeot 	struct list_head next;
37524edb884SFrançois Tigeot 	int seqno;
37624edb884SFrançois Tigeot 	int state;
37724edb884SFrançois Tigeot 	bool path_msg;
37824edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_reply_body reply;
37924edb884SFrançois Tigeot };
38024edb884SFrançois Tigeot 
38124edb884SFrançois Tigeot /* sideband msg handler */
38224edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr;
38324edb884SFrançois Tigeot struct drm_dp_mst_topology_cbs {
38424edb884SFrançois Tigeot 	/* create a connector for a port */
3852c9916cdSFrançois Tigeot 	struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
3860e1ba51bSFrançois Tigeot 	void (*register_connector)(struct drm_connector *connector);
38724edb884SFrançois Tigeot 	void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
38824edb884SFrançois Tigeot 				  struct drm_connector *connector);
38924edb884SFrançois Tigeot 	void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
39024edb884SFrançois Tigeot 
39124edb884SFrançois Tigeot };
39224edb884SFrançois Tigeot 
39324edb884SFrançois Tigeot #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
39424edb884SFrançois Tigeot 
39524edb884SFrançois Tigeot #define DP_PAYLOAD_LOCAL 1
39624edb884SFrançois Tigeot #define DP_PAYLOAD_REMOTE 2
39724edb884SFrançois Tigeot #define DP_PAYLOAD_DELETE_LOCAL 3
39824edb884SFrançois Tigeot 
39924edb884SFrançois Tigeot struct drm_dp_payload {
40024edb884SFrançois Tigeot 	int payload_state;
40124edb884SFrançois Tigeot 	int start_slot;
40224edb884SFrançois Tigeot 	int num_slots;
4032c9916cdSFrançois Tigeot 	int vcpi;
40424edb884SFrançois Tigeot };
40524edb884SFrançois Tigeot 
40624edb884SFrançois Tigeot /**
40724edb884SFrançois Tigeot  * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
40824edb884SFrançois Tigeot  *
40924edb884SFrançois Tigeot  * This struct represents the toplevel displayport MST topology manager.
41024edb884SFrançois Tigeot  * There should be one instance of this for every MST capable DP connector
41124edb884SFrançois Tigeot  * on the GPU.
41224edb884SFrançois Tigeot  */
41324edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr {
414*1dedbd3bSFrançois Tigeot 	/**
415*1dedbd3bSFrançois Tigeot 	 * @dev: device pointer for adding i2c devices etc.
416*1dedbd3bSFrançois Tigeot 	 */
41724edb884SFrançois Tigeot 	struct device *dev;
418*1dedbd3bSFrançois Tigeot 	/**
419*1dedbd3bSFrançois Tigeot 	 * @cbs: callbacks for connector addition and destruction.
420*1dedbd3bSFrançois Tigeot 	 */
421aee94f86SFrançois Tigeot 	const struct drm_dp_mst_topology_cbs *cbs;
422*1dedbd3bSFrançois Tigeot 	/**
423*1dedbd3bSFrançois Tigeot 	 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
424*1dedbd3bSFrançois Tigeot 	 * in one go.
425*1dedbd3bSFrançois Tigeot 	 */
42624edb884SFrançois Tigeot 	int max_dpcd_transaction_bytes;
427*1dedbd3bSFrançois Tigeot 	/**
428*1dedbd3bSFrançois Tigeot 	 * @aux: AUX channel for the DP MST connector this topolgy mgr is
429*1dedbd3bSFrançois Tigeot 	 * controlling.
430*1dedbd3bSFrançois Tigeot 	 */
431*1dedbd3bSFrançois Tigeot 	struct drm_dp_aux *aux;
432*1dedbd3bSFrançois Tigeot 	/**
433*1dedbd3bSFrançois Tigeot 	 * @max_payloads: maximum number of payloads the GPU can generate.
434*1dedbd3bSFrançois Tigeot 	 */
43524edb884SFrançois Tigeot 	int max_payloads;
436*1dedbd3bSFrançois Tigeot 	/**
437*1dedbd3bSFrançois Tigeot 	 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
438*1dedbd3bSFrançois Tigeot 	 * to build the MST connector path value.
439*1dedbd3bSFrançois Tigeot 	 */
44024edb884SFrançois Tigeot 	int conn_base_id;
44124edb884SFrançois Tigeot 
442*1dedbd3bSFrançois Tigeot 	/**
443*1dedbd3bSFrançois Tigeot 	 * @down_rep_recv: Message receiver state for down replies. This and
444*1dedbd3bSFrançois Tigeot 	 * @up_req_recv are only ever access from the work item, which is
445*1dedbd3bSFrançois Tigeot 	 * serialised.
446*1dedbd3bSFrançois Tigeot 	 */
44724edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx down_rep_recv;
448*1dedbd3bSFrançois Tigeot 	/**
449*1dedbd3bSFrançois Tigeot 	 * @up_req_recv: Message receiver state for up requests. This and
450*1dedbd3bSFrançois Tigeot 	 * @down_rep_recv are only ever access from the work item, which is
451*1dedbd3bSFrançois Tigeot 	 * serialised.
452*1dedbd3bSFrançois Tigeot 	 */
45324edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx up_req_recv;
45424edb884SFrançois Tigeot 
455*1dedbd3bSFrançois Tigeot 	/**
456*1dedbd3bSFrançois Tigeot 	 * @lock: protects mst state, primary, dpcd.
457*1dedbd3bSFrançois Tigeot 	 */
458*1dedbd3bSFrançois Tigeot 	struct lock lock;
45924edb884SFrançois Tigeot 
460*1dedbd3bSFrançois Tigeot 	/**
461*1dedbd3bSFrançois Tigeot 	 * @mst_state: If this manager is enabled for an MST capable port. False
462*1dedbd3bSFrançois Tigeot 	 * if no MST sink/branch devices is connected.
463*1dedbd3bSFrançois Tigeot 	 */
46424edb884SFrançois Tigeot 	bool mst_state;
465*1dedbd3bSFrançois Tigeot 	/**
466*1dedbd3bSFrançois Tigeot 	 * @mst_primary: Pointer to the primary/first branch device.
467*1dedbd3bSFrançois Tigeot 	 */
46824edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mst_primary;
469aee94f86SFrançois Tigeot 
470*1dedbd3bSFrançois Tigeot 	/**
471*1dedbd3bSFrançois Tigeot 	 * @dpcd: Cache of DPCD for primary port.
472*1dedbd3bSFrançois Tigeot 	 */
47324edb884SFrançois Tigeot 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
474*1dedbd3bSFrançois Tigeot 	/**
475*1dedbd3bSFrançois Tigeot 	 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
476*1dedbd3bSFrançois Tigeot 	 */
47724edb884SFrançois Tigeot 	u8 sink_count;
478*1dedbd3bSFrançois Tigeot 	/**
479*1dedbd3bSFrançois Tigeot 	 * @pbn_div: PBN to slots divisor.
480*1dedbd3bSFrançois Tigeot 	 */
48124edb884SFrançois Tigeot 	int pbn_div;
482*1dedbd3bSFrançois Tigeot 	/**
483*1dedbd3bSFrançois Tigeot 	 * @total_slots: Total slots that can be allocated.
484*1dedbd3bSFrançois Tigeot 	 */
48524edb884SFrançois Tigeot 	int total_slots;
486*1dedbd3bSFrançois Tigeot 	/**
487*1dedbd3bSFrançois Tigeot 	 * @avail_slots: Still available slots that can be allocated.
488*1dedbd3bSFrançois Tigeot 	 */
48924edb884SFrançois Tigeot 	int avail_slots;
490*1dedbd3bSFrançois Tigeot 	/**
491*1dedbd3bSFrançois Tigeot 	 * @total_pbn: Total PBN count.
492*1dedbd3bSFrançois Tigeot 	 */
49324edb884SFrançois Tigeot 	int total_pbn;
49424edb884SFrançois Tigeot 
495*1dedbd3bSFrançois Tigeot 	/**
496*1dedbd3bSFrançois Tigeot 	 * @qlock: protects @tx_msg_downq, the tx_slots in struct
497*1dedbd3bSFrançois Tigeot 	 * &drm_dp_mst_branch and txmsg->state once they are queued
498*1dedbd3bSFrançois Tigeot 	 */
49924edb884SFrançois Tigeot 	struct lock qlock;
500*1dedbd3bSFrançois Tigeot 	/**
501*1dedbd3bSFrançois Tigeot 	 * @tx_msg_downq: List of pending down replies.
502*1dedbd3bSFrançois Tigeot 	 */
50324edb884SFrançois Tigeot 	struct list_head tx_msg_downq;
50424edb884SFrançois Tigeot 
505*1dedbd3bSFrançois Tigeot 	/**
506*1dedbd3bSFrançois Tigeot 	 * @payload_lock: Protect payload information.
507*1dedbd3bSFrançois Tigeot 	 */
50824edb884SFrançois Tigeot 	struct lock payload_lock;
509*1dedbd3bSFrançois Tigeot 	/**
510*1dedbd3bSFrançois Tigeot 	 * @proposed_vcpis: Array of pointers for the new VCPI allocation. The
511*1dedbd3bSFrançois Tigeot 	 * VCPI structure itself is embedded into the corresponding
512*1dedbd3bSFrançois Tigeot 	 * &drm_dp_mst_port structure.
513*1dedbd3bSFrançois Tigeot 	 */
51424edb884SFrançois Tigeot 	struct drm_dp_vcpi **proposed_vcpis;
515*1dedbd3bSFrançois Tigeot 	/**
516*1dedbd3bSFrançois Tigeot 	 * @payloads: Array of payloads.
517*1dedbd3bSFrançois Tigeot 	 */
51824edb884SFrançois Tigeot 	struct drm_dp_payload *payloads;
519*1dedbd3bSFrançois Tigeot 	/**
520*1dedbd3bSFrançois Tigeot 	 * @payload_mask: Elements of @payloads actually in use. Since
521*1dedbd3bSFrançois Tigeot 	 * reallocation of active outputs isn't possible gaps can be created by
522*1dedbd3bSFrançois Tigeot 	 * disabling outputs out of order compared to how they've been enabled.
523*1dedbd3bSFrançois Tigeot 	 */
52424edb884SFrançois Tigeot 	unsigned long payload_mask;
525*1dedbd3bSFrançois Tigeot 	/**
526*1dedbd3bSFrançois Tigeot 	 * @vcpi_mask: Similar to @payload_mask, but for @proposed_vcpis.
527*1dedbd3bSFrançois Tigeot 	 */
5282c9916cdSFrançois Tigeot 	unsigned long vcpi_mask;
52924edb884SFrançois Tigeot 
530*1dedbd3bSFrançois Tigeot 	/**
531*1dedbd3bSFrançois Tigeot 	 * @tx_waitq: Wait to queue stall for the tx worker.
532*1dedbd3bSFrançois Tigeot 	 */
53324edb884SFrançois Tigeot 	wait_queue_head_t tx_waitq;
534*1dedbd3bSFrançois Tigeot 	/**
535*1dedbd3bSFrançois Tigeot 	 * @work: Probe work.
536*1dedbd3bSFrançois Tigeot 	 */
53724edb884SFrançois Tigeot 	struct work_struct work;
538*1dedbd3bSFrançois Tigeot 	/**
539*1dedbd3bSFrançois Tigeot 	 * @tx_work: Sideband transmit worker. This can nest within the main
540*1dedbd3bSFrançois Tigeot 	 * @work worker for each transaction @work launches.
541*1dedbd3bSFrançois Tigeot 	 */
54224edb884SFrançois Tigeot 	struct work_struct tx_work;
5430e1ba51bSFrançois Tigeot 
544*1dedbd3bSFrançois Tigeot 	/**
545*1dedbd3bSFrançois Tigeot 	 * @destroy_connector_list: List of to be destroyed connectors.
546*1dedbd3bSFrançois Tigeot 	 */
5470e1ba51bSFrançois Tigeot 	struct list_head destroy_connector_list;
548*1dedbd3bSFrançois Tigeot 	/**
549*1dedbd3bSFrançois Tigeot 	 * @destroy_connector_lock: Protects @connector_list.
550*1dedbd3bSFrançois Tigeot 	 */
5510e1ba51bSFrançois Tigeot 	struct lock destroy_connector_lock;
552*1dedbd3bSFrançois Tigeot 	/**
553*1dedbd3bSFrançois Tigeot 	 * @destroy_connector_work: Work item to destroy connectors. Needed to
554*1dedbd3bSFrançois Tigeot 	 * avoid locking inversion.
555*1dedbd3bSFrançois Tigeot 	 */
5560e1ba51bSFrançois Tigeot 	struct work_struct destroy_connector_work;
55724edb884SFrançois Tigeot };
55824edb884SFrançois Tigeot 
55924edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr, struct device *dev, struct drm_dp_aux *aux, int max_dpcd_transaction_bytes, int max_payloads, int conn_base_id);
56024edb884SFrançois Tigeot 
56124edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
56224edb884SFrançois Tigeot 
56324edb884SFrançois Tigeot 
56424edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
56524edb884SFrançois Tigeot 
56624edb884SFrançois Tigeot 
56724edb884SFrançois Tigeot int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
56824edb884SFrançois Tigeot 
56924edb884SFrançois Tigeot 
5702c9916cdSFranç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);
57124edb884SFrançois Tigeot 
572aee94f86SFrançois Tigeot bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
573aee94f86SFrançois Tigeot 					struct drm_dp_mst_port *port);
57424edb884SFranç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);
57524edb884SFrançois Tigeot 
57624edb884SFrançois Tigeot 
57724edb884SFrançois Tigeot int drm_dp_calc_pbn_mode(int clock, int bpp);
57824edb884SFrançois Tigeot 
57924edb884SFrançois Tigeot 
58024edb884SFrançois Tigeot bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots);
58124edb884SFrançois Tigeot 
582477eb7f9SFrançois Tigeot int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
583477eb7f9SFrançois Tigeot 
58424edb884SFrançois Tigeot 
58524edb884SFrançois Tigeot void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
58624edb884SFrançois Tigeot 
58724edb884SFrançois Tigeot 
58824edb884SFrançois Tigeot void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
58924edb884SFrançois Tigeot 				struct drm_dp_mst_port *port);
59024edb884SFrançois Tigeot 
59124edb884SFrançois Tigeot 
59224edb884SFrançois Tigeot int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
59324edb884SFrançois Tigeot 			   int pbn);
59424edb884SFrançois Tigeot 
59524edb884SFrançois Tigeot 
59624edb884SFrançois Tigeot int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
59724edb884SFrançois Tigeot 
59824edb884SFrançois Tigeot 
59924edb884SFrançois Tigeot int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
60024edb884SFrançois Tigeot 
60124edb884SFrançois Tigeot int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
60224edb884SFrançois Tigeot 
60324edb884SFrançois Tigeot void drm_dp_mst_dump_topology(struct seq_file *m,
60424edb884SFrançois Tigeot 			      struct drm_dp_mst_topology_mgr *mgr);
60524edb884SFrançois Tigeot 
60624edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
60724edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
60824edb884SFrançois Tigeot #endif
609