Lines Matching +full:fsl +full:- +full:mc
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Copyright 2019-2020 NXP
15 #include <linux/fsl/mc.h>
17 #include "fsl-mc-private.h"
29 return mc_dev->obj_desc.id == obj_desc->id && in fsl_mc_device_match()
30 strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0; in fsl_mc_device_match()
35 if (strcmp(obj->type, "dpmcp") == 0 || in fsl_mc_obj_desc_is_allocatable()
36 strcmp(obj->type, "dpcon") == 0 || in fsl_mc_obj_desc_is_allocatable()
37 strcmp(obj->type, "dpbp") == 0) in fsl_mc_obj_desc_is_allocatable()
52 for (i = 0; i < objs->child_count; i++) { in __fsl_mc_device_remove_if_not_in_mc()
53 struct fsl_mc_obj_desc *obj_desc = &objs->child_array[i]; in __fsl_mc_device_remove_if_not_in_mc()
55 if (strlen(obj_desc->type) != 0 && in __fsl_mc_device_remove_if_not_in_mc()
60 if (i == objs->child_count) in __fsl_mc_device_remove_if_not_in_mc()
73 * dprc_remove_devices - Removes devices for objects removed from a DPRC
75 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
77 * present in the DPRC in the MC.
81 * the MC by removing devices that represent MC objects that have
91 * but not in the MC: in dprc_remove_devices()
97 device_for_each_child(&mc_bus_dev->dev, &objs, in dprc_remove_devices()
101 * There are no child objects for this DPRC in the MC. in dprc_remove_devices()
104 device_for_each_child(&mc_bus_dev->dev, NULL, in dprc_remove_devices()
123 dev = device_find_child(&mc_bus_dev->dev, obj_desc, in fsl_mc_device_lookup()
130 * check_plugged_state_change - Check change in an MC object's plugged state
132 * @mc_dev: pointer to the fsl-mc device for a given MC object
133 * @obj_desc: pointer to the MC object's descriptor in the MC
135 * If the plugged state has changed from unplugged to plugged, the fsl-mc
137 * If the plugged state has changed from plugged to unplugged, the fsl-mc
145 obj_desc->state & FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
148 (mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED)) { in check_plugged_state_change()
150 mc_dev->obj_desc.state |= FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
151 error = device_attach(&mc_dev->dev); in check_plugged_state_change()
153 dev_err(&mc_dev->dev, in check_plugged_state_change()
158 mc_dev->obj_desc.state &= ~FSL_MC_OBJ_STATE_PLUGGED; in check_plugged_state_change()
159 device_release_driver(&mc_dev->dev); in check_plugged_state_change()
176 put_device(&child_dev->dev); in fsl_mc_obj_device_add()
178 error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev, in fsl_mc_obj_device_add()
186 * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
188 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
194 * state of the MC by adding objects that have been newly discovered
207 if (strlen(obj_desc->type) > 0 && in dprc_add_new_devices()
215 if (strlen(obj_desc->type) > 0 && in dprc_add_new_devices()
222 * dprc_scan_objects - Discover objects in a DPRC
224 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
229 * state of the Linux bus driver, MC by adding and removing
232 * dpbp, dpmcp) and non-allocatable devices (e.g., dprc, dpni).
233 * All allocatable devices needed to be probed before all non-allocatable
234 * devices, to ensure that device drivers for non-allocatable
238 * of the device drivers for the non-allocatable devices.
246 unsigned int irq_count = mc_bus_dev->obj_desc.irq_count; in dprc_scan_objects()
250 error = dprc_get_obj_count(mc_bus_dev->mc_io, in dprc_scan_objects()
252 mc_bus_dev->mc_handle, in dprc_scan_objects()
255 dev_err(&mc_bus_dev->dev, "dprc_get_obj_count() failed: %d\n", in dprc_scan_objects()
264 devm_kmalloc_array(&mc_bus_dev->dev, num_child_objects, in dprc_scan_objects()
268 return -ENOMEM; in dprc_scan_objects()
278 error = dprc_get_obj(mc_bus_dev->mc_io, in dprc_scan_objects()
280 mc_bus_dev->mc_handle, in dprc_scan_objects()
283 dev_err(&mc_bus_dev->dev, in dprc_scan_objects()
290 obj_desc->type[0] = '\0'; in dprc_scan_objects()
291 obj_desc->id = error; in dprc_scan_objects()
298 * are coherent regardless of what the MC reports. in dprc_scan_objects()
300 if ((strcmp(obj_desc->type, "dpseci") == 0) && in dprc_scan_objects()
301 (obj_desc->ver_major < 4)) in dprc_scan_objects()
302 obj_desc->flags |= in dprc_scan_objects()
305 irq_count += obj_desc->irq_count; in dprc_scan_objects()
306 dev_dbg(&mc_bus_dev->dev, in dprc_scan_objects()
308 obj_desc->type, obj_desc->id); in dprc_scan_objects()
312 dev_err(&mc_bus_dev->dev, in dprc_scan_objects()
322 if (dev_get_msi_domain(&mc_bus_dev->dev)) { in dprc_scan_objects()
324 dev_warn(&mc_bus_dev->dev, in dprc_scan_objects()
329 if (alloc_interrupts && !mc_bus->irq_resources) { in dprc_scan_objects()
344 devm_kfree(&mc_bus_dev->dev, child_obj_desc_array); in dprc_scan_objects()
350 * dprc_scan_container - Scans a physical DPRC and synchronizes Linux bus state
352 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
355 * bus driver with the actual state of the MC by adding and removing
369 mutex_lock(&mc_bus->scan_mutex); in dprc_scan_container()
371 mutex_unlock(&mc_bus->scan_mutex); in dprc_scan_container()
377 * dprc_irq0_handler - Regular ISR for DPRC interrupt 0
388 * dprc_irq0_handler_thread - Handler thread function for DPRC interrupt 0
400 struct fsl_mc_io *mc_io = mc_dev->mc_io; in dprc_irq0_handler_thread()
401 struct msi_desc *msi_desc = mc_dev->irqs[0]->msi_desc; in dprc_irq0_handler_thread()
406 if (!(mc_dev->flags & FSL_MC_IS_DPRC)) in dprc_irq0_handler_thread()
409 mutex_lock(&mc_bus->scan_mutex); in dprc_irq0_handler_thread()
410 if (!msi_desc || msi_desc->irq != (u32)irq_num) in dprc_irq0_handler_thread()
414 error = dprc_get_irq_status(mc_io, 0, mc_dev->mc_handle, 0, in dprc_irq0_handler_thread()
422 error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, in dprc_irq0_handler_thread()
439 * If the error is -ENXIO, we ignore it, as it indicates in dprc_irq0_handler_thread()
441 * an object was removed from the DPRC in the MC, while in dprc_irq0_handler_thread()
444 if (error != -ENXIO) { in dprc_irq0_handler_thread()
454 mutex_unlock(&mc_bus->scan_mutex); in dprc_irq0_handler_thread()
464 struct fsl_mc_io *mc_io = mc_dev->mc_io; in disable_dprc_irq()
469 error = dprc_set_irq_enable(mc_io, 0, mc_dev->mc_handle, 0, 0); in disable_dprc_irq()
471 dev_err(&mc_dev->dev, in disable_dprc_irq()
480 error = dprc_set_irq_mask(mc_io, 0, mc_dev->mc_handle, 0, 0x0); in disable_dprc_irq()
482 dev_err(&mc_dev->dev, in disable_dprc_irq()
491 error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, ~0x0U); in disable_dprc_irq()
493 dev_err(&mc_dev->dev, in disable_dprc_irq()
505 struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; in register_dprc_irq_handler()
508 * NOTE: devm_request_threaded_irq() invokes the device-specific in register_dprc_irq_handler()
511 error = devm_request_threaded_irq(&mc_dev->dev, in register_dprc_irq_handler()
512 irq->msi_desc->irq, in register_dprc_irq_handler()
516 dev_name(&mc_dev->dev), in register_dprc_irq_handler()
517 &mc_dev->dev); in register_dprc_irq_handler()
519 dev_err(&mc_dev->dev, in register_dprc_irq_handler()
535 error = dprc_set_irq_mask(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, in enable_dprc_irq()
538 dev_err(&mc_dev->dev, in enable_dprc_irq()
548 error = dprc_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, 1); in enable_dprc_irq()
550 dev_err(&mc_dev->dev, in enable_dprc_irq()
591 * dprc_setup - opens and creates a mc_io for DPRC
593 * @mc_dev: Pointer to fsl-mc device representing a DPRC
595 * It opens the physical DPRC in the MC.
596 * It configures the DPRC portal used to communicate with MC
601 struct device *parent_dev = mc_dev->dev.parent; in dprc_setup()
611 return -EINVAL; in dprc_setup()
613 if (dev_get_msi_domain(&mc_dev->dev)) in dprc_setup()
614 return -EINVAL; in dprc_setup()
616 if (!mc_dev->mc_io) { in dprc_setup()
621 return -EINVAL; in dprc_setup()
623 if (mc_dev->obj_desc.region_count == 0) in dprc_setup()
624 return -EINVAL; in dprc_setup()
626 region_size = resource_size(mc_dev->regions); in dprc_setup()
628 error = fsl_create_mc_io(&mc_dev->dev, in dprc_setup()
629 mc_dev->regions[0].start, in dprc_setup()
633 &mc_dev->mc_io); in dprc_setup()
640 mc_msi_domain = fsl_mc_find_msi_domain(&mc_dev->dev); in dprc_setup()
642 dev_warn(&mc_dev->dev, in dprc_setup()
643 "WARNING: MC bus without interrupt support\n"); in dprc_setup()
645 dev_set_msi_domain(&mc_dev->dev, mc_msi_domain); in dprc_setup()
649 error = dprc_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id, in dprc_setup()
650 &mc_dev->mc_handle); in dprc_setup()
652 dev_err(&mc_dev->dev, "dprc_open() failed: %d\n", error); in dprc_setup()
656 error = dprc_get_attributes(mc_dev->mc_io, 0, mc_dev->mc_handle, in dprc_setup()
657 &mc_bus->dprc_attr); in dprc_setup()
659 dev_err(&mc_dev->dev, "dprc_get_attributes() failed: %d\n", in dprc_setup()
664 error = dprc_get_api_version(mc_dev->mc_io, 0, in dprc_setup()
668 dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n", in dprc_setup()
676 dev_err(&mc_dev->dev, in dprc_setup()
679 error = -ENOTSUPP; in dprc_setup()
686 (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); in dprc_setup()
690 dev_set_msi_domain(&mc_dev->dev, NULL); in dprc_setup()
693 fsl_destroy_mc_io(mc_dev->mc_io); in dprc_setup()
694 mc_dev->mc_io = NULL; in dprc_setup()
702 * dprc_probe - callback invoked when a DPRC is being bound to this driver
704 * @mc_dev: Pointer to fsl-mc device representing a DPRC
706 * It opens the physical DPRC in the MC.
707 * It scans the DPRC to discover the MC objects contained in it.
708 * It creates the interrupt pool for the MC bus associated with the DPRC.
720 * Discover MC objects in DPRC object: in dprc_probe()
727 * Configure interrupt for the DPRC object associated with this MC bus: in dprc_probe()
733 dev_info(&mc_dev->dev, "DPRC device bound to driver"); in dprc_probe()
737 device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); in dprc_probe()
748 struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; in dprc_teardown_irq()
752 devm_free_irq(&mc_dev->dev, irq->msi_desc->irq, &mc_dev->dev); in dprc_teardown_irq()
758 * dprc_cleanup - function that cleanups a DPRC
760 * @mc_dev: Pointer to fsl-mc device representing the DPRC
762 * It closes the DPRC device in the MC.
763 * It destroys the interrupt pool associated with this MC bus.
774 return -EINVAL; in dprc_cleanup()
776 if (dev_get_msi_domain(&mc_dev->dev)) { in dprc_cleanup()
778 dev_set_msi_domain(&mc_dev->dev, NULL); in dprc_cleanup()
786 if (!mc_dev->mc_io) { in dprc_cleanup()
787 dev_err(&mc_dev->dev, "mc_io is NULL, tear down cannot be performed in firmware\n"); in dprc_cleanup()
788 return -EINVAL; in dprc_cleanup()
791 error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); in dprc_cleanup()
793 dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error); in dprc_cleanup()
795 if (!fsl_mc_is_root_dprc(&mc_dev->dev)) { in dprc_cleanup()
796 fsl_destroy_mc_io(mc_dev->mc_io); in dprc_cleanup()
797 mc_dev->mc_io = NULL; in dprc_cleanup()
805 * dprc_remove - callback invoked when a DPRC is being unbound from this driver
807 * @mc_dev: Pointer to fsl-mc device representing the DPRC
809 * It removes the DPRC's child objects from Linux (not from the MC) and
810 * closes the DPRC device in the MC.
812 * It destroys the interrupt pool associated with this MC bus.
819 return -EINVAL; in dprc_remove()
821 if (!mc_bus->irq_resources) in dprc_remove()
822 return -EINVAL; in dprc_remove()
824 if (dev_get_msi_domain(&mc_dev->dev)) in dprc_remove()
827 device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); in dprc_remove()
831 dev_info(&mc_dev->dev, "DPRC device unbound from driver"); in dprc_remove()