Commit 61551536 authored by Niklas Schnelle's avatar Niklas Schnelle Committed by Jarkko Sakkinen

char: tpm: handle HAS_IOPORT dependencies

In a future patch HAS_IOPORT=n will disable inb()/outb() and friends at
compile time. We thus need to add this dependency and ifdef sections of
code using inb()/outb() as alternative access methods.
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Co-developed-by: default avatarArnd Bergmann <arnd@kernel.org>
Signed-off-by: default avatarArnd Bergmann <arnd@kernel.org>
Signed-off-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
Acked-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
parent 45db3ab7
...@@ -149,6 +149,7 @@ config TCG_NSC ...@@ -149,6 +149,7 @@ config TCG_NSC
config TCG_ATMEL config TCG_ATMEL
tristate "Atmel TPM Interface" tristate "Atmel TPM Interface"
depends on PPC64 || HAS_IOPORT_MAP depends on PPC64 || HAS_IOPORT_MAP
depends on HAS_IOPORT
help help
If you have a TPM security chip from Atmel say Yes and it If you have a TPM security chip from Atmel say Yes and it
will be accessible from within Linux. To compile this driver will be accessible from within Linux. To compile this driver
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
#define TPM_MAX_TRIES 5000 #define TPM_MAX_TRIES 5000
#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 #define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
#ifdef CONFIG_HAS_IOPORT
#define TPM_INF_IO_PORT 0x0 #define TPM_INF_IO_PORT 0x0
#endif
#define TPM_INF_IO_MEM 0x1 #define TPM_INF_IO_MEM 0x1
#define TPM_INF_ADDR 0x0 #define TPM_INF_ADDR 0x0
...@@ -51,34 +53,40 @@ static struct tpm_inf_dev tpm_dev; ...@@ -51,34 +53,40 @@ static struct tpm_inf_dev tpm_dev;
static inline void tpm_data_out(unsigned char data, unsigned char offset) static inline void tpm_data_out(unsigned char data, unsigned char offset)
{ {
#ifdef CONFIG_HAS_IOPORT
if (tpm_dev.iotype == TPM_INF_IO_PORT) if (tpm_dev.iotype == TPM_INF_IO_PORT)
outb(data, tpm_dev.data_regs + offset); outb(data, tpm_dev.data_regs + offset);
else else
#endif
writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset); writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset);
} }
static inline unsigned char tpm_data_in(unsigned char offset) static inline unsigned char tpm_data_in(unsigned char offset)
{ {
#ifdef CONFIG_HAS_IOPORT
if (tpm_dev.iotype == TPM_INF_IO_PORT) if (tpm_dev.iotype == TPM_INF_IO_PORT)
return inb(tpm_dev.data_regs + offset); return inb(tpm_dev.data_regs + offset);
else #endif
return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset); return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
} }
static inline void tpm_config_out(unsigned char data, unsigned char offset) static inline void tpm_config_out(unsigned char data, unsigned char offset)
{ {
#ifdef CONFIG_HAS_IOPORT
if (tpm_dev.iotype == TPM_INF_IO_PORT) if (tpm_dev.iotype == TPM_INF_IO_PORT)
outb(data, tpm_dev.config_port + offset); outb(data, tpm_dev.config_port + offset);
else else
#endif
writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset); writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset);
} }
static inline unsigned char tpm_config_in(unsigned char offset) static inline unsigned char tpm_config_in(unsigned char offset)
{ {
#ifdef CONFIG_HAS_IOPORT
if (tpm_dev.iotype == TPM_INF_IO_PORT) if (tpm_dev.iotype == TPM_INF_IO_PORT)
return inb(tpm_dev.config_port + offset); return inb(tpm_dev.config_port + offset);
else #endif
return readb(tpm_dev.mem_base + tpm_dev.index_off + offset); return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
} }
/* TPM header definitions */ /* TPM header definitions */
......
...@@ -1057,11 +1057,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value) ...@@ -1057,11 +1057,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
clkrun_val &= ~LPC_CLKRUN_EN; clkrun_val &= ~LPC_CLKRUN_EN;
iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET); iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
/*
* Write any random value on port 0x80 which is on LPC, to make
* sure LPC clock is running before sending any TPM command.
*/
outb(0xCC, 0x80);
} else { } else {
data->clkrun_enabled--; data->clkrun_enabled--;
if (data->clkrun_enabled) if (data->clkrun_enabled)
...@@ -1072,13 +1067,15 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value) ...@@ -1072,13 +1067,15 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
/* Enable LPC CLKRUN# */ /* Enable LPC CLKRUN# */
clkrun_val |= LPC_CLKRUN_EN; clkrun_val |= LPC_CLKRUN_EN;
iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET); iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
/*
* Write any random value on port 0x80 which is on LPC, to make
* sure LPC clock is running before sending any TPM command.
*/
outb(0xCC, 0x80);
} }
#ifdef CONFIG_HAS_IOPORT
/*
* Write any random value on port 0x80 which is on LPC, to make
* sure LPC clock is running before sending any TPM command.
*/
outb(0xCC, 0x80);
#endif
} }
static const struct tpm_class_ops tpm_tis = { static const struct tpm_class_ops tpm_tis = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment