drivers/char/tpm/tpm1-cmd.c
Source file repositories/reference/linux-study-clean/drivers/char/tpm/tpm1-cmd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/tpm/tpm1-cmd.c- Extension
.c- Size
- 18864 bytes
- Lines
- 809
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/poll.hlinux/slab.hlinux/mutex.hlinux/spinlock.hlinux/freezer.hlinux/tpm_eventlog.htpm.h
Detected Declarations
struct tpm1_get_random_outfunction tpm1_calc_ordinal_durationfunction tpm1_startupfunction tpm1_get_timeoutsfunction tpm1_pcr_extendfunction tpm1_getcapfunction tpm1_get_randomfunction tpm1_pcr_readfunction tpm1_continue_selftestfunction tpm1_do_selftestfunction tpm1_auto_startupfunction tpm1_pm_suspendfunction tpm1_get_pcr_allocationexport tpm1_getcapexport tpm1_do_selftest
Annotated Snippet
struct tpm1_get_random_out {
__be32 rng_data_len;
u8 rng_data[TPM_MAX_RNG_DATA];
} __packed;
/**
* tpm1_get_random() - get random bytes from the TPM's RNG
* @chip: a &struct tpm_chip instance
* @dest: destination buffer for the random bytes
* @max: the maximum number of bytes to write to @dest
*
* Return:
* * number of bytes read
* * -errno (positive TPM return codes are masked to -EIO)
*/
int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
{
struct tpm1_get_random_out *out;
u32 num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA);
struct tpm_buf buf;
u32 total = 0;
int retries = 5;
u32 recd;
int rc;
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM);
if (rc)
return rc;
do {
tpm_buf_append_u32(&buf, num_bytes);
rc = tpm_transmit_cmd(chip, &buf, sizeof(out->rng_data_len),
"attempting get random");
if (rc) {
if (rc > 0)
rc = -EIO;
goto out;
}
out = (struct tpm1_get_random_out *)&buf.data[TPM_HEADER_SIZE];
recd = be32_to_cpu(out->rng_data_len);
if (recd > num_bytes) {
rc = -EFAULT;
goto out;
}
if (tpm_buf_length(&buf) < TPM_HEADER_SIZE +
sizeof(out->rng_data_len) + recd) {
rc = -EFAULT;
goto out;
}
memcpy(dest, out->rng_data, recd);
dest += recd;
total += recd;
num_bytes -= recd;
tpm_buf_reset(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM);
} while (retries-- && total < max);
rc = total ? (int)total : -EIO;
out:
tpm_buf_destroy(&buf);
return rc;
}
#define TPM_ORD_PCRREAD 21
int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
{
struct tpm_buf buf;
int rc;
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCRREAD);
if (rc)
return rc;
tpm_buf_append_u32(&buf, pcr_idx);
rc = tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE,
"attempting to read a pcr value");
if (rc)
goto out;
if (tpm_buf_length(&buf) < TPM_DIGEST_SIZE) {
rc = -EFAULT;
goto out;
}
Annotation
- Immediate include surface: `linux/poll.h`, `linux/slab.h`, `linux/mutex.h`, `linux/spinlock.h`, `linux/freezer.h`, `linux/tpm_eventlog.h`, `tpm.h`.
- Detected declarations: `struct tpm1_get_random_out`, `function tpm1_calc_ordinal_duration`, `function tpm1_startup`, `function tpm1_get_timeouts`, `function tpm1_pcr_extend`, `function tpm1_getcap`, `function tpm1_get_random`, `function tpm1_pcr_read`, `function tpm1_continue_selftest`, `function tpm1_do_selftest`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: integration 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.