drm_dp_mst_helper.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. struct edid *cached_edid; /* for DP logical ports - make tiling work */
  84. };
  85. /**
  86. * struct drm_dp_mst_branch - MST branch device.
  87. * @kref: reference count for this port.
  88. * @rad: Relative Address to talk to this branch device.
  89. * @lct: Link count total to talk to this branch device.
  90. * @num_ports: number of ports on the branch.
  91. * @msg_slots: one bit per transmitted msg slot.
  92. * @ports: linked list of ports on this branch.
  93. * @port_parent: pointer to the port parent, NULL if toplevel.
  94. * @mgr: topology manager for this branch device.
  95. * @tx_slots: transmission slots for this device.
  96. * @last_seqno: last sequence number used to talk to this.
  97. * @link_address_sent: if a link address message has been sent to this device yet.
  98. * @guid: guid for DP 1.2 branch device. port under this branch can be
  99. * identified by port #.
  100. *
  101. * This structure represents an MST branch device, there is one
  102. * primary branch device at the root, along with any other branches connected
  103. * to downstream port of parent branches.
  104. */
  105. struct drm_dp_mst_branch {
  106. struct kref kref;
  107. u8 rad[8];
  108. u8 lct;
  109. int num_ports;
  110. int msg_slots;
  111. struct list_head ports;
  112. /* list of tx ops queue for this port */
  113. struct drm_dp_mst_port *port_parent;
  114. struct drm_dp_mst_topology_mgr *mgr;
  115. /* slots are protected by mstb->mgr->qlock */
  116. struct drm_dp_sideband_msg_tx *tx_slots[2];
  117. int last_seqno;
  118. bool link_address_sent;
  119. /* global unique identifier to identify branch devices */
  120. u8 guid[16];
  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. #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
  225. struct drm_dp_remote_i2c_read {
  226. u8 num_transactions;
  227. u8 port_number;
  228. struct {
  229. u8 i2c_dev_id;
  230. u8 num_bytes;
  231. u8 *bytes;
  232. u8 no_stop_bit;
  233. u8 i2c_transaction_delay;
  234. } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
  235. u8 read_i2c_device_id;
  236. u8 num_bytes_read;
  237. };
  238. struct drm_dp_remote_i2c_write {
  239. u8 port_number;
  240. u8 write_i2c_device_id;
  241. u8 num_bytes;
  242. u8 *bytes;
  243. };
  244. /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
  245. struct drm_dp_port_number_req {
  246. u8 port_number;
  247. };
  248. struct drm_dp_enum_path_resources_ack_reply {
  249. u8 port_number;
  250. u16 full_payload_bw_number;
  251. u16 avail_payload_bw_number;
  252. };
  253. /* covers POWER_DOWN_PHY, POWER_UP_PHY */
  254. struct drm_dp_port_number_rep {
  255. u8 port_number;
  256. };
  257. struct drm_dp_query_payload {
  258. u8 port_number;
  259. u8 vcpi;
  260. };
  261. struct drm_dp_resource_status_notify {
  262. u8 port_number;
  263. u8 guid[16];
  264. u16 available_pbn;
  265. };
  266. struct drm_dp_query_payload_ack_reply {
  267. u8 port_number;
  268. u8 allocated_pbn;
  269. };
  270. struct drm_dp_sideband_msg_req_body {
  271. u8 req_type;
  272. union ack_req {
  273. struct drm_dp_connection_status_notify conn_stat;
  274. struct drm_dp_port_number_req port_num;
  275. struct drm_dp_resource_status_notify resource_stat;
  276. struct drm_dp_query_payload query_payload;
  277. struct drm_dp_allocate_payload allocate_payload;
  278. struct drm_dp_remote_dpcd_read dpcd_read;
  279. struct drm_dp_remote_dpcd_write dpcd_write;
  280. struct drm_dp_remote_i2c_read i2c_read;
  281. struct drm_dp_remote_i2c_write i2c_write;
  282. } u;
  283. };
  284. struct drm_dp_sideband_msg_reply_body {
  285. u8 reply_type;
  286. u8 req_type;
  287. union ack_replies {
  288. struct drm_dp_nak_reply nak;
  289. struct drm_dp_link_address_ack_reply link_addr;
  290. struct drm_dp_port_number_rep port_number;
  291. struct drm_dp_enum_path_resources_ack_reply path_resources;
  292. struct drm_dp_allocate_payload_ack_reply allocate_payload;
  293. struct drm_dp_query_payload_ack_reply query_payload;
  294. struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
  295. struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
  296. struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
  297. struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
  298. struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
  299. struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
  300. } u;
  301. };
  302. /* msg is queued to be put into a slot */
  303. #define DRM_DP_SIDEBAND_TX_QUEUED 0
  304. /* msg has started transmitting on a slot - still on msgq */
  305. #define DRM_DP_SIDEBAND_TX_START_SEND 1
  306. /* msg has finished transmitting on a slot - removed from msgq only in slot */
  307. #define DRM_DP_SIDEBAND_TX_SENT 2
  308. /* msg has received a response - removed from slot */
  309. #define DRM_DP_SIDEBAND_TX_RX 3
  310. #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
  311. struct drm_dp_sideband_msg_tx {
  312. u8 msg[256];
  313. u8 chunk[48];
  314. u8 cur_offset;
  315. u8 cur_len;
  316. struct drm_dp_mst_branch *dst;
  317. struct list_head next;
  318. int seqno;
  319. int state;
  320. bool path_msg;
  321. struct drm_dp_sideband_msg_reply_body reply;
  322. };
  323. /* sideband msg handler */
  324. struct drm_dp_mst_topology_mgr;
  325. struct drm_dp_mst_topology_cbs {
  326. /* create a connector for a port */
  327. struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
  328. void (*register_connector)(struct drm_connector *connector);
  329. void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
  330. struct drm_connector *connector);
  331. void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
  332. };
  333. #define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
  334. #define DP_PAYLOAD_LOCAL 1
  335. #define DP_PAYLOAD_REMOTE 2
  336. #define DP_PAYLOAD_DELETE_LOCAL 3
  337. struct drm_dp_payload {
  338. int payload_state;
  339. int start_slot;
  340. int num_slots;
  341. int vcpi;
  342. };
  343. /**
  344. * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
  345. * @dev: device pointer for adding i2c devices etc.
  346. * @cbs: callbacks for connector addition and destruction.
  347. * @max_dpcd_transaction_bytes - maximum number of bytes to read/write in one go.
  348. * @aux: aux channel for the DP connector.
  349. * @max_payloads: maximum number of payloads the GPU can generate.
  350. * @conn_base_id: DRM connector ID this mgr is connected to.
  351. * @down_rep_recv: msg receiver state for down replies.
  352. * @up_req_recv: msg receiver state for up requests.
  353. * @lock: protects mst state, primary, dpcd.
  354. * @mst_state: if this manager is enabled for an MST capable port.
  355. * @mst_primary: pointer to the primary branch device.
  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 + dpcd */
  375. bool mst_state;
  376. struct drm_dp_mst_branch *mst_primary;
  377. u8 dpcd[DP_RECEIVER_CAP_SIZE];
  378. u8 sink_count;
  379. int pbn_div;
  380. int total_slots;
  381. int avail_slots;
  382. int total_pbn;
  383. /* messages to be transmitted */
  384. /* qlock protects the upq/downq and in_progress,
  385. the mstb tx_slots and txmsg->state once they are queued */
  386. struct mutex qlock;
  387. struct list_head tx_msg_downq;
  388. bool tx_down_in_progress;
  389. /* payload info + lock for it */
  390. struct mutex payload_lock;
  391. struct drm_dp_vcpi **proposed_vcpis;
  392. struct drm_dp_payload *payloads;
  393. unsigned long payload_mask;
  394. unsigned long vcpi_mask;
  395. wait_queue_head_t tx_waitq;
  396. struct work_struct work;
  397. struct work_struct tx_work;
  398. struct list_head destroy_connector_list;
  399. struct mutex destroy_connector_lock;
  400. struct work_struct destroy_connector_work;
  401. };
  402. 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);
  403. void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
  404. int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
  405. int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
  406. 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);
  407. struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  408. int drm_dp_calc_pbn_mode(int clock, int bpp);
  409. bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots);
  410. int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  411. void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
  412. void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
  413. struct drm_dp_mst_port *port);
  414. int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
  415. int pbn);
  416. int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
  417. int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
  418. int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
  419. void drm_dp_mst_dump_topology(struct seq_file *m,
  420. struct drm_dp_mst_topology_mgr *mgr);
  421. void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
  422. int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
  423. #endif