Lines Matching +full:qoriq +full:- +full:mc +full:- +full:dpmac
1 // SPDX-License-Identifier: GPL-2.0
3 * Freescale Management Complex (MC) bus driver
5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Copyright 2019-2020 NXP
11 #define pr_fmt(fmt) "fsl-mc: " fmt
21 #include <linux/dma-mapping.h>
24 #include <linux/dma-map-ops.h>
26 #include "fsl-mc-private.h"
29 * Default DMA mask for devices on a fsl-mc bus
36 * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
37 * @root_mc_bus_dev: fsl-mc device representing the root DPRC
50 * struct fsl_mc_addr_translation_range - bus to system address translation
52 * @mc_region_type: Type of MC region for the range being translated
53 * @start_mc_offset: Start MC offset of the range being translated
54 * @end_mc_offset: MC offset of the first byte after the range (last MC
55 * offset of the range is end_mc_offset - 1)
76 * fsl_mc_bus_match - device to driver matching callback
77 * @dev: the fsl-mc device to match against
78 * @drv: the device driver to search for matching fsl-mc object type
91 if (mc_dev->driver_override) { in fsl_mc_bus_match()
92 found = !strcmp(mc_dev->driver_override, mc_drv->driver.name); in fsl_mc_bus_match()
96 if (!mc_drv->match_id_table) in fsl_mc_bus_match()
103 if ((mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED) == 0 && in fsl_mc_bus_match()
104 !fsl_mc_is_root_dprc(&mc_dev->dev)) in fsl_mc_bus_match()
111 for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) { in fsl_mc_bus_match()
112 if (id->vendor == mc_dev->obj_desc.vendor && in fsl_mc_bus_match()
113 strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) { in fsl_mc_bus_match()
126 * fsl_mc_bus_uevent - callback invoked when a device is added
132 if (add_uevent_var(env, "MODALIAS=fsl-mc:v%08Xd%s", in fsl_mc_bus_uevent()
133 mc_dev->obj_desc.vendor, in fsl_mc_bus_uevent()
134 mc_dev->obj_desc.type)) in fsl_mc_bus_uevent()
135 return -ENOMEM; in fsl_mc_bus_uevent()
144 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); in fsl_mc_dma_configure()
145 u32 input_id = mc_dev->icid; in fsl_mc_dma_configure()
149 dma_dev = dma_dev->parent; in fsl_mc_dma_configure()
152 ret = of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id); in fsl_mc_dma_configure()
156 if (!ret && !mc_drv->driver_managed_dma) { in fsl_mc_dma_configure()
167 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); in fsl_mc_dma_cleanup()
169 if (!mc_drv->driver_managed_dma) in fsl_mc_dma_cleanup()
178 return sprintf(buf, "fsl-mc:v%08Xd%s\n", mc_dev->obj_desc.vendor, in modalias_show()
179 mc_dev->obj_desc.type); in modalias_show()
190 if (WARN_ON(dev->bus != &fsl_mc_bus_type)) in driver_override_store()
191 return -EINVAL; in driver_override_store()
193 ret = driver_set_override(dev, &mc_dev->driver_override, buf, count); in driver_override_store()
205 return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override); in driver_override_show()
227 mutex_lock(&root_mc_bus->scan_mutex); in scan_fsl_mc_bus()
229 mutex_unlock(&root_mc_bus->scan_mutex); in scan_fsl_mc_bus()
241 return -EINVAL; in rescan_store()
262 return -EINVAL; in fsl_mc_bus_set_autorescan()
313 .name = "fsl-mc",
416 { &fsl_mc_bus_dpmac_type, "dpmac" }, in fsl_mc_get_device_type()
442 mc_drv = to_fsl_mc_driver(dev->driver); in fsl_mc_driver_probe()
444 error = mc_drv->probe(mc_dev); in fsl_mc_driver_probe()
446 if (error != -EPROBE_DEFER) in fsl_mc_driver_probe()
456 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); in fsl_mc_driver_remove()
459 mc_drv->remove(mc_dev); in fsl_mc_driver_remove()
466 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); in fsl_mc_driver_shutdown()
469 mc_drv->shutdown(mc_dev); in fsl_mc_driver_shutdown()
473 * __fsl_mc_driver_register - registers a child device driver with the
474 * MC bus
485 mc_driver->driver.owner = owner; in __fsl_mc_driver_register()
486 mc_driver->driver.bus = &fsl_mc_bus_type; in __fsl_mc_driver_register()
488 if (mc_driver->probe) in __fsl_mc_driver_register()
489 mc_driver->driver.probe = fsl_mc_driver_probe; in __fsl_mc_driver_register()
491 if (mc_driver->remove) in __fsl_mc_driver_register()
492 mc_driver->driver.remove = fsl_mc_driver_remove; in __fsl_mc_driver_register()
494 if (mc_driver->shutdown) in __fsl_mc_driver_register()
495 mc_driver->driver.shutdown = fsl_mc_driver_shutdown; in __fsl_mc_driver_register()
497 error = driver_register(&mc_driver->driver); in __fsl_mc_driver_register()
500 mc_driver->driver.name, error); in __fsl_mc_driver_register()
509 * fsl_mc_driver_unregister - unregisters a device driver from the
510 * MC bus
514 driver_unregister(&mc_driver->driver); in fsl_mc_driver_unregister()
519 * mc_get_version() - Retrieves the Management Complex firmware
540 /* send command to mc*/ in mc_get_version()
547 mc_ver_info->revision = le32_to_cpu(rsp_params->revision); in mc_get_version()
548 mc_ver_info->major = le32_to_cpu(rsp_params->version_major); in mc_get_version()
549 mc_ver_info->minor = le32_to_cpu(rsp_params->version_minor); in mc_get_version()
555 * fsl_mc_get_version - function to retrieve the MC f/w version information
557 * Return: mc version when called after fsl-mc-bus probe; NULL otherwise.
569 * fsl_mc_get_root_dprc - function to traverse to the root dprc
580 while (dev_is_fsl_mc((*root_dprc_dev)->parent)) in fsl_mc_get_root_dprc()
581 *root_dprc_dev = (*root_dprc_dev)->parent; in fsl_mc_get_root_dprc()
593 dev_err(mc_io->dev, "dprc_open() failed: %d\n", error); in get_dprc_attr()
600 dev_err(mc_io->dev, "dprc_get_attributes() failed: %d\n", in get_dprc_attr()
631 struct fsl_mc *mc; in translate_mc_addr() local
633 fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); in translate_mc_addr()
634 mc = dev_get_drvdata(root_dprc_dev->parent); in translate_mc_addr()
636 if (mc->num_translation_ranges == 0) { in translate_mc_addr()
644 for (i = 0; i < mc->num_translation_ranges; i++) { in translate_mc_addr()
646 &mc->translation_ranges[i]; in translate_mc_addr()
648 if (mc_region_type == range->mc_region_type && in translate_mc_addr()
649 mc_offset >= range->start_mc_offset && in translate_mc_addr()
650 mc_offset < range->end_mc_offset) { in translate_mc_addr()
651 *phys_addr = range->start_phys_addr + in translate_mc_addr()
652 (mc_offset - range->start_mc_offset); in translate_mc_addr()
657 return -EFAULT; in translate_mc_addr()
666 struct fsl_mc_obj_desc *obj_desc = &mc_dev->obj_desc; in fsl_mc_device_get_mmio_regions()
667 struct device *parent_dev = mc_dev->dev.parent; in fsl_mc_device_get_mmio_regions()
677 * This function should not have been called for this MC object in fsl_mc_device_get_mmio_regions()
681 return -EINVAL; in fsl_mc_device_get_mmio_regions()
684 regions = kmalloc_array(obj_desc->region_count, in fsl_mc_device_get_mmio_regions()
687 return -ENOMEM; in fsl_mc_device_get_mmio_regions()
689 for (i = 0; i < obj_desc->region_count; i++) { in fsl_mc_device_get_mmio_regions()
692 error = dprc_get_obj_region(mc_bus_dev->mc_io, in fsl_mc_device_get_mmio_regions()
694 mc_bus_dev->mc_handle, in fsl_mc_device_get_mmio_regions()
695 obj_desc->type, in fsl_mc_device_get_mmio_regions()
696 obj_desc->id, i, ®ion_desc); in fsl_mc_device_get_mmio_regions()
703 * Older MC only returned region offset and no base address in fsl_mc_device_get_mmio_regions()
716 * Some versions of the MC firmware wrongly report in fsl_mc_device_get_mmio_regions()
733 "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", in fsl_mc_device_get_mmio_regions()
735 obj_desc->type, obj_desc->id, i); in fsl_mc_device_get_mmio_regions()
739 regions[i].end = regions[i].start + region_desc.size - 1; in fsl_mc_device_get_mmio_regions()
740 regions[i].name = "fsl-mc object MMIO region"; in fsl_mc_device_get_mmio_regions()
745 mc_dev->regions = regions; in fsl_mc_device_get_mmio_regions()
754 * fsl_mc_is_root_dprc - function to check if a given device is a root dprc
770 kfree(mc_dev->regions); in fsl_mc_device_release()
779 * Add a newly discovered fsl-mc device to be visible in Linux
796 if (strcmp(obj_desc->type, "dprc") == 0) { in fsl_mc_device_add()
798 * Allocate an MC bus device object: in fsl_mc_device_add()
802 return -ENOMEM; in fsl_mc_device_add()
804 mutex_init(&mc_bus->scan_mutex); in fsl_mc_device_add()
805 mc_dev = &mc_bus->mc_dev; in fsl_mc_device_add()
812 return -ENOMEM; in fsl_mc_device_add()
815 mc_dev->obj_desc = *obj_desc; in fsl_mc_device_add()
816 mc_dev->mc_io = mc_io; in fsl_mc_device_add()
817 device_initialize(&mc_dev->dev); in fsl_mc_device_add()
818 mc_dev->dev.parent = parent_dev; in fsl_mc_device_add()
819 mc_dev->dev.bus = &fsl_mc_bus_type; in fsl_mc_device_add()
820 mc_dev->dev.release = fsl_mc_device_release; in fsl_mc_device_add()
821 mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type); in fsl_mc_device_add()
822 if (!mc_dev->dev.type) { in fsl_mc_device_add()
823 error = -ENODEV; in fsl_mc_device_add()
824 dev_err(parent_dev, "unknown device type %s\n", obj_desc->type); in fsl_mc_device_add()
827 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); in fsl_mc_device_add()
829 if (strcmp(obj_desc->type, "dprc") == 0) { in fsl_mc_device_add()
832 mc_dev->flags |= FSL_MC_IS_DPRC; in fsl_mc_device_add()
837 * parent DPRC's MC portal instead of the child DPRC's MC in fsl_mc_device_add()
842 * given MC object, using the same MC portal. in fsl_mc_device_add()
848 mc_io2 = parent_mc_dev->mc_io; in fsl_mc_device_add()
854 error = -EINVAL; in fsl_mc_device_add()
861 error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); in fsl_mc_device_add()
866 * A non-DPRC object has to be a child of a DPRC, use the in fsl_mc_device_add()
869 mc_dev->icid = parent_mc_dev->icid; in fsl_mc_device_add()
870 mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; in fsl_mc_device_add()
871 mc_dev->dev.dma_mask = &mc_dev->dma_mask; in fsl_mc_device_add()
872 mc_dev->dev.coherent_dma_mask = mc_dev->dma_mask; in fsl_mc_device_add()
873 dev_set_msi_domain(&mc_dev->dev, in fsl_mc_device_add()
874 dev_get_msi_domain(&parent_mc_dev->dev)); in fsl_mc_device_add()
878 * Get MMIO regions for the device from the MC: in fsl_mc_device_add()
883 if (parent_mc_dev && obj_desc->region_count != 0) { in fsl_mc_device_add()
891 * The device-specific probe callback will get invoked by device_add() in fsl_mc_device_add()
893 error = device_add(&mc_dev->dev); in fsl_mc_device_add()
897 dev_name(&mc_dev->dev), error); in fsl_mc_device_add()
901 dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev)); in fsl_mc_device_add()
907 kfree(mc_dev->regions); in fsl_mc_device_add()
918 * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
921 * @mc_dev: Pointer to an fsl-mc device
925 kfree(mc_dev->driver_override); in fsl_mc_device_remove()
926 mc_dev->driver_override = NULL; in fsl_mc_device_remove()
929 * The device-specific remove callback will get invoked by device_del() in fsl_mc_device_remove()
931 device_del(&mc_dev->dev); in fsl_mc_device_remove()
932 put_device(&mc_dev->dev); in fsl_mc_device_remove()
945 mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); in fsl_mc_get_endpoint()
946 strcpy(endpoint1.type, mc_dev->obj_desc.type); in fsl_mc_get_endpoint()
947 endpoint1.id = mc_dev->obj_desc.id; in fsl_mc_get_endpoint()
950 err = dprc_get_connection(mc_bus_dev->mc_io, 0, in fsl_mc_get_endpoint()
951 mc_bus_dev->mc_handle, in fsl_mc_get_endpoint()
955 if (err == -ENOTCONN || state == -1) in fsl_mc_get_endpoint()
956 return ERR_PTR(-ENOTCONN); in fsl_mc_get_endpoint()
959 dev_err(&mc_bus_dev->dev, "dprc_get_connection() = %d\n", err); in fsl_mc_get_endpoint()
970 * yet discovered by the fsl-mc bus, thus the lookup returned NULL. in fsl_mc_get_endpoint()
976 if (mutex_trylock(&mc_bus->scan_mutex)) { in fsl_mc_get_endpoint()
978 mutex_unlock(&mc_bus->scan_mutex); in fsl_mc_get_endpoint()
992 return ERR_PTR(-EPERM); in fsl_mc_get_endpoint()
1007 of_range_parser_init(&parser, dev->of_node); in get_mc_addr_translation_ranges()
1012 * 'fsl,qoriq-mc' node. In this case, identity mapping in get_mc_addr_translation_ranges()
1023 return -ENOMEM; in get_mc_addr_translation_ranges()
1027 r->mc_region_type = range.flags; in get_mc_addr_translation_ranges()
1028 r->start_mc_offset = range.bus_addr; in get_mc_addr_translation_ranges()
1029 r->end_mc_offset = range.bus_addr + range.size; in get_mc_addr_translation_ranges()
1030 r->start_phys_addr = range.cpu_addr; in get_mc_addr_translation_ranges()
1038 * fsl_mc_bus_probe - callback invoked when the root MC bus is being
1045 struct fsl_mc *mc; in fsl_mc_bus_probe() local
1053 mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); in fsl_mc_bus_probe()
1054 if (!mc) in fsl_mc_bus_probe()
1055 return -ENOMEM; in fsl_mc_bus_probe()
1057 platform_set_drvdata(pdev, mc); in fsl_mc_bus_probe()
1061 mc->fsl_mc_regs = devm_ioremap_resource(&pdev->dev, plat_res); in fsl_mc_bus_probe()
1062 if (IS_ERR(mc->fsl_mc_regs)) in fsl_mc_bus_probe()
1063 return PTR_ERR(mc->fsl_mc_regs); in fsl_mc_bus_probe()
1066 if (mc->fsl_mc_regs) { in fsl_mc_bus_probe()
1067 if (IS_ENABLED(CONFIG_ACPI) && !dev_of_node(&pdev->dev)) { in fsl_mc_bus_probe()
1068 mc_stream_id = readl(mc->fsl_mc_regs + FSL_MC_FAPR); in fsl_mc_bus_probe()
1077 error = acpi_dma_configure_id(&pdev->dev, in fsl_mc_bus_probe()
1080 if (error == -EPROBE_DEFER) in fsl_mc_bus_probe()
1083 dev_warn(&pdev->dev, in fsl_mc_bus_probe()
1089 * Some bootloaders pause the MC firmware before booting the in fsl_mc_bus_probe()
1090 * kernel so that MC will not cause faults as soon as the in fsl_mc_bus_probe()
1092 * in place for MC. in fsl_mc_bus_probe()
1093 * At this point MC should have all its SMMU setup done so make in fsl_mc_bus_probe()
1096 writel(readl(mc->fsl_mc_regs + FSL_MC_GCR1) & in fsl_mc_bus_probe()
1098 mc->fsl_mc_regs + FSL_MC_GCR1); in fsl_mc_bus_probe()
1102 * Get physical address of MC portal for the root DPRC: in fsl_mc_bus_probe()
1105 mc_portal_phys_addr = plat_res->start; in fsl_mc_bus_probe()
1109 error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, in fsl_mc_bus_probe()
1117 dev_err(&pdev->dev, in fsl_mc_bus_probe()
1122 dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n", in fsl_mc_bus_probe()
1125 if (dev_of_node(&pdev->dev)) { in fsl_mc_bus_probe()
1126 error = get_mc_addr_translation_ranges(&pdev->dev, in fsl_mc_bus_probe()
1127 &mc->translation_ranges, in fsl_mc_bus_probe()
1128 &mc->num_translation_ranges); in fsl_mc_bus_probe()
1135 dev_err(&pdev->dev, in fsl_mc_bus_probe()
1153 error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); in fsl_mc_bus_probe()
1157 mc->root_mc_bus_dev = mc_bus_dev; in fsl_mc_bus_probe()
1158 mc_bus_dev->dev.fwnode = pdev->dev.fwnode; in fsl_mc_bus_probe()
1167 * fsl_mc_bus_remove - callback invoked when the root MC bus is being
1172 struct fsl_mc *mc = platform_get_drvdata(pdev); in fsl_mc_bus_remove() local
1175 mc_io = mc->root_mc_bus_dev->mc_io; in fsl_mc_bus_remove()
1176 fsl_mc_device_remove(mc->root_mc_bus_dev); in fsl_mc_bus_remove()
1181 if (mc->fsl_mc_regs) { in fsl_mc_bus_remove()
1183 * Pause the MC firmware so that it doesn't crash in certain in fsl_mc_bus_remove()
1186 writel(readl(mc->fsl_mc_regs + FSL_MC_GCR1) | in fsl_mc_bus_remove()
1188 mc->fsl_mc_regs + FSL_MC_GCR1); in fsl_mc_bus_remove()
1193 {.compatible = "fsl,qoriq-mc",},
1235 fsl_mc_regs = ioremap(res->start, resource_size(res)); in fsl_mc_bus_notifier()
1240 * Make sure that the MC firmware is paused before the IOMMU setup for in fsl_mc_bus_notifier()