Skip to content

Commit 6155153

Browse files
niklas88jarkkojs
authored andcommitted
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: Jarkko Sakkinen <jarkko@kernel.org> Co-developed-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Acked-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 45db3ab commit 6155153

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

drivers/char/tpm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ config TCG_NSC
149149
config TCG_ATMEL
150150
tristate "Atmel TPM Interface"
151151
depends on PPC64 || HAS_IOPORT_MAP
152+
depends on HAS_IOPORT
152153
help
153154
If you have a TPM security chip from Atmel say Yes and it
154155
will be accessible from within Linux. To compile this driver

drivers/char/tpm/tpm_infineon.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#define TPM_MAX_TRIES 5000
2727
#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
2828

29+
#ifdef CONFIG_HAS_IOPORT
2930
#define TPM_INF_IO_PORT 0x0
31+
#endif
3032
#define TPM_INF_IO_MEM 0x1
3133

3234
#define TPM_INF_ADDR 0x0
@@ -51,34 +53,40 @@ static struct tpm_inf_dev tpm_dev;
5153

5254
static inline void tpm_data_out(unsigned char data, unsigned char offset)
5355
{
56+
#ifdef CONFIG_HAS_IOPORT
5457
if (tpm_dev.iotype == TPM_INF_IO_PORT)
5558
outb(data, tpm_dev.data_regs + offset);
5659
else
60+
#endif
5761
writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset);
5862
}
5963

6064
static inline unsigned char tpm_data_in(unsigned char offset)
6165
{
66+
#ifdef CONFIG_HAS_IOPORT
6267
if (tpm_dev.iotype == TPM_INF_IO_PORT)
6368
return inb(tpm_dev.data_regs + offset);
64-
else
65-
return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
69+
#endif
70+
return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
6671
}
6772

6873
static inline void tpm_config_out(unsigned char data, unsigned char offset)
6974
{
75+
#ifdef CONFIG_HAS_IOPORT
7076
if (tpm_dev.iotype == TPM_INF_IO_PORT)
7177
outb(data, tpm_dev.config_port + offset);
7278
else
79+
#endif
7380
writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset);
7481
}
7582

7683
static inline unsigned char tpm_config_in(unsigned char offset)
7784
{
85+
#ifdef CONFIG_HAS_IOPORT
7886
if (tpm_dev.iotype == TPM_INF_IO_PORT)
7987
return inb(tpm_dev.config_port + offset);
80-
else
81-
return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
88+
#endif
89+
return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
8290
}
8391

8492
/* TPM header definitions */

drivers/char/tpm/tpm_tis_core.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
10571057
clkrun_val &= ~LPC_CLKRUN_EN;
10581058
iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
10591059

1060-
/*
1061-
* Write any random value on port 0x80 which is on LPC, to make
1062-
* sure LPC clock is running before sending any TPM command.
1063-
*/
1064-
outb(0xCC, 0x80);
10651060
} else {
10661061
data->clkrun_enabled--;
10671062
if (data->clkrun_enabled)
@@ -1072,13 +1067,15 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
10721067
/* Enable LPC CLKRUN# */
10731068
clkrun_val |= LPC_CLKRUN_EN;
10741069
iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
1075-
1076-
/*
1077-
* Write any random value on port 0x80 which is on LPC, to make
1078-
* sure LPC clock is running before sending any TPM command.
1079-
*/
1080-
outb(0xCC, 0x80);
10811070
}
1071+
1072+
#ifdef CONFIG_HAS_IOPORT
1073+
/*
1074+
* Write any random value on port 0x80 which is on LPC, to make
1075+
* sure LPC clock is running before sending any TPM command.
1076+
*/
1077+
outb(0xCC, 0x80);
1078+
#endif
10821079
}
10831080

10841081
static const struct tpm_class_ops tpm_tis = {

0 commit comments

Comments
 (0)