drivers/char/tpm/tpm-buf.c
Source file repositories/reference/linux-study-clean/drivers/char/tpm/tpm-buf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/tpm/tpm-buf.c- Extension
.c- Size
- 5707 bytes
- Lines
- 247
- 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/tpm_command.hlinux/module.hlinux/tpm.h
Detected Declarations
function tpm_buf_initfunction tpm_buf_resetfunction tpm_buf_init_sizedfunction tpm_buf_reset_sizedfunction tpm_buf_destroyfunction tpm_buf_lengthfunction tpm_buf_appendfunction tpm_buf_append_u8function tpm_buf_append_u16function tpm_buf_append_u32function tpm_buf_append_handlefunction tpm_buf_readfunction tpm_buf_read_u8function tpm_buf_read_u16function tpm_buf_read_u32export tpm_buf_initexport tpm_buf_resetexport tpm_buf_init_sizedexport tpm_buf_reset_sizedexport tpm_buf_destroyexport tpm_buf_lengthexport tpm_buf_appendexport tpm_buf_append_u8export tpm_buf_append_u16export tpm_buf_append_u32export tpm_buf_read_u8export tpm_buf_read_u16export tpm_buf_read_u32
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Handling of TPM command and other buffers.
*/
#include <linux/tpm_command.h>
#include <linux/module.h>
#include <linux/tpm.h>
/**
* tpm_buf_init() - Allocate and initialize a TPM command
* @buf: A &tpm_buf
* @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS
* @ordinal: A command ordinal
*
* Return: 0 or -ENOMEM
*/
int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal)
{
buf->data = (u8 *)__get_free_page(GFP_KERNEL);
if (!buf->data)
return -ENOMEM;
tpm_buf_reset(buf, tag, ordinal);
return 0;
}
EXPORT_SYMBOL_GPL(tpm_buf_init);
/**
* tpm_buf_reset() - Initialize a TPM command
* @buf: A &tpm_buf
* @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS
* @ordinal: A command ordinal
*/
void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal)
{
struct tpm_header *head = (struct tpm_header *)buf->data;
WARN_ON(tag != TPM_TAG_RQU_COMMAND && tag != TPM2_ST_NO_SESSIONS &&
tag != TPM2_ST_SESSIONS && tag != 0);
buf->flags = 0;
buf->length = sizeof(*head);
head->tag = cpu_to_be16(tag);
head->length = cpu_to_be32(sizeof(*head));
head->ordinal = cpu_to_be32(ordinal);
buf->handles = 0;
}
EXPORT_SYMBOL_GPL(tpm_buf_reset);
/**
* tpm_buf_init_sized() - Allocate and initialize a sized (TPM2B) buffer
* @buf: A @tpm_buf
*
* Return: 0 or -ENOMEM
*/
int tpm_buf_init_sized(struct tpm_buf *buf)
{
buf->data = (u8 *)__get_free_page(GFP_KERNEL);
if (!buf->data)
return -ENOMEM;
tpm_buf_reset_sized(buf);
return 0;
}
EXPORT_SYMBOL_GPL(tpm_buf_init_sized);
/**
* tpm_buf_reset_sized() - Initialize a sized buffer
* @buf: A &tpm_buf
*/
void tpm_buf_reset_sized(struct tpm_buf *buf)
{
buf->flags = TPM_BUF_TPM2B;
buf->length = 2;
buf->data[0] = 0;
buf->data[1] = 0;
}
EXPORT_SYMBOL_GPL(tpm_buf_reset_sized);
void tpm_buf_destroy(struct tpm_buf *buf)
{
free_page((unsigned long)buf->data);
}
EXPORT_SYMBOL_GPL(tpm_buf_destroy);
/**
* tpm_buf_length() - Return the number of bytes consumed by the data
* @buf: A &tpm_buf
*
Annotation
- Immediate include surface: `linux/tpm_command.h`, `linux/module.h`, `linux/tpm.h`.
- Detected declarations: `function tpm_buf_init`, `function tpm_buf_reset`, `function tpm_buf_init_sized`, `function tpm_buf_reset_sized`, `function tpm_buf_destroy`, `function tpm_buf_length`, `function tpm_buf_append`, `function tpm_buf_append_u8`, `function tpm_buf_append_u16`, `function tpm_buf_append_u32`.
- 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.