1 From aa8dac23408e24432f7d6c404cddc8997a142bd6 Mon Sep 17 00:00:00 2001
2 From: Diana Craciun <diana.craciun@nxp.com>
3 Date: Mon, 30 Sep 2019 11:56:35 +0300
4 Subject: [PATCH] vfio/fsl-mc: Add irq infrastructure for fsl-mc devices
6 This patch adds the skeleton for interrupt support
7 for fsl-mc devices. The interrupts are not yet functional,
8 the functionality will be added by subsequent patches.
10 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
11 Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
13 drivers/vfio/fsl-mc/Makefile | 2 +-
14 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 71 ++++++++++++++++++++++++++++++-
15 drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 62 +++++++++++++++++++++++++++
16 drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 5 +++
17 4 files changed, 137 insertions(+), 3 deletions(-)
18 create mode 100644 drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c
20 --- a/drivers/vfio/fsl-mc/Makefile
21 +++ b/drivers/vfio/fsl-mc/Makefile
23 vfio-fsl_mc-y := vfio_fsl_mc.o
24 -obj-$(CONFIG_VFIO_FSL_MC) += vfio_fsl_mc.o
25 +obj-$(CONFIG_VFIO_FSL_MC) += vfio_fsl_mc.o vfio_fsl_mc_intr.o
26 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
27 +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
28 @@ -208,11 +208,75 @@ static long vfio_fsl_mc_ioctl(void *devi
30 case VFIO_DEVICE_GET_IRQ_INFO:
33 + struct vfio_irq_info info;
35 + minsz = offsetofend(struct vfio_irq_info, count);
36 + if (copy_from_user(&info, (void __user *)arg, minsz))
39 + if (info.argsz < minsz)
42 + if (info.index >= mc_dev->obj_desc.irq_count)
45 + info.flags = VFIO_IRQ_INFO_EVENTFD;
48 + return copy_to_user((void __user *)arg, &info, minsz);
50 case VFIO_DEVICE_SET_IRQS:
53 + struct vfio_irq_set hdr;
57 + minsz = offsetofend(struct vfio_irq_set, count);
59 + if (copy_from_user(&hdr, (void __user *)arg, minsz))
62 + if (hdr.argsz < minsz)
65 + if (hdr.index >= mc_dev->obj_desc.irq_count)
68 + if (hdr.start != 0 || hdr.count > 1)
71 + if (hdr.count == 0 &&
72 + (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE) ||
73 + !(hdr.flags & VFIO_IRQ_SET_ACTION_TRIGGER)))
76 + if (hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK |
77 + VFIO_IRQ_SET_ACTION_TYPE_MASK))
80 + if (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE)) {
83 + if (hdr.flags & VFIO_IRQ_SET_DATA_BOOL)
84 + size = sizeof(uint8_t);
85 + else if (hdr.flags & VFIO_IRQ_SET_DATA_EVENTFD)
86 + size = sizeof(int32_t);
90 + if (hdr.argsz - minsz < hdr.count * size)
93 + data = memdup_user((void __user *)(arg + minsz),
96 + return PTR_ERR(data);
99 + ret = vfio_fsl_mc_set_irqs_ioctl(vdev, hdr.flags,
100 + hdr.index, hdr.start,
104 case VFIO_DEVICE_RESET:
106 @@ -304,6 +368,9 @@ static int vfio_fsl_mc_init_device(struc
108 unsigned int irq_count;
110 + /* innherit the msi domain from parent */
111 + dev_set_msi_domain(&mc_dev->dev, dev_get_msi_domain(mc_dev->dev.parent));
113 /* Non-dprc devices share mc_io from parent */
114 if (!is_fsl_mc_bus_dprc(mc_dev)) {
115 struct fsl_mc_device *mc_cont = to_fsl_mc_device(mc_dev->dev.parent);
117 +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c
119 +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
121 + * Copyright 2013-2016 Freescale Semiconductor Inc.
122 + * Copyright 2019 NXP
125 +#include <linux/vfio.h>
126 +#include <linux/slab.h>
127 +#include <linux/types.h>
128 +#include <linux/eventfd.h>
129 +#include <linux/msi.h>
131 +#include "linux/fsl/mc.h"
132 +#include "vfio_fsl_mc_private.h"
134 +static int vfio_fsl_mc_irq_mask(struct vfio_fsl_mc_device *vdev,
135 + unsigned int index, unsigned int start,
136 + unsigned int count, uint32_t flags,
142 +static int vfio_fsl_mc_irq_unmask(struct vfio_fsl_mc_device *vdev,
143 + unsigned int index, unsigned int start,
144 + unsigned int count, uint32_t flags,
150 +static int vfio_fsl_mc_set_irq_trigger(struct vfio_fsl_mc_device *vdev,
151 + unsigned int index, unsigned int start,
152 + unsigned int count, uint32_t flags,
157 +int vfio_fsl_mc_set_irqs_ioctl(struct vfio_fsl_mc_device *vdev,
158 + uint32_t flags, unsigned int index,
159 + unsigned int start, unsigned int count,
164 + switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
165 + case VFIO_IRQ_SET_ACTION_MASK:
166 + ret = vfio_fsl_mc_irq_mask(vdev, index, start, count,
169 + case VFIO_IRQ_SET_ACTION_UNMASK:
170 + ret = vfio_fsl_mc_irq_unmask(vdev, index, start, count,
173 + case VFIO_IRQ_SET_ACTION_TRIGGER:
174 + ret = vfio_fsl_mc_set_irq_trigger(vdev, index, start,
175 + count, flags, data);
181 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h
182 +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h
183 @@ -35,4 +35,9 @@ struct vfio_fsl_mc_device {
184 struct vfio_fsl_mc_reflck *reflck;
187 +int vfio_fsl_mc_set_irqs_ioctl(struct vfio_fsl_mc_device *vdev,
188 + uint32_t flags, unsigned int index,
189 + unsigned int start, unsigned int count,
192 #endif /* VFIO_PCI_PRIVATE_H */