drivers/crypto/ti/dthev2-common.c

Source file repositories/reference/linux-study-clean/drivers/crypto/ti/dthev2-common.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/ti/dthev2-common.c
Extension
.c
Size
5664 bytes
Lines
237
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * K3 DTHE V2 crypto accelerator driver
 *
 * Copyright (C) Texas Instruments 2025 - https://www.ti.com
 * Author: T Pratham <t-pratham@ti.com>
 */

#include <crypto/aes.h>
#include <crypto/algapi.h>
#include <crypto/engine.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>

#include "dthev2-common.h"

#include <linux/delay.h>
#include <linux/dmaengine.h>
#include <linux/dmapool.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>

#define DRIVER_NAME	"dthev2"

static struct dthe_list dthe_dev_list = {
	.dev_list = LIST_HEAD_INIT(dthe_dev_list.dev_list),
	.lock = __SPIN_LOCK_UNLOCKED(dthe_dev_list.lock),
};

struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx)
{
	struct dthe_data *dev_data;

	if (ctx->dev_data)
		return ctx->dev_data;

	spin_lock_bh(&dthe_dev_list.lock);
	dev_data = list_first_entry(&dthe_dev_list.dev_list, struct dthe_data, list);
	if (dev_data)
		list_move_tail(&dev_data->list, &dthe_dev_list.dev_list);
	spin_unlock_bh(&dthe_dev_list.lock);

	return dev_data;
}

struct scatterlist *dthe_copy_sg(struct scatterlist *dst,
				 struct scatterlist *src,
				 int buflen)
{
	struct scatterlist *from_sg, *to_sg;
	int sglen;

	for (to_sg = dst, from_sg = src; buflen && from_sg; buflen -= sglen) {
		sglen = from_sg->length;
		if (sglen > buflen)
			sglen = buflen;
		sg_set_buf(to_sg, sg_virt(from_sg), sglen);
		from_sg = sg_next(from_sg);
		to_sg = sg_next(to_sg);
	}

	return to_sg;
}

static int dthe_dma_init(struct dthe_data *dev_data)
{
	int ret;
	struct dma_slave_config cfg;

	dev_data->dma_aes_rx = NULL;
	dev_data->dma_aes_tx = NULL;
	dev_data->dma_sha_tx = NULL;

	dev_data->dma_aes_rx = dma_request_chan(dev_data->dev, "rx");
	if (IS_ERR(dev_data->dma_aes_rx)) {
		return dev_err_probe(dev_data->dev, PTR_ERR(dev_data->dma_aes_rx),
				     "Unable to request rx DMA channel\n");
	}

	dev_data->dma_aes_tx = dma_request_chan(dev_data->dev, "tx1");
	if (IS_ERR(dev_data->dma_aes_tx)) {
		ret = dev_err_probe(dev_data->dev, PTR_ERR(dev_data->dma_aes_tx),
				    "Unable to request tx1 DMA channel\n");
		goto err_dma_aes_tx;
	}

Annotation

Implementation Notes