drm_dp_mst_helper.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. * @guid_valid: for DP 1.2 devices if we have validated the GUID.
  44. * @guid: guid for DP 1.2 device on this port.
  45. * @port_num: port number
  46. * @input: if this port is an input port.
  47. * @mcs: message capability status - DP 1.2 spec.
  48. * @ddps: DisplayPort Device Plug Status - DP 1.2
  49. * @pdt: Peer Device Type
  50. * @ldps: Legacy Device Plug Status
  51. * @dpcd_rev: DPCD revision of device on this port
  52. * @num_sdp_streams: Number of simultaneous streams
  53. * @num_sdp_stream_sinks: Number of stream sinks
  54. * @available_pbn: Available bandwidth for this port.
  55. * @next: link to next port on this branch device
  56. * @mstb: branch device attach below this port
  57. * @aux: i2c aux transport to talk to device connected to this port.
  58. * @parent: branch device parent of this port
  59. * @vcpi: Virtual Channel Payload info for this port.
  60. * @connector: DRM connector this port is connected to.
  61. * @mgr: topology manager this port lives under.
  62. *
  63. * This structure represents an MST port endpoint on a device somewhere
  64. * in the MST topology.
  65. */
  66. struct drm_dp_mst_port {
  67. struct kref kref;
  68. /* if dpcd 1.2 device is on this port - its GUID info */
  69. bool guid_valid;
  70. u8 guid[16];
  71. u8 port_num;
  72. bool input;
  73. bool mcs;
  74. bool ddps;
  75. u8 pdt;
  76. bool ldps;
  77. u8 dpcd_rev;
  78. u8 num_sdp_streams;
  79. u8 num_sdp_stream_sinks;
  80. uint16_t available_pbn;
  81. struct list_head next;
  82. struct drm_dp_mst_branch *mstb; /* pointer to an mstb if this port has one */
  83. struct drm_dp_aux aux; /* i2c bus for this port? */
  84. struct drm_dp_mst_branch *parent;
  85. struct drm_dp_vcpi vcpi;
  86. struct drm_connector *connector;
  87. struct drm_dp_mst_topology_mgr *mgr;
  88. struct edid *cached_edid; /* for DP logical ports - make tiling work */
  89. bool has_audio;
  90. };
  91. /**
  92. * struct drm_dp_mst_branch - MST branch device.
  93. * @kref: reference count for this port.
  94. * @rad: Relative Address to talk to this branch device.
  95. * @lct: Link count total to talk to this branch device.
  96. * @num_ports: number of ports on the branch.
  97. * @msg_slots: one bit per transmitted msg slot.
  98. * @ports: linked list of ports on this branch.
  99. * @port_parent: pointer to the port parent, NULL if toplevel.
  100. * @mgr: topology manager for this branch device.
  101. * @tx_slots: transmission slots for this device.
  102. * @last_seqno: last sequence number used to talk to this.
  103. * @link_address_sent: if a link address message has been sent to this device yet.
  104. *
  105. * This structure represents an MST branch device, there is one
  106. * primary branch device at the root, along with any others connected
  107. * to downstream ports
  108. */
  109. struct drm_dp_mst_branch {
  110. struct kref kref;
  111. u8 rad[8];
  112. u8 lct;
  113. int num_ports;
  114. int msg_slots;
  115. struct list_head ports;
  116. /* list of tx ops queue for this port */
  117. struct drm_dp_mst_port *port_parent;
  118. struct drm_dp_mst_topology_mgr *mgr;
  119. /* slots are protected by mstb->mgr->qlock */
  120. struct drm_dp_sideband_msg_tx *tx_slots[2];
  121. int last_seqno;
  122. bool link_address_sent;
  123. };
  124. /* sideband msg header - not bit struct */
  125. struct drm_dp_sideband_msg_hdr {
  126. u8 lct;
  127. u8 lcr;
  128. u8 rad[8];
  129. bool broadcast;
  130. bool path_msg;
  131. u8 msg_len;
  132. bool somt;
  133. bool eomt;
  134. bool seqno;
  135. };
  136. struct drm_dp_nak_reply {
  137. u8 guid[16];
  138. u8 reason;
  139. u8 nak_data;
  140. };
  141. struct drm_dp_link_address_ack_reply {
  142. u8 guid[16];
  143. u8 nports;
  144. struct drm_dp_link_addr_reply_port {
  145. bool input_port;
  146. u8 peer_device_type;
  147. u8 port_number;
  148. bool mcs;
  149. bool ddps;
  150. bool legacy_device_plug_status;
  151. u8 dpcd_revision;
  152. u8 peer_guid[16];
  153. u8 num_sdp_streams;
  154. u8 num_sdp_stream_sinks;
  155. } ports[16];
  156. };
  157. struct drm_dp_remote_dpcd_read_ack_reply {
  158. u8 port_number;
  159. u8 num_bytes;
  160. u8 bytes[255];
  161. };
  162. struct drm_dp_remote_dpcd_write_ack_reply {
  163. u8 port_number;
  164. };
  165. struct drm_dp_remote_dpcd_write_nak_reply {
  166. u8 port_number;
  167. u8 reason;
  168. u8 bytes_written_before_failure;
  169. };
  170. struct drm_dp_remote_i2c_read_ack_reply {
  171. u8 port_number;
  172. u8 num_bytes;
  173. u8 bytes[255];
  174. };
  175. struct drm_dp_remote_i2c_read_nak_reply {
  176. u8 port_number;
  177. u8 nak_reason;
  178. u8 i2c_nak_transaction;
  179. };
  180. struct drm_dp_remote_i2c_write_ack_reply {
  181. u8 port_number;
  182. };
  183. struct drm_dp_sideband_msg_rx {
  184. u8 chunk[48];
  185. u8 msg[256];
  186. u8 curchunk_len;
  187. u8 curchunk_idx; /* chunk we are parsing now */
  188. u8 curchunk_hdrlen;
  189. u8 curlen; /* total length of the msg */
  190. bool have_somt;
  191. bool have_eomt;
  192. struct drm_dp_sideband_msg_hdr initial_hdr;
  193. };
  194. #define DRM_DP_MAX_SDP_STREAMS 16
  195. struct drm_dp_allocate_payload {
  196. u8 port_number;
  197. u8 number_sdp_streams;
  198. u8 vcpi;
  199. u16 pbn;
  200. u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
  201. };
  202. struct drm_dp_allocate_payload_ack_reply {
  203. u8 port_number;
  204. u8 vcpi;
  205. u16 allocated_pbn;
  206. };
  207. struct drm_dp_connection_status_notify {
  208. u8 guid[16];
  209. u8 port_number;
  210. bool legacy_device_plug_status;
  211. bool displayport_device_plug_status;
  212. bool message_capability_status;
  213. bool input_port;
  214. u8 peer_device_type;
  215. };
  216. struct drm_dp_remote_dpcd_read {
  217. u8 port_number;
  218. u32 dpcd_address;
  219. u8 num_bytes;
  220. };
  221. struct drm_dp_remote_dpcd_write {
  222. u8 port_number;
  223. u32 dpcd_address;
  224. u8 num_bytes;
  225. u8 *bytes;
  226. };
  227. #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
  228. struct drm_dp_remote_i2c_read {
  229. u8 num_transactions;
  230. u8 port_number;
  231. struct {
  232. u8 i2c_dev_id;
  233. u8 num_bytes;
  234. u8 *bytes;
  235. u8 no_stop_bit;
  236. u8 i2c_transaction_delay;
  237. } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
  238. u8 read_i2c_device_id;
  239. u8 num_bytes_read;
  240. };
  241. struct drm_dp_remote_i2c_write {
  242. u8 port_number;
  243. u8 write_i2c_device_id;
  244. u8 num_bytes;
  245. u8 *bytes;
  246. };
  247. /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
  248. struct drm_dp_port_number_req {
  249. u8 port_number;
  250. };
  251. struct drm_dp_enum_path_resources_ack_reply {
  252. u8 port_number;
  253. u16 full_payload_bw_number;
  254. u16 avail_payload_bw_number;
  255. };
  256. /* covers POWER_DOWN_PHY, POWER_UP_PHY */
  257. struct drm_dp_port_number_rep {
  258. u8 port_number;
  259. };
  260. struct drm_dp_query_payload {
  261. u8 port_number;
  262. u8 vcpi;
  263. };
  264. struct drm_dp_resource_status_notify {
  265. u8 port_number;
  266. u8 guid[16];
  267. u16 available_pbn;
  268. };
  269. struct drm_dp_query_payload_ack_reply {
  270. u8 port_number;
  271. u8 allocated_pbn;
  272. };
  273. struct drm_dp_sideband_msg_req_body {
  274. u8 req_type;
  275. union ack_req {
  276. struct drm_dp_connection_status_notify conn_stat;
  277. struct drm_dp_port_number_req port_num;
  278. struct drm_dp_resource_status_notify resource_stat;
  279. struct drm_dp_query_payload query_payload;
  280. struct drm_dp_allocate_payload allocate_payload;
  281. struct drm_dp_remote_dpcd_read dpcd_read;
  282. struct drm_dp_remote_dpcd_write dpcd_write;
  283. struct drm_dp_remote_i2c_read i2c_read;
  284. struct drm_dp_remote_i2c_write i2c_write;
  285. } u;
  286. };
  287. struct drm_dp_sideband_msg_reply_body {
  288. u8 reply_type;
  289. u8 req_type;
  290. union ack_replies {
  291. struct drm_dp_nak_reply nak;
  292. struct drm_dp_link_address_ack_reply link_addr;
  293. struct drm_dp_port_number_rep port_number;
  294. struct drm_dp_enum_path_resources_ack_reply path_resources;
  295. struct drm_dp_allocate_payload_ack_reply allocate_payload;
  296. struct drm_dp_query_payload_ack_reply query_payload;
  297. struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
  298. struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
  299. struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
  300. struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
  301. struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
  302. struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
  303. } u;
  304. };
  305. /* msg is queued to be put into a slot */
  306. #define DRM_DP_SIDEBAND_TX_QUEUED 0
  307. /* msg has started transmitting on a slot - still on msgq */
  308. #define DRM_DP_SIDEBAND_TX_START_SEND 1
  309. /* msg has finished transmitting on a slot - removed from msgq only in slot */
  310. #define DRM_DP_SIDEBAND_TX_SENT 2
  311. /* msg has received a response - removed from slot */
  312. #define DRM_DP_SIDEBAND_TX_RX 3
  313. #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
  314. struct drm_dp_sideband_msg_tx {
  315. u8 msg[256];
  316. u8 chunk[48];
  317. u8 cur_offset;
  318. u8 cur_len;
  319. struct drm_dp_mst_branch *dst;
  320. struct list_head next;
  321. int seqno;
  322. int state;
  323. bool path_msg;
  324. struct drm_dp_sideband_msg_reply_body reply;
  325. };
  326. /* sideband msg handler */
  327. struct drm_dp_mst_topology_mgr;
  328. struct drm_dp_mst_topology_cbs {
  329. /* create a connector for a port */
  330. struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
  331. void (*register_connector)(struct drm_connector *connector);
  332. void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
  333. struct drm_connector *connector);
  334. void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
  335. };
  336. #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
  337. #define DP_PAYLOAD_LOCAL 1
  338. #define DP_PAYLOAD_REMOTE 2
  339. #define DP_PAYLOAD_DELETE_LOCAL 3
  340. struct drm_dp_payload {
  341. int payload_state;
  342. int start_slot;
  343. int num_slots;
  344. int vcpi;
  345. };
  346. /**
  347. * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
  348. * @dev: device pointer for adding i2c devices etc.
  349. * @cbs: callbacks for connector addition and destruction.
  350. * @max_dpcd_transaction_bytes - maximum number of bytes to read/write in one go.
  351. * @aux: aux channel for the DP connector.
  352. * @max_payloads: maximum number of payloads the GPU can generate.
  353. * @conn_base_id: DRM connector ID this mgr is connected to.
  354. * @down_rep_recv: msg receiver state for down replies.
  355. * @up_req_recv: msg receiver state for up requests.
  356. * @lock: protects mst state, primary, guid, dpcd.
  357. * @mst_state: if this manager is enabled for an MST capable port.
  358. * @mst_primary: pointer to the primary branch device.
  359. * @guid_valid: GUID valid for the primary branch device.
  360. * @guid: GUID for primary port.
  361. * @dpcd: cache of DPCD for primary port.
  362. * @pbn_div: PBN to slots divisor.
  363. *
  364. * This struct represents the toplevel displayport MST topology manager.
  365. * There should be one instance of this for every MST capable DP connector
  366. * on the GPU.
  367. */
  368. struct drm_dp_mst_topology_mgr {
  369. struct device *dev;
  370. struct drm_dp_mst_topology_cbs *cbs;
  371. int max_dpcd_transaction_bytes;
  372. struct drm_dp_aux *aux; /* auxch for this topology mgr to use */
  373. int max_payloads;
  374. int conn_base_id;
  375. /* only ever accessed from the workqueue - which should be serialised */
  376. struct drm_dp_sideband_msg_rx down_rep_recv;
  377. struct drm_dp_sideband_msg_rx up_req_recv;
  378. /* pointer to info about the initial MST device */
  379. struct mutex lock; /* protects mst_state + primary + guid + dpcd */
  380. bool mst_state;
  381. struct drm_dp_mst_branch *mst_primary;
  382. /* primary MST device GUID */
  383. bool guid_valid;
  384. u8 guid[16];
  385. u8 dpcd[DP_RECEIVER_CAP_SIZE];
  386. u8 sink_count;
  387. int pbn_div;
  388. int total_slots;
  389. int avail_slots;
  390. int total_pbn;
  391. /* messages to be transmitted */
  392. /* qlock protects the upq/downq and in_progress,
  393. the mstb tx_slots and txmsg->state once they are queued */
  394. struct mutex qlock;
  395. struct list_head tx_msg_downq;
  396. bool tx_down_in_progress;
  397. /* payload info + lock for it */
  398. struct mutex payload_lock;
  399. struct drm_dp_vcpi **proposed_vcpis;
  400. struct drm_dp_payload *payloads;
  401. unsigned long payload_mask;
  402. unsigned long vcpi_mask;
  403. wait_queue_head_t tx_waitq;
  404. struct work_struct work;
  405. struct work_struct tx_work;
  406. struct list_head destroy_connector_list;
  407. struct mutex destroy_connector_lock;
  408. struct work_struct destroy_connector_work;
  409. };
  410. 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);
  411. void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
  412. int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
  413. int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
  414. 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);
  415. bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
  416. struct drm_dp_mst_port *port);
  417. struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  418. int drm_dp_calc_pbn_mode(int clock, int bpp);
  419. bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots);
  420. int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  421. void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  422. void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
  423. struct drm_dp_mst_port *port);
  424. int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
  425. int pbn);
  426. int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
  427. int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
  428. int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
  429. void drm_dp_mst_dump_topology(struct seq_file *m,
  430. struct drm_dp_mst_topology_mgr *mgr);
  431. void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
  432. int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
  433. #endif