ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 821-vfio-0007-vfio-fsl-mc-Add-irq-infrastructure-for-fsl-mc-device.patch
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
5
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.
9
10 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
11 Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
12 ---
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
19
20 --- a/drivers/vfio/fsl-mc/Makefile
21 +++ b/drivers/vfio/fsl-mc/Makefile
22 @@ -1,2 +1,2 @@
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
29         }
30         case VFIO_DEVICE_GET_IRQ_INFO:
31         {
32 -               return -EINVAL;
33 +               struct vfio_irq_info info;
34 +
35 +               minsz = offsetofend(struct vfio_irq_info, count);
36 +               if (copy_from_user(&info, (void __user *)arg, minsz))
37 +                       return -EFAULT;
38 +
39 +               if (info.argsz < minsz)
40 +                       return -EINVAL;
41 +
42 +               if (info.index >= mc_dev->obj_desc.irq_count)
43 +                       return -EINVAL;
44 +
45 +               info.flags = VFIO_IRQ_INFO_EVENTFD;
46 +               info.count = 1;
47 +
48 +               return copy_to_user((void __user *)arg, &info, minsz);
49         }
50         case VFIO_DEVICE_SET_IRQS:
51         {
52 -               return -EINVAL;
53 +               struct vfio_irq_set hdr;
54 +               u8 *data = NULL;
55 +               int ret = 0;
56 +
57 +               minsz = offsetofend(struct vfio_irq_set, count);
58 +
59 +               if (copy_from_user(&hdr, (void __user *)arg, minsz))
60 +                       return -EFAULT;
61 +
62 +               if (hdr.argsz < minsz)
63 +                       return -EINVAL;
64 +
65 +               if (hdr.index >= mc_dev->obj_desc.irq_count)
66 +                       return -EINVAL;
67 +
68 +               if (hdr.start != 0 || hdr.count > 1)
69 +                       return -EINVAL;
70 +
71 +               if (hdr.count == 0 &&
72 +                   (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE) ||
73 +                   !(hdr.flags & VFIO_IRQ_SET_ACTION_TRIGGER)))
74 +                       return -EINVAL;
75 +
76 +               if (hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK |
77 +                                 VFIO_IRQ_SET_ACTION_TYPE_MASK))
78 +                       return -EINVAL;
79 +
80 +               if (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE)) {
81 +                       size_t size;
82 +
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);
87 +                       else
88 +                               return -EINVAL;
89 +
90 +                       if (hdr.argsz - minsz < hdr.count * size)
91 +                               return -EINVAL;
92 +
93 +                       data = memdup_user((void __user *)(arg + minsz),
94 +                                          hdr.count * size);
95 +                       if (IS_ERR(data))
96 +                               return PTR_ERR(data);
97 +               }
98 +
99 +               ret = vfio_fsl_mc_set_irqs_ioctl(vdev, hdr.flags,
100 +                                                hdr.index, hdr.start,
101 +                                                hdr.count, data);
102 +               return ret;
103         }
104         case VFIO_DEVICE_RESET:
105         {
106 @@ -304,6 +368,9 @@ static int vfio_fsl_mc_init_device(struc
107         int ret = 0;
108         unsigned int irq_count;
109  
110 +       /* innherit the msi domain from parent */
111 +       dev_set_msi_domain(&mc_dev->dev, dev_get_msi_domain(mc_dev->dev.parent));
112 +
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);
116 --- /dev/null
117 +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c
118 @@ -0,0 +1,62 @@
119 +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
120 +/*
121 + * Copyright 2013-2016 Freescale Semiconductor Inc.
122 + * Copyright 2019 NXP
123 + */
124 +
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>
130 +
131 +#include "linux/fsl/mc.h"
132 +#include "vfio_fsl_mc_private.h"
133 +
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,
137 +                               void *data)
138 +{
139 +       return -EINVAL;
140 +}
141 +
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,
145 +                               void *data)
146 +{
147 +       return -EINVAL;
148 +}
149 +
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,
153 +                                      void *data)
154 +{
155 +       return -EINVAL;
156 +}
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,
160 +                              void *data)
161 +{
162 +       int ret = -ENOTTY;
163 +
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,
167 +                                          flags, data);
168 +               break;
169 +       case VFIO_IRQ_SET_ACTION_UNMASK:
170 +               ret = vfio_fsl_mc_irq_unmask(vdev, index, start, count,
171 +                                            flags, data);
172 +               break;
173 +       case VFIO_IRQ_SET_ACTION_TRIGGER:
174 +               ret = vfio_fsl_mc_set_irq_trigger(vdev, index, start,
175 +                                                 count, flags, data);
176 +               break;
177 +       }
178 +
179 +       return ret;
180 +}
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;
185  };
186  
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,
190 +                              void *data);
191 +
192  #endif /* VFIO_PCI_PRIVATE_H */