mei: add support for txe hw
Subsystems (2)
cover mei: add support for txe hw
Add support for Trusted Execution Environment (TXE) hardware.
Tomas Winkler (5):
mei: txe: add hw-txe-regs.h header file
mei: txe: add hw-txe.h header file
mei: txe: add hw-txe.c
mei: txe: add pci-txe.c
mei: txe: add Kbuild for TXE device
drivers/misc/mei/Kconfig | 9 + drivers/misc/mei/Makefile | 6 +- drivers/misc/mei/hw-txe-regs.h | 294 +++++++++++ drivers/misc/mei/hw-txe.c | 1106 ++++++++++++++++++++++++++++++++++++++++ drivers/misc/mei/hw-txe.h | 71 +++ drivers/misc/mei/pci-txe.c | 293 +++++++++++ 6 files changed, 1778 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/mei/hw-txe-regs.h create mode 100644 drivers/misc/mei/hw-txe.c create mode 100644 drivers/misc/mei/hw-txe.h create mode 100644 drivers/misc/mei/pci-txe.c
Signature · 1 line
1.8.4.2
PATCH 1/5 mei: txe: add hw-txe-regs.h header file
This header file add register definitions
for TXE hardware found BayTrail platforms.
--- drivers/misc/mei/hw-txe-regs.h | 294 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 drivers/misc/mei/hw-txe-regs.h
drivers/misc/mei/hw-txe-regs.h new file +294 -0
@@ -0,0 +1,294 @@ +/****************************************************************************** +* Intel Management Engine Interface (Intel MEI) Linux driver +* Intel MEI Interface Header +* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* GPL LICENSE SUMMARY +* +* Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* The full GNU General Public License is included in this distribution +* in the file called COPYING +* +* Contact Information: +* Intel Corporation. +* [email protected] +* http://www.intel.com +* +* BSD LICENSE +* +* Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*****************************************************************************/ +#ifndef _MEI_HW_TXE_REGS_H_ +#define _MEI_HW_TXE_REGS_H_ + +#include "hw.h" + +#define SEC_ALIVENESS_TIMER_TIMEOUT (5 * MSEC_PER_SEC) +#define SEC_ALIVENESS_WAIT_TIMEOUT (1 * MSEC_PER_SEC) +#define SEC_RESET_WAIT_TIMEOUT (1 * MSEC_PER_SEC) +#define SEC_READY_WAIT_TIMEOUT (5 * MSEC_PER_SEC) +#define START_MESSAGE_RESPONSE_WAIT_TIMEOUT (5 * MSEC_PER_SEC) +#define RESET_CANCEL_WAIT_TIMEOUT (1 * MSEC_PER_SEC) + +enum { +SEC_BAR , +BRIDGE_BAR , + +NUM_OF_MEM_BARS +}; + +/* SeC FW Status Register +* +* FW uses this register in order to report its status to host. +* This register resides in PCI-E config space. +*/ +#define PCI_CFG_TXE_FW_STS0 0x40 +# define PCI_CFG_TXE_FW_STS0_WRK_ST_MSK 0x0000000F +# define PCI_CFG_TXE_FW_STS0_OP_ST_MSK 0x000001C0 +# define PCI_CFG_TXE_FW_STS0_FW_INIT_CMPLT 0x00000200 +# define PCI_CFG_TXE_FW_STS0_ERR_CODE_MSK 0x0000F000 +# define PCI_CFG_TXE_FW_STS0_OP_MODE_MSK 0x000F0000 +# define PCI_CFG_TXE_FW_STS0_RST_CNT_MSK 0x00F00000 + + +#define IPC_BASE_ADDR 0x80400/* SeC IPC Base Address */ + +/* IPC Input Doorbell Register */ +#define SEC_IPC_INPUT_DOORBELL_REG (0x0000 + IPC_BASE_ADDR) + +/* IPC Input Status Register +* This register indicates whether or not processing of +* the most recent command has been completed by the SEC +* New commands and payloads should not be written by the Host +* until this indicates that the previous command has been processed. +*/ +#define SEC_IPC_INPUT_STATUS_REG (0x0008 + IPC_BASE_ADDR) +# define SEC_IPC_INPUT_STATUS_RDY BIT(0) + +/* IPC Host Interrupt Status Register */ +#define SEC_IPC_HOST_INT_STATUS_REG (0x0010 + IPC_BASE_ADDR) +#define SEC_IPC_HOST_INT_STATUS_OUT_DB BIT(0) +#define SEC_IPC_HOST_INT_STATUS_IN_RDY BIT(1) +#define SEC_IPC_HOST_INT_STATUS_HDCP_M0_RCVD BIT(5) +#define SEC_IPC_HOST_INT_STATUS_ILL_MEM_ACCESS BIT(17) +#define SEC_IPC_HOST_INT_STATUS_AES_HKEY_ERR BIT(18) +#define SEC_IPC_HOST_INT_STATUS_DES_HKEY_ERR BIT(19) +#define SEC_IPC_HOST_INT_STATUS_TMRMTB_OVERFLOW BIT(21) + +/* Convenient mask for pending interrupts */ +#define SEC_IPC_HOST_INT_STATUS_PENDING \ + (SEC_IPC_HOST_INT_STATUS_OUT_DB| \ + SEC_IPC_HOST_INT_STATUS_IN_RDY) + +/* IPC Host Interrupt Mask Register */ +#define SEC_IPC_HOST_INT_MASK_REG (0x0014 + IPC_BASE_ADDR) + +# define SEC_IPC_HOST_INT_MASK_OUT_DB BIT(0)/* Output Doorbell Int Mask */ +# define SEC_IPC_HOST_INT_MASK_IN_RDY BIT(1)/* Input Ready Int Mask */ + +/* IPC Input Payload RAM */ +#define SEC_IPC_INPUT_PAYLOAD_REG (0x0100 + IPC_BASE_ADDR) +/* IPC Shared Payload RAM */ +#define IPC_SHARED_PAYLOAD_REG (0x0200 + IPC_BASE_ADDR) + +/* SeC Address Translation Table Entry 2 - Ctrl +* +* This register resides also in SeC's PCI-E Memory space. +*/ +#define SATT2_CTRL_REG 0x1040 +# define SATT2_CTRL_VALID_MSK BIT(0) +# define SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT 8 +# define SATT2_CTRL_BRIDGE_HOST_EN_MSK BIT(12) + +/* SATT Table Entry 2 SAP Base Address Register */ +#define SATT2_SAP_BA_REG 0x1044 +/* SATT Table Entry 2 SAP Size Register. */ +#define SATT2_SAP_SIZE_REG 0x1048 +/* SATT Table Entry 2 SAP Bridge Address - LSB Register */ +#define SATT2_BRG_BA_LSB_REG 0x104C + +/* Host High-level Interrupt Status Register */ +#define HHISR_REG 0x2020 +/* Host High-level Interrupt Enable Register +* +* Resides in PCI memory space. This is the top hierarchy for +* interrupts from SeC to host, aggregating both interrupts that +* arrive through HICR registers as well as interrupts +* that arrive via IPC. +*/ +#define HHIER_REG 0x2024 +#define IPC_HHIER_SEC BIT(0) +#define IPC_HHIER_BRIDGE BIT(1) +#define IPC_HHIER_MSK (IPC_HHIER_SEC | IPC_HHIER_BRIDGE) + +/* Host High-level Interrupt Mask Register. +* +* Resides in PCI memory space. +* This is the top hierarchy for masking interrupts from SeC to host. +*/ +#define HHIMR_REG 0x2028 +#define IPC_HHIMR_SEC BIT(0) +#define IPC_HHIMR_BRIDGE BIT(1) + +/* Host High-level IRQ Status Register */ +#define HHIRQSR_REG 0x202C + +/* Host Interrupt Cause Register 0 - SeC IPC Readiness +* +* This register is both an ICR to Host from PCI Memory Space +* and it is also exposed in the SeC memory space. +* This register is used by SeC's IPC driver in order +* to synchronize with host about IPC interface state. +*/ +#define HICR_SEC_IPC_READINESS_REG 0x2040 +#define HICR_SEC_IPC_READINESS_HOST_RDY BIT(0) +#define HICR_SEC_IPC_READINESS_SEC_RDY BIT(1) +#define HICR_SEC_IPC_READINESS_SYS_RDY \ + (HICR_SEC_IPC_READINESS_HOST_RDY | \ + HICR_SEC_IPC_READINESS_SEC_RDY) +#define HICR_SEC_IPC_READINESS_RDY_CLR BIT(2) + +/* Host Interrupt Cause Register 1 - Aliveness Response */ +/* This register is both an ICR to Host from PCI Memory Space +* and it is also exposed in the SeC memory space. +* The register may be used by SeC to ACK a host request for aliveness. +*/ +#define HICR_HOST_ALIVENESS_RESP_REG 0x2044 +#define HICR_HOST_ALIVENESS_RESP_ACK BIT(0) + +/* Host Interrupt Cause Register 2 - SeC IPC Output Doorbell */ +#define HICR_SEC_IPC_OUTPUT_DOORBELL_REG 0x2048 + +/* Host Interrupt Status Register. +* +* Resides in PCI memory space. +* This is the main register involved in generating interrupts +* from SeC to host via HICRs. +* The interrupt generation rules are as follows: +* An interrupt will be generated whenever for any i, +* there is a transition from a state where at least one of +* the following conditions did not hold, to a state where +* ALL the following conditions hold: +* A) HISR.INT[i]_STS == 1. +* B) HIER.INT[i]_EN == 1. +*/ +#define HISR_REG 0x2060 +#define HISR_INT_0_STS BIT(0) +#define HISR_INT_1_STS BIT(1) +#define HISR_INT_2_STS BIT(2) +#define HISR_INT_3_STS BIT(3) +#define HISR_INT_4_STS BIT(4) +#define HISR_INT_5_STS BIT(5) +#define HISR_INT_6_STS BIT(6) +#define HISR_INT_7_STS BIT(7) +#define HISR_INT_STS_MSK \ + (HISR_INT_0_STS | HISR_INT_1_STS | HISR_INT_2_STS) + +/* Host Interrupt Enable Register. Resides in PCI memory space. */ +#define HIER_REG 0x2064 +#define HIER_INT_0_EN BIT(0) +#define HIER_INT_1_EN BIT(1) +#define HIER_INT_2_EN BIT(2) +#define HIER_INT_3_EN BIT(3) +#define HIER_INT_4_EN BIT(4) +#define HIER_INT_5_EN BIT(5) +#define HIER_INT_6_EN BIT(6) +#define HIER_INT_7_EN BIT(7) + +#define HIER_INT_EN_MSK \ + (HIER_INT_0_EN | HIER_INT_1_EN | HIER_INT_2_EN) + + +/* SEC Memory Space IPC output payload. +* +* This register is part of the output payload which SEC provides to host. +*/ +#define BRIDGE_IPC_OUTPUT_PAYLOAD_REG 0x20C0 + +/* SeC Interrupt Cause Register - Host Aliveness Request +* This register is both an ICR to SeC and it is also exposed +* in the host-visible PCI memory space. +* The register is used by host to request SeC aliveness. +*/ +#define SICR_HOST_ALIVENESS_REQ_REG 0x214C +#define SICR_HOST_ALIVENESS_REQ_REQUESTED BIT(0) + + +/* SeC Interrupt Cause Register - Host IPC Readiness +* +* This register is both an ICR to SeC and it is also exposed +* in the host-visible PCI memory space. +* This register is used by the host's SeC driver uses in order +* to synchronize with SeC about IPC interface state. +*/ +#define SICR_HOST_IPC_READINESS_REQ_REG 0x2150 + + +#define SICR_HOST_IPC_READINESS_HOST_RDY BIT(0) +#define SICR_HOST_IPC_READINESS_SEC_RDY BIT(1) +#define SICR_HOST_IPC_READINESS_SYS_RDY \ + (SICR_HOST_IPC_READINESS_HOST_RDY | \ + SICR_HOST_IPC_READINESS_SEC_RDY) +#define SICR_HOST_IPC_READINESS_RDY_CLR BIT(2) + +/* SeC Interrupt Cause Register - SeC IPC Output Status +* +* This register indicates whether or not processing of the most recent +* command has been completed by the Host. +* New commands and payloads should not be written by SeC until this +* register indicates that the previous command has been processed. +*/ +#define SICR_SEC_IPC_OUTPUT_STATUS_REG 0x2154 +# define SEC_IPC_OUTPUT_STATUS_RDY BIT(0) + + + +/* MEI IPC Message payload size 64 bytes */ +#define PAYLOAD_SIZE 64 + +/* MAX size for SATT range 32MB */ +#define SATT_RANGE_MAX (32 << 20) + + +#endif /* _MEI_HW_TXE_REGS_H_ */ +
Signature · 1 line
1.8.4.2
PATCH 2/5 mei: txe: add hw-txe.h header file
In reply to Tomas WinklerThis header file add mei_txe_hw structure
that hold txe hw specific state and other sw constructs.
--- drivers/misc/mei/hw-txe.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 drivers/misc/mei/hw-txe.h
drivers/misc/mei/hw-txe.h new file +71 -0
@@ -0,0 +1,71 @@ +/* +* +* Intel Management Engine Interface (Intel MEI) Linux driver +* Copyright (c) 2013-2014, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +*/ + +#ifndef _MEI_HW_TXE_H_ +#define _MEI_HW_TXE_H_ + +#include "hw.h" +#include "hw-txe-regs.h" + +/* Flatten Hierarchy interrupt cause */ +#define TXE_INTR_READINESS_BIT 0/* HISR_INT_0_STS */ +#define TXE_INTR_READINESS HISR_INT_0_STS +#define TXE_INTR_ALIVENESS_BIT 1/* HISR_INT_1_STS */ +#define TXE_INTR_ALIVENESS HISR_INT_1_STS +#define TXE_INTR_OUT_DB_BIT 2/* HISR_INT_2_STS */ +#define TXE_INTR_OUT_DB HISR_INT_2_STS +#define TXE_INTR_IN_READY_BIT 8/* beyond HISR */ +#define TXE_INTR_IN_READY BIT(8) + +/** +* struct mei_txe_hw - txe hardware specifics +* +* @mem_addr: SeC and BRIDGE bars +* @aliveness: aliveness (power gating) state of the hardware +* @readiness: readiness state of the hardware +* @wait_aliveness: aliveness wait queue +* @recvd_aliveness: aliveness interrupt was recived +* @intr_cause: translated interrupt cause +*/ +struct mei_txe_hw { +void __iomem *mem_addr[NUM_OF_MEM_BARS ]; +u32 aliveness; +u32 readiness; + +wait_queue_head_t wait_aliveness; +bool recvd_aliveness; + +unsigned long intr_cause; +}; + +#define to_txe_hw (dev) (struct mei_txe_hw *)((dev)->hw) + +static inline struct mei_device *hw_txe_to_mei (struct mei_txe_hw *hw) +{ + return container_of((void *)hw, struct mei_device, hw); +} + +struct mei_device *mei_txe_dev_init (struct pci_dev *pdev); + +irqreturn_t mei_txe_irq_quick_handler (int irq,void *dev_id); +irqreturn_t mei_txe_irq_thread_handler (int irq,void *dev_id); + +int mei_txe_aliveness_set_sync (struct mei_device *dev,u32 req); + +int mei_txe_setup_satt2 (struct mei_device *dev,phys_addr_t addr,u32 range); + + +#endif /* _MEI_HW_TXE_H_ */
Signature · 1 line
1.8.4.2
PATCH 3/5 mei: txe: add hw-txe.c
In reply to Tomas Winklerhw-txe.c adds txe hw specific functionality
It implements hw specific interrupt handler, mei_hw_ops functions and as well txe hw helpers
--- drivers/misc/mei/hw-txe.c | 1106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1106 insertions(+) create mode 100644 drivers/misc/mei/hw-txe.c
drivers/misc/mei/hw-txe.c new file +1106 -0
@@ -0,0 +1,1106 @@ +/* +* +* Intel Management Engine Interface (Intel MEI) Linux driver +* Copyright (c) 2013-2014, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +*/ + +#include <linux/pci.h> +#include <linux/jiffies.h> +#include <linux/delay.h> +#include <linux/kthread.h> + +#include <linux/mei.h> + +#include "mei_dev.h" +#include "hw-txe.h" +#include "client.h" +#include "hbm.h" + +/** +* mei_txe_reg_read - Reads 32bit data from the device +* +* @base_addr: registers base address +* @offset: register offset +* +*/ +static inline u32 mei_txe_reg_read (void __iomem *base_addr, +unsigned long offset) +{ +return ioread32 (base_addr + offset); +} + +/** +* mei_txe_reg_write - Writes 32bit data to the device +* +* @base_addr: registers base address +* @offset: register offset +* @value: the value to write +*/ +static inline void mei_txe_reg_write (void __iomem *base_addr, +unsigned long offset,u32 value) +{ +iowrite32 (value, base_addr + offset); +} + +/** +* mei_txe_sec_reg_read_silent - Reads 32bit data from the SeC BAR +* +* @dev: the device structure +* @offset: register offset +* +* Doesn't check for aliveness while Reads 32bit data from the SeC BAR +*/ +static inline u32 mei_txe_sec_reg_read_silent (struct mei_txe_hw *hw, +unsigned long offset) +{ +return mei_txe_reg_read (hw->mem_addr[SEC_BAR ], offset); +} + +/** +* mei_txe_sec_reg_read - Reads 32bit data from the SeC BAR +* +* @dev: the device structure +* @offset: register offset +* +* Reads 32bit data from the SeC BAR and shout loud if aliveness is not set +*/ +static inline u32 mei_txe_sec_reg_read (struct mei_txe_hw *hw, +unsigned long offset) +{ +WARN (!hw->aliveness,"sec read: aliveness not asserted\n" ); +return mei_txe_sec_reg_read_silent (hw, offset); +} +/** +* mei_txe_sec_reg_write_silent - Writes 32bit data to the SeC BAR +* doesn't check for aliveness +* +* @dev: the device structure +* @offset: register offset +* @value: value to write +* +* Doesn't check for aliveness while writes 32bit data from to the SeC BAR +*/ +static inline void mei_txe_sec_reg_write_silent (struct mei_txe_hw *hw, +unsigned long offset,u32 value) +{ +mei_txe_reg_write (hw->mem_addr[SEC_BAR ], offset, value); +} + +/** +* mei_txe_sec_reg_write - Writes 32bit data to the SeC BAR +* +* @dev: the device structure +* @offset: register offset +* @value: value to write +* +* Writes 32bit data from the SeC BAR and shout loud if aliveness is not set +*/ +static inline void mei_txe_sec_reg_write (struct mei_txe_hw *hw, +unsigned long offset,u32 value) +{ +WARN (!hw->aliveness,"sec write: aliveness not asserted\n" ); +mei_txe_sec_reg_write_silent (hw, offset, value); +} +/** +* mei_txe_br_reg_read - Reads 32bit data from the Bridge BAR +* +* @hw: the device structure +* @offset: offset from which to read the data +* +*/ +static inline u32 mei_txe_br_reg_read (struct mei_txe_hw *hw, +unsigned long offset) +{ +return mei_txe_reg_read (hw->mem_addr[BRIDGE_BAR ], offset); +} + +/** +* mei_txe_br_reg_write - Writes 32bit data to the Bridge BAR +* +* @hw: the device structure +* @offset: offset from which to write the data +* @value: the byte to write +*/ +static inline void mei_txe_br_reg_write (struct mei_txe_hw *hw, +unsigned long offset,u32 value) +{ +mei_txe_reg_write (hw->mem_addr[BRIDGE_BAR ], offset, value); +} + +/** +* mei_txe_aliveness_set - request for aliveness change +* +* @dev: the device structure +* @req: requested aliveness value +* +* Request for aliveness change and returns true if the change is +* really needed and false if aliveness is already +* in the requested state +* Requires device lock to be held +*/ +static bool mei_txe_aliveness_set (struct mei_device *dev,u32 req) +{ + +struct mei_txe_hw *hw =to_txe_hw (dev); +bool do_req = hw->aliveness != req; + +dev_dbg (&dev->pdev->dev,"Aliveness current=%d request=%d\n" , + hw->aliveness, req); +if (do_req) { + hw->recvd_aliveness = false; +mei_txe_br_reg_write (hw,SICR_HOST_ALIVENESS_REQ_REG , req); + } +return do_req; +} + + +/** +* mei_txe_aliveness_req_get - get aliveness requested register value +* +* @dev: the device structure +* +* Extract HICR_HOST_ALIVENESS_RESP_ACK bit from +* from HICR_HOST_ALIVENESS_REQ register value +*/ +static u32 mei_txe_aliveness_req_get (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 reg; + reg =mei_txe_br_reg_read (hw,SICR_HOST_ALIVENESS_REQ_REG ); +return reg &SICR_HOST_ALIVENESS_REQ_REQUESTED ; +} + +/** +* mei_txe_aliveness_get - get aliveness response register value +* @dev: the device structure +* +* Extract HICR_HOST_ALIVENESS_RESP_ACK bit +* from HICR_HOST_ALIVENESS_RESP register value +*/ +static u32 mei_txe_aliveness_get (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 reg; + reg =mei_txe_br_reg_read (hw,HICR_HOST_ALIVENESS_RESP_REG ); +return reg &HICR_HOST_ALIVENESS_RESP_ACK ; +} + +/** +* mei_txe_aliveness_poll - waits for aliveness to settle +* +* @dev: the device structure +* @expected: expected aliveness value +* +* Polls for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set +* returns > 0 if the expected value was received, -ETIME otherwise +*/ +static int mei_txe_aliveness_poll (struct mei_device *dev,u32 expected) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +int t =0 ; + +do { + hw->aliveness =mei_txe_aliveness_get (dev); +if (hw->aliveness == expected) { +dev_dbg (&dev->pdev->dev, +"aliveness settled after %d msecs\n" , t); +return t; + } +mutex_unlock (&dev->device_lock); +msleep (MSEC_PER_SEC /5 ); +mutex_lock (&dev->device_lock); + t +=MSEC_PER_SEC /5 ; + }while (t <SEC_ALIVENESS_WAIT_TIMEOUT ); + +dev_err (&dev->pdev->dev,"aliveness timed out\n" ); +return -ETIME ; +} + +/** +* mei_txe_aliveness_wait - waits for aliveness to settle +* +* @dev: the device structure +* @expected: expected aliveness value +* +* Waits for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set +* returns returns 0 on success and < 0 otherwise +*/ +static int mei_txe_aliveness_wait (struct mei_device *dev,u32 expected) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +const unsigned long timeout = +msecs_to_jiffies (SEC_ALIVENESS_WAIT_TIMEOUT ); +long err; +int ret; + + hw->aliveness =mei_txe_aliveness_get (dev); +if (hw->aliveness == expected) +return 0 ; + +mutex_unlock (&dev->device_lock); + err =wait_event_timeout (hw->wait_aliveness, + hw->recvd_aliveness, timeout); +mutex_lock (&dev->device_lock); + + hw->aliveness =mei_txe_aliveness_get (dev); + ret = hw->aliveness == expected ?0 : -ETIME ; + +if (ret) +dev_err (&dev->pdev->dev,"aliveness timed out" ); +else +dev_dbg (&dev->pdev->dev,"aliveness settled after %d msecs\n" , +jiffies_to_msecs (timeout - err)); + hw->recvd_aliveness = false; +return ret; +} + +/** +* mei_txe_aliveness_set_sync - sets an wait for aliveness to complete +* +* @dev: the device structure +* +* returns returns 0 on success and < 0 otherwise +*/ +int mei_txe_aliveness_set_sync (struct mei_device *dev,u32 req) +{ +if (mei_txe_aliveness_set (dev, req)) +return mei_txe_aliveness_wait (dev, req); +return 0 ; +} + +/** +* mei_txe_input_ready_interrupt_enable - sets the Input Ready Interrupt +* +* @dev: the device structure +*/ +static void mei_txe_input_ready_interrupt_enable (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 hintmsk; +/* Enable the SEC_IPC_HOST_INT_MASK_IN_RDY interrupt */ + hintmsk =mei_txe_sec_reg_read (hw,SEC_IPC_HOST_INT_MASK_REG ); + hintmsk |=SEC_IPC_HOST_INT_MASK_IN_RDY ; +mei_txe_sec_reg_write (hw,SEC_IPC_HOST_INT_MASK_REG , hintmsk); +} + +/** +* mei_txe_input_doorbell_set +* - Sets bit 0 in SEC_IPC_INPUT_DOORBELL.IPC_INPUT_DOORBELL. +* @dev: the device structure +*/ +static void mei_txe_input_doorbell_set (struct mei_txe_hw *hw) +{ +/* Clear the interrupt cause */ +clear_bit (TXE_INTR_IN_READY_BIT , &hw->intr_cause); +mei_txe_sec_reg_write (hw,SEC_IPC_INPUT_DOORBELL_REG ,1 ); +} + +/** +* mei_txe_output_ready_set - Sets the SICR_SEC_IPC_OUTPUT_STATUS bit to 1 +* +* @dev: the device structure +*/ +static void mei_txe_output_ready_set (struct mei_txe_hw *hw) +{ +mei_txe_br_reg_write (hw, +SICR_SEC_IPC_OUTPUT_STATUS_REG , +SEC_IPC_OUTPUT_STATUS_RDY ); +} + +/** +* mei_txe_is_input_ready - check if TXE is ready for receiving data +* +* @dev: the device structure +*/ +static bool mei_txe_is_input_ready (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 status; + status =mei_txe_sec_reg_read (hw,SEC_IPC_INPUT_STATUS_REG ); +return !!(SEC_IPC_INPUT_STATUS_RDY & status); +} + +/** +* mei_txe_intr_clear - clear all interrupts +* +* @dev: the device structure +*/ +static inline void mei_txe_intr_clear (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_sec_reg_write_silent (hw,SEC_IPC_HOST_INT_STATUS_REG , +SEC_IPC_HOST_INT_STATUS_PENDING ); +mei_txe_br_reg_write (hw,HISR_REG ,HISR_INT_STS_MSK ); +mei_txe_br_reg_write (hw,HHISR_REG ,IPC_HHIER_MSK ); +} + +/** +* mei_txe_intr_disable - disable all interrupts +* +* @dev: the device structure +*/ +static void mei_txe_intr_disable (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_br_reg_write (hw,HHIER_REG ,0 ); +mei_txe_br_reg_write (hw,HIER_REG ,0 ); +} +/** +* mei_txe_intr_disable - enable all interrupts +* +* @dev: the device structure +*/ +static void mei_txe_intr_enable (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_br_reg_write (hw,HHIER_REG ,IPC_HHIER_MSK ); +mei_txe_br_reg_write (hw,HIER_REG ,HIER_INT_EN_MSK ); +} + +/** +* mei_txe_pending_interrupts - check if there are pending interrupts +* only Aliveness, Input ready, and output doorbell are of relevance +* +* @dev: the device structure +* +* Checks if there are pending interrupts +* only Aliveness, Readiness, Input ready, and Output doorbell are relevant +*/ +static bool mei_txe_pending_interrupts (struct mei_device *dev) +{ + +struct mei_txe_hw *hw =to_txe_hw (dev); +bool ret = (hw->intr_cause & (TXE_INTR_READINESS | +TXE_INTR_ALIVENESS | +TXE_INTR_IN_READY | +TXE_INTR_OUT_DB )); + +if (ret) { +dev_dbg (&dev->pdev->dev, +"Pending Interrupts InReady=%01d Readiness=%01d, Aliveness=%01d, OutDoor=%01d\n" , + !!(hw->intr_cause &TXE_INTR_IN_READY ), + !!(hw->intr_cause &TXE_INTR_READINESS ), + !!(hw->intr_cause &TXE_INTR_ALIVENESS ), + !!(hw->intr_cause &TXE_INTR_OUT_DB )); + } +return ret; +} + +/** +* mei_txe_input_payload_write - write a dword to the host buffer +* at offset idx +* +* @dev: the device structure +* @idx: index in the host buffer +* @value: value +*/ +static void mei_txe_input_payload_write (struct mei_device *dev, +unsigned long idx,u32 value) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_sec_reg_write (hw,SEC_IPC_INPUT_PAYLOAD_REG + + (idx *sizeof (u32)), value); +} + +/** +* mei_txe_out_data_read - read dword from the device buffer +* at offset idx +* +* @dev: the device structure +* @idx: index in the device buffer +* +* returns register value at index +*/ +static u32 mei_txe_out_data_read (const struct mei_device *dev, +unsigned long idx) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +return mei_txe_br_reg_read (hw, +BRIDGE_IPC_OUTPUT_PAYLOAD_REG + (idx *sizeof (u32))); +} + +/* Readiness */ + +/** +* mei_txe_readiness_set_host_rdy +* +* @dev: the device structure +*/ +static void mei_txe_readiness_set_host_rdy (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_br_reg_write (hw, +SICR_HOST_IPC_READINESS_REQ_REG , +SICR_HOST_IPC_READINESS_HOST_RDY ); +} + +/** +* mei_txe_readiness_clear +* +* @dev: the device structure +*/ +static void mei_txe_readiness_clear (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +mei_txe_br_reg_write (hw,SICR_HOST_IPC_READINESS_REQ_REG , +SICR_HOST_IPC_READINESS_RDY_CLR ); +} +/** +* mei_txe_readiness_get - Reads and returns +* the HICR_SEC_IPC_READINESS register value +* +* @dev: the device structure +*/ +static u32 mei_txe_readiness_get (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +return mei_txe_br_reg_read (hw,HICR_SEC_IPC_READINESS_REG ); +} + + +/** +* mei_txe_readiness_is_sec_rdy - check readiness +* for HICR_SEC_IPC_READINESS_SEC_RDY +* +* @readiness - cached readiness state +*/ +static inline bool mei_txe_readiness_is_sec_rdy (u32 readiness) +{ +return !!(readiness &HICR_SEC_IPC_READINESS_SEC_RDY ); +} + +/** +* mei_txe_hw_is_ready - check if the hw is ready +* +* @dev: the device structure +*/ +static bool mei_txe_hw_is_ready (struct mei_device *dev) +{ +u32 readiness =mei_txe_readiness_get (dev); +return mei_txe_readiness_is_sec_rdy (readiness); +} + +/** +* mei_txe_host_is_ready - check if the host is ready +* +* @dev: the device structure +*/ +static inline bool mei_txe_host_is_ready (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 reg =mei_txe_br_reg_read (hw,HICR_SEC_IPC_READINESS_REG ); +return !!(reg &HICR_SEC_IPC_READINESS_HOST_RDY ); +} + +/** +* mei_txe_readiness_wait - wait till readiness settles +* +* @dev: the device structure +* +* returns 0 on success and -ETIME on timeout +*/ +static int mei_txe_readiness_wait (struct mei_device *dev) +{ +if (mei_txe_hw_is_ready (dev)) +return 0 ; + +mutex_unlock (&dev->device_lock); +wait_event_timeout (dev->wait_hw_ready, dev->recvd_hw_ready, +msecs_to_jiffies (SEC_RESET_WAIT_TIMEOUT )); +mutex_lock (&dev->device_lock); +if (!dev->recvd_hw_ready) { +dev_err (&dev->pdev->dev,"wait for readiness failed\n" ); +return -ETIME ; + } + + dev->recvd_hw_ready = false; +return 0 ; +} + +/** +* mei_txe_hw_config - configure hardware at the start of the devices +* +* @dev: the device structure +* +* Configure hardware at the start of the device should be done only +* once at the device probe time +*/ +static void mei_txe_hw_config (struct mei_device *dev) +{ + +struct mei_txe_hw *hw =to_txe_hw (dev); +/* Doesn't change in runtime */ + dev->hbuf_depth =PAYLOAD_SIZE /4 ; + + hw->aliveness =mei_txe_aliveness_get (dev); + hw->readiness =mei_txe_readiness_get (dev); + +dev_dbg (&dev->pdev->dev,"aliveness_resp = 0x%08x, readiness = 0x%08x.\n" , + hw->aliveness, hw->readiness); +} + + +/** +* mei_txe_write - writes a message to device. +* +* @dev: the device structure +* @header: header of message +* @buf: message buffer will be written +* returns 1 if success, 0 - otherwise. +*/ + +static int mei_txe_write (struct mei_device *dev, +struct mei_msg_hdr *header,unsigned char *buf) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +unsigned long rem; +unsigned long length; +u32 *reg_buf = (u32 *)buf; +int i; + +if (WARN_ON (!header || !buf)) +return -EINVAL ; + + length = header->length; + +dev_dbg (&dev->pdev->dev,MEI_HDR_FMT ,MEI_HDR_PRM (header)); + +if ((length +sizeof (struct mei_msg_hdr )) >PAYLOAD_SIZE ) { +dev_err (&dev->pdev->dev,"write length exceeded = %ld > %d\n" , + length +sizeof (struct mei_msg_hdr ),PAYLOAD_SIZE ); +return -ERANGE ; + } + +if (WARN (!hw->aliveness,"txe write: aliveness not asserted\n" )) +return -EAGAIN ; + +/* Enable Input Ready Interrupt. */ +mei_txe_input_ready_interrupt_enable (dev); + +if (!mei_txe_is_input_ready (dev)) { +dev_err (&dev->pdev->dev,"Input is not ready" ); +return -EAGAIN ; + } + +mei_txe_input_payload_write (dev,0 , *((u32 *)header)); + +for (i =0 ; i < length /4 ; i++) +mei_txe_input_payload_write (dev, i +1 , reg_buf[i]); + + rem = length &0x3 ; +if (rem >0 ) { +u32 reg =0 ; +memcpy (®, &buf[length - rem], rem); +mei_txe_input_payload_write (dev, i +1 , reg); + } + + dev->hbuf_is_ready = false; +/* Set Input-Doorbell */ +mei_txe_input_doorbell_set (hw); + +return 0 ; +} + +/** +* mei_txe_hbuf_max_len - mimics the me hbuf circular buffer +* +* @dev: the device structure +* +* returns the PAYLOAD_SIZE - 4 +*/ +static size_t mei_txe_hbuf_max_len (const struct mei_device *dev) +{ +return PAYLOAD_SIZE -sizeof (struct mei_msg_hdr ); +} + +/** +* mei_txe_hbuf_empty_slots - mimics the me hbuf circular buffer +* +* @dev: the device structure +* +* returns always hbuf_depth +*/ +static int mei_txe_hbuf_empty_slots (struct mei_device *dev) +{ +return dev->hbuf_depth; +} + +/** +* mei_txe_count_full_read_slots - mimics the me device circular buffer +* +* @dev: the device structure +* +* returns always buffer size in dwords count +*/ +static int mei_txe_count_full_read_slots (struct mei_device *dev) +{ +/* read buffers has static size */ +return PAYLOAD_SIZE /4 ; +} + +/** +* mei_txe_read_hdr - read message header which is always in 4 first bytes +* +* @dev: the device structure +* +* returns mei message header +*/ + +static u32 mei_txe_read_hdr (const struct mei_device *dev) +{ +return mei_txe_out_data_read (dev,0 ); +} +/** +* mei_txe_read - reads a message from the txe device. +* +* @dev: the device structure +* @buf: message buffer will be written +* @len: message size will be read +* +* returns -EINVAL on error wrong argument and 0 on success +*/ +static int mei_txe_read (struct mei_device *dev, +unsigned char *buf,unsigned long len) +{ + +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 i; +u32 *reg_buf = (u32 *)buf; +u32 rem = len &0x3 ; + +if (WARN_ON (!buf || !len)) +return -EINVAL ; + +dev_dbg (&dev->pdev->dev, +"buffer-length = %lu buf[0]0x%08X\n" , + len,mei_txe_out_data_read (dev,0 )); + +for (i =0 ; i < len /4 ; i++) { +/* skip header: index starts from 1 */ +u32 reg =mei_txe_out_data_read (dev, i +1 ); +dev_dbg (&dev->pdev->dev,"buf[%d] = 0x%08X\n" , i, reg); + *reg_buf++ = reg; + } + +if (rem) { +u32 reg =mei_txe_out_data_read (dev, i +1 ); +memcpy (reg_buf, ®, rem); + } + +mei_txe_output_ready_set (hw); +return 0 ; +} + +/** +* mei_txe_hw_reset - resets host and fw. +* +* @dev: the device structure +* @intr_enable: if interrupt should be enabled after reset. +* +* returns 0 on success and < 0 in case of error +*/ +static int mei_txe_hw_reset (struct mei_device *dev,bool intr_enable) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); + +u32 aliveness_req; +/* +* read input doorbell to ensure consistency between Bridge and SeC +* return value might be garbage return +*/ + (void )mei_txe_sec_reg_read_silent (hw,SEC_IPC_INPUT_DOORBELL_REG ); + + aliveness_req =mei_txe_aliveness_req_get (dev); + hw->aliveness =mei_txe_aliveness_get (dev); + +/* Disable interrupts in this stage we will poll */ +mei_txe_intr_disable (dev); + +/* +* If Aliveness Request and Aliveness Response are not equal then +* wait for them to be equal +* Since we might have interrupts disabled - poll for it +*/ +if (aliveness_req != hw->aliveness) +if (mei_txe_aliveness_poll (dev, aliveness_req) <0 ) { +dev_err (&dev->pdev->dev, +"wait for aliveness settle failed ... bailing out\n" ); +return -EIO ; + } + +/* +* If Aliveness Request and Aliveness Response are set then clear them +*/ +if (aliveness_req) { +mei_txe_aliveness_set (dev,0 ); +if (mei_txe_aliveness_poll (dev,0 ) <0 ) { +dev_err (&dev->pdev->dev, +"wait for aliveness failed ... bailing out\n" ); +return -EIO ; + } + } + +/* +* Set rediness RDY_CLR bit +*/ +mei_txe_readiness_clear (dev); + +return 0 ; +} + +/** +* mei_txe_hw_start - start the hardware after reset +* +* @dev: the device structure +* +* returns 0 on success and < 0 in case of error +*/ +static int mei_txe_hw_start (struct mei_device *dev) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +int ret; + +u32 hisr; + +/* bring back interrupts */ +mei_txe_intr_enable (dev); + + ret =mei_txe_readiness_wait (dev); +if (ret <0 ) { +dev_err (&dev->pdev->dev,"wating for readiness failed\n" ); +return ret; + } + +/* +* If HISR.INT2_STS interrupt status bit is set then clear it. +*/ + hisr =mei_txe_br_reg_read (hw,HISR_REG ); +if (hisr &HISR_INT_2_STS ) +mei_txe_br_reg_write (hw,HISR_REG ,HISR_INT_2_STS ); + +/* Clear the interrupt cause of OutputDoorbell */ +clear_bit (TXE_INTR_OUT_DB_BIT , &hw->intr_cause); + + ret =mei_txe_aliveness_set_sync (dev,1 ); +if (ret <0 ) { +dev_err (&dev->pdev->dev,"wait for aliveness failed ... bailing out\n" ); +return ret; + } + +/* enable input ready interrupts: +* SEC_IPC_HOST_INT_MASK.IPC_INPUT_READY_INT_MASK +*/ +mei_txe_input_ready_interrupt_enable (dev); + + +/* Set the SICR_SEC_IPC_OUTPUT_STATUS.IPC_OUTPUT_READY bit */ +mei_txe_output_ready_set (hw); + +/* Set bit SICR_HOST_IPC_READINESS.HOST_RDY +*/ +mei_txe_readiness_set_host_rdy (dev); + +return 0 ; +} + +/** +* mei_txe_check_and_ack_intrs - translate multi BAR interrupt into +* single bit mask and acknowledge the interrupts +* +* @dev: the device structure +* @do_ack: acknowledge interrupts +*/ +static bool mei_txe_check_and_ack_intrs (struct mei_device *dev,bool do_ack) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); +u32 hisr; +u32 hhisr; +u32 ipc_isr; +u32 aliveness; +bool generated; + +/* read interrupt registers */ + hhisr =mei_txe_br_reg_read (hw,HHISR_REG ); + generated = (hhisr &IPC_HHIER_MSK ); +if (!generated) + goto out; + + hisr =mei_txe_br_reg_read (hw,HISR_REG ); + + aliveness =mei_txe_aliveness_get (dev); +if (hhisr &IPC_HHIER_SEC && aliveness) + ipc_isr =mei_txe_sec_reg_read_silent (hw, +SEC_IPC_HOST_INT_STATUS_REG ); +else + ipc_isr =0 ; + + generated = generated || + (hisr &HISR_INT_STS_MSK ) || + (ipc_isr &SEC_IPC_HOST_INT_STATUS_PENDING ); + +if (generated && do_ack) { +/* Save the interrupt causes */ + hw->intr_cause |= hisr &HISR_INT_STS_MSK ; +if (ipc_isr &SEC_IPC_HOST_INT_STATUS_IN_RDY ) + hw->intr_cause |=TXE_INTR_IN_READY ; + + +mei_txe_intr_disable (dev); +/* Clear the interrupts in hierarchy: +* IPC and Bridge, than the High Level */ +mei_txe_sec_reg_write_silent (hw, +SEC_IPC_HOST_INT_STATUS_REG , ipc_isr); +mei_txe_br_reg_write (hw,HISR_REG , hisr); +mei_txe_br_reg_write (hw,HHISR_REG , hhisr); + } + +out: +return generated; +} + +/** +* mei_txe_irq_quick_handler - The ISR of the MEI device +* +* @irq: The irq number +* @dev_id: pointer to the device structure +* +* returns irqreturn_t +*/ +irqreturn_t mei_txe_irq_quick_handler (int irq,void *dev_id) +{ +struct mei_device *dev = dev_id; + +if (mei_txe_check_and_ack_intrs (dev, true)) +return IRQ_WAKE_THREAD ; +return IRQ_NONE ; +} + + +/** +* mei_txe_irq_thread_handler - txe interrupt thread +* +* @irq: The irq number +* @dev_id: pointer to the device structure +* +* returns irqreturn_t +* +*/ +irqreturn_t mei_txe_irq_thread_handler (int irq,void *dev_id) +{ +struct mei_device *dev = (struct mei_device *) dev_id; +struct mei_txe_hw *hw =to_txe_hw (dev); +struct mei_cl_cb complete_list; +s32 slots; +int rets =0 ; + +dev_dbg (&dev->pdev->dev,"irq thread: Interrupt Registers HHISR|HISR|SEC=%02X|%04X|%02X\n" , +mei_txe_br_reg_read (hw,HHISR_REG ), +mei_txe_br_reg_read (hw,HISR_REG ), +mei_txe_sec_reg_read_silent (hw,SEC_IPC_HOST_INT_STATUS_REG )); + + +/* initialize our complete list */ +mutex_lock (&dev->device_lock); +mei_io_list_init (&complete_list); + +if (pci_dev_msi_enabled (dev->pdev)) +mei_txe_check_and_ack_intrs (dev, true); + +/* show irq events */ +mei_txe_pending_interrupts (dev); + + hw->aliveness =mei_txe_aliveness_get (dev); + hw->readiness =mei_txe_readiness_get (dev); + +/* Readiness: +* Detection of TXE driver going through reset +* or TXE driver resetting the HECI interface. +*/ +if (test_and_clear_bit (TXE_INTR_READINESS_BIT , &hw->intr_cause)) { +dev_dbg (&dev->pdev->dev,"Readiness Interrupt was received...\n" ); + +/* Check if SeC is going through reset */ +if (mei_txe_readiness_is_sec_rdy (hw->readiness)) { +dev_dbg (&dev->pdev->dev,"we need to start the dev.\n" ); + dev->recvd_hw_ready = true; + }else { + dev->recvd_hw_ready = false; +if (dev->dev_state !=MEI_DEV_RESETTING ) { + +dev_warn (&dev->pdev->dev,"FW not ready: resetting.\n" ); +schedule_work (&dev->reset_work); + goto end; + + } + } +wake_up (&dev->wait_hw_ready); + } + +/************************************************************/ +/* Check interrupt cause: +* Aliveness: Detection of SeC acknowledge of host request that +* it remain alive or host cancellation of that request. +*/ + +if (test_and_clear_bit (TXE_INTR_ALIVENESS_BIT , &hw->intr_cause)) { +/* Clear the interrupt cause */ +dev_dbg (&dev->pdev->dev, +"Aliveness Interrupt: Status: %d\n" , hw->aliveness); + hw->recvd_aliveness = true; +if (waitqueue_active (&hw->wait_aliveness)) +wake_up (&hw->wait_aliveness); + } + + +/* Output Doorbell: +* Detection of SeC having sent output to host +*/ + slots =mei_count_full_read_slots (dev); +if (test_and_clear_bit (TXE_INTR_OUT_DB_BIT , &hw->intr_cause)) { +/* Read from TXE */ + rets =mei_irq_read_handler (dev, &complete_list, &slots); +if (rets && dev->dev_state !=MEI_DEV_RESETTING ) { +dev_err (&dev->pdev->dev, +"mei_irq_read_handler ret = %d.\n" , rets); + +schedule_work (&dev->reset_work); + goto end; + } + } +/* Input Ready: Detection if host can write to SeC */ +if (test_and_clear_bit (TXE_INTR_IN_READY_BIT , &hw->intr_cause)) + dev->hbuf_is_ready = true; + +if (hw->aliveness && dev->hbuf_is_ready) { +/* if SeC did not complete reading the written data by host */ +if (!mei_txe_is_input_ready (dev)) { +dev_dbg (&dev->pdev->dev,"got Input Ready Int, but SEC_IPC_INPUT_STATUS_RDY is 0.\n" ); + goto end; + } + + rets =mei_irq_write_handler (dev, &complete_list); +if (rets) +dev_err (&dev->pdev->dev, +"mei_irq_write_handler ret = %d.\n" , rets); + } + + + +mei_irq_compl_handler (dev, &complete_list); + +end: +dev_dbg (&dev->pdev->dev,"interrupt thread end ret = %d\n" , rets); + +mutex_unlock (&dev->device_lock); + +mei_enable_interrupts (dev); +return IRQ_HANDLED ; +} + +static const struct mei_hw_ops mei_txe_hw_ops = { + + .host_is_ready = mei_txe_host_is_ready, + + .hw_is_ready = mei_txe_hw_is_ready, + .hw_reset = mei_txe_hw_reset, + .hw_config = mei_txe_hw_config, + .hw_start = mei_txe_hw_start, + + .intr_clear = mei_txe_intr_clear, + .intr_enable = mei_txe_intr_enable, + .intr_disable = mei_txe_intr_disable, + + .hbuf_free_slots = mei_txe_hbuf_empty_slots, + .hbuf_is_ready = mei_txe_is_input_ready, + .hbuf_max_len = mei_txe_hbuf_max_len, + + .write = mei_txe_write, + + .rdbuf_full_slots = mei_txe_count_full_read_slots, + .read_hdr = mei_txe_read_hdr, + + .read = mei_txe_read, + +}; + +/** +* mei_txe_dev_init - allocates and initializes txe hardware specific structure +* +* @pdev - pci device +* returns struct mei_device * on success or NULL; +* +*/ +struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +{ +struct mei_device *dev; +struct mei_txe_hw *hw; + + dev =kzalloc (sizeof (struct mei_device ) + +sizeof (struct mei_txe_hw ),GFP_KERNEL ); +if (!dev) +return NULL ; + +mei_device_init (dev); + + hw =to_txe_hw (dev); + +init_waitqueue_head (&hw->wait_aliveness); + + dev->ops = &mei_txe_hw_ops; + + dev->pdev = pdev; +return dev; +} + +/** +* mei_txe_setup_satt2 - SATT2 configuration for DMA support. +* +* @dev: the device structure +* @addr: physical address start of the range +* @range: physical range size +*/ +int mei_txe_setup_satt2 (struct mei_device *dev,phys_addr_t addr,u32 range) +{ +struct mei_txe_hw *hw =to_txe_hw (dev); + +u32 lo32 =lower_32_bits (addr); +u32 hi32 =upper_32_bits (addr); +u32 ctrl; + +/* SATT is limited to 36 Bits */ +if (hi32 & ~0xF ) +return -EINVAL ; + +/* SATT has to be 16Byte aligned */ +if (lo32 &0xF ) +return -EINVAL ; + +/* SATT range has to be 4Bytes aligned */ +if (range &0x4 ) +return -EINVAL ; + +/* SATT is limited to 32 MB range*/ +if (range >SATT_RANGE_MAX ) +return -EINVAL ; + + ctrl =SATT2_CTRL_VALID_MSK ; + ctrl |= hi32 <<SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT ; + +mei_txe_br_reg_write (hw,SATT2_SAP_SIZE_REG , range); +mei_txe_br_reg_write (hw,SATT2_BRG_BA_LSB_REG , lo32); +mei_txe_br_reg_write (hw,SATT2_CTRL_REG , ctrl); +dev_dbg (&dev->pdev->dev,"SATT2: SAP_SIZE_OFFSET=0x%08X, BRG_BA_LSB_OFFSET=0x%08X, CTRL_OFFSET=0x%08X\n" , + range, lo32, ctrl); + +return 0 ; +}
Signature · 1 line
1.8.4.2
PATCH 4/5 mei: txe: add pci-txe.c
In reply to Tomas Winklerregister txe hardware with pci bus
and add pci pm handlers
--- drivers/misc/mei/pci-txe.c | 293 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 drivers/misc/mei/pci-txe.c
drivers/misc/mei/pci-txe.c new file +293 -0
@@ -0,0 +1,293 @@ +/* +* +* Intel Management Engine Interface (Intel MEI) Linux driver +* Copyright (c) 2013-2014, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/errno.h> +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/uuid.h> +#include <linux/jiffies.h> +#include <linux/interrupt.h> +#include <linux/workqueue.h> + +#include <linux/mei.h> + + +#include "mei_dev.h" +#include "hw-txe.h" + +static DEFINE_PCI_DEVICE_TABLE (mei_txe_pci_tbl) = { + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,0x0F18 )},/* Baytrail */ + {0 , } +}; +MODULE_DEVICE_TABLE (pci, mei_txe_pci_tbl); + + +static void mei_txe_pci_iounmap (struct pci_dev *pdev,struct mei_txe_hw *hw) +{ +int i; +for (i =SEC_BAR ; i <NUM_OF_MEM_BARS ; i++) { +if (hw->mem_addr[i]) { +pci_iounmap (pdev, hw->mem_addr[i]); + hw->mem_addr[i] =NULL ; + } + } +} +/** +* mei_probe - Device Initialization Routine +* +* @pdev: PCI device structure +* @ent: entry in mei_txe_pci_tbl +* +* returns 0 on success, <0 on failure. +*/ +static int mei_txe_probe (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +struct mei_device *dev; +struct mei_txe_hw *hw; +int err; +int i; + +/* enable pci dev */ + err =pci_enable_device (pdev); +if (err) { +dev_err (&pdev->dev,"failed to enable pci device.\n" ); + goto end; + } +/* set PCI host mastering */ +pci_set_master (pdev); +/* pci request regions for mei driver */ + err =pci_request_regions (pdev,KBUILD_MODNAME ); +if (err) { +dev_err (&pdev->dev,"failed to get pci regions.\n" ); + goto disable_device; + } + + err =pci_set_dma_mask (pdev,DMA_BIT_MASK (36 )); +if (err) { + err =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (err) { +dev_err (&pdev->dev,"No suitable DMA available.\n" ); + goto release_regions; + } + } + +/* allocates and initializes the mei dev structure */ + dev =mei_txe_dev_init (pdev); +if (!dev) { + err = -ENOMEM ; + goto release_regions; + } + hw =to_txe_hw (dev); + +/* mapping IO device memory */ +for (i =SEC_BAR ; i <NUM_OF_MEM_BARS ; i++) { + hw->mem_addr[i] =pci_iomap (pdev, i,0 ); +if (!hw->mem_addr[i]) { +dev_err (&pdev->dev,"mapping I/O device memory failure.\n" ); + err = -ENOMEM ; + goto free_device; + } + } + + +pci_enable_msi (pdev); + +/* clear spurious interrupts */ +mei_clear_interrupts (dev); + +/* request and enable interrupt */ +if (pci_dev_msi_enabled (pdev)) + err =request_threaded_irq (pdev->irq, +NULL , + mei_txe_irq_thread_handler, +IRQF_ONESHOT ,KBUILD_MODNAME , dev); +else + err =request_threaded_irq (pdev->irq, + mei_txe_irq_quick_handler, + mei_txe_irq_thread_handler, +IRQF_SHARED ,KBUILD_MODNAME , dev); +if (err) { +dev_err (&pdev->dev,"mei: request_threaded_irq failure. irq = %d\n" , + pdev->irq); + goto free_device; + } + +if (mei_start (dev)) { +dev_err (&pdev->dev,"init hw failure.\n" ); + err = -ENODEV ; + goto release_irq; + } + + err =mei_register (dev); +if (err) + goto release_irq; + +pci_set_drvdata (pdev, dev); + +return 0 ; + +release_irq: + +mei_cancel_work (dev); + +/* disable interrupts */ +mei_disable_interrupts (dev); + +free_irq (pdev->irq, dev); +pci_disable_msi (pdev); + +free_device: +mei_txe_pci_iounmap (pdev, hw); + +kfree (dev); +release_regions: +pci_release_regions (pdev); +disable_device: +pci_disable_device (pdev); +end: +dev_err (&pdev->dev,"initialization failed.\n" ); +return err; +} + +/** +* mei_remove - Device Removal Routine +* +* @pdev: PCI device structure +* +* mei_remove is called by the PCI subsystem to alert the driver +* that it should release a PCI device. +*/ +static void mei_txe_remove (struct pci_dev *pdev) +{ +struct mei_device *dev; +struct mei_txe_hw *hw; + + dev =pci_get_drvdata (pdev); +if (!dev) { +dev_err (&pdev->dev,"mei: dev =NULL\n" ); +return ; + } + + hw =to_txe_hw (dev); + +mei_stop (dev); + +/* disable interrupts */ +mei_disable_interrupts (dev); +free_irq (pdev->irq, dev); +pci_disable_msi (pdev); + +pci_set_drvdata (pdev,NULL ); + +mei_txe_pci_iounmap (pdev, hw); + +mei_deregister (dev); + +kfree (dev); + +pci_release_regions (pdev); +pci_disable_device (pdev); +} + + +#ifdef CONFIG_PM +static int mei_txe_pci_suspend (struct device *device) +{ +struct pci_dev *pdev =to_pci_dev (device); +struct mei_device *dev =pci_get_drvdata (pdev); + +if (!dev) +return -ENODEV ; + +dev_dbg (&pdev->dev,"suspend\n" ); + +mei_stop (dev); + +mei_disable_interrupts (dev); + +free_irq (pdev->irq, dev); +pci_disable_msi (pdev); + +return 0 ; +} + +static int mei_txe_pci_resume (struct device *device) +{ +struct pci_dev *pdev =to_pci_dev (device); +struct mei_device *dev; +int err; + + dev =pci_get_drvdata (pdev); +if (!dev) +return -ENODEV ; + +pci_enable_msi (pdev); + +mei_clear_interrupts (dev); + +/* request and enable interrupt */ +if (pci_dev_msi_enabled (pdev)) + err =request_threaded_irq (pdev->irq, +NULL , + mei_txe_irq_thread_handler, +IRQF_ONESHOT ,KBUILD_MODNAME , dev); +else + err =request_threaded_irq (pdev->irq, + mei_txe_irq_quick_handler, + mei_txe_irq_thread_handler, +IRQF_SHARED ,KBUILD_MODNAME , dev); +if (err) { +dev_err (&pdev->dev,"request_threaded_irq failed: irq = %d.\n" , + pdev->irq); +return err; + } + + err =mei_restart (dev); + +return err; +} + +static SIMPLE_DEV_PM_OPS(mei_txe_pm_ops, + mei_txe_pci_suspend, + mei_txe_pci_resume); + +#define MEI_TXE_PM_OPS (&mei_txe_pm_ops) +#else +#define MEI_TXE_PM_OPS NULL +#endif /* CONFIG_PM */ +/* +* PCI driver structure +*/ +static struct pci_driver mei_txe_driver = { + .name =KBUILD_MODNAME , + .id_table = mei_txe_pci_tbl, + .probe = mei_txe_probe, + .remove = mei_txe_remove, + .shutdown = mei_txe_remove, + .driver.pm =MEI_TXE_PM_OPS , +}; + +module_pci_driver (mei_txe_driver); + +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_DESCRIPTION ("Intel(R) Trusted Execution Environment Interface" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
1.8.4.2
PATCH 5/5 mei: txe: add Kbuild for TXE device
In reply to Tomas Winkler--- drivers/misc/mei/Kconfig | 9 +++++++++ drivers/misc/mei/Makefile | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/misc/mei/Kconfig +9 -0
@@ -34,3 +34,12 @@ config INTEL_MEI_ME 82Q33 Express 82X38/X48 Express +config INTEL_MEI_TXE + tristate "Intel Trusted Execution Environment with ME Interface" + select INTEL_MEI + depends on X86 && PCI + help + MEI Support for Trusted Execution Environment device on Intel SoCs + + Supported SoCs: + Intel Bay Trail
drivers/misc/mei/Makefile +5 -1
@@ -1,6 +1,6 @@ # # Makefile - Intel Management Engine Interface (Intel MEI) Linux driver -# Copyright (c) 2010-2011, Intel Corporation. +# Copyright (c) 2010-2014, Intel Corporation. # obj-$(CONFIG_INTEL_MEI) += mei.o mei-objs := init.o
@@ -17,3 +17,7 @@ mei-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o mei-me-objs := pci-me.o mei-me-objs += hw-me.o + +obj-$(CONFIG_INTEL_MEI_TXE) += mei-txe.o +mei-txe-objs := pci-txe.o +mei-txe-objs += hw-txe.o
Signature · 1 line
1.8.4.2