qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: dan tan <dantan@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, stefanb@linux.vnet.ibm.com,
	pbonzini@redhat.com, farosas@suse.de, lvivier@redhat.com,
	clg@kaod.org
Cc: qemu-ppc@nongnu.org
Subject: Re: [PATCH v2 3/3] tests/qtest/tpm: add unit test to tis-spi
Date: Sun, 27 Oct 2024 13:42:44 -0400	[thread overview]
Message-ID: <33618d67-861c-41aa-99d3-c610b59dc9e6@linux.ibm.com> (raw)
In-Reply-To: <20241025201247.29574-4-dantan@linux.vnet.ibm.com>



On 10/25/24 4:12 PM, dan tan wrote:
> Add qtest cases to exercise main TPM locality functionality
> The TPM device emulation is provided by swtpm, which is TCG
> TPM 2.0, and TCG TPM TIS compliant. See
> https://trustedcomputinggroup.org/wp-content/uploads/TCG_PC_Client_Platform_TPM_Profile_PTP_2.0_r1.03_v22.pdf
> https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientTPMInterfaceSpecification_TIS__1-3_27_03212013.pdf
> The SPI registers are specific to the PowerNV platform
> architecture
> 
> Signed-off-by: dan tan <dantan@linux.vnet.ibm.com>
> ---
;
> +
> +static inline void tpm_reg_writeb(const PnvChip *c,
> +                                  int locl,
> +                                  uint8_t reg,
> +                                  uint8_t val)
> +{
> +    uint32_t tpm_reg_locl = SPI_TPM_TIS_ADDR | (locl << TPM_TIS_LOCALITY_SHIFT);
> +
> +    spi_access_start(c, false, 1, TPM_WRITE_OP, tpm_reg_locl | reg);
> +    spi_write_reg(c, bswap64(val));

spi_write_reg(c, (uint64_t)val << 56);

A #define for the 56 would be good.


> +
> +static void spi_access_start(const PnvChip *chip,
> +                             bool n2,
> +                             uint8_t bytes,
> +                             uint8_t tpm_op,
> +                             uint32_t tpm_reg)
> +{
> +    uint64_t cfg_reg;
> +    uint64_t reg_op;
> +    uint64_t seq_op = SEQ_OP_REG_BASIC;
> +
> +    cfg_reg = pnv_spi_tpm_read(chip, SPI_CLK_CFG_REG);
> +    if (cfg_reg != CFG_COUNT_COMPARE_1) {
> +        pnv_spi_tpm_write(chip, SPI_CLK_CFG_REG, CFG_COUNT_COMPARE_1);
> +    }
> +    /* bytes - sequencer operation register bits 24:31 */
> +    if (n2) {
> +        seq_op |= SPI_SHIFT_COUNTER_N2 | (bytes << 0x18);
> +    } else {
> +        seq_op |= SPI_SHIFT_COUNTER_N1 | (bytes << 0x18);
> +    }
> +    pnv_spi_tpm_write(chip, SPI_SEQ_OP_REG, seq_op);
> +    pnv_spi_tpm_write(chip, SPI_MM_REG, MM_REG_RDR_MATCH);
> +    pnv_spi_tpm_write(chip, SPI_CTR_CFG_REG, (uint64_t)0);
> +    reg_op = bswap64(tpm_op) | ((uint64_t)tpm_reg << 0x20);


Same #define to use here, maybe called SPI_XMIT_DATA_OP_SHIFT. And one 
for the 0x20, maybe called SPI_XMIT_DATA_ADDR_SHIFT. Any reference to a 
spec?

(uint64_t)tmp_op << SPI_XMIT_DATA_OP_SHIFT | (uint64_t)(tpm_reg & 
0xffffff) << SPI_XMIT_DATA_ADDR_SHIFT;


> +    pnv_spi_tpm_write(chip, SPI_XMIT_DATA_REG, reg_op);
> +}
> +


      parent reply	other threads:[~2024-10-27 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 20:12 [PATCH v2 0/3] *** TPM TIS SPI pull request *** dan tan
2024-10-25 20:12 ` [PATCH v2 1/3] tpm/tpm_tis_spi: Support TPM for SPI (Serial Peripheral Interface) dan tan
2024-10-27  1:47   ` Stefan Berger
2024-10-25 20:12 ` [PATCH v2 2/3] tpm/tpm_tis_spi: activation for the PowerNV machines dan tan
2024-10-25 20:12 ` [PATCH v2 3/3] tests/qtest/tpm: add unit test to tis-spi dan tan
2024-10-27  1:56   ` Stefan Berger
2024-10-27 17:42   ` Stefan Berger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33618d67-861c-41aa-99d3-c610b59dc9e6@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=clg@kaod.org \
    --cc=dantan@linux.vnet.ibm.com \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).