.. | .. |
---|
3 | 3 | * Freescale Management Complex (MC) bus driver |
---|
4 | 4 | * |
---|
5 | 5 | * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. |
---|
| 6 | + * Copyright 2019-2020 NXP |
---|
6 | 7 | * Author: German Rivera <German.Rivera@freescale.com> |
---|
7 | 8 | * |
---|
8 | 9 | */ |
---|
.. | .. |
---|
18 | 19 | #include <linux/bitops.h> |
---|
19 | 20 | #include <linux/msi.h> |
---|
20 | 21 | #include <linux/dma-mapping.h> |
---|
| 22 | +#include <linux/acpi.h> |
---|
| 23 | +#include <linux/iommu.h> |
---|
21 | 24 | |
---|
22 | 25 | #include "fsl-mc-private.h" |
---|
23 | 26 | |
---|
.. | .. |
---|
25 | 28 | * Default DMA mask for devices on a fsl-mc bus |
---|
26 | 29 | */ |
---|
27 | 30 | #define FSL_MC_DEFAULT_DMA_MASK (~0ULL) |
---|
| 31 | + |
---|
| 32 | +static struct fsl_mc_version mc_version; |
---|
28 | 33 | |
---|
29 | 34 | /** |
---|
30 | 35 | * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device |
---|
.. | .. |
---|
36 | 41 | struct fsl_mc_device *root_mc_bus_dev; |
---|
37 | 42 | u8 num_translation_ranges; |
---|
38 | 43 | struct fsl_mc_addr_translation_range *translation_ranges; |
---|
| 44 | + void *fsl_mc_regs; |
---|
39 | 45 | }; |
---|
40 | 46 | |
---|
41 | 47 | /** |
---|
.. | .. |
---|
54 | 60 | phys_addr_t start_phys_addr; |
---|
55 | 61 | }; |
---|
56 | 62 | |
---|
57 | | -/** |
---|
58 | | - * struct mc_version |
---|
59 | | - * @major: Major version number: incremented on API compatibility changes |
---|
60 | | - * @minor: Minor version number: incremented on API additions (that are |
---|
61 | | - * backward compatible); reset when major version is incremented |
---|
62 | | - * @revision: Internal revision number: incremented on implementation changes |
---|
63 | | - * and/or bug fixes that have no impact on API |
---|
64 | | - */ |
---|
65 | | -struct mc_version { |
---|
66 | | - u32 major; |
---|
67 | | - u32 minor; |
---|
68 | | - u32 revision; |
---|
69 | | -}; |
---|
| 63 | +#define FSL_MC_FAPR 0x28 |
---|
| 64 | +#define MC_FAPR_PL BIT(18) |
---|
| 65 | +#define MC_FAPR_BMT BIT(17) |
---|
| 66 | + |
---|
| 67 | +static phys_addr_t mc_portal_base_phys_addr; |
---|
70 | 68 | |
---|
71 | 69 | /** |
---|
72 | 70 | * fsl_mc_bus_match - device to driver matching callback |
---|
.. | .. |
---|
82 | 80 | struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
---|
83 | 81 | struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); |
---|
84 | 82 | bool found = false; |
---|
| 83 | + |
---|
| 84 | + /* When driver_override is set, only bind to the matching driver */ |
---|
| 85 | + if (mc_dev->driver_override) { |
---|
| 86 | + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name); |
---|
| 87 | + goto out; |
---|
| 88 | + } |
---|
85 | 89 | |
---|
86 | 90 | if (!mc_drv->match_id_table) |
---|
87 | 91 | goto out; |
---|
.. | .. |
---|
127 | 131 | return 0; |
---|
128 | 132 | } |
---|
129 | 133 | |
---|
| 134 | +static int fsl_mc_dma_configure(struct device *dev) |
---|
| 135 | +{ |
---|
| 136 | + struct device *dma_dev = dev; |
---|
| 137 | + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
---|
| 138 | + u32 input_id = mc_dev->icid; |
---|
| 139 | + |
---|
| 140 | + while (dev_is_fsl_mc(dma_dev)) |
---|
| 141 | + dma_dev = dma_dev->parent; |
---|
| 142 | + |
---|
| 143 | + if (dev_of_node(dma_dev)) |
---|
| 144 | + return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id); |
---|
| 145 | + |
---|
| 146 | + return acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id); |
---|
| 147 | +} |
---|
| 148 | + |
---|
130 | 149 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
---|
131 | 150 | char *buf) |
---|
132 | 151 | { |
---|
.. | .. |
---|
137 | 156 | } |
---|
138 | 157 | static DEVICE_ATTR_RO(modalias); |
---|
139 | 158 | |
---|
| 159 | +static ssize_t driver_override_store(struct device *dev, |
---|
| 160 | + struct device_attribute *attr, |
---|
| 161 | + const char *buf, size_t count) |
---|
| 162 | +{ |
---|
| 163 | + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
---|
| 164 | + char *driver_override, *old = mc_dev->driver_override; |
---|
| 165 | + char *cp; |
---|
| 166 | + |
---|
| 167 | + if (WARN_ON(dev->bus != &fsl_mc_bus_type)) |
---|
| 168 | + return -EINVAL; |
---|
| 169 | + |
---|
| 170 | + if (count >= (PAGE_SIZE - 1)) |
---|
| 171 | + return -EINVAL; |
---|
| 172 | + |
---|
| 173 | + driver_override = kstrndup(buf, count, GFP_KERNEL); |
---|
| 174 | + if (!driver_override) |
---|
| 175 | + return -ENOMEM; |
---|
| 176 | + |
---|
| 177 | + cp = strchr(driver_override, '\n'); |
---|
| 178 | + if (cp) |
---|
| 179 | + *cp = '\0'; |
---|
| 180 | + |
---|
| 181 | + if (strlen(driver_override)) { |
---|
| 182 | + mc_dev->driver_override = driver_override; |
---|
| 183 | + } else { |
---|
| 184 | + kfree(driver_override); |
---|
| 185 | + mc_dev->driver_override = NULL; |
---|
| 186 | + } |
---|
| 187 | + |
---|
| 188 | + kfree(old); |
---|
| 189 | + |
---|
| 190 | + return count; |
---|
| 191 | +} |
---|
| 192 | + |
---|
| 193 | +static ssize_t driver_override_show(struct device *dev, |
---|
| 194 | + struct device_attribute *attr, char *buf) |
---|
| 195 | +{ |
---|
| 196 | + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); |
---|
| 197 | + |
---|
| 198 | + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override); |
---|
| 199 | +} |
---|
| 200 | +static DEVICE_ATTR_RW(driver_override); |
---|
| 201 | + |
---|
140 | 202 | static struct attribute *fsl_mc_dev_attrs[] = { |
---|
141 | 203 | &dev_attr_modalias.attr, |
---|
| 204 | + &dev_attr_driver_override.attr, |
---|
142 | 205 | NULL, |
---|
143 | 206 | }; |
---|
144 | 207 | |
---|
.. | .. |
---|
148 | 211 | .name = "fsl-mc", |
---|
149 | 212 | .match = fsl_mc_bus_match, |
---|
150 | 213 | .uevent = fsl_mc_bus_uevent, |
---|
| 214 | + .dma_configure = fsl_mc_dma_configure, |
---|
151 | 215 | .dev_groups = fsl_mc_dev_groups, |
---|
152 | 216 | }; |
---|
153 | 217 | EXPORT_SYMBOL_GPL(fsl_mc_bus_type); |
---|
.. | .. |
---|
155 | 219 | struct device_type fsl_mc_bus_dprc_type = { |
---|
156 | 220 | .name = "fsl_mc_bus_dprc" |
---|
157 | 221 | }; |
---|
| 222 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dprc_type); |
---|
158 | 223 | |
---|
159 | 224 | struct device_type fsl_mc_bus_dpni_type = { |
---|
160 | 225 | .name = "fsl_mc_bus_dpni" |
---|
161 | 226 | }; |
---|
| 227 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpni_type); |
---|
162 | 228 | |
---|
163 | 229 | struct device_type fsl_mc_bus_dpio_type = { |
---|
164 | 230 | .name = "fsl_mc_bus_dpio" |
---|
165 | 231 | }; |
---|
| 232 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpio_type); |
---|
166 | 233 | |
---|
167 | 234 | struct device_type fsl_mc_bus_dpsw_type = { |
---|
168 | 235 | .name = "fsl_mc_bus_dpsw" |
---|
169 | 236 | }; |
---|
| 237 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpsw_type); |
---|
170 | 238 | |
---|
171 | 239 | struct device_type fsl_mc_bus_dpbp_type = { |
---|
172 | 240 | .name = "fsl_mc_bus_dpbp" |
---|
173 | 241 | }; |
---|
| 242 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpbp_type); |
---|
174 | 243 | |
---|
175 | 244 | struct device_type fsl_mc_bus_dpcon_type = { |
---|
176 | 245 | .name = "fsl_mc_bus_dpcon" |
---|
177 | 246 | }; |
---|
| 247 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpcon_type); |
---|
178 | 248 | |
---|
179 | 249 | struct device_type fsl_mc_bus_dpmcp_type = { |
---|
180 | 250 | .name = "fsl_mc_bus_dpmcp" |
---|
181 | 251 | }; |
---|
| 252 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmcp_type); |
---|
182 | 253 | |
---|
183 | 254 | struct device_type fsl_mc_bus_dpmac_type = { |
---|
184 | 255 | .name = "fsl_mc_bus_dpmac" |
---|
185 | 256 | }; |
---|
| 257 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmac_type); |
---|
186 | 258 | |
---|
187 | 259 | struct device_type fsl_mc_bus_dprtc_type = { |
---|
188 | 260 | .name = "fsl_mc_bus_dprtc" |
---|
189 | 261 | }; |
---|
| 262 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dprtc_type); |
---|
| 263 | + |
---|
| 264 | +struct device_type fsl_mc_bus_dpseci_type = { |
---|
| 265 | + .name = "fsl_mc_bus_dpseci" |
---|
| 266 | +}; |
---|
| 267 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpseci_type); |
---|
| 268 | + |
---|
| 269 | +struct device_type fsl_mc_bus_dpdmux_type = { |
---|
| 270 | + .name = "fsl_mc_bus_dpdmux" |
---|
| 271 | +}; |
---|
| 272 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmux_type); |
---|
| 273 | + |
---|
| 274 | +struct device_type fsl_mc_bus_dpdcei_type = { |
---|
| 275 | + .name = "fsl_mc_bus_dpdcei" |
---|
| 276 | +}; |
---|
| 277 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdcei_type); |
---|
| 278 | + |
---|
| 279 | +struct device_type fsl_mc_bus_dpaiop_type = { |
---|
| 280 | + .name = "fsl_mc_bus_dpaiop" |
---|
| 281 | +}; |
---|
| 282 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpaiop_type); |
---|
| 283 | + |
---|
| 284 | +struct device_type fsl_mc_bus_dpci_type = { |
---|
| 285 | + .name = "fsl_mc_bus_dpci" |
---|
| 286 | +}; |
---|
| 287 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpci_type); |
---|
| 288 | + |
---|
| 289 | +struct device_type fsl_mc_bus_dpdmai_type = { |
---|
| 290 | + .name = "fsl_mc_bus_dpdmai" |
---|
| 291 | +}; |
---|
| 292 | +EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmai_type); |
---|
190 | 293 | |
---|
191 | 294 | static struct device_type *fsl_mc_get_device_type(const char *type) |
---|
192 | 295 | { |
---|
.. | .. |
---|
203 | 306 | { &fsl_mc_bus_dpmcp_type, "dpmcp" }, |
---|
204 | 307 | { &fsl_mc_bus_dpmac_type, "dpmac" }, |
---|
205 | 308 | { &fsl_mc_bus_dprtc_type, "dprtc" }, |
---|
| 309 | + { &fsl_mc_bus_dpseci_type, "dpseci" }, |
---|
| 310 | + { &fsl_mc_bus_dpdmux_type, "dpdmux" }, |
---|
| 311 | + { &fsl_mc_bus_dpdcei_type, "dpdcei" }, |
---|
| 312 | + { &fsl_mc_bus_dpaiop_type, "dpaiop" }, |
---|
| 313 | + { &fsl_mc_bus_dpci_type, "dpci" }, |
---|
| 314 | + { &fsl_mc_bus_dpdmai_type, "dpdmai" }, |
---|
206 | 315 | { NULL, NULL } |
---|
207 | 316 | }; |
---|
208 | 317 | int i; |
---|
.. | .. |
---|
312 | 421 | */ |
---|
313 | 422 | static int mc_get_version(struct fsl_mc_io *mc_io, |
---|
314 | 423 | u32 cmd_flags, |
---|
315 | | - struct mc_version *mc_ver_info) |
---|
| 424 | + struct fsl_mc_version *mc_ver_info) |
---|
316 | 425 | { |
---|
317 | 426 | struct fsl_mc_command cmd = { 0 }; |
---|
318 | 427 | struct dpmng_rsp_get_version *rsp_params; |
---|
.. | .. |
---|
338 | 447 | } |
---|
339 | 448 | |
---|
340 | 449 | /** |
---|
| 450 | + * fsl_mc_get_version - function to retrieve the MC f/w version information |
---|
| 451 | + * |
---|
| 452 | + * Return: mc version when called after fsl-mc-bus probe; NULL otherwise. |
---|
| 453 | + */ |
---|
| 454 | +struct fsl_mc_version *fsl_mc_get_version(void) |
---|
| 455 | +{ |
---|
| 456 | + if (mc_version.major) |
---|
| 457 | + return &mc_version; |
---|
| 458 | + |
---|
| 459 | + return NULL; |
---|
| 460 | +} |
---|
| 461 | +EXPORT_SYMBOL_GPL(fsl_mc_get_version); |
---|
| 462 | + |
---|
| 463 | +/** |
---|
341 | 464 | * fsl_mc_get_root_dprc - function to traverse to the root dprc |
---|
342 | 465 | */ |
---|
343 | | -static void fsl_mc_get_root_dprc(struct device *dev, |
---|
344 | | - struct device **root_dprc_dev) |
---|
| 466 | +void fsl_mc_get_root_dprc(struct device *dev, |
---|
| 467 | + struct device **root_dprc_dev) |
---|
345 | 468 | { |
---|
346 | 469 | if (!dev) { |
---|
347 | 470 | *root_dprc_dev = NULL; |
---|
.. | .. |
---|
382 | 505 | } |
---|
383 | 506 | |
---|
384 | 507 | static int get_dprc_icid(struct fsl_mc_io *mc_io, |
---|
385 | | - int container_id, u16 *icid) |
---|
| 508 | + int container_id, u32 *icid) |
---|
386 | 509 | { |
---|
387 | 510 | struct dprc_attributes attr; |
---|
388 | 511 | int error; |
---|
.. | .. |
---|
471 | 594 | "dprc_get_obj_region() failed: %d\n", error); |
---|
472 | 595 | goto error_cleanup_regions; |
---|
473 | 596 | } |
---|
474 | | - |
---|
475 | | - error = translate_mc_addr(mc_dev, mc_region_type, |
---|
| 597 | + /* |
---|
| 598 | + * Older MC only returned region offset and no base address |
---|
| 599 | + * If base address is in the region_desc use it otherwise |
---|
| 600 | + * revert to old mechanism |
---|
| 601 | + */ |
---|
| 602 | + if (region_desc.base_address) { |
---|
| 603 | + regions[i].start = region_desc.base_address + |
---|
| 604 | + region_desc.base_offset; |
---|
| 605 | + } else { |
---|
| 606 | + error = translate_mc_addr(mc_dev, mc_region_type, |
---|
476 | 607 | region_desc.base_offset, |
---|
477 | 608 | ®ions[i].start); |
---|
| 609 | + |
---|
| 610 | + /* |
---|
| 611 | + * Some versions of the MC firmware wrongly report |
---|
| 612 | + * 0 for register base address of the DPMCP associated |
---|
| 613 | + * with child DPRC objects thus rendering them unusable. |
---|
| 614 | + * This is particularly troublesome in ACPI boot |
---|
| 615 | + * scenarios where the legacy way of extracting this |
---|
| 616 | + * base address from the device tree does not apply. |
---|
| 617 | + * Given that DPMCPs share the same base address, |
---|
| 618 | + * workaround this by using the base address extracted |
---|
| 619 | + * from the root DPRC container. |
---|
| 620 | + */ |
---|
| 621 | + if (is_fsl_mc_bus_dprc(mc_dev) && |
---|
| 622 | + regions[i].start == region_desc.base_offset) |
---|
| 623 | + regions[i].start += mc_portal_base_phys_addr; |
---|
| 624 | + } |
---|
| 625 | + |
---|
478 | 626 | if (error < 0) { |
---|
479 | 627 | dev_err(parent_dev, |
---|
480 | 628 | "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", |
---|
.. | .. |
---|
485 | 633 | |
---|
486 | 634 | regions[i].end = regions[i].start + region_desc.size - 1; |
---|
487 | 635 | regions[i].name = "fsl-mc object MMIO region"; |
---|
488 | | - regions[i].flags = IORESOURCE_IO; |
---|
489 | | - if (region_desc.flags & DPRC_REGION_CACHEABLE) |
---|
490 | | - regions[i].flags |= IORESOURCE_CACHEABLE; |
---|
| 636 | + regions[i].flags = region_desc.flags & IORESOURCE_BITS; |
---|
| 637 | + regions[i].flags |= IORESOURCE_MEM; |
---|
491 | 638 | } |
---|
492 | 639 | |
---|
493 | 640 | mc_dev->regions = regions; |
---|
.. | .. |
---|
549 | 696 | if (!mc_bus) |
---|
550 | 697 | return -ENOMEM; |
---|
551 | 698 | |
---|
| 699 | + mutex_init(&mc_bus->scan_mutex); |
---|
552 | 700 | mc_dev = &mc_bus->mc_dev; |
---|
553 | 701 | } else { |
---|
554 | 702 | /* |
---|
.. | .. |
---|
616 | 764 | mc_dev->icid = parent_mc_dev->icid; |
---|
617 | 765 | mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; |
---|
618 | 766 | mc_dev->dev.dma_mask = &mc_dev->dma_mask; |
---|
| 767 | + mc_dev->dev.coherent_dma_mask = mc_dev->dma_mask; |
---|
619 | 768 | dev_set_msi_domain(&mc_dev->dev, |
---|
620 | 769 | dev_get_msi_domain(&parent_mc_dev->dev)); |
---|
621 | 770 | } |
---|
.. | .. |
---|
632 | 781 | if (error < 0) |
---|
633 | 782 | goto error_cleanup_dev; |
---|
634 | 783 | } |
---|
635 | | - |
---|
636 | | - /* Objects are coherent, unless 'no shareability' flag set. */ |
---|
637 | | - if (!(obj_desc->flags & FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY)) |
---|
638 | | - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true); |
---|
639 | 784 | |
---|
640 | 785 | /* |
---|
641 | 786 | * The device-specific probe callback will get invoked by device_add() |
---|
.. | .. |
---|
670 | 815 | */ |
---|
671 | 816 | void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) |
---|
672 | 817 | { |
---|
| 818 | + kfree(mc_dev->driver_override); |
---|
| 819 | + mc_dev->driver_override = NULL; |
---|
| 820 | + |
---|
673 | 821 | /* |
---|
674 | 822 | * The device-specific remove callback will get invoked by device_del() |
---|
675 | 823 | */ |
---|
.. | .. |
---|
677 | 825 | put_device(&mc_dev->dev); |
---|
678 | 826 | } |
---|
679 | 827 | EXPORT_SYMBOL_GPL(fsl_mc_device_remove); |
---|
| 828 | + |
---|
| 829 | +struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev) |
---|
| 830 | +{ |
---|
| 831 | + struct fsl_mc_device *mc_bus_dev, *endpoint; |
---|
| 832 | + struct fsl_mc_obj_desc endpoint_desc = {{ 0 }}; |
---|
| 833 | + struct dprc_endpoint endpoint1 = {{ 0 }}; |
---|
| 834 | + struct dprc_endpoint endpoint2 = {{ 0 }}; |
---|
| 835 | + int state, err; |
---|
| 836 | + |
---|
| 837 | + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); |
---|
| 838 | + strcpy(endpoint1.type, mc_dev->obj_desc.type); |
---|
| 839 | + endpoint1.id = mc_dev->obj_desc.id; |
---|
| 840 | + |
---|
| 841 | + err = dprc_get_connection(mc_bus_dev->mc_io, 0, |
---|
| 842 | + mc_bus_dev->mc_handle, |
---|
| 843 | + &endpoint1, &endpoint2, |
---|
| 844 | + &state); |
---|
| 845 | + |
---|
| 846 | + if (err == -ENOTCONN || state == -1) |
---|
| 847 | + return ERR_PTR(-ENOTCONN); |
---|
| 848 | + |
---|
| 849 | + if (err < 0) { |
---|
| 850 | + dev_err(&mc_bus_dev->dev, "dprc_get_connection() = %d\n", err); |
---|
| 851 | + return ERR_PTR(err); |
---|
| 852 | + } |
---|
| 853 | + |
---|
| 854 | + strcpy(endpoint_desc.type, endpoint2.type); |
---|
| 855 | + endpoint_desc.id = endpoint2.id; |
---|
| 856 | + endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev); |
---|
| 857 | + |
---|
| 858 | + return endpoint; |
---|
| 859 | +} |
---|
| 860 | +EXPORT_SYMBOL_GPL(fsl_mc_get_endpoint); |
---|
680 | 861 | |
---|
681 | 862 | static int parse_mc_ranges(struct device *dev, |
---|
682 | 863 | int *paddr_cells, |
---|
.. | .. |
---|
693 | 874 | *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); |
---|
694 | 875 | if (!(*ranges_start) || !ranges_len) { |
---|
695 | 876 | dev_warn(dev, |
---|
696 | | - "missing or empty ranges property for device tree node '%s'\n", |
---|
697 | | - mc_node->name); |
---|
| 877 | + "missing or empty ranges property for device tree node '%pOFn'\n", |
---|
| 878 | + mc_node); |
---|
698 | 879 | return 0; |
---|
699 | 880 | } |
---|
700 | 881 | |
---|
.. | .. |
---|
717 | 898 | |
---|
718 | 899 | tuple_len = range_tuple_cell_count * sizeof(__be32); |
---|
719 | 900 | if (ranges_len % tuple_len != 0) { |
---|
720 | | - dev_err(dev, "malformed ranges property '%s'\n", mc_node->name); |
---|
| 901 | + dev_err(dev, "malformed ranges property '%pOFn'\n", mc_node); |
---|
721 | 902 | return -EINVAL; |
---|
722 | 903 | } |
---|
723 | 904 | |
---|
.. | .. |
---|
794 | 975 | struct fsl_mc_io *mc_io = NULL; |
---|
795 | 976 | int container_id; |
---|
796 | 977 | phys_addr_t mc_portal_phys_addr; |
---|
797 | | - u32 mc_portal_size; |
---|
798 | | - struct mc_version mc_version; |
---|
799 | | - struct resource res; |
---|
| 978 | + u32 mc_portal_size, mc_stream_id; |
---|
| 979 | + struct resource *plat_res; |
---|
800 | 980 | |
---|
801 | 981 | mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); |
---|
802 | 982 | if (!mc) |
---|
.. | .. |
---|
804 | 984 | |
---|
805 | 985 | platform_set_drvdata(pdev, mc); |
---|
806 | 986 | |
---|
| 987 | + plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
| 988 | + if (plat_res) { |
---|
| 989 | + mc->fsl_mc_regs = devm_ioremap_resource(&pdev->dev, plat_res); |
---|
| 990 | + if (IS_ERR(mc->fsl_mc_regs)) |
---|
| 991 | + return PTR_ERR(mc->fsl_mc_regs); |
---|
| 992 | + } |
---|
| 993 | + |
---|
| 994 | + if (mc->fsl_mc_regs && IS_ENABLED(CONFIG_ACPI) && |
---|
| 995 | + !dev_of_node(&pdev->dev)) { |
---|
| 996 | + mc_stream_id = readl(mc->fsl_mc_regs + FSL_MC_FAPR); |
---|
| 997 | + /* |
---|
| 998 | + * HW ORs the PL and BMT bit, places the result in bit 15 of |
---|
| 999 | + * the StreamID and ORs in the ICID. Calculate it accordingly. |
---|
| 1000 | + */ |
---|
| 1001 | + mc_stream_id = (mc_stream_id & 0xffff) | |
---|
| 1002 | + ((mc_stream_id & (MC_FAPR_PL | MC_FAPR_BMT)) ? |
---|
| 1003 | + 0x4000 : 0); |
---|
| 1004 | + error = acpi_dma_configure_id(&pdev->dev, DEV_DMA_COHERENT, |
---|
| 1005 | + &mc_stream_id); |
---|
| 1006 | + if (error) |
---|
| 1007 | + dev_warn(&pdev->dev, "failed to configure dma: %d.\n", |
---|
| 1008 | + error); |
---|
| 1009 | + } |
---|
| 1010 | + |
---|
807 | 1011 | /* |
---|
808 | 1012 | * Get physical address of MC portal for the root DPRC: |
---|
809 | 1013 | */ |
---|
810 | | - error = of_address_to_resource(pdev->dev.of_node, 0, &res); |
---|
811 | | - if (error < 0) { |
---|
812 | | - dev_err(&pdev->dev, |
---|
813 | | - "of_address_to_resource() failed for %pOF\n", |
---|
814 | | - pdev->dev.of_node); |
---|
815 | | - return error; |
---|
816 | | - } |
---|
| 1014 | + plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
| 1015 | + mc_portal_phys_addr = plat_res->start; |
---|
| 1016 | + mc_portal_size = resource_size(plat_res); |
---|
| 1017 | + mc_portal_base_phys_addr = mc_portal_phys_addr & ~0x3ffffff; |
---|
817 | 1018 | |
---|
818 | | - mc_portal_phys_addr = res.start; |
---|
819 | | - mc_portal_size = resource_size(&res); |
---|
820 | 1019 | error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, |
---|
821 | 1020 | mc_portal_size, NULL, |
---|
822 | 1021 | FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io); |
---|
.. | .. |
---|
833 | 1032 | dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n", |
---|
834 | 1033 | mc_version.major, mc_version.minor, mc_version.revision); |
---|
835 | 1034 | |
---|
836 | | - error = get_mc_addr_translation_ranges(&pdev->dev, |
---|
837 | | - &mc->translation_ranges, |
---|
838 | | - &mc->num_translation_ranges); |
---|
839 | | - if (error < 0) |
---|
840 | | - goto error_cleanup_mc_io; |
---|
| 1035 | + if (dev_of_node(&pdev->dev)) { |
---|
| 1036 | + error = get_mc_addr_translation_ranges(&pdev->dev, |
---|
| 1037 | + &mc->translation_ranges, |
---|
| 1038 | + &mc->num_translation_ranges); |
---|
| 1039 | + if (error < 0) |
---|
| 1040 | + goto error_cleanup_mc_io; |
---|
| 1041 | + } |
---|
841 | 1042 | |
---|
842 | 1043 | error = dprc_get_container_id(mc_io, 0, &container_id); |
---|
843 | 1044 | if (error < 0) { |
---|
.. | .. |
---|
864 | 1065 | goto error_cleanup_mc_io; |
---|
865 | 1066 | |
---|
866 | 1067 | mc->root_mc_bus_dev = mc_bus_dev; |
---|
| 1068 | + mc_bus_dev->dev.fwnode = pdev->dev.fwnode; |
---|
867 | 1069 | return 0; |
---|
868 | 1070 | |
---|
869 | 1071 | error_cleanup_mc_io: |
---|
.. | .. |
---|
897 | 1099 | |
---|
898 | 1100 | MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table); |
---|
899 | 1101 | |
---|
| 1102 | +static const struct acpi_device_id fsl_mc_bus_acpi_match_table[] = { |
---|
| 1103 | + {"NXP0008", 0 }, |
---|
| 1104 | + { } |
---|
| 1105 | +}; |
---|
| 1106 | +MODULE_DEVICE_TABLE(acpi, fsl_mc_bus_acpi_match_table); |
---|
| 1107 | + |
---|
900 | 1108 | static struct platform_driver fsl_mc_bus_driver = { |
---|
901 | 1109 | .driver = { |
---|
902 | 1110 | .name = "fsl_mc_bus", |
---|
903 | 1111 | .pm = NULL, |
---|
904 | 1112 | .of_match_table = fsl_mc_bus_match_table, |
---|
| 1113 | + .acpi_match_table = fsl_mc_bus_acpi_match_table, |
---|
905 | 1114 | }, |
---|
906 | 1115 | .probe = fsl_mc_bus_probe, |
---|
907 | 1116 | .remove = fsl_mc_bus_remove, |
---|