drivers/ufs/core/ufs-rpmb.c
Source file repositories/reference/linux-study-clean/drivers/ufs/core/ufs-rpmb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ufs/core/ufs-rpmb.c- Extension
.c- Size
- 6482 bytes
- Lines
- 255
- Domain
- Driver Families
- Bucket
- drivers/ufs
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/module.hlinux/device.hlinux/kernel.hlinux/types.hlinux/rpmb.hlinux/string.hlinux/list.hufs/ufshcd.hlinux/unaligned.hufshcd-priv.h
Detected Declarations
struct ufs_rpmb_devfunction ufs_sec_submitfunction ufs_rpmb_route_framesfunction ufs_rpmb_device_releasefunction ufs_rpmb_probefunction ufs_rpmb_remove
Annotated Snippet
static const struct bus_type ufs_rpmb_bus_type = {
.name = "ufs_rpmb",
};
/* UFS RPMB device structure */
struct ufs_rpmb_dev {
u8 region_id;
struct device dev;
struct rpmb_dev *rdev;
struct ufs_hba *hba;
struct list_head node;
};
static int ufs_sec_submit(struct ufs_hba *hba, u16 spsp, void *buffer, size_t len, bool send)
{
struct scsi_device *sdev = hba->ufs_rpmb_wlun;
u8 cdb[12] = { };
cdb[0] = send ? SECURITY_PROTOCOL_OUT : SECURITY_PROTOCOL_IN;
cdb[1] = UFS_RPMB_SEC_PROTOCOL;
put_unaligned_be16(spsp, &cdb[2]);
put_unaligned_be32(len, &cdb[6]);
return scsi_execute_cmd(sdev, cdb, send ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
buffer, len, /*timeout=*/30 * HZ, 0, NULL);
}
/* UFS RPMB route frames implementation */
static int ufs_rpmb_route_frames(struct device *dev, u8 *req, unsigned int req_len, u8 *resp,
unsigned int resp_len)
{
struct ufs_rpmb_dev *ufs_rpmb = dev_get_drvdata(dev);
struct rpmb_frame *frm_out = (struct rpmb_frame *)req;
bool need_result_read = true;
u16 req_type, protocol_id;
struct ufs_hba *hba;
int ret;
if (!ufs_rpmb) {
dev_err(dev, "Missing driver data\n");
return -ENODEV;
}
hba = ufs_rpmb->hba;
req_type = be16_to_cpu(frm_out->req_resp);
switch (req_type) {
case RPMB_PROGRAM_KEY:
if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
return -EINVAL;
break;
case RPMB_GET_WRITE_COUNTER:
if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
return -EINVAL;
need_result_read = false;
break;
case RPMB_WRITE_DATA:
if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame))
return -EINVAL;
break;
case RPMB_READ_DATA:
if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame))
return -EINVAL;
need_result_read = false;
break;
default:
dev_err(dev, "Unknown request type=0x%04x\n", req_type);
return -EINVAL;
}
protocol_id = ufs_rpmb->region_id << 8 | UFS_RPMB_SEC_PROTOCOL_ID;
ret = ufs_sec_submit(hba, protocol_id, req, req_len, true);
if (ret) {
dev_err(dev, "Command failed with ret=%d\n", ret);
return ret;
}
if (need_result_read) {
struct rpmb_frame *frm_resp = (struct rpmb_frame *)resp;
memset(frm_resp, 0, sizeof(*frm_resp));
frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ);
ret = ufs_sec_submit(hba, protocol_id, resp, resp_len, true);
if (ret) {
dev_err(dev, "Result read request failed with ret=%d\n", ret);
return ret;
}
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/device.h`, `linux/kernel.h`, `linux/types.h`, `linux/rpmb.h`, `linux/string.h`, `linux/list.h`, `ufs/ufshcd.h`.
- Detected declarations: `struct ufs_rpmb_dev`, `function ufs_sec_submit`, `function ufs_rpmb_route_frames`, `function ufs_rpmb_device_release`, `function ufs_rpmb_probe`, `function ufs_rpmb_remove`.
- Atlas domain: Driver Families / drivers/ufs.
- Implementation status: pattern 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.