1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef _DRM_DP_MST_HELPER_H_
23#define _DRM_DP_MST_HELPER_H_
24
25#include <linux/types.h>
26#include <drm/drm_dp_helper.h>
27#include <drm/drm_atomic.h>
28
29struct drm_dp_mst_branch;
30
31
32
33
34
35
36
37
38struct drm_dp_vcpi {
39 int vcpi;
40 int pbn;
41 int aligned_pbn;
42 int num_slots;
43};
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68struct drm_dp_mst_port {
69
70
71
72
73 struct kref topology_kref;
74
75
76
77
78
79
80 struct kref malloc_kref;
81
82 u8 port_num;
83 bool input;
84 bool mcs;
85 bool ddps;
86 u8 pdt;
87 bool ldps;
88 u8 dpcd_rev;
89 u8 num_sdp_streams;
90 u8 num_sdp_stream_sinks;
91 uint16_t available_pbn;
92 struct list_head next;
93 struct drm_dp_mst_branch *mstb;
94 struct drm_dp_aux aux;
95 struct drm_dp_mst_branch *parent;
96
97 struct drm_dp_vcpi vcpi;
98 struct drm_connector *connector;
99 struct drm_dp_mst_topology_mgr *mgr;
100
101
102
103
104
105 struct edid *cached_edid;
106
107
108
109
110 bool has_audio;
111};
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132struct drm_dp_mst_branch {
133
134
135
136
137 struct kref topology_kref;
138
139
140
141
142
143
144 struct kref malloc_kref;
145
146 u8 rad[8];
147 u8 lct;
148 int num_ports;
149
150 int msg_slots;
151 struct list_head ports;
152
153
154 struct drm_dp_mst_port *port_parent;
155 struct drm_dp_mst_topology_mgr *mgr;
156
157
158 struct drm_dp_sideband_msg_tx *tx_slots[2];
159 int last_seqno;
160 bool link_address_sent;
161
162
163 u8 guid[16];
164};
165
166
167
168struct drm_dp_sideband_msg_hdr {
169 u8 lct;
170 u8 lcr;
171 u8 rad[8];
172 bool broadcast;
173 bool path_msg;
174 u8 msg_len;
175 bool somt;
176 bool eomt;
177 bool seqno;
178};
179
180struct drm_dp_nak_reply {
181 u8 guid[16];
182 u8 reason;
183 u8 nak_data;
184};
185
186struct drm_dp_link_address_ack_reply {
187 u8 guid[16];
188 u8 nports;
189 struct drm_dp_link_addr_reply_port {
190 bool input_port;
191 u8 peer_device_type;
192 u8 port_number;
193 bool mcs;
194 bool ddps;
195 bool legacy_device_plug_status;
196 u8 dpcd_revision;
197 u8 peer_guid[16];
198 u8 num_sdp_streams;
199 u8 num_sdp_stream_sinks;
200 } ports[16];
201};
202
203struct drm_dp_remote_dpcd_read_ack_reply {
204 u8 port_number;
205 u8 num_bytes;
206 u8 bytes[255];
207};
208
209struct drm_dp_remote_dpcd_write_ack_reply {
210 u8 port_number;
211};
212
213struct drm_dp_remote_dpcd_write_nak_reply {
214 u8 port_number;
215 u8 reason;
216 u8 bytes_written_before_failure;
217};
218
219struct drm_dp_remote_i2c_read_ack_reply {
220 u8 port_number;
221 u8 num_bytes;
222 u8 bytes[255];
223};
224
225struct drm_dp_remote_i2c_read_nak_reply {
226 u8 port_number;
227 u8 nak_reason;
228 u8 i2c_nak_transaction;
229};
230
231struct drm_dp_remote_i2c_write_ack_reply {
232 u8 port_number;
233};
234
235
236struct drm_dp_sideband_msg_rx {
237 u8 chunk[48];
238 u8 msg[256];
239 u8 curchunk_len;
240 u8 curchunk_idx;
241 u8 curchunk_hdrlen;
242 u8 curlen;
243 bool have_somt;
244 bool have_eomt;
245 struct drm_dp_sideband_msg_hdr initial_hdr;
246};
247
248#define DRM_DP_MAX_SDP_STREAMS 16
249struct drm_dp_allocate_payload {
250 u8 port_number;
251 u8 number_sdp_streams;
252 u8 vcpi;
253 u16 pbn;
254 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
255};
256
257struct drm_dp_allocate_payload_ack_reply {
258 u8 port_number;
259 u8 vcpi;
260 u16 allocated_pbn;
261};
262
263struct drm_dp_connection_status_notify {
264 u8 guid[16];
265 u8 port_number;
266 bool legacy_device_plug_status;
267 bool displayport_device_plug_status;
268 bool message_capability_status;
269 bool input_port;
270 u8 peer_device_type;
271};
272
273struct drm_dp_remote_dpcd_read {
274 u8 port_number;
275 u32 dpcd_address;
276 u8 num_bytes;
277};
278
279struct drm_dp_remote_dpcd_write {
280 u8 port_number;
281 u32 dpcd_address;
282 u8 num_bytes;
283 u8 *bytes;
284};
285
286#define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
287struct drm_dp_remote_i2c_read {
288 u8 num_transactions;
289 u8 port_number;
290 struct {
291 u8 i2c_dev_id;
292 u8 num_bytes;
293 u8 *bytes;
294 u8 no_stop_bit;
295 u8 i2c_transaction_delay;
296 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
297 u8 read_i2c_device_id;
298 u8 num_bytes_read;
299};
300
301struct drm_dp_remote_i2c_write {
302 u8 port_number;
303 u8 write_i2c_device_id;
304 u8 num_bytes;
305 u8 *bytes;
306};
307
308
309struct drm_dp_port_number_req {
310 u8 port_number;
311};
312
313struct drm_dp_enum_path_resources_ack_reply {
314 u8 port_number;
315 u16 full_payload_bw_number;
316 u16 avail_payload_bw_number;
317};
318
319
320struct drm_dp_port_number_rep {
321 u8 port_number;
322};
323
324struct drm_dp_query_payload {
325 u8 port_number;
326 u8 vcpi;
327};
328
329struct drm_dp_resource_status_notify {
330 u8 port_number;
331 u8 guid[16];
332 u16 available_pbn;
333};
334
335struct drm_dp_query_payload_ack_reply {
336 u8 port_number;
337 u8 allocated_pbn;
338};
339
340struct drm_dp_sideband_msg_req_body {
341 u8 req_type;
342 union ack_req {
343 struct drm_dp_connection_status_notify conn_stat;
344 struct drm_dp_port_number_req port_num;
345 struct drm_dp_resource_status_notify resource_stat;
346
347 struct drm_dp_query_payload query_payload;
348 struct drm_dp_allocate_payload allocate_payload;
349
350 struct drm_dp_remote_dpcd_read dpcd_read;
351 struct drm_dp_remote_dpcd_write dpcd_write;
352
353 struct drm_dp_remote_i2c_read i2c_read;
354 struct drm_dp_remote_i2c_write i2c_write;
355 } u;
356};
357
358struct drm_dp_sideband_msg_reply_body {
359 u8 reply_type;
360 u8 req_type;
361 union ack_replies {
362 struct drm_dp_nak_reply nak;
363 struct drm_dp_link_address_ack_reply link_addr;
364 struct drm_dp_port_number_rep port_number;
365
366 struct drm_dp_enum_path_resources_ack_reply path_resources;
367 struct drm_dp_allocate_payload_ack_reply allocate_payload;
368 struct drm_dp_query_payload_ack_reply query_payload;
369
370 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
371 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
372 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
373
374 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
375 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
376 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
377 } u;
378};
379
380
381#define DRM_DP_SIDEBAND_TX_QUEUED 0
382
383#define DRM_DP_SIDEBAND_TX_START_SEND 1
384
385#define DRM_DP_SIDEBAND_TX_SENT 2
386
387#define DRM_DP_SIDEBAND_TX_RX 3
388#define DRM_DP_SIDEBAND_TX_TIMEOUT 4
389
390struct drm_dp_sideband_msg_tx {
391 u8 msg[256];
392 u8 chunk[48];
393 u8 cur_offset;
394 u8 cur_len;
395 struct drm_dp_mst_branch *dst;
396 struct list_head next;
397 int seqno;
398 int state;
399 bool path_msg;
400 struct drm_dp_sideband_msg_reply_body reply;
401};
402
403
404struct drm_dp_mst_topology_mgr;
405struct drm_dp_mst_topology_cbs {
406
407 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
408 void (*register_connector)(struct drm_connector *connector);
409 void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
410 struct drm_connector *connector);
411};
412
413#define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
414
415#define DP_PAYLOAD_LOCAL 1
416#define DP_PAYLOAD_REMOTE 2
417#define DP_PAYLOAD_DELETE_LOCAL 3
418
419struct drm_dp_payload {
420 int payload_state;
421 int start_slot;
422 int num_slots;
423 int vcpi;
424};
425
426#define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
427
428struct drm_dp_vcpi_allocation {
429 struct drm_dp_mst_port *port;
430 int vcpi;
431 struct list_head next;
432};
433
434struct drm_dp_mst_topology_state {
435 struct drm_private_state base;
436 struct list_head vcpis;
437 struct drm_dp_mst_topology_mgr *mgr;
438};
439
440#define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
441
442
443
444
445
446
447
448
449struct drm_dp_mst_topology_mgr {
450
451
452
453 struct drm_private_obj base;
454
455
456
457
458 struct drm_device *dev;
459
460
461
462 const struct drm_dp_mst_topology_cbs *cbs;
463
464
465
466
467 int max_dpcd_transaction_bytes;
468
469
470
471
472 struct drm_dp_aux *aux;
473
474
475
476 int max_payloads;
477
478
479
480
481 int conn_base_id;
482
483
484
485
486
487
488 struct drm_dp_sideband_msg_rx down_rep_recv;
489
490
491
492
493
494 struct drm_dp_sideband_msg_rx up_req_recv;
495
496
497
498
499 struct mutex lock;
500
501
502
503
504
505 bool mst_state;
506
507
508
509 struct drm_dp_mst_branch *mst_primary;
510
511
512
513
514 u8 dpcd[DP_RECEIVER_CAP_SIZE];
515
516
517
518 u8 sink_count;
519
520
521
522 int pbn_div;
523
524
525
526
527 const struct drm_private_state_funcs *funcs;
528
529
530
531
532
533 struct mutex qlock;
534
535
536
537 struct list_head tx_msg_downq;
538
539
540
541
542 struct mutex payload_lock;
543
544
545
546
547 struct drm_dp_vcpi **proposed_vcpis;
548
549
550
551 struct drm_dp_payload *payloads;
552
553
554
555
556
557 unsigned long payload_mask;
558
559
560
561 unsigned long vcpi_mask;
562
563
564
565
566 wait_queue_head_t tx_waitq;
567
568
569
570 struct work_struct work;
571
572
573
574
575 struct work_struct tx_work;
576
577
578
579
580 struct list_head destroy_connector_list;
581
582
583
584 struct mutex destroy_connector_lock;
585
586
587
588
589 struct work_struct destroy_connector_work;
590};
591
592int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
593 struct drm_device *dev, struct drm_dp_aux *aux,
594 int max_dpcd_transaction_bytes,
595 int max_payloads, int conn_base_id);
596
597void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
598
599
600int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
601
602
603int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
604
605
606enum 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);
607
608bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
609 struct drm_dp_mst_port *port);
610struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
611
612
613int drm_dp_calc_pbn_mode(int clock, int bpp);
614
615
616bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
617 struct drm_dp_mst_port *port, int pbn, int slots);
618
619int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
620
621
622void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
623
624
625void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
626 struct drm_dp_mst_port *port);
627
628
629int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
630 int pbn);
631
632
633int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
634
635
636int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
637
638int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
639
640void drm_dp_mst_dump_topology(struct seq_file *m,
641 struct drm_dp_mst_topology_mgr *mgr);
642
643void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
644int __must_check
645drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
646
647ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
648 unsigned int offset, void *buffer, size_t size);
649ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
650 unsigned int offset, void *buffer, size_t size);
651
652int drm_dp_mst_connector_late_register(struct drm_connector *connector,
653 struct drm_dp_mst_port *port);
654void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
655 struct drm_dp_mst_port *port);
656
657struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
658 struct drm_dp_mst_topology_mgr *mgr);
659int __must_check
660drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
661 struct drm_dp_mst_topology_mgr *mgr,
662 struct drm_dp_mst_port *port, int pbn);
663int __must_check
664drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
665 struct drm_dp_mst_topology_mgr *mgr,
666 struct drm_dp_mst_port *port);
667int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
668 struct drm_dp_mst_port *port, bool power_up);
669int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
670
671void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
672void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
673
674extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695static inline bool
696__drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
697 struct drm_dp_mst_topology_mgr **mgr,
698 struct drm_dp_mst_topology_state **old_state,
699 struct drm_dp_mst_topology_state **new_state,
700 int i)
701{
702 struct __drm_private_objs_state *objs_state = &state->private_objs[i];
703
704 if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
705 return false;
706
707 *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
708 if (old_state)
709 *old_state = to_dp_mst_topology_state(objs_state->old_state);
710 if (new_state)
711 *new_state = to_dp_mst_topology_state(objs_state->new_state);
712
713 return true;
714}
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731#define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
732 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
733 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748#define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
749 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
750 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766#define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
767 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
768 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
769
770#endif
771