Bogdan Purcareata | 203e2de | 2018-01-17 18:36:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Freescale Management Complex (MC) bus driver |
| 4 | * |
Stuart Yoder | 6466dac | 2016-10-26 11:20:33 -0500 | [diff] [blame] | 5 | * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. |
Bharat Bhushan | 1f86a00 | 2020-09-29 11:54:31 +0300 | [diff] [blame] | 6 | * Copyright 2019-2020 NXP |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 7 | * Author: German Rivera <German.Rivera@freescale.com> |
| 8 | * |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 9 | */ |
| 10 | |
Stuart Yoder | a673783 | 2016-10-26 11:20:29 -0500 | [diff] [blame] | 11 | #define pr_fmt(fmt) "fsl-mc: " fmt |
| 12 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/of_device.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/limits.h> |
J. German Rivera | 660a24b | 2016-01-06 16:03:29 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
| 20 | #include <linux/msi.h> |
Stuart Yoder | 5143ecf | 2016-08-23 17:14:18 -0500 | [diff] [blame] | 21 | #include <linux/dma-mapping.h> |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 22 | #include <linux/acpi.h> |
| 23 | #include <linux/iommu.h> |
Stuart Yoder | d4e7513 | 2016-08-23 17:14:23 -0500 | [diff] [blame] | 24 | |
Stuart Yoder | 243444f | 2016-08-23 17:13:30 -0500 | [diff] [blame] | 25 | #include "fsl-mc-private.h" |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 26 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 27 | /* |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 28 | * Default DMA mask for devices on a fsl-mc bus |
| 29 | */ |
| 30 | #define FSL_MC_DEFAULT_DMA_MASK (~0ULL) |
| 31 | |
Andrei Botila | 0544cb7 | 2020-03-19 09:12:31 -0700 | [diff] [blame] | 32 | static struct fsl_mc_version mc_version; |
| 33 | |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 34 | /** |
| 35 | * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 36 | * @root_mc_bus_dev: fsl-mc device representing the root DPRC |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 37 | * @num_translation_ranges: number of entries in addr_translation_ranges |
| 38 | * @translation_ranges: array of bus to system address translation ranges |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 39 | * @fsl_mc_regs: base address of register bank |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 40 | */ |
| 41 | struct fsl_mc { |
| 42 | struct fsl_mc_device *root_mc_bus_dev; |
| 43 | u8 num_translation_ranges; |
| 44 | struct fsl_mc_addr_translation_range *translation_ranges; |
Laurentiu Tudor | 59b26d2 | 2020-12-16 18:10:15 +0200 | [diff] [blame] | 45 | void __iomem *fsl_mc_regs; |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct fsl_mc_addr_translation_range - bus to system address translation |
| 50 | * range |
| 51 | * @mc_region_type: Type of MC region for the range being translated |
| 52 | * @start_mc_offset: Start MC offset of the range being translated |
| 53 | * @end_mc_offset: MC offset of the first byte after the range (last MC |
| 54 | * offset of the range is end_mc_offset - 1) |
| 55 | * @start_phys_addr: system physical address corresponding to start_mc_addr |
| 56 | */ |
| 57 | struct fsl_mc_addr_translation_range { |
| 58 | enum dprc_region_type mc_region_type; |
| 59 | u64 start_mc_offset; |
| 60 | u64 end_mc_offset; |
| 61 | phys_addr_t start_phys_addr; |
| 62 | }; |
| 63 | |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 64 | #define FSL_MC_GCR1 0x0 |
| 65 | #define GCR1_P1_STOP BIT(31) |
Laurentiu Tudor | c40cbad | 2021-07-15 17:07:13 +0300 | [diff] [blame] | 66 | #define GCR1_P2_STOP BIT(30) |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 67 | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 68 | #define FSL_MC_FAPR 0x28 |
| 69 | #define MC_FAPR_PL BIT(18) |
| 70 | #define MC_FAPR_BMT BIT(17) |
| 71 | |
Laurentiu Tudor | 8990f96 | 2021-07-15 17:07:18 +0300 | [diff] [blame] | 72 | static phys_addr_t mc_portal_base_phys_addr; |
| 73 | |
Stuart Yoder | e730d86 | 2016-08-23 17:13:40 -0500 | [diff] [blame] | 74 | /** |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 75 | * fsl_mc_bus_match - device to driver matching callback |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 76 | * @dev: the fsl-mc device to match against |
| 77 | * @drv: the device driver to search for matching fsl-mc object type |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 78 | * structures |
| 79 | * |
| 80 | * Returns 1 on success, 0 otherwise. |
| 81 | */ |
| 82 | static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) |
| 83 | { |
Stuart Yoder | 57538af | 2016-06-22 16:40:44 -0500 | [diff] [blame] | 84 | const struct fsl_mc_device_id *id; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 85 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 86 | struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); |
| 87 | bool found = false; |
| 88 | |
Bharat Bhushan | 1f86a00 | 2020-09-29 11:54:31 +0300 | [diff] [blame] | 89 | /* When driver_override is set, only bind to the matching driver */ |
| 90 | if (mc_dev->driver_override) { |
| 91 | found = !strcmp(mc_dev->driver_override, mc_drv->driver.name); |
| 92 | goto out; |
| 93 | } |
| 94 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 95 | if (!mc_drv->match_id_table) |
| 96 | goto out; |
| 97 | |
| 98 | /* |
| 99 | * If the object is not 'plugged' don't match. |
| 100 | * Only exception is the root DPRC, which is a special case. |
| 101 | */ |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 102 | if ((mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED) == 0 && |
Itai Katz | b55f00c | 2015-10-04 10:09:51 +0300 | [diff] [blame] | 103 | !fsl_mc_is_root_dprc(&mc_dev->dev)) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 104 | goto out; |
| 105 | |
| 106 | /* |
| 107 | * Traverse the match_id table of the given driver, trying to find |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 108 | * a matching for the given device. |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 109 | */ |
| 110 | for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) { |
| 111 | if (id->vendor == mc_dev->obj_desc.vendor && |
J. German Rivera | 3b0a9b1 | 2015-03-27 16:01:09 -0500 | [diff] [blame] | 112 | strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) { |
Itai Katz | 9787d4e | 2016-04-11 11:55:40 -0500 | [diff] [blame] | 113 | found = true; |
J. German Rivera | 3b0a9b1 | 2015-03-27 16:01:09 -0500 | [diff] [blame] | 114 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | out: |
| 120 | dev_dbg(dev, "%smatched\n", found ? "" : "not "); |
| 121 | return found; |
| 122 | } |
| 123 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 124 | /* |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 125 | * fsl_mc_bus_uevent - callback invoked when a device is added |
| 126 | */ |
| 127 | static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 128 | { |
Stuart Yoder | d568b76 | 2016-06-22 16:40:43 -0500 | [diff] [blame] | 129 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 130 | |
| 131 | if (add_uevent_var(env, "MODALIAS=fsl-mc:v%08Xd%s", |
| 132 | mc_dev->obj_desc.vendor, |
| 133 | mc_dev->obj_desc.type)) |
| 134 | return -ENOMEM; |
| 135 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
Nipun Gupta | a259ed1 | 2018-09-10 19:19:19 +0530 | [diff] [blame] | 139 | static int fsl_mc_dma_configure(struct device *dev) |
| 140 | { |
| 141 | struct device *dma_dev = dev; |
Lorenzo Pieralisi | a081bd4 | 2020-06-19 09:20:08 +0100 | [diff] [blame] | 142 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 143 | u32 input_id = mc_dev->icid; |
Nipun Gupta | a259ed1 | 2018-09-10 19:19:19 +0530 | [diff] [blame] | 144 | |
| 145 | while (dev_is_fsl_mc(dma_dev)) |
| 146 | dma_dev = dma_dev->parent; |
| 147 | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 148 | if (dev_of_node(dma_dev)) |
| 149 | return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id); |
| 150 | |
| 151 | return acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id); |
Nipun Gupta | a259ed1 | 2018-09-10 19:19:19 +0530 | [diff] [blame] | 152 | } |
| 153 | |
Stuart Yoder | 3d579c3 | 2016-06-22 16:40:42 -0500 | [diff] [blame] | 154 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 155 | char *buf) |
| 156 | { |
| 157 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 158 | |
| 159 | return sprintf(buf, "fsl-mc:v%08Xd%s\n", mc_dev->obj_desc.vendor, |
| 160 | mc_dev->obj_desc.type); |
| 161 | } |
| 162 | static DEVICE_ATTR_RO(modalias); |
| 163 | |
Bharat Bhushan | 1f86a00 | 2020-09-29 11:54:31 +0300 | [diff] [blame] | 164 | static ssize_t driver_override_store(struct device *dev, |
| 165 | struct device_attribute *attr, |
| 166 | const char *buf, size_t count) |
| 167 | { |
| 168 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 169 | char *driver_override, *old = mc_dev->driver_override; |
| 170 | char *cp; |
| 171 | |
| 172 | if (WARN_ON(dev->bus != &fsl_mc_bus_type)) |
| 173 | return -EINVAL; |
| 174 | |
| 175 | if (count >= (PAGE_SIZE - 1)) |
| 176 | return -EINVAL; |
| 177 | |
| 178 | driver_override = kstrndup(buf, count, GFP_KERNEL); |
| 179 | if (!driver_override) |
| 180 | return -ENOMEM; |
| 181 | |
| 182 | cp = strchr(driver_override, '\n'); |
| 183 | if (cp) |
| 184 | *cp = '\0'; |
| 185 | |
| 186 | if (strlen(driver_override)) { |
| 187 | mc_dev->driver_override = driver_override; |
| 188 | } else { |
| 189 | kfree(driver_override); |
| 190 | mc_dev->driver_override = NULL; |
| 191 | } |
| 192 | |
| 193 | kfree(old); |
| 194 | |
| 195 | return count; |
| 196 | } |
| 197 | |
| 198 | static ssize_t driver_override_show(struct device *dev, |
| 199 | struct device_attribute *attr, char *buf) |
| 200 | { |
| 201 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 202 | |
| 203 | return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override); |
| 204 | } |
| 205 | static DEVICE_ATTR_RW(driver_override); |
| 206 | |
Stuart Yoder | 3d579c3 | 2016-06-22 16:40:42 -0500 | [diff] [blame] | 207 | static struct attribute *fsl_mc_dev_attrs[] = { |
| 208 | &dev_attr_modalias.attr, |
Bharat Bhushan | 1f86a00 | 2020-09-29 11:54:31 +0300 | [diff] [blame] | 209 | &dev_attr_driver_override.attr, |
Stuart Yoder | 3d579c3 | 2016-06-22 16:40:42 -0500 | [diff] [blame] | 210 | NULL, |
| 211 | }; |
| 212 | |
Wei Yongjun | a71a6d9 | 2016-08-28 16:19:29 +0000 | [diff] [blame] | 213 | ATTRIBUTE_GROUPS(fsl_mc_dev); |
Stuart Yoder | 3d579c3 | 2016-06-22 16:40:42 -0500 | [diff] [blame] | 214 | |
Ioana Ciornei | 3f60994 | 2021-01-14 19:07:51 +0200 | [diff] [blame] | 215 | static int scan_fsl_mc_bus(struct device *dev, void *data) |
| 216 | { |
| 217 | struct fsl_mc_device *root_mc_dev; |
| 218 | struct fsl_mc_bus *root_mc_bus; |
| 219 | |
| 220 | if (!fsl_mc_is_root_dprc(dev)) |
| 221 | goto exit; |
| 222 | |
| 223 | root_mc_dev = to_fsl_mc_device(dev); |
| 224 | root_mc_bus = to_fsl_mc_bus(root_mc_dev); |
| 225 | mutex_lock(&root_mc_bus->scan_mutex); |
Laurentiu Tudor | aa0a1ae | 2021-07-15 17:07:11 +0300 | [diff] [blame] | 226 | dprc_scan_objects(root_mc_dev, false); |
Ioana Ciornei | 3f60994 | 2021-01-14 19:07:51 +0200 | [diff] [blame] | 227 | mutex_unlock(&root_mc_bus->scan_mutex); |
| 228 | |
| 229 | exit: |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static ssize_t rescan_store(struct bus_type *bus, |
| 234 | const char *buf, size_t count) |
| 235 | { |
| 236 | unsigned long val; |
| 237 | |
| 238 | if (kstrtoul(buf, 0, &val) < 0) |
| 239 | return -EINVAL; |
| 240 | |
| 241 | if (val) |
| 242 | bus_for_each_dev(bus, NULL, NULL, scan_fsl_mc_bus); |
| 243 | |
| 244 | return count; |
| 245 | } |
| 246 | static BUS_ATTR_WO(rescan); |
| 247 | |
Ioana Ciornei | 296c626 | 2021-01-14 19:07:52 +0200 | [diff] [blame] | 248 | static int fsl_mc_bus_set_autorescan(struct device *dev, void *data) |
| 249 | { |
| 250 | struct fsl_mc_device *root_mc_dev; |
| 251 | unsigned long val; |
| 252 | char *buf = data; |
| 253 | |
| 254 | if (!fsl_mc_is_root_dprc(dev)) |
| 255 | goto exit; |
| 256 | |
| 257 | root_mc_dev = to_fsl_mc_device(dev); |
| 258 | |
| 259 | if (kstrtoul(buf, 0, &val) < 0) |
| 260 | return -EINVAL; |
| 261 | |
| 262 | if (val) |
| 263 | enable_dprc_irq(root_mc_dev); |
| 264 | else |
| 265 | disable_dprc_irq(root_mc_dev); |
| 266 | |
| 267 | exit: |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int fsl_mc_bus_get_autorescan(struct device *dev, void *data) |
| 272 | { |
| 273 | struct fsl_mc_device *root_mc_dev; |
| 274 | char *buf = data; |
| 275 | |
| 276 | if (!fsl_mc_is_root_dprc(dev)) |
| 277 | goto exit; |
| 278 | |
| 279 | root_mc_dev = to_fsl_mc_device(dev); |
| 280 | |
| 281 | sprintf(buf, "%d\n", get_dprc_irq_state(root_mc_dev)); |
| 282 | exit: |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static ssize_t autorescan_store(struct bus_type *bus, |
| 287 | const char *buf, size_t count) |
| 288 | { |
| 289 | bus_for_each_dev(bus, NULL, (void *)buf, fsl_mc_bus_set_autorescan); |
| 290 | |
| 291 | return count; |
| 292 | } |
| 293 | |
| 294 | static ssize_t autorescan_show(struct bus_type *bus, char *buf) |
| 295 | { |
| 296 | bus_for_each_dev(bus, NULL, (void *)buf, fsl_mc_bus_get_autorescan); |
| 297 | return strlen(buf); |
| 298 | } |
| 299 | |
| 300 | static BUS_ATTR_RW(autorescan); |
| 301 | |
Ioana Ciornei | 3f60994 | 2021-01-14 19:07:51 +0200 | [diff] [blame] | 302 | static struct attribute *fsl_mc_bus_attrs[] = { |
| 303 | &bus_attr_rescan.attr, |
Ioana Ciornei | 296c626 | 2021-01-14 19:07:52 +0200 | [diff] [blame] | 304 | &bus_attr_autorescan.attr, |
Ioana Ciornei | 3f60994 | 2021-01-14 19:07:51 +0200 | [diff] [blame] | 305 | NULL, |
| 306 | }; |
| 307 | |
| 308 | ATTRIBUTE_GROUPS(fsl_mc_bus); |
| 309 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 310 | struct bus_type fsl_mc_bus_type = { |
| 311 | .name = "fsl-mc", |
| 312 | .match = fsl_mc_bus_match, |
| 313 | .uevent = fsl_mc_bus_uevent, |
Nipun Gupta | a259ed1 | 2018-09-10 19:19:19 +0530 | [diff] [blame] | 314 | .dma_configure = fsl_mc_dma_configure, |
Stuart Yoder | 3d579c3 | 2016-06-22 16:40:42 -0500 | [diff] [blame] | 315 | .dev_groups = fsl_mc_dev_groups, |
Ioana Ciornei | 3f60994 | 2021-01-14 19:07:51 +0200 | [diff] [blame] | 316 | .bus_groups = fsl_mc_bus_groups, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 317 | }; |
| 318 | EXPORT_SYMBOL_GPL(fsl_mc_bus_type); |
| 319 | |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 320 | struct device_type fsl_mc_bus_dprc_type = { |
| 321 | .name = "fsl_mc_bus_dprc" |
| 322 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 323 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dprc_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 324 | |
| 325 | struct device_type fsl_mc_bus_dpni_type = { |
| 326 | .name = "fsl_mc_bus_dpni" |
| 327 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 328 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpni_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 329 | |
| 330 | struct device_type fsl_mc_bus_dpio_type = { |
| 331 | .name = "fsl_mc_bus_dpio" |
| 332 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 333 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpio_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 334 | |
| 335 | struct device_type fsl_mc_bus_dpsw_type = { |
| 336 | .name = "fsl_mc_bus_dpsw" |
| 337 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 338 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpsw_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 339 | |
| 340 | struct device_type fsl_mc_bus_dpbp_type = { |
| 341 | .name = "fsl_mc_bus_dpbp" |
| 342 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 343 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpbp_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 344 | |
| 345 | struct device_type fsl_mc_bus_dpcon_type = { |
| 346 | .name = "fsl_mc_bus_dpcon" |
| 347 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 348 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpcon_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 349 | |
| 350 | struct device_type fsl_mc_bus_dpmcp_type = { |
| 351 | .name = "fsl_mc_bus_dpmcp" |
| 352 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 353 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmcp_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 354 | |
| 355 | struct device_type fsl_mc_bus_dpmac_type = { |
| 356 | .name = "fsl_mc_bus_dpmac" |
| 357 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 358 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmac_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 359 | |
| 360 | struct device_type fsl_mc_bus_dprtc_type = { |
| 361 | .name = "fsl_mc_bus_dprtc" |
| 362 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 363 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dprtc_type); |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 364 | |
Horia Geantă | e9158b3 | 2018-09-12 11:59:26 +0300 | [diff] [blame] | 365 | struct device_type fsl_mc_bus_dpseci_type = { |
| 366 | .name = "fsl_mc_bus_dpseci" |
| 367 | }; |
Ioana Ciornei | 6fff8c0 | 2019-10-31 01:18:28 +0200 | [diff] [blame] | 368 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpseci_type); |
Horia Geantă | e9158b3 | 2018-09-12 11:59:26 +0300 | [diff] [blame] | 369 | |
Ioana Ciornei | a3b7a58 | 2020-07-17 18:47:58 +0300 | [diff] [blame] | 370 | struct device_type fsl_mc_bus_dpdmux_type = { |
| 371 | .name = "fsl_mc_bus_dpdmux" |
| 372 | }; |
| 373 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmux_type); |
| 374 | |
| 375 | struct device_type fsl_mc_bus_dpdcei_type = { |
| 376 | .name = "fsl_mc_bus_dpdcei" |
| 377 | }; |
| 378 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdcei_type); |
| 379 | |
| 380 | struct device_type fsl_mc_bus_dpaiop_type = { |
| 381 | .name = "fsl_mc_bus_dpaiop" |
| 382 | }; |
| 383 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpaiop_type); |
| 384 | |
| 385 | struct device_type fsl_mc_bus_dpci_type = { |
| 386 | .name = "fsl_mc_bus_dpci" |
| 387 | }; |
| 388 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpci_type); |
| 389 | |
| 390 | struct device_type fsl_mc_bus_dpdmai_type = { |
| 391 | .name = "fsl_mc_bus_dpdmai" |
| 392 | }; |
| 393 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmai_type); |
| 394 | |
Ioana Ciornei | e70ba1b | 2021-02-08 19:09:48 +0200 | [diff] [blame] | 395 | struct device_type fsl_mc_bus_dpdbg_type = { |
| 396 | .name = "fsl_mc_bus_dpdbg" |
| 397 | }; |
| 398 | EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdbg_type); |
| 399 | |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 400 | static struct device_type *fsl_mc_get_device_type(const char *type) |
| 401 | { |
| 402 | static const struct { |
| 403 | struct device_type *dev_type; |
| 404 | const char *type; |
| 405 | } dev_types[] = { |
| 406 | { &fsl_mc_bus_dprc_type, "dprc" }, |
| 407 | { &fsl_mc_bus_dpni_type, "dpni" }, |
| 408 | { &fsl_mc_bus_dpio_type, "dpio" }, |
| 409 | { &fsl_mc_bus_dpsw_type, "dpsw" }, |
| 410 | { &fsl_mc_bus_dpbp_type, "dpbp" }, |
| 411 | { &fsl_mc_bus_dpcon_type, "dpcon" }, |
| 412 | { &fsl_mc_bus_dpmcp_type, "dpmcp" }, |
| 413 | { &fsl_mc_bus_dpmac_type, "dpmac" }, |
| 414 | { &fsl_mc_bus_dprtc_type, "dprtc" }, |
Horia Geantă | e9158b3 | 2018-09-12 11:59:26 +0300 | [diff] [blame] | 415 | { &fsl_mc_bus_dpseci_type, "dpseci" }, |
Ioana Ciornei | a3b7a58 | 2020-07-17 18:47:58 +0300 | [diff] [blame] | 416 | { &fsl_mc_bus_dpdmux_type, "dpdmux" }, |
| 417 | { &fsl_mc_bus_dpdcei_type, "dpdcei" }, |
| 418 | { &fsl_mc_bus_dpaiop_type, "dpaiop" }, |
| 419 | { &fsl_mc_bus_dpci_type, "dpci" }, |
| 420 | { &fsl_mc_bus_dpdmai_type, "dpdmai" }, |
Ioana Ciornei | e70ba1b | 2021-02-08 19:09:48 +0200 | [diff] [blame] | 421 | { &fsl_mc_bus_dpdbg_type, "dpdbg" }, |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 422 | { NULL, NULL } |
| 423 | }; |
| 424 | int i; |
| 425 | |
| 426 | for (i = 0; dev_types[i].dev_type; i++) |
| 427 | if (!strcmp(dev_types[i].type, type)) |
| 428 | return dev_types[i].dev_type; |
| 429 | |
| 430 | return NULL; |
| 431 | } |
| 432 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 433 | static int fsl_mc_driver_probe(struct device *dev) |
| 434 | { |
| 435 | struct fsl_mc_driver *mc_drv; |
| 436 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 437 | int error; |
| 438 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 439 | mc_drv = to_fsl_mc_driver(dev->driver); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 440 | |
| 441 | error = mc_drv->probe(mc_dev); |
| 442 | if (error < 0) { |
Nipun Gupta | 9c70dbd | 2017-12-11 21:15:38 +0530 | [diff] [blame] | 443 | if (error != -EPROBE_DEFER) |
| 444 | dev_err(dev, "%s failed: %d\n", __func__, error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 445 | return error; |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int fsl_mc_driver_remove(struct device *dev) |
| 452 | { |
| 453 | struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); |
| 454 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 455 | int error; |
| 456 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 457 | error = mc_drv->remove(mc_dev); |
| 458 | if (error < 0) { |
Stuart Yoder | 66fcc74 | 2016-10-26 11:20:30 -0500 | [diff] [blame] | 459 | dev_err(dev, "%s failed: %d\n", __func__, error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 460 | return error; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static void fsl_mc_driver_shutdown(struct device *dev) |
| 467 | { |
| 468 | struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); |
| 469 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
| 470 | |
| 471 | mc_drv->shutdown(mc_dev); |
| 472 | } |
| 473 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 474 | /* |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 475 | * __fsl_mc_driver_register - registers a child device driver with the |
| 476 | * MC bus |
| 477 | * |
| 478 | * This function is implicitly invoked from the registration function of |
| 479 | * fsl_mc device drivers, which is generated by the |
| 480 | * module_fsl_mc_driver() macro. |
| 481 | */ |
| 482 | int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver, |
| 483 | struct module *owner) |
| 484 | { |
| 485 | int error; |
| 486 | |
| 487 | mc_driver->driver.owner = owner; |
| 488 | mc_driver->driver.bus = &fsl_mc_bus_type; |
| 489 | |
| 490 | if (mc_driver->probe) |
| 491 | mc_driver->driver.probe = fsl_mc_driver_probe; |
| 492 | |
| 493 | if (mc_driver->remove) |
| 494 | mc_driver->driver.remove = fsl_mc_driver_remove; |
| 495 | |
| 496 | if (mc_driver->shutdown) |
| 497 | mc_driver->driver.shutdown = fsl_mc_driver_shutdown; |
| 498 | |
| 499 | error = driver_register(&mc_driver->driver); |
| 500 | if (error < 0) { |
| 501 | pr_err("driver_register() failed for %s: %d\n", |
| 502 | mc_driver->driver.name, error); |
| 503 | return error; |
| 504 | } |
| 505 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | EXPORT_SYMBOL_GPL(__fsl_mc_driver_register); |
| 509 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 510 | /* |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 511 | * fsl_mc_driver_unregister - unregisters a device driver from the |
| 512 | * MC bus |
| 513 | */ |
| 514 | void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver) |
| 515 | { |
| 516 | driver_unregister(&mc_driver->driver); |
| 517 | } |
| 518 | EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); |
| 519 | |
Itai Katz | 14f9280 | 2015-10-04 10:09:50 +0300 | [diff] [blame] | 520 | /** |
Laurentiu Tudor | 3ea73a4 | 2017-06-27 17:41:31 +0300 | [diff] [blame] | 521 | * mc_get_version() - Retrieves the Management Complex firmware |
| 522 | * version information |
| 523 | * @mc_io: Pointer to opaque I/O object |
| 524 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 525 | * @mc_ver_info: Returned version information structure |
| 526 | * |
| 527 | * Return: '0' on Success; Error code otherwise. |
| 528 | */ |
| 529 | static int mc_get_version(struct fsl_mc_io *mc_io, |
| 530 | u32 cmd_flags, |
Andrei Botila | 0544cb7 | 2020-03-19 09:12:31 -0700 | [diff] [blame] | 531 | struct fsl_mc_version *mc_ver_info) |
Laurentiu Tudor | 3ea73a4 | 2017-06-27 17:41:31 +0300 | [diff] [blame] | 532 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 533 | struct fsl_mc_command cmd = { 0 }; |
Laurentiu Tudor | 3ea73a4 | 2017-06-27 17:41:31 +0300 | [diff] [blame] | 534 | struct dpmng_rsp_get_version *rsp_params; |
| 535 | int err; |
| 536 | |
| 537 | /* prepare command */ |
| 538 | cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION, |
| 539 | cmd_flags, |
| 540 | 0); |
| 541 | |
| 542 | /* send command to mc*/ |
| 543 | err = mc_send_command(mc_io, &cmd); |
| 544 | if (err) |
| 545 | return err; |
| 546 | |
| 547 | /* retrieve response parameters */ |
| 548 | rsp_params = (struct dpmng_rsp_get_version *)cmd.params; |
| 549 | mc_ver_info->revision = le32_to_cpu(rsp_params->revision); |
| 550 | mc_ver_info->major = le32_to_cpu(rsp_params->version_major); |
| 551 | mc_ver_info->minor = le32_to_cpu(rsp_params->version_minor); |
| 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | /** |
Andrei Botila | 0544cb7 | 2020-03-19 09:12:31 -0700 | [diff] [blame] | 557 | * fsl_mc_get_version - function to retrieve the MC f/w version information |
| 558 | * |
| 559 | * Return: mc version when called after fsl-mc-bus probe; NULL otherwise. |
| 560 | */ |
| 561 | struct fsl_mc_version *fsl_mc_get_version(void) |
| 562 | { |
| 563 | if (mc_version.major) |
| 564 | return &mc_version; |
| 565 | |
| 566 | return NULL; |
| 567 | } |
| 568 | EXPORT_SYMBOL_GPL(fsl_mc_get_version); |
| 569 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 570 | /* |
Ramiro Oliveira | f86a180 | 2016-09-30 15:01:21 +0100 | [diff] [blame] | 571 | * fsl_mc_get_root_dprc - function to traverse to the root dprc |
| 572 | */ |
Diana Craciun | 998fb7b | 2020-06-19 09:20:12 +0100 | [diff] [blame] | 573 | void fsl_mc_get_root_dprc(struct device *dev, |
| 574 | struct device **root_dprc_dev) |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 575 | { |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 576 | if (!dev) { |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 577 | *root_dprc_dev = NULL; |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 578 | } else if (!dev_is_fsl_mc(dev)) { |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 579 | *root_dprc_dev = NULL; |
| 580 | } else { |
| 581 | *root_dprc_dev = dev; |
Nipun Gupta | df5e9b5 | 2016-06-29 22:44:39 +0530 | [diff] [blame] | 582 | while (dev_is_fsl_mc((*root_dprc_dev)->parent)) |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 583 | *root_dprc_dev = (*root_dprc_dev)->parent; |
| 584 | } |
| 585 | } |
| 586 | |
Itai Katz | 9529d16 | 2016-04-11 11:55:55 -0500 | [diff] [blame] | 587 | static int get_dprc_attr(struct fsl_mc_io *mc_io, |
| 588 | int container_id, struct dprc_attributes *attr) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 589 | { |
Nayeemahmed Badebade | a2f9ff6 | 2015-09-04 22:30:33 +0530 | [diff] [blame] | 590 | u16 dprc_handle; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 591 | int error; |
| 592 | |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 593 | error = dprc_open(mc_io, 0, container_id, &dprc_handle); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 594 | if (error < 0) { |
Cihangir Akturk | 2e11590 | 2016-03-14 18:14:07 +0200 | [diff] [blame] | 595 | dev_err(mc_io->dev, "dprc_open() failed: %d\n", error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 596 | return error; |
| 597 | } |
| 598 | |
Itai Katz | 9529d16 | 2016-04-11 11:55:55 -0500 | [diff] [blame] | 599 | memset(attr, 0, sizeof(struct dprc_attributes)); |
| 600 | error = dprc_get_attributes(mc_io, 0, dprc_handle, attr); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 601 | if (error < 0) { |
Cihangir Akturk | 2e11590 | 2016-03-14 18:14:07 +0200 | [diff] [blame] | 602 | dev_err(mc_io->dev, "dprc_get_attributes() failed: %d\n", |
Bhumika Goyal | 454b0ec | 2016-03-04 19:15:55 +0530 | [diff] [blame] | 603 | error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 604 | goto common_cleanup; |
| 605 | } |
| 606 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 607 | error = 0; |
| 608 | |
| 609 | common_cleanup: |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 610 | (void)dprc_close(mc_io, 0, dprc_handle); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 611 | return error; |
| 612 | } |
| 613 | |
Itai Katz | 9529d16 | 2016-04-11 11:55:55 -0500 | [diff] [blame] | 614 | static int get_dprc_icid(struct fsl_mc_io *mc_io, |
Bharat Bhushan | 273ee53d | 2020-09-29 11:54:40 +0300 | [diff] [blame] | 615 | int container_id, u32 *icid) |
Itai Katz | 9529d16 | 2016-04-11 11:55:55 -0500 | [diff] [blame] | 616 | { |
| 617 | struct dprc_attributes attr; |
| 618 | int error; |
| 619 | |
| 620 | error = get_dprc_attr(mc_io, container_id, &attr); |
| 621 | if (error == 0) |
| 622 | *icid = attr.icid; |
| 623 | |
| 624 | return error; |
| 625 | } |
| 626 | |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 627 | static int translate_mc_addr(struct fsl_mc_device *mc_dev, |
| 628 | enum dprc_region_type mc_region_type, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 629 | u64 mc_offset, phys_addr_t *phys_addr) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 630 | { |
| 631 | int i; |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 632 | struct device *root_dprc_dev; |
| 633 | struct fsl_mc *mc; |
| 634 | |
| 635 | fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); |
Itai Katz | e4ea40f | 2015-10-04 10:09:52 +0300 | [diff] [blame] | 636 | mc = dev_get_drvdata(root_dprc_dev->parent); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 637 | |
| 638 | if (mc->num_translation_ranges == 0) { |
| 639 | /* |
| 640 | * Do identity mapping: |
| 641 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 642 | *phys_addr = mc_offset; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | for (i = 0; i < mc->num_translation_ranges; i++) { |
| 647 | struct fsl_mc_addr_translation_range *range = |
| 648 | &mc->translation_ranges[i]; |
| 649 | |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 650 | if (mc_region_type == range->mc_region_type && |
| 651 | mc_offset >= range->start_mc_offset && |
| 652 | mc_offset < range->end_mc_offset) { |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 653 | *phys_addr = range->start_phys_addr + |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 654 | (mc_offset - range->start_mc_offset); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 655 | return 0; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | return -EFAULT; |
| 660 | } |
| 661 | |
| 662 | static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, |
| 663 | struct fsl_mc_device *mc_bus_dev) |
| 664 | { |
| 665 | int i; |
| 666 | int error; |
| 667 | struct resource *regions; |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 668 | struct fsl_mc_obj_desc *obj_desc = &mc_dev->obj_desc; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 669 | struct device *parent_dev = mc_dev->dev.parent; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 670 | enum dprc_region_type mc_region_type; |
| 671 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 672 | if (is_fsl_mc_bus_dprc(mc_dev) || |
| 673 | is_fsl_mc_bus_dpmcp(mc_dev)) { |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 674 | mc_region_type = DPRC_REGION_TYPE_MC_PORTAL; |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 675 | } else if (is_fsl_mc_bus_dpio(mc_dev)) { |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 676 | mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL; |
| 677 | } else { |
| 678 | /* |
| 679 | * This function should not have been called for this MC object |
| 680 | * type, as this object type is not supposed to have MMIO |
| 681 | * regions |
| 682 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | } |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 685 | |
| 686 | regions = kmalloc_array(obj_desc->region_count, |
| 687 | sizeof(regions[0]), GFP_KERNEL); |
| 688 | if (!regions) |
| 689 | return -ENOMEM; |
| 690 | |
| 691 | for (i = 0; i < obj_desc->region_count; i++) { |
| 692 | struct dprc_region_desc region_desc; |
| 693 | |
| 694 | error = dprc_get_obj_region(mc_bus_dev->mc_io, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 695 | 0, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 696 | mc_bus_dev->mc_handle, |
| 697 | obj_desc->type, |
| 698 | obj_desc->id, i, ®ion_desc); |
| 699 | if (error < 0) { |
| 700 | dev_err(parent_dev, |
| 701 | "dprc_get_obj_region() failed: %d\n", error); |
| 702 | goto error_cleanup_regions; |
| 703 | } |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 704 | /* |
| 705 | * Older MC only returned region offset and no base address |
| 706 | * If base address is in the region_desc use it otherwise |
| 707 | * revert to old mechanism |
| 708 | */ |
Laurentiu Tudor | 8990f96 | 2021-07-15 17:07:18 +0300 | [diff] [blame] | 709 | if (region_desc.base_address) { |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 710 | regions[i].start = region_desc.base_address + |
| 711 | region_desc.base_offset; |
Laurentiu Tudor | 8990f96 | 2021-07-15 17:07:18 +0300 | [diff] [blame] | 712 | } else { |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 713 | error = translate_mc_addr(mc_dev, mc_region_type, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 714 | region_desc.base_offset, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 715 | ®ions[i].start); |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 716 | |
Laurentiu Tudor | 8990f96 | 2021-07-15 17:07:18 +0300 | [diff] [blame] | 717 | /* |
| 718 | * Some versions of the MC firmware wrongly report |
| 719 | * 0 for register base address of the DPMCP associated |
| 720 | * with child DPRC objects thus rendering them unusable. |
| 721 | * This is particularly troublesome in ACPI boot |
| 722 | * scenarios where the legacy way of extracting this |
| 723 | * base address from the device tree does not apply. |
| 724 | * Given that DPMCPs share the same base address, |
| 725 | * workaround this by using the base address extracted |
| 726 | * from the root DPRC container. |
| 727 | */ |
| 728 | if (is_fsl_mc_bus_dprc(mc_dev) && |
| 729 | regions[i].start == region_desc.base_offset) |
| 730 | regions[i].start += mc_portal_base_phys_addr; |
| 731 | } |
| 732 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 733 | if (error < 0) { |
| 734 | dev_err(parent_dev, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 735 | "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", |
| 736 | region_desc.base_offset, |
| 737 | obj_desc->type, obj_desc->id, i); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 738 | goto error_cleanup_regions; |
| 739 | } |
| 740 | |
| 741 | regions[i].end = regions[i].start + region_desc.size - 1; |
| 742 | regions[i].name = "fsl-mc object MMIO region"; |
Diana Craciun | e0c171d | 2020-09-29 11:54:32 +0300 | [diff] [blame] | 743 | regions[i].flags = region_desc.flags & IORESOURCE_BITS; |
| 744 | regions[i].flags |= IORESOURCE_MEM; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | mc_dev->regions = regions; |
| 748 | return 0; |
| 749 | |
| 750 | error_cleanup_regions: |
| 751 | kfree(regions); |
| 752 | return error; |
| 753 | } |
| 754 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 755 | /* |
Stuart Yoder | fde867d | 2016-06-22 16:40:47 -0500 | [diff] [blame] | 756 | * fsl_mc_is_root_dprc - function to check if a given device is a root dprc |
| 757 | */ |
| 758 | bool fsl_mc_is_root_dprc(struct device *dev) |
| 759 | { |
| 760 | struct device *root_dprc_dev; |
| 761 | |
| 762 | fsl_mc_get_root_dprc(dev, &root_dprc_dev); |
| 763 | if (!root_dprc_dev) |
| 764 | return false; |
| 765 | return dev == root_dprc_dev; |
| 766 | } |
| 767 | |
Laurentiu Tudor | 95b3523 | 2017-02-07 09:43:46 -0600 | [diff] [blame] | 768 | static void fsl_mc_device_release(struct device *dev) |
| 769 | { |
| 770 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
Laurentiu Tudor | 95b3523 | 2017-02-07 09:43:46 -0600 | [diff] [blame] | 771 | |
| 772 | kfree(mc_dev->regions); |
| 773 | |
Laurentiu Tudor | 19e2be7 | 2017-11-17 15:38:34 +0200 | [diff] [blame] | 774 | if (is_fsl_mc_bus_dprc(mc_dev)) |
Laurentiu Tudor | a042fbe | 2017-06-08 17:28:48 +0300 | [diff] [blame] | 775 | kfree(to_fsl_mc_bus(mc_dev)); |
Laurentiu Tudor | 95b3523 | 2017-02-07 09:43:46 -0600 | [diff] [blame] | 776 | else |
Laurentiu Tudor | 9b65332 | 2017-02-07 09:43:48 -0600 | [diff] [blame] | 777 | kfree(mc_dev); |
Laurentiu Tudor | 95b3523 | 2017-02-07 09:43:46 -0600 | [diff] [blame] | 778 | } |
| 779 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 780 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 781 | * Add a newly discovered fsl-mc device to be visible in Linux |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 782 | */ |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 783 | int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 784 | struct fsl_mc_io *mc_io, |
| 785 | struct device *parent_dev, |
| 786 | struct fsl_mc_device **new_mc_dev) |
| 787 | { |
| 788 | int error; |
| 789 | struct fsl_mc_device *mc_dev = NULL; |
| 790 | struct fsl_mc_bus *mc_bus = NULL; |
| 791 | struct fsl_mc_device *parent_mc_dev; |
| 792 | |
Nipun Gupta | df5e9b5 | 2016-06-29 22:44:39 +0530 | [diff] [blame] | 793 | if (dev_is_fsl_mc(parent_dev)) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 794 | parent_mc_dev = to_fsl_mc_device(parent_dev); |
| 795 | else |
| 796 | parent_mc_dev = NULL; |
| 797 | |
| 798 | if (strcmp(obj_desc->type, "dprc") == 0) { |
| 799 | /* |
| 800 | * Allocate an MC bus device object: |
| 801 | */ |
Laurentiu Tudor | dc341c4 | 2017-02-07 09:43:47 -0600 | [diff] [blame] | 802 | mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 803 | if (!mc_bus) |
| 804 | return -ENOMEM; |
| 805 | |
Diana Craciun | 5d781fa | 2020-09-29 11:54:35 +0300 | [diff] [blame] | 806 | mutex_init(&mc_bus->scan_mutex); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 807 | mc_dev = &mc_bus->mc_dev; |
| 808 | } else { |
| 809 | /* |
| 810 | * Allocate a regular fsl_mc_device object: |
| 811 | */ |
Laurentiu Tudor | 9b65332 | 2017-02-07 09:43:48 -0600 | [diff] [blame] | 812 | mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 813 | if (!mc_dev) |
| 814 | return -ENOMEM; |
| 815 | } |
| 816 | |
| 817 | mc_dev->obj_desc = *obj_desc; |
| 818 | mc_dev->mc_io = mc_io; |
| 819 | device_initialize(&mc_dev->dev); |
| 820 | mc_dev->dev.parent = parent_dev; |
| 821 | mc_dev->dev.bus = &fsl_mc_bus_type; |
Laurentiu Tudor | 95b3523 | 2017-02-07 09:43:46 -0600 | [diff] [blame] | 822 | mc_dev->dev.release = fsl_mc_device_release; |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 823 | mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type); |
| 824 | if (!mc_dev->dev.type) { |
Greg Kroah-Hartman | fb17be9 | 2017-11-27 09:25:51 +0100 | [diff] [blame] | 825 | error = -ENODEV; |
Laurentiu Tudor | 47433b6 | 2017-11-17 15:38:33 +0200 | [diff] [blame] | 826 | dev_err(parent_dev, "unknown device type %s\n", obj_desc->type); |
| 827 | goto error_cleanup_dev; |
| 828 | } |
J. German Rivera | 77371fb | 2015-03-27 16:01:04 -0500 | [diff] [blame] | 829 | dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 830 | |
| 831 | if (strcmp(obj_desc->type, "dprc") == 0) { |
| 832 | struct fsl_mc_io *mc_io2; |
| 833 | |
| 834 | mc_dev->flags |= FSL_MC_IS_DPRC; |
| 835 | |
| 836 | /* |
| 837 | * To get the DPRC's ICID, we need to open the DPRC |
| 838 | * in get_dprc_icid(). For child DPRCs, we do so using the |
| 839 | * parent DPRC's MC portal instead of the child DPRC's MC |
| 840 | * portal, in case the child DPRC is already opened with |
| 841 | * its own portal (e.g., the DPRC used by AIOP). |
| 842 | * |
| 843 | * NOTE: There cannot be more than one active open for a |
| 844 | * given MC object, using the same MC portal. |
| 845 | */ |
| 846 | if (parent_mc_dev) { |
| 847 | /* |
| 848 | * device being added is a child DPRC device |
| 849 | */ |
| 850 | mc_io2 = parent_mc_dev->mc_io; |
| 851 | } else { |
| 852 | /* |
| 853 | * device being added is the root DPRC device |
| 854 | */ |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 855 | if (!mc_io) { |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 856 | error = -EINVAL; |
| 857 | goto error_cleanup_dev; |
| 858 | } |
| 859 | |
| 860 | mc_io2 = mc_io; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); |
| 864 | if (error < 0) |
| 865 | goto error_cleanup_dev; |
| 866 | } else { |
| 867 | /* |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 868 | * A non-DPRC object has to be a child of a DPRC, use the |
| 869 | * parent's ICID and interrupt domain. |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 870 | */ |
| 871 | mc_dev->icid = parent_mc_dev->icid; |
| 872 | mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; |
| 873 | mc_dev->dev.dma_mask = &mc_dev->dma_mask; |
Nipun Gupta | 761ba8e | 2018-09-10 19:19:20 +0530 | [diff] [blame] | 874 | mc_dev->dev.coherent_dma_mask = mc_dev->dma_mask; |
J. German Rivera | 660a24b | 2016-01-06 16:03:29 -0600 | [diff] [blame] | 875 | dev_set_msi_domain(&mc_dev->dev, |
| 876 | dev_get_msi_domain(&parent_mc_dev->dev)); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* |
| 880 | * Get MMIO regions for the device from the MC: |
| 881 | * |
| 882 | * NOTE: the root DPRC is a special case as its MMIO region is |
| 883 | * obtained from the device tree |
| 884 | */ |
| 885 | if (parent_mc_dev && obj_desc->region_count != 0) { |
| 886 | error = fsl_mc_device_get_mmio_regions(mc_dev, |
| 887 | parent_mc_dev); |
| 888 | if (error < 0) |
| 889 | goto error_cleanup_dev; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * The device-specific probe callback will get invoked by device_add() |
| 894 | */ |
| 895 | error = device_add(&mc_dev->dev); |
| 896 | if (error < 0) { |
| 897 | dev_err(parent_dev, |
| 898 | "device_add() failed for device %s: %d\n", |
| 899 | dev_name(&mc_dev->dev), error); |
| 900 | goto error_cleanup_dev; |
| 901 | } |
| 902 | |
Stuart Yoder | e3494af | 2016-10-26 11:20:31 -0500 | [diff] [blame] | 903 | dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev)); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 904 | |
| 905 | *new_mc_dev = mc_dev; |
| 906 | return 0; |
| 907 | |
| 908 | error_cleanup_dev: |
| 909 | kfree(mc_dev->regions); |
Laurentiu Tudor | a042fbe | 2017-06-08 17:28:48 +0300 | [diff] [blame] | 910 | kfree(mc_bus); |
| 911 | kfree(mc_dev); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 912 | |
| 913 | return error; |
| 914 | } |
| 915 | EXPORT_SYMBOL_GPL(fsl_mc_device_add); |
| 916 | |
Laurentiu Tudor | 8c97a4f | 2021-07-15 17:07:15 +0300 | [diff] [blame] | 917 | static struct notifier_block fsl_mc_nb; |
| 918 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 919 | /** |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 920 | * fsl_mc_device_remove - Remove an fsl-mc device from being visible to |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 921 | * Linux |
| 922 | * |
Stuart Yoder | 58caaac | 2016-10-26 11:20:32 -0500 | [diff] [blame] | 923 | * @mc_dev: Pointer to an fsl-mc device |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 924 | */ |
| 925 | void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) |
| 926 | { |
Bharat Bhushan | 1f86a00 | 2020-09-29 11:54:31 +0300 | [diff] [blame] | 927 | kfree(mc_dev->driver_override); |
| 928 | mc_dev->driver_override = NULL; |
| 929 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 930 | /* |
| 931 | * The device-specific remove callback will get invoked by device_del() |
| 932 | */ |
| 933 | device_del(&mc_dev->dev); |
| 934 | put_device(&mc_dev->dev); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 935 | } |
| 936 | EXPORT_SYMBOL_GPL(fsl_mc_device_remove); |
| 937 | |
Ioana Ciornei | 27cfdad | 2021-08-03 19:57:42 +0300 | [diff] [blame] | 938 | struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev, |
| 939 | u16 if_id) |
Ioana Ciornei | 1ac210d | 2019-10-31 01:18:29 +0200 | [diff] [blame] | 940 | { |
| 941 | struct fsl_mc_device *mc_bus_dev, *endpoint; |
Ioana Ciornei | cff081e | 2019-12-04 16:29:50 +0200 | [diff] [blame] | 942 | struct fsl_mc_obj_desc endpoint_desc = {{ 0 }}; |
| 943 | struct dprc_endpoint endpoint1 = {{ 0 }}; |
| 944 | struct dprc_endpoint endpoint2 = {{ 0 }}; |
Ioana Ciornei | 1ac210d | 2019-10-31 01:18:29 +0200 | [diff] [blame] | 945 | int state, err; |
| 946 | |
| 947 | mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); |
| 948 | strcpy(endpoint1.type, mc_dev->obj_desc.type); |
| 949 | endpoint1.id = mc_dev->obj_desc.id; |
Ioana Ciornei | 27cfdad | 2021-08-03 19:57:42 +0300 | [diff] [blame] | 950 | endpoint1.if_id = if_id; |
Ioana Ciornei | 1ac210d | 2019-10-31 01:18:29 +0200 | [diff] [blame] | 951 | |
| 952 | err = dprc_get_connection(mc_bus_dev->mc_io, 0, |
| 953 | mc_bus_dev->mc_handle, |
| 954 | &endpoint1, &endpoint2, |
| 955 | &state); |
| 956 | |
| 957 | if (err == -ENOTCONN || state == -1) |
| 958 | return ERR_PTR(-ENOTCONN); |
| 959 | |
| 960 | if (err < 0) { |
| 961 | dev_err(&mc_bus_dev->dev, "dprc_get_connection() = %d\n", err); |
| 962 | return ERR_PTR(err); |
| 963 | } |
| 964 | |
| 965 | strcpy(endpoint_desc.type, endpoint2.type); |
| 966 | endpoint_desc.id = endpoint2.id; |
| 967 | endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev); |
| 968 | |
Ioana Ciornei | ef57e6c | 2021-01-08 11:07:24 +0200 | [diff] [blame] | 969 | /* |
| 970 | * We know that the device has an endpoint because we verified by |
| 971 | * interrogating the firmware. This is the case when the device was not |
| 972 | * yet discovered by the fsl-mc bus, thus the lookup returned NULL. |
Laurentiu Tudor | 8567494 | 2021-07-15 17:07:17 +0300 | [diff] [blame] | 973 | * Force a rescan of the devices in this container and retry the lookup. |
| 974 | */ |
| 975 | if (!endpoint) { |
| 976 | struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); |
| 977 | |
| 978 | if (mutex_trylock(&mc_bus->scan_mutex)) { |
| 979 | err = dprc_scan_objects(mc_bus_dev, true); |
| 980 | mutex_unlock(&mc_bus->scan_mutex); |
| 981 | } |
| 982 | |
| 983 | if (err < 0) |
| 984 | return ERR_PTR(err); |
| 985 | } |
| 986 | |
| 987 | endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev); |
| 988 | /* |
| 989 | * This means that the endpoint might reside in a different isolation |
| 990 | * context (DPRC/container). Not much to do, so return a permssion |
| 991 | * error. |
Ioana Ciornei | ef57e6c | 2021-01-08 11:07:24 +0200 | [diff] [blame] | 992 | */ |
| 993 | if (!endpoint) |
Laurentiu Tudor | 8567494 | 2021-07-15 17:07:17 +0300 | [diff] [blame] | 994 | return ERR_PTR(-EPERM); |
Ioana Ciornei | ef57e6c | 2021-01-08 11:07:24 +0200 | [diff] [blame] | 995 | |
Ioana Ciornei | 1ac210d | 2019-10-31 01:18:29 +0200 | [diff] [blame] | 996 | return endpoint; |
| 997 | } |
| 998 | EXPORT_SYMBOL_GPL(fsl_mc_get_endpoint); |
| 999 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1000 | static int parse_mc_ranges(struct device *dev, |
| 1001 | int *paddr_cells, |
| 1002 | int *mc_addr_cells, |
| 1003 | int *mc_size_cells, |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1004 | const __be32 **ranges_start) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1005 | { |
| 1006 | const __be32 *prop; |
| 1007 | int range_tuple_cell_count; |
| 1008 | int ranges_len; |
| 1009 | int tuple_len; |
| 1010 | struct device_node *mc_node = dev->of_node; |
| 1011 | |
| 1012 | *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); |
| 1013 | if (!(*ranges_start) || !ranges_len) { |
| 1014 | dev_warn(dev, |
Rob Herring | 6b825b1 | 2018-08-27 19:51:18 -0500 | [diff] [blame] | 1015 | "missing or empty ranges property for device tree node '%pOFn'\n", |
| 1016 | mc_node); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | *paddr_cells = of_n_addr_cells(mc_node); |
| 1021 | |
| 1022 | prop = of_get_property(mc_node, "#address-cells", NULL); |
| 1023 | if (prop) |
| 1024 | *mc_addr_cells = be32_to_cpup(prop); |
| 1025 | else |
| 1026 | *mc_addr_cells = *paddr_cells; |
| 1027 | |
| 1028 | prop = of_get_property(mc_node, "#size-cells", NULL); |
| 1029 | if (prop) |
| 1030 | *mc_size_cells = be32_to_cpup(prop); |
| 1031 | else |
| 1032 | *mc_size_cells = of_n_size_cells(mc_node); |
| 1033 | |
| 1034 | range_tuple_cell_count = *paddr_cells + *mc_addr_cells + |
| 1035 | *mc_size_cells; |
| 1036 | |
| 1037 | tuple_len = range_tuple_cell_count * sizeof(__be32); |
| 1038 | if (ranges_len % tuple_len != 0) { |
Rob Herring | 6b825b1 | 2018-08-27 19:51:18 -0500 | [diff] [blame] | 1039 | dev_err(dev, "malformed ranges property '%pOFn'\n", mc_node); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1040 | return -EINVAL; |
| 1041 | } |
| 1042 | |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1043 | return ranges_len / tuple_len; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | static int get_mc_addr_translation_ranges(struct device *dev, |
| 1047 | struct fsl_mc_addr_translation_range |
| 1048 | **ranges, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1049 | u8 *num_ranges) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1050 | { |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1051 | int ret; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1052 | int paddr_cells; |
| 1053 | int mc_addr_cells; |
| 1054 | int mc_size_cells; |
| 1055 | int i; |
| 1056 | const __be32 *ranges_start; |
| 1057 | const __be32 *cell; |
| 1058 | |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1059 | ret = parse_mc_ranges(dev, |
Brett Hitchcock | 814f3be2 | 2017-05-14 13:20:03 -0700 | [diff] [blame] | 1060 | &paddr_cells, |
| 1061 | &mc_addr_cells, |
| 1062 | &mc_size_cells, |
| 1063 | &ranges_start); |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1064 | if (ret < 0) |
| 1065 | return ret; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1066 | |
Arnd Bergmann | a45e47f | 2017-02-27 21:42:16 +0100 | [diff] [blame] | 1067 | *num_ranges = ret; |
| 1068 | if (!ret) { |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1069 | /* |
| 1070 | * Missing or empty ranges property ("ranges;") for the |
| 1071 | * 'fsl,qoriq-mc' node. In this case, identity mapping |
| 1072 | * will be used. |
| 1073 | */ |
| 1074 | *ranges = NULL; |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | *ranges = devm_kcalloc(dev, *num_ranges, |
| 1079 | sizeof(struct fsl_mc_addr_translation_range), |
| 1080 | GFP_KERNEL); |
| 1081 | if (!(*ranges)) |
| 1082 | return -ENOMEM; |
| 1083 | |
| 1084 | cell = ranges_start; |
| 1085 | for (i = 0; i < *num_ranges; ++i) { |
| 1086 | struct fsl_mc_addr_translation_range *range = &(*ranges)[i]; |
| 1087 | |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1088 | range->mc_region_type = of_read_number(cell, 1); |
| 1089 | range->start_mc_offset = of_read_number(cell + 1, |
| 1090 | mc_addr_cells - 1); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1091 | cell += mc_addr_cells; |
| 1092 | range->start_phys_addr = of_read_number(cell, paddr_cells); |
| 1093 | cell += paddr_cells; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1094 | range->end_mc_offset = range->start_mc_offset + |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1095 | of_read_number(cell, mc_size_cells); |
| 1096 | |
| 1097 | cell += mc_size_cells; |
| 1098 | } |
| 1099 | |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 1103 | /* |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1104 | * fsl_mc_bus_probe - callback invoked when the root MC bus is being |
| 1105 | * added |
| 1106 | */ |
| 1107 | static int fsl_mc_bus_probe(struct platform_device *pdev) |
| 1108 | { |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 1109 | struct fsl_mc_obj_desc obj_desc; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1110 | int error; |
| 1111 | struct fsl_mc *mc; |
| 1112 | struct fsl_mc_device *mc_bus_dev = NULL; |
| 1113 | struct fsl_mc_io *mc_io = NULL; |
| 1114 | int container_id; |
| 1115 | phys_addr_t mc_portal_phys_addr; |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1116 | u32 mc_portal_size, mc_stream_id; |
| 1117 | struct resource *plat_res; |
| 1118 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1119 | mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); |
| 1120 | if (!mc) |
| 1121 | return -ENOMEM; |
| 1122 | |
| 1123 | platform_set_drvdata(pdev, mc); |
| 1124 | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1125 | plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Laurentiu Tudor | 61243c0 | 2020-11-05 17:30:49 +0200 | [diff] [blame] | 1126 | if (plat_res) { |
Laurentiu Tudor | aef85b5 | 2020-09-14 13:54:59 +0300 | [diff] [blame] | 1127 | mc->fsl_mc_regs = devm_ioremap_resource(&pdev->dev, plat_res); |
Laurentiu Tudor | 61243c0 | 2020-11-05 17:30:49 +0200 | [diff] [blame] | 1128 | if (IS_ERR(mc->fsl_mc_regs)) |
| 1129 | return PTR_ERR(mc->fsl_mc_regs); |
| 1130 | } |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1131 | |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 1132 | if (mc->fsl_mc_regs) { |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 1133 | if (IS_ENABLED(CONFIG_ACPI) && !dev_of_node(&pdev->dev)) { |
| 1134 | mc_stream_id = readl(mc->fsl_mc_regs + FSL_MC_FAPR); |
| 1135 | /* |
| 1136 | * HW ORs the PL and BMT bit, places the result in bit |
| 1137 | * 14 of the StreamID and ORs in the ICID. Calculate it |
| 1138 | * accordingly. |
| 1139 | */ |
| 1140 | mc_stream_id = (mc_stream_id & 0xffff) | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1141 | ((mc_stream_id & (MC_FAPR_PL | MC_FAPR_BMT)) ? |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 1142 | BIT(14) : 0); |
| 1143 | error = acpi_dma_configure_id(&pdev->dev, |
| 1144 | DEV_DMA_COHERENT, |
| 1145 | &mc_stream_id); |
Laurentiu Tudor | f8cfa9b | 2021-07-15 17:07:12 +0300 | [diff] [blame] | 1146 | if (error == -EPROBE_DEFER) |
| 1147 | return error; |
Laurentiu Tudor | 74abd1f | 2020-11-05 17:30:50 +0200 | [diff] [blame] | 1148 | if (error) |
| 1149 | dev_warn(&pdev->dev, |
| 1150 | "failed to configure dma: %d.\n", |
| 1151 | error); |
| 1152 | } |
Laurentiu Tudor | f8cfa9b | 2021-07-15 17:07:12 +0300 | [diff] [blame] | 1153 | |
| 1154 | /* |
| 1155 | * Some bootloaders pause the MC firmware before booting the |
| 1156 | * kernel so that MC will not cause faults as soon as the |
| 1157 | * SMMU probes due to the fact that there's no configuration |
| 1158 | * in place for MC. |
| 1159 | * At this point MC should have all its SMMU setup done so make |
| 1160 | * sure it is resumed. |
| 1161 | */ |
Laurentiu Tudor | c40cbad | 2021-07-15 17:07:13 +0300 | [diff] [blame] | 1162 | writel(readl(mc->fsl_mc_regs + FSL_MC_GCR1) & |
| 1163 | (~(GCR1_P1_STOP | GCR1_P2_STOP)), |
Laurentiu Tudor | f8cfa9b | 2021-07-15 17:07:12 +0300 | [diff] [blame] | 1164 | mc->fsl_mc_regs + FSL_MC_GCR1); |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1165 | } |
| 1166 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1167 | /* |
| 1168 | * Get physical address of MC portal for the root DPRC: |
| 1169 | */ |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1170 | plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1171 | mc_portal_phys_addr = plat_res->start; |
| 1172 | mc_portal_size = resource_size(plat_res); |
Laurentiu Tudor | 8990f96 | 2021-07-15 17:07:18 +0300 | [diff] [blame] | 1173 | mc_portal_base_phys_addr = mc_portal_phys_addr & ~0x3ffffff; |
| 1174 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1175 | error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, |
J. German Rivera | 1129cde | 2016-01-06 16:03:24 -0600 | [diff] [blame] | 1176 | mc_portal_size, NULL, |
| 1177 | FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1178 | if (error < 0) |
| 1179 | return error; |
| 1180 | |
J. German Rivera | 4057743 | 2015-09-23 16:10:59 -0500 | [diff] [blame] | 1181 | error = mc_get_version(mc_io, 0, &mc_version); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1182 | if (error != 0) { |
| 1183 | dev_err(&pdev->dev, |
| 1184 | "mc_get_version() failed with error %d\n", error); |
| 1185 | goto error_cleanup_mc_io; |
| 1186 | } |
| 1187 | |
Stuart Yoder | e3494af | 2016-10-26 11:20:31 -0500 | [diff] [blame] | 1188 | dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n", |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1189 | mc_version.major, mc_version.minor, mc_version.revision); |
| 1190 | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1191 | if (dev_of_node(&pdev->dev)) { |
| 1192 | error = get_mc_addr_translation_ranges(&pdev->dev, |
| 1193 | &mc->translation_ranges, |
| 1194 | &mc->num_translation_ranges); |
| 1195 | if (error < 0) |
| 1196 | goto error_cleanup_mc_io; |
| 1197 | } |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1198 | |
Ioana Ciornei | decd3d0 | 2016-10-26 11:20:34 -0500 | [diff] [blame] | 1199 | error = dprc_get_container_id(mc_io, 0, &container_id); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1200 | if (error < 0) { |
| 1201 | dev_err(&pdev->dev, |
Laurentiu Tudor | 58acb38 | 2017-02-07 09:43:50 -0600 | [diff] [blame] | 1202 | "dprc_get_container_id() failed: %d\n", error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1203 | goto error_cleanup_mc_io; |
| 1204 | } |
| 1205 | |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 1206 | memset(&obj_desc, 0, sizeof(struct fsl_mc_obj_desc)); |
Ioana Ciornei | decd3d0 | 2016-10-26 11:20:34 -0500 | [diff] [blame] | 1207 | error = dprc_get_api_version(mc_io, 0, |
| 1208 | &obj_desc.ver_major, |
| 1209 | &obj_desc.ver_minor); |
Itai Katz | 9529d16 | 2016-04-11 11:55:55 -0500 | [diff] [blame] | 1210 | if (error < 0) |
| 1211 | goto error_cleanup_mc_io; |
| 1212 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1213 | obj_desc.vendor = FSL_MC_VENDOR_FREESCALE; |
| 1214 | strcpy(obj_desc.type, "dprc"); |
| 1215 | obj_desc.id = container_id; |
J. German Rivera | a17f4aa | 2015-10-17 11:18:23 -0500 | [diff] [blame] | 1216 | obj_desc.irq_count = 1; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1217 | obj_desc.region_count = 0; |
| 1218 | |
| 1219 | error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); |
| 1220 | if (error < 0) |
| 1221 | goto error_cleanup_mc_io; |
| 1222 | |
| 1223 | mc->root_mc_bus_dev = mc_bus_dev; |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1224 | mc_bus_dev->dev.fwnode = pdev->dev.fwnode; |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1225 | return 0; |
| 1226 | |
| 1227 | error_cleanup_mc_io: |
| 1228 | fsl_destroy_mc_io(mc_io); |
| 1229 | return error; |
| 1230 | } |
| 1231 | |
Lee Jones | d71b57d | 2021-06-17 12:04:55 +0100 | [diff] [blame] | 1232 | /* |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1233 | * fsl_mc_bus_remove - callback invoked when the root MC bus is being |
| 1234 | * removed |
| 1235 | */ |
| 1236 | static int fsl_mc_bus_remove(struct platform_device *pdev) |
| 1237 | { |
| 1238 | struct fsl_mc *mc = platform_get_drvdata(pdev); |
| 1239 | |
Laurentiu Tudor | a385dd7 | 2017-11-17 15:38:32 +0200 | [diff] [blame] | 1240 | if (!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev)) |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1241 | return -EINVAL; |
| 1242 | |
| 1243 | fsl_mc_device_remove(mc->root_mc_bus_dev); |
Bharat Bhushan | f936271 | 2016-06-22 16:40:48 -0500 | [diff] [blame] | 1244 | |
| 1245 | fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io); |
| 1246 | mc->root_mc_bus_dev->mc_io = NULL; |
| 1247 | |
Laurentiu Tudor | 8c97a4f | 2021-07-15 17:07:15 +0300 | [diff] [blame] | 1248 | bus_unregister_notifier(&fsl_mc_bus_type, &fsl_mc_nb); |
| 1249 | |
Laurentiu Tudor | 39243fc | 2021-07-15 17:07:16 +0300 | [diff] [blame] | 1250 | if (mc->fsl_mc_regs) { |
| 1251 | /* |
| 1252 | * Pause the MC firmware so that it doesn't crash in certain |
| 1253 | * scenarios, such as kexec. |
| 1254 | */ |
| 1255 | writel(readl(mc->fsl_mc_regs + FSL_MC_GCR1) | |
| 1256 | (GCR1_P1_STOP | GCR1_P2_STOP), |
| 1257 | mc->fsl_mc_regs + FSL_MC_GCR1); |
| 1258 | } |
| 1259 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1260 | return 0; |
| 1261 | } |
| 1262 | |
Laurentiu Tudor | 3ab520c | 2021-07-15 17:07:14 +0300 | [diff] [blame] | 1263 | static void fsl_mc_bus_shutdown(struct platform_device *pdev) |
| 1264 | { |
| 1265 | fsl_mc_bus_remove(pdev); |
| 1266 | } |
| 1267 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1268 | static const struct of_device_id fsl_mc_bus_match_table[] = { |
| 1269 | {.compatible = "fsl,qoriq-mc",}, |
| 1270 | {}, |
| 1271 | }; |
| 1272 | |
| 1273 | MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table); |
| 1274 | |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1275 | static const struct acpi_device_id fsl_mc_bus_acpi_match_table[] = { |
| 1276 | {"NXP0008", 0 }, |
| 1277 | { } |
| 1278 | }; |
| 1279 | MODULE_DEVICE_TABLE(acpi, fsl_mc_bus_acpi_match_table); |
| 1280 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1281 | static struct platform_driver fsl_mc_bus_driver = { |
| 1282 | .driver = { |
| 1283 | .name = "fsl_mc_bus", |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1284 | .pm = NULL, |
| 1285 | .of_match_table = fsl_mc_bus_match_table, |
Makarand Pawagi | 6305166 | 2020-06-19 09:20:13 +0100 | [diff] [blame] | 1286 | .acpi_match_table = fsl_mc_bus_acpi_match_table, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1287 | }, |
| 1288 | .probe = fsl_mc_bus_probe, |
| 1289 | .remove = fsl_mc_bus_remove, |
Laurentiu Tudor | 3ab520c | 2021-07-15 17:07:14 +0300 | [diff] [blame] | 1290 | .shutdown = fsl_mc_bus_shutdown, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1291 | }; |
| 1292 | |
Laurentiu Tudor | 8c97a4f | 2021-07-15 17:07:15 +0300 | [diff] [blame] | 1293 | static int fsl_mc_bus_notifier(struct notifier_block *nb, |
| 1294 | unsigned long action, void *data) |
| 1295 | { |
| 1296 | struct device *dev = data; |
| 1297 | struct resource *res; |
| 1298 | void __iomem *fsl_mc_regs; |
| 1299 | |
| 1300 | if (action != BUS_NOTIFY_ADD_DEVICE) |
| 1301 | return 0; |
| 1302 | |
| 1303 | if (!of_match_device(fsl_mc_bus_match_table, dev) && |
| 1304 | !acpi_match_device(fsl_mc_bus_acpi_match_table, dev)) |
| 1305 | return 0; |
| 1306 | |
| 1307 | res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 1); |
| 1308 | if (!res) |
| 1309 | return 0; |
| 1310 | |
| 1311 | fsl_mc_regs = ioremap(res->start, resource_size(res)); |
| 1312 | if (!fsl_mc_regs) |
| 1313 | return 0; |
| 1314 | |
| 1315 | /* |
| 1316 | * Make sure that the MC firmware is paused before the IOMMU setup for |
| 1317 | * it is done or otherwise the firmware will crash right after the SMMU |
| 1318 | * gets probed and enabled. |
| 1319 | */ |
| 1320 | writel(readl(fsl_mc_regs + FSL_MC_GCR1) | (GCR1_P1_STOP | GCR1_P2_STOP), |
| 1321 | fsl_mc_regs + FSL_MC_GCR1); |
| 1322 | iounmap(fsl_mc_regs); |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static struct notifier_block fsl_mc_nb = { |
| 1328 | .notifier_call = fsl_mc_bus_notifier, |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1329 | }; |
| 1330 | |
| 1331 | static int __init fsl_mc_bus_driver_init(void) |
| 1332 | { |
| 1333 | int error; |
| 1334 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1335 | error = bus_register(&fsl_mc_bus_type); |
| 1336 | if (error < 0) { |
Stuart Yoder | a673783 | 2016-10-26 11:20:29 -0500 | [diff] [blame] | 1337 | pr_err("bus type registration failed: %d\n", error); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1338 | goto error_cleanup_cache; |
| 1339 | } |
| 1340 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1341 | error = platform_driver_register(&fsl_mc_bus_driver); |
| 1342 | if (error < 0) { |
| 1343 | pr_err("platform_driver_register() failed: %d\n", error); |
| 1344 | goto error_cleanup_bus; |
| 1345 | } |
| 1346 | |
J. German Rivera | f2f2726 | 2015-03-05 19:29:11 -0600 | [diff] [blame] | 1347 | error = dprc_driver_init(); |
| 1348 | if (error < 0) |
| 1349 | goto error_cleanup_driver; |
| 1350 | |
J. German Rivera | e91ffa9 | 2015-03-27 16:01:08 -0500 | [diff] [blame] | 1351 | error = fsl_mc_allocator_driver_init(); |
| 1352 | if (error < 0) |
| 1353 | goto error_cleanup_dprc_driver; |
| 1354 | |
Laurentiu Tudor | 8c97a4f | 2021-07-15 17:07:15 +0300 | [diff] [blame] | 1355 | return bus_register_notifier(&platform_bus_type, &fsl_mc_nb); |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1356 | |
J. German Rivera | e91ffa9 | 2015-03-27 16:01:08 -0500 | [diff] [blame] | 1357 | error_cleanup_dprc_driver: |
| 1358 | dprc_driver_exit(); |
| 1359 | |
J. German Rivera | f2f2726 | 2015-03-05 19:29:11 -0600 | [diff] [blame] | 1360 | error_cleanup_driver: |
| 1361 | platform_driver_unregister(&fsl_mc_bus_driver); |
| 1362 | |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1363 | error_cleanup_bus: |
| 1364 | bus_unregister(&fsl_mc_bus_type); |
| 1365 | |
| 1366 | error_cleanup_cache: |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1367 | return error; |
| 1368 | } |
J. German Rivera | bbf9d17 | 2015-03-05 19:29:10 -0600 | [diff] [blame] | 1369 | postcore_initcall(fsl_mc_bus_driver_init); |