Greg Kroah-Hartman | 989d42e | 2017-11-07 17:30:07 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 2 | /* |
| 3 | * MSI framework for platform devices |
| 4 | * |
| 5 | * Copyright (C) 2015 ARM Limited, All Rights Reserved. |
| 6 | * Author: Marc Zyngier <marc.zyngier@arm.com> |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/idr.h> |
| 11 | #include <linux/irq.h> |
| 12 | #include <linux/irqdomain.h> |
| 13 | #include <linux/msi.h> |
| 14 | #include <linux/slab.h> |
| 15 | |
MaJun | aff5e06 | 2015-12-22 10:47:22 +0800 | [diff] [blame] | 16 | #define DEV_ID_SHIFT 21 |
Marc Zyngier | ab6484e | 2015-11-23 08:26:02 +0000 | [diff] [blame] | 17 | #define MAX_DEV_MSIS (1 << (32 - DEV_ID_SHIFT)) |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Internal data structure containing a (made up, but unique) devid |
| 21 | * and the callback to write the MSI message. |
| 22 | */ |
| 23 | struct platform_msi_priv_data { |
Barry Song | 00ed140 | 2021-08-13 15:56:28 +1200 | [diff] [blame] | 24 | struct device *dev; |
| 25 | void *host_data; |
Barry Song | 00ed140 | 2021-08-13 15:56:28 +1200 | [diff] [blame] | 26 | msi_alloc_info_t arg; |
| 27 | irq_write_msi_msg_t write_msg; |
| 28 | int devid; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | /* The devid allocator */ |
| 32 | static DEFINE_IDA(platform_msi_devid_ida); |
| 33 | |
| 34 | #ifdef GENERIC_MSI_DOMAIN_OPS |
| 35 | /* |
| 36 | * Convert an msi_desc to a globaly unique identifier (per-device |
| 37 | * devid + msi_desc position in the msi_list). |
| 38 | */ |
| 39 | static irq_hw_number_t platform_msi_calc_hwirq(struct msi_desc *desc) |
| 40 | { |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 41 | u32 devid = desc->dev->msi.data->platform_data->devid; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 42 | |
Thomas Gleixner | dba27c7 | 2021-12-10 23:19:14 +0100 | [diff] [blame] | 43 | return (devid << (32 - DEV_ID_SHIFT)) | desc->msi_index; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void platform_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc) |
| 47 | { |
| 48 | arg->desc = desc; |
| 49 | arg->hwirq = platform_msi_calc_hwirq(desc); |
| 50 | } |
| 51 | |
| 52 | static int platform_msi_init(struct irq_domain *domain, |
| 53 | struct msi_domain_info *info, |
| 54 | unsigned int virq, irq_hw_number_t hwirq, |
| 55 | msi_alloc_info_t *arg) |
| 56 | { |
Marc Zyngier | e4084a1 | 2015-09-13 13:37:03 +0100 | [diff] [blame] | 57 | return irq_domain_set_hwirq_and_chip(domain, virq, hwirq, |
| 58 | info->chip, info->chip_data); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 59 | } |
Marc Zyngier | 91f90da | 2020-11-29 13:52:06 +0000 | [diff] [blame] | 60 | |
| 61 | static void platform_msi_set_proxy_dev(msi_alloc_info_t *arg) |
| 62 | { |
| 63 | arg->flags |= MSI_ALLOC_FLAGS_PROXY_DEVICE; |
| 64 | } |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 65 | #else |
| 66 | #define platform_msi_set_desc NULL |
| 67 | #define platform_msi_init NULL |
Marc Zyngier | 91f90da | 2020-11-29 13:52:06 +0000 | [diff] [blame] | 68 | #define platform_msi_set_proxy_dev(x) do {} while(0) |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | static void platform_msi_update_dom_ops(struct msi_domain_info *info) |
| 72 | { |
| 73 | struct msi_domain_ops *ops = info->ops; |
| 74 | |
| 75 | BUG_ON(!ops); |
| 76 | |
| 77 | if (ops->msi_init == NULL) |
| 78 | ops->msi_init = platform_msi_init; |
| 79 | if (ops->set_desc == NULL) |
| 80 | ops->set_desc = platform_msi_set_desc; |
| 81 | } |
| 82 | |
| 83 | static void platform_msi_write_msg(struct irq_data *data, struct msi_msg *msg) |
| 84 | { |
Marc Zyngier | e4084a1 | 2015-09-13 13:37:03 +0100 | [diff] [blame] | 85 | struct msi_desc *desc = irq_data_get_msi_desc(data); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 86 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 87 | desc->dev->msi.data->platform_data->write_msg(desc, msg); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void platform_msi_update_chip_ops(struct msi_domain_info *info) |
| 91 | { |
| 92 | struct irq_chip *chip = info->chip; |
| 93 | |
| 94 | BUG_ON(!chip); |
| 95 | if (!chip->irq_mask) |
| 96 | chip->irq_mask = irq_chip_mask_parent; |
| 97 | if (!chip->irq_unmask) |
| 98 | chip->irq_unmask = irq_chip_unmask_parent; |
| 99 | if (!chip->irq_eoi) |
| 100 | chip->irq_eoi = irq_chip_eoi_parent; |
| 101 | if (!chip->irq_set_affinity) |
| 102 | chip->irq_set_affinity = msi_domain_set_affinity; |
| 103 | if (!chip->irq_write_msi_msg) |
| 104 | chip->irq_write_msi_msg = platform_msi_write_msg; |
Marc Zyngier | 6988e0e | 2018-05-08 13:14:31 +0100 | [diff] [blame] | 105 | if (WARN_ON((info->flags & MSI_FLAG_LEVEL_CAPABLE) && |
| 106 | !(chip->flags & IRQCHIP_SUPPORTS_LEVEL_MSI))) |
| 107 | info->flags &= ~MSI_FLAG_LEVEL_CAPABLE; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 110 | /** |
| 111 | * platform_msi_create_irq_domain - Create a platform MSI interrupt domain |
Marc Zyngier | be5436c | 2015-10-13 12:51:44 +0100 | [diff] [blame] | 112 | * @fwnode: Optional fwnode of the interrupt controller |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 113 | * @info: MSI domain info |
| 114 | * @parent: Parent irq domain |
| 115 | * |
| 116 | * Updates the domain and chip ops and creates a platform MSI |
| 117 | * interrupt domain. |
| 118 | * |
| 119 | * Returns: |
| 120 | * A domain pointer or NULL in case of failure. |
| 121 | */ |
Marc Zyngier | be5436c | 2015-10-13 12:51:44 +0100 | [diff] [blame] | 122 | struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode, |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 123 | struct msi_domain_info *info, |
| 124 | struct irq_domain *parent) |
| 125 | { |
| 126 | struct irq_domain *domain; |
| 127 | |
| 128 | if (info->flags & MSI_FLAG_USE_DEF_DOM_OPS) |
| 129 | platform_msi_update_dom_ops(info); |
| 130 | if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) |
| 131 | platform_msi_update_chip_ops(info); |
Thomas Gleixner | 653b50c | 2021-12-06 23:51:41 +0100 | [diff] [blame] | 132 | info->flags |= MSI_FLAG_DEV_SYSFS | MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS | |
| 133 | MSI_FLAG_FREE_MSI_DESCS; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 134 | |
Marc Zyngier | be5436c | 2015-10-13 12:51:44 +0100 | [diff] [blame] | 135 | domain = msi_create_irq_domain(fwnode, info, parent); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 136 | if (domain) |
Marc Zyngier | 96f0d93 | 2017-06-22 11:42:50 +0100 | [diff] [blame] | 137 | irq_domain_update_bus_token(domain, DOMAIN_BUS_PLATFORM_MSI); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 138 | |
| 139 | return domain; |
| 140 | } |
| 141 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 142 | static int platform_msi_alloc_priv_data(struct device *dev, unsigned int nvec, |
| 143 | irq_write_msi_msg_t write_msi_msg) |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 144 | { |
| 145 | struct platform_msi_priv_data *datap; |
Thomas Gleixner | 077aead | 2021-12-10 23:18:58 +0100 | [diff] [blame] | 146 | int err; |
| 147 | |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 148 | /* |
Matthias Brugger | 788d239 | 2017-01-16 19:48:20 +0100 | [diff] [blame] | 149 | * Limit the number of interrupts to 2048 per device. Should we |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 150 | * need to bump this up, DEV_ID_SHIFT should be adjusted |
| 151 | * accordingly (which would impact the max number of MSI |
| 152 | * capable devices). |
| 153 | */ |
Thomas Gleixner | 34fff628 | 2021-12-10 23:18:54 +0100 | [diff] [blame] | 154 | if (!dev->msi.domain || !write_msi_msg || !nvec || nvec > MAX_DEV_MSIS) |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 155 | return -EINVAL; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 156 | |
Thomas Gleixner | 34fff628 | 2021-12-10 23:18:54 +0100 | [diff] [blame] | 157 | if (dev->msi.domain->bus_token != DOMAIN_BUS_PLATFORM_MSI) { |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 158 | dev_err(dev, "Incompatible msi_domain, giving up\n"); |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 159 | return -EINVAL; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Thomas Gleixner | 077aead | 2021-12-10 23:18:58 +0100 | [diff] [blame] | 162 | err = msi_setup_device_data(dev); |
| 163 | if (err) |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 164 | return err; |
Thomas Gleixner | 077aead | 2021-12-10 23:18:58 +0100 | [diff] [blame] | 165 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 166 | /* Already initialized? */ |
| 167 | if (dev->msi.data->platform_data) |
| 168 | return -EBUSY; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 169 | |
| 170 | datap = kzalloc(sizeof(*datap), GFP_KERNEL); |
| 171 | if (!datap) |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 172 | return -ENOMEM; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 173 | |
| 174 | datap->devid = ida_simple_get(&platform_msi_devid_ida, |
| 175 | 0, 1 << DEV_ID_SHIFT, GFP_KERNEL); |
| 176 | if (datap->devid < 0) { |
Thomas Gleixner | 077aead | 2021-12-10 23:18:58 +0100 | [diff] [blame] | 177 | err = datap->devid; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 178 | kfree(datap); |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 179 | return err; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | datap->write_msg = write_msi_msg; |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 183 | datap->dev = dev; |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 184 | dev->msi.data->platform_data = datap; |
| 185 | return 0; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 188 | static void platform_msi_free_priv_data(struct device *dev) |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 189 | { |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 190 | struct platform_msi_priv_data *data = dev->msi.data->platform_data; |
| 191 | |
| 192 | dev->msi.data->platform_data = NULL; |
Marc Zyngier | 72f57f2 | 2015-11-23 08:26:03 +0000 | [diff] [blame] | 193 | ida_simple_remove(&platform_msi_devid_ida, data->devid); |
| 194 | kfree(data); |
| 195 | } |
| 196 | |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 197 | /** |
| 198 | * platform_msi_domain_alloc_irqs - Allocate MSI interrupts for @dev |
| 199 | * @dev: The device for which to allocate interrupts |
| 200 | * @nvec: The number of interrupts to allocate |
| 201 | * @write_msi_msg: Callback to write an interrupt message for @dev |
| 202 | * |
| 203 | * Returns: |
| 204 | * Zero for success, or an error code in case of failure |
| 205 | */ |
| 206 | int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec, |
| 207 | irq_write_msi_msg_t write_msi_msg) |
| 208 | { |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 209 | int err; |
| 210 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 211 | err = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg); |
| 212 | if (err) |
| 213 | return err; |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 214 | |
Thomas Gleixner | 34fff628 | 2021-12-10 23:18:54 +0100 | [diff] [blame] | 215 | err = msi_domain_alloc_irqs(dev->msi.domain, dev, nvec); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 216 | if (err) |
Thomas Gleixner | 653b50c | 2021-12-06 23:51:41 +0100 | [diff] [blame] | 217 | platform_msi_free_priv_data(dev); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 218 | |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 219 | return err; |
| 220 | } |
Thomas Petazzoni | bb1a793 | 2016-01-26 13:52:27 +0000 | [diff] [blame] | 221 | EXPORT_SYMBOL_GPL(platform_msi_domain_alloc_irqs); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * platform_msi_domain_free_irqs - Free MSI interrupts for @dev |
| 225 | * @dev: The device for which to free interrupts |
| 226 | */ |
| 227 | void platform_msi_domain_free_irqs(struct device *dev) |
| 228 | { |
Thomas Gleixner | 34fff628 | 2021-12-10 23:18:54 +0100 | [diff] [blame] | 229 | msi_domain_free_irqs(dev->msi.domain, dev); |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 230 | platform_msi_free_priv_data(dev); |
Marc Zyngier | c09fcc4b | 2015-07-28 14:46:16 +0100 | [diff] [blame] | 231 | } |
Thomas Petazzoni | bb1a793 | 2016-01-26 13:52:27 +0000 | [diff] [blame] | 232 | EXPORT_SYMBOL_GPL(platform_msi_domain_free_irqs); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * platform_msi_get_host_data - Query the private data associated with |
| 236 | * a platform-msi domain |
| 237 | * @domain: The platform-msi domain |
| 238 | * |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 239 | * Return: The private data provided when calling |
| 240 | * platform_msi_create_device_domain(). |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 241 | */ |
| 242 | void *platform_msi_get_host_data(struct irq_domain *domain) |
| 243 | { |
| 244 | struct platform_msi_priv_data *data = domain->host_data; |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 245 | |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 246 | return data->host_data; |
| 247 | } |
| 248 | |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 249 | static struct lock_class_key platform_device_msi_lock_class; |
| 250 | |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 251 | /** |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 252 | * __platform_msi_create_device_domain - Create a platform-msi device domain |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 253 | * |
| 254 | * @dev: The device generating the MSIs |
| 255 | * @nvec: The number of MSIs that need to be allocated |
Pierre-Louis Bossart | 3c65213 | 2021-03-31 18:26:13 -0500 | [diff] [blame] | 256 | * @is_tree: flag to indicate tree hierarchy |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 257 | * @write_msi_msg: Callback to write an interrupt message for @dev |
| 258 | * @ops: The hierarchy domain operations to use |
| 259 | * @host_data: Private data associated to this domain |
| 260 | * |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 261 | * Return: An irqdomain for @nvec interrupts on success, NULL in case of error. |
| 262 | * |
| 263 | * This is for interrupt domains which stack on a platform-msi domain |
| 264 | * created by platform_msi_create_irq_domain(). @dev->msi.domain points to |
| 265 | * that platform-msi domain which is the parent for the new domain. |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 266 | */ |
| 267 | struct irq_domain * |
Marc Zyngier | 1f83515 | 2018-10-01 16:13:45 +0200 | [diff] [blame] | 268 | __platform_msi_create_device_domain(struct device *dev, |
| 269 | unsigned int nvec, |
| 270 | bool is_tree, |
| 271 | irq_write_msi_msg_t write_msi_msg, |
| 272 | const struct irq_domain_ops *ops, |
| 273 | void *host_data) |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 274 | { |
| 275 | struct platform_msi_priv_data *data; |
| 276 | struct irq_domain *domain; |
| 277 | int err; |
| 278 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 279 | err = platform_msi_alloc_priv_data(dev, nvec, write_msi_msg); |
| 280 | if (err) |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 281 | return NULL; |
| 282 | |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 283 | /* |
| 284 | * Use a separate lock class for the MSI descriptor mutex on |
| 285 | * platform MSI device domains because the descriptor mutex nests |
| 286 | * into the domain mutex. See alloc/free below. |
| 287 | */ |
| 288 | lockdep_set_class(&dev->msi.data->mutex, &platform_device_msi_lock_class); |
| 289 | |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 290 | data = dev->msi.data->platform_data; |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 291 | data->host_data = host_data; |
Thomas Gleixner | 34fff628 | 2021-12-10 23:18:54 +0100 | [diff] [blame] | 292 | domain = irq_domain_create_hierarchy(dev->msi.domain, 0, |
Marc Zyngier | 1f83515 | 2018-10-01 16:13:45 +0200 | [diff] [blame] | 293 | is_tree ? 0 : nvec, |
Hanjun Guo | 6943acf | 2017-03-07 20:40:07 +0800 | [diff] [blame] | 294 | dev->fwnode, ops, data); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 295 | if (!domain) |
| 296 | goto free_priv; |
| 297 | |
Marc Zyngier | 91f90da | 2020-11-29 13:52:06 +0000 | [diff] [blame] | 298 | platform_msi_set_proxy_dev(&data->arg); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 299 | err = msi_domain_prepare_irqs(domain->parent, dev, nvec, &data->arg); |
| 300 | if (err) |
| 301 | goto free_domain; |
| 302 | |
| 303 | return domain; |
| 304 | |
| 305 | free_domain: |
| 306 | irq_domain_remove(domain); |
| 307 | free_priv: |
Thomas Gleixner | fc22e7d | 2021-12-10 23:19:11 +0100 | [diff] [blame] | 308 | platform_msi_free_priv_data(dev); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | /** |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 313 | * platform_msi_device_domain_free - Free interrupts associated with a platform-msi |
| 314 | * device domain |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 315 | * |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 316 | * @domain: The platform-msi device domain |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 317 | * @virq: The base irq from which to perform the free operation |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 318 | * @nr_irqs: How many interrupts to free from @virq |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 319 | */ |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 320 | void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int virq, |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 321 | unsigned int nr_irqs) |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 322 | { |
| 323 | struct platform_msi_priv_data *data = domain->host_data; |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 324 | |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 325 | msi_lock_descs(data->dev); |
| 326 | irq_domain_free_irqs_common(domain, virq, nr_irqs); |
| 327 | msi_free_msi_descs_range(data->dev, MSI_DESC_ALL, virq, virq + nr_irqs - 1); |
| 328 | msi_unlock_descs(data->dev); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /** |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 332 | * platform_msi_device_domain_alloc - Allocate interrupts associated with |
| 333 | * a platform-msi device domain |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 334 | * |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 335 | * @domain: The platform-msi device domain |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 336 | * @virq: The base irq from which to perform the allocate operation |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 337 | * @nr_irqs: How many interrupts to allocate from @virq |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 338 | * |
| 339 | * Return 0 on success, or an error code on failure. Must be called |
| 340 | * with irq_domain_mutex held (which can only be done as part of a |
| 341 | * top-level interrupt allocation). |
| 342 | */ |
Thomas Gleixner | 9835cec | 2021-12-10 23:19:09 +0100 | [diff] [blame] | 343 | int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int virq, |
| 344 | unsigned int nr_irqs) |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 345 | { |
| 346 | struct platform_msi_priv_data *data = domain->host_data; |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 347 | struct device *dev = data->dev; |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 348 | |
Thomas Gleixner | a80713f | 2021-12-06 23:51:42 +0100 | [diff] [blame] | 349 | return msi_domain_populate_irqs(domain->parent, dev, virq, nr_irqs, &data->arg); |
Marc Zyngier | 552c494 | 2015-11-23 08:26:07 +0000 | [diff] [blame] | 350 | } |