Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions hal/tpm_io_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#ifdef WOLFTPM_INCLUDE_IO_FILE
#ifdef WOLFTPM_MMIO

#ifndef MIMO_BASE_ADDRESS
#define MIMO_BASE_ADDRESS 0xFE000000u
#ifndef MMIO_BASE_ADDRESS
#define MMIO_BASE_ADDRESS 0xFE000000u
#endif

#ifndef WOLFTPM_ADV_IO
Expand Down Expand Up @@ -100,20 +100,31 @@ int TPM2_IoCb_Mmio(TPM2_CTX *ctx, int isRead, word32 addr, byte* buf, word16 siz
{
size_t i;
word32 effectiveAddr;
word32 regOffset;
Comment thread
rizlik marked this conversation as resolved.
int isFifo;

/* Bounds check to prevent address wrap-around */
if (addr >= TPM_MMIO_MAX_OFFSET) {
return TPM_RC_FAILURE;
}

effectiveAddr = MIMO_BASE_ADDRESS + addr;
effectiveAddr = MMIO_BASE_ADDRESS + addr;

/* FIFO registers use the same address for every access
* (hardware auto-increments internally).
* Non-FIFO registers need the address advanced for multi-byte access. */
regOffset = addr & 0x0FFFu;
isFifo = (regOffset == TPM_TIS_DATA_FIFO_OFFSET ||
regOffset == TPM_TIS_XDATA_FIFO_OFFSET);

/* IO for 32-bit aligned */
for (i = 0; ((size_t)size - i) >= sizeof(word32); i += sizeof(word32)) {
if (isRead)
TPM2_Mmio_Read32(effectiveAddr, buf + i);
else
TPM2_Mmio_Write32(effectiveAddr, buf + i);
if (!isFifo)
effectiveAddr += sizeof(word32);
}

/* IO for unaligned remainder */
Expand All @@ -122,6 +133,8 @@ int TPM2_IoCb_Mmio(TPM2_CTX *ctx, int isRead, word32 addr, byte* buf, word16 siz
TPM2_Mmio_Read8(effectiveAddr, buf + i);
else
TPM2_Mmio_Write8(effectiveAddr, buf + i);
if (!isFifo)
effectiveAddr++;
}

(void)ctx;
Expand Down
Loading
Loading