Fix obtaining RSP address in TPM CRB for non-amd64 platforms

On amd64 the RSP address can be read in single 8-byte transaction,
which is obviously not possible on 32-bit platforms. Fix that
by performing 2 4-byte read on them.

Obtained from: Semihalf
Sponsored by: Stormshield
This commit is contained in:
Marcin Wojtas 2018-12-20 01:05:09 +00:00
parent b562884d63
commit efa9b503c6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=342271
2 changed files with 8 additions and 0 deletions

View file

@ -153,12 +153,14 @@ RD4(struct tpm_sc *sc, bus_size_t off)
return (bus_read_4(sc->mem_res, off));
}
#ifdef __amd64__
static inline uint64_t
RD8(struct tpm_sc *sc, bus_size_t off)
{
return (bus_read_8(sc->mem_res, off));
}
#endif
static inline void
WR1(struct tpm_sc *sc, bus_size_t off, uint8_t val)
{

View file

@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#define TPM_CRB_CTRL_CMD_HADDR 0x60
#define TPM_CRB_CTRL_RSP_SIZE 0x64
#define TPM_CRB_CTRL_RSP_ADDR 0x68
#define TPM_CRB_CTRL_RSP_HADDR 0x6c
#define TPM_CRB_DATA_BUFFER 0x80
#define TPM_LOC_STATE_ESTB BIT(0)
@ -188,7 +189,12 @@ tpmcrb_attach(device_t dev)
* addr is stored in two 4 byte neighboring registers, whereas RSP is
* stored in a single 8 byte one.
*/
#ifdef __amd64__
crb_sc->rsp_off = RD8(sc, TPM_CRB_CTRL_RSP_ADDR);
#else
crb_sc->rsp_off = RD4(sc, TPM_CRB_CTRL_RSP_ADDR);
crb_sc->rsp_off |= ((uint64_t) RD4(sc, TPM_CRB_CTRL_RSP_HADDR) << 32);
#endif
crb_sc->cmd_off = RD4(sc, TPM_CRB_CTRL_CMD_LADDR);
crb_sc->cmd_off |= ((uint64_t) RD4(sc, TPM_CRB_CTRL_CMD_HADDR) << 32);
crb_sc->cmd_buf_size = RD4(sc, TPM_CRB_CTRL_CMD_SIZE);