Bogdan Purcareata | 203e2de | 2018-01-17 18:36:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 2 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 3 | * fsl-mc object allocator driver |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 4 | * |
Stuart Yoder | 6466dac | 2016-10-26 11:20:33 -0500 | [diff] [blame] | 5 | * Copyright (C) 2013-2016 Freescale Semiconductor, Inc. |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 6 | * |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
Stuart Yoder | d4e7513 | 2016-08-23 17:14:23 -0500 | [diff] [blame] | 9 | #include <linux/module.h> |
| 10 | #include <linux/msi.h> |
Bogdan Purcareata | 6bd067c | 2018-02-05 08:07:42 -0600 | [diff] [blame] | 11 | #include <linux/fsl/mc.h> |
Stuart Yoder | d4e7513 | 2016-08-23 17:14:23 -0500 | [diff] [blame] | 12 | |
Stuart Yoder | 243444f | 2016-08-23 17:13:30 -0500 | [diff] [blame] | 13 | #include "fsl-mc-private.h" |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 14 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 15 | static bool __must_check fsl_mc_is_allocatable(struct fsl_mc_device *mc_dev) |
Laurentiu Tudor | 410ab9b | 2017-06-22 16:35:47 +0300 | [diff] [blame] | 16 | { |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 17 | return is_fsl_mc_bus_dpbp(mc_dev) || |
| 18 | is_fsl_mc_bus_dpmcp(mc_dev) || |
| 19 | is_fsl_mc_bus_dpcon(mc_dev); |
Laurentiu Tudor | 410ab9b | 2017-06-22 16:35:47 +0300 | [diff] [blame] | 20 | } |
Stuart Yoder | e267ddd | 2016-08-23 17:13:17 -0500 | [diff] [blame] | 21 | |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 22 | /** |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 23 | * fsl_mc_resource_pool_add_device - add allocatable object to a resource |
| 24 | * pool of a given fsl-mc bus |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 25 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 26 | * @mc_bus: pointer to the fsl-mc bus |
| 27 | * @pool_type: pool type |
| 28 | * @mc_dev: pointer to allocatable fsl-mc device |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 29 | */ |
| 30 | static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus |
| 31 | *mc_bus, |
| 32 | enum fsl_mc_pool_type |
| 33 | pool_type, |
| 34 | struct fsl_mc_device |
| 35 | *mc_dev) |
| 36 | { |
| 37 | struct fsl_mc_resource_pool *res_pool; |
| 38 | struct fsl_mc_resource *resource; |
| 39 | struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; |
| 40 | int error = -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 41 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 42 | if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 43 | goto out; |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 44 | if (!fsl_mc_is_allocatable(mc_dev)) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 45 | goto out; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 46 | if (mc_dev->resource) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 47 | goto out; |
| 48 | |
| 49 | res_pool = &mc_bus->resource_pools[pool_type]; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 50 | if (res_pool->type != pool_type) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 51 | goto out; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 52 | if (res_pool->mc_bus != mc_bus) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 53 | goto out; |
| 54 | |
| 55 | mutex_lock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 56 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 57 | if (res_pool->max_count < 0) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 58 | goto out_unlock; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 59 | if (res_pool->free_count < 0 || |
| 60 | res_pool->free_count > res_pool->max_count) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 61 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 62 | |
| 63 | resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource), |
| 64 | GFP_KERNEL); |
| 65 | if (!resource) { |
| 66 | error = -ENOMEM; |
| 67 | dev_err(&mc_bus_dev->dev, |
| 68 | "Failed to allocate memory for fsl_mc_resource\n"); |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 69 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | resource->type = pool_type; |
| 73 | resource->id = mc_dev->obj_desc.id; |
| 74 | resource->data = mc_dev; |
| 75 | resource->parent_pool = res_pool; |
| 76 | INIT_LIST_HEAD(&resource->node); |
| 77 | list_add_tail(&resource->node, &res_pool->free_list); |
| 78 | mc_dev->resource = resource; |
| 79 | res_pool->free_count++; |
| 80 | res_pool->max_count++; |
| 81 | error = 0; |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 82 | out_unlock: |
| 83 | mutex_unlock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 84 | out: |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 85 | return error; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * fsl_mc_resource_pool_remove_device - remove an allocatable device from a |
| 90 | * resource pool |
| 91 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 92 | * @mc_dev: pointer to allocatable fsl-mc device |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 93 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 94 | * It permanently removes an allocatable fsl-mc device from the resource |
| 95 | * pool. It's an error if the device is in use. |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 96 | */ |
| 97 | static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device |
| 98 | *mc_dev) |
| 99 | { |
| 100 | struct fsl_mc_device *mc_bus_dev; |
| 101 | struct fsl_mc_bus *mc_bus; |
| 102 | struct fsl_mc_resource_pool *res_pool; |
| 103 | struct fsl_mc_resource *resource; |
| 104 | int error = -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 105 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 106 | if (!fsl_mc_is_allocatable(mc_dev)) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 107 | goto out; |
| 108 | |
| 109 | resource = mc_dev->resource; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 110 | if (!resource || resource->data != mc_dev) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 111 | goto out; |
| 112 | |
| 113 | mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); |
| 114 | mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 115 | res_pool = resource->parent_pool; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 116 | if (res_pool != &mc_bus->resource_pools[resource->type]) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 117 | goto out; |
| 118 | |
| 119 | mutex_lock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 120 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 121 | if (res_pool->max_count <= 0) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 122 | goto out_unlock; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 123 | if (res_pool->free_count <= 0 || |
| 124 | res_pool->free_count > res_pool->max_count) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 125 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * If the device is currently allocated, its resource is not |
| 129 | * in the free list and thus, the device cannot be removed. |
| 130 | */ |
| 131 | if (list_empty(&resource->node)) { |
| 132 | error = -EBUSY; |
| 133 | dev_err(&mc_bus_dev->dev, |
| 134 | "Device %s cannot be removed from resource pool\n", |
| 135 | dev_name(&mc_dev->dev)); |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 136 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 137 | } |
| 138 | |
Wei Yongjun | 9f4feef | 2016-09-15 02:27:04 +0000 | [diff] [blame] | 139 | list_del_init(&resource->node); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 140 | res_pool->free_count--; |
| 141 | res_pool->max_count--; |
| 142 | |
| 143 | devm_kfree(&mc_bus_dev->dev, resource); |
| 144 | mc_dev->resource = NULL; |
| 145 | error = 0; |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 146 | out_unlock: |
| 147 | mutex_unlock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 148 | out: |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 149 | return error; |
| 150 | } |
| 151 | |
| 152 | static const char *const fsl_mc_pool_type_strings[] = { |
| 153 | [FSL_MC_POOL_DPMCP] = "dpmcp", |
| 154 | [FSL_MC_POOL_DPBP] = "dpbp", |
| 155 | [FSL_MC_POOL_DPCON] = "dpcon", |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 156 | [FSL_MC_POOL_IRQ] = "irq", |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static int __must_check object_type_to_pool_type(const char *object_type, |
| 160 | enum fsl_mc_pool_type |
| 161 | *pool_type) |
| 162 | { |
| 163 | unsigned int i; |
| 164 | |
| 165 | for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) { |
| 166 | if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) { |
| 167 | *pool_type = i; |
| 168 | return 0; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | |
| 175 | int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, |
| 176 | enum fsl_mc_pool_type pool_type, |
| 177 | struct fsl_mc_resource **new_resource) |
| 178 | { |
| 179 | struct fsl_mc_resource_pool *res_pool; |
| 180 | struct fsl_mc_resource *resource; |
| 181 | struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; |
| 182 | int error = -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 183 | |
| 184 | BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) != |
| 185 | FSL_MC_NUM_POOL_TYPES); |
| 186 | |
| 187 | *new_resource = NULL; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 188 | if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 189 | goto out; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 190 | |
| 191 | res_pool = &mc_bus->resource_pools[pool_type]; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 192 | if (res_pool->mc_bus != mc_bus) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 193 | goto out; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 194 | |
| 195 | mutex_lock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 196 | resource = list_first_entry_or_null(&res_pool->free_list, |
| 197 | struct fsl_mc_resource, node); |
| 198 | |
| 199 | if (!resource) { |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 200 | error = -ENXIO; |
| 201 | dev_err(&mc_bus_dev->dev, |
| 202 | "No more resources of type %s left\n", |
| 203 | fsl_mc_pool_type_strings[pool_type]); |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 204 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 205 | } |
| 206 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 207 | if (resource->type != pool_type) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 208 | goto out_unlock; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 209 | if (resource->parent_pool != res_pool) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 210 | goto out_unlock; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 211 | if (res_pool->free_count <= 0 || |
| 212 | res_pool->free_count > res_pool->max_count) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 213 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 214 | |
Wei Yongjun | 9f4feef | 2016-09-15 02:27:04 +0000 | [diff] [blame] | 215 | list_del_init(&resource->node); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 216 | |
| 217 | res_pool->free_count--; |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 218 | error = 0; |
| 219 | out_unlock: |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 220 | mutex_unlock(&res_pool->mutex); |
| 221 | *new_resource = resource; |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 222 | out: |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 223 | return error; |
| 224 | } |
| 225 | EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate); |
| 226 | |
| 227 | void fsl_mc_resource_free(struct fsl_mc_resource *resource) |
| 228 | { |
| 229 | struct fsl_mc_resource_pool *res_pool; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 230 | |
| 231 | res_pool = resource->parent_pool; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 232 | if (resource->type != res_pool->type) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 233 | return; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 234 | |
| 235 | mutex_lock(&res_pool->mutex); |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 236 | if (res_pool->free_count < 0 || |
| 237 | res_pool->free_count >= res_pool->max_count) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 238 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 239 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 240 | if (!list_empty(&resource->node)) |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 241 | goto out_unlock; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 242 | |
| 243 | list_add_tail(&resource->node, &res_pool->free_list); |
| 244 | res_pool->free_count++; |
Cihangir Akturk | 6ffdc7b | 2016-04-09 21:45:18 +0300 | [diff] [blame] | 245 | out_unlock: |
| 246 | mutex_unlock(&res_pool->mutex); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 247 | } |
| 248 | EXPORT_SYMBOL_GPL(fsl_mc_resource_free); |
| 249 | |
| 250 | /** |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 251 | * fsl_mc_object_allocate - Allocates an fsl-mc object of the given |
| 252 | * pool type from a given fsl-mc bus instance |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 253 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 254 | * @mc_dev: fsl-mc device which is used in conjunction with the |
| 255 | * allocated object |
| 256 | * @pool_type: pool type |
Lee Jones | 07fbbf2 | 2021-06-17 12:04:58 +0100 | [diff] [blame] | 257 | * @new_mc_adev: pointer to area where the pointer to the allocated device |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 258 | * is to be returned |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 259 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 260 | * Allocatable objects are always used in conjunction with some functional |
| 261 | * device. This function allocates an object of the specified type from |
| 262 | * the DPRC containing the functional device. |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 263 | * |
| 264 | * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC |
| 265 | * portals are allocated using fsl_mc_portal_allocate(), instead of |
| 266 | * this function. |
| 267 | */ |
| 268 | int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, |
| 269 | enum fsl_mc_pool_type pool_type, |
| 270 | struct fsl_mc_device **new_mc_adev) |
| 271 | { |
| 272 | struct fsl_mc_device *mc_bus_dev; |
| 273 | struct fsl_mc_bus *mc_bus; |
| 274 | struct fsl_mc_device *mc_adev; |
| 275 | int error = -EINVAL; |
| 276 | struct fsl_mc_resource *resource = NULL; |
| 277 | |
| 278 | *new_mc_adev = NULL; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 279 | if (mc_dev->flags & FSL_MC_IS_DPRC) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 280 | goto error; |
| 281 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 282 | if (!dev_is_fsl_mc(mc_dev->dev.parent)) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 283 | goto error; |
| 284 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 285 | if (pool_type == FSL_MC_POOL_DPMCP) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 286 | goto error; |
| 287 | |
| 288 | mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); |
| 289 | mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 290 | error = fsl_mc_resource_allocate(mc_bus, pool_type, &resource); |
| 291 | if (error < 0) |
| 292 | goto error; |
| 293 | |
| 294 | mc_adev = resource->data; |
Zhang Changzhong | 3d70fb0 | 2020-12-04 16:02:47 +0800 | [diff] [blame] | 295 | if (!mc_adev) { |
| 296 | error = -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 297 | goto error; |
Zhang Changzhong | 3d70fb0 | 2020-12-04 16:02:47 +0800 | [diff] [blame] | 298 | } |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 299 | |
Ioana Ciornei | afb7742 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 300 | mc_adev->consumer_link = device_link_add(&mc_dev->dev, |
| 301 | &mc_adev->dev, |
| 302 | DL_FLAG_AUTOREMOVE_CONSUMER); |
| 303 | if (!mc_adev->consumer_link) { |
| 304 | error = -EINVAL; |
| 305 | goto error; |
| 306 | } |
| 307 | |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 308 | *new_mc_adev = mc_adev; |
| 309 | return 0; |
| 310 | error: |
| 311 | if (resource) |
| 312 | fsl_mc_resource_free(resource); |
| 313 | |
| 314 | return error; |
| 315 | } |
| 316 | EXPORT_SYMBOL_GPL(fsl_mc_object_allocate); |
| 317 | |
| 318 | /** |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 319 | * fsl_mc_object_free - Returns an fsl-mc object to the resource |
| 320 | * pool where it came from. |
| 321 | * @mc_adev: Pointer to the fsl-mc device |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 322 | */ |
| 323 | void fsl_mc_object_free(struct fsl_mc_device *mc_adev) |
| 324 | { |
| 325 | struct fsl_mc_resource *resource; |
| 326 | |
| 327 | resource = mc_adev->resource; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 328 | if (resource->type == FSL_MC_POOL_DPMCP) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 329 | return; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 330 | if (resource->data != mc_adev) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 331 | return; |
| 332 | |
| 333 | fsl_mc_resource_free(resource); |
Ioana Ciornei | afb7742 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 334 | |
Ioana Ciornei | afb7742 | 2018-12-10 16:50:19 +0000 | [diff] [blame] | 335 | mc_adev->consumer_link = NULL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 336 | } |
| 337 | EXPORT_SYMBOL_GPL(fsl_mc_object_free); |
| 338 | |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 339 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 340 | * A DPRC and the devices in the DPRC all share the same GIC-ITS device |
| 341 | * ID. A block of IRQs is pre-allocated and maintained in a pool |
| 342 | * from which devices can allocate them when needed. |
| 343 | */ |
| 344 | |
| 345 | /* |
| 346 | * Initialize the interrupt pool associated with an fsl-mc bus. |
| 347 | * It allocates a block of IRQs from the GIC-ITS. |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 348 | */ |
Diana Craciun | 0dadd95 | 2020-09-29 11:54:39 +0300 | [diff] [blame] | 349 | int fsl_mc_populate_irq_pool(struct fsl_mc_device *mc_bus_dev, |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 350 | unsigned int irq_count) |
| 351 | { |
| 352 | unsigned int i; |
| 353 | struct msi_desc *msi_desc; |
| 354 | struct fsl_mc_device_irq *irq_resources; |
| 355 | struct fsl_mc_device_irq *mc_dev_irq; |
| 356 | int error; |
Diana Craciun | 0dadd95 | 2020-09-29 11:54:39 +0300 | [diff] [blame] | 357 | struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 358 | struct fsl_mc_resource_pool *res_pool = |
| 359 | &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; |
| 360 | |
Diana Craciun | 0dadd95 | 2020-09-29 11:54:39 +0300 | [diff] [blame] | 361 | /* do nothing if the IRQ pool is already populated */ |
| 362 | if (mc_bus->irq_resources) |
| 363 | return 0; |
| 364 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 365 | if (irq_count == 0 || |
| 366 | irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 367 | return -EINVAL; |
| 368 | |
| 369 | error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count); |
| 370 | if (error < 0) |
| 371 | return error; |
| 372 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 373 | irq_resources = devm_kcalloc(&mc_bus_dev->dev, |
| 374 | irq_count, sizeof(*irq_resources), |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 375 | GFP_KERNEL); |
| 376 | if (!irq_resources) { |
| 377 | error = -ENOMEM; |
| 378 | goto cleanup_msi_irqs; |
| 379 | } |
| 380 | |
| 381 | for (i = 0; i < irq_count; i++) { |
| 382 | mc_dev_irq = &irq_resources[i]; |
| 383 | |
| 384 | /* |
| 385 | * NOTE: This mc_dev_irq's MSI addr/value pair will be set |
| 386 | * by the fsl_mc_msi_write_msg() callback |
| 387 | */ |
| 388 | mc_dev_irq->resource.type = res_pool->type; |
| 389 | mc_dev_irq->resource.data = mc_dev_irq; |
| 390 | mc_dev_irq->resource.parent_pool = res_pool; |
| 391 | INIT_LIST_HEAD(&mc_dev_irq->resource.node); |
| 392 | list_add_tail(&mc_dev_irq->resource.node, &res_pool->free_list); |
| 393 | } |
| 394 | |
| 395 | for_each_msi_entry(msi_desc, &mc_bus_dev->dev) { |
| 396 | mc_dev_irq = &irq_resources[msi_desc->fsl_mc.msi_index]; |
| 397 | mc_dev_irq->msi_desc = msi_desc; |
| 398 | mc_dev_irq->resource.id = msi_desc->irq; |
| 399 | } |
| 400 | |
| 401 | res_pool->max_count = irq_count; |
| 402 | res_pool->free_count = irq_count; |
| 403 | mc_bus->irq_resources = irq_resources; |
| 404 | return 0; |
| 405 | |
| 406 | cleanup_msi_irqs: |
| 407 | fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); |
| 408 | return error; |
| 409 | } |
| 410 | EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool); |
| 411 | |
Lee Jones | 07fbbf2 | 2021-06-17 12:04:58 +0100 | [diff] [blame] | 412 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 413 | * Teardown the interrupt pool associated with an fsl-mc bus. |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 414 | * It frees the IRQs that were allocated to the pool, back to the GIC-ITS. |
| 415 | */ |
Diana Craciun | 0dadd95 | 2020-09-29 11:54:39 +0300 | [diff] [blame] | 416 | void fsl_mc_cleanup_irq_pool(struct fsl_mc_device *mc_bus_dev) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 417 | { |
Diana Craciun | 0dadd95 | 2020-09-29 11:54:39 +0300 | [diff] [blame] | 418 | struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 419 | struct fsl_mc_resource_pool *res_pool = |
| 420 | &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; |
| 421 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 422 | if (!mc_bus->irq_resources) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 423 | return; |
| 424 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 425 | if (res_pool->max_count == 0) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 426 | return; |
| 427 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 428 | if (res_pool->free_count != res_pool->max_count) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 429 | return; |
| 430 | |
| 431 | INIT_LIST_HEAD(&res_pool->free_list); |
| 432 | res_pool->max_count = 0; |
| 433 | res_pool->free_count = 0; |
| 434 | mc_bus->irq_resources = NULL; |
| 435 | fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); |
| 436 | } |
| 437 | EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool); |
| 438 | |
Lee Jones | 07fbbf2 | 2021-06-17 12:04:58 +0100 | [diff] [blame] | 439 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 440 | * Allocate the IRQs required by a given fsl-mc device. |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 441 | */ |
| 442 | int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev) |
| 443 | { |
| 444 | int i; |
| 445 | int irq_count; |
| 446 | int res_allocated_count = 0; |
| 447 | int error = -EINVAL; |
| 448 | struct fsl_mc_device_irq **irqs = NULL; |
| 449 | struct fsl_mc_bus *mc_bus; |
| 450 | struct fsl_mc_resource_pool *res_pool; |
| 451 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 452 | if (mc_dev->irqs) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 453 | return -EINVAL; |
| 454 | |
| 455 | irq_count = mc_dev->obj_desc.irq_count; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 456 | if (irq_count == 0) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 457 | return -EINVAL; |
| 458 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 459 | if (is_fsl_mc_bus_dprc(mc_dev)) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 460 | mc_bus = to_fsl_mc_bus(mc_dev); |
| 461 | else |
| 462 | mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); |
| 463 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 464 | if (!mc_bus->irq_resources) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 465 | return -EINVAL; |
| 466 | |
| 467 | res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; |
| 468 | if (res_pool->free_count < irq_count) { |
| 469 | dev_err(&mc_dev->dev, |
| 470 | "Not able to allocate %u irqs for device\n", irq_count); |
| 471 | return -ENOSPC; |
| 472 | } |
| 473 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 474 | irqs = devm_kcalloc(&mc_dev->dev, irq_count, sizeof(irqs[0]), |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 475 | GFP_KERNEL); |
| 476 | if (!irqs) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | for (i = 0; i < irq_count; i++) { |
| 480 | struct fsl_mc_resource *resource; |
| 481 | |
| 482 | error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_IRQ, |
| 483 | &resource); |
| 484 | if (error < 0) |
| 485 | goto error_resource_alloc; |
| 486 | |
| 487 | irqs[i] = to_fsl_mc_irq(resource); |
| 488 | res_allocated_count++; |
| 489 | |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 490 | irqs[i]->mc_dev = mc_dev; |
| 491 | irqs[i]->dev_irq_index = i; |
| 492 | } |
| 493 | |
| 494 | mc_dev->irqs = irqs; |
| 495 | return 0; |
| 496 | |
| 497 | error_resource_alloc: |
| 498 | for (i = 0; i < res_allocated_count; i++) { |
| 499 | irqs[i]->mc_dev = NULL; |
| 500 | fsl_mc_resource_free(&irqs[i]->resource); |
| 501 | } |
| 502 | |
| 503 | return error; |
| 504 | } |
| 505 | EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs); |
| 506 | |
| 507 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 508 | * Frees the IRQs that were allocated for an fsl-mc device. |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 509 | */ |
| 510 | void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev) |
| 511 | { |
| 512 | int i; |
| 513 | int irq_count; |
| 514 | struct fsl_mc_bus *mc_bus; |
| 515 | struct fsl_mc_device_irq **irqs = mc_dev->irqs; |
| 516 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 517 | if (!irqs) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 518 | return; |
| 519 | |
| 520 | irq_count = mc_dev->obj_desc.irq_count; |
| 521 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 522 | if (is_fsl_mc_bus_dprc(mc_dev)) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 523 | mc_bus = to_fsl_mc_bus(mc_dev); |
| 524 | else |
| 525 | mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); |
| 526 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 527 | if (!mc_bus->irq_resources) |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 528 | return; |
| 529 | |
| 530 | for (i = 0; i < irq_count; i++) { |
J. German Rivera | 89f067df | 2016-01-06 16:03:23 -0600 | [diff] [blame] | 531 | irqs[i]->mc_dev = NULL; |
| 532 | fsl_mc_resource_free(&irqs[i]->resource); |
| 533 | } |
| 534 | |
| 535 | mc_dev->irqs = NULL; |
| 536 | } |
| 537 | EXPORT_SYMBOL_GPL(fsl_mc_free_irqs); |
| 538 | |
Stuart Yoder | 3640695 | 2016-08-23 17:13:24 -0500 | [diff] [blame] | 539 | void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev) |
| 540 | { |
| 541 | int pool_type; |
| 542 | struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 543 | |
| 544 | for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) { |
| 545 | struct fsl_mc_resource_pool *res_pool = |
| 546 | &mc_bus->resource_pools[pool_type]; |
| 547 | |
| 548 | res_pool->type = pool_type; |
| 549 | res_pool->max_count = 0; |
| 550 | res_pool->free_count = 0; |
| 551 | res_pool->mc_bus = mc_bus; |
| 552 | INIT_LIST_HEAD(&res_pool->free_list); |
| 553 | mutex_init(&res_pool->mutex); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | static void fsl_mc_cleanup_resource_pool(struct fsl_mc_device *mc_bus_dev, |
| 558 | enum fsl_mc_pool_type pool_type) |
| 559 | { |
| 560 | struct fsl_mc_resource *resource; |
| 561 | struct fsl_mc_resource *next; |
| 562 | struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 563 | struct fsl_mc_resource_pool *res_pool = |
| 564 | &mc_bus->resource_pools[pool_type]; |
| 565 | int free_count = 0; |
| 566 | |
Stuart Yoder | 3640695 | 2016-08-23 17:13:24 -0500 | [diff] [blame] | 567 | list_for_each_entry_safe(resource, next, &res_pool->free_list, node) { |
| 568 | free_count++; |
Stuart Yoder | 3640695 | 2016-08-23 17:13:24 -0500 | [diff] [blame] | 569 | devm_kfree(&mc_bus_dev->dev, resource); |
| 570 | } |
Stuart Yoder | 3640695 | 2016-08-23 17:13:24 -0500 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev) |
| 574 | { |
| 575 | int pool_type; |
| 576 | |
| 577 | for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) |
| 578 | fsl_mc_cleanup_resource_pool(mc_bus_dev, pool_type); |
| 579 | } |
| 580 | |
Lee Jones | 07fbbf2 | 2021-06-17 12:04:58 +0100 | [diff] [blame] | 581 | /* |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 582 | * fsl_mc_allocator_probe - callback invoked when an allocatable device is |
| 583 | * being added to the system |
| 584 | */ |
| 585 | static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) |
| 586 | { |
| 587 | enum fsl_mc_pool_type pool_type; |
| 588 | struct fsl_mc_device *mc_bus_dev; |
| 589 | struct fsl_mc_bus *mc_bus; |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 590 | int error; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 591 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 592 | if (!fsl_mc_is_allocatable(mc_dev)) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 593 | return -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 594 | |
| 595 | mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 596 | if (!dev_is_fsl_mc(&mc_bus_dev->dev)) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 597 | return -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 598 | |
| 599 | mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 600 | error = object_type_to_pool_type(mc_dev->obj_desc.type, &pool_type); |
| 601 | if (error < 0) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 602 | return error; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 603 | |
| 604 | error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev); |
| 605 | if (error < 0) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 606 | return error; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 607 | |
J. German Rivera | 6998d6b | 2015-10-17 11:18:16 -0500 | [diff] [blame] | 608 | dev_dbg(&mc_dev->dev, |
Stuart Yoder | e3494af | 2016-10-26 11:20:31 -0500 | [diff] [blame] | 609 | "Allocatable fsl-mc device bound to fsl_mc_allocator driver"); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 610 | return 0; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 611 | } |
| 612 | |
Lee Jones | 07fbbf2 | 2021-06-17 12:04:58 +0100 | [diff] [blame] | 613 | /* |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 614 | * fsl_mc_allocator_remove - callback invoked when an allocatable device is |
| 615 | * being removed from the system |
| 616 | */ |
| 617 | static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev) |
| 618 | { |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 619 | int error; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 620 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 621 | if (!fsl_mc_is_allocatable(mc_dev)) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 622 | return -EINVAL; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 623 | |
J. German Rivera | 6958cd4 | 2015-10-17 11:18:20 -0500 | [diff] [blame] | 624 | if (mc_dev->resource) { |
| 625 | error = fsl_mc_resource_pool_remove_device(mc_dev); |
| 626 | if (error < 0) |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 627 | return error; |
J. German Rivera | 6958cd4 | 2015-10-17 11:18:20 -0500 | [diff] [blame] | 628 | } |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 629 | |
J. German Rivera | 6998d6b | 2015-10-17 11:18:16 -0500 | [diff] [blame] | 630 | dev_dbg(&mc_dev->dev, |
Stuart Yoder | e3494af | 2016-10-26 11:20:31 -0500 | [diff] [blame] | 631 | "Allocatable fsl-mc device unbound from fsl_mc_allocator driver"); |
J. German Rivera | 09a38ab | 2015-10-17 11:18:21 -0500 | [diff] [blame] | 632 | return 0; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 633 | } |
| 634 | |
Stuart Yoder | 57538af | 2016-06-22 16:40:44 -0500 | [diff] [blame] | 635 | static const struct fsl_mc_device_id match_id_table[] = { |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 636 | { |
| 637 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 638 | .obj_type = "dpbp", |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 639 | }, |
| 640 | { |
| 641 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 642 | .obj_type = "dpmcp", |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 643 | }, |
| 644 | { |
| 645 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 646 | .obj_type = "dpcon", |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 647 | }, |
| 648 | {.vendor = 0x0}, |
| 649 | }; |
| 650 | |
| 651 | static struct fsl_mc_driver fsl_mc_allocator_driver = { |
| 652 | .driver = { |
| 653 | .name = "fsl_mc_allocator", |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 654 | .pm = NULL, |
| 655 | }, |
| 656 | .match_id_table = match_id_table, |
| 657 | .probe = fsl_mc_allocator_probe, |
| 658 | .remove = fsl_mc_allocator_remove, |
| 659 | }; |
| 660 | |
J. German Rivera | e91ffa9 | 2015-03-27 16:01:08 -0500 | [diff] [blame] | 661 | int __init fsl_mc_allocator_driver_init(void) |
| 662 | { |
| 663 | return fsl_mc_driver_register(&fsl_mc_allocator_driver); |
| 664 | } |
Ioana Ciornei | 1e8ac83 | 2018-03-15 12:05:33 -0500 | [diff] [blame] | 665 | |
| 666 | void fsl_mc_allocator_driver_exit(void) |
| 667 | { |
| 668 | fsl_mc_driver_unregister(&fsl_mc_allocator_driver); |
| 669 | } |