drivers/char/tpm/tpm-sysfs.c
Source file repositories/reference/linux-study-clean/drivers/char/tpm/tpm-sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/tpm/tpm-sysfs.c- Extension
.c- Size
- 13762 bytes
- Lines
- 548
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.htpm.h
Detected Declarations
struct tpm_readpubek_outstruct tpm_pcr_attrfunction pubek_showfunction pcrs_showfunction enabled_showfunction active_showfunction owned_showfunction temp_deactivated_showfunction caps_showfunction cancel_storefunction durations_showfunction timeouts_showfunction tpm_version_major_showfunction null_name_showfunction pcr_value_showfunction tpm_sysfs_add_device
Annotated Snippet
struct tpm_readpubek_out {
u8 algorithm[4];
u8 encscheme[2];
u8 sigscheme[2];
__be32 paramsize;
u8 parameters[12];
__be32 keysize;
u8 modulus[256];
u8 checksum[20];
} __packed;
#define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
#define TPM_ORD_READPUBEK 124
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct tpm_buf tpm_buf;
struct tpm_readpubek_out *out;
int i;
char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev);
char anti_replay[20];
memset(&anti_replay, 0, sizeof(anti_replay));
if (tpm_try_get_ops(chip))
return 0;
if (tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK))
goto out_ops;
tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay));
if (tpm_transmit_cmd(chip, &tpm_buf, READ_PUBEK_RESULT_MIN_BODY_SIZE,
"attempting to read the PUBEK"))
goto out_buf;
out = (struct tpm_readpubek_out *)&tpm_buf.data[10];
str +=
sprintf(str,
"Algorithm: %4ph\n"
"Encscheme: %2ph\n"
"Sigscheme: %2ph\n"
"Parameters: %12ph\n"
"Modulus length: %d\n"
"Modulus:\n",
out->algorithm,
out->encscheme,
out->sigscheme,
out->parameters,
be32_to_cpu(out->keysize));
for (i = 0; i < 256; i += 16)
str += sprintf(str, "%16ph\n", &out->modulus[i]);
out_buf:
tpm_buf_destroy(&tpm_buf);
out_ops:
tpm_put_ops(chip);
return str - buf;
}
static DEVICE_ATTR_RO(pubek);
static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
cap_t cap;
u8 digest[TPM_DIGEST_SIZE];
u32 i, j, num_pcrs;
char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev);
if (tpm_try_get_ops(chip))
return 0;
if (tpm1_getcap(chip, TPM_CAP_PROP_PCR, &cap,
"attempting to determine the number of PCRS",
sizeof(cap.num_pcrs))) {
tpm_put_ops(chip);
return 0;
}
num_pcrs = be32_to_cpu(cap.num_pcrs);
for (i = 0; i < num_pcrs; i++) {
if (tpm1_pcr_read(chip, i, digest)) {
str = buf;
break;
}
str += sprintf(str, "PCR-%02d: ", i);
Annotation
- Immediate include surface: `linux/device.h`, `tpm.h`.
- Detected declarations: `struct tpm_readpubek_out`, `struct tpm_pcr_attr`, `function pubek_show`, `function pcrs_show`, `function enabled_show`, `function active_show`, `function owned_show`, `function temp_deactivated_show`, `function caps_show`, `function cancel_store`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.