Lines Matching +full:mc +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Copyright 2019-2020 NXP
14 #include <linux/fsl/mc.h>
16 #include "fsl-mc-private.h"
28 return mc_dev->obj_desc.id == obj_desc->id && in fsl_mc_device_match()
29 strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0; in fsl_mc_device_match()
34 if (strcmp(obj->type, "dpmcp") == 0 || in fsl_mc_obj_desc_is_allocatable()
35 strcmp(obj->type, "dpcon") == 0 || in fsl_mc_obj_desc_is_allocatable()
36 strcmp(obj->type, "dpbp") == 0) in fsl_mc_obj_desc_is_allocatable()
54 for (i = 0; i < objs->child_count; i++) { in __fsl_mc_device_remove_if_not_in_mc()
55 struct fsl_mc_obj_desc *obj_desc = &objs->child_array[i]; in __fsl_mc_device_remove_if_not_in_mc()
57 if (strlen(obj_desc->type) != 0 && in __fsl_mc_device_remove_if_not_in_mc()
62 if (i == objs->child_count) in __fsl_mc_device_remove_if_not_in_mc()
78 * dprc_remove_devices - Removes devices for objects removed from a DPRC
80 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
82 * present in the DPRC in the MC.
85 * Synchronizes the state of the Linux bus driver with the actual state of
86 * the MC by removing devices that represent MC objects that have
96 * but not in the MC: in dprc_remove_devices()
102 device_for_each_child(&mc_bus_dev->dev, &objs, in dprc_remove_devices()
106 * There are no child objects for this DPRC in the MC. in dprc_remove_devices()
109 device_for_each_child(&mc_bus_dev->dev, NULL, in dprc_remove_devices()
128 dev = device_find_child(&mc_bus_dev->dev, obj_desc, in fsl_mc_device_lookup()
135 * check_plugged_state_change - Check change in an MC object's plugged state
137 * @mc_dev: pointer to the fsl-mc device for a given MC object
138 * @obj_desc: pointer to the MC object's descriptor in the MC
140 * If the plugged state has changed from unplugged to plugged, the fsl-mc
142 * If the plugged state has changed from plugged to unplugged, the fsl-mc
150 obj_desc->state & FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
153 (mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED)) { in check_plugged_state_change()
155 mc_dev->obj_desc.state |= FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
156 error = device_attach(&mc_dev->dev); in check_plugged_state_change()
158 dev_err(&mc_dev->dev, in check_plugged_state_change()
163 mc_dev->obj_desc.state &= ~FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
164 device_release_driver(&mc_dev->dev); in check_plugged_state_change()
181 put_device(&child_dev->dev); in fsl_mc_obj_device_add()
183 error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev, in fsl_mc_obj_device_add()
191 * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
193 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
198 * Synchronizes the state of the Linux bus driver with the actual
199 * state of the MC by adding objects that have been newly discovered
212 if (strlen(obj_desc->type) > 0 && in dprc_add_new_devices()
220 if (strlen(obj_desc->type) > 0 && in dprc_add_new_devices()
227 * dprc_scan_objects - Discover objects in a DPRC
229 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
234 * state of the Linux bus driver, MC by adding and removing
237 * dpbp, dpmcp) and non-allocatable devices (e.g., dprc, dpni).
238 * All allocatable devices needed to be probed before all non-allocatable
239 * devices, to ensure that device drivers for non-allocatable
243 * of the device drivers for the non-allocatable devices.
251 unsigned int irq_count = mc_bus_dev->obj_desc.irq_count; in dprc_scan_objects()
255 error = dprc_get_obj_count(mc_bus_dev->mc_io, in dprc_scan_objects()
257 mc_bus_dev->mc_handle, in dprc_scan_objects()
260 dev_err(&mc_bus_dev->dev, "dprc_get_obj_count() failed: %d\n", in dprc_scan_objects()
269 devm_kmalloc_array(&mc_bus_dev->dev, num_child_objects, in dprc_scan_objects()
273 return -ENOMEM; in dprc_scan_objects()
283 error = dprc_get_obj(mc_bus_dev->mc_io, in dprc_scan_objects()
285 mc_bus_dev->mc_handle, in dprc_scan_objects()
288 dev_err(&mc_bus_dev->dev, in dprc_scan_objects()
295 obj_desc->type[0] = '\0'; in dprc_scan_objects()
296 obj_desc->id = error; in dprc_scan_objects()
303 * are coherent regardless of what the MC reports. in dprc_scan_objects()
305 if ((strcmp(obj_desc->type, "dpseci") == 0) && in dprc_scan_objects()
306 (obj_desc->ver_major < 4)) in dprc_scan_objects()
307 obj_desc->flags |= in dprc_scan_objects()
310 irq_count += obj_desc->irq_count; in dprc_scan_objects()
311 dev_dbg(&mc_bus_dev->dev, in dprc_scan_objects()
313 obj_desc->type, obj_desc->id); in dprc_scan_objects()
317 dev_err(&mc_bus_dev->dev, in dprc_scan_objects()
327 if (dev_get_msi_domain(&mc_bus_dev->dev)) { in dprc_scan_objects()
329 dev_warn(&mc_bus_dev->dev, in dprc_scan_objects()
334 if (alloc_interrupts && !mc_bus->irq_resources) { in dprc_scan_objects()
349 devm_kfree(&mc_bus_dev->dev, child_obj_desc_array); in dprc_scan_objects()
355 * dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state
357 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
361 * bus driver with the actual state of the MC by adding and removing
375 mutex_lock(&mc_bus->scan_mutex); in dprc_scan_container()
377 mutex_unlock(&mc_bus->scan_mutex); in dprc_scan_container()
384 * dprc_irq0_handler - Regular ISR for DPRC interrupt 0
395 * dprc_irq0_handler_thread - Handler thread function for DPRC interrupt 0
407 struct fsl_mc_io *mc_io = mc_dev->mc_io; in dprc_irq0_handler_thread()
408 int irq = mc_dev->irqs[0]->virq; in dprc_irq0_handler_thread()
413 if (!(mc_dev->flags & FSL_MC_IS_DPRC)) in dprc_irq0_handler_thread()
416 mutex_lock(&mc_bus->scan_mutex); in dprc_irq0_handler_thread()
421 error = dprc_get_irq_status(mc_io, 0, mc_dev->mc_handle, 0, in dprc_irq0_handler_thread()
429 error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, in dprc_irq0_handler_thread()
446 * If the error is -ENXIO, we ignore it, as it indicates in dprc_irq0_handler_thread()
448 * an object was removed from the DPRC in the MC, while in dprc_irq0_handler_thread()
451 if (error != -ENXIO) { in dprc_irq0_handler_thread()
461 mutex_unlock(&mc_bus->scan_mutex); in dprc_irq0_handler_thread()
472 struct fsl_mc_io *mc_io = mc_dev->mc_io; in disable_dprc_irq()
477 error = dprc_set_irq_enable(mc_io, 0, mc_dev->mc_handle, 0, 0); in disable_dprc_irq()
479 dev_err(&mc_dev->dev, in disable_dprc_irq()
488 error = dprc_set_irq_mask(mc_io, 0, mc_dev->mc_handle, 0, 0x0); in disable_dprc_irq()
490 dev_err(&mc_dev->dev, in disable_dprc_irq()
499 error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, ~0x0U); in disable_dprc_irq()
501 dev_err(&mc_dev->dev, in disable_dprc_irq()
507 mc_bus->irq_enabled = 0; in disable_dprc_irq()
516 return mc_bus->irq_enabled; in get_dprc_irq_state()
522 struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; in register_dprc_irq_handler()
525 * NOTE: devm_request_threaded_irq() invokes the device-specific in register_dprc_irq_handler()
528 error = devm_request_threaded_irq(&mc_dev->dev, in register_dprc_irq_handler()
529 irq->virq, in register_dprc_irq_handler()
533 dev_name(&mc_dev->dev), in register_dprc_irq_handler()
534 &mc_dev->dev); in register_dprc_irq_handler()
536 dev_err(&mc_dev->dev, in register_dprc_irq_handler()
553 error = dprc_set_irq_mask(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, in enable_dprc_irq()
556 dev_err(&mc_dev->dev, in enable_dprc_irq()
566 error = dprc_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, 1); in enable_dprc_irq()
568 dev_err(&mc_dev->dev, in enable_dprc_irq()
575 mc_bus->irq_enabled = 1; in enable_dprc_irq()
611 * dprc_setup - opens and creates a mc_io for DPRC
613 * @mc_dev: Pointer to fsl-mc device representing a DPRC
615 * It opens the physical DPRC in the MC.
616 * It configures the DPRC portal used to communicate with MC
621 struct device *parent_dev = mc_dev->dev.parent; in dprc_setup()
632 return -EINVAL; in dprc_setup()
634 if (dev_get_msi_domain(&mc_dev->dev)) in dprc_setup()
635 return -EINVAL; in dprc_setup()
637 if (!mc_dev->mc_io) { in dprc_setup()
642 return -EINVAL; in dprc_setup()
644 if (mc_dev->obj_desc.region_count == 0) in dprc_setup()
645 return -EINVAL; in dprc_setup()
647 region_size = resource_size(mc_dev->regions); in dprc_setup()
649 error = fsl_create_mc_io(&mc_dev->dev, in dprc_setup()
650 mc_dev->regions[0].start, in dprc_setup()
654 &mc_dev->mc_io); in dprc_setup()
662 return -EPROBE_DEFER; in dprc_setup()
666 mc_msi_domain = fsl_mc_find_msi_domain(&mc_dev->dev); in dprc_setup()
668 dev_warn(&mc_dev->dev, in dprc_setup()
669 "WARNING: MC bus without interrupt support\n"); in dprc_setup()
671 dev_set_msi_domain(&mc_dev->dev, mc_msi_domain); in dprc_setup()
675 error = dprc_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id, in dprc_setup()
676 &mc_dev->mc_handle); in dprc_setup()
678 dev_err(&mc_dev->dev, "dprc_open() failed: %d\n", error); in dprc_setup()
682 error = dprc_get_attributes(mc_dev->mc_io, 0, mc_dev->mc_handle, in dprc_setup()
683 &mc_bus->dprc_attr); in dprc_setup()
685 dev_err(&mc_dev->dev, "dprc_get_attributes() failed: %d\n", in dprc_setup()
690 error = dprc_get_api_version(mc_dev->mc_io, 0, in dprc_setup()
694 dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n", in dprc_setup()
700 dev_err(&mc_dev->dev, in dprc_setup()
703 error = -ENOTSUPP; in dprc_setup()
710 (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); in dprc_setup()
714 dev_set_msi_domain(&mc_dev->dev, NULL); in dprc_setup()
717 fsl_destroy_mc_io(mc_dev->mc_io); in dprc_setup()
718 mc_dev->mc_io = NULL; in dprc_setup()
729 * dprc_probe - callback invoked when a DPRC is being bound to this driver
731 * @mc_dev: Pointer to fsl-mc device representing a DPRC
733 * It opens the physical DPRC in the MC.
734 * It scans the DPRC to discover the MC objects contained in it.
735 * It creates the interrupt pool for the MC bus associated with the DPRC.
747 * Discover MC objects in DPRC object: in dprc_probe()
754 * Configure interrupt for the DPRC object associated with this MC bus: in dprc_probe()
760 dev_info(&mc_dev->dev, "DPRC device bound to driver"); in dprc_probe()
764 device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); in dprc_probe()
775 struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; in dprc_teardown_irq()
779 devm_free_irq(&mc_dev->dev, irq->virq, &mc_dev->dev); in dprc_teardown_irq()
785 * dprc_cleanup - function that cleanups a DPRC
787 * @mc_dev: Pointer to fsl-mc device representing the DPRC
789 * It closes the DPRC device in the MC.
790 * It destroys the interrupt pool associated with this MC bus.
802 return -EINVAL; in dprc_cleanup()
804 if (dev_get_msi_domain(&mc_dev->dev)) { in dprc_cleanup()
806 dev_set_msi_domain(&mc_dev->dev, NULL); in dprc_cleanup()
814 if (!mc_dev->mc_io) { in dprc_cleanup()
815 dev_err(&mc_dev->dev, "mc_io is NULL, tear down cannot be performed in firmware\n"); in dprc_cleanup()
816 return -EINVAL; in dprc_cleanup()
819 error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); in dprc_cleanup()
821 dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error); in dprc_cleanup()
823 if (!fsl_mc_is_root_dprc(&mc_dev->dev)) { in dprc_cleanup()
824 fsl_destroy_mc_io(mc_dev->mc_io); in dprc_cleanup()
825 mc_dev->mc_io = NULL; in dprc_cleanup()
835 * dprc_remove - callback invoked when a DPRC is being unbound from this driver
837 * @mc_dev: Pointer to fsl-mc device representing the DPRC
839 * It removes the DPRC's child objects from Linux (not from the MC) and
840 * closes the DPRC device in the MC.
842 * It destroys the interrupt pool associated with this MC bus.
848 if (!mc_bus->irq_resources) { in dprc_remove()
849 dev_err(&mc_dev->dev, "No irq resources, so unbinding the device failed\n"); in dprc_remove()
853 if (dev_get_msi_domain(&mc_dev->dev)) in dprc_remove()
856 device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); in dprc_remove()
860 dev_info(&mc_dev->dev, "DPRC device unbound from driver"); in dprc_remove()