1 // SPDX-License-Identifier: GPL-2.0
3 * Freescale Management Complex (MC) bus driver
5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
6 * Author: German Rivera <German.Rivera@freescale.com>
10 #define pr_fmt(fmt) "fsl-mc: " fmt
12 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/of_address.h>
15 #include <linux/ioport.h>
16 #include <linux/slab.h>
17 #include <linux/limits.h>
18 #include <linux/bitops.h>
19 #include <linux/msi.h>
20 #include <linux/dma-mapping.h>
22 #include "fsl-mc-private.h"
25 * Default DMA mask for devices on a fsl-mc bus
27 #define FSL_MC_DEFAULT_DMA_MASK (~0ULL)
30 * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
31 * @root_mc_bus_dev: fsl-mc device representing the root DPRC
32 * @num_translation_ranges: number of entries in addr_translation_ranges
33 * @translation_ranges: array of bus to system address translation ranges
36 struct fsl_mc_device
*root_mc_bus_dev
;
37 u8 num_translation_ranges
;
38 struct fsl_mc_addr_translation_range
*translation_ranges
;
42 * struct fsl_mc_addr_translation_range - bus to system address translation
44 * @mc_region_type: Type of MC region for the range being translated
45 * @start_mc_offset: Start MC offset of the range being translated
46 * @end_mc_offset: MC offset of the first byte after the range (last MC
47 * offset of the range is end_mc_offset - 1)
48 * @start_phys_addr: system physical address corresponding to start_mc_addr
50 struct fsl_mc_addr_translation_range
{
51 enum dprc_region_type mc_region_type
;
54 phys_addr_t start_phys_addr
;
59 * @major: Major version number: incremented on API compatibility changes
60 * @minor: Minor version number: incremented on API additions (that are
61 * backward compatible); reset when major version is incremented
62 * @revision: Internal revision number: incremented on implementation changes
63 * and/or bug fixes that have no impact on API
72 * fsl_mc_bus_match - device to driver matching callback
73 * @dev: the fsl-mc device to match against
74 * @drv: the device driver to search for matching fsl-mc object type
77 * Returns 1 on success, 0 otherwise.
79 static int fsl_mc_bus_match(struct device
*dev
, struct device_driver
*drv
)
81 const struct fsl_mc_device_id
*id
;
82 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
83 struct fsl_mc_driver
*mc_drv
= to_fsl_mc_driver(drv
);
86 if (!mc_drv
->match_id_table
)
90 * If the object is not 'plugged' don't match.
91 * Only exception is the root DPRC, which is a special case.
93 if ((mc_dev
->obj_desc
.state
& FSL_MC_OBJ_STATE_PLUGGED
) == 0 &&
94 !fsl_mc_is_root_dprc(&mc_dev
->dev
))
98 * Traverse the match_id table of the given driver, trying to find
99 * a matching for the given device.
101 for (id
= mc_drv
->match_id_table
; id
->vendor
!= 0x0; id
++) {
102 if (id
->vendor
== mc_dev
->obj_desc
.vendor
&&
103 strcmp(id
->obj_type
, mc_dev
->obj_desc
.type
) == 0) {
111 dev_dbg(dev
, "%smatched\n", found
? "" : "not ");
116 * fsl_mc_bus_uevent - callback invoked when a device is added
118 static int fsl_mc_bus_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
120 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
122 if (add_uevent_var(env
, "MODALIAS=fsl-mc:v%08Xd%s",
123 mc_dev
->obj_desc
.vendor
,
124 mc_dev
->obj_desc
.type
))
130 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
,
133 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
135 return sprintf(buf
, "fsl-mc:v%08Xd%s\n", mc_dev
->obj_desc
.vendor
,
136 mc_dev
->obj_desc
.type
);
138 static DEVICE_ATTR_RO(modalias
);
140 static struct attribute
*fsl_mc_dev_attrs
[] = {
141 &dev_attr_modalias
.attr
,
145 ATTRIBUTE_GROUPS(fsl_mc_dev
);
147 struct bus_type fsl_mc_bus_type
= {
149 .match
= fsl_mc_bus_match
,
150 .uevent
= fsl_mc_bus_uevent
,
151 .dev_groups
= fsl_mc_dev_groups
,
153 EXPORT_SYMBOL_GPL(fsl_mc_bus_type
);
155 struct device_type fsl_mc_bus_dprc_type
= {
156 .name
= "fsl_mc_bus_dprc"
159 struct device_type fsl_mc_bus_dpni_type
= {
160 .name
= "fsl_mc_bus_dpni"
163 struct device_type fsl_mc_bus_dpio_type
= {
164 .name
= "fsl_mc_bus_dpio"
167 struct device_type fsl_mc_bus_dpsw_type
= {
168 .name
= "fsl_mc_bus_dpsw"
171 struct device_type fsl_mc_bus_dpbp_type
= {
172 .name
= "fsl_mc_bus_dpbp"
175 struct device_type fsl_mc_bus_dpcon_type
= {
176 .name
= "fsl_mc_bus_dpcon"
179 struct device_type fsl_mc_bus_dpmcp_type
= {
180 .name
= "fsl_mc_bus_dpmcp"
183 struct device_type fsl_mc_bus_dpmac_type
= {
184 .name
= "fsl_mc_bus_dpmac"
187 struct device_type fsl_mc_bus_dprtc_type
= {
188 .name
= "fsl_mc_bus_dprtc"
191 static struct device_type
*fsl_mc_get_device_type(const char *type
)
193 static const struct {
194 struct device_type
*dev_type
;
197 { &fsl_mc_bus_dprc_type
, "dprc" },
198 { &fsl_mc_bus_dpni_type
, "dpni" },
199 { &fsl_mc_bus_dpio_type
, "dpio" },
200 { &fsl_mc_bus_dpsw_type
, "dpsw" },
201 { &fsl_mc_bus_dpbp_type
, "dpbp" },
202 { &fsl_mc_bus_dpcon_type
, "dpcon" },
203 { &fsl_mc_bus_dpmcp_type
, "dpmcp" },
204 { &fsl_mc_bus_dpmac_type
, "dpmac" },
205 { &fsl_mc_bus_dprtc_type
, "dprtc" },
210 for (i
= 0; dev_types
[i
].dev_type
; i
++)
211 if (!strcmp(dev_types
[i
].type
, type
))
212 return dev_types
[i
].dev_type
;
217 static int fsl_mc_driver_probe(struct device
*dev
)
219 struct fsl_mc_driver
*mc_drv
;
220 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
223 mc_drv
= to_fsl_mc_driver(dev
->driver
);
225 error
= mc_drv
->probe(mc_dev
);
227 if (error
!= -EPROBE_DEFER
)
228 dev_err(dev
, "%s failed: %d\n", __func__
, error
);
235 static int fsl_mc_driver_remove(struct device
*dev
)
237 struct fsl_mc_driver
*mc_drv
= to_fsl_mc_driver(dev
->driver
);
238 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
241 error
= mc_drv
->remove(mc_dev
);
243 dev_err(dev
, "%s failed: %d\n", __func__
, error
);
250 static void fsl_mc_driver_shutdown(struct device
*dev
)
252 struct fsl_mc_driver
*mc_drv
= to_fsl_mc_driver(dev
->driver
);
253 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
255 mc_drv
->shutdown(mc_dev
);
259 * __fsl_mc_driver_register - registers a child device driver with the
262 * This function is implicitly invoked from the registration function of
263 * fsl_mc device drivers, which is generated by the
264 * module_fsl_mc_driver() macro.
266 int __fsl_mc_driver_register(struct fsl_mc_driver
*mc_driver
,
267 struct module
*owner
)
271 mc_driver
->driver
.owner
= owner
;
272 mc_driver
->driver
.bus
= &fsl_mc_bus_type
;
274 if (mc_driver
->probe
)
275 mc_driver
->driver
.probe
= fsl_mc_driver_probe
;
277 if (mc_driver
->remove
)
278 mc_driver
->driver
.remove
= fsl_mc_driver_remove
;
280 if (mc_driver
->shutdown
)
281 mc_driver
->driver
.shutdown
= fsl_mc_driver_shutdown
;
283 error
= driver_register(&mc_driver
->driver
);
285 pr_err("driver_register() failed for %s: %d\n",
286 mc_driver
->driver
.name
, error
);
292 EXPORT_SYMBOL_GPL(__fsl_mc_driver_register
);
295 * fsl_mc_driver_unregister - unregisters a device driver from the
298 void fsl_mc_driver_unregister(struct fsl_mc_driver
*mc_driver
)
300 driver_unregister(&mc_driver
->driver
);
302 EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister
);
305 * mc_get_version() - Retrieves the Management Complex firmware
306 * version information
307 * @mc_io: Pointer to opaque I/O object
308 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
309 * @mc_ver_info: Returned version information structure
311 * Return: '0' on Success; Error code otherwise.
313 static int mc_get_version(struct fsl_mc_io
*mc_io
,
315 struct mc_version
*mc_ver_info
)
317 struct fsl_mc_command cmd
= { 0 };
318 struct dpmng_rsp_get_version
*rsp_params
;
321 /* prepare command */
322 cmd
.header
= mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION
,
326 /* send command to mc*/
327 err
= mc_send_command(mc_io
, &cmd
);
331 /* retrieve response parameters */
332 rsp_params
= (struct dpmng_rsp_get_version
*)cmd
.params
;
333 mc_ver_info
->revision
= le32_to_cpu(rsp_params
->revision
);
334 mc_ver_info
->major
= le32_to_cpu(rsp_params
->version_major
);
335 mc_ver_info
->minor
= le32_to_cpu(rsp_params
->version_minor
);
341 * fsl_mc_get_root_dprc - function to traverse to the root dprc
343 static void fsl_mc_get_root_dprc(struct device
*dev
,
344 struct device
**root_dprc_dev
)
347 *root_dprc_dev
= NULL
;
348 } else if (!dev_is_fsl_mc(dev
)) {
349 *root_dprc_dev
= NULL
;
351 *root_dprc_dev
= dev
;
352 while (dev_is_fsl_mc((*root_dprc_dev
)->parent
))
353 *root_dprc_dev
= (*root_dprc_dev
)->parent
;
357 static int get_dprc_attr(struct fsl_mc_io
*mc_io
,
358 int container_id
, struct dprc_attributes
*attr
)
363 error
= dprc_open(mc_io
, 0, container_id
, &dprc_handle
);
365 dev_err(mc_io
->dev
, "dprc_open() failed: %d\n", error
);
369 memset(attr
, 0, sizeof(struct dprc_attributes
));
370 error
= dprc_get_attributes(mc_io
, 0, dprc_handle
, attr
);
372 dev_err(mc_io
->dev
, "dprc_get_attributes() failed: %d\n",
380 (void)dprc_close(mc_io
, 0, dprc_handle
);
384 static int get_dprc_icid(struct fsl_mc_io
*mc_io
,
385 int container_id
, u16
*icid
)
387 struct dprc_attributes attr
;
390 error
= get_dprc_attr(mc_io
, container_id
, &attr
);
397 static int translate_mc_addr(struct fsl_mc_device
*mc_dev
,
398 enum dprc_region_type mc_region_type
,
399 u64 mc_offset
, phys_addr_t
*phys_addr
)
402 struct device
*root_dprc_dev
;
405 fsl_mc_get_root_dprc(&mc_dev
->dev
, &root_dprc_dev
);
406 mc
= dev_get_drvdata(root_dprc_dev
->parent
);
408 if (mc
->num_translation_ranges
== 0) {
410 * Do identity mapping:
412 *phys_addr
= mc_offset
;
416 for (i
= 0; i
< mc
->num_translation_ranges
; i
++) {
417 struct fsl_mc_addr_translation_range
*range
=
418 &mc
->translation_ranges
[i
];
420 if (mc_region_type
== range
->mc_region_type
&&
421 mc_offset
>= range
->start_mc_offset
&&
422 mc_offset
< range
->end_mc_offset
) {
423 *phys_addr
= range
->start_phys_addr
+
424 (mc_offset
- range
->start_mc_offset
);
432 static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device
*mc_dev
,
433 struct fsl_mc_device
*mc_bus_dev
)
437 struct resource
*regions
;
438 struct fsl_mc_obj_desc
*obj_desc
= &mc_dev
->obj_desc
;
439 struct device
*parent_dev
= mc_dev
->dev
.parent
;
440 enum dprc_region_type mc_region_type
;
442 if (is_fsl_mc_bus_dprc(mc_dev
) ||
443 is_fsl_mc_bus_dpmcp(mc_dev
)) {
444 mc_region_type
= DPRC_REGION_TYPE_MC_PORTAL
;
445 } else if (is_fsl_mc_bus_dpio(mc_dev
)) {
446 mc_region_type
= DPRC_REGION_TYPE_QBMAN_PORTAL
;
449 * This function should not have been called for this MC object
450 * type, as this object type is not supposed to have MMIO
456 regions
= kmalloc_array(obj_desc
->region_count
,
457 sizeof(regions
[0]), GFP_KERNEL
);
461 for (i
= 0; i
< obj_desc
->region_count
; i
++) {
462 struct dprc_region_desc region_desc
;
464 error
= dprc_get_obj_region(mc_bus_dev
->mc_io
,
466 mc_bus_dev
->mc_handle
,
468 obj_desc
->id
, i
, ®ion_desc
);
471 "dprc_get_obj_region() failed: %d\n", error
);
472 goto error_cleanup_regions
;
475 error
= translate_mc_addr(mc_dev
, mc_region_type
,
476 region_desc
.base_offset
,
480 "Invalid MC offset: %#x (for %s.%d\'s region %d)\n",
481 region_desc
.base_offset
,
482 obj_desc
->type
, obj_desc
->id
, i
);
483 goto error_cleanup_regions
;
486 regions
[i
].end
= regions
[i
].start
+ region_desc
.size
- 1;
487 regions
[i
].name
= "fsl-mc object MMIO region";
488 regions
[i
].flags
= IORESOURCE_IO
;
489 if (region_desc
.flags
& DPRC_REGION_CACHEABLE
)
490 regions
[i
].flags
|= IORESOURCE_CACHEABLE
;
493 mc_dev
->regions
= regions
;
496 error_cleanup_regions
:
502 * fsl_mc_is_root_dprc - function to check if a given device is a root dprc
504 bool fsl_mc_is_root_dprc(struct device
*dev
)
506 struct device
*root_dprc_dev
;
508 fsl_mc_get_root_dprc(dev
, &root_dprc_dev
);
511 return dev
== root_dprc_dev
;
514 static void fsl_mc_device_release(struct device
*dev
)
516 struct fsl_mc_device
*mc_dev
= to_fsl_mc_device(dev
);
518 kfree(mc_dev
->regions
);
520 if (is_fsl_mc_bus_dprc(mc_dev
))
521 kfree(to_fsl_mc_bus(mc_dev
));
527 * Add a newly discovered fsl-mc device to be visible in Linux
529 int fsl_mc_device_add(struct fsl_mc_obj_desc
*obj_desc
,
530 struct fsl_mc_io
*mc_io
,
531 struct device
*parent_dev
,
532 struct fsl_mc_device
**new_mc_dev
)
535 struct fsl_mc_device
*mc_dev
= NULL
;
536 struct fsl_mc_bus
*mc_bus
= NULL
;
537 struct fsl_mc_device
*parent_mc_dev
;
539 if (dev_is_fsl_mc(parent_dev
))
540 parent_mc_dev
= to_fsl_mc_device(parent_dev
);
542 parent_mc_dev
= NULL
;
544 if (strcmp(obj_desc
->type
, "dprc") == 0) {
546 * Allocate an MC bus device object:
548 mc_bus
= kzalloc(sizeof(*mc_bus
), GFP_KERNEL
);
552 mc_dev
= &mc_bus
->mc_dev
;
555 * Allocate a regular fsl_mc_device object:
557 mc_dev
= kzalloc(sizeof(*mc_dev
), GFP_KERNEL
);
562 mc_dev
->obj_desc
= *obj_desc
;
563 mc_dev
->mc_io
= mc_io
;
564 device_initialize(&mc_dev
->dev
);
565 mc_dev
->dev
.parent
= parent_dev
;
566 mc_dev
->dev
.bus
= &fsl_mc_bus_type
;
567 mc_dev
->dev
.release
= fsl_mc_device_release
;
568 mc_dev
->dev
.type
= fsl_mc_get_device_type(obj_desc
->type
);
569 if (!mc_dev
->dev
.type
) {
571 dev_err(parent_dev
, "unknown device type %s\n", obj_desc
->type
);
572 goto error_cleanup_dev
;
574 dev_set_name(&mc_dev
->dev
, "%s.%d", obj_desc
->type
, obj_desc
->id
);
576 if (strcmp(obj_desc
->type
, "dprc") == 0) {
577 struct fsl_mc_io
*mc_io2
;
579 mc_dev
->flags
|= FSL_MC_IS_DPRC
;
582 * To get the DPRC's ICID, we need to open the DPRC
583 * in get_dprc_icid(). For child DPRCs, we do so using the
584 * parent DPRC's MC portal instead of the child DPRC's MC
585 * portal, in case the child DPRC is already opened with
586 * its own portal (e.g., the DPRC used by AIOP).
588 * NOTE: There cannot be more than one active open for a
589 * given MC object, using the same MC portal.
593 * device being added is a child DPRC device
595 mc_io2
= parent_mc_dev
->mc_io
;
598 * device being added is the root DPRC device
602 goto error_cleanup_dev
;
608 error
= get_dprc_icid(mc_io2
, obj_desc
->id
, &mc_dev
->icid
);
610 goto error_cleanup_dev
;
613 * A non-DPRC object has to be a child of a DPRC, use the
614 * parent's ICID and interrupt domain.
616 mc_dev
->icid
= parent_mc_dev
->icid
;
617 mc_dev
->dma_mask
= FSL_MC_DEFAULT_DMA_MASK
;
618 mc_dev
->dev
.dma_mask
= &mc_dev
->dma_mask
;
619 dev_set_msi_domain(&mc_dev
->dev
,
620 dev_get_msi_domain(&parent_mc_dev
->dev
));
624 * Get MMIO regions for the device from the MC:
626 * NOTE: the root DPRC is a special case as its MMIO region is
627 * obtained from the device tree
629 if (parent_mc_dev
&& obj_desc
->region_count
!= 0) {
630 error
= fsl_mc_device_get_mmio_regions(mc_dev
,
633 goto error_cleanup_dev
;
636 /* Objects are coherent, unless 'no shareability' flag set. */
637 if (!(obj_desc
->flags
& FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY
))
638 arch_setup_dma_ops(&mc_dev
->dev
, 0, 0, NULL
, true);
641 * The device-specific probe callback will get invoked by device_add()
643 error
= device_add(&mc_dev
->dev
);
646 "device_add() failed for device %s: %d\n",
647 dev_name(&mc_dev
->dev
), error
);
648 goto error_cleanup_dev
;
651 dev_dbg(parent_dev
, "added %s\n", dev_name(&mc_dev
->dev
));
653 *new_mc_dev
= mc_dev
;
657 kfree(mc_dev
->regions
);
663 EXPORT_SYMBOL_GPL(fsl_mc_device_add
);
666 * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
669 * @mc_dev: Pointer to an fsl-mc device
671 void fsl_mc_device_remove(struct fsl_mc_device
*mc_dev
)
674 * The device-specific remove callback will get invoked by device_del()
676 device_del(&mc_dev
->dev
);
677 put_device(&mc_dev
->dev
);
679 EXPORT_SYMBOL_GPL(fsl_mc_device_remove
);
681 static int parse_mc_ranges(struct device
*dev
,
685 const __be32
**ranges_start
)
688 int range_tuple_cell_count
;
691 struct device_node
*mc_node
= dev
->of_node
;
693 *ranges_start
= of_get_property(mc_node
, "ranges", &ranges_len
);
694 if (!(*ranges_start
) || !ranges_len
) {
696 "missing or empty ranges property for device tree node '%s'\n",
701 *paddr_cells
= of_n_addr_cells(mc_node
);
703 prop
= of_get_property(mc_node
, "#address-cells", NULL
);
705 *mc_addr_cells
= be32_to_cpup(prop
);
707 *mc_addr_cells
= *paddr_cells
;
709 prop
= of_get_property(mc_node
, "#size-cells", NULL
);
711 *mc_size_cells
= be32_to_cpup(prop
);
713 *mc_size_cells
= of_n_size_cells(mc_node
);
715 range_tuple_cell_count
= *paddr_cells
+ *mc_addr_cells
+
718 tuple_len
= range_tuple_cell_count
* sizeof(__be32
);
719 if (ranges_len
% tuple_len
!= 0) {
720 dev_err(dev
, "malformed ranges property '%s'\n", mc_node
->name
);
724 return ranges_len
/ tuple_len
;
727 static int get_mc_addr_translation_ranges(struct device
*dev
,
728 struct fsl_mc_addr_translation_range
737 const __be32
*ranges_start
;
740 ret
= parse_mc_ranges(dev
,
751 * Missing or empty ranges property ("ranges;") for the
752 * 'fsl,qoriq-mc' node. In this case, identity mapping
759 *ranges
= devm_kcalloc(dev
, *num_ranges
,
760 sizeof(struct fsl_mc_addr_translation_range
),
766 for (i
= 0; i
< *num_ranges
; ++i
) {
767 struct fsl_mc_addr_translation_range
*range
= &(*ranges
)[i
];
769 range
->mc_region_type
= of_read_number(cell
, 1);
770 range
->start_mc_offset
= of_read_number(cell
+ 1,
772 cell
+= mc_addr_cells
;
773 range
->start_phys_addr
= of_read_number(cell
, paddr_cells
);
775 range
->end_mc_offset
= range
->start_mc_offset
+
776 of_read_number(cell
, mc_size_cells
);
778 cell
+= mc_size_cells
;
785 * fsl_mc_bus_probe - callback invoked when the root MC bus is being
788 static int fsl_mc_bus_probe(struct platform_device
*pdev
)
790 struct fsl_mc_obj_desc obj_desc
;
793 struct fsl_mc_device
*mc_bus_dev
= NULL
;
794 struct fsl_mc_io
*mc_io
= NULL
;
796 phys_addr_t mc_portal_phys_addr
;
798 struct mc_version mc_version
;
801 mc
= devm_kzalloc(&pdev
->dev
, sizeof(*mc
), GFP_KERNEL
);
805 platform_set_drvdata(pdev
, mc
);
808 * Get physical address of MC portal for the root DPRC:
810 error
= of_address_to_resource(pdev
->dev
.of_node
, 0, &res
);
813 "of_address_to_resource() failed for %pOF\n",
818 mc_portal_phys_addr
= res
.start
;
819 mc_portal_size
= resource_size(&res
);
820 error
= fsl_create_mc_io(&pdev
->dev
, mc_portal_phys_addr
,
821 mc_portal_size
, NULL
,
822 FSL_MC_IO_ATOMIC_CONTEXT_PORTAL
, &mc_io
);
826 error
= mc_get_version(mc_io
, 0, &mc_version
);
829 "mc_get_version() failed with error %d\n", error
);
830 goto error_cleanup_mc_io
;
833 dev_info(&pdev
->dev
, "MC firmware version: %u.%u.%u\n",
834 mc_version
.major
, mc_version
.minor
, mc_version
.revision
);
836 error
= get_mc_addr_translation_ranges(&pdev
->dev
,
837 &mc
->translation_ranges
,
838 &mc
->num_translation_ranges
);
840 goto error_cleanup_mc_io
;
842 error
= dprc_get_container_id(mc_io
, 0, &container_id
);
845 "dprc_get_container_id() failed: %d\n", error
);
846 goto error_cleanup_mc_io
;
849 memset(&obj_desc
, 0, sizeof(struct fsl_mc_obj_desc
));
850 error
= dprc_get_api_version(mc_io
, 0,
852 &obj_desc
.ver_minor
);
854 goto error_cleanup_mc_io
;
856 obj_desc
.vendor
= FSL_MC_VENDOR_FREESCALE
;
857 strcpy(obj_desc
.type
, "dprc");
858 obj_desc
.id
= container_id
;
859 obj_desc
.irq_count
= 1;
860 obj_desc
.region_count
= 0;
862 error
= fsl_mc_device_add(&obj_desc
, mc_io
, &pdev
->dev
, &mc_bus_dev
);
864 goto error_cleanup_mc_io
;
866 mc
->root_mc_bus_dev
= mc_bus_dev
;
870 fsl_destroy_mc_io(mc_io
);
875 * fsl_mc_bus_remove - callback invoked when the root MC bus is being
878 static int fsl_mc_bus_remove(struct platform_device
*pdev
)
880 struct fsl_mc
*mc
= platform_get_drvdata(pdev
);
882 if (!fsl_mc_is_root_dprc(&mc
->root_mc_bus_dev
->dev
))
885 fsl_mc_device_remove(mc
->root_mc_bus_dev
);
887 fsl_destroy_mc_io(mc
->root_mc_bus_dev
->mc_io
);
888 mc
->root_mc_bus_dev
->mc_io
= NULL
;
893 static const struct of_device_id fsl_mc_bus_match_table
[] = {
894 {.compatible
= "fsl,qoriq-mc",},
898 MODULE_DEVICE_TABLE(of
, fsl_mc_bus_match_table
);
900 static struct platform_driver fsl_mc_bus_driver
= {
902 .name
= "fsl_mc_bus",
904 .of_match_table
= fsl_mc_bus_match_table
,
906 .probe
= fsl_mc_bus_probe
,
907 .remove
= fsl_mc_bus_remove
,
910 static int __init
fsl_mc_bus_driver_init(void)
914 error
= bus_register(&fsl_mc_bus_type
);
916 pr_err("bus type registration failed: %d\n", error
);
917 goto error_cleanup_cache
;
920 error
= platform_driver_register(&fsl_mc_bus_driver
);
922 pr_err("platform_driver_register() failed: %d\n", error
);
923 goto error_cleanup_bus
;
926 error
= dprc_driver_init();
928 goto error_cleanup_driver
;
930 error
= fsl_mc_allocator_driver_init();
932 goto error_cleanup_dprc_driver
;
936 error_cleanup_dprc_driver
:
939 error_cleanup_driver
:
940 platform_driver_unregister(&fsl_mc_bus_driver
);
943 bus_unregister(&fsl_mc_bus_type
);
948 postcore_initcall(fsl_mc_bus_driver_init
);