-
Notifications
You must be signed in to change notification settings - Fork 4
/
tpmio.c
64 lines (48 loc) · 1.06 KB
/
tpmio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (c) 2019 Apertus Solutions, LLC
*
* Author(s):
* Daniel P. Smith <[email protected]>
*/
#ifdef LINUX_KERNEL
#include <linux/types.h>
#include <asm/io.h>
#endif
#include "tpm.h"
#include "tpm_common.h"
static noinline void tpm_io_delay(void)
{
/* This is the default delay type in native_io_delay */
asm volatile ("outb %al, $0x80");
}
void tpm_udelay(int loops)
{
while (loops--)
tpm_io_delay(); /* Approximately 1 us */
}
void tpm_mdelay(int ms)
{
int i;
for (i = 0; i < ms; i++)
tpm_udelay(1000);
}
u8 tpm_read8(u32 field)
{
void *mmio_addr = (void *)(uintptr_t)(TPM_MMIO_BASE | field);
return ioread8(mmio_addr);
}
void tpm_write8(unsigned char val, u32 field)
{
void *mmio_addr = (void *)(uintptr_t)(TPM_MMIO_BASE | field);
iowrite8(val, mmio_addr);
}
u32 tpm_read32(u32 field)
{
void *mmio_addr = (void *)(uintptr_t)(TPM_MMIO_BASE | field);
return ioread32(mmio_addr);
}
void tpm_write32(unsigned int val, u32 field)
{
void *mmio_addr = (void *)(uintptr_t)(TPM_MMIO_BASE | field);
iowrite32(val, mmio_addr);
}