1 // SPDX-License-Identifier: GPL-2.0
3 * Freescale data path resource container (DPRC) driver
5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Copyright 2019-2020 NXP
7 * Author: German Rivera <German.Rivera@freescale.com>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/interrupt.h>
14 #include <linux/fsl/mc.h>
16 #include "fsl-mc-private.h"
18 #define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc"
20 struct fsl_mc_child_objs
{
22 struct fsl_mc_obj_desc
*child_array
;
25 static bool fsl_mc_device_match(struct fsl_mc_device
*mc_dev
,
26 struct fsl_mc_obj_desc
*obj_desc
)
28 return mc_dev
->obj_desc
.id
== obj_desc
->id
&&
29 strcmp(mc_dev
->obj_desc
.type
, obj_desc
->type
) == 0;
32 static bool fsl_mc_obj_desc_is_allocatable(struct fsl_mc_obj_desc
*obj
)
34 if (strcmp(obj
->type
, "dpmcp") == 0 ||
35 strcmp(obj
->type
, "dpcon") == 0 ||
36 strcmp(obj
->type
, "dpbp") == 0)
42 static int __fsl_mc_device_remove_if_not_in_mc(struct device
*dev
, void *data
)
45 struct fsl_mc_child_objs
*objs
;
46 struct fsl_mc_device
*mc_dev
;
48 if (!dev_is_fsl_mc(dev
))
51 mc_dev
= to_fsl_mc_device(dev
);
54 for (i
= 0; i
< objs
->child_count
; i
++) {
55 struct fsl_mc_obj_desc
*obj_desc
= &objs
->child_array
[i
];
57 if (strlen(obj_desc
->type
) != 0 &&
58 fsl_mc_device_match(mc_dev
, obj_desc
))
62 if (i
== objs
->child_count
)
63 fsl_mc_device_remove(mc_dev
);
68 static int __fsl_mc_device_remove(struct device
*dev
, void *data
)
70 if (!dev_is_fsl_mc(dev
))
73 fsl_mc_device_remove(to_fsl_mc_device(dev
));
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
81 * @obj_desc_array: array of object descriptors for child objects currently
82 * present in the DPRC in the MC.
83 * @num_child_objects_in_mc: number of entries in obj_desc_array
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
87 * been dynamically removed in the physical DPRC.
89 void dprc_remove_devices(struct fsl_mc_device
*mc_bus_dev
,
90 struct fsl_mc_obj_desc
*obj_desc_array
,
91 int num_child_objects_in_mc
)
93 if (num_child_objects_in_mc
!= 0) {
95 * Remove child objects that are in the DPRC in Linux,
98 struct fsl_mc_child_objs objs
;
100 objs
.child_count
= num_child_objects_in_mc
;
101 objs
.child_array
= obj_desc_array
;
102 device_for_each_child(&mc_bus_dev
->dev
, &objs
,
103 __fsl_mc_device_remove_if_not_in_mc
);
106 * There are no child objects for this DPRC in the MC.
107 * So, remove all the child devices from Linux:
109 device_for_each_child(&mc_bus_dev
->dev
, NULL
,
110 __fsl_mc_device_remove
);
113 EXPORT_SYMBOL_GPL(dprc_remove_devices
);
115 static int __fsl_mc_device_match(struct device
*dev
, void *data
)
117 struct fsl_mc_obj_desc
*obj_desc
= data
;
118 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
120 return fsl_mc_device_match(mc_dev
, obj_desc
);
123 struct fsl_mc_device
*fsl_mc_device_lookup(struct fsl_mc_obj_desc
*obj_desc
,
124 struct fsl_mc_device
*mc_bus_dev
)
128 dev
= device_find_child(&mc_bus_dev
->dev
, obj_desc
,
129 __fsl_mc_device_match
);
131 return dev
? to_fsl_mc_device(dev
) : NULL
;
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
141 * device is bound to the corresponding device driver.
142 * If the plugged state has changed from plugged to unplugged, the fsl-mc
143 * device is unbound from the corresponding device driver.
145 static void check_plugged_state_change(struct fsl_mc_device
*mc_dev
,
146 struct fsl_mc_obj_desc
*obj_desc
)
149 u32 plugged_flag_at_mc
=
150 obj_desc
->state
& FSL_MC_OBJ_STATE_PLUGGED
;
152 if (plugged_flag_at_mc
!=
153 (mc_dev
->obj_desc
.state
& FSL_MC_OBJ_STATE_PLUGGED
)) {
154 if (plugged_flag_at_mc
) {
155 mc_dev
->obj_desc
.state
|= FSL_MC_OBJ_STATE_PLUGGED
;
156 error
= device_attach(&mc_dev
->dev
);
158 dev_err(&mc_dev
->dev
,
159 "device_attach() failed: %d\n",
163 mc_dev
->obj_desc
.state
&= ~FSL_MC_OBJ_STATE_PLUGGED
;
164 device_release_driver(&mc_dev
->dev
);
169 static void fsl_mc_obj_device_add(struct fsl_mc_device
*mc_bus_dev
,
170 struct fsl_mc_obj_desc
*obj_desc
)
173 struct fsl_mc_device
*child_dev
;
176 * Check if device is already known to Linux:
178 child_dev
= fsl_mc_device_lookup(obj_desc
, mc_bus_dev
);
180 check_plugged_state_change(child_dev
, obj_desc
);
181 put_device(&child_dev
->dev
);
183 error
= fsl_mc_device_add(obj_desc
, NULL
, &mc_bus_dev
->dev
,
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
194 * @obj_desc_array: array of device descriptors for child devices currently
195 * present in the physical DPRC.
196 * @num_child_objects_in_mc: number of entries in obj_desc_array
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
200 * in the physical DPRC.
202 static void dprc_add_new_devices(struct fsl_mc_device
*mc_bus_dev
,
203 struct fsl_mc_obj_desc
*obj_desc_array
,
204 int num_child_objects_in_mc
)
208 /* probe the allocable objects first */
209 for (i
= 0; i
< num_child_objects_in_mc
; i
++) {
210 struct fsl_mc_obj_desc
*obj_desc
= &obj_desc_array
[i
];
212 if (strlen(obj_desc
->type
) > 0 &&
213 fsl_mc_obj_desc_is_allocatable(obj_desc
))
214 fsl_mc_obj_device_add(mc_bus_dev
, obj_desc
);
217 for (i
= 0; i
< num_child_objects_in_mc
; i
++) {
218 struct fsl_mc_obj_desc
*obj_desc
= &obj_desc_array
[i
];
220 if (strlen(obj_desc
->type
) > 0 &&
221 !fsl_mc_obj_desc_is_allocatable(obj_desc
))
222 fsl_mc_obj_device_add(mc_bus_dev
, obj_desc
);
227 * dprc_scan_objects - Discover objects in a DPRC
229 * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
230 * @alloc_interrupts: if true the function allocates the interrupt pool,
231 * otherwise the interrupt allocation is delayed
233 * Detects objects added and removed from a DPRC and synchronizes the
234 * state of the Linux bus driver, MC by adding and removing
235 * devices accordingly.
236 * Two types of devices can be found in a DPRC: allocatable objects (e.g.,
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
240 * devices can allocate any type of allocatable devices.
241 * That is, we need to ensure that the corresponding resource pools are
242 * populated before they can get allocation requests from probe callbacks
243 * of the device drivers for the non-allocatable devices.
245 int dprc_scan_objects(struct fsl_mc_device
*mc_bus_dev
,
246 bool alloc_interrupts
)
248 int num_child_objects
;
249 int dprc_get_obj_failures
;
251 unsigned int irq_count
= mc_bus_dev
->obj_desc
.irq_count
;
252 struct fsl_mc_obj_desc
*child_obj_desc_array
= NULL
;
253 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_bus_dev
);
255 error
= dprc_get_obj_count(mc_bus_dev
->mc_io
,
257 mc_bus_dev
->mc_handle
,
260 dev_err(&mc_bus_dev
->dev
, "dprc_get_obj_count() failed: %d\n",
265 if (num_child_objects
!= 0) {
268 child_obj_desc_array
=
269 devm_kmalloc_array(&mc_bus_dev
->dev
, num_child_objects
,
270 sizeof(*child_obj_desc_array
),
272 if (!child_obj_desc_array
)
276 * Discover objects currently present in the physical DPRC:
278 dprc_get_obj_failures
= 0;
279 for (i
= 0; i
< num_child_objects
; i
++) {
280 struct fsl_mc_obj_desc
*obj_desc
=
281 &child_obj_desc_array
[i
];
283 error
= dprc_get_obj(mc_bus_dev
->mc_io
,
285 mc_bus_dev
->mc_handle
,
288 dev_err(&mc_bus_dev
->dev
,
289 "dprc_get_obj(i=%d) failed: %d\n",
292 * Mark the obj entry as "invalid", by using the
293 * empty string as obj type:
295 obj_desc
->type
[0] = '\0';
296 obj_desc
->id
= error
;
297 dprc_get_obj_failures
++;
302 * add a quirk for all versions of dpsec < 4.0...none
303 * are coherent regardless of what the MC reports.
305 if ((strcmp(obj_desc
->type
, "dpseci") == 0) &&
306 (obj_desc
->ver_major
< 4))
308 FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY
;
310 irq_count
+= obj_desc
->irq_count
;
311 dev_dbg(&mc_bus_dev
->dev
,
312 "Discovered object: type %s, id %d\n",
313 obj_desc
->type
, obj_desc
->id
);
316 if (dprc_get_obj_failures
!= 0) {
317 dev_err(&mc_bus_dev
->dev
,
318 "%d out of %d devices could not be retrieved\n",
319 dprc_get_obj_failures
, num_child_objects
);
324 * Allocate IRQ's before binding the scanned devices with their
325 * respective drivers.
327 if (dev_get_msi_domain(&mc_bus_dev
->dev
)) {
328 if (irq_count
> FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS
) {
329 dev_warn(&mc_bus_dev
->dev
,
330 "IRQs needed (%u) exceed IRQs preallocated (%u)\n",
331 irq_count
, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS
);
334 if (alloc_interrupts
&& !mc_bus
->irq_resources
) {
335 error
= fsl_mc_populate_irq_pool(mc_bus_dev
,
336 FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS
);
342 dprc_remove_devices(mc_bus_dev
, child_obj_desc_array
,
345 dprc_add_new_devices(mc_bus_dev
, child_obj_desc_array
,
348 if (child_obj_desc_array
)
349 devm_kfree(&mc_bus_dev
->dev
, child_obj_desc_array
);
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
358 * @alloc_interrupts: if true the function allocates the interrupt pool,
359 * otherwise the interrupt allocation is delayed
360 * Scans the physical DPRC and synchronizes the state of the Linux
361 * bus driver with the actual state of the MC by adding and removing
362 * devices as appropriate.
364 int dprc_scan_container(struct fsl_mc_device
*mc_bus_dev
,
365 bool alloc_interrupts
)
368 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_bus_dev
);
370 fsl_mc_init_all_resource_pools(mc_bus_dev
);
373 * Discover objects in the DPRC:
375 mutex_lock(&mc_bus
->scan_mutex
);
376 error
= dprc_scan_objects(mc_bus_dev
, alloc_interrupts
);
377 mutex_unlock(&mc_bus
->scan_mutex
);
381 EXPORT_SYMBOL_GPL(dprc_scan_container
);
384 * dprc_irq0_handler - Regular ISR for DPRC interrupt 0
386 * @irq_num: IRQ number of the interrupt being handled
387 * @arg: Pointer to device structure
389 static irqreturn_t
dprc_irq0_handler(int irq_num
, void *arg
)
391 return IRQ_WAKE_THREAD
;
395 * dprc_irq0_handler_thread - Handler thread function for DPRC interrupt 0
397 * @irq_num: IRQ number of the interrupt being handled
398 * @arg: Pointer to device structure
400 static irqreturn_t
dprc_irq0_handler_thread(int irq_num
, void *arg
)
404 struct device
*dev
= arg
;
405 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
406 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
407 struct fsl_mc_io
*mc_io
= mc_dev
->mc_io
;
408 int irq
= mc_dev
->irqs
[0]->virq
;
410 dev_dbg(dev
, "DPRC IRQ %d triggered on CPU %u\n",
411 irq_num
, smp_processor_id());
413 if (!(mc_dev
->flags
& FSL_MC_IS_DPRC
))
416 mutex_lock(&mc_bus
->scan_mutex
);
417 if (irq
!= (u32
)irq_num
)
421 error
= dprc_get_irq_status(mc_io
, 0, mc_dev
->mc_handle
, 0,
425 "dprc_get_irq_status() failed: %d\n", error
);
429 error
= dprc_clear_irq_status(mc_io
, 0, mc_dev
->mc_handle
, 0,
433 "dprc_clear_irq_status() failed: %d\n", error
);
437 if (status
& (DPRC_IRQ_EVENT_OBJ_ADDED
|
438 DPRC_IRQ_EVENT_OBJ_REMOVED
|
439 DPRC_IRQ_EVENT_CONTAINER_DESTROYED
|
440 DPRC_IRQ_EVENT_OBJ_DESTROYED
|
441 DPRC_IRQ_EVENT_OBJ_CREATED
)) {
443 error
= dprc_scan_objects(mc_dev
, true);
446 * If the error is -ENXIO, we ignore it, as it indicates
447 * that the object scan was aborted, as we detected that
448 * an object was removed from the DPRC in the MC, while
449 * we were scanning the DPRC.
451 if (error
!= -ENXIO
) {
452 dev_err(dev
, "dprc_scan_objects() failed: %d\n",
461 mutex_unlock(&mc_bus
->scan_mutex
);
466 * Disable and clear interrupt for a given DPRC object
468 int disable_dprc_irq(struct fsl_mc_device
*mc_dev
)
470 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
472 struct fsl_mc_io
*mc_io
= mc_dev
->mc_io
;
475 * Disable generation of interrupt, while we configure it:
477 error
= dprc_set_irq_enable(mc_io
, 0, mc_dev
->mc_handle
, 0, 0);
479 dev_err(&mc_dev
->dev
,
480 "Disabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n",
486 * Disable all interrupt causes for the interrupt:
488 error
= dprc_set_irq_mask(mc_io
, 0, mc_dev
->mc_handle
, 0, 0x0);
490 dev_err(&mc_dev
->dev
,
491 "Disabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n",
497 * Clear any leftover interrupts:
499 error
= dprc_clear_irq_status(mc_io
, 0, mc_dev
->mc_handle
, 0, ~0x0U
);
501 dev_err(&mc_dev
->dev
,
502 "Disabling DPRC IRQ failed: dprc_clear_irq_status() failed: %d\n",
507 mc_bus
->irq_enabled
= 0;
512 int get_dprc_irq_state(struct fsl_mc_device
*mc_dev
)
514 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
516 return mc_bus
->irq_enabled
;
519 static int register_dprc_irq_handler(struct fsl_mc_device
*mc_dev
)
522 struct fsl_mc_device_irq
*irq
= mc_dev
->irqs
[0];
525 * NOTE: devm_request_threaded_irq() invokes the device-specific
526 * function that programs the MSI physically in the device
528 error
= devm_request_threaded_irq(&mc_dev
->dev
,
531 dprc_irq0_handler_thread
,
532 IRQF_NO_SUSPEND
| IRQF_ONESHOT
,
533 dev_name(&mc_dev
->dev
),
536 dev_err(&mc_dev
->dev
,
537 "devm_request_threaded_irq() failed: %d\n",
545 int enable_dprc_irq(struct fsl_mc_device
*mc_dev
)
547 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
551 * Enable all interrupt causes for the interrupt:
553 error
= dprc_set_irq_mask(mc_dev
->mc_io
, 0, mc_dev
->mc_handle
, 0,
556 dev_err(&mc_dev
->dev
,
557 "Enabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n",
564 * Enable generation of the interrupt:
566 error
= dprc_set_irq_enable(mc_dev
->mc_io
, 0, mc_dev
->mc_handle
, 0, 1);
568 dev_err(&mc_dev
->dev
,
569 "Enabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n",
575 mc_bus
->irq_enabled
= 1;
581 * Setup interrupt for a given DPRC device
583 static int dprc_setup_irq(struct fsl_mc_device
*mc_dev
)
587 error
= fsl_mc_allocate_irqs(mc_dev
);
591 error
= disable_dprc_irq(mc_dev
);
593 goto error_free_irqs
;
595 error
= register_dprc_irq_handler(mc_dev
);
597 goto error_free_irqs
;
599 error
= enable_dprc_irq(mc_dev
);
601 goto error_free_irqs
;
606 fsl_mc_free_irqs(mc_dev
);
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
619 int dprc_setup(struct fsl_mc_device
*mc_dev
)
621 struct device
*parent_dev
= mc_dev
->dev
.parent
;
622 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
623 struct irq_domain
*mc_msi_domain
;
624 bool mc_io_created
= false;
625 bool msi_domain_set
= false;
626 bool uapi_created
= false;
627 u16 major_ver
, minor_ver
;
631 if (!is_fsl_mc_bus_dprc(mc_dev
))
634 if (dev_get_msi_domain(&mc_dev
->dev
))
637 if (!mc_dev
->mc_io
) {
639 * This is a child DPRC:
641 if (!dev_is_fsl_mc(parent_dev
))
644 if (mc_dev
->obj_desc
.region_count
== 0)
647 region_size
= resource_size(mc_dev
->regions
);
649 error
= fsl_create_mc_io(&mc_dev
->dev
,
650 mc_dev
->regions
[0].start
,
653 FSL_MC_IO_ATOMIC_CONTEXT_PORTAL
,
658 mc_io_created
= true;
660 error
= fsl_mc_uapi_create_device_file(mc_bus
);
662 return -EPROBE_DEFER
;
666 mc_msi_domain
= fsl_mc_find_msi_domain(&mc_dev
->dev
);
667 if (!mc_msi_domain
) {
668 dev_warn(&mc_dev
->dev
,
669 "WARNING: MC bus without interrupt support\n");
671 dev_set_msi_domain(&mc_dev
->dev
, mc_msi_domain
);
672 msi_domain_set
= true;
675 error
= dprc_open(mc_dev
->mc_io
, 0, mc_dev
->obj_desc
.id
,
678 dev_err(&mc_dev
->dev
, "dprc_open() failed: %d\n", error
);
679 goto error_cleanup_msi_domain
;
682 error
= dprc_get_attributes(mc_dev
->mc_io
, 0, mc_dev
->mc_handle
,
685 dev_err(&mc_dev
->dev
, "dprc_get_attributes() failed: %d\n",
687 goto error_cleanup_open
;
690 error
= dprc_get_api_version(mc_dev
->mc_io
, 0,
694 dev_err(&mc_dev
->dev
, "dprc_get_api_version() failed: %d\n",
696 goto error_cleanup_open
;
699 if (major_ver
< DPRC_MIN_VER_MAJOR
) {
700 dev_err(&mc_dev
->dev
,
701 "ERROR: DPRC version %d.%d not supported\n",
702 major_ver
, minor_ver
);
704 goto error_cleanup_open
;
710 (void)dprc_close(mc_dev
->mc_io
, 0, mc_dev
->mc_handle
);
712 error_cleanup_msi_domain
:
714 dev_set_msi_domain(&mc_dev
->dev
, NULL
);
717 fsl_destroy_mc_io(mc_dev
->mc_io
);
718 mc_dev
->mc_io
= NULL
;
722 fsl_mc_uapi_remove_device_file(mc_bus
);
726 EXPORT_SYMBOL_GPL(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.
736 * It configures the interrupts for the DPRC device itself.
738 static int dprc_probe(struct fsl_mc_device
*mc_dev
)
742 error
= dprc_setup(mc_dev
);
747 * Discover MC objects in DPRC object:
749 error
= dprc_scan_container(mc_dev
, true);
754 * Configure interrupt for the DPRC object associated with this MC bus:
756 error
= dprc_setup_irq(mc_dev
);
760 dev_info(&mc_dev
->dev
, "DPRC device bound to driver");
764 device_for_each_child(&mc_dev
->dev
, NULL
, __fsl_mc_device_remove
);
766 dprc_cleanup(mc_dev
);
771 * Tear down interrupt for a given DPRC object
773 static void dprc_teardown_irq(struct fsl_mc_device
*mc_dev
)
775 struct fsl_mc_device_irq
*irq
= mc_dev
->irqs
[0];
777 (void)disable_dprc_irq(mc_dev
);
779 devm_free_irq(&mc_dev
->dev
, irq
->virq
, &mc_dev
->dev
);
781 fsl_mc_free_irqs(mc_dev
);
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.
793 int dprc_cleanup(struct fsl_mc_device
*mc_dev
)
795 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
798 /* this function should be called only for DPRCs, it
799 * is an error to call it for regular objects
801 if (!is_fsl_mc_bus_dprc(mc_dev
))
804 if (dev_get_msi_domain(&mc_dev
->dev
)) {
805 fsl_mc_cleanup_irq_pool(mc_dev
);
806 dev_set_msi_domain(&mc_dev
->dev
, NULL
);
809 fsl_mc_cleanup_all_resource_pools(mc_dev
);
811 /* if this step fails we cannot go further with cleanup as there is no way of
812 * communicating with the firmware
814 if (!mc_dev
->mc_io
) {
815 dev_err(&mc_dev
->dev
, "mc_io is NULL, tear down cannot be performed in firmware\n");
819 error
= dprc_close(mc_dev
->mc_io
, 0, mc_dev
->mc_handle
);
821 dev_err(&mc_dev
->dev
, "dprc_close() failed: %d\n", error
);
823 if (!fsl_mc_is_root_dprc(&mc_dev
->dev
)) {
824 fsl_destroy_mc_io(mc_dev
->mc_io
);
825 mc_dev
->mc_io
= NULL
;
827 fsl_mc_uapi_remove_device_file(mc_bus
);
832 EXPORT_SYMBOL_GPL(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.
841 * It tears down the interrupts that were configured for the DPRC device.
842 * It destroys the interrupt pool associated with this MC bus.
844 static void dprc_remove(struct fsl_mc_device
*mc_dev
)
846 struct fsl_mc_bus
*mc_bus
= to_fsl_mc_bus(mc_dev
);
848 if (!mc_bus
->irq_resources
) {
849 dev_err(&mc_dev
->dev
, "No irq resources, so unbinding the device failed\n");
853 if (dev_get_msi_domain(&mc_dev
->dev
))
854 dprc_teardown_irq(mc_dev
);
856 device_for_each_child(&mc_dev
->dev
, NULL
, __fsl_mc_device_remove
);
858 dprc_cleanup(mc_dev
);
860 dev_info(&mc_dev
->dev
, "DPRC device unbound from driver");
863 static const struct fsl_mc_device_id match_id_table
[] = {
865 .vendor
= FSL_MC_VENDOR_FREESCALE
,
870 static struct fsl_mc_driver dprc_driver
= {
872 .name
= FSL_MC_DPRC_DRIVER_NAME
,
873 .owner
= THIS_MODULE
,
876 .match_id_table
= match_id_table
,
878 .remove
= dprc_remove
,
881 int __init
dprc_driver_init(void)
883 return fsl_mc_driver_register(&dprc_driver
);
886 void dprc_driver_exit(void)
888 fsl_mc_driver_unregister(&dprc_driver
);