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 927088b2c3d3f2c60bd5c3fa9735ba90d2e0bdd3..418c9ed59ffde7c61e40f6ace72ea35ee7a002ac 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 9c924a1440a913deb1dd46ad21414d0032b683dc..99c6e565ec8d5391f010e7200aa84048c8f5bf7d 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 714070ebb6e7a21d957fc4cff3920e12984c71af..176cd8dbf1db2c61d5f2ed193c63822e898ac9c6 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 = {