Skip to content

Commit 17eaf21

Browse files
dmcraciungregkh
authored andcommitted
bus/fsl-mc: Add a container setup function
Both DPRC driver and VFIO driver use the same initialization code for the DPRC. Introduced a new function which groups this initialization code. The function is exported and may be used by VFIO as well. Reviewed-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> Acked-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> Signed-off-by: Diana Craciun <diana.craciun@oss.nxp.com> Link: https://lore.kernel.org/r/20200929085441.17448-10-diana.craciun@oss.nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 46f35b5 commit 17eaf21

2 files changed

Lines changed: 51 additions & 22 deletions

File tree

‎drivers/bus/fsl-mc/dprc-driver.c‎

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -588,25 +588,24 @@ static int dprc_setup_irq(struct fsl_mc_device *mc_dev)
588588
}
589589

590590
/**
591-
* dprc_probe - callback invoked when a DPRC is being bound to this driver
591+
* dprc_setup - opens and creates a mc_io for DPRC
592592
*
593593
* @mc_dev: Pointer to fsl-mc device representing a DPRC
594594
*
595595
* It opens the physical DPRC in the MC.
596-
* It scans the DPRC to discover the MC objects contained in it.
597-
* It creates the interrupt pool for the MC bus associated with the DPRC.
598-
* It configures the interrupts for the DPRC device itself.
596+
* It configures the DPRC portal used to communicate with MC
599597
*/
600-
static int dprc_probe(struct fsl_mc_device *mc_dev)
598+
599+
int dprc_setup(struct fsl_mc_device *mc_dev)
601600
{
602-
int error;
603-
size_t region_size;
604601
struct device *parent_dev = mc_dev->dev.parent;
605602
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
603+
struct irq_domain *mc_msi_domain;
606604
bool mc_io_created = false;
607605
bool msi_domain_set = false;
608606
u16 major_ver, minor_ver;
609-
struct irq_domain *mc_msi_domain;
607+
size_t region_size;
608+
int error;
610609

611610
if (!is_fsl_mc_bus_dprc(mc_dev))
612611
return -EINVAL;
@@ -681,35 +680,63 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
681680
goto error_cleanup_open;
682681
}
683682

683+
return 0;
684+
685+
error_cleanup_open:
686+
(void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
687+
688+
error_cleanup_msi_domain:
689+
if (msi_domain_set)
690+
dev_set_msi_domain(&mc_dev->dev, NULL);
691+
692+
if (mc_io_created) {
693+
fsl_destroy_mc_io(mc_dev->mc_io);
694+
mc_dev->mc_io = NULL;
695+
}
696+
697+
return error;
698+
}
699+
EXPORT_SYMBOL_GPL(dprc_setup);
700+
701+
/**
702+
* dprc_probe - callback invoked when a DPRC is being bound to this driver
703+
*
704+
* @mc_dev: Pointer to fsl-mc device representing a DPRC
705+
*
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.
709+
* It configures the interrupts for the DPRC device itself.
710+
*/
711+
static int dprc_probe(struct fsl_mc_device *mc_dev)
712+
{
713+
int error;
714+
715+
error = dprc_setup(mc_dev);
716+
if (error < 0)
717+
return error;
718+
684719
/*
685720
* Discover MC objects in DPRC object:
686721
*/
687722
error = dprc_scan_container(mc_dev, true);
688723
if (error < 0)
689-
goto error_cleanup_open;
724+
goto dprc_cleanup;
690725

691726
/*
692727
* Configure interrupt for the DPRC object associated with this MC bus:
693728
*/
694729
error = dprc_setup_irq(mc_dev);
695730
if (error < 0)
696-
goto error_cleanup_open;
731+
goto scan_cleanup;
697732

698733
dev_info(&mc_dev->dev, "DPRC device bound to driver");
699734
return 0;
700735

701-
error_cleanup_open:
702-
(void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
703-
704-
error_cleanup_msi_domain:
705-
if (msi_domain_set)
706-
dev_set_msi_domain(&mc_dev->dev, NULL);
707-
708-
if (mc_io_created) {
709-
fsl_destroy_mc_io(mc_dev->mc_io);
710-
mc_dev->mc_io = NULL;
711-
}
712-
736+
scan_cleanup:
737+
device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
738+
dprc_cleanup:
739+
dprc_cleanup(mc_dev);
713740
return error;
714741
}
715742

‎include/linux/fsl/mc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ void dprc_remove_devices(struct fsl_mc_device *mc_bus_dev,
540540

541541
int dprc_cleanup(struct fsl_mc_device *mc_dev);
542542

543+
int dprc_setup(struct fsl_mc_device *mc_dev);
544+
543545
/*
544546
* Data Path Buffer Pool (DPBP) API
545547
* Contains initialization APIs and runtime control APIs for DPBP

0 commit comments

Comments
 (0)