drm_dp_mst_helper.h 14 KB

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