char: tpm: handle HAS_IOPORT dependencies
authorNiklas Schnelle <schnelle@linux.ibm.com>
Thu, 4 Apr 2024 10:58:40 +0000 (12:58 +0200)
committerJarkko Sakkinen <jarkko@kernel.org>
Thu, 9 May 2024 19:30:50 +0000 (22:30 +0300)
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>
drivers/char/tpm/Kconfig
drivers/char/tpm/tpm_infineon.c
drivers/char/tpm/tpm_tis_core.c

index 927088b..418c9ed 100644 (file)
@@ -149,6 +149,7 @@ config TCG_NSC
 config TCG_ATMEL
        tristate "Atmel TPM Interface"
        depends on PPC64 || HAS_IOPORT_MAP
+       depends on HAS_IOPORT
        help
          If you have a TPM security chip from Atmel say Yes and it 
          will be accessible from within Linux.  To compile this driver 
index 9c924a1..99c6e56 100644 (file)
@@ -26,7 +26,9 @@
 #define        TPM_MAX_TRIES           5000
 #define        TPM_INFINEON_DEV_VEN_VALUE      0x15D1
 
+#ifdef CONFIG_HAS_IOPORT
 #define TPM_INF_IO_PORT                0x0
+#endif
 #define TPM_INF_IO_MEM         0x1
 
 #define TPM_INF_ADDR           0x0
@@ -51,34 +53,40 @@ static struct tpm_inf_dev tpm_dev;
 
 static inline void tpm_data_out(unsigned char data, unsigned char offset)
 {
+#ifdef CONFIG_HAS_IOPORT
        if (tpm_dev.iotype == TPM_INF_IO_PORT)
                outb(data, tpm_dev.data_regs + offset);
        else
+#endif
                writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset);
 }
 
 static inline unsigned char tpm_data_in(unsigned char offset)
 {
+#ifdef CONFIG_HAS_IOPORT
        if (tpm_dev.iotype == TPM_INF_IO_PORT)
                return inb(tpm_dev.data_regs + offset);
-       else
-               return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
+#endif
+       return readb(tpm_dev.mem_base + tpm_dev.data_regs + 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)
                outb(data, tpm_dev.config_port + offset);
        else
+#endif
                writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset);
 }
 
 static inline unsigned char tpm_config_in(unsigned char offset)
 {
+#ifdef CONFIG_HAS_IOPORT
        if (tpm_dev.iotype == TPM_INF_IO_PORT)
                return inb(tpm_dev.config_port + offset);
-       else
-               return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
+#endif
+       return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
 }
 
 /* TPM header definitions */
index 714070e..176cd8d 100644 (file)
@@ -1057,11 +1057,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
                clkrun_val &= ~LPC_CLKRUN_EN;
                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 {
                data->clkrun_enabled--;
                if (data->clkrun_enabled)
@@ -1072,13 +1067,15 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
                /* Enable LPC CLKRUN# */
                clkrun_val |= LPC_CLKRUN_EN;
                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 = {