Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Freescale Management Complex (MC) bus driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright 2019-2020 NXP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Author: German Rivera <German.Rivera@freescale.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #define pr_fmt(fmt) "fsl-mc: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/msi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/iommu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include "fsl-mc-private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Default DMA mask for devices on a fsl-mc bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #define FSL_MC_DEFAULT_DMA_MASK	(~0ULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) static struct fsl_mc_version mc_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * @root_mc_bus_dev: fsl-mc device representing the root DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * @num_translation_ranges: number of entries in addr_translation_ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  * @translation_ranges: array of bus to system address translation ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) struct fsl_mc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	struct fsl_mc_device *root_mc_bus_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	u8 num_translation_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	struct fsl_mc_addr_translation_range *translation_ranges;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	void *fsl_mc_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * struct fsl_mc_addr_translation_range - bus to system address translation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  * range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  * @mc_region_type: Type of MC region for the range being translated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  * @start_mc_offset: Start MC offset of the range being translated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  * @end_mc_offset: MC offset of the first byte after the range (last MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  * offset of the range is end_mc_offset - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  * @start_phys_addr: system physical address corresponding to start_mc_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) struct fsl_mc_addr_translation_range {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	enum dprc_region_type mc_region_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	u64 start_mc_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	u64 end_mc_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	phys_addr_t start_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define FSL_MC_FAPR	0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define MC_FAPR_PL	BIT(18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define MC_FAPR_BMT	BIT(17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static phys_addr_t mc_portal_base_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * fsl_mc_bus_match - device to driver matching callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * @dev: the fsl-mc device to match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  * @drv: the device driver to search for matching fsl-mc object type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  * structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * Returns 1 on success, 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	const struct fsl_mc_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	/* When driver_override is set, only bind to the matching driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	if (mc_dev->driver_override) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	if (!mc_drv->match_id_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	 * If the object is not 'plugged' don't match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	 * Only exception is the root DPRC, which is a special case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	if ((mc_dev->obj_desc.state & FSL_MC_OBJ_STATE_PLUGGED) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	    !fsl_mc_is_root_dprc(&mc_dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	 * Traverse the match_id table of the given driver, trying to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	 * a matching for the given device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 		if (id->vendor == mc_dev->obj_desc.vendor &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		    strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 			found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	dev_dbg(dev, "%smatched\n", found ? "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)  * fsl_mc_bus_uevent - callback invoked when a device is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	if (add_uevent_var(env, "MODALIAS=fsl-mc:v%08Xd%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 			   mc_dev->obj_desc.vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 			   mc_dev->obj_desc.type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static int fsl_mc_dma_configure(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	struct device *dma_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	u32 input_id = mc_dev->icid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	while (dev_is_fsl_mc(dma_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		dma_dev = dma_dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	if (dev_of_node(dma_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		return of_dma_configure_id(dev, dma_dev->of_node, 0, &input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	return acpi_dma_configure_id(dev, DEV_DMA_COHERENT, &input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 			     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	return sprintf(buf, "fsl-mc:v%08Xd%s\n", mc_dev->obj_desc.vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		       mc_dev->obj_desc.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) static ssize_t driver_override_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 				     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	char *driver_override, *old = mc_dev->driver_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	if (WARN_ON(dev->bus != &fsl_mc_bus_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	if (count >= (PAGE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	driver_override = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	if (!driver_override)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	cp = strchr(driver_override, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	if (cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		*cp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	if (strlen(driver_override)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		mc_dev->driver_override = driver_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		kfree(driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		mc_dev->driver_override = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	kfree(old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static ssize_t driver_override_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 				    struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) static DEVICE_ATTR_RW(driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) static struct attribute *fsl_mc_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	&dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	&dev_attr_driver_override.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) ATTRIBUTE_GROUPS(fsl_mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) struct bus_type fsl_mc_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	.name = "fsl-mc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	.match = fsl_mc_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	.uevent = fsl_mc_bus_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	.dma_configure  = fsl_mc_dma_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	.dev_groups = fsl_mc_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) struct device_type fsl_mc_bus_dprc_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	.name = "fsl_mc_bus_dprc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) EXPORT_SYMBOL_GPL(fsl_mc_bus_dprc_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) struct device_type fsl_mc_bus_dpni_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.name = "fsl_mc_bus_dpni"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpni_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) struct device_type fsl_mc_bus_dpio_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	.name = "fsl_mc_bus_dpio"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpio_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) struct device_type fsl_mc_bus_dpsw_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	.name = "fsl_mc_bus_dpsw"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpsw_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) struct device_type fsl_mc_bus_dpbp_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	.name = "fsl_mc_bus_dpbp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpbp_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) struct device_type fsl_mc_bus_dpcon_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	.name = "fsl_mc_bus_dpcon"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpcon_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) struct device_type fsl_mc_bus_dpmcp_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	.name = "fsl_mc_bus_dpmcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmcp_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) struct device_type fsl_mc_bus_dpmac_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	.name = "fsl_mc_bus_dpmac"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpmac_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) struct device_type fsl_mc_bus_dprtc_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	.name = "fsl_mc_bus_dprtc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) EXPORT_SYMBOL_GPL(fsl_mc_bus_dprtc_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) struct device_type fsl_mc_bus_dpseci_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	.name = "fsl_mc_bus_dpseci"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpseci_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) struct device_type fsl_mc_bus_dpdmux_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	.name = "fsl_mc_bus_dpdmux"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmux_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) struct device_type fsl_mc_bus_dpdcei_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	.name = "fsl_mc_bus_dpdcei"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdcei_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) struct device_type fsl_mc_bus_dpaiop_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.name = "fsl_mc_bus_dpaiop"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpaiop_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) struct device_type fsl_mc_bus_dpci_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	.name = "fsl_mc_bus_dpci"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpci_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) struct device_type fsl_mc_bus_dpdmai_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	.name = "fsl_mc_bus_dpdmai"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) EXPORT_SYMBOL_GPL(fsl_mc_bus_dpdmai_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) static struct device_type *fsl_mc_get_device_type(const char *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		struct device_type *dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		const char *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	} dev_types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		{ &fsl_mc_bus_dprc_type, "dprc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		{ &fsl_mc_bus_dpni_type, "dpni" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		{ &fsl_mc_bus_dpio_type, "dpio" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		{ &fsl_mc_bus_dpsw_type, "dpsw" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		{ &fsl_mc_bus_dpbp_type, "dpbp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		{ &fsl_mc_bus_dpcon_type, "dpcon" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		{ &fsl_mc_bus_dpmcp_type, "dpmcp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		{ &fsl_mc_bus_dpmac_type, "dpmac" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		{ &fsl_mc_bus_dprtc_type, "dprtc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		{ &fsl_mc_bus_dpseci_type, "dpseci" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		{ &fsl_mc_bus_dpdmux_type, "dpdmux" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		{ &fsl_mc_bus_dpdcei_type, "dpdcei" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		{ &fsl_mc_bus_dpaiop_type, "dpaiop" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		{ &fsl_mc_bus_dpci_type, "dpci" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		{ &fsl_mc_bus_dpdmai_type, "dpdmai" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		{ NULL, NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	for (i = 0; dev_types[i].dev_type; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		if (!strcmp(dev_types[i].type, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			return dev_types[i].dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) static int fsl_mc_driver_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct fsl_mc_driver *mc_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	mc_drv = to_fsl_mc_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	error = mc_drv->probe(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			dev_err(dev, "%s failed: %d\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) static int fsl_mc_driver_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	error = mc_drv->remove(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		dev_err(dev, "%s failed: %d\n", __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) static void fsl_mc_driver_shutdown(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	mc_drv->shutdown(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  * __fsl_mc_driver_register - registers a child device driver with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  * MC bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)  * This function is implicitly invoked from the registration function of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  * fsl_mc device drivers, which is generated by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)  * module_fsl_mc_driver() macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			     struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	mc_driver->driver.owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	mc_driver->driver.bus = &fsl_mc_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (mc_driver->probe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		mc_driver->driver.probe = fsl_mc_driver_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	if (mc_driver->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		mc_driver->driver.remove = fsl_mc_driver_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (mc_driver->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		mc_driver->driver.shutdown = fsl_mc_driver_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	error = driver_register(&mc_driver->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		pr_err("driver_register() failed for %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		       mc_driver->driver.name, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) EXPORT_SYMBOL_GPL(__fsl_mc_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  * fsl_mc_driver_unregister - unregisters a device driver from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  * MC bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	driver_unregister(&mc_driver->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * mc_get_version() - Retrieves the Management Complex firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  *			version information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  * @mc_io:		Pointer to opaque I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * @mc_ver_info:	Returned version information structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  * Return:	'0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static int mc_get_version(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			  u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			  struct fsl_mc_version *mc_ver_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	struct dpmng_rsp_get_version *rsp_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	/* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 					  cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 					  0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	/* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	/* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	rsp_params = (struct dpmng_rsp_get_version *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	mc_ver_info->revision = le32_to_cpu(rsp_params->revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	mc_ver_info->major = le32_to_cpu(rsp_params->version_major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	mc_ver_info->minor = le32_to_cpu(rsp_params->version_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  * fsl_mc_get_version - function to retrieve the MC f/w version information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  * Return:	mc version when called after fsl-mc-bus probe; NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) struct fsl_mc_version *fsl_mc_get_version(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	if (mc_version.major)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		return &mc_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) EXPORT_SYMBOL_GPL(fsl_mc_get_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  * fsl_mc_get_root_dprc - function to traverse to the root dprc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) void fsl_mc_get_root_dprc(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			 struct device **root_dprc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		*root_dprc_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	} else if (!dev_is_fsl_mc(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		*root_dprc_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		*root_dprc_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		while (dev_is_fsl_mc((*root_dprc_dev)->parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			*root_dprc_dev = (*root_dprc_dev)->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) static int get_dprc_attr(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			 int container_id, struct dprc_attributes *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	u16 dprc_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	error = dprc_open(mc_io, 0, container_id, &dprc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		dev_err(mc_io->dev, "dprc_open() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	memset(attr, 0, sizeof(struct dprc_attributes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	error = dprc_get_attributes(mc_io, 0, dprc_handle, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		dev_err(mc_io->dev, "dprc_get_attributes() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		goto common_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) common_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	(void)dprc_close(mc_io, 0, dprc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) static int get_dprc_icid(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			 int container_id, u32 *icid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	struct dprc_attributes attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	error = get_dprc_attr(mc_io, container_id, &attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	if (error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		*icid = attr.icid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static int translate_mc_addr(struct fsl_mc_device *mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			     enum dprc_region_type mc_region_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			     u64 mc_offset, phys_addr_t *phys_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	struct device *root_dprc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	struct fsl_mc *mc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	mc = dev_get_drvdata(root_dprc_dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	if (mc->num_translation_ranges == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		 * Do identity mapping:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		*phys_addr = mc_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	for (i = 0; i < mc->num_translation_ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		struct fsl_mc_addr_translation_range *range =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			&mc->translation_ranges[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		if (mc_region_type == range->mc_region_type &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		    mc_offset >= range->start_mc_offset &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		    mc_offset < range->end_mc_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			*phys_addr = range->start_phys_addr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 				     (mc_offset - range->start_mc_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 					  struct fsl_mc_device *mc_bus_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	struct resource *regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	struct fsl_mc_obj_desc *obj_desc = &mc_dev->obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct device *parent_dev = mc_dev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	enum dprc_region_type mc_region_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	if (is_fsl_mc_bus_dprc(mc_dev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	    is_fsl_mc_bus_dpmcp(mc_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		mc_region_type = DPRC_REGION_TYPE_MC_PORTAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	} else if (is_fsl_mc_bus_dpio(mc_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		 * This function should not have been called for this MC object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		 * type, as this object type is not supposed to have MMIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		 * regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	regions = kmalloc_array(obj_desc->region_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 				sizeof(regions[0]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	if (!regions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	for (i = 0; i < obj_desc->region_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		struct dprc_region_desc region_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		error = dprc_get_obj_region(mc_bus_dev->mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 					    0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 					    mc_bus_dev->mc_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 					    obj_desc->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 					    obj_desc->id, i, &region_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 			dev_err(parent_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 				"dprc_get_obj_region() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			goto error_cleanup_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		 * Older MC only returned region offset and no base address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		 * If base address is in the region_desc use it otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		 * revert to old mechanism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		if (region_desc.base_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			regions[i].start = region_desc.base_address +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 						region_desc.base_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			error = translate_mc_addr(mc_dev, mc_region_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 					  region_desc.base_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 					  &regions[i].start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			 * Some versions of the MC firmware wrongly report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			 * 0 for register base address of the DPMCP associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			 * with child DPRC objects thus rendering them unusable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			 * This is particularly troublesome in ACPI boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			 * scenarios where the legacy way of extracting this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			 * base address from the device tree does not apply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			 * Given that DPMCPs share the same base address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 			 * workaround this by using the base address extracted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			 * from the root DPRC container.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			if (is_fsl_mc_bus_dprc(mc_dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			    regions[i].start == region_desc.base_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 				regions[i].start += mc_portal_base_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			dev_err(parent_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				"Invalid MC offset: %#x (for %s.%d\'s region %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				region_desc.base_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 				obj_desc->type, obj_desc->id, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 			goto error_cleanup_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		regions[i].end = regions[i].start + region_desc.size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		regions[i].name = "fsl-mc object MMIO region";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		regions[i].flags = region_desc.flags & IORESOURCE_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		regions[i].flags |= IORESOURCE_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	mc_dev->regions = regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) error_cleanup_regions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	kfree(regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)  * fsl_mc_is_root_dprc - function to check if a given device is a root dprc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) bool fsl_mc_is_root_dprc(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct device *root_dprc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	fsl_mc_get_root_dprc(dev, &root_dprc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	if (!root_dprc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	return dev == root_dprc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) static void fsl_mc_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	kfree(mc_dev->regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (is_fsl_mc_bus_dprc(mc_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		kfree(to_fsl_mc_bus(mc_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		kfree(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)  * Add a newly discovered fsl-mc device to be visible in Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		      struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		      struct device *parent_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		      struct fsl_mc_device **new_mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	struct fsl_mc_device *mc_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	struct fsl_mc_bus *mc_bus = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	struct fsl_mc_device *parent_mc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	if (dev_is_fsl_mc(parent_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		parent_mc_dev = to_fsl_mc_device(parent_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		parent_mc_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	if (strcmp(obj_desc->type, "dprc") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		 * Allocate an MC bus device object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		if (!mc_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		mutex_init(&mc_bus->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		mc_dev = &mc_bus->mc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		 * Allocate a regular fsl_mc_device object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		if (!mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	mc_dev->obj_desc = *obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	mc_dev->mc_io = mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	device_initialize(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	mc_dev->dev.parent = parent_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	mc_dev->dev.bus = &fsl_mc_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	mc_dev->dev.release = fsl_mc_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (!mc_dev->dev.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		dev_err(parent_dev, "unknown device type %s\n", obj_desc->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		goto error_cleanup_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	if (strcmp(obj_desc->type, "dprc") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		struct fsl_mc_io *mc_io2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		mc_dev->flags |= FSL_MC_IS_DPRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		 * To get the DPRC's ICID, we need to open the DPRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		 * in get_dprc_icid(). For child DPRCs, we do so using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		 * parent DPRC's MC portal instead of the child DPRC's MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		 * portal, in case the child DPRC is already opened with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		 * its own portal (e.g., the DPRC used by AIOP).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		 * NOTE: There cannot be more than one active open for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		 * given MC object, using the same MC portal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		if (parent_mc_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			 * device being added is a child DPRC device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			mc_io2 = parent_mc_dev->mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			 * device being added is the root DPRC device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			if (!mc_io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 				error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				goto error_cleanup_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			mc_io2 = mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			goto error_cleanup_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		 * A non-DPRC object has to be a child of a DPRC, use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		 * parent's ICID and interrupt domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		mc_dev->icid = parent_mc_dev->icid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		mc_dev->dev.dma_mask = &mc_dev->dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		mc_dev->dev.coherent_dma_mask = mc_dev->dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		dev_set_msi_domain(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 				   dev_get_msi_domain(&parent_mc_dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	 * Get MMIO regions for the device from the MC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	 * NOTE: the root DPRC is a special case as its MMIO region is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	 * obtained from the device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (parent_mc_dev && obj_desc->region_count != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		error = fsl_mc_device_get_mmio_regions(mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 						       parent_mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			goto error_cleanup_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	 * The device-specific probe callback will get invoked by device_add()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	error = device_add(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		dev_err(parent_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			"device_add() failed for device %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			dev_name(&mc_dev->dev), error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		goto error_cleanup_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	*new_mc_dev = mc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) error_cleanup_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	kfree(mc_dev->regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	kfree(mc_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	kfree(mc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) EXPORT_SYMBOL_GPL(fsl_mc_device_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  * Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)  * @mc_dev: Pointer to an fsl-mc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	kfree(mc_dev->driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	mc_dev->driver_override = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	 * The device-specific remove callback will get invoked by device_del()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	device_del(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	put_device(&mc_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct fsl_mc_device *mc_bus_dev, *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	struct fsl_mc_obj_desc endpoint_desc = {{ 0 }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	struct dprc_endpoint endpoint1 = {{ 0 }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	struct dprc_endpoint endpoint2 = {{ 0 }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	int state, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	strcpy(endpoint1.type, mc_dev->obj_desc.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	endpoint1.id = mc_dev->obj_desc.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	err = dprc_get_connection(mc_bus_dev->mc_io, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 				  mc_bus_dev->mc_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 				  &endpoint1, &endpoint2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 				  &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	if (err == -ENOTCONN || state == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		return ERR_PTR(-ENOTCONN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		dev_err(&mc_bus_dev->dev, "dprc_get_connection() = %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	strcpy(endpoint_desc.type, endpoint2.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	endpoint_desc.id = endpoint2.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) EXPORT_SYMBOL_GPL(fsl_mc_get_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) static int parse_mc_ranges(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 			   int *paddr_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			   int *mc_addr_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			   int *mc_size_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 			   const __be32 **ranges_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	const __be32 *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	int range_tuple_cell_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	int ranges_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	int tuple_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	struct device_node *mc_node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	*ranges_start = of_get_property(mc_node, "ranges", &ranges_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	if (!(*ranges_start) || !ranges_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 			 "missing or empty ranges property for device tree node '%pOFn'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			 mc_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	*paddr_cells = of_n_addr_cells(mc_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	prop = of_get_property(mc_node, "#address-cells", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	if (prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		*mc_addr_cells = be32_to_cpup(prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		*mc_addr_cells = *paddr_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	prop = of_get_property(mc_node, "#size-cells", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		*mc_size_cells = be32_to_cpup(prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		*mc_size_cells = of_n_size_cells(mc_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	range_tuple_cell_count = *paddr_cells + *mc_addr_cells +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 				 *mc_size_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	tuple_len = range_tuple_cell_count * sizeof(__be32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	if (ranges_len % tuple_len != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		dev_err(dev, "malformed ranges property '%pOFn'\n", mc_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	return ranges_len / tuple_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) static int get_mc_addr_translation_ranges(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 					  struct fsl_mc_addr_translation_range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 						**ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 					  u8 *num_ranges)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	int paddr_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	int mc_addr_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	int mc_size_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	const __be32 *ranges_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	const __be32 *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	ret = parse_mc_ranges(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			      &paddr_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 			      &mc_addr_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			      &mc_size_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			      &ranges_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	*num_ranges = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		 * Missing or empty ranges property ("ranges;") for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		 * 'fsl,qoriq-mc' node. In this case, identity mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		 * will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		*ranges = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	*ranges = devm_kcalloc(dev, *num_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			       sizeof(struct fsl_mc_addr_translation_range),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 			       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (!(*ranges))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	cell = ranges_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	for (i = 0; i < *num_ranges; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		struct fsl_mc_addr_translation_range *range = &(*ranges)[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		range->mc_region_type = of_read_number(cell, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		range->start_mc_offset = of_read_number(cell + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 							mc_addr_cells - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		cell += mc_addr_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		range->start_phys_addr = of_read_number(cell, paddr_cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		cell += paddr_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		range->end_mc_offset = range->start_mc_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				     of_read_number(cell, mc_size_cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		cell += mc_size_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * fsl_mc_bus_probe - callback invoked when the root MC bus is being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  * added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) static int fsl_mc_bus_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	struct fsl_mc_obj_desc obj_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	struct fsl_mc *mc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct fsl_mc_device *mc_bus_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	struct fsl_mc_io *mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	int container_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	phys_addr_t mc_portal_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	u32 mc_portal_size, mc_stream_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	struct resource *plat_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	if (!mc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	platform_set_drvdata(pdev, mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	if (plat_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		mc->fsl_mc_regs = devm_ioremap_resource(&pdev->dev, plat_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		if (IS_ERR(mc->fsl_mc_regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			return PTR_ERR(mc->fsl_mc_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	if (mc->fsl_mc_regs && IS_ENABLED(CONFIG_ACPI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	    !dev_of_node(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		mc_stream_id = readl(mc->fsl_mc_regs + FSL_MC_FAPR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		 * HW ORs the PL and BMT bit, places the result in bit 15 of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		 * the StreamID and ORs in the ICID. Calculate it accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		mc_stream_id = (mc_stream_id & 0xffff) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 				((mc_stream_id & (MC_FAPR_PL | MC_FAPR_BMT)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 					0x4000 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		error = acpi_dma_configure_id(&pdev->dev, DEV_DMA_COHERENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 					      &mc_stream_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 			dev_warn(&pdev->dev, "failed to configure dma: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 				 error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * Get physical address of MC portal for the root DPRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	plat_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	mc_portal_phys_addr = plat_res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	mc_portal_size = resource_size(plat_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	mc_portal_base_phys_addr = mc_portal_phys_addr & ~0x3ffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 				 mc_portal_size, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				 FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	error = mc_get_version(mc_io, 0, &mc_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	if (error != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 			"mc_get_version() failed with error %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		 mc_version.major, mc_version.minor, mc_version.revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (dev_of_node(&pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		error = get_mc_addr_translation_ranges(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 						&mc->translation_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 						&mc->num_translation_ranges);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	error = dprc_get_container_id(mc_io, 0, &container_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			"dprc_get_container_id() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	memset(&obj_desc, 0, sizeof(struct fsl_mc_obj_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	error = dprc_get_api_version(mc_io, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 				     &obj_desc.ver_major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 				     &obj_desc.ver_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	obj_desc.vendor = FSL_MC_VENDOR_FREESCALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	strcpy(obj_desc.type, "dprc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	obj_desc.id = container_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	obj_desc.irq_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	obj_desc.region_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	mc->root_mc_bus_dev = mc_bus_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	mc_bus_dev->dev.fwnode = pdev->dev.fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) error_cleanup_mc_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	fsl_destroy_mc_io(mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  * fsl_mc_bus_remove - callback invoked when the root MC bus is being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)  * removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static int fsl_mc_bus_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	struct fsl_mc *mc = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	fsl_mc_device_remove(mc->root_mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	mc->root_mc_bus_dev->mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static const struct of_device_id fsl_mc_bus_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	{.compatible = "fsl,qoriq-mc",},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) static const struct acpi_device_id fsl_mc_bus_acpi_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	{"NXP0008", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) MODULE_DEVICE_TABLE(acpi, fsl_mc_bus_acpi_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static struct platform_driver fsl_mc_bus_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		   .name = "fsl_mc_bus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		   .pm = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		   .of_match_table = fsl_mc_bus_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		   .acpi_match_table = fsl_mc_bus_acpi_match_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	.probe = fsl_mc_bus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	.remove = fsl_mc_bus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static int __init fsl_mc_bus_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	error = bus_register(&fsl_mc_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		pr_err("bus type registration failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		goto error_cleanup_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	error = platform_driver_register(&fsl_mc_bus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		pr_err("platform_driver_register() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		goto error_cleanup_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	error = dprc_driver_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		goto error_cleanup_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	error = fsl_mc_allocator_driver_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		goto error_cleanup_dprc_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) error_cleanup_dprc_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	dprc_driver_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) error_cleanup_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	platform_driver_unregister(&fsl_mc_bus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) error_cleanup_bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	bus_unregister(&fsl_mc_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) error_cleanup_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) postcore_initcall(fsl_mc_bus_driver_init);