Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2013 - Virtual Open Systems
0004  * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
0005  */
0006 
0007 #ifndef VFIO_PLATFORM_PRIVATE_H
0008 #define VFIO_PLATFORM_PRIVATE_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/vfio.h>
0013 
0014 #define VFIO_PLATFORM_OFFSET_SHIFT   40
0015 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
0016 
0017 #define VFIO_PLATFORM_OFFSET_TO_INDEX(off)  \
0018     (off >> VFIO_PLATFORM_OFFSET_SHIFT)
0019 
0020 #define VFIO_PLATFORM_INDEX_TO_OFFSET(index)    \
0021     ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
0022 
0023 struct vfio_platform_irq {
0024     u32         flags;
0025     u32         count;
0026     int         hwirq;
0027     char            *name;
0028     struct eventfd_ctx  *trigger;
0029     bool            masked;
0030     spinlock_t      lock;
0031     struct virqfd       *unmask;
0032     struct virqfd       *mask;
0033 };
0034 
0035 struct vfio_platform_region {
0036     u64         addr;
0037     resource_size_t     size;
0038     u32         flags;
0039     u32         type;
0040 #define VFIO_PLATFORM_REGION_TYPE_MMIO  1
0041 #define VFIO_PLATFORM_REGION_TYPE_PIO   2
0042     void __iomem        *ioaddr;
0043 };
0044 
0045 struct vfio_platform_device {
0046     struct vfio_device      vdev;
0047     struct vfio_platform_region *regions;
0048     u32             num_regions;
0049     struct vfio_platform_irq    *irqs;
0050     u32             num_irqs;
0051     struct mutex            igate;
0052     const char          *compat;
0053     const char          *acpihid;
0054     struct module           *reset_module;
0055     struct device           *device;
0056 
0057     /*
0058      * These fields should be filled by the bus specific binder
0059      */
0060     void        *opaque;
0061     const char  *name;
0062     uint32_t    flags;
0063     /* callbacks to discover device resources */
0064     struct resource*
0065         (*get_resource)(struct vfio_platform_device *vdev, int i);
0066     int (*get_irq)(struct vfio_platform_device *vdev, int i);
0067     int (*of_reset)(struct vfio_platform_device *vdev);
0068 
0069     bool                reset_required;
0070 };
0071 
0072 typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
0073 
0074 struct vfio_platform_reset_node {
0075     struct list_head link;
0076     char *compat;
0077     struct module *owner;
0078     vfio_platform_reset_fn_t of_reset;
0079 };
0080 
0081 int vfio_platform_probe_common(struct vfio_platform_device *vdev,
0082                    struct device *dev);
0083 void vfio_platform_remove_common(struct vfio_platform_device *vdev);
0084 
0085 int vfio_platform_irq_init(struct vfio_platform_device *vdev);
0086 void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
0087 
0088 int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
0089                  uint32_t flags, unsigned index,
0090                  unsigned start, unsigned count, void *data);
0091 
0092 void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
0093 void vfio_platform_unregister_reset(const char *compat,
0094                     vfio_platform_reset_fn_t fn);
0095 #define vfio_platform_register_reset(__compat, __reset)     \
0096 static struct vfio_platform_reset_node __reset ## _node = { \
0097     .owner = THIS_MODULE,                   \
0098     .compat = __compat,                 \
0099     .of_reset = __reset,                    \
0100 };                              \
0101 __vfio_platform_register_reset(&__reset ## _node)
0102 
0103 #define module_vfio_reset_handler(compat, reset)        \
0104 MODULE_ALIAS("vfio-reset:" compat);             \
0105 static int __init reset ## _module_init(void)           \
0106 {                               \
0107     vfio_platform_register_reset(compat, reset);        \
0108     return 0;                       \
0109 };                              \
0110 static void __exit reset ## _module_exit(void)          \
0111 {                               \
0112     vfio_platform_unregister_reset(compat, reset);      \
0113 };                              \
0114 module_init(reset ## _module_init);             \
0115 module_exit(reset ## _module_exit)
0116 
0117 #endif /* VFIO_PLATFORM_PRIVATE_H */