drivers/char/tpm/tpm-chip.c
Source file repositories/reference/linux-study-clean/drivers/char/tpm/tpm-chip.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/tpm/tpm-chip.c- Extension
.c- Size
- 14357 bytes
- Lines
- 661
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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/major.hlinux/tpm_eventlog.hlinux/hw_random.htpm.h
Detected Declarations
function tpm_request_localityfunction tpm_relinquish_localityfunction tpm_cmd_readyfunction tpm_go_idlefunction tpm_clk_enablefunction tpm_clk_disablefunction tpm_chip_startfunction tpm_chip_stopfunction tpm_try_get_opsfunction tpm_put_opsfunction tpm_default_chipfunction tpm_dev_releasefunction tpm_class_shutdownfunction tpm_chip_allocfunction tpm_put_devicefunction tpmm_chip_allocfunction tpm_add_char_devicefunction tpm_del_char_devicefunction tpm_del_legacy_sysfsfunction tpm_add_legacy_sysfsfunction tpm_hwrng_readfunction tpm_is_hwrng_enabledfunction tpm_add_hwrngfunction tpm_get_pcr_allocationfunction tpm_chip_bootstrapfunction tpm_chip_registerfunction tpm_chip_unregisterexport tpm_chip_startexport tpm_chip_stopexport tpm_try_get_opsexport tpm_put_opsexport tpm_default_chipexport tpm_chip_allocexport tpmm_chip_allocexport tpm_chip_bootstrapexport tpm_chip_registerexport tpm_chip_unregister
Annotated Snippet
if (ret) {
tpm_clk_disable(chip);
return ret;
}
}
ret = tpm_cmd_ready(chip);
if (ret) {
tpm_relinquish_locality(chip);
tpm_clk_disable(chip);
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(tpm_chip_start);
/**
* tpm_chip_stop() - power off the TPM
* @chip: a TPM chip to use
*
* Return:
* * The response length - OK
* * -errno - A system error
*/
void tpm_chip_stop(struct tpm_chip *chip)
{
tpm_go_idle(chip);
tpm_relinquish_locality(chip);
tpm_clk_disable(chip);
}
EXPORT_SYMBOL_GPL(tpm_chip_stop);
/**
* tpm_try_get_ops() - Get a ref to the tpm_chip
* @chip: Chip to ref
*
* The caller must already have some kind of locking to ensure that chip is
* valid. This function will lock the chip so that the ops member can be
* accessed safely. The locking prevents tpm_chip_unregister from
* completing, so it should not be held for long periods.
*
* Returns -ERRNO if the chip could not be got.
*/
int tpm_try_get_ops(struct tpm_chip *chip)
{
int rc = -EIO;
if (chip->flags & TPM_CHIP_FLAG_DISABLE)
return rc;
get_device(&chip->dev);
down_read(&chip->ops_sem);
if (!chip->ops)
goto out_ops;
mutex_lock(&chip->tpm_mutex);
/* tmp_chip_start may issue IO that is denied while suspended */
if (chip->flags & TPM_CHIP_FLAG_SUSPENDED)
goto out_lock;
rc = tpm_chip_start(chip);
if (rc)
goto out_lock;
return 0;
out_lock:
mutex_unlock(&chip->tpm_mutex);
out_ops:
up_read(&chip->ops_sem);
put_device(&chip->dev);
return rc;
}
EXPORT_SYMBOL_GPL(tpm_try_get_ops);
/**
* tpm_put_ops() - Release a ref to the tpm_chip
* @chip: Chip to put
*
* This is the opposite pair to tpm_try_get_ops(). After this returns chip may
* be kfree'd.
*/
void tpm_put_ops(struct tpm_chip *chip)
{
tpm_chip_stop(chip);
mutex_unlock(&chip->tpm_mutex);
up_read(&chip->ops_sem);
put_device(&chip->dev);
Annotation
- Immediate include surface: `linux/poll.h`, `linux/slab.h`, `linux/mutex.h`, `linux/spinlock.h`, `linux/freezer.h`, `linux/major.h`, `linux/tpm_eventlog.h`, `linux/hw_random.h`.
- Detected declarations: `function tpm_request_locality`, `function tpm_relinquish_locality`, `function tpm_cmd_ready`, `function tpm_go_idle`, `function tpm_clk_enable`, `function tpm_clk_disable`, `function tpm_chip_start`, `function tpm_chip_stop`, `function tpm_try_get_ops`, `function tpm_put_ops`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.