lkml.org 
[lkml]   [2022]   [Apr]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 05/37] char: impi, tpm: depend on HAS_IOPORT
From
Hello Niklas,

On 29.04.22 15:50, Niklas Schnelle wrote:
> In a future patch HAS_IOPORT=n will result in inb()/outb() and friends
> not being declared. We thus need to add this dependency and ifdef
> sections of code using inb()/outb() as alternative access methods.
>
> Co-developed-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>

[snip]

> diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
> index 9c924a1440a9..2d2ae37153ba 100644
> --- a/drivers/char/tpm/tpm_infineon.c
> +++ b/drivers/char/tpm/tpm_infineon.c
> @@ -51,34 +51,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

This looks ugly. Can't you declare inb/outb anyway and skip the definition,
so you can use IS_ENABLED() here instead?

You can mark the declarations with __compiletime_error("some message"), so
if an IS_ENABLED() reference is not removed at compile time, you get some
readable error message instead of a link error.

Cheers,
Ahmad

> 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 */
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index dc56b976d816..1efb58dc1b41 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -879,11 +879,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)
> @@ -894,13 +889,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 = {


--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

\
 
 \ /
  Last update: 2022-04-29 16:08    [W:0.565 / U:0.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site