gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / misc / mei / hdcp / mei_hdcp.c
blob4c596c646ac0978e4295a9731d67a63983b627df
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright © 2019 Intel Corporation
5 * mei_hdcp.c: HDCP client driver for mei bus
7 * Author:
8 * Ramalingam C <ramalingam.c@intel.com>
9 */
11 /**
12 * DOC: MEI_HDCP Client Driver
14 * The mei_hdcp driver acts as a translation layer between HDCP 2.2
15 * protocol implementer (I915) and ME FW by translating HDCP2.2
16 * negotiation messages to ME FW command payloads and vice versa.
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/uuid.h>
22 #include <linux/mei_cl_bus.h>
23 #include <linux/component.h>
24 #include <drm/drm_connector.h>
25 #include <drm/i915_component.h>
26 #include <drm/i915_mei_hdcp_interface.h>
28 #include "mei_hdcp.h"
30 /**
31 * mei_hdcp_initiate_session() - Initiate a Wired HDCP2.2 Tx Session in ME FW
32 * @dev: device corresponding to the mei_cl_device
33 * @data: Intel HW specific hdcp data
34 * @ake_data: AKE_Init msg output.
36 * Return: 0 on Success, <0 on Failure.
38 static int
39 mei_hdcp_initiate_session(struct device *dev, struct hdcp_port_data *data,
40 struct hdcp2_ake_init *ake_data)
42 struct wired_cmd_initiate_hdcp2_session_in session_init_in = { { 0 } };
43 struct wired_cmd_initiate_hdcp2_session_out
44 session_init_out = { { 0 } };
45 struct mei_cl_device *cldev;
46 ssize_t byte;
48 if (!dev || !data || !ake_data)
49 return -EINVAL;
51 cldev = to_mei_cl_device(dev);
53 session_init_in.header.api_version = HDCP_API_VERSION;
54 session_init_in.header.command_id = WIRED_INITIATE_HDCP2_SESSION;
55 session_init_in.header.status = ME_HDCP_STATUS_SUCCESS;
56 session_init_in.header.buffer_len =
57 WIRED_CMD_BUF_LEN_INITIATE_HDCP2_SESSION_IN;
59 session_init_in.port.integrated_port_type = data->port_type;
60 session_init_in.port.physical_port = (u8)data->fw_ddi;
61 session_init_in.port.attached_transcoder = (u8)data->fw_tc;
62 session_init_in.protocol = data->protocol;
64 byte = mei_cldev_send(cldev, (u8 *)&session_init_in,
65 sizeof(session_init_in));
66 if (byte < 0) {
67 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
68 return byte;
71 byte = mei_cldev_recv(cldev, (u8 *)&session_init_out,
72 sizeof(session_init_out));
73 if (byte < 0) {
74 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
75 return byte;
78 if (session_init_out.header.status != ME_HDCP_STATUS_SUCCESS) {
79 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
80 WIRED_INITIATE_HDCP2_SESSION,
81 session_init_out.header.status);
82 return -EIO;
85 ake_data->msg_id = HDCP_2_2_AKE_INIT;
86 ake_data->tx_caps = session_init_out.tx_caps;
87 memcpy(ake_data->r_tx, session_init_out.r_tx, HDCP_2_2_RTX_LEN);
89 return 0;
92 /**
93 * mei_hdcp_verify_receiver_cert_prepare_km() - Verify the Receiver Certificate
94 * AKE_Send_Cert and prepare AKE_Stored_Km/AKE_No_Stored_Km
95 * @dev: device corresponding to the mei_cl_device
96 * @data: Intel HW specific hdcp data
97 * @rx_cert: AKE_Send_Cert for verification
98 * @km_stored: Pairing status flag output
99 * @ek_pub_km: AKE_Stored_Km/AKE_No_Stored_Km output msg
100 * @msg_sz : size of AKE_XXXXX_Km output msg
102 * Return: 0 on Success, <0 on Failure
104 static int
105 mei_hdcp_verify_receiver_cert_prepare_km(struct device *dev,
106 struct hdcp_port_data *data,
107 struct hdcp2_ake_send_cert *rx_cert,
108 bool *km_stored,
109 struct hdcp2_ake_no_stored_km
110 *ek_pub_km,
111 size_t *msg_sz)
113 struct wired_cmd_verify_receiver_cert_in verify_rxcert_in = { { 0 } };
114 struct wired_cmd_verify_receiver_cert_out verify_rxcert_out = { { 0 } };
115 struct mei_cl_device *cldev;
116 ssize_t byte;
118 if (!dev || !data || !rx_cert || !km_stored || !ek_pub_km || !msg_sz)
119 return -EINVAL;
121 cldev = to_mei_cl_device(dev);
123 verify_rxcert_in.header.api_version = HDCP_API_VERSION;
124 verify_rxcert_in.header.command_id = WIRED_VERIFY_RECEIVER_CERT;
125 verify_rxcert_in.header.status = ME_HDCP_STATUS_SUCCESS;
126 verify_rxcert_in.header.buffer_len =
127 WIRED_CMD_BUF_LEN_VERIFY_RECEIVER_CERT_IN;
129 verify_rxcert_in.port.integrated_port_type = data->port_type;
130 verify_rxcert_in.port.physical_port = (u8)data->fw_ddi;
131 verify_rxcert_in.port.attached_transcoder = (u8)data->fw_tc;
133 verify_rxcert_in.cert_rx = rx_cert->cert_rx;
134 memcpy(verify_rxcert_in.r_rx, &rx_cert->r_rx, HDCP_2_2_RRX_LEN);
135 memcpy(verify_rxcert_in.rx_caps, rx_cert->rx_caps, HDCP_2_2_RXCAPS_LEN);
137 byte = mei_cldev_send(cldev, (u8 *)&verify_rxcert_in,
138 sizeof(verify_rxcert_in));
139 if (byte < 0) {
140 dev_dbg(dev, "mei_cldev_send failed: %zd\n", byte);
141 return byte;
144 byte = mei_cldev_recv(cldev, (u8 *)&verify_rxcert_out,
145 sizeof(verify_rxcert_out));
146 if (byte < 0) {
147 dev_dbg(dev, "mei_cldev_recv failed: %zd\n", byte);
148 return byte;
151 if (verify_rxcert_out.header.status != ME_HDCP_STATUS_SUCCESS) {
152 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
153 WIRED_VERIFY_RECEIVER_CERT,
154 verify_rxcert_out.header.status);
155 return -EIO;
158 *km_stored = !!verify_rxcert_out.km_stored;
159 if (verify_rxcert_out.km_stored) {
160 ek_pub_km->msg_id = HDCP_2_2_AKE_STORED_KM;
161 *msg_sz = sizeof(struct hdcp2_ake_stored_km);
162 } else {
163 ek_pub_km->msg_id = HDCP_2_2_AKE_NO_STORED_KM;
164 *msg_sz = sizeof(struct hdcp2_ake_no_stored_km);
167 memcpy(ek_pub_km->e_kpub_km, &verify_rxcert_out.ekm_buff,
168 sizeof(verify_rxcert_out.ekm_buff));
170 return 0;
174 * mei_hdcp_verify_hprime() - Verify AKE_Send_H_prime at ME FW.
175 * @dev: device corresponding to the mei_cl_device
176 * @data: Intel HW specific hdcp data
177 * @rx_hprime: AKE_Send_H_prime msg for ME FW verification
179 * Return: 0 on Success, <0 on Failure
181 static int
182 mei_hdcp_verify_hprime(struct device *dev, struct hdcp_port_data *data,
183 struct hdcp2_ake_send_hprime *rx_hprime)
185 struct wired_cmd_ake_send_hprime_in send_hprime_in = { { 0 } };
186 struct wired_cmd_ake_send_hprime_out send_hprime_out = { { 0 } };
187 struct mei_cl_device *cldev;
188 ssize_t byte;
190 if (!dev || !data || !rx_hprime)
191 return -EINVAL;
193 cldev = to_mei_cl_device(dev);
195 send_hprime_in.header.api_version = HDCP_API_VERSION;
196 send_hprime_in.header.command_id = WIRED_AKE_SEND_HPRIME;
197 send_hprime_in.header.status = ME_HDCP_STATUS_SUCCESS;
198 send_hprime_in.header.buffer_len = WIRED_CMD_BUF_LEN_AKE_SEND_HPRIME_IN;
200 send_hprime_in.port.integrated_port_type = data->port_type;
201 send_hprime_in.port.physical_port = (u8)data->fw_ddi;
202 send_hprime_in.port.attached_transcoder = (u8)data->fw_tc;
204 memcpy(send_hprime_in.h_prime, rx_hprime->h_prime,
205 HDCP_2_2_H_PRIME_LEN);
207 byte = mei_cldev_send(cldev, (u8 *)&send_hprime_in,
208 sizeof(send_hprime_in));
209 if (byte < 0) {
210 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
211 return byte;
214 byte = mei_cldev_recv(cldev, (u8 *)&send_hprime_out,
215 sizeof(send_hprime_out));
216 if (byte < 0) {
217 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
218 return byte;
221 if (send_hprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
222 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
223 WIRED_AKE_SEND_HPRIME, send_hprime_out.header.status);
224 return -EIO;
227 return 0;
231 * mei_hdcp_store_pairing_info() - Store pairing info received at ME FW
232 * @dev: device corresponding to the mei_cl_device
233 * @data: Intel HW specific hdcp data
234 * @pairing_info: AKE_Send_Pairing_Info msg input to ME FW
236 * Return: 0 on Success, <0 on Failure
238 static int
239 mei_hdcp_store_pairing_info(struct device *dev, struct hdcp_port_data *data,
240 struct hdcp2_ake_send_pairing_info *pairing_info)
242 struct wired_cmd_ake_send_pairing_info_in pairing_info_in = { { 0 } };
243 struct wired_cmd_ake_send_pairing_info_out pairing_info_out = { { 0 } };
244 struct mei_cl_device *cldev;
245 ssize_t byte;
247 if (!dev || !data || !pairing_info)
248 return -EINVAL;
250 cldev = to_mei_cl_device(dev);
252 pairing_info_in.header.api_version = HDCP_API_VERSION;
253 pairing_info_in.header.command_id = WIRED_AKE_SEND_PAIRING_INFO;
254 pairing_info_in.header.status = ME_HDCP_STATUS_SUCCESS;
255 pairing_info_in.header.buffer_len =
256 WIRED_CMD_BUF_LEN_SEND_PAIRING_INFO_IN;
258 pairing_info_in.port.integrated_port_type = data->port_type;
259 pairing_info_in.port.physical_port = (u8)data->fw_ddi;
260 pairing_info_in.port.attached_transcoder = (u8)data->fw_tc;
262 memcpy(pairing_info_in.e_kh_km, pairing_info->e_kh_km,
263 HDCP_2_2_E_KH_KM_LEN);
265 byte = mei_cldev_send(cldev, (u8 *)&pairing_info_in,
266 sizeof(pairing_info_in));
267 if (byte < 0) {
268 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
269 return byte;
272 byte = mei_cldev_recv(cldev, (u8 *)&pairing_info_out,
273 sizeof(pairing_info_out));
274 if (byte < 0) {
275 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
276 return byte;
279 if (pairing_info_out.header.status != ME_HDCP_STATUS_SUCCESS) {
280 dev_dbg(dev, "ME cmd 0x%08X failed. Status: 0x%X\n",
281 WIRED_AKE_SEND_PAIRING_INFO,
282 pairing_info_out.header.status);
283 return -EIO;
286 return 0;
290 * mei_hdcp_initiate_locality_check() - Prepare LC_Init
291 * @dev: device corresponding to the mei_cl_device
292 * @data: Intel HW specific hdcp data
293 * @lc_init_data: LC_Init msg output
295 * Return: 0 on Success, <0 on Failure
297 static int
298 mei_hdcp_initiate_locality_check(struct device *dev,
299 struct hdcp_port_data *data,
300 struct hdcp2_lc_init *lc_init_data)
302 struct wired_cmd_init_locality_check_in lc_init_in = { { 0 } };
303 struct wired_cmd_init_locality_check_out lc_init_out = { { 0 } };
304 struct mei_cl_device *cldev;
305 ssize_t byte;
307 if (!dev || !data || !lc_init_data)
308 return -EINVAL;
310 cldev = to_mei_cl_device(dev);
312 lc_init_in.header.api_version = HDCP_API_VERSION;
313 lc_init_in.header.command_id = WIRED_INIT_LOCALITY_CHECK;
314 lc_init_in.header.status = ME_HDCP_STATUS_SUCCESS;
315 lc_init_in.header.buffer_len = WIRED_CMD_BUF_LEN_INIT_LOCALITY_CHECK_IN;
317 lc_init_in.port.integrated_port_type = data->port_type;
318 lc_init_in.port.physical_port = (u8)data->fw_ddi;
319 lc_init_in.port.attached_transcoder = (u8)data->fw_tc;
321 byte = mei_cldev_send(cldev, (u8 *)&lc_init_in, sizeof(lc_init_in));
322 if (byte < 0) {
323 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
324 return byte;
327 byte = mei_cldev_recv(cldev, (u8 *)&lc_init_out, sizeof(lc_init_out));
328 if (byte < 0) {
329 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
330 return byte;
333 if (lc_init_out.header.status != ME_HDCP_STATUS_SUCCESS) {
334 dev_dbg(dev, "ME cmd 0x%08X Failed. status: 0x%X\n",
335 WIRED_INIT_LOCALITY_CHECK, lc_init_out.header.status);
336 return -EIO;
339 lc_init_data->msg_id = HDCP_2_2_LC_INIT;
340 memcpy(lc_init_data->r_n, lc_init_out.r_n, HDCP_2_2_RN_LEN);
342 return 0;
346 * mei_hdcp_verify_lprime() - Verify lprime.
347 * @dev: device corresponding to the mei_cl_device
348 * @data: Intel HW specific hdcp data
349 * @rx_lprime: LC_Send_L_prime msg for ME FW verification
351 * Return: 0 on Success, <0 on Failure
353 static int
354 mei_hdcp_verify_lprime(struct device *dev, struct hdcp_port_data *data,
355 struct hdcp2_lc_send_lprime *rx_lprime)
357 struct wired_cmd_validate_locality_in verify_lprime_in = { { 0 } };
358 struct wired_cmd_validate_locality_out verify_lprime_out = { { 0 } };
359 struct mei_cl_device *cldev;
360 ssize_t byte;
362 if (!dev || !data || !rx_lprime)
363 return -EINVAL;
365 cldev = to_mei_cl_device(dev);
367 verify_lprime_in.header.api_version = HDCP_API_VERSION;
368 verify_lprime_in.header.command_id = WIRED_VALIDATE_LOCALITY;
369 verify_lprime_in.header.status = ME_HDCP_STATUS_SUCCESS;
370 verify_lprime_in.header.buffer_len =
371 WIRED_CMD_BUF_LEN_VALIDATE_LOCALITY_IN;
373 verify_lprime_in.port.integrated_port_type = data->port_type;
374 verify_lprime_in.port.physical_port = (u8)data->fw_ddi;
375 verify_lprime_in.port.attached_transcoder = (u8)data->fw_tc;
377 memcpy(verify_lprime_in.l_prime, rx_lprime->l_prime,
378 HDCP_2_2_L_PRIME_LEN);
380 byte = mei_cldev_send(cldev, (u8 *)&verify_lprime_in,
381 sizeof(verify_lprime_in));
382 if (byte < 0) {
383 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
384 return byte;
387 byte = mei_cldev_recv(cldev, (u8 *)&verify_lprime_out,
388 sizeof(verify_lprime_out));
389 if (byte < 0) {
390 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
391 return byte;
394 if (verify_lprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
395 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
396 WIRED_VALIDATE_LOCALITY,
397 verify_lprime_out.header.status);
398 return -EIO;
401 return 0;
405 * mei_hdcp_get_session_key() - Prepare SKE_Send_Eks.
406 * @dev: device corresponding to the mei_cl_device
407 * @data: Intel HW specific hdcp data
408 * @ske_data: SKE_Send_Eks msg output from ME FW.
410 * Return: 0 on Success, <0 on Failure
412 static int mei_hdcp_get_session_key(struct device *dev,
413 struct hdcp_port_data *data,
414 struct hdcp2_ske_send_eks *ske_data)
416 struct wired_cmd_get_session_key_in get_skey_in = { { 0 } };
417 struct wired_cmd_get_session_key_out get_skey_out = { { 0 } };
418 struct mei_cl_device *cldev;
419 ssize_t byte;
421 if (!dev || !data || !ske_data)
422 return -EINVAL;
424 cldev = to_mei_cl_device(dev);
426 get_skey_in.header.api_version = HDCP_API_VERSION;
427 get_skey_in.header.command_id = WIRED_GET_SESSION_KEY;
428 get_skey_in.header.status = ME_HDCP_STATUS_SUCCESS;
429 get_skey_in.header.buffer_len = WIRED_CMD_BUF_LEN_GET_SESSION_KEY_IN;
431 get_skey_in.port.integrated_port_type = data->port_type;
432 get_skey_in.port.physical_port = (u8)data->fw_ddi;
433 get_skey_in.port.attached_transcoder = (u8)data->fw_tc;
435 byte = mei_cldev_send(cldev, (u8 *)&get_skey_in, sizeof(get_skey_in));
436 if (byte < 0) {
437 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
438 return byte;
441 byte = mei_cldev_recv(cldev, (u8 *)&get_skey_out, sizeof(get_skey_out));
443 if (byte < 0) {
444 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
445 return byte;
448 if (get_skey_out.header.status != ME_HDCP_STATUS_SUCCESS) {
449 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
450 WIRED_GET_SESSION_KEY, get_skey_out.header.status);
451 return -EIO;
454 ske_data->msg_id = HDCP_2_2_SKE_SEND_EKS;
455 memcpy(ske_data->e_dkey_ks, get_skey_out.e_dkey_ks,
456 HDCP_2_2_E_DKEY_KS_LEN);
457 memcpy(ske_data->riv, get_skey_out.r_iv, HDCP_2_2_RIV_LEN);
459 return 0;
463 * mei_hdcp_repeater_check_flow_prepare_ack() - Validate the Downstream topology
464 * and prepare rep_ack.
465 * @dev: device corresponding to the mei_cl_device
466 * @data: Intel HW specific hdcp data
467 * @rep_topology: Receiver ID List to be validated
468 * @rep_send_ack : repeater ack from ME FW.
470 * Return: 0 on Success, <0 on Failure
472 static int
473 mei_hdcp_repeater_check_flow_prepare_ack(struct device *dev,
474 struct hdcp_port_data *data,
475 struct hdcp2_rep_send_receiverid_list
476 *rep_topology,
477 struct hdcp2_rep_send_ack
478 *rep_send_ack)
480 struct wired_cmd_verify_repeater_in verify_repeater_in = { { 0 } };
481 struct wired_cmd_verify_repeater_out verify_repeater_out = { { 0 } };
482 struct mei_cl_device *cldev;
483 ssize_t byte;
485 if (!dev || !rep_topology || !rep_send_ack || !data)
486 return -EINVAL;
488 cldev = to_mei_cl_device(dev);
490 verify_repeater_in.header.api_version = HDCP_API_VERSION;
491 verify_repeater_in.header.command_id = WIRED_VERIFY_REPEATER;
492 verify_repeater_in.header.status = ME_HDCP_STATUS_SUCCESS;
493 verify_repeater_in.header.buffer_len =
494 WIRED_CMD_BUF_LEN_VERIFY_REPEATER_IN;
496 verify_repeater_in.port.integrated_port_type = data->port_type;
497 verify_repeater_in.port.physical_port = (u8)data->fw_ddi;
498 verify_repeater_in.port.attached_transcoder = (u8)data->fw_tc;
500 memcpy(verify_repeater_in.rx_info, rep_topology->rx_info,
501 HDCP_2_2_RXINFO_LEN);
502 memcpy(verify_repeater_in.seq_num_v, rep_topology->seq_num_v,
503 HDCP_2_2_SEQ_NUM_LEN);
504 memcpy(verify_repeater_in.v_prime, rep_topology->v_prime,
505 HDCP_2_2_V_PRIME_HALF_LEN);
506 memcpy(verify_repeater_in.receiver_ids, rep_topology->receiver_ids,
507 HDCP_2_2_RECEIVER_IDS_MAX_LEN);
509 byte = mei_cldev_send(cldev, (u8 *)&verify_repeater_in,
510 sizeof(verify_repeater_in));
511 if (byte < 0) {
512 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
513 return byte;
516 byte = mei_cldev_recv(cldev, (u8 *)&verify_repeater_out,
517 sizeof(verify_repeater_out));
518 if (byte < 0) {
519 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
520 return byte;
523 if (verify_repeater_out.header.status != ME_HDCP_STATUS_SUCCESS) {
524 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
525 WIRED_VERIFY_REPEATER,
526 verify_repeater_out.header.status);
527 return -EIO;
530 memcpy(rep_send_ack->v, verify_repeater_out.v,
531 HDCP_2_2_V_PRIME_HALF_LEN);
532 rep_send_ack->msg_id = HDCP_2_2_REP_SEND_ACK;
534 return 0;
538 * mei_hdcp_verify_mprime() - Verify mprime.
539 * @dev: device corresponding to the mei_cl_device
540 * @data: Intel HW specific hdcp data
541 * @stream_ready: RepeaterAuth_Stream_Ready msg for ME FW verification.
543 * Return: 0 on Success, <0 on Failure
545 static int mei_hdcp_verify_mprime(struct device *dev,
546 struct hdcp_port_data *data,
547 struct hdcp2_rep_stream_ready *stream_ready)
549 struct wired_cmd_repeater_auth_stream_req_in
550 verify_mprime_in = { { 0 } };
551 struct wired_cmd_repeater_auth_stream_req_out
552 verify_mprime_out = { { 0 } };
553 struct mei_cl_device *cldev;
554 ssize_t byte;
556 if (!dev || !stream_ready || !data)
557 return -EINVAL;
559 cldev = to_mei_cl_device(dev);
561 verify_mprime_in.header.api_version = HDCP_API_VERSION;
562 verify_mprime_in.header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ;
563 verify_mprime_in.header.status = ME_HDCP_STATUS_SUCCESS;
564 verify_mprime_in.header.buffer_len =
565 WIRED_CMD_BUF_LEN_REPEATER_AUTH_STREAM_REQ_MIN_IN;
567 verify_mprime_in.port.integrated_port_type = data->port_type;
568 verify_mprime_in.port.physical_port = (u8)data->fw_ddi;
569 verify_mprime_in.port.attached_transcoder = (u8)data->fw_tc;
571 memcpy(verify_mprime_in.m_prime, stream_ready->m_prime,
572 HDCP_2_2_MPRIME_LEN);
573 drm_hdcp_cpu_to_be24(verify_mprime_in.seq_num_m, data->seq_num_m);
574 memcpy(verify_mprime_in.streams, data->streams,
575 (data->k * sizeof(struct hdcp2_streamid_type)));
577 verify_mprime_in.k = cpu_to_be16(data->k);
579 byte = mei_cldev_send(cldev, (u8 *)&verify_mprime_in,
580 sizeof(verify_mprime_in));
581 if (byte < 0) {
582 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
583 return byte;
586 byte = mei_cldev_recv(cldev, (u8 *)&verify_mprime_out,
587 sizeof(verify_mprime_out));
588 if (byte < 0) {
589 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
590 return byte;
593 if (verify_mprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
594 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
595 WIRED_REPEATER_AUTH_STREAM_REQ,
596 verify_mprime_out.header.status);
597 return -EIO;
600 return 0;
604 * mei_hdcp_enable_authentication() - Mark a port as authenticated
605 * through ME FW
606 * @dev: device corresponding to the mei_cl_device
607 * @data: Intel HW specific hdcp data
609 * Return: 0 on Success, <0 on Failure
611 static int mei_hdcp_enable_authentication(struct device *dev,
612 struct hdcp_port_data *data)
614 struct wired_cmd_enable_auth_in enable_auth_in = { { 0 } };
615 struct wired_cmd_enable_auth_out enable_auth_out = { { 0 } };
616 struct mei_cl_device *cldev;
617 ssize_t byte;
619 if (!dev || !data)
620 return -EINVAL;
622 cldev = to_mei_cl_device(dev);
624 enable_auth_in.header.api_version = HDCP_API_VERSION;
625 enable_auth_in.header.command_id = WIRED_ENABLE_AUTH;
626 enable_auth_in.header.status = ME_HDCP_STATUS_SUCCESS;
627 enable_auth_in.header.buffer_len = WIRED_CMD_BUF_LEN_ENABLE_AUTH_IN;
629 enable_auth_in.port.integrated_port_type = data->port_type;
630 enable_auth_in.port.physical_port = (u8)data->fw_ddi;
631 enable_auth_in.port.attached_transcoder = (u8)data->fw_tc;
632 enable_auth_in.stream_type = data->streams[0].stream_type;
634 byte = mei_cldev_send(cldev, (u8 *)&enable_auth_in,
635 sizeof(enable_auth_in));
636 if (byte < 0) {
637 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
638 return byte;
641 byte = mei_cldev_recv(cldev, (u8 *)&enable_auth_out,
642 sizeof(enable_auth_out));
643 if (byte < 0) {
644 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
645 return byte;
648 if (enable_auth_out.header.status != ME_HDCP_STATUS_SUCCESS) {
649 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
650 WIRED_ENABLE_AUTH, enable_auth_out.header.status);
651 return -EIO;
654 return 0;
658 * mei_hdcp_close_session() - Close the Wired HDCP Tx session of ME FW per port.
659 * This also disables the authenticated state of the port.
660 * @dev: device corresponding to the mei_cl_device
661 * @data: Intel HW specific hdcp data
663 * Return: 0 on Success, <0 on Failure
665 static int
666 mei_hdcp_close_session(struct device *dev, struct hdcp_port_data *data)
668 struct wired_cmd_close_session_in session_close_in = { { 0 } };
669 struct wired_cmd_close_session_out session_close_out = { { 0 } };
670 struct mei_cl_device *cldev;
671 ssize_t byte;
673 if (!dev || !data)
674 return -EINVAL;
676 cldev = to_mei_cl_device(dev);
678 session_close_in.header.api_version = HDCP_API_VERSION;
679 session_close_in.header.command_id = WIRED_CLOSE_SESSION;
680 session_close_in.header.status = ME_HDCP_STATUS_SUCCESS;
681 session_close_in.header.buffer_len =
682 WIRED_CMD_BUF_LEN_CLOSE_SESSION_IN;
684 session_close_in.port.integrated_port_type = data->port_type;
685 session_close_in.port.physical_port = (u8)data->fw_ddi;
686 session_close_in.port.attached_transcoder = (u8)data->fw_tc;
688 byte = mei_cldev_send(cldev, (u8 *)&session_close_in,
689 sizeof(session_close_in));
690 if (byte < 0) {
691 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
692 return byte;
695 byte = mei_cldev_recv(cldev, (u8 *)&session_close_out,
696 sizeof(session_close_out));
697 if (byte < 0) {
698 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
699 return byte;
702 if (session_close_out.header.status != ME_HDCP_STATUS_SUCCESS) {
703 dev_dbg(dev, "Session Close Failed. status: 0x%X\n",
704 session_close_out.header.status);
705 return -EIO;
708 return 0;
711 static const struct i915_hdcp_component_ops mei_hdcp_ops = {
712 .owner = THIS_MODULE,
713 .initiate_hdcp2_session = mei_hdcp_initiate_session,
714 .verify_receiver_cert_prepare_km =
715 mei_hdcp_verify_receiver_cert_prepare_km,
716 .verify_hprime = mei_hdcp_verify_hprime,
717 .store_pairing_info = mei_hdcp_store_pairing_info,
718 .initiate_locality_check = mei_hdcp_initiate_locality_check,
719 .verify_lprime = mei_hdcp_verify_lprime,
720 .get_session_key = mei_hdcp_get_session_key,
721 .repeater_check_flow_prepare_ack =
722 mei_hdcp_repeater_check_flow_prepare_ack,
723 .verify_mprime = mei_hdcp_verify_mprime,
724 .enable_hdcp_authentication = mei_hdcp_enable_authentication,
725 .close_hdcp_session = mei_hdcp_close_session,
728 static int mei_component_master_bind(struct device *dev)
730 struct mei_cl_device *cldev = to_mei_cl_device(dev);
731 struct i915_hdcp_comp_master *comp_master =
732 mei_cldev_get_drvdata(cldev);
733 int ret;
735 dev_dbg(dev, "%s\n", __func__);
736 comp_master->ops = &mei_hdcp_ops;
737 comp_master->mei_dev = dev;
738 ret = component_bind_all(dev, comp_master);
739 if (ret < 0)
740 return ret;
742 return 0;
745 static void mei_component_master_unbind(struct device *dev)
747 struct mei_cl_device *cldev = to_mei_cl_device(dev);
748 struct i915_hdcp_comp_master *comp_master =
749 mei_cldev_get_drvdata(cldev);
751 dev_dbg(dev, "%s\n", __func__);
752 component_unbind_all(dev, comp_master);
755 static const struct component_master_ops mei_component_master_ops = {
756 .bind = mei_component_master_bind,
757 .unbind = mei_component_master_unbind,
761 * mei_hdcp_component_match - compare function for matching mei hdcp.
763 * The function checks if the driver is i915, the subcomponent is HDCP
764 * and the grand parent of hdcp and the parent of i915 are the same
765 * PCH device.
767 * @dev: master device
768 * @subcomponent: subcomponent to match (I915_COMPONENT_HDCP)
769 * @data: compare data (mei hdcp device)
771 * Return:
772 * * 1 - if components match
773 * * 0 - otherwise
775 static int mei_hdcp_component_match(struct device *dev, int subcomponent,
776 void *data)
778 struct device *base = data;
780 if (strcmp(dev->driver->name, "i915") ||
781 subcomponent != I915_COMPONENT_HDCP)
782 return 0;
784 base = base->parent;
785 if (!base)
786 return 0;
788 base = base->parent;
789 dev = dev->parent;
791 return (base && dev && dev == base);
794 static int mei_hdcp_probe(struct mei_cl_device *cldev,
795 const struct mei_cl_device_id *id)
797 struct i915_hdcp_comp_master *comp_master;
798 struct component_match *master_match;
799 int ret;
801 ret = mei_cldev_enable(cldev);
802 if (ret < 0) {
803 dev_err(&cldev->dev, "mei_cldev_enable Failed. %d\n", ret);
804 goto enable_err_exit;
807 comp_master = kzalloc(sizeof(*comp_master), GFP_KERNEL);
808 if (!comp_master) {
809 ret = -ENOMEM;
810 goto err_exit;
813 master_match = NULL;
814 component_match_add_typed(&cldev->dev, &master_match,
815 mei_hdcp_component_match, &cldev->dev);
816 if (IS_ERR_OR_NULL(master_match)) {
817 ret = -ENOMEM;
818 goto err_exit;
821 mei_cldev_set_drvdata(cldev, comp_master);
822 ret = component_master_add_with_match(&cldev->dev,
823 &mei_component_master_ops,
824 master_match);
825 if (ret < 0) {
826 dev_err(&cldev->dev, "Master comp add failed %d\n", ret);
827 goto err_exit;
830 return 0;
832 err_exit:
833 mei_cldev_set_drvdata(cldev, NULL);
834 kfree(comp_master);
835 mei_cldev_disable(cldev);
836 enable_err_exit:
837 return ret;
840 static int mei_hdcp_remove(struct mei_cl_device *cldev)
842 struct i915_hdcp_comp_master *comp_master =
843 mei_cldev_get_drvdata(cldev);
845 component_master_del(&cldev->dev, &mei_component_master_ops);
846 kfree(comp_master);
847 mei_cldev_set_drvdata(cldev, NULL);
849 return mei_cldev_disable(cldev);
852 #define MEI_UUID_HDCP GUID_INIT(0xB638AB7E, 0x94E2, 0x4EA2, 0xA5, \
853 0x52, 0xD1, 0xC5, 0x4B, 0x62, 0x7F, 0x04)
855 static struct mei_cl_device_id mei_hdcp_tbl[] = {
856 { .uuid = MEI_UUID_HDCP, .version = MEI_CL_VERSION_ANY },
859 MODULE_DEVICE_TABLE(mei, mei_hdcp_tbl);
861 static struct mei_cl_driver mei_hdcp_driver = {
862 .id_table = mei_hdcp_tbl,
863 .name = KBUILD_MODNAME,
864 .probe = mei_hdcp_probe,
865 .remove = mei_hdcp_remove,
868 module_mei_cl_driver(mei_hdcp_driver);
870 MODULE_AUTHOR("Intel Corporation");
871 MODULE_LICENSE("GPL");
872 MODULE_DESCRIPTION("MEI HDCP");