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  * @guid_valid: for DP 1.2 devices if we have validated the GUID.
4824edb884SFrançois Tigeot  * @guid: guid for DP 1.2 device on this port.
4924edb884SFrançois Tigeot  * @port_num: port number
5024edb884SFrançois Tigeot  * @input: if this port is an input port.
5124edb884SFrançois Tigeot  * @mcs: message capability status - DP 1.2 spec.
5224edb884SFrançois Tigeot  * @ddps: DisplayPort Device Plug Status - DP 1.2
5324edb884SFrançois Tigeot  * @pdt: Peer Device Type
5424edb884SFrançois Tigeot  * @ldps: Legacy Device Plug Status
5524edb884SFrançois Tigeot  * @dpcd_rev: DPCD revision of device on this port
5624edb884SFrançois Tigeot  * @num_sdp_streams: Number of simultaneous streams
5724edb884SFrançois Tigeot  * @num_sdp_stream_sinks: Number of stream sinks
5824edb884SFrançois Tigeot  * @available_pbn: Available bandwidth for this port.
5924edb884SFrançois Tigeot  * @next: link to next port on this branch device
6024edb884SFrançois Tigeot  * @mstb: branch device attach below this port
6124edb884SFrançois Tigeot  * @aux: i2c aux transport to talk to device connected to this port.
6224edb884SFrançois Tigeot  * @parent: branch device parent of this port
6324edb884SFrançois Tigeot  * @vcpi: Virtual Channel Payload info for this port.
6424edb884SFrançois Tigeot  * @connector: DRM connector this port is connected to.
6524edb884SFrançois Tigeot  * @mgr: topology manager this port lives under.
6624edb884SFrançois Tigeot  *
6724edb884SFrançois Tigeot  * This structure represents an MST port endpoint on a device somewhere
6824edb884SFrançois Tigeot  * in the MST topology.
6924edb884SFrançois Tigeot  */
7024edb884SFrançois Tigeot struct drm_dp_mst_port {
7124edb884SFrançois Tigeot 	struct kref kref;
7224edb884SFrançois Tigeot 
7324edb884SFrançois Tigeot 	/* if dpcd 1.2 device is on this port - its GUID info */
7424edb884SFrançois Tigeot 	bool guid_valid;
7524edb884SFrançois Tigeot 	u8 guid[16];
7624edb884SFrançois Tigeot 
7724edb884SFrançois Tigeot 	u8 port_num;
7824edb884SFrançois Tigeot 	bool input;
7924edb884SFrançois Tigeot 	bool mcs;
8024edb884SFrançois Tigeot 	bool ddps;
8124edb884SFrançois Tigeot 	u8 pdt;
8224edb884SFrançois Tigeot 	bool ldps;
8324edb884SFrançois Tigeot 	u8 dpcd_rev;
8424edb884SFrançois Tigeot 	u8 num_sdp_streams;
8524edb884SFrançois Tigeot 	u8 num_sdp_stream_sinks;
8624edb884SFrançois Tigeot 	uint16_t available_pbn;
8724edb884SFrançois Tigeot 	struct list_head next;
8824edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mstb; /* pointer to an mstb if this port has one */
8924edb884SFrançois Tigeot 	struct drm_dp_aux aux; /* i2c bus for this port? */
9024edb884SFrançois Tigeot 	struct drm_dp_mst_branch *parent;
9124edb884SFrançois Tigeot 
9224edb884SFrançois Tigeot 	struct drm_dp_vcpi vcpi;
9324edb884SFrançois Tigeot 	struct drm_connector *connector;
9424edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
952c9916cdSFrançois Tigeot 
962c9916cdSFrançois Tigeot 	struct edid *cached_edid; /* for DP logical ports - make tiling work */
9724edb884SFrançois Tigeot };
9824edb884SFrançois Tigeot 
9924edb884SFrançois Tigeot /**
10024edb884SFrançois Tigeot  * struct drm_dp_mst_branch - MST branch device.
10124edb884SFrançois Tigeot  * @kref: reference count for this port.
10224edb884SFrançois Tigeot  * @rad: Relative Address to talk to this branch device.
10324edb884SFrançois Tigeot  * @lct: Link count total to talk to this branch device.
10424edb884SFrançois Tigeot  * @num_ports: number of ports on the branch.
10524edb884SFrançois Tigeot  * @msg_slots: one bit per transmitted msg slot.
10624edb884SFrançois Tigeot  * @ports: linked list of ports on this branch.
10724edb884SFrançois Tigeot  * @port_parent: pointer to the port parent, NULL if toplevel.
10824edb884SFrançois Tigeot  * @mgr: topology manager for this branch device.
10924edb884SFrançois Tigeot  * @tx_slots: transmission slots for this device.
11024edb884SFrançois Tigeot  * @last_seqno: last sequence number used to talk to this.
11124edb884SFrançois Tigeot  * @link_address_sent: if a link address message has been sent to this device yet.
11224edb884SFrançois Tigeot  *
11324edb884SFrançois Tigeot  * This structure represents an MST branch device, there is one
11424edb884SFrançois Tigeot  * primary branch device at the root, along with any others connected
11524edb884SFrançois Tigeot  * to downstream ports
11624edb884SFrançois Tigeot  */
11724edb884SFrançois Tigeot struct drm_dp_mst_branch {
11824edb884SFrançois Tigeot 	struct kref kref;
11924edb884SFrançois Tigeot 	u8 rad[8];
12024edb884SFrançois Tigeot 	u8 lct;
12124edb884SFrançois Tigeot 	int num_ports;
12224edb884SFrançois Tigeot 
12324edb884SFrançois Tigeot 	int msg_slots;
12424edb884SFrançois Tigeot 	struct list_head ports;
12524edb884SFrançois Tigeot 
12624edb884SFrançois Tigeot 	/* list of tx ops queue for this port */
12724edb884SFrançois Tigeot 	struct drm_dp_mst_port *port_parent;
12824edb884SFrançois Tigeot 	struct drm_dp_mst_topology_mgr *mgr;
12924edb884SFrançois Tigeot 
13024edb884SFrançois Tigeot 	/* slots are protected by mstb->mgr->qlock */
13124edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_tx *tx_slots[2];
13224edb884SFrançois Tigeot 	int last_seqno;
13324edb884SFrançois Tigeot 	bool link_address_sent;
13424edb884SFrançois Tigeot };
13524edb884SFrançois Tigeot 
13624edb884SFrançois Tigeot 
13724edb884SFrançois Tigeot /* sideband msg header - not bit struct */
13824edb884SFrançois Tigeot struct drm_dp_sideband_msg_hdr {
13924edb884SFrançois Tigeot 	u8 lct;
14024edb884SFrançois Tigeot 	u8 lcr;
14124edb884SFrançois Tigeot 	u8 rad[8];
14224edb884SFrançois Tigeot 	bool broadcast;
14324edb884SFrançois Tigeot 	bool path_msg;
14424edb884SFrançois Tigeot 	u8 msg_len;
14524edb884SFrançois Tigeot 	bool somt;
14624edb884SFrançois Tigeot 	bool eomt;
14724edb884SFrançois Tigeot 	bool seqno;
14824edb884SFrançois Tigeot };
14924edb884SFrançois Tigeot 
15024edb884SFrançois Tigeot struct drm_dp_nak_reply {
15124edb884SFrançois Tigeot 	u8 guid[16];
15224edb884SFrançois Tigeot 	u8 reason;
15324edb884SFrançois Tigeot 	u8 nak_data;
15424edb884SFrançois Tigeot };
15524edb884SFrançois Tigeot 
15624edb884SFrançois Tigeot struct drm_dp_link_address_ack_reply {
15724edb884SFrançois Tigeot 	u8 guid[16];
15824edb884SFrançois Tigeot 	u8 nports;
15924edb884SFrançois Tigeot 	struct drm_dp_link_addr_reply_port {
16024edb884SFrançois Tigeot 		bool input_port;
16124edb884SFrançois Tigeot 		u8 peer_device_type;
16224edb884SFrançois Tigeot 		u8 port_number;
16324edb884SFrançois Tigeot 		bool mcs;
16424edb884SFrançois Tigeot 		bool ddps;
16524edb884SFrançois Tigeot 		bool legacy_device_plug_status;
16624edb884SFrançois Tigeot 		u8 dpcd_revision;
16724edb884SFrançois Tigeot 		u8 peer_guid[16];
16824edb884SFrançois Tigeot 		u8 num_sdp_streams;
16924edb884SFrançois Tigeot 		u8 num_sdp_stream_sinks;
17024edb884SFrançois Tigeot 	} ports[16];
17124edb884SFrançois Tigeot };
17224edb884SFrançois Tigeot 
17324edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read_ack_reply {
17424edb884SFrançois Tigeot 	u8 port_number;
17524edb884SFrançois Tigeot 	u8 num_bytes;
17624edb884SFrançois Tigeot 	u8 bytes[255];
17724edb884SFrançois Tigeot };
17824edb884SFrançois Tigeot 
17924edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_ack_reply {
18024edb884SFrançois Tigeot 	u8 port_number;
18124edb884SFrançois Tigeot };
18224edb884SFrançois Tigeot 
18324edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write_nak_reply {
18424edb884SFrançois Tigeot 	u8 port_number;
18524edb884SFrançois Tigeot 	u8 reason;
18624edb884SFrançois Tigeot 	u8 bytes_written_before_failure;
18724edb884SFrançois Tigeot };
18824edb884SFrançois Tigeot 
18924edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_ack_reply {
19024edb884SFrançois Tigeot 	u8 port_number;
19124edb884SFrançois Tigeot 	u8 num_bytes;
19224edb884SFrançois Tigeot 	u8 bytes[255];
19324edb884SFrançois Tigeot };
19424edb884SFrançois Tigeot 
19524edb884SFrançois Tigeot struct drm_dp_remote_i2c_read_nak_reply {
19624edb884SFrançois Tigeot 	u8 port_number;
19724edb884SFrançois Tigeot 	u8 nak_reason;
19824edb884SFrançois Tigeot 	u8 i2c_nak_transaction;
19924edb884SFrançois Tigeot };
20024edb884SFrançois Tigeot 
20124edb884SFrançois Tigeot struct drm_dp_remote_i2c_write_ack_reply {
20224edb884SFrançois Tigeot 	u8 port_number;
20324edb884SFrançois Tigeot };
20424edb884SFrançois Tigeot 
20524edb884SFrançois Tigeot 
20624edb884SFrançois Tigeot struct drm_dp_sideband_msg_rx {
20724edb884SFrançois Tigeot 	u8 chunk[48];
20824edb884SFrançois Tigeot 	u8 msg[256];
20924edb884SFrançois Tigeot 	u8 curchunk_len;
21024edb884SFrançois Tigeot 	u8 curchunk_idx; /* chunk we are parsing now */
21124edb884SFrançois Tigeot 	u8 curchunk_hdrlen;
21224edb884SFrançois Tigeot 	u8 curlen; /* total length of the msg */
21324edb884SFrançois Tigeot 	bool have_somt;
21424edb884SFrançois Tigeot 	bool have_eomt;
21524edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_hdr initial_hdr;
21624edb884SFrançois Tigeot };
21724edb884SFrançois Tigeot 
21824edb884SFrançois Tigeot 
21924edb884SFrançois Tigeot struct drm_dp_allocate_payload {
22024edb884SFrançois Tigeot 	u8 port_number;
22124edb884SFrançois Tigeot 	u8 number_sdp_streams;
22224edb884SFrançois Tigeot 	u8 vcpi;
22324edb884SFrançois Tigeot 	u16 pbn;
22424edb884SFrançois Tigeot 	u8 sdp_stream_sink[8];
22524edb884SFrançois Tigeot };
22624edb884SFrançois Tigeot 
22724edb884SFrançois Tigeot struct drm_dp_allocate_payload_ack_reply {
22824edb884SFrançois Tigeot 	u8 port_number;
22924edb884SFrançois Tigeot 	u8 vcpi;
23024edb884SFrançois Tigeot 	u16 allocated_pbn;
23124edb884SFrançois Tigeot };
23224edb884SFrançois Tigeot 
23324edb884SFrançois Tigeot struct drm_dp_connection_status_notify {
23424edb884SFrançois Tigeot 	u8 guid[16];
23524edb884SFrançois Tigeot 	u8 port_number;
23624edb884SFrançois Tigeot 	bool legacy_device_plug_status;
23724edb884SFrançois Tigeot 	bool displayport_device_plug_status;
23824edb884SFrançois Tigeot 	bool message_capability_status;
23924edb884SFrançois Tigeot 	bool input_port;
24024edb884SFrançois Tigeot 	u8 peer_device_type;
24124edb884SFrançois Tigeot };
24224edb884SFrançois Tigeot 
24324edb884SFrançois Tigeot struct drm_dp_remote_dpcd_read {
24424edb884SFrançois Tigeot 	u8 port_number;
24524edb884SFrançois Tigeot 	u32 dpcd_address;
24624edb884SFrançois Tigeot 	u8 num_bytes;
24724edb884SFrançois Tigeot };
24824edb884SFrançois Tigeot 
24924edb884SFrançois Tigeot struct drm_dp_remote_dpcd_write {
25024edb884SFrançois Tigeot 	u8 port_number;
25124edb884SFrançois Tigeot 	u32 dpcd_address;
25224edb884SFrançois Tigeot 	u8 num_bytes;
25324edb884SFrançois Tigeot 	u8 *bytes;
25424edb884SFrançois Tigeot };
25524edb884SFrançois Tigeot 
25624edb884SFrançois Tigeot struct drm_dp_remote_i2c_read {
25724edb884SFrançois Tigeot 	u8 num_transactions;
25824edb884SFrançois Tigeot 	u8 port_number;
25924edb884SFrançois Tigeot 	struct {
26024edb884SFrançois Tigeot 		u8 i2c_dev_id;
26124edb884SFrançois Tigeot 		u8 num_bytes;
26224edb884SFrançois Tigeot 		u8 *bytes;
26324edb884SFrançois Tigeot 		u8 no_stop_bit;
26424edb884SFrançois Tigeot 		u8 i2c_transaction_delay;
26524edb884SFrançois Tigeot 	} transactions[4];
26624edb884SFrançois Tigeot 	u8 read_i2c_device_id;
26724edb884SFrançois Tigeot 	u8 num_bytes_read;
26824edb884SFrançois Tigeot };
26924edb884SFrançois Tigeot 
27024edb884SFrançois Tigeot struct drm_dp_remote_i2c_write {
27124edb884SFrançois Tigeot 	u8 port_number;
27224edb884SFrançois Tigeot 	u8 write_i2c_device_id;
27324edb884SFrançois Tigeot 	u8 num_bytes;
27424edb884SFrançois Tigeot 	u8 *bytes;
27524edb884SFrançois Tigeot };
27624edb884SFrançois Tigeot 
27724edb884SFrançois Tigeot /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
27824edb884SFrançois Tigeot struct drm_dp_port_number_req {
27924edb884SFrançois Tigeot 	u8 port_number;
28024edb884SFrançois Tigeot };
28124edb884SFrançois Tigeot 
28224edb884SFrançois Tigeot struct drm_dp_enum_path_resources_ack_reply {
28324edb884SFrançois Tigeot 	u8 port_number;
28424edb884SFrançois Tigeot 	u16 full_payload_bw_number;
28524edb884SFrançois Tigeot 	u16 avail_payload_bw_number;
28624edb884SFrançois Tigeot };
28724edb884SFrançois Tigeot 
28824edb884SFrançois Tigeot /* covers POWER_DOWN_PHY, POWER_UP_PHY */
28924edb884SFrançois Tigeot struct drm_dp_port_number_rep {
29024edb884SFrançois Tigeot 	u8 port_number;
29124edb884SFrançois Tigeot };
29224edb884SFrançois Tigeot 
29324edb884SFrançois Tigeot struct drm_dp_query_payload {
29424edb884SFrançois Tigeot 	u8 port_number;
29524edb884SFrançois Tigeot 	u8 vcpi;
29624edb884SFrançois Tigeot };
29724edb884SFrançois Tigeot 
29824edb884SFrançois Tigeot struct drm_dp_resource_status_notify {
29924edb884SFrançois Tigeot 	u8 port_number;
30024edb884SFrançois Tigeot 	u8 guid[16];
30124edb884SFrançois Tigeot 	u16 available_pbn;
30224edb884SFrançois Tigeot };
30324edb884SFrançois Tigeot 
30424edb884SFrançois Tigeot struct drm_dp_query_payload_ack_reply {
30524edb884SFrançois Tigeot 	u8 port_number;
30624edb884SFrançois Tigeot 	u8 allocated_pbn;
30724edb884SFrançois Tigeot };
30824edb884SFrançois Tigeot 
30924edb884SFrançois Tigeot struct drm_dp_sideband_msg_req_body {
31024edb884SFrançois Tigeot 	u8 req_type;
31124edb884SFrançois Tigeot 	union ack_req {
31224edb884SFrançois Tigeot 		struct drm_dp_connection_status_notify conn_stat;
31324edb884SFrançois Tigeot 		struct drm_dp_port_number_req port_num;
31424edb884SFrançois Tigeot 		struct drm_dp_resource_status_notify resource_stat;
31524edb884SFrançois Tigeot 
31624edb884SFrançois Tigeot 		struct drm_dp_query_payload query_payload;
31724edb884SFrançois Tigeot 		struct drm_dp_allocate_payload allocate_payload;
31824edb884SFrançois Tigeot 
31924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read dpcd_read;
32024edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write dpcd_write;
32124edb884SFrançois Tigeot 
32224edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read i2c_read;
32324edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write i2c_write;
32424edb884SFrançois Tigeot 	} u;
32524edb884SFrançois Tigeot };
32624edb884SFrançois Tigeot 
32724edb884SFrançois Tigeot struct drm_dp_sideband_msg_reply_body {
32824edb884SFrançois Tigeot 	u8 reply_type;
32924edb884SFrançois Tigeot 	u8 req_type;
33024edb884SFrançois Tigeot 	union ack_replies {
33124edb884SFrançois Tigeot 		struct drm_dp_nak_reply nak;
33224edb884SFrançois Tigeot 		struct drm_dp_link_address_ack_reply link_addr;
33324edb884SFrançois Tigeot 		struct drm_dp_port_number_rep port_number;
33424edb884SFrançois Tigeot 
33524edb884SFrançois Tigeot 		struct drm_dp_enum_path_resources_ack_reply path_resources;
33624edb884SFrançois Tigeot 		struct drm_dp_allocate_payload_ack_reply allocate_payload;
33724edb884SFrançois Tigeot 		struct drm_dp_query_payload_ack_reply query_payload;
33824edb884SFrançois Tigeot 
33924edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
34024edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
34124edb884SFrançois Tigeot 		struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
34224edb884SFrançois Tigeot 
34324edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
34424edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
34524edb884SFrançois Tigeot 		struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
34624edb884SFrançois Tigeot 	} u;
34724edb884SFrançois Tigeot };
34824edb884SFrançois Tigeot 
34924edb884SFrançois Tigeot /* msg is queued to be put into a slot */
35024edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_QUEUED 0
35124edb884SFrançois Tigeot /* msg has started transmitting on a slot - still on msgq */
35224edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_START_SEND 1
35324edb884SFrançois Tigeot /* msg has finished transmitting on a slot - removed from msgq only in slot */
35424edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_SENT 2
35524edb884SFrançois Tigeot /* msg has received a response - removed from slot */
35624edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_RX 3
35724edb884SFrançois Tigeot #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
35824edb884SFrançois Tigeot 
35924edb884SFrançois Tigeot struct drm_dp_sideband_msg_tx {
36024edb884SFrançois Tigeot 	u8 msg[256];
36124edb884SFrançois Tigeot 	u8 chunk[48];
36224edb884SFrançois Tigeot 	u8 cur_offset;
36324edb884SFrançois Tigeot 	u8 cur_len;
36424edb884SFrançois Tigeot 	struct drm_dp_mst_branch *dst;
36524edb884SFrançois Tigeot 	struct list_head next;
36624edb884SFrançois Tigeot 	int seqno;
36724edb884SFrançois Tigeot 	int state;
36824edb884SFrançois Tigeot 	bool path_msg;
36924edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_reply_body reply;
37024edb884SFrançois Tigeot };
37124edb884SFrançois Tigeot 
37224edb884SFrançois Tigeot /* sideband msg handler */
37324edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr;
37424edb884SFrançois Tigeot struct drm_dp_mst_topology_cbs {
37524edb884SFrançois Tigeot 	/* create a connector for a port */
3762c9916cdSFrançois Tigeot 	struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
37724edb884SFrançois Tigeot 	void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
37824edb884SFrançois Tigeot 				  struct drm_connector *connector);
37924edb884SFrançois Tigeot 	void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
38024edb884SFrançois Tigeot 
38124edb884SFrançois Tigeot };
38224edb884SFrançois Tigeot 
38324edb884SFrançois Tigeot #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
38424edb884SFrançois Tigeot 
38524edb884SFrançois Tigeot #define DP_PAYLOAD_LOCAL 1
38624edb884SFrançois Tigeot #define DP_PAYLOAD_REMOTE 2
38724edb884SFrançois Tigeot #define DP_PAYLOAD_DELETE_LOCAL 3
38824edb884SFrançois Tigeot 
38924edb884SFrançois Tigeot struct drm_dp_payload {
39024edb884SFrançois Tigeot 	int payload_state;
39124edb884SFrançois Tigeot 	int start_slot;
39224edb884SFrançois Tigeot 	int num_slots;
3932c9916cdSFrançois Tigeot 	int vcpi;
39424edb884SFrançois Tigeot };
39524edb884SFrançois Tigeot 
39624edb884SFrançois Tigeot /**
39724edb884SFrançois Tigeot  * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
39824edb884SFrançois Tigeot  * @dev: device pointer for adding i2c devices etc.
39924edb884SFrançois Tigeot  * @cbs: callbacks for connector addition and destruction.
40024edb884SFrançois Tigeot  * @max_dpcd_transaction_bytes - maximum number of bytes to read/write in one go.
40124edb884SFrançois Tigeot  * @aux: aux channel for the DP connector.
40224edb884SFrançois Tigeot  * @max_payloads: maximum number of payloads the GPU can generate.
40324edb884SFrançois Tigeot  * @conn_base_id: DRM connector ID this mgr is connected to.
40424edb884SFrançois Tigeot  * @down_rep_recv: msg receiver state for down replies.
40524edb884SFrançois Tigeot  * @up_req_recv: msg receiver state for up requests.
40624edb884SFrançois Tigeot  * @lock: protects mst state, primary, guid, dpcd.
40724edb884SFrançois Tigeot  * @mst_state: if this manager is enabled for an MST capable port.
40824edb884SFrançois Tigeot  * @mst_primary: pointer to the primary branch device.
40924edb884SFrançois Tigeot  * @guid_valid: GUID valid for the primary branch device.
41024edb884SFrançois Tigeot  * @guid: GUID for primary port.
41124edb884SFrançois Tigeot  * @dpcd: cache of DPCD for primary port.
41224edb884SFrançois Tigeot  * @pbn_div: PBN to slots divisor.
41324edb884SFrançois Tigeot  *
41424edb884SFrançois Tigeot  * This struct represents the toplevel displayport MST topology manager.
41524edb884SFrançois Tigeot  * There should be one instance of this for every MST capable DP connector
41624edb884SFrançois Tigeot  * on the GPU.
41724edb884SFrançois Tigeot  */
41824edb884SFrançois Tigeot struct drm_dp_mst_topology_mgr {
41924edb884SFrançois Tigeot 
42024edb884SFrançois Tigeot 	struct device *dev;
42124edb884SFrançois Tigeot 	struct drm_dp_mst_topology_cbs *cbs;
42224edb884SFrançois Tigeot 	int max_dpcd_transaction_bytes;
42324edb884SFrançois Tigeot 	struct drm_dp_aux *aux; /* auxch for this topology mgr to use */
42424edb884SFrançois Tigeot 	int max_payloads;
42524edb884SFrançois Tigeot 	int conn_base_id;
42624edb884SFrançois Tigeot 
42724edb884SFrançois Tigeot 	/* only ever accessed from the workqueue - which should be serialised */
42824edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx down_rep_recv;
42924edb884SFrançois Tigeot 	struct drm_dp_sideband_msg_rx up_req_recv;
43024edb884SFrançois Tigeot 
43124edb884SFrançois Tigeot 	/* pointer to info about the initial MST device */
43224edb884SFrançois Tigeot 	struct lock lock; /* protects mst_state + primary + guid + dpcd */
43324edb884SFrançois Tigeot 
43424edb884SFrançois Tigeot 	bool mst_state;
43524edb884SFrançois Tigeot 	struct drm_dp_mst_branch *mst_primary;
43624edb884SFrançois Tigeot 	/* primary MST device GUID */
43724edb884SFrançois Tigeot 	bool guid_valid;
43824edb884SFrançois Tigeot 	u8 guid[16];
43924edb884SFrançois Tigeot 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
44024edb884SFrançois Tigeot 	u8 sink_count;
44124edb884SFrançois Tigeot 	int pbn_div;
44224edb884SFrançois Tigeot 	int total_slots;
44324edb884SFrançois Tigeot 	int avail_slots;
44424edb884SFrançois Tigeot 	int total_pbn;
44524edb884SFrançois Tigeot 
44624edb884SFrançois Tigeot 	/* messages to be transmitted */
44724edb884SFrançois Tigeot 	/* qlock protects the upq/downq and in_progress,
44824edb884SFrançois Tigeot 	   the mstb tx_slots and txmsg->state once they are queued */
44924edb884SFrançois Tigeot 	struct lock qlock;
45024edb884SFrançois Tigeot 	struct list_head tx_msg_downq;
45124edb884SFrançois Tigeot 	struct list_head tx_msg_upq;
45224edb884SFrançois Tigeot 	bool tx_down_in_progress;
45324edb884SFrançois Tigeot 	bool tx_up_in_progress;
45424edb884SFrançois Tigeot 
45524edb884SFrançois Tigeot 	/* payload info + lock for it */
45624edb884SFrançois Tigeot 	struct lock payload_lock;
45724edb884SFrançois Tigeot 	struct drm_dp_vcpi **proposed_vcpis;
45824edb884SFrançois Tigeot 	struct drm_dp_payload *payloads;
45924edb884SFrançois Tigeot 	unsigned long payload_mask;
4602c9916cdSFrançois Tigeot 	unsigned long vcpi_mask;
46124edb884SFrançois Tigeot 
46224edb884SFrançois Tigeot 	wait_queue_head_t tx_waitq;
46324edb884SFrançois Tigeot 	struct work_struct work;
46424edb884SFrançois Tigeot 
46524edb884SFrançois Tigeot 	struct work_struct tx_work;
46624edb884SFrançois Tigeot };
46724edb884SFrançois Tigeot 
46824edb884SFranç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);
46924edb884SFrançois Tigeot 
47024edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
47124edb884SFrançois Tigeot 
47224edb884SFrançois Tigeot 
47324edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
47424edb884SFrançois Tigeot 
47524edb884SFrançois Tigeot 
47624edb884SFrançois Tigeot int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
47724edb884SFrançois Tigeot 
47824edb884SFrançois Tigeot 
4792c9916cdSFranç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);
48024edb884SFrançois Tigeot 
48124edb884SFranç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);
48224edb884SFrançois Tigeot 
48324edb884SFrançois Tigeot 
48424edb884SFrançois Tigeot int drm_dp_calc_pbn_mode(int clock, int bpp);
48524edb884SFrançois Tigeot 
48624edb884SFrançois Tigeot 
48724edb884SFranç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);
48824edb884SFrançois Tigeot 
489*477eb7f9SFrançois Tigeot int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
490*477eb7f9SFrançois Tigeot 
49124edb884SFrançois Tigeot 
49224edb884SFrançois Tigeot void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
49324edb884SFrançois Tigeot 
49424edb884SFrançois Tigeot 
49524edb884SFrançois Tigeot void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
49624edb884SFrançois Tigeot 				struct drm_dp_mst_port *port);
49724edb884SFrançois Tigeot 
49824edb884SFrançois Tigeot 
49924edb884SFrançois Tigeot int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
50024edb884SFrançois Tigeot 			   int pbn);
50124edb884SFrançois Tigeot 
50224edb884SFrançois Tigeot 
50324edb884SFrançois Tigeot int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
50424edb884SFrançois Tigeot 
50524edb884SFrançois Tigeot 
50624edb884SFrançois Tigeot int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
50724edb884SFrançois Tigeot 
50824edb884SFrançois Tigeot int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
50924edb884SFrançois Tigeot 
51024edb884SFrançois Tigeot void drm_dp_mst_dump_topology(struct seq_file *m,
51124edb884SFrançois Tigeot 			      struct drm_dp_mst_topology_mgr *mgr);
51224edb884SFrançois Tigeot 
51324edb884SFrançois Tigeot void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
51424edb884SFrançois Tigeot int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
51524edb884SFrançois Tigeot #endif
516