2 * Copyright © 2014 Red Hat.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 #ifndef _DRM_DP_MST_HELPER_H_
23 #define _DRM_DP_MST_HELPER_H_
25 #include <linux/types.h>
26 #include <drm/drm_dp_helper.h>
28 struct drm_dp_mst_branch
;
31 * struct drm_dp_vcpi - Virtual Channel Payload Identifer
32 * @vcpi: Virtual channel ID.
33 * @pbn: Payload Bandwidth Number for this channel
34 * @aligned_pbn: PBN aligned with slot size
35 * @num_slots: number of slots for this PBN
45 * struct drm_dp_mst_port - MST port
46 * @kref: reference count for this port.
47 * @guid_valid: for DP 1.2 devices if we have validated the GUID.
48 * @guid: guid for DP 1.2 device on this port.
49 * @port_num: port number
50 * @input: if this port is an input port.
51 * @mcs: message capability status - DP 1.2 spec.
52 * @ddps: DisplayPort Device Plug Status - DP 1.2
53 * @pdt: Peer Device Type
54 * @ldps: Legacy Device Plug Status
55 * @dpcd_rev: DPCD revision of device on this port
56 * @num_sdp_streams: Number of simultaneous streams
57 * @num_sdp_stream_sinks: Number of stream sinks
58 * @available_pbn: Available bandwidth for this port.
59 * @next: link to next port on this branch device
60 * @mstb: branch device attach below this port
61 * @aux: i2c aux transport to talk to device connected to this port.
62 * @parent: branch device parent of this port
63 * @vcpi: Virtual Channel Payload info for this port.
64 * @connector: DRM connector this port is connected to.
65 * @mgr: topology manager this port lives under.
67 * This structure represents an MST port endpoint on a device somewhere
68 * in the MST topology.
70 struct drm_dp_mst_port
{
73 /* if dpcd 1.2 device is on this port - its GUID info */
85 u8 num_sdp_stream_sinks
;
86 uint16_t available_pbn
;
87 struct list_head next
;
88 struct drm_dp_mst_branch
*mstb
; /* pointer to an mstb if this port has one */
89 struct drm_dp_aux aux
; /* i2c bus for this port? */
90 struct drm_dp_mst_branch
*parent
;
92 struct drm_dp_vcpi vcpi
;
93 struct drm_connector
*connector
;
94 struct drm_dp_mst_topology_mgr
*mgr
;
98 * struct drm_dp_mst_branch - MST branch device.
99 * @kref: reference count for this port.
100 * @rad: Relative Address to talk to this branch device.
101 * @lct: Link count total to talk to this branch device.
102 * @num_ports: number of ports on the branch.
103 * @msg_slots: one bit per transmitted msg slot.
104 * @ports: linked list of ports on this branch.
105 * @port_parent: pointer to the port parent, NULL if toplevel.
106 * @mgr: topology manager for this branch device.
107 * @tx_slots: transmission slots for this device.
108 * @last_seqno: last sequence number used to talk to this.
109 * @link_address_sent: if a link address message has been sent to this device yet.
111 * This structure represents an MST branch device, there is one
112 * primary branch device at the root, along with any others connected
113 * to downstream ports
115 struct drm_dp_mst_branch
{
122 struct list_head ports
;
124 /* list of tx ops queue for this port */
125 struct drm_dp_mst_port
*port_parent
;
126 struct drm_dp_mst_topology_mgr
*mgr
;
128 /* slots are protected by mstb->mgr->qlock */
129 struct drm_dp_sideband_msg_tx
*tx_slots
[2];
131 bool link_address_sent
;
135 /* sideband msg header - not bit struct */
136 struct drm_dp_sideband_msg_hdr
{
148 struct drm_dp_nak_reply
{
154 struct drm_dp_link_address_ack_reply
{
157 struct drm_dp_link_addr_reply_port
{
163 bool legacy_device_plug_status
;
167 u8 num_sdp_stream_sinks
;
171 struct drm_dp_remote_dpcd_read_ack_reply
{
177 struct drm_dp_remote_dpcd_write_ack_reply
{
181 struct drm_dp_remote_dpcd_write_nak_reply
{
184 u8 bytes_written_before_failure
;
187 struct drm_dp_remote_i2c_read_ack_reply
{
193 struct drm_dp_remote_i2c_read_nak_reply
{
196 u8 i2c_nak_transaction
;
199 struct drm_dp_remote_i2c_write_ack_reply
{
204 struct drm_dp_sideband_msg_rx
{
208 u8 curchunk_idx
; /* chunk we are parsing now */
210 u8 curlen
; /* total length of the msg */
213 struct drm_dp_sideband_msg_hdr initial_hdr
;
217 struct drm_dp_allocate_payload
{
219 u8 number_sdp_streams
;
222 u8 sdp_stream_sink
[8];
225 struct drm_dp_allocate_payload_ack_reply
{
231 struct drm_dp_connection_status_notify
{
234 bool legacy_device_plug_status
;
235 bool displayport_device_plug_status
;
236 bool message_capability_status
;
241 struct drm_dp_remote_dpcd_read
{
247 struct drm_dp_remote_dpcd_write
{
254 struct drm_dp_remote_i2c_read
{
262 u8 i2c_transaction_delay
;
264 u8 read_i2c_device_id
;
268 struct drm_dp_remote_i2c_write
{
270 u8 write_i2c_device_id
;
275 /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
276 struct drm_dp_port_number_req
{
280 struct drm_dp_enum_path_resources_ack_reply
{
282 u16 full_payload_bw_number
;
283 u16 avail_payload_bw_number
;
286 /* covers POWER_DOWN_PHY, POWER_UP_PHY */
287 struct drm_dp_port_number_rep
{
291 struct drm_dp_query_payload
{
296 struct drm_dp_resource_status_notify
{
302 struct drm_dp_query_payload_ack_reply
{
307 struct drm_dp_sideband_msg_req_body
{
310 struct drm_dp_connection_status_notify conn_stat
;
311 struct drm_dp_port_number_req port_num
;
312 struct drm_dp_resource_status_notify resource_stat
;
314 struct drm_dp_query_payload query_payload
;
315 struct drm_dp_allocate_payload allocate_payload
;
317 struct drm_dp_remote_dpcd_read dpcd_read
;
318 struct drm_dp_remote_dpcd_write dpcd_write
;
320 struct drm_dp_remote_i2c_read i2c_read
;
321 struct drm_dp_remote_i2c_write i2c_write
;
325 struct drm_dp_sideband_msg_reply_body
{
329 struct drm_dp_nak_reply nak
;
330 struct drm_dp_link_address_ack_reply link_addr
;
331 struct drm_dp_port_number_rep port_number
;
333 struct drm_dp_enum_path_resources_ack_reply path_resources
;
334 struct drm_dp_allocate_payload_ack_reply allocate_payload
;
335 struct drm_dp_query_payload_ack_reply query_payload
;
337 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack
;
338 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack
;
339 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack
;
341 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack
;
342 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack
;
343 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack
;
347 /* msg is queued to be put into a slot */
348 #define DRM_DP_SIDEBAND_TX_QUEUED 0
349 /* msg has started transmitting on a slot - still on msgq */
350 #define DRM_DP_SIDEBAND_TX_START_SEND 1
351 /* msg has finished transmitting on a slot - removed from msgq only in slot */
352 #define DRM_DP_SIDEBAND_TX_SENT 2
353 /* msg has received a response - removed from slot */
354 #define DRM_DP_SIDEBAND_TX_RX 3
355 #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
357 struct drm_dp_sideband_msg_tx
{
362 struct drm_dp_mst_branch
*dst
;
363 struct list_head next
;
367 struct drm_dp_sideband_msg_reply_body reply
;
370 /* sideband msg handler */
371 struct drm_dp_mst_topology_mgr
;
372 struct drm_dp_mst_topology_cbs
{
373 /* create a connector for a port */
374 struct drm_connector
*(*add_connector
)(struct drm_dp_mst_topology_mgr
*mgr
, struct drm_dp_mst_port
*port
, char *path
);
375 void (*destroy_connector
)(struct drm_dp_mst_topology_mgr
*mgr
,
376 struct drm_connector
*connector
);
377 void (*hotplug
)(struct drm_dp_mst_topology_mgr
*mgr
);
381 #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
383 #define DP_PAYLOAD_LOCAL 1
384 #define DP_PAYLOAD_REMOTE 2
385 #define DP_PAYLOAD_DELETE_LOCAL 3
387 struct drm_dp_payload
{
394 * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
395 * @dev: device pointer for adding i2c devices etc.
396 * @cbs: callbacks for connector addition and destruction.
397 * @max_dpcd_transaction_bytes - maximum number of bytes to read/write in one go.
398 * @aux: aux channel for the DP connector.
399 * @max_payloads: maximum number of payloads the GPU can generate.
400 * @conn_base_id: DRM connector ID this mgr is connected to.
401 * @down_rep_recv: msg receiver state for down replies.
402 * @up_req_recv: msg receiver state for up requests.
403 * @lock: protects mst state, primary, guid, dpcd.
404 * @mst_state: if this manager is enabled for an MST capable port.
405 * @mst_primary: pointer to the primary branch device.
406 * @guid_valid: GUID valid for the primary branch device.
407 * @guid: GUID for primary port.
408 * @dpcd: cache of DPCD for primary port.
409 * @pbn_div: PBN to slots divisor.
411 * This struct represents the toplevel displayport MST topology manager.
412 * There should be one instance of this for every MST capable DP connector
415 struct drm_dp_mst_topology_mgr
{
418 struct drm_dp_mst_topology_cbs
*cbs
;
419 int max_dpcd_transaction_bytes
;
420 struct drm_dp_aux
*aux
; /* auxch for this topology mgr to use */
424 /* only ever accessed from the workqueue - which should be serialised */
425 struct drm_dp_sideband_msg_rx down_rep_recv
;
426 struct drm_dp_sideband_msg_rx up_req_recv
;
428 /* pointer to info about the initial MST device */
429 struct mutex lock
; /* protects mst_state + primary + guid + dpcd */
432 struct drm_dp_mst_branch
*mst_primary
;
433 /* primary MST device GUID */
436 u8 dpcd
[DP_RECEIVER_CAP_SIZE
];
443 /* messages to be transmitted */
444 /* qlock protects the upq/downq and in_progress,
445 the mstb tx_slots and txmsg->state once they are queued */
447 struct list_head tx_msg_downq
;
448 struct list_head tx_msg_upq
;
449 bool tx_down_in_progress
;
450 bool tx_up_in_progress
;
452 /* payload info + lock for it */
453 struct mutex payload_lock
;
454 struct drm_dp_vcpi
**proposed_vcpis
;
455 struct drm_dp_payload
*payloads
;
456 unsigned long payload_mask
;
458 wait_queue_head_t tx_waitq
;
459 struct work_struct work
;
461 struct work_struct tx_work
;
464 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
);
466 void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr
*mgr
);
469 int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr
*mgr
, bool mst_state
);
472 int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr
*mgr
, u8
*esi
, bool *handled
);
475 enum drm_connector_status
drm_dp_mst_detect_port(struct drm_dp_mst_topology_mgr
*mgr
, struct drm_dp_mst_port
*port
);
477 struct edid
*drm_dp_mst_get_edid(struct drm_connector
*connector
, struct drm_dp_mst_topology_mgr
*mgr
, struct drm_dp_mst_port
*port
);
480 int drm_dp_calc_pbn_mode(int clock
, int bpp
);
483 bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr
*mgr
, struct drm_dp_mst_port
*port
, int pbn
, int *slots
);
486 void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr
*mgr
, struct drm_dp_mst_port
*port
);
489 void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr
*mgr
,
490 struct drm_dp_mst_port
*port
);
493 int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr
*mgr
,
497 int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr
*mgr
);
500 int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr
*mgr
);
502 int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr
*mgr
);
504 void drm_dp_mst_dump_topology(struct seq_file
*m
,
505 struct drm_dp_mst_topology_mgr
*mgr
);
507 void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr
*mgr
);
508 int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr
*mgr
);