drm_dp_mst_helper.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * Copyright © 2014 Red Hat.
  3. *
  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.
  13. *
  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
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef _DRM_DP_MST_HELPER_H_
  23. #define _DRM_DP_MST_HELPER_H_
  24. #include <linux/types.h>
  25. #include <drm/drm_dp_helper.h>
  26. struct drm_dp_mst_branch;
  27. /**
  28. * struct drm_dp_vcpi - Virtual Channel Payload Identifier
  29. * @vcpi: Virtual channel ID.
  30. * @pbn: Payload Bandwidth Number for this channel
  31. * @aligned_pbn: PBN aligned with slot size
  32. * @num_slots: number of slots for this PBN
  33. */
  34. struct drm_dp_vcpi {
  35. int vcpi;
  36. int pbn;
  37. int aligned_pbn;
  38. int num_slots;
  39. };
  40. /**
  41. * struct drm_dp_mst_port - MST port
  42. * @kref: reference count for this port.
  43. * @port_num: port number
  44. * @input: if this port is an input port.
  45. * @mcs: message capability status - DP 1.2 spec.
  46. * @ddps: DisplayPort Device Plug Status - DP 1.2
  47. * @pdt: Peer Device Type
  48. * @ldps: Legacy Device Plug Status
  49. * @dpcd_rev: DPCD revision of device on this port
  50. * @num_sdp_streams: Number of simultaneous streams
  51. * @num_sdp_stream_sinks: Number of stream sinks
  52. * @available_pbn: Available bandwidth for this port.
  53. * @next: link to next port on this branch device
  54. * @mstb: branch device attach below this port
  55. * @aux: i2c aux transport to talk to device connected to this port.
  56. * @parent: branch device parent of this port
  57. * @vcpi: Virtual Channel Payload info for this port.
  58. * @connector: DRM connector this port is connected to.
  59. * @mgr: topology manager this port lives under.
  60. *
  61. * This structure represents an MST port endpoint on a device somewhere
  62. * in the MST topology.
  63. */
  64. struct drm_dp_mst_port {
  65. struct kref kref;
  66. u8 port_num;
  67. bool input;
  68. bool mcs;
  69. bool ddps;
  70. u8 pdt;
  71. bool ldps;
  72. u8 dpcd_rev;
  73. u8 num_sdp_streams;
  74. u8 num_sdp_stream_sinks;
  75. uint16_t available_pbn;
  76. struct list_head next;
  77. struct drm_dp_mst_branch *mstb; /* pointer to an mstb if this port has one */
  78. struct drm_dp_aux aux; /* i2c bus for this port? */
  79. struct drm_dp_mst_branch *parent;
  80. struct drm_dp_vcpi vcpi;
  81. struct drm_connector *connector;
  82. struct drm_dp_mst_topology_mgr *mgr;
  83. /**
  84. * @cached_edid: for DP logical ports - make tiling work by ensuring
  85. * that the EDID for all connectors is read immediately.
  86. */
  87. struct edid *cached_edid;
  88. /**
  89. * @has_audio: Tracks whether the sink connector to this port is
  90. * audio-capable.
  91. */
  92. bool has_audio;
  93. };
  94. /**
  95. * struct drm_dp_mst_branch - MST branch device.
  96. * @kref: reference count for this port.
  97. * @rad: Relative Address to talk to this branch device.
  98. * @lct: Link count total to talk to this branch device.
  99. * @num_ports: number of ports on the branch.
  100. * @msg_slots: one bit per transmitted msg slot.
  101. * @ports: linked list of ports on this branch.
  102. * @port_parent: pointer to the port parent, NULL if toplevel.
  103. * @mgr: topology manager for this branch device.
  104. * @tx_slots: transmission slots for this device.
  105. * @last_seqno: last sequence number used to talk to this.
  106. * @link_address_sent: if a link address message has been sent to this device yet.
  107. * @guid: guid for DP 1.2 branch device. port under this branch can be
  108. * identified by port #.
  109. *
  110. * This structure represents an MST branch device, there is one
  111. * primary branch device at the root, along with any other branches connected
  112. * to downstream port of parent branches.
  113. */
  114. struct drm_dp_mst_branch {
  115. struct kref kref;
  116. u8 rad[8];
  117. u8 lct;
  118. int num_ports;
  119. int msg_slots;
  120. struct list_head ports;
  121. /* list of tx ops queue for this port */
  122. struct drm_dp_mst_port *port_parent;
  123. struct drm_dp_mst_topology_mgr *mgr;
  124. /* slots are protected by mstb->mgr->qlock */
  125. struct drm_dp_sideband_msg_tx *tx_slots[2];
  126. int last_seqno;
  127. bool link_address_sent;
  128. /* global unique identifier to identify branch devices */
  129. u8 guid[16];
  130. };
  131. /* sideband msg header - not bit struct */
  132. struct drm_dp_sideband_msg_hdr {
  133. u8 lct;
  134. u8 lcr;
  135. u8 rad[8];
  136. bool broadcast;
  137. bool path_msg;
  138. u8 msg_len;
  139. bool somt;
  140. bool eomt;
  141. bool seqno;
  142. };
  143. struct drm_dp_nak_reply {
  144. u8 guid[16];
  145. u8 reason;
  146. u8 nak_data;
  147. };
  148. struct drm_dp_link_address_ack_reply {
  149. u8 guid[16];
  150. u8 nports;
  151. struct drm_dp_link_addr_reply_port {
  152. bool input_port;
  153. u8 peer_device_type;
  154. u8 port_number;
  155. bool mcs;
  156. bool ddps;
  157. bool legacy_device_plug_status;
  158. u8 dpcd_revision;
  159. u8 peer_guid[16];
  160. u8 num_sdp_streams;
  161. u8 num_sdp_stream_sinks;
  162. } ports[16];
  163. };
  164. struct drm_dp_remote_dpcd_read_ack_reply {
  165. u8 port_number;
  166. u8 num_bytes;
  167. u8 bytes[255];
  168. };
  169. struct drm_dp_remote_dpcd_write_ack_reply {
  170. u8 port_number;
  171. };
  172. struct drm_dp_remote_dpcd_write_nak_reply {
  173. u8 port_number;
  174. u8 reason;
  175. u8 bytes_written_before_failure;
  176. };
  177. struct drm_dp_remote_i2c_read_ack_reply {
  178. u8 port_number;
  179. u8 num_bytes;
  180. u8 bytes[255];
  181. };
  182. struct drm_dp_remote_i2c_read_nak_reply {
  183. u8 port_number;
  184. u8 nak_reason;
  185. u8 i2c_nak_transaction;
  186. };
  187. struct drm_dp_remote_i2c_write_ack_reply {
  188. u8 port_number;
  189. };
  190. struct drm_dp_sideband_msg_rx {
  191. u8 chunk[48];
  192. u8 msg[256];
  193. u8 curchunk_len;
  194. u8 curchunk_idx; /* chunk we are parsing now */
  195. u8 curchunk_hdrlen;
  196. u8 curlen; /* total length of the msg */
  197. bool have_somt;
  198. bool have_eomt;
  199. struct drm_dp_sideband_msg_hdr initial_hdr;
  200. };
  201. #define DRM_DP_MAX_SDP_STREAMS 16
  202. struct drm_dp_allocate_payload {
  203. u8 port_number;
  204. u8 number_sdp_streams;
  205. u8 vcpi;
  206. u16 pbn;
  207. u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
  208. };
  209. struct drm_dp_allocate_payload_ack_reply {
  210. u8 port_number;
  211. u8 vcpi;
  212. u16 allocated_pbn;
  213. };
  214. struct drm_dp_connection_status_notify {
  215. u8 guid[16];
  216. u8 port_number;
  217. bool legacy_device_plug_status;
  218. bool displayport_device_plug_status;
  219. bool message_capability_status;
  220. bool input_port;
  221. u8 peer_device_type;
  222. };
  223. struct drm_dp_remote_dpcd_read {
  224. u8 port_number;
  225. u32 dpcd_address;
  226. u8 num_bytes;
  227. };
  228. struct drm_dp_remote_dpcd_write {
  229. u8 port_number;
  230. u32 dpcd_address;
  231. u8 num_bytes;
  232. u8 *bytes;
  233. };
  234. #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
  235. struct drm_dp_remote_i2c_read {
  236. u8 num_transactions;
  237. u8 port_number;
  238. struct {
  239. u8 i2c_dev_id;
  240. u8 num_bytes;
  241. u8 *bytes;
  242. u8 no_stop_bit;
  243. u8 i2c_transaction_delay;
  244. } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
  245. u8 read_i2c_device_id;
  246. u8 num_bytes_read;
  247. };
  248. struct drm_dp_remote_i2c_write {
  249. u8 port_number;
  250. u8 write_i2c_device_id;
  251. u8 num_bytes;
  252. u8 *bytes;
  253. };
  254. /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
  255. struct drm_dp_port_number_req {
  256. u8 port_number;
  257. };
  258. struct drm_dp_enum_path_resources_ack_reply {
  259. u8 port_number;
  260. u16 full_payload_bw_number;
  261. u16 avail_payload_bw_number;
  262. };
  263. /* covers POWER_DOWN_PHY, POWER_UP_PHY */
  264. struct drm_dp_port_number_rep {
  265. u8 port_number;
  266. };
  267. struct drm_dp_query_payload {
  268. u8 port_number;
  269. u8 vcpi;
  270. };
  271. struct drm_dp_resource_status_notify {
  272. u8 port_number;
  273. u8 guid[16];
  274. u16 available_pbn;
  275. };
  276. struct drm_dp_query_payload_ack_reply {
  277. u8 port_number;
  278. u8 allocated_pbn;
  279. };
  280. struct drm_dp_sideband_msg_req_body {
  281. u8 req_type;
  282. union ack_req {
  283. struct drm_dp_connection_status_notify conn_stat;
  284. struct drm_dp_port_number_req port_num;
  285. struct drm_dp_resource_status_notify resource_stat;
  286. struct drm_dp_query_payload query_payload;
  287. struct drm_dp_allocate_payload allocate_payload;
  288. struct drm_dp_remote_dpcd_read dpcd_read;
  289. struct drm_dp_remote_dpcd_write dpcd_write;
  290. struct drm_dp_remote_i2c_read i2c_read;
  291. struct drm_dp_remote_i2c_write i2c_write;
  292. } u;
  293. };
  294. struct drm_dp_sideband_msg_reply_body {
  295. u8 reply_type;
  296. u8 req_type;
  297. union ack_replies {
  298. struct drm_dp_nak_reply nak;
  299. struct drm_dp_link_address_ack_reply link_addr;
  300. struct drm_dp_port_number_rep port_number;
  301. struct drm_dp_enum_path_resources_ack_reply path_resources;
  302. struct drm_dp_allocate_payload_ack_reply allocate_payload;
  303. struct drm_dp_query_payload_ack_reply query_payload;
  304. struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
  305. struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
  306. struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
  307. struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
  308. struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
  309. struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
  310. } u;
  311. };
  312. /* msg is queued to be put into a slot */
  313. #define DRM_DP_SIDEBAND_TX_QUEUED 0
  314. /* msg has started transmitting on a slot - still on msgq */
  315. #define DRM_DP_SIDEBAND_TX_START_SEND 1
  316. /* msg has finished transmitting on a slot - removed from msgq only in slot */
  317. #define DRM_DP_SIDEBAND_TX_SENT 2
  318. /* msg has received a response - removed from slot */
  319. #define DRM_DP_SIDEBAND_TX_RX 3
  320. #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
  321. struct drm_dp_sideband_msg_tx {
  322. u8 msg[256];
  323. u8 chunk[48];
  324. u8 cur_offset;
  325. u8 cur_len;
  326. struct drm_dp_mst_branch *dst;
  327. struct list_head next;
  328. int seqno;
  329. int state;
  330. bool path_msg;
  331. struct drm_dp_sideband_msg_reply_body reply;
  332. };
  333. /* sideband msg handler */
  334. struct drm_dp_mst_topology_mgr;
  335. struct drm_dp_mst_topology_cbs {
  336. /* create a connector for a port */
  337. struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
  338. void (*register_connector)(struct drm_connector *connector);
  339. void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
  340. struct drm_connector *connector);
  341. void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
  342. };
  343. #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
  344. #define DP_PAYLOAD_LOCAL 1
  345. #define DP_PAYLOAD_REMOTE 2
  346. #define DP_PAYLOAD_DELETE_LOCAL 3
  347. struct drm_dp_payload {
  348. int payload_state;
  349. int start_slot;
  350. int num_slots;
  351. int vcpi;
  352. };
  353. /**
  354. * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
  355. *
  356. * This struct represents the toplevel displayport MST topology manager.
  357. * There should be one instance of this for every MST capable DP connector
  358. * on the GPU.
  359. */
  360. struct drm_dp_mst_topology_mgr {
  361. /**
  362. * @dev: device pointer for adding i2c devices etc.
  363. */
  364. struct device *dev;
  365. /**
  366. * @cbs: callbacks for connector addition and destruction.
  367. */
  368. const struct drm_dp_mst_topology_cbs *cbs;
  369. /**
  370. * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
  371. * in one go.
  372. */
  373. int max_dpcd_transaction_bytes;
  374. /**
  375. * @aux: AUX channel for the DP MST connector this topolgy mgr is
  376. * controlling.
  377. */
  378. struct drm_dp_aux *aux;
  379. /**
  380. * @max_payloads: maximum number of payloads the GPU can generate.
  381. */
  382. int max_payloads;
  383. /**
  384. * @conn_base_id: DRM connector ID this mgr is connected to. Only used
  385. * to build the MST connector path value.
  386. */
  387. int conn_base_id;
  388. /**
  389. * @down_rep_recv: Message receiver state for down replies. This and
  390. * @up_req_recv are only ever access from the work item, which is
  391. * serialised.
  392. */
  393. struct drm_dp_sideband_msg_rx down_rep_recv;
  394. /**
  395. * @up_req_recv: Message receiver state for up requests. This and
  396. * @down_rep_recv are only ever access from the work item, which is
  397. * serialised.
  398. */
  399. struct drm_dp_sideband_msg_rx up_req_recv;
  400. /**
  401. * @lock: protects mst state, primary, dpcd.
  402. */
  403. struct mutex lock;
  404. /**
  405. * @mst_state: If this manager is enabled for an MST capable port. False
  406. * if no MST sink/branch devices is connected.
  407. */
  408. bool mst_state;
  409. /**
  410. * @mst_primary: Pointer to the primary/first branch device.
  411. */
  412. struct drm_dp_mst_branch *mst_primary;
  413. /**
  414. * @dpcd: Cache of DPCD for primary port.
  415. */
  416. u8 dpcd[DP_RECEIVER_CAP_SIZE];
  417. /**
  418. * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
  419. */
  420. u8 sink_count;
  421. /**
  422. * @pbn_div: PBN to slots divisor.
  423. */
  424. int pbn_div;
  425. /**
  426. * @total_slots: Total slots that can be allocated.
  427. */
  428. int total_slots;
  429. /**
  430. * @avail_slots: Still available slots that can be allocated.
  431. */
  432. int avail_slots;
  433. /**
  434. * @total_pbn: Total PBN count.
  435. */
  436. int total_pbn;
  437. /**
  438. * @qlock: protects @tx_msg_downq, the tx_slots in struct
  439. * &drm_dp_mst_branch and txmsg->state once they are queued
  440. */
  441. struct mutex qlock;
  442. /**
  443. * @tx_msg_downq: List of pending down replies.
  444. */
  445. struct list_head tx_msg_downq;
  446. /**
  447. * @payload_lock: Protect payload information.
  448. */
  449. struct mutex payload_lock;
  450. /**
  451. * @proposed_vcpis: Array of pointers for the new VCPI allocation. The
  452. * VCPI structure itself is embedded into the corresponding
  453. * &drm_dp_mst_port structure.
  454. */
  455. struct drm_dp_vcpi **proposed_vcpis;
  456. /**
  457. * @payloads: Array of payloads.
  458. */
  459. struct drm_dp_payload *payloads;
  460. /**
  461. * @payload_mask: Elements of @payloads actually in use. Since
  462. * reallocation of active outputs isn't possible gaps can be created by
  463. * disabling outputs out of order compared to how they've been enabled.
  464. */
  465. unsigned long payload_mask;
  466. /**
  467. * @vcpi_mask: Similar to @payload_mask, but for @proposed_vcpis.
  468. */
  469. unsigned long vcpi_mask;
  470. /**
  471. * @tx_waitq: Wait to queue stall for the tx worker.
  472. */
  473. wait_queue_head_t tx_waitq;
  474. /**
  475. * @work: Probe work.
  476. */
  477. struct work_struct work;
  478. /**
  479. * @tx_work: Sideband transmit worker. This can nest within the main
  480. * @work worker for each transaction @work launches.
  481. */
  482. struct work_struct tx_work;
  483. /**
  484. * @destroy_connector_list: List of to be destroyed connectors.
  485. */
  486. struct list_head destroy_connector_list;
  487. /**
  488. * @destroy_connector_lock: Protects @connector_list.
  489. */
  490. struct mutex destroy_connector_lock;
  491. /**
  492. * @destroy_connector_work: Work item to destroy connectors. Needed to
  493. * avoid locking inversion.
  494. */
  495. struct work_struct destroy_connector_work;
  496. };
  497. 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);
  498. void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
  499. int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
  500. int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
  501. 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);
  502. bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
  503. struct drm_dp_mst_port *port);
  504. struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  505. int drm_dp_calc_pbn_mode(int clock, int bpp);
  506. bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots);
  507. int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  508. void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  509. void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
  510. struct drm_dp_mst_port *port);
  511. int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
  512. int pbn);
  513. int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
  514. int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
  515. int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
  516. void drm_dp_mst_dump_topology(struct seq_file *m,
  517. struct drm_dp_mst_topology_mgr *mgr);
  518. void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
  519. int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
  520. #endif