linux/samples/vfio-mdev/mtty.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Mediated virtual PCI serial host device driver
 *
 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 *     Author: Neo Jia <[email protected]>
 *             Kirti Wankhede <[email protected]>
 *
 * Sample driver that creates mdev device that simulates serial port over PCI
 * card.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/cdev.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/vfio.h>
#include <linux/iommu.h>
#include <linux/sysfs.h>
#include <linux/ctype.h>
#include <linux/file.h>
#include <linux/mdev.h>
#include <linux/pci.h>
#include <linux/serial.h>
#include <uapi/linux/serial_reg.h>
#include <linux/eventfd.h>
#include <linux/anon_inodes.h>

/*
 * #defines
 */

#define VERSION_STRING
#define DRIVER_AUTHOR

#define MTTY_CLASS_NAME

#define MTTY_NAME

#define MTTY_STRING_LEN

#define MTTY_CONFIG_SPACE_SIZE
#define MTTY_IO_BAR_SIZE
#define MTTY_MMIO_BAR_SIZE

#define STORE_LE16(addr, val)
#define STORE_LE32(addr, val)

#define MAX_FIFO_SIZE

#define CIRCULAR_BUF_INC_IDX(idx)

#define MTTY_VFIO_PCI_OFFSET_SHIFT

#define MTTY_VFIO_PCI_OFFSET_TO_INDEX(off)
#define MTTY_VFIO_PCI_INDEX_TO_OFFSET(index)
#define MTTY_VFIO_PCI_OFFSET_MASK
#define MAX_MTTYS

/*
 * Global Structures
 */

static struct mtty_dev {} mtty_dev;

struct mdev_region_info {};

#if defined(DEBUG_REGS)
static const char *wr_reg[] = {
	"TX",
	"IER",
	"FCR",
	"LCR",
	"MCR",
	"LSR",
	"MSR",
	"SCR"
};

static const char *rd_reg[] = {
	"RX",
	"IER",
	"IIR",
	"LCR",
	"MCR",
	"LSR",
	"MSR",
	"SCR"
};
#endif

/* loop back buffer */
struct rxtx {};

struct serial_port {};

struct mtty_data {};

struct mdev_state;

struct mtty_migration_file {};

/* State of each mdev device */
struct mdev_state {};

static struct mtty_type {} mtty_types[2] =;

static struct mdev_type *mtty_mdev_types[] =;

static atomic_t mdev_avail_ports =;

static const struct file_operations vd_fops =;

static const struct vfio_device_ops mtty_dev_ops;

/* Helper functions */

static void dump_buffer(u8 *buf, uint32_t count)
{}

static bool is_intx(struct mdev_state *mdev_state)
{}

static bool is_msi(struct mdev_state *mdev_state)
{}

static bool is_noirq(struct mdev_state *mdev_state)
{}

static void mtty_trigger_interrupt(struct mdev_state *mdev_state)
{}

static void mtty_create_config_space(struct mdev_state *mdev_state)
{}

static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset,
				 u8 *buf, u32 count)
{}

static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
				u16 offset, u8 *buf, u32 count)
{}

static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state,
			    u16 offset, u8 *buf, u32 count)
{}

static void mdev_read_base(struct mdev_state *mdev_state)
{}

static ssize_t mdev_access(struct mdev_state *mdev_state, u8 *buf, size_t count,
			   loff_t pos, bool is_write)
{}

static size_t mtty_data_size(struct mdev_state *mdev_state)
{}

static void mtty_disable_file(struct mtty_migration_file *migf)
{}

static void mtty_disable_files(struct mdev_state *mdev_state)
{}

static void mtty_state_mutex_unlock(struct mdev_state *mdev_state)
{}

static int mtty_release_migf(struct inode *inode, struct file *filp)
{}

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

static ssize_t mtty_save_read(struct file *filp, char __user *buf,
			      size_t len, loff_t *pos)
{}

static const struct file_operations mtty_save_fops =;

static void mtty_save_state(struct mdev_state *mdev_state)
{}

static int mtty_load_state(struct mdev_state *mdev_state)
{}

static struct mtty_migration_file *
mtty_save_device_data(struct mdev_state *mdev_state,
		      enum vfio_device_mig_state state)
{}

static ssize_t mtty_resume_write(struct file *filp, const char __user *buf,
				 size_t len, loff_t *pos)
{}

static const struct file_operations mtty_resume_fops =;

static struct mtty_migration_file *
mtty_resume_device_data(struct mdev_state *mdev_state)
{}

static struct file *mtty_step_state(struct mdev_state *mdev_state,
				     enum vfio_device_mig_state new)
{}

static struct file *mtty_set_state(struct vfio_device *vdev,
				   enum vfio_device_mig_state new_state)
{}

static int mtty_get_state(struct vfio_device *vdev,
			  enum vfio_device_mig_state *current_state)
{}

static int mtty_get_data_size(struct vfio_device *vdev,
			      unsigned long *stop_copy_length)
{}

static const struct vfio_migration_ops mtty_migration_ops =;

static int mtty_log_start(struct vfio_device *vdev,
			  struct rb_root_cached *ranges,
			  u32 nnodes, u64 *page_size)
{}

static int mtty_log_stop(struct vfio_device *vdev)
{}

static int mtty_log_read_and_clear(struct vfio_device *vdev,
				   unsigned long iova, unsigned long length,
				   struct iova_bitmap *dirty)
{}

static const struct vfio_log_ops mtty_log_ops =;

static int mtty_init_dev(struct vfio_device *vdev)
{}

static int mtty_probe(struct mdev_device *mdev)
{}

static void mtty_release_dev(struct vfio_device *vdev)
{}

static void mtty_remove(struct mdev_device *mdev)
{}

static int mtty_reset(struct mdev_state *mdev_state)
{}

static ssize_t mtty_read(struct vfio_device *vdev, char __user *buf,
			 size_t count, loff_t *ppos)
{}

static ssize_t mtty_write(struct vfio_device *vdev, const char __user *buf,
		   size_t count, loff_t *ppos)
{}

static void mtty_disable_intx(struct mdev_state *mdev_state)
{}

static void mtty_disable_msi(struct mdev_state *mdev_state)
{}

static int mtty_set_irqs(struct mdev_state *mdev_state, uint32_t flags,
			 unsigned int index, unsigned int start,
			 unsigned int count, void *data)
{}

static int mtty_get_region_info(struct mdev_state *mdev_state,
			 struct vfio_region_info *region_info,
			 u16 *cap_type_id, void **cap_type)
{}

static int mtty_get_irq_info(struct vfio_irq_info *irq_info)
{}

static int mtty_get_device_info(struct vfio_device_info *dev_info)
{}

static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
			unsigned long arg)
{}

static ssize_t
sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
		     char *buf)
{}

static DEVICE_ATTR_RO(sample_mdev_dev);

static struct attribute *mdev_dev_attrs[] =;

static const struct attribute_group mdev_dev_group =;

static const struct attribute_group *mdev_dev_groups[] =;

static unsigned int mtty_get_available(struct mdev_type *mtype)
{}

static void mtty_close(struct vfio_device *vdev)
{}

static const struct vfio_device_ops mtty_dev_ops =;

static struct mdev_driver mtty_driver =;

static void mtty_device_release(struct device *dev)
{}

static int __init mtty_dev_init(void)
{}

static void __exit mtty_dev_exit(void)
{}

module_init()
module_exit()

MODULE_LICENSE();
MODULE_DESCRIPTION();
MODULE_VERSION();
MODULE_AUTHOR();