Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2013 - Virtual Open Systems
  4 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
 
 
 
 
 
 
 
 
 
  5 */
  6
  7#ifndef VFIO_PLATFORM_PRIVATE_H
  8#define VFIO_PLATFORM_PRIVATE_H
  9
 10#include <linux/types.h>
 11#include <linux/interrupt.h>
 12#include <linux/vfio.h>
 13
 14#define VFIO_PLATFORM_OFFSET_SHIFT   40
 15#define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
 16
 17#define VFIO_PLATFORM_OFFSET_TO_INDEX(off)	\
 18	(off >> VFIO_PLATFORM_OFFSET_SHIFT)
 19
 20#define VFIO_PLATFORM_INDEX_TO_OFFSET(index)	\
 21	((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
 22
 23struct vfio_platform_irq {
 24	u32			flags;
 25	u32			count;
 26	int			hwirq;
 27	char			*name;
 28	struct eventfd_ctx	*trigger;
 29	bool			masked;
 30	spinlock_t		lock;
 31	struct virqfd		*unmask;
 32	struct virqfd		*mask;
 33};
 34
 35struct vfio_platform_region {
 36	u64			addr;
 37	resource_size_t		size;
 38	u32			flags;
 39	u32			type;
 40#define VFIO_PLATFORM_REGION_TYPE_MMIO	1
 41#define VFIO_PLATFORM_REGION_TYPE_PIO	2
 42	void __iomem		*ioaddr;
 43};
 44
 45struct vfio_platform_device {
 46	struct vfio_device		vdev;
 47	struct vfio_platform_region	*regions;
 48	u32				num_regions;
 49	struct vfio_platform_irq	*irqs;
 50	u32				num_irqs;
 
 51	struct mutex			igate;
 
 52	const char			*compat;
 53	const char			*acpihid;
 54	struct module			*reset_module;
 55	struct device			*device;
 56
 57	/*
 58	 * These fields should be filled by the bus specific binder
 59	 */
 60	void		*opaque;
 61	const char	*name;
 62	uint32_t	flags;
 63	/* callbacks to discover device resources */
 64	struct resource*
 65		(*get_resource)(struct vfio_platform_device *vdev, int i);
 66	int	(*get_irq)(struct vfio_platform_device *vdev, int i);
 67	int	(*of_reset)(struct vfio_platform_device *vdev);
 68
 69	bool				reset_required;
 70};
 71
 72typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
 73
 74struct vfio_platform_reset_node {
 75	struct list_head link;
 76	char *compat;
 77	struct module *owner;
 78	vfio_platform_reset_fn_t of_reset;
 79};
 80
 81int vfio_platform_init_common(struct vfio_platform_device *vdev);
 82void vfio_platform_release_common(struct vfio_platform_device *vdev);
 83
 84int vfio_platform_open_device(struct vfio_device *core_vdev);
 85void vfio_platform_close_device(struct vfio_device *core_vdev);
 86long vfio_platform_ioctl(struct vfio_device *core_vdev,
 87			 unsigned int cmd, unsigned long arg);
 88ssize_t vfio_platform_read(struct vfio_device *core_vdev,
 89			   char __user *buf, size_t count,
 90			   loff_t *ppos);
 91ssize_t vfio_platform_write(struct vfio_device *core_vdev,
 92			    const char __user *buf,
 93			    size_t count, loff_t *ppos);
 94int vfio_platform_mmap(struct vfio_device *core_vdev,
 95		       struct vm_area_struct *vma);
 96
 97int vfio_platform_irq_init(struct vfio_platform_device *vdev);
 98void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
 99
100int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
101				 uint32_t flags, unsigned index,
102				 unsigned start, unsigned count, void *data);
103
104void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
105void vfio_platform_unregister_reset(const char *compat,
106				    vfio_platform_reset_fn_t fn);
107#define vfio_platform_register_reset(__compat, __reset)		\
108static struct vfio_platform_reset_node __reset ## _node = {	\
109	.owner = THIS_MODULE,					\
110	.compat = __compat,					\
111	.of_reset = __reset,					\
112};								\
113__vfio_platform_register_reset(&__reset ## _node)
114
115#define module_vfio_reset_handler(compat, reset)		\
116MODULE_ALIAS("vfio-reset:" compat);				\
117static int __init reset ## _module_init(void)			\
118{								\
119	vfio_platform_register_reset(compat, reset);		\
120	return 0;						\
121};								\
122static void __exit reset ## _module_exit(void)			\
123{								\
124	vfio_platform_unregister_reset(compat, reset);		\
125};								\
126module_init(reset ## _module_init);				\
127module_exit(reset ## _module_exit)
128
129#endif /* VFIO_PLATFORM_PRIVATE_H */
v4.6
 
  1/*
  2 * Copyright (C) 2013 - Virtual Open Systems
  3 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify
  6 * it under the terms of the GNU General Public License, version 2, as
  7 * published by the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 */
 14
 15#ifndef VFIO_PLATFORM_PRIVATE_H
 16#define VFIO_PLATFORM_PRIVATE_H
 17
 18#include <linux/types.h>
 19#include <linux/interrupt.h>
 
 20
 21#define VFIO_PLATFORM_OFFSET_SHIFT   40
 22#define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
 23
 24#define VFIO_PLATFORM_OFFSET_TO_INDEX(off)	\
 25	(off >> VFIO_PLATFORM_OFFSET_SHIFT)
 26
 27#define VFIO_PLATFORM_INDEX_TO_OFFSET(index)	\
 28	((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
 29
 30struct vfio_platform_irq {
 31	u32			flags;
 32	u32			count;
 33	int			hwirq;
 34	char			*name;
 35	struct eventfd_ctx	*trigger;
 36	bool			masked;
 37	spinlock_t		lock;
 38	struct virqfd		*unmask;
 39	struct virqfd		*mask;
 40};
 41
 42struct vfio_platform_region {
 43	u64			addr;
 44	resource_size_t		size;
 45	u32			flags;
 46	u32			type;
 47#define VFIO_PLATFORM_REGION_TYPE_MMIO	1
 48#define VFIO_PLATFORM_REGION_TYPE_PIO	2
 49	void __iomem		*ioaddr;
 50};
 51
 52struct vfio_platform_device {
 
 53	struct vfio_platform_region	*regions;
 54	u32				num_regions;
 55	struct vfio_platform_irq	*irqs;
 56	u32				num_irqs;
 57	int				refcnt;
 58	struct mutex			igate;
 59	struct module			*parent_module;
 60	const char			*compat;
 
 61	struct module			*reset_module;
 62	struct device			*device;
 63
 64	/*
 65	 * These fields should be filled by the bus specific binder
 66	 */
 67	void		*opaque;
 68	const char	*name;
 69	uint32_t	flags;
 70	/* callbacks to discover device resources */
 71	struct resource*
 72		(*get_resource)(struct vfio_platform_device *vdev, int i);
 73	int	(*get_irq)(struct vfio_platform_device *vdev, int i);
 74	int	(*reset)(struct vfio_platform_device *vdev);
 
 
 75};
 76
 77typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
 78
 79struct vfio_platform_reset_node {
 80	struct list_head link;
 81	char *compat;
 82	struct module *owner;
 83	vfio_platform_reset_fn_t reset;
 84};
 85
 86extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
 87				      struct device *dev);
 88extern struct vfio_platform_device *vfio_platform_remove_common
 89				     (struct device *dev);
 90
 91extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
 92extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
 93
 94extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
 95					uint32_t flags, unsigned index,
 96					unsigned start, unsigned count,
 97					void *data);
 98
 99extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
100extern void vfio_platform_unregister_reset(const char *compat,
101					   vfio_platform_reset_fn_t fn);
 
 
 
 
 
 
 
 
 
 
102#define vfio_platform_register_reset(__compat, __reset)		\
103static struct vfio_platform_reset_node __reset ## _node = {	\
104	.owner = THIS_MODULE,					\
105	.compat = __compat,					\
106	.reset = __reset,					\
107};								\
108__vfio_platform_register_reset(&__reset ## _node)
109
110#define module_vfio_reset_handler(compat, reset)		\
111MODULE_ALIAS("vfio-reset:" compat);				\
112static int __init reset ## _module_init(void)			\
113{								\
114	vfio_platform_register_reset(compat, reset);		\
115	return 0;						\
116};								\
117static void __exit reset ## _module_exit(void)			\
118{								\
119	vfio_platform_unregister_reset(compat, reset);		\
120};								\
121module_init(reset ## _module_init);				\
122module_exit(reset ## _module_exit)
123
124#endif /* VFIO_PLATFORM_PRIVATE_H */