linux/drivers/misc/nsm.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Amazon Nitro Secure Module driver.
 *
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * The Nitro Secure Module implements commands via CBOR over virtio.
 * This driver exposes a raw message ioctls on /dev/nsm that user
 * space can use to issue these commands.
 */

#include <linux/file.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/hw_random.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/uio.h>
#include <linux/virtio_config.h>
#include <linux/virtio_ids.h>
#include <linux/virtio.h>
#include <linux/wait.h>
#include <uapi/linux/nsm.h>

/* Timeout for NSM virtqueue respose in milliseconds. */
#define NSM_DEFAULT_TIMEOUT_MSECS

/* Maximum length input data */
struct nsm_data_req {};

/* Maximum length output data */
struct nsm_data_resp {};

/* Full NSM request/response message */
struct nsm_msg {};

struct nsm {};

/* NSM device ID */
static const struct virtio_device_id id_table[] =;

static struct nsm *file_to_nsm(struct file *file)
{}

static struct nsm *hwrng_to_nsm(struct hwrng *rng)
{}

#define CBOR_TYPE_MASK
#define CBOR_TYPE_MAP
#define CBOR_TYPE_TEXT
#define CBOR_TYPE_ARRAY
#define CBOR_HEADER_SIZE_SHORT

#define CBOR_SHORT_SIZE_MAX_VALUE
#define CBOR_LONG_SIZE_U8
#define CBOR_LONG_SIZE_U16
#define CBOR_LONG_SIZE_U32
#define CBOR_LONG_SIZE_U64

static bool cbor_object_is_array(const u8 *cbor_object, size_t cbor_object_size)
{}

static int cbor_object_get_array(u8 *cbor_object, size_t cbor_object_size, u8 **cbor_array)
{}

/* Copy the request of a raw message to kernel space */
static int fill_req_raw(struct nsm *nsm, struct nsm_data_req *req,
			struct nsm_raw *raw)
{}

/* Copy the response of a raw message back to user-space */
static int parse_resp_raw(struct nsm *nsm, struct nsm_data_resp *resp,
			  struct nsm_raw *raw)
{}

/* Virtqueue interrupt handler */
static void nsm_vq_callback(struct virtqueue *vq)
{}

/* Forward a message to the NSM device and wait for the response from it */
static int nsm_sendrecv_msg_locked(struct nsm *nsm)
{}

static int fill_req_get_random(struct nsm *nsm, struct nsm_data_req *req)
{}

static int parse_resp_get_random(struct nsm *nsm, struct nsm_data_resp *resp,
				 void *out, size_t max)
{}

/*
 * HwRNG implementation
 */
static int nsm_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{}

static long nsm_dev_ioctl(struct file *file, unsigned int cmd,
	unsigned long arg)
{}

static int nsm_device_init_vq(struct virtio_device *vdev)
{}

static const struct file_operations nsm_dev_fops =;

/* Handler for probing the NSM device */
static int nsm_device_probe(struct virtio_device *vdev)
{}

/* Handler for removing the NSM device */
static void nsm_device_remove(struct virtio_device *vdev)
{}

/* NSM device configuration structure */
static struct virtio_driver virtio_nsm_driver =;

module_virtio_driver();
MODULE_DEVICE_TABLE(virtio, id_table);
MODULE_DESCRIPTION();
MODULE_LICENSE();