drivers/crypto/ccp/psp-dev.c
Source file repositories/reference/linux-study-clean/drivers/crypto/ccp/psp-dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/ccp/psp-dev.c- Extension
.c- Size
- 7924 bytes
- Lines
- 382
- Domain
- Driver Families
- Bucket
- drivers/crypto
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/kernel.hlinux/irqreturn.hlinux/mutex.hlinux/bitfield.hlinux/delay.hsp-dev.hpsp-dev.hsev-dev.htee-dev.hsfs.hplatform-access.hdbc.hhsti.h
Detected Declarations
function psp_mailbox_pollfunction psp_mailbox_commandfunction psp_extended_mailbox_cmdfunction psp_irq_handlerfunction psp_get_capabilityfunction initializationfunction psp_check_sev_supportfunction psp_check_tee_supportfunction psp_check_sfs_supportfunction psp_initfunction psp_dev_initfunction psp_dev_destroyfunction psp_set_sev_irq_handlerfunction psp_clear_sev_irq_handlerfunction psp_restorefunction psp_pci_initfunction psp_pci_exit
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* AMD Platform Security Processor (PSP) interface
*
* Copyright (C) 2016,2019 Advanced Micro Devices, Inc.
*
* Author: Brijesh Singh <brijesh.singh@amd.com>
*/
#include <linux/kernel.h>
#include <linux/irqreturn.h>
#include <linux/mutex.h>
#include <linux/bitfield.h>
#include <linux/delay.h>
#include "sp-dev.h"
#include "psp-dev.h"
#include "sev-dev.h"
#include "tee-dev.h"
#include "sfs.h"
#include "platform-access.h"
#include "dbc.h"
#include "hsti.h"
struct psp_device *psp_master;
#define PSP_C2PMSG_17_CMDRESP_CMD GENMASK(19, 16)
static int psp_mailbox_poll(const void __iomem *cmdresp_reg, unsigned int *cmdresp,
unsigned int timeout_msecs)
{
while (true) {
*cmdresp = ioread32(cmdresp_reg);
if (FIELD_GET(PSP_CMDRESP_RESP, *cmdresp))
return 0;
if (!timeout_msecs--)
break;
usleep_range(1000, 1100);
}
return -ETIMEDOUT;
}
int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff,
unsigned int timeout_msecs, unsigned int *cmdresp)
{
void __iomem *cmdresp_reg, *cmdbuff_lo_reg, *cmdbuff_hi_reg;
int ret;
if (!psp || !psp->vdata || !psp->vdata->cmdresp_reg ||
!psp->vdata->cmdbuff_addr_lo_reg || !psp->vdata->cmdbuff_addr_hi_reg)
return -ENODEV;
cmdresp_reg = psp->io_regs + psp->vdata->cmdresp_reg;
cmdbuff_lo_reg = psp->io_regs + psp->vdata->cmdbuff_addr_lo_reg;
cmdbuff_hi_reg = psp->io_regs + psp->vdata->cmdbuff_addr_hi_reg;
mutex_lock(&psp->mailbox_mutex);
/* Ensure mailbox is ready for a command */
ret = -EBUSY;
if (psp_mailbox_poll(cmdresp_reg, cmdresp, 0))
goto unlock;
if (cmdbuff) {
iowrite32(lower_32_bits(__psp_pa(cmdbuff)), cmdbuff_lo_reg);
iowrite32(upper_32_bits(__psp_pa(cmdbuff)), cmdbuff_hi_reg);
}
*cmdresp = FIELD_PREP(PSP_C2PMSG_17_CMDRESP_CMD, cmd);
iowrite32(*cmdresp, cmdresp_reg);
ret = psp_mailbox_poll(cmdresp_reg, cmdresp, timeout_msecs);
unlock:
mutex_unlock(&psp->mailbox_mutex);
return ret;
}
int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs,
struct psp_ext_request *req)
{
unsigned int reg;
int ret;
print_hex_dump_debug("->psp ", DUMP_PREFIX_OFFSET, 16, 2, req,
req->header.payload_size, false);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/irqreturn.h`, `linux/mutex.h`, `linux/bitfield.h`, `linux/delay.h`, `sp-dev.h`, `psp-dev.h`, `sev-dev.h`.
- Detected declarations: `function psp_mailbox_poll`, `function psp_mailbox_command`, `function psp_extended_mailbox_cmd`, `function psp_irq_handler`, `function psp_get_capability`, `function initialization`, `function psp_check_sev_support`, `function psp_check_tee_support`, `function psp_check_sfs_support`, `function psp_init`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.