1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2022, Intel Corporation. All rights reserved.
4 * Intel Management Engine Interface (Intel MEI) Linux driver
9 #include <linux/kthread.h>
10 #include <linux/interrupt.h>
11 #include <linux/pm_runtime.h>
12 #include <linux/sizes.h>
13 #include <linux/delay.h>
19 #include "hw-me-regs.h"
21 #include "mei-trace.h"
24 * mei_me_reg_read - Reads 32bit data from the mei device
26 * @hw: the me hardware structure
27 * @offset: offset from which to read the data
29 * Return: register value (u32)
31 static inline u32 mei_me_reg_read(const struct mei_me_hw *hw,
34 return ioread32(hw->mem_addr + offset);
39 * mei_me_reg_write - Writes 32bit data to the mei device
41 * @hw: the me hardware structure
42 * @offset: offset from which to write the data
43 * @value: register value to write (u32)
45 static inline void mei_me_reg_write(const struct mei_me_hw *hw,
46 unsigned long offset, u32 value)
48 iowrite32(value, hw->mem_addr + offset);
52 * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer
53 * read window register
55 * @dev: the device structure
57 * Return: ME_CB_RW register value (u32)
59 static inline u32 mei_me_mecbrw_read(const struct mei_device *dev)
61 return mei_me_reg_read(to_me_hw(dev), ME_CB_RW);
65 * mei_me_hcbww_write - write 32bit data to the host circular buffer
67 * @dev: the device structure
68 * @data: 32bit data to be written to the host circular buffer
70 static inline void mei_me_hcbww_write(struct mei_device *dev, u32 data)
72 mei_me_reg_write(to_me_hw(dev), H_CB_WW, data);
76 * mei_me_mecsr_read - Reads 32bit data from the ME CSR
78 * @dev: the device structure
80 * Return: ME_CSR_HA register value (u32)
82 static inline u32 mei_me_mecsr_read(const struct mei_device *dev)
86 reg = mei_me_reg_read(to_me_hw(dev), ME_CSR_HA);
87 trace_mei_reg_read(dev->dev, "ME_CSR_HA", ME_CSR_HA, reg);
93 * mei_hcsr_read - Reads 32bit data from the host CSR
95 * @dev: the device structure
97 * Return: H_CSR register value (u32)
99 static inline u32 mei_hcsr_read(const struct mei_device *dev)
103 reg = mei_me_reg_read(to_me_hw(dev), H_CSR);
104 trace_mei_reg_read(dev->dev, "H_CSR", H_CSR, reg);
110 * mei_hcsr_write - writes H_CSR register to the mei device
112 * @dev: the device structure
113 * @reg: new register value
115 static inline void mei_hcsr_write(struct mei_device *dev, u32 reg)
117 trace_mei_reg_write(dev->dev, "H_CSR", H_CSR, reg);
118 mei_me_reg_write(to_me_hw(dev), H_CSR, reg);
122 * mei_hcsr_set - writes H_CSR register to the mei device,
123 * and ignores the H_IS bit for it is write-one-to-zero.
125 * @dev: the device structure
126 * @reg: new register value
128 static inline void mei_hcsr_set(struct mei_device *dev, u32 reg)
130 reg &= ~H_CSR_IS_MASK;
131 mei_hcsr_write(dev, reg);
135 * mei_hcsr_set_hig - set host interrupt (set H_IG)
137 * @dev: the device structure
139 static inline void mei_hcsr_set_hig(struct mei_device *dev)
143 hcsr = mei_hcsr_read(dev) | H_IG;
144 mei_hcsr_set(dev, hcsr);
148 * mei_me_d0i3c_read - Reads 32bit data from the D0I3C register
150 * @dev: the device structure
152 * Return: H_D0I3C register value (u32)
154 static inline u32 mei_me_d0i3c_read(const struct mei_device *dev)
158 reg = mei_me_reg_read(to_me_hw(dev), H_D0I3C);
159 trace_mei_reg_read(dev->dev, "H_D0I3C", H_D0I3C, reg);
165 * mei_me_d0i3c_write - writes H_D0I3C register to device
167 * @dev: the device structure
168 * @reg: new register value
170 static inline void mei_me_d0i3c_write(struct mei_device *dev, u32 reg)
172 trace_mei_reg_write(dev->dev, "H_D0I3C", H_D0I3C, reg);
173 mei_me_reg_write(to_me_hw(dev), H_D0I3C, reg);
177 * mei_me_trc_status - read trc status register
180 * @trc: trc status register value
182 * Return: 0 on success, error otherwise
184 static int mei_me_trc_status(struct mei_device *dev, u32 *trc)
186 struct mei_me_hw *hw = to_me_hw(dev);
188 if (!hw->cfg->hw_trc_supported)
191 *trc = mei_me_reg_read(hw, ME_TRC);
192 trace_mei_reg_read(dev->dev, "ME_TRC", ME_TRC, *trc);
198 * mei_me_fw_status - read fw status register from pci config space
201 * @fw_status: fw status register values
203 * Return: 0 on success, error otherwise
205 static int mei_me_fw_status(struct mei_device *dev,
206 struct mei_fw_status *fw_status)
208 struct mei_me_hw *hw = to_me_hw(dev);
209 const struct mei_fw_status *fw_src = &hw->cfg->fw_status;
213 if (!fw_status || !hw->read_fws)
216 fw_status->count = fw_src->count;
217 for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) {
218 ret = hw->read_fws(dev, fw_src->status[i],
219 &fw_status->status[i]);
220 trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_X",
222 fw_status->status[i]);
231 * mei_me_hw_config - configure hw dependent settings
236 * * -EINVAL when read_fws is not set
240 static int mei_me_hw_config(struct mei_device *dev)
242 struct mei_me_hw *hw = to_me_hw(dev);
245 if (WARN_ON(!hw->read_fws))
248 /* Doesn't change in runtime */
249 hcsr = mei_hcsr_read(dev);
250 hw->hbuf_depth = (hcsr & H_CBD) >> 24;
253 hw->read_fws(dev, PCI_CFG_HFS_1, ®);
254 trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
256 ((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK);
258 hw->pg_state = MEI_PG_OFF;
259 if (hw->d0i3_supported) {
260 reg = mei_me_d0i3c_read(dev);
261 if (reg & H_D0I3C_I3)
262 hw->pg_state = MEI_PG_ON;
269 * mei_me_pg_state - translate internal pg state
270 * to the mei power gating state
274 * Return: MEI_PG_OFF if aliveness is on and MEI_PG_ON otherwise
276 static inline enum mei_pg_state mei_me_pg_state(struct mei_device *dev)
278 struct mei_me_hw *hw = to_me_hw(dev);
283 static inline u32 me_intr_src(u32 hcsr)
285 return hcsr & H_CSR_IS_MASK;
289 * me_intr_disable - disables mei device interrupts
290 * using supplied hcsr register value.
292 * @dev: the device structure
293 * @hcsr: supplied hcsr register value
295 static inline void me_intr_disable(struct mei_device *dev, u32 hcsr)
297 hcsr &= ~H_CSR_IE_MASK;
298 mei_hcsr_set(dev, hcsr);
302 * me_intr_clear - clear and stop interrupts
304 * @dev: the device structure
305 * @hcsr: supplied hcsr register value
307 static inline void me_intr_clear(struct mei_device *dev, u32 hcsr)
309 if (me_intr_src(hcsr))
310 mei_hcsr_write(dev, hcsr);
314 * mei_me_intr_clear - clear and stop interrupts
316 * @dev: the device structure
318 static void mei_me_intr_clear(struct mei_device *dev)
320 u32 hcsr = mei_hcsr_read(dev);
322 me_intr_clear(dev, hcsr);
325 * mei_me_intr_enable - enables mei device interrupts
327 * @dev: the device structure
329 static void mei_me_intr_enable(struct mei_device *dev)
333 if (mei_me_hw_use_polling(to_me_hw(dev)))
336 hcsr = mei_hcsr_read(dev) | H_CSR_IE_MASK;
337 mei_hcsr_set(dev, hcsr);
341 * mei_me_intr_disable - disables mei device interrupts
343 * @dev: the device structure
345 static void mei_me_intr_disable(struct mei_device *dev)
347 u32 hcsr = mei_hcsr_read(dev);
349 me_intr_disable(dev, hcsr);
353 * mei_me_synchronize_irq - wait for pending IRQ handlers
355 * @dev: the device structure
357 static void mei_me_synchronize_irq(struct mei_device *dev)
359 struct mei_me_hw *hw = to_me_hw(dev);
361 if (mei_me_hw_use_polling(hw))
364 synchronize_irq(hw->irq);
368 * mei_me_hw_reset_release - release device from the reset
370 * @dev: the device structure
372 static void mei_me_hw_reset_release(struct mei_device *dev)
374 u32 hcsr = mei_hcsr_read(dev);
378 mei_hcsr_set(dev, hcsr);
382 * mei_me_host_set_ready - enable device
386 static void mei_me_host_set_ready(struct mei_device *dev)
388 u32 hcsr = mei_hcsr_read(dev);
390 if (!mei_me_hw_use_polling(to_me_hw(dev)))
391 hcsr |= H_CSR_IE_MASK;
393 hcsr |= H_IG | H_RDY;
394 mei_hcsr_set(dev, hcsr);
398 * mei_me_host_is_ready - check whether the host has turned ready
403 static bool mei_me_host_is_ready(struct mei_device *dev)
405 u32 hcsr = mei_hcsr_read(dev);
407 return (hcsr & H_RDY) == H_RDY;
411 * mei_me_hw_is_ready - check whether the me(hw) has turned ready
416 static bool mei_me_hw_is_ready(struct mei_device *dev)
418 u32 mecsr = mei_me_mecsr_read(dev);
420 return (mecsr & ME_RDY_HRA) == ME_RDY_HRA;
424 * mei_me_hw_is_resetting - check whether the me(hw) is in reset
429 static bool mei_me_hw_is_resetting(struct mei_device *dev)
431 u32 mecsr = mei_me_mecsr_read(dev);
433 return (mecsr & ME_RST_HRA) == ME_RST_HRA;
437 * mei_gsc_pxp_check - check for gsc firmware entering pxp mode
439 * @dev: the device structure
441 static void mei_gsc_pxp_check(struct mei_device *dev)
443 struct mei_me_hw *hw = to_me_hw(dev);
446 if (dev->pxp_mode == MEI_DEV_PXP_DEFAULT)
449 hw->read_fws(dev, PCI_CFG_HFS_5, &fwsts5);
450 trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_5", PCI_CFG_HFS_5, fwsts5);
451 if ((fwsts5 & GSC_CFG_HFS_5_BOOT_TYPE_MSK) == GSC_CFG_HFS_5_BOOT_TYPE_PXP) {
452 dev_dbg(dev->dev, "pxp mode is ready 0x%08x\n", fwsts5);
453 dev->pxp_mode = MEI_DEV_PXP_READY;
455 dev_dbg(dev->dev, "pxp mode is not ready 0x%08x\n", fwsts5);
460 * mei_me_hw_ready_wait - wait until the me(hw) has turned ready
461 * or timeout is reached
464 * Return: 0 on success, error otherwise
466 static int mei_me_hw_ready_wait(struct mei_device *dev)
468 mutex_unlock(&dev->device_lock);
469 wait_event_timeout(dev->wait_hw_ready,
471 dev->timeouts.hw_ready);
472 mutex_lock(&dev->device_lock);
473 if (!dev->recvd_hw_ready) {
474 dev_err(dev->dev, "wait hw ready failed\n");
478 mei_gsc_pxp_check(dev);
480 mei_me_hw_reset_release(dev);
481 dev->recvd_hw_ready = false;
486 * mei_me_hw_start - hw start routine
489 * Return: 0 on success, error otherwise
491 static int mei_me_hw_start(struct mei_device *dev)
493 int ret = mei_me_hw_ready_wait(dev);
497 dev_dbg(dev->dev, "hw is ready\n");
499 mei_me_host_set_ready(dev);
505 * mei_hbuf_filled_slots - gets number of device filled buffer slots
507 * @dev: the device structure
509 * Return: number of filled slots
511 static unsigned char mei_hbuf_filled_slots(struct mei_device *dev)
514 char read_ptr, write_ptr;
516 hcsr = mei_hcsr_read(dev);
518 read_ptr = (char) ((hcsr & H_CBRP) >> 8);
519 write_ptr = (char) ((hcsr & H_CBWP) >> 16);
521 return (unsigned char) (write_ptr - read_ptr);
525 * mei_me_hbuf_is_empty - checks if host buffer is empty.
527 * @dev: the device structure
529 * Return: true if empty, false - otherwise.
531 static bool mei_me_hbuf_is_empty(struct mei_device *dev)
533 return mei_hbuf_filled_slots(dev) == 0;
537 * mei_me_hbuf_empty_slots - counts write empty slots.
539 * @dev: the device structure
541 * Return: -EOVERFLOW if overflow, otherwise empty slots count
543 static int mei_me_hbuf_empty_slots(struct mei_device *dev)
545 struct mei_me_hw *hw = to_me_hw(dev);
546 unsigned char filled_slots, empty_slots;
548 filled_slots = mei_hbuf_filled_slots(dev);
549 empty_slots = hw->hbuf_depth - filled_slots;
551 /* check for overflow */
552 if (filled_slots > hw->hbuf_depth)
559 * mei_me_hbuf_depth - returns depth of the hw buffer.
561 * @dev: the device structure
563 * Return: size of hw buffer in slots
565 static u32 mei_me_hbuf_depth(const struct mei_device *dev)
567 struct mei_me_hw *hw = to_me_hw(dev);
569 return hw->hbuf_depth;
573 * mei_me_hbuf_write - writes a message to host hw buffer.
575 * @dev: the device structure
576 * @hdr: header of message
577 * @hdr_len: header length in bytes: must be multiplication of a slot (4bytes)
579 * @data_len: payload length in bytes
581 * Return: 0 if success, < 0 - otherwise.
583 static int mei_me_hbuf_write(struct mei_device *dev,
584 const void *hdr, size_t hdr_len,
585 const void *data, size_t data_len)
593 if (WARN_ON(!hdr || !data || hdr_len & 0x3))
596 dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM((struct mei_msg_hdr *)hdr));
598 empty_slots = mei_hbuf_empty_slots(dev);
599 dev_dbg(dev->dev, "empty slots = %d.\n", empty_slots);
604 dw_cnt = mei_data2slots(hdr_len + data_len);
605 if (dw_cnt > (u32)empty_slots)
609 for (i = 0; i < hdr_len / MEI_SLOT_SIZE; i++)
610 mei_me_hcbww_write(dev, reg_buf[i]);
613 for (i = 0; i < data_len / MEI_SLOT_SIZE; i++)
614 mei_me_hcbww_write(dev, reg_buf[i]);
616 rem = data_len & 0x3;
620 memcpy(®, (const u8 *)data + data_len - rem, rem);
621 mei_me_hcbww_write(dev, reg);
624 mei_hcsr_set_hig(dev);
625 if (!mei_me_hw_is_ready(dev))
632 * mei_me_count_full_read_slots - counts read full slots.
634 * @dev: the device structure
636 * Return: -EOVERFLOW if overflow, otherwise filled slots count
638 static int mei_me_count_full_read_slots(struct mei_device *dev)
641 char read_ptr, write_ptr;
642 unsigned char buffer_depth, filled_slots;
644 me_csr = mei_me_mecsr_read(dev);
645 buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24);
646 read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8);
647 write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16);
648 filled_slots = (unsigned char) (write_ptr - read_ptr);
650 /* check for overflow */
651 if (filled_slots > buffer_depth)
654 dev_dbg(dev->dev, "filled_slots =%08x\n", filled_slots);
655 return (int)filled_slots;
659 * mei_me_read_slots - reads a message from mei device.
661 * @dev: the device structure
662 * @buffer: message buffer will be written
663 * @buffer_length: message size will be read
667 static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer,
668 unsigned long buffer_length)
670 u32 *reg_buf = (u32 *)buffer;
672 for (; buffer_length >= MEI_SLOT_SIZE; buffer_length -= MEI_SLOT_SIZE)
673 *reg_buf++ = mei_me_mecbrw_read(dev);
675 if (buffer_length > 0) {
676 u32 reg = mei_me_mecbrw_read(dev);
678 memcpy(reg_buf, ®, buffer_length);
681 mei_hcsr_set_hig(dev);
686 * mei_me_pg_set - write pg enter register
688 * @dev: the device structure
690 static void mei_me_pg_set(struct mei_device *dev)
692 struct mei_me_hw *hw = to_me_hw(dev);
695 reg = mei_me_reg_read(hw, H_HPG_CSR);
696 trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
698 reg |= H_HPG_CSR_PGI;
700 trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
701 mei_me_reg_write(hw, H_HPG_CSR, reg);
705 * mei_me_pg_unset - write pg exit register
707 * @dev: the device structure
709 static void mei_me_pg_unset(struct mei_device *dev)
711 struct mei_me_hw *hw = to_me_hw(dev);
714 reg = mei_me_reg_read(hw, H_HPG_CSR);
715 trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
717 WARN(!(reg & H_HPG_CSR_PGI), "PGI is not set\n");
719 reg |= H_HPG_CSR_PGIHEXR;
721 trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
722 mei_me_reg_write(hw, H_HPG_CSR, reg);
726 * mei_me_pg_legacy_enter_sync - perform legacy pg entry procedure
728 * @dev: the device structure
730 * Return: 0 on success an error code otherwise
732 static int mei_me_pg_legacy_enter_sync(struct mei_device *dev)
734 struct mei_me_hw *hw = to_me_hw(dev);
737 dev->pg_event = MEI_PG_EVENT_WAIT;
739 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
743 mutex_unlock(&dev->device_lock);
744 wait_event_timeout(dev->wait_pg,
745 dev->pg_event == MEI_PG_EVENT_RECEIVED,
747 mutex_lock(&dev->device_lock);
749 if (dev->pg_event == MEI_PG_EVENT_RECEIVED) {
756 dev->pg_event = MEI_PG_EVENT_IDLE;
757 hw->pg_state = MEI_PG_ON;
763 * mei_me_pg_legacy_exit_sync - perform legacy pg exit procedure
765 * @dev: the device structure
767 * Return: 0 on success an error code otherwise
769 static int mei_me_pg_legacy_exit_sync(struct mei_device *dev)
771 struct mei_me_hw *hw = to_me_hw(dev);
774 if (dev->pg_event == MEI_PG_EVENT_RECEIVED)
777 dev->pg_event = MEI_PG_EVENT_WAIT;
779 mei_me_pg_unset(dev);
781 mutex_unlock(&dev->device_lock);
782 wait_event_timeout(dev->wait_pg,
783 dev->pg_event == MEI_PG_EVENT_RECEIVED,
785 mutex_lock(&dev->device_lock);
788 if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
793 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
794 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD);
798 mutex_unlock(&dev->device_lock);
799 wait_event_timeout(dev->wait_pg,
800 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED,
802 mutex_lock(&dev->device_lock);
804 if (dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED)
810 dev->pg_event = MEI_PG_EVENT_IDLE;
811 hw->pg_state = MEI_PG_OFF;
817 * mei_me_pg_in_transition - is device now in pg transition
819 * @dev: the device structure
821 * Return: true if in pg transition, false otherwise
823 static bool mei_me_pg_in_transition(struct mei_device *dev)
825 return dev->pg_event >= MEI_PG_EVENT_WAIT &&
826 dev->pg_event <= MEI_PG_EVENT_INTR_WAIT;
830 * mei_me_pg_is_enabled - detect if PG is supported by HW
832 * @dev: the device structure
834 * Return: true is pg supported, false otherwise
836 static bool mei_me_pg_is_enabled(struct mei_device *dev)
838 struct mei_me_hw *hw = to_me_hw(dev);
839 u32 reg = mei_me_mecsr_read(dev);
841 if (hw->d0i3_supported)
844 if ((reg & ME_PGIC_HRA) == 0)
847 if (!dev->hbm_f_pg_supported)
853 dev_dbg(dev->dev, "pg: not supported: d0i3 = %d HGP = %d hbm version %d.%d ?= %d.%d\n",
855 !!(reg & ME_PGIC_HRA),
856 dev->version.major_version,
857 dev->version.minor_version,
858 HBM_MAJOR_VERSION_PGI,
859 HBM_MINOR_VERSION_PGI);
865 * mei_me_d0i3_set - write d0i3 register bit on mei device.
867 * @dev: the device structure
868 * @intr: ask for interrupt
870 * Return: D0I3C register value
872 static u32 mei_me_d0i3_set(struct mei_device *dev, bool intr)
874 u32 reg = mei_me_d0i3c_read(dev);
881 mei_me_d0i3c_write(dev, reg);
882 /* read it to ensure HW consistency */
883 reg = mei_me_d0i3c_read(dev);
888 * mei_me_d0i3_unset - clean d0i3 register bit on mei device.
890 * @dev: the device structure
892 * Return: D0I3C register value
894 static u32 mei_me_d0i3_unset(struct mei_device *dev)
896 u32 reg = mei_me_d0i3c_read(dev);
900 mei_me_d0i3c_write(dev, reg);
901 /* read it to ensure HW consistency */
902 reg = mei_me_d0i3c_read(dev);
907 * mei_me_d0i3_enter_sync - perform d0i3 entry procedure
909 * @dev: the device structure
911 * Return: 0 on success an error code otherwise
913 static int mei_me_d0i3_enter_sync(struct mei_device *dev)
915 struct mei_me_hw *hw = to_me_hw(dev);
919 reg = mei_me_d0i3c_read(dev);
920 if (reg & H_D0I3C_I3) {
921 /* we are in d0i3, nothing to do */
922 dev_dbg(dev->dev, "d0i3 set not needed\n");
927 /* PGI entry procedure */
928 dev->pg_event = MEI_PG_EVENT_WAIT;
930 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
932 /* FIXME: should we reset here? */
935 mutex_unlock(&dev->device_lock);
936 wait_event_timeout(dev->wait_pg,
937 dev->pg_event == MEI_PG_EVENT_RECEIVED,
939 mutex_lock(&dev->device_lock);
941 if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
945 /* end PGI entry procedure */
947 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
949 reg = mei_me_d0i3_set(dev, true);
950 if (!(reg & H_D0I3C_CIP)) {
951 dev_dbg(dev->dev, "d0i3 enter wait not needed\n");
956 mutex_unlock(&dev->device_lock);
957 wait_event_timeout(dev->wait_pg,
958 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED,
960 mutex_lock(&dev->device_lock);
962 if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
963 reg = mei_me_d0i3c_read(dev);
964 if (!(reg & H_D0I3C_I3)) {
972 hw->pg_state = MEI_PG_ON;
974 dev->pg_event = MEI_PG_EVENT_IDLE;
975 dev_dbg(dev->dev, "d0i3 enter ret = %d\n", ret);
980 * mei_me_d0i3_enter - perform d0i3 entry procedure
981 * no hbm PG handshake
982 * no waiting for confirmation; runs with interrupts
985 * @dev: the device structure
987 * Return: 0 on success an error code otherwise
989 static int mei_me_d0i3_enter(struct mei_device *dev)
991 struct mei_me_hw *hw = to_me_hw(dev);
994 reg = mei_me_d0i3c_read(dev);
995 if (reg & H_D0I3C_I3) {
996 /* we are in d0i3, nothing to do */
997 dev_dbg(dev->dev, "already d0i3 : set not needed\n");
1001 mei_me_d0i3_set(dev, false);
1003 hw->pg_state = MEI_PG_ON;
1004 dev->pg_event = MEI_PG_EVENT_IDLE;
1005 dev_dbg(dev->dev, "d0i3 enter\n");
1010 * mei_me_d0i3_exit_sync - perform d0i3 exit procedure
1012 * @dev: the device structure
1014 * Return: 0 on success an error code otherwise
1016 static int mei_me_d0i3_exit_sync(struct mei_device *dev)
1018 struct mei_me_hw *hw = to_me_hw(dev);
1022 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
1024 reg = mei_me_d0i3c_read(dev);
1025 if (!(reg & H_D0I3C_I3)) {
1026 /* we are not in d0i3, nothing to do */
1027 dev_dbg(dev->dev, "d0i3 exit not needed\n");
1032 reg = mei_me_d0i3_unset(dev);
1033 if (!(reg & H_D0I3C_CIP)) {
1034 dev_dbg(dev->dev, "d0i3 exit wait not needed\n");
1039 mutex_unlock(&dev->device_lock);
1040 wait_event_timeout(dev->wait_pg,
1041 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED,
1042 dev->timeouts.d0i3);
1043 mutex_lock(&dev->device_lock);
1045 if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
1046 reg = mei_me_d0i3c_read(dev);
1047 if (reg & H_D0I3C_I3) {
1055 hw->pg_state = MEI_PG_OFF;
1057 dev->pg_event = MEI_PG_EVENT_IDLE;
1059 dev_dbg(dev->dev, "d0i3 exit ret = %d\n", ret);
1064 * mei_me_pg_legacy_intr - perform legacy pg processing
1065 * in interrupt thread handler
1067 * @dev: the device structure
1069 static void mei_me_pg_legacy_intr(struct mei_device *dev)
1071 struct mei_me_hw *hw = to_me_hw(dev);
1073 if (dev->pg_event != MEI_PG_EVENT_INTR_WAIT)
1076 dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
1077 hw->pg_state = MEI_PG_OFF;
1078 if (waitqueue_active(&dev->wait_pg))
1079 wake_up(&dev->wait_pg);
1083 * mei_me_d0i3_intr - perform d0i3 processing in interrupt thread handler
1085 * @dev: the device structure
1086 * @intr_source: interrupt source
1088 static void mei_me_d0i3_intr(struct mei_device *dev, u32 intr_source)
1090 struct mei_me_hw *hw = to_me_hw(dev);
1092 if (dev->pg_event == MEI_PG_EVENT_INTR_WAIT &&
1093 (intr_source & H_D0I3C_IS)) {
1094 dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
1095 if (hw->pg_state == MEI_PG_ON) {
1096 hw->pg_state = MEI_PG_OFF;
1097 if (dev->hbm_state != MEI_HBM_IDLE) {
1099 * force H_RDY because it could be
1100 * wiped off during PG
1102 dev_dbg(dev->dev, "d0i3 set host ready\n");
1103 mei_me_host_set_ready(dev);
1106 hw->pg_state = MEI_PG_ON;
1109 wake_up(&dev->wait_pg);
1112 if (hw->pg_state == MEI_PG_ON && (intr_source & H_IS)) {
1114 * HW sent some data and we are in D0i3, so
1115 * we got here because of HW initiated exit from D0i3.
1116 * Start runtime pm resume sequence to exit low power state.
1118 dev_dbg(dev->dev, "d0i3 want resume\n");
1119 mei_hbm_pg_resume(dev);
1124 * mei_me_pg_intr - perform pg processing in interrupt thread handler
1126 * @dev: the device structure
1127 * @intr_source: interrupt source
1129 static void mei_me_pg_intr(struct mei_device *dev, u32 intr_source)
1131 struct mei_me_hw *hw = to_me_hw(dev);
1133 if (hw->d0i3_supported)
1134 mei_me_d0i3_intr(dev, intr_source);
1136 mei_me_pg_legacy_intr(dev);
1140 * mei_me_pg_enter_sync - perform runtime pm entry procedure
1142 * @dev: the device structure
1144 * Return: 0 on success an error code otherwise
1146 int mei_me_pg_enter_sync(struct mei_device *dev)
1148 struct mei_me_hw *hw = to_me_hw(dev);
1150 if (hw->d0i3_supported)
1151 return mei_me_d0i3_enter_sync(dev);
1153 return mei_me_pg_legacy_enter_sync(dev);
1157 * mei_me_pg_exit_sync - perform runtime pm exit procedure
1159 * @dev: the device structure
1161 * Return: 0 on success an error code otherwise
1163 int mei_me_pg_exit_sync(struct mei_device *dev)
1165 struct mei_me_hw *hw = to_me_hw(dev);
1167 if (hw->d0i3_supported)
1168 return mei_me_d0i3_exit_sync(dev);
1170 return mei_me_pg_legacy_exit_sync(dev);
1174 * mei_me_hw_reset - resets fw via mei csr register.
1176 * @dev: the device structure
1177 * @intr_enable: if interrupt should be enabled after reset.
1179 * Return: 0 on success an error code otherwise
1181 static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
1183 struct mei_me_hw *hw = to_me_hw(dev);
1188 mei_me_intr_enable(dev);
1189 if (hw->d0i3_supported) {
1190 ret = mei_me_d0i3_exit_sync(dev);
1194 hw->pg_state = MEI_PG_OFF;
1198 pm_runtime_set_active(dev->dev);
1200 hcsr = mei_hcsr_read(dev);
1201 /* H_RST may be found lit before reset is started,
1202 * for example if preceding reset flow hasn't completed.
1203 * In that case asserting H_RST will be ignored, therefore
1204 * we need to clean H_RST bit to start a successful reset sequence.
1206 if ((hcsr & H_RST) == H_RST) {
1207 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
1209 mei_hcsr_set(dev, hcsr);
1210 hcsr = mei_hcsr_read(dev);
1213 hcsr |= H_RST | H_IG | H_CSR_IS_MASK;
1215 if (!intr_enable || mei_me_hw_use_polling(to_me_hw(dev)))
1216 hcsr &= ~H_CSR_IE_MASK;
1218 dev->recvd_hw_ready = false;
1219 mei_hcsr_write(dev, hcsr);
1222 * Host reads the H_CSR once to ensure that the
1223 * posted write to H_CSR completes.
1225 hcsr = mei_hcsr_read(dev);
1227 if ((hcsr & H_RST) == 0)
1228 dev_warn(dev->dev, "H_RST is not set = 0x%08X", hcsr);
1230 if ((hcsr & H_RDY) == H_RDY)
1231 dev_warn(dev->dev, "H_RDY is not cleared 0x%08X", hcsr);
1234 mei_me_hw_reset_release(dev);
1235 if (hw->d0i3_supported) {
1236 ret = mei_me_d0i3_enter(dev);
1245 * mei_me_irq_quick_handler - The ISR of the MEI device
1247 * @irq: The irq number
1248 * @dev_id: pointer to the device structure
1250 * Return: irqreturn_t
1252 irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id)
1254 struct mei_device *dev = (struct mei_device *)dev_id;
1257 hcsr = mei_hcsr_read(dev);
1258 if (!me_intr_src(hcsr))
1261 dev_dbg(dev->dev, "interrupt source 0x%08X\n", me_intr_src(hcsr));
1263 /* disable interrupts on device */
1264 me_intr_disable(dev, hcsr);
1265 return IRQ_WAKE_THREAD;
1267 EXPORT_SYMBOL_GPL(mei_me_irq_quick_handler);
1270 * mei_me_irq_thread_handler - function called after ISR to handle the interrupt
1273 * @irq: The irq number
1274 * @dev_id: pointer to the device structure
1276 * Return: irqreturn_t
1279 irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
1281 struct mei_device *dev = (struct mei_device *) dev_id;
1282 struct list_head cmpl_list;
1287 dev_dbg(dev->dev, "function called after ISR to handle the interrupt processing.\n");
1288 /* initialize our complete list */
1289 mutex_lock(&dev->device_lock);
1291 hcsr = mei_hcsr_read(dev);
1292 me_intr_clear(dev, hcsr);
1294 INIT_LIST_HEAD(&cmpl_list);
1296 /* check if ME wants a reset */
1297 if (!mei_hw_is_ready(dev) && dev->dev_state != MEI_DEV_RESETTING) {
1298 dev_warn(dev->dev, "FW not ready: resetting: dev_state = %d pxp = %d\n",
1299 dev->dev_state, dev->pxp_mode);
1300 if (dev->dev_state == MEI_DEV_POWERING_DOWN ||
1301 dev->dev_state == MEI_DEV_POWER_DOWN)
1302 mei_cl_all_disconnect(dev);
1303 else if (dev->dev_state != MEI_DEV_DISABLED)
1304 schedule_work(&dev->reset_work);
1308 if (mei_me_hw_is_resetting(dev))
1309 mei_hcsr_set_hig(dev);
1311 mei_me_pg_intr(dev, me_intr_src(hcsr));
1313 /* check if we need to start the dev */
1314 if (!mei_host_is_ready(dev)) {
1315 if (mei_hw_is_ready(dev)) {
1316 dev_dbg(dev->dev, "we need to start the dev.\n");
1317 dev->recvd_hw_ready = true;
1318 wake_up(&dev->wait_hw_ready);
1320 dev_dbg(dev->dev, "Spurious Interrupt\n");
1324 /* check slots available for reading */
1325 slots = mei_count_full_read_slots(dev);
1327 dev_dbg(dev->dev, "slots to read = %08x\n", slots);
1328 rets = mei_irq_read_handler(dev, &cmpl_list, &slots);
1329 /* There is a race between ME write and interrupt delivery:
1330 * Not all data is always available immediately after the
1331 * interrupt, so try to read again on the next interrupt.
1333 if (rets == -ENODATA)
1337 dev_err(dev->dev, "mei_irq_read_handler ret = %d, state = %d.\n",
1338 rets, dev->dev_state);
1339 if (dev->dev_state != MEI_DEV_RESETTING &&
1340 dev->dev_state != MEI_DEV_DISABLED &&
1341 dev->dev_state != MEI_DEV_POWERING_DOWN &&
1342 dev->dev_state != MEI_DEV_POWER_DOWN)
1343 schedule_work(&dev->reset_work);
1348 dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
1351 * During PG handshake only allowed write is the replay to the
1352 * PG exit message, so block calling write function
1353 * if the pg event is in PG handshake
1355 if (dev->pg_event != MEI_PG_EVENT_WAIT &&
1356 dev->pg_event != MEI_PG_EVENT_RECEIVED) {
1357 rets = mei_irq_write_handler(dev, &cmpl_list);
1358 dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
1361 mei_irq_compl_handler(dev, &cmpl_list);
1364 dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets);
1365 mei_me_intr_enable(dev);
1366 mutex_unlock(&dev->device_lock);
1369 EXPORT_SYMBOL_GPL(mei_me_irq_thread_handler);
1371 #define MEI_POLLING_TIMEOUT_ACTIVE 100
1372 #define MEI_POLLING_TIMEOUT_IDLE 500
1375 * mei_me_polling_thread - interrupt register polling thread
1377 * The thread monitors the interrupt source register and calls
1378 * mei_me_irq_thread_handler() to handle the firmware
1381 * The function polls in MEI_POLLING_TIMEOUT_ACTIVE timeout
1382 * in case there was an event, in idle case the polling
1383 * time increases yet again by MEI_POLLING_TIMEOUT_ACTIVE
1384 * up to MEI_POLLING_TIMEOUT_IDLE.
1390 int mei_me_polling_thread(void *_dev)
1392 struct mei_device *dev = _dev;
1393 irqreturn_t irq_ret;
1394 long polling_timeout = MEI_POLLING_TIMEOUT_ACTIVE;
1396 dev_dbg(dev->dev, "kernel thread is running\n");
1397 while (!kthread_should_stop()) {
1398 struct mei_me_hw *hw = to_me_hw(dev);
1401 wait_event_timeout(hw->wait_active,
1402 hw->is_active || kthread_should_stop(),
1403 msecs_to_jiffies(MEI_POLLING_TIMEOUT_IDLE));
1405 if (kthread_should_stop())
1408 hcsr = mei_hcsr_read(dev);
1409 if (me_intr_src(hcsr)) {
1410 polling_timeout = MEI_POLLING_TIMEOUT_ACTIVE;
1411 irq_ret = mei_me_irq_thread_handler(1, dev);
1412 if (irq_ret != IRQ_HANDLED)
1413 dev_err(dev->dev, "irq_ret %d\n", irq_ret);
1416 * Increase timeout by MEI_POLLING_TIMEOUT_ACTIVE
1417 * up to MEI_POLLING_TIMEOUT_IDLE
1419 polling_timeout = clamp_val(polling_timeout + MEI_POLLING_TIMEOUT_ACTIVE,
1420 MEI_POLLING_TIMEOUT_ACTIVE,
1421 MEI_POLLING_TIMEOUT_IDLE);
1424 schedule_timeout_interruptible(msecs_to_jiffies(polling_timeout));
1429 EXPORT_SYMBOL_GPL(mei_me_polling_thread);
1431 static const struct mei_hw_ops mei_me_hw_ops = {
1433 .trc_status = mei_me_trc_status,
1434 .fw_status = mei_me_fw_status,
1435 .pg_state = mei_me_pg_state,
1437 .host_is_ready = mei_me_host_is_ready,
1439 .hw_is_ready = mei_me_hw_is_ready,
1440 .hw_reset = mei_me_hw_reset,
1441 .hw_config = mei_me_hw_config,
1442 .hw_start = mei_me_hw_start,
1444 .pg_in_transition = mei_me_pg_in_transition,
1445 .pg_is_enabled = mei_me_pg_is_enabled,
1447 .intr_clear = mei_me_intr_clear,
1448 .intr_enable = mei_me_intr_enable,
1449 .intr_disable = mei_me_intr_disable,
1450 .synchronize_irq = mei_me_synchronize_irq,
1452 .hbuf_free_slots = mei_me_hbuf_empty_slots,
1453 .hbuf_is_ready = mei_me_hbuf_is_empty,
1454 .hbuf_depth = mei_me_hbuf_depth,
1456 .write = mei_me_hbuf_write,
1458 .rdbuf_full_slots = mei_me_count_full_read_slots,
1459 .read_hdr = mei_me_mecbrw_read,
1460 .read = mei_me_read_slots
1464 * mei_me_fw_type_nm() - check for nm sku
1466 * Read ME FW Status register to check for the Node Manager (NM) Firmware.
1467 * The NM FW is only signaled in PCI function 0.
1468 * __Note__: Deprecated by PCH8 and newer.
1472 * Return: true in case of NM firmware
1474 static bool mei_me_fw_type_nm(const struct pci_dev *pdev)
1479 devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
1480 pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_2, ®);
1481 trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg);
1482 /* make sure that bit 9 (NM) is up and bit 10 (DM) is down */
1483 return (reg & 0x600) == 0x200;
1486 #define MEI_CFG_FW_NM \
1487 .quirk_probe = mei_me_fw_type_nm
1490 * mei_me_fw_type_sps_4() - check for sps 4.0 sku
1492 * Read ME FW Status register to check for SPS Firmware.
1493 * The SPS FW is only signaled in the PCI function 0.
1494 * __Note__: Deprecated by SPS 5.0 and newer.
1498 * Return: true in case of SPS firmware
1500 static bool mei_me_fw_type_sps_4(const struct pci_dev *pdev)
1505 devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
1506 pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_1, ®);
1507 trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
1508 return (reg & PCI_CFG_HFS_1_OPMODE_MSK) == PCI_CFG_HFS_1_OPMODE_SPS;
1511 #define MEI_CFG_FW_SPS_4 \
1512 .quirk_probe = mei_me_fw_type_sps_4
1515 * mei_me_fw_type_sps_ign() - check for sps or ign sku
1517 * Read ME FW Status register to check for SPS or IGN Firmware.
1518 * The SPS/IGN FW is only signaled in pci function 0
1522 * Return: true in case of SPS/IGN firmware
1524 static bool mei_me_fw_type_sps_ign(const struct pci_dev *pdev)
1530 devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
1531 pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_3, ®);
1532 trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_3", PCI_CFG_HFS_3, reg);
1533 fw_type = (reg & PCI_CFG_HFS_3_FW_SKU_MSK);
1535 dev_dbg(&pdev->dev, "fw type is %d\n", fw_type);
1537 return fw_type == PCI_CFG_HFS_3_FW_SKU_IGN ||
1538 fw_type == PCI_CFG_HFS_3_FW_SKU_SPS;
1541 #define MEI_CFG_KIND_ITOUCH \
1544 #define MEI_CFG_TYPE_GSC \
1547 #define MEI_CFG_TYPE_GSCFI \
1550 #define MEI_CFG_FW_SPS_IGN \
1551 .quirk_probe = mei_me_fw_type_sps_ign
1553 #define MEI_CFG_FW_VER_SUPP \
1554 .fw_ver_supported = 1
1556 #define MEI_CFG_ICH_HFS \
1557 .fw_status.count = 0
1559 #define MEI_CFG_ICH10_HFS \
1560 .fw_status.count = 1, \
1561 .fw_status.status[0] = PCI_CFG_HFS_1
1563 #define MEI_CFG_PCH_HFS \
1564 .fw_status.count = 2, \
1565 .fw_status.status[0] = PCI_CFG_HFS_1, \
1566 .fw_status.status[1] = PCI_CFG_HFS_2
1568 #define MEI_CFG_PCH8_HFS \
1569 .fw_status.count = 6, \
1570 .fw_status.status[0] = PCI_CFG_HFS_1, \
1571 .fw_status.status[1] = PCI_CFG_HFS_2, \
1572 .fw_status.status[2] = PCI_CFG_HFS_3, \
1573 .fw_status.status[3] = PCI_CFG_HFS_4, \
1574 .fw_status.status[4] = PCI_CFG_HFS_5, \
1575 .fw_status.status[5] = PCI_CFG_HFS_6
1577 #define MEI_CFG_DMA_128 \
1578 .dma_size[DMA_DSCR_HOST] = SZ_128K, \
1579 .dma_size[DMA_DSCR_DEVICE] = SZ_128K, \
1580 .dma_size[DMA_DSCR_CTRL] = PAGE_SIZE
1582 #define MEI_CFG_TRC \
1583 .hw_trc_supported = 1
1585 /* ICH Legacy devices */
1586 static const struct mei_cfg mei_me_ich_cfg = {
1591 static const struct mei_cfg mei_me_ich10_cfg = {
1596 static const struct mei_cfg mei_me_pch6_cfg = {
1601 static const struct mei_cfg mei_me_pch7_cfg = {
1603 MEI_CFG_FW_VER_SUPP,
1606 /* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
1607 static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
1609 MEI_CFG_FW_VER_SUPP,
1613 /* PCH8 Lynx Point and newer devices */
1614 static const struct mei_cfg mei_me_pch8_cfg = {
1616 MEI_CFG_FW_VER_SUPP,
1619 /* PCH8 Lynx Point and newer devices - iTouch */
1620 static const struct mei_cfg mei_me_pch8_itouch_cfg = {
1621 MEI_CFG_KIND_ITOUCH,
1623 MEI_CFG_FW_VER_SUPP,
1626 /* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
1627 static const struct mei_cfg mei_me_pch8_sps_4_cfg = {
1629 MEI_CFG_FW_VER_SUPP,
1633 /* LBG with quirk for SPS (4.0) Firmware exclusion */
1634 static const struct mei_cfg mei_me_pch12_sps_4_cfg = {
1636 MEI_CFG_FW_VER_SUPP,
1640 /* Cannon Lake and newer devices */
1641 static const struct mei_cfg mei_me_pch12_cfg = {
1643 MEI_CFG_FW_VER_SUPP,
1647 /* Cannon Lake with quirk for SPS 5.0 and newer Firmware exclusion */
1648 static const struct mei_cfg mei_me_pch12_sps_cfg = {
1650 MEI_CFG_FW_VER_SUPP,
1655 /* Cannon Lake itouch with quirk for SPS 5.0 and newer Firmware exclusion
1658 static const struct mei_cfg mei_me_pch12_itouch_sps_cfg = {
1659 MEI_CFG_KIND_ITOUCH,
1661 MEI_CFG_FW_VER_SUPP,
1665 /* Tiger Lake and newer devices */
1666 static const struct mei_cfg mei_me_pch15_cfg = {
1668 MEI_CFG_FW_VER_SUPP,
1673 /* Tiger Lake with quirk for SPS 5.0 and newer Firmware exclusion */
1674 static const struct mei_cfg mei_me_pch15_sps_cfg = {
1676 MEI_CFG_FW_VER_SUPP,
1682 /* Graphics System Controller */
1683 static const struct mei_cfg mei_me_gsc_cfg = {
1686 MEI_CFG_FW_VER_SUPP,
1689 /* Graphics System Controller Firmware Interface */
1690 static const struct mei_cfg mei_me_gscfi_cfg = {
1693 MEI_CFG_FW_VER_SUPP,
1697 * mei_cfg_list - A list of platform platform specific configurations.
1698 * Note: has to be synchronized with enum mei_cfg_idx.
1700 static const struct mei_cfg *const mei_cfg_list[] = {
1701 [MEI_ME_UNDEF_CFG] = NULL,
1702 [MEI_ME_ICH_CFG] = &mei_me_ich_cfg,
1703 [MEI_ME_ICH10_CFG] = &mei_me_ich10_cfg,
1704 [MEI_ME_PCH6_CFG] = &mei_me_pch6_cfg,
1705 [MEI_ME_PCH7_CFG] = &mei_me_pch7_cfg,
1706 [MEI_ME_PCH_CPT_PBG_CFG] = &mei_me_pch_cpt_pbg_cfg,
1707 [MEI_ME_PCH8_CFG] = &mei_me_pch8_cfg,
1708 [MEI_ME_PCH8_ITOUCH_CFG] = &mei_me_pch8_itouch_cfg,
1709 [MEI_ME_PCH8_SPS_4_CFG] = &mei_me_pch8_sps_4_cfg,
1710 [MEI_ME_PCH12_CFG] = &mei_me_pch12_cfg,
1711 [MEI_ME_PCH12_SPS_4_CFG] = &mei_me_pch12_sps_4_cfg,
1712 [MEI_ME_PCH12_SPS_CFG] = &mei_me_pch12_sps_cfg,
1713 [MEI_ME_PCH12_SPS_ITOUCH_CFG] = &mei_me_pch12_itouch_sps_cfg,
1714 [MEI_ME_PCH15_CFG] = &mei_me_pch15_cfg,
1715 [MEI_ME_PCH15_SPS_CFG] = &mei_me_pch15_sps_cfg,
1716 [MEI_ME_GSC_CFG] = &mei_me_gsc_cfg,
1717 [MEI_ME_GSCFI_CFG] = &mei_me_gscfi_cfg,
1720 const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx)
1722 BUILD_BUG_ON(ARRAY_SIZE(mei_cfg_list) != MEI_ME_NUM_CFG);
1724 if (idx >= MEI_ME_NUM_CFG)
1727 return mei_cfg_list[idx];
1729 EXPORT_SYMBOL_GPL(mei_me_get_cfg);
1732 * mei_me_dev_init - allocates and initializes the mei device structure
1734 * @parent: device associated with physical device (pci/platform)
1735 * @cfg: per device generation config
1736 * @slow_fw: configure longer timeouts as FW is slow
1738 * Return: The mei_device pointer on success, NULL on failure.
1740 struct mei_device *mei_me_dev_init(struct device *parent,
1741 const struct mei_cfg *cfg, bool slow_fw)
1743 struct mei_device *dev;
1744 struct mei_me_hw *hw;
1747 dev = devm_kzalloc(parent, sizeof(*dev) + sizeof(*hw), GFP_KERNEL);
1753 for (i = 0; i < DMA_DSCR_NUM; i++)
1754 dev->dr_dscr[i].size = cfg->dma_size[i];
1756 mei_device_init(dev, parent, slow_fw, &mei_me_hw_ops);
1759 dev->fw_f_fw_ver_supported = cfg->fw_ver_supported;
1761 dev->kind = cfg->kind;
1765 EXPORT_SYMBOL_GPL(mei_me_dev_init);