From df5e9b5fbc4e68a0f0345fbc0f65e60d7440279f Mon Sep 17 00:00:00 2001 From: Nipun Gupta Date: Wed, 29 Jun 2016 22:44:39 +0530 Subject: fsl-mc: add helper macro to determine if a device is of fsl_mc type Add a helper macro to return if a device has a bus type of fsl_mc. This makes the bus driver code more readable and provides a way for drivers like the SMMU driver to easily check the bus type. Signed-off-by: Nipun Gupta Signed-off-by: Bharat Bhushan Acked-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-driver.c | 4 ++-- drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +- drivers/staging/fsl-mc/bus/mc-allocator.c | 6 +++--- drivers/staging/fsl-mc/bus/mc-bus.c | 6 +++--- drivers/staging/fsl-mc/include/mc.h | 7 +++++++ 5 files changed, 16 insertions(+), 9 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index d2a71f14bf72..0523ba8a1965 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -649,7 +649,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev) /* * This is a child DPRC: */ - if (WARN_ON(parent_dev->bus != &fsl_mc_bus_type)) + if (WARN_ON(!dev_is_fsl_mc(parent_dev))) return -EINVAL; if (WARN_ON(mc_dev->obj_desc.region_count == 0)) @@ -681,7 +681,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev) */ struct irq_domain *mc_msi_domain; - if (WARN_ON(parent_dev->bus == &fsl_mc_bus_type)) + if (WARN_ON(dev_is_fsl_mc(parent_dev))) return -EINVAL; error = fsl_mc_find_msi_domain(parent_dev, diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c index 720e2b018d00..d0c20d669309 100644 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c @@ -35,7 +35,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain, struct fsl_mc_device *mc_bus_dev; struct msi_domain_info *msi_info; - if (WARN_ON(dev->bus != &fsl_mc_bus_type)) + if (WARN_ON(!dev_is_fsl_mc(dev))) return -EINVAL; mc_bus_dev = to_fsl_mc_device(dev); diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c index e59d85060c7b..0f50a07fe10c 100644 --- a/drivers/staging/fsl-mc/bus/mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/mc-allocator.c @@ -281,7 +281,7 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, if (mc_dev->flags & FSL_MC_IS_DPRC) { mc_bus_dev = mc_dev; } else { - if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type)) + if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) return error; mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); @@ -420,7 +420,7 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC)) goto error; - if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type)) + if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) goto error; if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP)) @@ -678,7 +678,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) return -EINVAL; mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - if (WARN_ON(mc_bus_dev->dev.bus != &fsl_mc_bus_type)) + if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev))) return -EINVAL; mc_bus = to_fsl_mc_bus(mc_bus_dev); diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c index db3afdbdf4ae..b54900565acb 100644 --- a/drivers/staging/fsl-mc/bus/mc-bus.c +++ b/drivers/staging/fsl-mc/bus/mc-bus.c @@ -236,11 +236,11 @@ static void fsl_mc_get_root_dprc(struct device *dev, { if (WARN_ON(!dev)) { *root_dprc_dev = NULL; - } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) { + } else if (WARN_ON(!dev_is_fsl_mc(dev))) { *root_dprc_dev = NULL; } else { *root_dprc_dev = dev; - while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type) + while (dev_is_fsl_mc((*root_dprc_dev)->parent)) *root_dprc_dev = (*root_dprc_dev)->parent; } } @@ -434,7 +434,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc, struct fsl_mc_bus *mc_bus = NULL; struct fsl_mc_device *parent_mc_dev; - if (parent_dev->bus == &fsl_mc_bus_type) + if (dev_is_fsl_mc(parent_dev)) parent_mc_dev = to_fsl_mc_device(parent_dev); else parent_mc_dev = NULL; diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index 853cbf38a400..2d6753532c96 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -166,6 +166,13 @@ struct fsl_mc_device { #define to_fsl_mc_device(_dev) \ container_of(_dev, struct fsl_mc_device, dev) +#ifdef CONFIG_FSL_MC_BUS +#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type) +#else +/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */ +#define dev_is_fsl_mc(_dev) (0) +#endif + /* * module_fsl_mc_driver() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of -- cgit v1.2.3-59-g8ed1b From 37f144008a36bd8394ebc00ac562a1bbf426c7a5 Mon Sep 17 00:00:00 2001 From: Paul Gortmaker Date: Sat, 2 Jul 2016 19:48:51 -0400 Subject: staging: fsl-mc: make bus/mc-bus explicitly non-modular The Kconfig currently controlling compilation of this code is: config FSL_MC_BUS bool "Freescale Management Complex (MC) bus driver" ...meaning that it currently is not being built as a module by anyone. Lets remove the modular code that is essentially orphaned, so that when reading the driver there is no doubt it is builtin-only. Since the code was already not using module_init, we don't have to change the initcall and the init ordering remains unchanged with this commit. We also delete the MODULE_LICENSE tag etc. since all that information is already contained at the top of the file in the comments. We don't replace module.h with init.h since the file does make some references to "struct *module" for processing other modules. Cc: "J. German Rivera" Cc: Greg Kroah-Hartman Cc: devel@driverdev.osuosl.org Signed-off-by: Paul Gortmaker Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/mc-bus.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c index b54900565acb..fe20c5d6994c 100644 --- a/drivers/staging/fsl-mc/bus/mc-bus.c +++ b/drivers/staging/fsl-mc/bus/mc-bus.c @@ -887,25 +887,4 @@ error_cleanup_cache: kmem_cache_destroy(mc_dev_cache); return error; } - postcore_initcall(fsl_mc_bus_driver_init); - -static void __exit fsl_mc_bus_driver_exit(void) -{ - if (WARN_ON(!mc_dev_cache)) - return; - - its_fsl_mc_msi_cleanup(); - fsl_mc_allocator_driver_exit(); - dprc_driver_exit(); - platform_driver_unregister(&fsl_mc_bus_driver); - bus_unregister(&fsl_mc_bus_type); - kmem_cache_destroy(mc_dev_cache); - pr_info("MC bus unregistered\n"); -} - -module_exit(fsl_mc_bus_driver_exit); - -MODULE_AUTHOR("Freescale Semiconductor Inc."); -MODULE_DESCRIPTION("Freescale Management Complex (MC) bus driver"); -MODULE_LICENSE("GPL"); -- cgit v1.2.3-59-g8ed1b From c37ebf8c3da2b0ae6a2b7942c0d61d04f541ab2d Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:04 -0500 Subject: staging: fsl-mc: rename mc-private.h to mc-bus.h The definitions in mc-private.h are not strictly speaking 'private', they are bus-related definitions expected to be referenced by bus driver components as well as system components (gic, smmu, vfio). Rename mc-private.h to mc-bus.h to more accurately reflect expected use. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-driver.c | 2 +- .../staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +- drivers/staging/fsl-mc/bus/mc-allocator.c | 2 +- drivers/staging/fsl-mc/bus/mc-bus.c | 2 +- drivers/staging/fsl-mc/bus/mc-msi.c | 2 +- drivers/staging/fsl-mc/include/mc-bus.h | 158 +++++++++++++++++++++ drivers/staging/fsl-mc/include/mc-private.h | 158 --------------------- 7 files changed, 163 insertions(+), 163 deletions(-) create mode 100644 drivers/staging/fsl-mc/include/mc-bus.h delete mode 100644 drivers/staging/fsl-mc/include/mc-private.h (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 0523ba8a1965..83e72b3ed4c1 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -9,7 +9,7 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-private.h" +#include "../include/mc-bus.h" #include "../include/mc-sys.h" #include #include diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c index d0c20d669309..aac437963446 100644 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c @@ -9,7 +9,7 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-private.h" +#include "../include/mc-bus.h" #include #include #include diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c index 0f50a07fe10c..3ebaecbc1ec0 100644 --- a/drivers/staging/fsl-mc/bus/mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/mc-allocator.c @@ -8,7 +8,7 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-private.h" +#include "../include/mc-bus.h" #include "../include/mc-sys.h" #include #include "../include/dpbp-cmd.h" diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c index fe20c5d6994c..975d30b8775e 100644 --- a/drivers/staging/fsl-mc/bus/mc-bus.c +++ b/drivers/staging/fsl-mc/bus/mc-bus.c @@ -9,7 +9,7 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-private.h" +#include "../include/mc-bus.h" #include #include #include diff --git a/drivers/staging/fsl-mc/bus/mc-msi.c b/drivers/staging/fsl-mc/bus/mc-msi.c index c7be156ae5e0..6e39a983f8e3 100644 --- a/drivers/staging/fsl-mc/bus/mc-msi.c +++ b/drivers/staging/fsl-mc/bus/mc-msi.c @@ -9,7 +9,7 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-private.h" +#include "../include/mc-bus.h" #include #include #include diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h new file mode 100644 index 000000000000..7f847e6734f3 --- /dev/null +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -0,0 +1,158 @@ +/* + * Freescale Management Complex (MC) bus declarations + * + * Copyright (C) 2014 Freescale Semiconductor, Inc. + * Author: German Rivera + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#ifndef _FSL_MC_MCBUS_H_ +#define _FSL_MC_MCBUS_H_ + +#include "../include/mc.h" +#include +#include + +#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" + +#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \ + (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ + (_mc_dev)->obj_desc.id == (_obj_desc)->id) + +#define FSL_MC_IS_ALLOCATABLE(_obj_type) \ + (strcmp(_obj_type, "dpbp") == 0 || \ + strcmp(_obj_type, "dpmcp") == 0 || \ + strcmp(_obj_type, "dpcon") == 0) + +struct irq_domain; +struct msi_domain_info; + +/** + * Maximum number of total IRQs that can be pre-allocated for an MC bus' + * IRQ pool + */ +#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 + +struct device_node; +struct irq_domain; +struct msi_domain_info; + +/** + * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device + * @root_mc_bus_dev: MC object device representing the root DPRC + * @num_translation_ranges: number of entries in addr_translation_ranges + * @translation_ranges: array of bus to system address translation ranges + */ +struct fsl_mc { + struct fsl_mc_device *root_mc_bus_dev; + u8 num_translation_ranges; + struct fsl_mc_addr_translation_range *translation_ranges; +}; + +/** + * struct fsl_mc_addr_translation_range - bus to system address translation + * range + * @mc_region_type: Type of MC region for the range being translated + * @start_mc_offset: Start MC offset of the range being translated + * @end_mc_offset: MC offset of the first byte after the range (last MC + * offset of the range is end_mc_offset - 1) + * @start_phys_addr: system physical address corresponding to start_mc_addr + */ +struct fsl_mc_addr_translation_range { + enum dprc_region_type mc_region_type; + u64 start_mc_offset; + u64 end_mc_offset; + phys_addr_t start_phys_addr; +}; + +/** + * struct fsl_mc_resource_pool - Pool of MC resources of a given + * type + * @type: type of resources in the pool + * @max_count: maximum number of resources in the pool + * @free_count: number of free resources in the pool + * @mutex: mutex to serialize access to the pool's free list + * @free_list: anchor node of list of free resources in the pool + * @mc_bus: pointer to the MC bus that owns this resource pool + */ +struct fsl_mc_resource_pool { + enum fsl_mc_pool_type type; + int16_t max_count; + int16_t free_count; + struct mutex mutex; /* serializes access to free_list */ + struct list_head free_list; + struct fsl_mc_bus *mc_bus; +}; + +/** + * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC + * @mc_dev: fsl-mc device for the bus device itself. + * @resource_pools: array of resource pools (one pool per resource type) + * for this MC bus. These resources represent allocatable entities + * from the physical DPRC. + * @irq_resources: Pointer to array of IRQ objects for the IRQ pool + * @scan_mutex: Serializes bus scanning + * @dprc_attr: DPRC attributes + */ +struct fsl_mc_bus { + struct fsl_mc_device mc_dev; + struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES]; + struct fsl_mc_device_irq *irq_resources; + struct mutex scan_mutex; /* serializes bus scanning */ + struct dprc_attributes dprc_attr; +}; + +#define to_fsl_mc_bus(_mc_dev) \ + container_of(_mc_dev, struct fsl_mc_bus, mc_dev) + +int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, + struct fsl_mc_io *mc_io, + struct device *parent_dev, + struct fsl_mc_device **new_mc_dev); + +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); + +int dprc_scan_container(struct fsl_mc_device *mc_bus_dev); + +int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, + unsigned int *total_irq_count); + +int __init dprc_driver_init(void); + +void dprc_driver_exit(void); + +int __init fsl_mc_allocator_driver_init(void); + +void fsl_mc_allocator_driver_exit(void); + +int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, + enum fsl_mc_pool_type pool_type, + struct fsl_mc_resource + **new_resource); + +void fsl_mc_resource_free(struct fsl_mc_resource *resource); + +struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, + struct msi_domain_info *info, + struct irq_domain *parent); + +int fsl_mc_find_msi_domain(struct device *mc_platform_dev, + struct irq_domain **mc_msi_domain); + +int fsl_mc_msi_domain_alloc_irqs(struct device *dev, + unsigned int irq_count); + +void fsl_mc_msi_domain_free_irqs(struct device *dev); + +int __init its_fsl_mc_msi_init(void); + +void its_fsl_mc_msi_cleanup(void); + +int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, + unsigned int irq_count); + +void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); + +#endif /* _FSL_MC_MCBUS_H_ */ diff --git a/drivers/staging/fsl-mc/include/mc-private.h b/drivers/staging/fsl-mc/include/mc-private.h deleted file mode 100644 index cab1ae90f09e..000000000000 --- a/drivers/staging/fsl-mc/include/mc-private.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Freescale Management Complex (MC) bus private declarations - * - * Copyright (C) 2014 Freescale Semiconductor, Inc. - * Author: German Rivera - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ -#ifndef _FSL_MC_PRIVATE_H_ -#define _FSL_MC_PRIVATE_H_ - -#include "../include/mc.h" -#include -#include - -#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" - -#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \ - (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ - (_mc_dev)->obj_desc.id == (_obj_desc)->id) - -#define FSL_MC_IS_ALLOCATABLE(_obj_type) \ - (strcmp(_obj_type, "dpbp") == 0 || \ - strcmp(_obj_type, "dpmcp") == 0 || \ - strcmp(_obj_type, "dpcon") == 0) - -struct irq_domain; -struct msi_domain_info; - -/** - * Maximum number of total IRQs that can be pre-allocated for an MC bus' - * IRQ pool - */ -#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 - -struct device_node; -struct irq_domain; -struct msi_domain_info; - -/** - * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device - * @root_mc_bus_dev: MC object device representing the root DPRC - * @num_translation_ranges: number of entries in addr_translation_ranges - * @translation_ranges: array of bus to system address translation ranges - */ -struct fsl_mc { - struct fsl_mc_device *root_mc_bus_dev; - u8 num_translation_ranges; - struct fsl_mc_addr_translation_range *translation_ranges; -}; - -/** - * struct fsl_mc_addr_translation_range - bus to system address translation - * range - * @mc_region_type: Type of MC region for the range being translated - * @start_mc_offset: Start MC offset of the range being translated - * @end_mc_offset: MC offset of the first byte after the range (last MC - * offset of the range is end_mc_offset - 1) - * @start_phys_addr: system physical address corresponding to start_mc_addr - */ -struct fsl_mc_addr_translation_range { - enum dprc_region_type mc_region_type; - u64 start_mc_offset; - u64 end_mc_offset; - phys_addr_t start_phys_addr; -}; - -/** - * struct fsl_mc_resource_pool - Pool of MC resources of a given - * type - * @type: type of resources in the pool - * @max_count: maximum number of resources in the pool - * @free_count: number of free resources in the pool - * @mutex: mutex to serialize access to the pool's free list - * @free_list: anchor node of list of free resources in the pool - * @mc_bus: pointer to the MC bus that owns this resource pool - */ -struct fsl_mc_resource_pool { - enum fsl_mc_pool_type type; - int16_t max_count; - int16_t free_count; - struct mutex mutex; /* serializes access to free_list */ - struct list_head free_list; - struct fsl_mc_bus *mc_bus; -}; - -/** - * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC - * @mc_dev: fsl-mc device for the bus device itself. - * @resource_pools: array of resource pools (one pool per resource type) - * for this MC bus. These resources represent allocatable entities - * from the physical DPRC. - * @irq_resources: Pointer to array of IRQ objects for the IRQ pool - * @scan_mutex: Serializes bus scanning - * @dprc_attr: DPRC attributes - */ -struct fsl_mc_bus { - struct fsl_mc_device mc_dev; - struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES]; - struct fsl_mc_device_irq *irq_resources; - struct mutex scan_mutex; /* serializes bus scanning */ - struct dprc_attributes dprc_attr; -}; - -#define to_fsl_mc_bus(_mc_dev) \ - container_of(_mc_dev, struct fsl_mc_bus, mc_dev) - -int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, - struct fsl_mc_io *mc_io, - struct device *parent_dev, - struct fsl_mc_device **new_mc_dev); - -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); - -int dprc_scan_container(struct fsl_mc_device *mc_bus_dev); - -int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, - unsigned int *total_irq_count); - -int __init dprc_driver_init(void); - -void dprc_driver_exit(void); - -int __init fsl_mc_allocator_driver_init(void); - -void fsl_mc_allocator_driver_exit(void); - -int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, - enum fsl_mc_pool_type pool_type, - struct fsl_mc_resource - **new_resource); - -void fsl_mc_resource_free(struct fsl_mc_resource *resource); - -struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, - struct msi_domain_info *info, - struct irq_domain *parent); - -int fsl_mc_find_msi_domain(struct device *mc_platform_dev, - struct irq_domain **mc_msi_domain); - -int fsl_mc_msi_domain_alloc_irqs(struct device *dev, - unsigned int irq_count); - -void fsl_mc_msi_domain_free_irqs(struct device *dev); - -int __init its_fsl_mc_msi_init(void); - -void its_fsl_mc_msi_cleanup(void); - -int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, - unsigned int irq_count); - -void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); - -#endif /* _FSL_MC_PRIVATE_H_ */ -- cgit v1.2.3-59-g8ed1b From 46d669daa36b85fbe0ca3d5c11fbf5a97b784c84 Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:12 -0500 Subject: staging: fsl-mc: improve naming of source files The mc- prefix on the source files names of some internal components of the fsl-mc bus driver makes things less clear that they could be. The string "mc" generally refers to hardware-- the physical DPAA 'management complex'. Names like "mc-allocator.c" have nothing to with the "MC" hardware per se. Improve clarity by using the prefix string "fsl-mc" instead which is what we are calling this bus. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/Makefile | 6 +- drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 755 ++++++++++++++++++++++ drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 890 ++++++++++++++++++++++++++ drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 287 +++++++++ drivers/staging/fsl-mc/bus/mc-allocator.c | 755 ---------------------- drivers/staging/fsl-mc/bus/mc-bus.c | 890 -------------------------- drivers/staging/fsl-mc/bus/mc-msi.c | 287 --------- 7 files changed, 1935 insertions(+), 1935 deletions(-) create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-allocator.c create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-bus.c create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-msi.c delete mode 100644 drivers/staging/fsl-mc/bus/mc-allocator.c delete mode 100644 drivers/staging/fsl-mc/bus/mc-bus.c delete mode 100644 drivers/staging/fsl-mc/bus/mc-msi.c (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/Makefile b/drivers/staging/fsl-mc/bus/Makefile index e7315170b7a3..5fb4c14b084d 100644 --- a/drivers/staging/fsl-mc/bus/Makefile +++ b/drivers/staging/fsl-mc/bus/Makefile @@ -7,13 +7,13 @@ # obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o -mc-bus-driver-objs := mc-bus.o \ +mc-bus-driver-objs := fsl-mc-bus.o \ mc-sys.o \ dprc.o \ dpmng.o \ dprc-driver.o \ - mc-allocator.o \ - mc-msi.o \ + fsl-mc-allocator.o \ + fsl-mc-msi.o \ irq-gic-v3-its-fsl-mc-msi.o \ dpmcp.o \ dpbp.o diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c new file mode 100644 index 000000000000..3ebaecbc1ec0 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -0,0 +1,755 @@ +/* + * Freescale MC object device allocator driver + * + * Copyright (C) 2013 Freescale Semiconductor, Inc. + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include "../include/mc-bus.h" +#include "../include/mc-sys.h" +#include +#include "../include/dpbp-cmd.h" +#include "../include/dpcon-cmd.h" +#include "dpmcp-cmd.h" +#include "dpmcp.h" +#include + +/** + * fsl_mc_resource_pool_add_device - add allocatable device to a resource + * pool of a given MC bus + * + * @mc_bus: pointer to the MC bus + * @pool_type: MC bus pool type + * @mc_dev: Pointer to allocatable MC object device + * + * It adds an allocatable MC object device to a container's resource pool of + * the given resource type + */ +static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus + *mc_bus, + enum fsl_mc_pool_type + pool_type, + struct fsl_mc_device + *mc_dev) +{ + struct fsl_mc_resource_pool *res_pool; + struct fsl_mc_resource *resource; + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + int error = -EINVAL; + + if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) + goto out; + if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) + goto out; + if (WARN_ON(mc_dev->resource)) + goto out; + + res_pool = &mc_bus->resource_pools[pool_type]; + if (WARN_ON(res_pool->type != pool_type)) + goto out; + if (WARN_ON(res_pool->mc_bus != mc_bus)) + goto out; + + mutex_lock(&res_pool->mutex); + + if (WARN_ON(res_pool->max_count < 0)) + goto out_unlock; + if (WARN_ON(res_pool->free_count < 0 || + res_pool->free_count > res_pool->max_count)) + goto out_unlock; + + resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource), + GFP_KERNEL); + if (!resource) { + error = -ENOMEM; + dev_err(&mc_bus_dev->dev, + "Failed to allocate memory for fsl_mc_resource\n"); + goto out_unlock; + } + + resource->type = pool_type; + resource->id = mc_dev->obj_desc.id; + resource->data = mc_dev; + resource->parent_pool = res_pool; + INIT_LIST_HEAD(&resource->node); + list_add_tail(&resource->node, &res_pool->free_list); + mc_dev->resource = resource; + res_pool->free_count++; + res_pool->max_count++; + error = 0; +out_unlock: + mutex_unlock(&res_pool->mutex); +out: + return error; +} + +/** + * fsl_mc_resource_pool_remove_device - remove an allocatable device from a + * resource pool + * + * @mc_dev: Pointer to allocatable MC object device + * + * It permanently removes an allocatable MC object device from the resource + * pool, the device is currently in, as long as it is in the pool's free list. + */ +static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device + *mc_dev) +{ + struct fsl_mc_device *mc_bus_dev; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_resource_pool *res_pool; + struct fsl_mc_resource *resource; + int error = -EINVAL; + + if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) + goto out; + + resource = mc_dev->resource; + if (WARN_ON(!resource || resource->data != mc_dev)) + goto out; + + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); + mc_bus = to_fsl_mc_bus(mc_bus_dev); + res_pool = resource->parent_pool; + if (WARN_ON(res_pool != &mc_bus->resource_pools[resource->type])) + goto out; + + mutex_lock(&res_pool->mutex); + + if (WARN_ON(res_pool->max_count <= 0)) + goto out_unlock; + if (WARN_ON(res_pool->free_count <= 0 || + res_pool->free_count > res_pool->max_count)) + goto out_unlock; + + /* + * If the device is currently allocated, its resource is not + * in the free list and thus, the device cannot be removed. + */ + if (list_empty(&resource->node)) { + error = -EBUSY; + dev_err(&mc_bus_dev->dev, + "Device %s cannot be removed from resource pool\n", + dev_name(&mc_dev->dev)); + goto out_unlock; + } + + list_del(&resource->node); + INIT_LIST_HEAD(&resource->node); + res_pool->free_count--; + res_pool->max_count--; + + devm_kfree(&mc_bus_dev->dev, resource); + mc_dev->resource = NULL; + error = 0; +out_unlock: + mutex_unlock(&res_pool->mutex); +out: + return error; +} + +static const char *const fsl_mc_pool_type_strings[] = { + [FSL_MC_POOL_DPMCP] = "dpmcp", + [FSL_MC_POOL_DPBP] = "dpbp", + [FSL_MC_POOL_DPCON] = "dpcon", + [FSL_MC_POOL_IRQ] = "irq", +}; + +static int __must_check object_type_to_pool_type(const char *object_type, + enum fsl_mc_pool_type + *pool_type) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) { + if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) { + *pool_type = i; + return 0; + } + } + + return -EINVAL; +} + +int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, + enum fsl_mc_pool_type pool_type, + struct fsl_mc_resource **new_resource) +{ + struct fsl_mc_resource_pool *res_pool; + struct fsl_mc_resource *resource; + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + int error = -EINVAL; + + BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) != + FSL_MC_NUM_POOL_TYPES); + + *new_resource = NULL; + if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) + goto out; + + res_pool = &mc_bus->resource_pools[pool_type]; + if (WARN_ON(res_pool->mc_bus != mc_bus)) + goto out; + + mutex_lock(&res_pool->mutex); + resource = list_first_entry_or_null(&res_pool->free_list, + struct fsl_mc_resource, node); + + if (!resource) { + WARN_ON(res_pool->free_count != 0); + error = -ENXIO; + dev_err(&mc_bus_dev->dev, + "No more resources of type %s left\n", + fsl_mc_pool_type_strings[pool_type]); + goto out_unlock; + } + + if (WARN_ON(resource->type != pool_type)) + goto out_unlock; + if (WARN_ON(resource->parent_pool != res_pool)) + goto out_unlock; + if (WARN_ON(res_pool->free_count <= 0 || + res_pool->free_count > res_pool->max_count)) + goto out_unlock; + + list_del(&resource->node); + INIT_LIST_HEAD(&resource->node); + + res_pool->free_count--; + error = 0; +out_unlock: + mutex_unlock(&res_pool->mutex); + *new_resource = resource; +out: + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate); + +void fsl_mc_resource_free(struct fsl_mc_resource *resource) +{ + struct fsl_mc_resource_pool *res_pool; + + res_pool = resource->parent_pool; + if (WARN_ON(resource->type != res_pool->type)) + return; + + mutex_lock(&res_pool->mutex); + if (WARN_ON(res_pool->free_count < 0 || + res_pool->free_count >= res_pool->max_count)) + goto out_unlock; + + if (WARN_ON(!list_empty(&resource->node))) + goto out_unlock; + + list_add_tail(&resource->node, &res_pool->free_list); + res_pool->free_count++; +out_unlock: + mutex_unlock(&res_pool->mutex); +} +EXPORT_SYMBOL_GPL(fsl_mc_resource_free); + +/** + * fsl_mc_portal_allocate - Allocates an MC portal + * + * @mc_dev: MC device for which the MC portal is to be allocated + * @mc_io_flags: Flags for the fsl_mc_io object that wraps the allocated + * MC portal. + * @new_mc_io: Pointer to area where the pointer to the fsl_mc_io object + * that wraps the allocated MC portal is to be returned + * + * This function allocates an MC portal from the device's parent DPRC, + * from the corresponding MC bus' pool of MC portals and wraps + * it in a new fsl_mc_io object. If 'mc_dev' is a DPRC itself, the + * portal is allocated from its own MC bus. + */ +int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, + u16 mc_io_flags, + struct fsl_mc_io **new_mc_io) +{ + struct fsl_mc_device *mc_bus_dev; + struct fsl_mc_bus *mc_bus; + phys_addr_t mc_portal_phys_addr; + size_t mc_portal_size; + struct fsl_mc_device *dpmcp_dev; + int error = -EINVAL; + struct fsl_mc_resource *resource = NULL; + struct fsl_mc_io *mc_io = NULL; + + if (mc_dev->flags & FSL_MC_IS_DPRC) { + mc_bus_dev = mc_dev; + } else { + if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) + return error; + + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); + } + + mc_bus = to_fsl_mc_bus(mc_bus_dev); + *new_mc_io = NULL; + error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_DPMCP, &resource); + if (error < 0) + return error; + + error = -EINVAL; + dpmcp_dev = resource->data; + if (WARN_ON(!dpmcp_dev)) + goto error_cleanup_resource; + + if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR || + (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR && + dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) { + dev_err(&dpmcp_dev->dev, + "ERROR: Version %d.%d of DPMCP not supported.\n", + dpmcp_dev->obj_desc.ver_major, + dpmcp_dev->obj_desc.ver_minor); + error = -ENOTSUPP; + goto error_cleanup_resource; + } + + if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0)) + goto error_cleanup_resource; + + mc_portal_phys_addr = dpmcp_dev->regions[0].start; + mc_portal_size = dpmcp_dev->regions[0].end - + dpmcp_dev->regions[0].start + 1; + + if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size)) + goto error_cleanup_resource; + + error = fsl_create_mc_io(&mc_bus_dev->dev, + mc_portal_phys_addr, + mc_portal_size, dpmcp_dev, + mc_io_flags, &mc_io); + if (error < 0) + goto error_cleanup_resource; + + *new_mc_io = mc_io; + return 0; + +error_cleanup_resource: + fsl_mc_resource_free(resource); + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate); + +/** + * fsl_mc_portal_free - Returns an MC portal to the pool of free MC portals + * of a given MC bus + * + * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free + */ +void fsl_mc_portal_free(struct fsl_mc_io *mc_io) +{ + struct fsl_mc_device *dpmcp_dev; + struct fsl_mc_resource *resource; + + /* + * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed + * to have a DPMCP object associated with. + */ + dpmcp_dev = mc_io->dpmcp_dev; + if (WARN_ON(!dpmcp_dev)) + return; + + resource = dpmcp_dev->resource; + if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP)) + return; + + if (WARN_ON(resource->data != dpmcp_dev)) + return; + + fsl_destroy_mc_io(mc_io); + fsl_mc_resource_free(resource); +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_free); + +/** + * fsl_mc_portal_reset - Resets the dpmcp object for a given fsl_mc_io object + * + * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free + */ +int fsl_mc_portal_reset(struct fsl_mc_io *mc_io) +{ + int error; + struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; + + if (WARN_ON(!dpmcp_dev)) + return -EINVAL; + + error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle); + if (error < 0) { + dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error); + return error; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_reset); + +/** + * fsl_mc_object_allocate - Allocates a MC object device of the given + * pool type from a given MC bus + * + * @mc_dev: MC device for which the MC object device is to be allocated + * @pool_type: MC bus resource pool type + * @new_mc_dev: Pointer to area where the pointer to the allocated + * MC object device is to be returned + * + * This function allocates a MC object device from the device's parent DPRC, + * from the corresponding MC bus' pool of allocatable MC object devices of + * the given resource type. mc_dev cannot be a DPRC itself. + * + * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC + * portals are allocated using fsl_mc_portal_allocate(), instead of + * this function. + */ +int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, + enum fsl_mc_pool_type pool_type, + struct fsl_mc_device **new_mc_adev) +{ + struct fsl_mc_device *mc_bus_dev; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_device *mc_adev; + int error = -EINVAL; + struct fsl_mc_resource *resource = NULL; + + *new_mc_adev = NULL; + if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC)) + goto error; + + if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) + goto error; + + if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP)) + goto error; + + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); + mc_bus = to_fsl_mc_bus(mc_bus_dev); + error = fsl_mc_resource_allocate(mc_bus, pool_type, &resource); + if (error < 0) + goto error; + + mc_adev = resource->data; + if (WARN_ON(!mc_adev)) + goto error; + + *new_mc_adev = mc_adev; + return 0; +error: + if (resource) + fsl_mc_resource_free(resource); + + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_object_allocate); + +/** + * fsl_mc_object_free - Returns an allocatable MC object device to the + * corresponding resource pool of a given MC bus. + * + * @mc_adev: Pointer to the MC object device + */ +void fsl_mc_object_free(struct fsl_mc_device *mc_adev) +{ + struct fsl_mc_resource *resource; + + resource = mc_adev->resource; + if (WARN_ON(resource->type == FSL_MC_POOL_DPMCP)) + return; + if (WARN_ON(resource->data != mc_adev)) + return; + + fsl_mc_resource_free(resource); +} +EXPORT_SYMBOL_GPL(fsl_mc_object_free); + +/* + * Initialize the interrupt pool associated with a MC bus. + * It allocates a block of IRQs from the GIC-ITS + */ +int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, + unsigned int irq_count) +{ + unsigned int i; + struct msi_desc *msi_desc; + struct fsl_mc_device_irq *irq_resources; + struct fsl_mc_device_irq *mc_dev_irq; + int error; + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + + if (WARN_ON(irq_count == 0 || + irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS)) + return -EINVAL; + + error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count); + if (error < 0) + return error; + + irq_resources = devm_kzalloc(&mc_bus_dev->dev, + sizeof(*irq_resources) * irq_count, + GFP_KERNEL); + if (!irq_resources) { + error = -ENOMEM; + goto cleanup_msi_irqs; + } + + for (i = 0; i < irq_count; i++) { + mc_dev_irq = &irq_resources[i]; + + /* + * NOTE: This mc_dev_irq's MSI addr/value pair will be set + * by the fsl_mc_msi_write_msg() callback + */ + mc_dev_irq->resource.type = res_pool->type; + mc_dev_irq->resource.data = mc_dev_irq; + mc_dev_irq->resource.parent_pool = res_pool; + INIT_LIST_HEAD(&mc_dev_irq->resource.node); + list_add_tail(&mc_dev_irq->resource.node, &res_pool->free_list); + } + + for_each_msi_entry(msi_desc, &mc_bus_dev->dev) { + mc_dev_irq = &irq_resources[msi_desc->fsl_mc.msi_index]; + mc_dev_irq->msi_desc = msi_desc; + mc_dev_irq->resource.id = msi_desc->irq; + } + + res_pool->max_count = irq_count; + res_pool->free_count = irq_count; + mc_bus->irq_resources = irq_resources; + return 0; + +cleanup_msi_irqs: + fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool); + +/** + * Teardown the interrupt pool associated with an MC bus. + * It frees the IRQs that were allocated to the pool, back to the GIC-ITS. + */ +void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus) +{ + struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + + if (WARN_ON(!mc_bus->irq_resources)) + return; + + if (WARN_ON(res_pool->max_count == 0)) + return; + + if (WARN_ON(res_pool->free_count != res_pool->max_count)) + return; + + INIT_LIST_HEAD(&res_pool->free_list); + res_pool->max_count = 0; + res_pool->free_count = 0; + mc_bus->irq_resources = NULL; + fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); +} +EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool); + +/** + * It allocates the IRQs required by a given MC object device. The + * IRQs are allocated from the interrupt pool associated with the + * MC bus that contains the device, if the device is not a DPRC device. + * Otherwise, the IRQs are allocated from the interrupt pool associated + * with the MC bus that represents the DPRC device itself. + */ +int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev) +{ + int i; + int irq_count; + int res_allocated_count = 0; + int error = -EINVAL; + struct fsl_mc_device_irq **irqs = NULL; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_resource_pool *res_pool; + + if (WARN_ON(mc_dev->irqs)) + return -EINVAL; + + irq_count = mc_dev->obj_desc.irq_count; + if (WARN_ON(irq_count == 0)) + return -EINVAL; + + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) + mc_bus = to_fsl_mc_bus(mc_dev); + else + mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); + + if (WARN_ON(!mc_bus->irq_resources)) + return -EINVAL; + + res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; + if (res_pool->free_count < irq_count) { + dev_err(&mc_dev->dev, + "Not able to allocate %u irqs for device\n", irq_count); + return -ENOSPC; + } + + irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]), + GFP_KERNEL); + if (!irqs) + return -ENOMEM; + + for (i = 0; i < irq_count; i++) { + struct fsl_mc_resource *resource; + + error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_IRQ, + &resource); + if (error < 0) + goto error_resource_alloc; + + irqs[i] = to_fsl_mc_irq(resource); + res_allocated_count++; + + WARN_ON(irqs[i]->mc_dev); + irqs[i]->mc_dev = mc_dev; + irqs[i]->dev_irq_index = i; + } + + mc_dev->irqs = irqs; + return 0; + +error_resource_alloc: + for (i = 0; i < res_allocated_count; i++) { + irqs[i]->mc_dev = NULL; + fsl_mc_resource_free(&irqs[i]->resource); + } + + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs); + +/* + * It frees the IRQs that were allocated for a MC object device, by + * returning them to the corresponding interrupt pool. + */ +void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev) +{ + int i; + int irq_count; + struct fsl_mc_bus *mc_bus; + struct fsl_mc_device_irq **irqs = mc_dev->irqs; + + if (WARN_ON(!irqs)) + return; + + irq_count = mc_dev->obj_desc.irq_count; + + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) + mc_bus = to_fsl_mc_bus(mc_dev); + else + mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); + + if (WARN_ON(!mc_bus->irq_resources)) + return; + + for (i = 0; i < irq_count; i++) { + WARN_ON(!irqs[i]->mc_dev); + irqs[i]->mc_dev = NULL; + fsl_mc_resource_free(&irqs[i]->resource); + } + + mc_dev->irqs = NULL; +} +EXPORT_SYMBOL_GPL(fsl_mc_free_irqs); + +/** + * fsl_mc_allocator_probe - callback invoked when an allocatable device is + * being added to the system + */ +static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) +{ + enum fsl_mc_pool_type pool_type; + struct fsl_mc_device *mc_bus_dev; + struct fsl_mc_bus *mc_bus; + int error; + + if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) + return -EINVAL; + + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); + if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev))) + return -EINVAL; + + mc_bus = to_fsl_mc_bus(mc_bus_dev); + error = object_type_to_pool_type(mc_dev->obj_desc.type, &pool_type); + if (error < 0) + return error; + + error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev); + if (error < 0) + return error; + + dev_dbg(&mc_dev->dev, + "Allocatable MC object device bound to fsl_mc_allocator driver"); + return 0; +} + +/** + * fsl_mc_allocator_remove - callback invoked when an allocatable device is + * being removed from the system + */ +static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev) +{ + int error; + + if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) + return -EINVAL; + + if (mc_dev->resource) { + error = fsl_mc_resource_pool_remove_device(mc_dev); + if (error < 0) + return error; + } + + dev_dbg(&mc_dev->dev, + "Allocatable MC object device unbound from fsl_mc_allocator driver"); + return 0; +} + +static const struct fsl_mc_device_id match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpbp", + }, + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpmcp", + }, + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpcon", + }, + {.vendor = 0x0}, +}; + +static struct fsl_mc_driver fsl_mc_allocator_driver = { + .driver = { + .name = "fsl_mc_allocator", + .owner = THIS_MODULE, + .pm = NULL, + }, + .match_id_table = match_id_table, + .probe = fsl_mc_allocator_probe, + .remove = fsl_mc_allocator_remove, +}; + +int __init fsl_mc_allocator_driver_init(void) +{ + return fsl_mc_driver_register(&fsl_mc_allocator_driver); +} + +void fsl_mc_allocator_driver_exit(void) +{ + fsl_mc_driver_unregister(&fsl_mc_allocator_driver); +} diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c new file mode 100644 index 000000000000..975d30b8775e --- /dev/null +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -0,0 +1,890 @@ +/* + * Freescale Management Complex (MC) bus driver + * + * Copyright (C) 2014 Freescale Semiconductor, Inc. + * Author: German Rivera + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include "../include/mc-bus.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "../include/dpmng.h" +#include "../include/mc-sys.h" +#include "dprc-cmd.h" + +static struct kmem_cache *mc_dev_cache; + +/** + * fsl_mc_bus_match - device to driver matching callback + * @dev: the MC object device structure to match against + * @drv: the device driver to search for matching MC object device id + * structures + * + * Returns 1 on success, 0 otherwise. + */ +static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) +{ + const struct fsl_mc_device_id *id; + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); + bool found = false; + + if (WARN_ON(!fsl_mc_bus_exists())) + goto out; + + if (!mc_drv->match_id_table) + goto out; + + /* + * If the object is not 'plugged' don't match. + * Only exception is the root DPRC, which is a special case. + */ + if ((mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED) == 0 && + !fsl_mc_is_root_dprc(&mc_dev->dev)) + goto out; + + /* + * Traverse the match_id table of the given driver, trying to find + * a matching for the given MC object device. + */ + for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) { + if (id->vendor == mc_dev->obj_desc.vendor && + strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) { + found = true; + + break; + } + } + +out: + dev_dbg(dev, "%smatched\n", found ? "" : "not "); + return found; +} + +/** + * fsl_mc_bus_uevent - callback invoked when a device is added + */ +static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + + if (add_uevent_var(env, "MODALIAS=fsl-mc:v%08Xd%s", + mc_dev->obj_desc.vendor, + mc_dev->obj_desc.type)) + return -ENOMEM; + + return 0; +} + +static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + + return sprintf(buf, "fsl-mc:v%08Xd%s\n", mc_dev->obj_desc.vendor, + mc_dev->obj_desc.type); +} +static DEVICE_ATTR_RO(modalias); + +static struct attribute *fsl_mc_dev_attrs[] = { + &dev_attr_modalias.attr, + NULL, +}; + +static const struct attribute_group fsl_mc_dev_group = { + .attrs = fsl_mc_dev_attrs, +}; + +static const struct attribute_group *fsl_mc_dev_groups[] = { + &fsl_mc_dev_group, + NULL, +}; + +struct bus_type fsl_mc_bus_type = { + .name = "fsl-mc", + .match = fsl_mc_bus_match, + .uevent = fsl_mc_bus_uevent, + .dev_groups = fsl_mc_dev_groups, +}; +EXPORT_SYMBOL_GPL(fsl_mc_bus_type); + +static atomic_t root_dprc_count = ATOMIC_INIT(0); + +static int fsl_mc_driver_probe(struct device *dev) +{ + struct fsl_mc_driver *mc_drv; + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + int error; + + if (WARN_ON(!dev->driver)) + return -EINVAL; + + mc_drv = to_fsl_mc_driver(dev->driver); + if (WARN_ON(!mc_drv->probe)) + return -EINVAL; + + error = mc_drv->probe(mc_dev); + if (error < 0) { + dev_err(dev, "MC object device probe callback failed: %d\n", + error); + return error; + } + + return 0; +} + +static int fsl_mc_driver_remove(struct device *dev) +{ + struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + int error; + + if (WARN_ON(!dev->driver)) + return -EINVAL; + + error = mc_drv->remove(mc_dev); + if (error < 0) { + dev_err(dev, + "MC object device remove callback failed: %d\n", + error); + return error; + } + + return 0; +} + +static void fsl_mc_driver_shutdown(struct device *dev) +{ + struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + + mc_drv->shutdown(mc_dev); +} + +/** + * __fsl_mc_driver_register - registers a child device driver with the + * MC bus + * + * This function is implicitly invoked from the registration function of + * fsl_mc device drivers, which is generated by the + * module_fsl_mc_driver() macro. + */ +int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver, + struct module *owner) +{ + int error; + + mc_driver->driver.owner = owner; + mc_driver->driver.bus = &fsl_mc_bus_type; + + if (mc_driver->probe) + mc_driver->driver.probe = fsl_mc_driver_probe; + + if (mc_driver->remove) + mc_driver->driver.remove = fsl_mc_driver_remove; + + if (mc_driver->shutdown) + mc_driver->driver.shutdown = fsl_mc_driver_shutdown; + + error = driver_register(&mc_driver->driver); + if (error < 0) { + pr_err("driver_register() failed for %s: %d\n", + mc_driver->driver.name, error); + return error; + } + + pr_info("MC object device driver %s registered\n", + mc_driver->driver.name); + return 0; +} +EXPORT_SYMBOL_GPL(__fsl_mc_driver_register); + +/** + * fsl_mc_driver_unregister - unregisters a device driver from the + * MC bus + */ +void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver) +{ + driver_unregister(&mc_driver->driver); +} +EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); + +/** + * fsl_mc_bus_exists - check if a root dprc exists + */ +bool fsl_mc_bus_exists(void) +{ + return atomic_read(&root_dprc_count) > 0; +} +EXPORT_SYMBOL_GPL(fsl_mc_bus_exists); + +/** +* fsl_mc_get_root_dprc - function to traverse to the root dprc +*/ +static void fsl_mc_get_root_dprc(struct device *dev, + struct device **root_dprc_dev) +{ + if (WARN_ON(!dev)) { + *root_dprc_dev = NULL; + } else if (WARN_ON(!dev_is_fsl_mc(dev))) { + *root_dprc_dev = NULL; + } else { + *root_dprc_dev = dev; + while (dev_is_fsl_mc((*root_dprc_dev)->parent)) + *root_dprc_dev = (*root_dprc_dev)->parent; + } +} + +static int get_dprc_attr(struct fsl_mc_io *mc_io, + int container_id, struct dprc_attributes *attr) +{ + u16 dprc_handle; + int error; + + error = dprc_open(mc_io, 0, container_id, &dprc_handle); + if (error < 0) { + dev_err(mc_io->dev, "dprc_open() failed: %d\n", error); + return error; + } + + memset(attr, 0, sizeof(struct dprc_attributes)); + error = dprc_get_attributes(mc_io, 0, dprc_handle, attr); + if (error < 0) { + dev_err(mc_io->dev, "dprc_get_attributes() failed: %d\n", + error); + goto common_cleanup; + } + + error = 0; + +common_cleanup: + (void)dprc_close(mc_io, 0, dprc_handle); + return error; +} + +static int get_dprc_icid(struct fsl_mc_io *mc_io, + int container_id, u16 *icid) +{ + struct dprc_attributes attr; + int error; + + error = get_dprc_attr(mc_io, container_id, &attr); + if (error == 0) + *icid = attr.icid; + + return error; +} + +static int get_dprc_version(struct fsl_mc_io *mc_io, + int container_id, u16 *major, u16 *minor) +{ + struct dprc_attributes attr; + int error; + + error = get_dprc_attr(mc_io, container_id, &attr); + if (error == 0) { + *major = attr.version.major; + *minor = attr.version.minor; + } + + return error; +} + +static int translate_mc_addr(struct fsl_mc_device *mc_dev, + enum dprc_region_type mc_region_type, + u64 mc_offset, phys_addr_t *phys_addr) +{ + int i; + struct device *root_dprc_dev; + struct fsl_mc *mc; + + fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); + if (WARN_ON(!root_dprc_dev)) + return -EINVAL; + mc = dev_get_drvdata(root_dprc_dev->parent); + + if (mc->num_translation_ranges == 0) { + /* + * Do identity mapping: + */ + *phys_addr = mc_offset; + return 0; + } + + for (i = 0; i < mc->num_translation_ranges; i++) { + struct fsl_mc_addr_translation_range *range = + &mc->translation_ranges[i]; + + if (mc_region_type == range->mc_region_type && + mc_offset >= range->start_mc_offset && + mc_offset < range->end_mc_offset) { + *phys_addr = range->start_phys_addr + + (mc_offset - range->start_mc_offset); + return 0; + } + } + + return -EFAULT; +} + +static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, + struct fsl_mc_device *mc_bus_dev) +{ + int i; + int error; + struct resource *regions; + struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc; + struct device *parent_dev = mc_dev->dev.parent; + enum dprc_region_type mc_region_type; + + if (strcmp(obj_desc->type, "dprc") == 0 || + strcmp(obj_desc->type, "dpmcp") == 0) { + mc_region_type = DPRC_REGION_TYPE_MC_PORTAL; + } else if (strcmp(obj_desc->type, "dpio") == 0) { + mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL; + } else { + /* + * This function should not have been called for this MC object + * type, as this object type is not supposed to have MMIO + * regions + */ + WARN_ON(true); + return -EINVAL; + } + + regions = kmalloc_array(obj_desc->region_count, + sizeof(regions[0]), GFP_KERNEL); + if (!regions) + return -ENOMEM; + + for (i = 0; i < obj_desc->region_count; i++) { + struct dprc_region_desc region_desc; + + error = dprc_get_obj_region(mc_bus_dev->mc_io, + 0, + mc_bus_dev->mc_handle, + obj_desc->type, + obj_desc->id, i, ®ion_desc); + if (error < 0) { + dev_err(parent_dev, + "dprc_get_obj_region() failed: %d\n", error); + goto error_cleanup_regions; + } + + WARN_ON(region_desc.size == 0); + error = translate_mc_addr(mc_dev, mc_region_type, + region_desc.base_offset, + ®ions[i].start); + if (error < 0) { + dev_err(parent_dev, + "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", + region_desc.base_offset, + obj_desc->type, obj_desc->id, i); + goto error_cleanup_regions; + } + + regions[i].end = regions[i].start + region_desc.size - 1; + regions[i].name = "fsl-mc object MMIO region"; + regions[i].flags = IORESOURCE_IO; + if (region_desc.flags & DPRC_REGION_CACHEABLE) + regions[i].flags |= IORESOURCE_CACHEABLE; + } + + mc_dev->regions = regions; + return 0; + +error_cleanup_regions: + kfree(regions); + return error; +} + +/** + * fsl_mc_is_root_dprc - function to check if a given device is a root dprc + */ +bool fsl_mc_is_root_dprc(struct device *dev) +{ + struct device *root_dprc_dev; + + fsl_mc_get_root_dprc(dev, &root_dprc_dev); + if (!root_dprc_dev) + return false; + return dev == root_dprc_dev; +} + +/** + * Add a newly discovered MC object device to be visible in Linux + */ +int fsl_mc_device_add(struct dprc_obj_desc *obj_desc, + struct fsl_mc_io *mc_io, + struct device *parent_dev, + struct fsl_mc_device **new_mc_dev) +{ + int error; + struct fsl_mc_device *mc_dev = NULL; + struct fsl_mc_bus *mc_bus = NULL; + struct fsl_mc_device *parent_mc_dev; + + if (dev_is_fsl_mc(parent_dev)) + parent_mc_dev = to_fsl_mc_device(parent_dev); + else + parent_mc_dev = NULL; + + if (strcmp(obj_desc->type, "dprc") == 0) { + /* + * Allocate an MC bus device object: + */ + mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL); + if (!mc_bus) + return -ENOMEM; + + mc_dev = &mc_bus->mc_dev; + } else { + /* + * Allocate a regular fsl_mc_device object: + */ + mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL); + if (!mc_dev) + return -ENOMEM; + } + + mc_dev->obj_desc = *obj_desc; + mc_dev->mc_io = mc_io; + device_initialize(&mc_dev->dev); + mc_dev->dev.parent = parent_dev; + mc_dev->dev.bus = &fsl_mc_bus_type; + dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); + + if (strcmp(obj_desc->type, "dprc") == 0) { + struct fsl_mc_io *mc_io2; + + mc_dev->flags |= FSL_MC_IS_DPRC; + + /* + * To get the DPRC's ICID, we need to open the DPRC + * in get_dprc_icid(). For child DPRCs, we do so using the + * parent DPRC's MC portal instead of the child DPRC's MC + * portal, in case the child DPRC is already opened with + * its own portal (e.g., the DPRC used by AIOP). + * + * NOTE: There cannot be more than one active open for a + * given MC object, using the same MC portal. + */ + if (parent_mc_dev) { + /* + * device being added is a child DPRC device + */ + mc_io2 = parent_mc_dev->mc_io; + } else { + /* + * device being added is the root DPRC device + */ + if (WARN_ON(!mc_io)) { + error = -EINVAL; + goto error_cleanup_dev; + } + + mc_io2 = mc_io; + + atomic_inc(&root_dprc_count); + } + + error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); + if (error < 0) + goto error_cleanup_dev; + } else { + /* + * A non-DPRC MC object device has to be a child of another + * MC object (specifically a DPRC object) + */ + mc_dev->icid = parent_mc_dev->icid; + mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; + mc_dev->dev.dma_mask = &mc_dev->dma_mask; + dev_set_msi_domain(&mc_dev->dev, + dev_get_msi_domain(&parent_mc_dev->dev)); + } + + /* + * Get MMIO regions for the device from the MC: + * + * NOTE: the root DPRC is a special case as its MMIO region is + * obtained from the device tree + */ + if (parent_mc_dev && obj_desc->region_count != 0) { + error = fsl_mc_device_get_mmio_regions(mc_dev, + parent_mc_dev); + if (error < 0) + goto error_cleanup_dev; + } + + /* Objects are coherent, unless 'no shareability' flag set. */ + if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY)) + arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true); + + /* + * The device-specific probe callback will get invoked by device_add() + */ + error = device_add(&mc_dev->dev); + if (error < 0) { + dev_err(parent_dev, + "device_add() failed for device %s: %d\n", + dev_name(&mc_dev->dev), error); + goto error_cleanup_dev; + } + + (void)get_device(&mc_dev->dev); + dev_dbg(parent_dev, "Added MC object device %s\n", + dev_name(&mc_dev->dev)); + + *new_mc_dev = mc_dev; + return 0; + +error_cleanup_dev: + kfree(mc_dev->regions); + if (mc_bus) + devm_kfree(parent_dev, mc_bus); + else + kmem_cache_free(mc_dev_cache, mc_dev); + + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_device_add); + +/** + * fsl_mc_device_remove - Remove a MC object device from being visible to + * Linux + * + * @mc_dev: Pointer to a MC object device object + */ +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) +{ + struct fsl_mc_bus *mc_bus = NULL; + + kfree(mc_dev->regions); + + /* + * The device-specific remove callback will get invoked by device_del() + */ + device_del(&mc_dev->dev); + put_device(&mc_dev->dev); + + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) { + mc_bus = to_fsl_mc_bus(mc_dev); + + if (fsl_mc_is_root_dprc(&mc_dev->dev)) { + if (atomic_read(&root_dprc_count) > 0) + atomic_dec(&root_dprc_count); + else + WARN_ON(1); + } + } + + if (mc_bus) + devm_kfree(mc_dev->dev.parent, mc_bus); + else + kmem_cache_free(mc_dev_cache, mc_dev); +} +EXPORT_SYMBOL_GPL(fsl_mc_device_remove); + +static int parse_mc_ranges(struct device *dev, + int *paddr_cells, + int *mc_addr_cells, + int *mc_size_cells, + const __be32 **ranges_start, + u8 *num_ranges) +{ + const __be32 *prop; + int range_tuple_cell_count; + int ranges_len; + int tuple_len; + struct device_node *mc_node = dev->of_node; + + *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); + if (!(*ranges_start) || !ranges_len) { + dev_warn(dev, + "missing or empty ranges property for device tree node '%s'\n", + mc_node->name); + + *num_ranges = 0; + return 0; + } + + *paddr_cells = of_n_addr_cells(mc_node); + + prop = of_get_property(mc_node, "#address-cells", NULL); + if (prop) + *mc_addr_cells = be32_to_cpup(prop); + else + *mc_addr_cells = *paddr_cells; + + prop = of_get_property(mc_node, "#size-cells", NULL); + if (prop) + *mc_size_cells = be32_to_cpup(prop); + else + *mc_size_cells = of_n_size_cells(mc_node); + + range_tuple_cell_count = *paddr_cells + *mc_addr_cells + + *mc_size_cells; + + tuple_len = range_tuple_cell_count * sizeof(__be32); + if (ranges_len % tuple_len != 0) { + dev_err(dev, "malformed ranges property '%s'\n", mc_node->name); + return -EINVAL; + } + + *num_ranges = ranges_len / tuple_len; + return 0; +} + +static int get_mc_addr_translation_ranges(struct device *dev, + struct fsl_mc_addr_translation_range + **ranges, + u8 *num_ranges) +{ + int error; + int paddr_cells; + int mc_addr_cells; + int mc_size_cells; + int i; + const __be32 *ranges_start; + const __be32 *cell; + + error = parse_mc_ranges(dev, + &paddr_cells, + &mc_addr_cells, + &mc_size_cells, + &ranges_start, + num_ranges); + if (error < 0) + return error; + + if (!(*num_ranges)) { + /* + * Missing or empty ranges property ("ranges;") for the + * 'fsl,qoriq-mc' node. In this case, identity mapping + * will be used. + */ + *ranges = NULL; + return 0; + } + + *ranges = devm_kcalloc(dev, *num_ranges, + sizeof(struct fsl_mc_addr_translation_range), + GFP_KERNEL); + if (!(*ranges)) + return -ENOMEM; + + cell = ranges_start; + for (i = 0; i < *num_ranges; ++i) { + struct fsl_mc_addr_translation_range *range = &(*ranges)[i]; + + range->mc_region_type = of_read_number(cell, 1); + range->start_mc_offset = of_read_number(cell + 1, + mc_addr_cells - 1); + cell += mc_addr_cells; + range->start_phys_addr = of_read_number(cell, paddr_cells); + cell += paddr_cells; + range->end_mc_offset = range->start_mc_offset + + of_read_number(cell, mc_size_cells); + + cell += mc_size_cells; + } + + return 0; +} + +/** + * fsl_mc_bus_probe - callback invoked when the root MC bus is being + * added + */ +static int fsl_mc_bus_probe(struct platform_device *pdev) +{ + struct dprc_obj_desc obj_desc; + int error; + struct fsl_mc *mc; + struct fsl_mc_device *mc_bus_dev = NULL; + struct fsl_mc_io *mc_io = NULL; + int container_id; + phys_addr_t mc_portal_phys_addr; + u32 mc_portal_size; + struct mc_version mc_version; + struct resource res; + + dev_info(&pdev->dev, "Root MC bus device probed"); + + mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); + if (!mc) + return -ENOMEM; + + platform_set_drvdata(pdev, mc); + + /* + * Get physical address of MC portal for the root DPRC: + */ + error = of_address_to_resource(pdev->dev.of_node, 0, &res); + if (error < 0) { + dev_err(&pdev->dev, + "of_address_to_resource() failed for %s\n", + pdev->dev.of_node->full_name); + return error; + } + + mc_portal_phys_addr = res.start; + mc_portal_size = resource_size(&res); + error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, + mc_portal_size, NULL, + FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io); + if (error < 0) + return error; + + error = mc_get_version(mc_io, 0, &mc_version); + if (error != 0) { + dev_err(&pdev->dev, + "mc_get_version() failed with error %d\n", error); + goto error_cleanup_mc_io; + } + + dev_info(&pdev->dev, + "Freescale Management Complex Firmware version: %u.%u.%u\n", + mc_version.major, mc_version.minor, mc_version.revision); + + error = get_mc_addr_translation_ranges(&pdev->dev, + &mc->translation_ranges, + &mc->num_translation_ranges); + if (error < 0) + goto error_cleanup_mc_io; + + error = dpmng_get_container_id(mc_io, 0, &container_id); + if (error < 0) { + dev_err(&pdev->dev, + "dpmng_get_container_id() failed: %d\n", error); + goto error_cleanup_mc_io; + } + + memset(&obj_desc, 0, sizeof(struct dprc_obj_desc)); + error = get_dprc_version(mc_io, container_id, + &obj_desc.ver_major, &obj_desc.ver_minor); + if (error < 0) + goto error_cleanup_mc_io; + + obj_desc.vendor = FSL_MC_VENDOR_FREESCALE; + strcpy(obj_desc.type, "dprc"); + obj_desc.id = container_id; + obj_desc.irq_count = 1; + obj_desc.region_count = 0; + + error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); + if (error < 0) + goto error_cleanup_mc_io; + + mc->root_mc_bus_dev = mc_bus_dev; + return 0; + +error_cleanup_mc_io: + fsl_destroy_mc_io(mc_io); + return error; +} + +/** + * fsl_mc_bus_remove - callback invoked when the root MC bus is being + * removed + */ +static int fsl_mc_bus_remove(struct platform_device *pdev) +{ + struct fsl_mc *mc = platform_get_drvdata(pdev); + + if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))) + return -EINVAL; + + fsl_mc_device_remove(mc->root_mc_bus_dev); + + fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io); + mc->root_mc_bus_dev->mc_io = NULL; + + dev_info(&pdev->dev, "Root MC bus device removed"); + return 0; +} + +static const struct of_device_id fsl_mc_bus_match_table[] = { + {.compatible = "fsl,qoriq-mc",}, + {}, +}; + +MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table); + +static struct platform_driver fsl_mc_bus_driver = { + .driver = { + .name = "fsl_mc_bus", + .pm = NULL, + .of_match_table = fsl_mc_bus_match_table, + }, + .probe = fsl_mc_bus_probe, + .remove = fsl_mc_bus_remove, +}; + +static int __init fsl_mc_bus_driver_init(void) +{ + int error; + + mc_dev_cache = kmem_cache_create("fsl_mc_device", + sizeof(struct fsl_mc_device), 0, 0, + NULL); + if (!mc_dev_cache) { + pr_err("Could not create fsl_mc_device cache\n"); + return -ENOMEM; + } + + error = bus_register(&fsl_mc_bus_type); + if (error < 0) { + pr_err("fsl-mc bus type registration failed: %d\n", error); + goto error_cleanup_cache; + } + + pr_info("fsl-mc bus type registered\n"); + + error = platform_driver_register(&fsl_mc_bus_driver); + if (error < 0) { + pr_err("platform_driver_register() failed: %d\n", error); + goto error_cleanup_bus; + } + + error = dprc_driver_init(); + if (error < 0) + goto error_cleanup_driver; + + error = fsl_mc_allocator_driver_init(); + if (error < 0) + goto error_cleanup_dprc_driver; + + error = its_fsl_mc_msi_init(); + if (error < 0) + goto error_cleanup_mc_allocator; + + return 0; + +error_cleanup_mc_allocator: + fsl_mc_allocator_driver_exit(); + +error_cleanup_dprc_driver: + dprc_driver_exit(); + +error_cleanup_driver: + platform_driver_unregister(&fsl_mc_bus_driver); + +error_cleanup_bus: + bus_unregister(&fsl_mc_bus_type); + +error_cleanup_cache: + kmem_cache_destroy(mc_dev_cache); + return error; +} +postcore_initcall(fsl_mc_bus_driver_init); diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c new file mode 100644 index 000000000000..6e39a983f8e3 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c @@ -0,0 +1,287 @@ +/* + * Freescale Management Complex (MC) bus driver MSI support + * + * Copyright (C) 2015 Freescale Semiconductor, Inc. + * Author: German Rivera + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include "../include/mc-bus.h" +#include +#include +#include +#include +#include +#include +#include +#include "../include/mc-sys.h" +#include "dprc-cmd.h" + +/* + * Generate a unique ID identifying the interrupt (only used within the MSI + * irqdomain. Combine the icid with the interrupt index. + */ +static irq_hw_number_t fsl_mc_domain_calc_hwirq(struct fsl_mc_device *dev, + struct msi_desc *desc) +{ + /* + * Make the base hwirq value for ICID*10000 so it is readable + * as a decimal value in /proc/interrupts. + */ + return (irq_hw_number_t)(desc->fsl_mc.msi_index + (dev->icid * 10000)); +} + +static void fsl_mc_msi_set_desc(msi_alloc_info_t *arg, + struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq = fsl_mc_domain_calc_hwirq(to_fsl_mc_device(desc->dev), + desc); +} + +static void fsl_mc_msi_update_dom_ops(struct msi_domain_info *info) +{ + struct msi_domain_ops *ops = info->ops; + + if (WARN_ON(!ops)) + return; + + /* + * set_desc should not be set by the caller + */ + if (ops->set_desc == NULL) + ops->set_desc = fsl_mc_msi_set_desc; +} + +static void __fsl_mc_msi_write_msg(struct fsl_mc_device *mc_bus_dev, + struct fsl_mc_device_irq *mc_dev_irq) +{ + int error; + struct fsl_mc_device *owner_mc_dev = mc_dev_irq->mc_dev; + struct msi_desc *msi_desc = mc_dev_irq->msi_desc; + struct dprc_irq_cfg irq_cfg; + + /* + * msi_desc->msg.address is 0x0 when this function is invoked in + * the free_irq() code path. In this case, for the MC, we don't + * really need to "unprogram" the MSI, so we just return. + */ + if (msi_desc->msg.address_lo == 0x0 && msi_desc->msg.address_hi == 0x0) + return; + + if (WARN_ON(!owner_mc_dev)) + return; + + irq_cfg.paddr = ((u64)msi_desc->msg.address_hi << 32) | + msi_desc->msg.address_lo; + irq_cfg.val = msi_desc->msg.data; + irq_cfg.irq_num = msi_desc->irq; + + if (owner_mc_dev == mc_bus_dev) { + /* + * IRQ is for the mc_bus_dev's DPRC itself + */ + error = dprc_set_irq(mc_bus_dev->mc_io, + MC_CMD_FLAG_INTR_DIS | MC_CMD_FLAG_PRI, + mc_bus_dev->mc_handle, + mc_dev_irq->dev_irq_index, + &irq_cfg); + if (error < 0) { + dev_err(&owner_mc_dev->dev, + "dprc_set_irq() failed: %d\n", error); + } + } else { + /* + * IRQ is for for a child device of mc_bus_dev + */ + error = dprc_set_obj_irq(mc_bus_dev->mc_io, + MC_CMD_FLAG_INTR_DIS | MC_CMD_FLAG_PRI, + mc_bus_dev->mc_handle, + owner_mc_dev->obj_desc.type, + owner_mc_dev->obj_desc.id, + mc_dev_irq->dev_irq_index, + &irq_cfg); + if (error < 0) { + dev_err(&owner_mc_dev->dev, + "dprc_obj_set_irq() failed: %d\n", error); + } + } +} + +/* + * NOTE: This function is invoked with interrupts disabled + */ +static void fsl_mc_msi_write_msg(struct irq_data *irq_data, + struct msi_msg *msg) +{ + struct msi_desc *msi_desc = irq_data_get_msi_desc(irq_data); + struct fsl_mc_device *mc_bus_dev = to_fsl_mc_device(msi_desc->dev); + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); + struct fsl_mc_device_irq *mc_dev_irq = + &mc_bus->irq_resources[msi_desc->fsl_mc.msi_index]; + + WARN_ON(mc_dev_irq->msi_desc != msi_desc); + msi_desc->msg = *msg; + + /* + * Program the MSI (paddr, value) pair in the device: + */ + __fsl_mc_msi_write_msg(mc_bus_dev, mc_dev_irq); +} + +static void fsl_mc_msi_update_chip_ops(struct msi_domain_info *info) +{ + struct irq_chip *chip = info->chip; + + if (WARN_ON((!chip))) + return; + + /* + * irq_write_msi_msg should not be set by the caller + */ + if (chip->irq_write_msi_msg == NULL) + chip->irq_write_msi_msg = fsl_mc_msi_write_msg; +} + +/** + * fsl_mc_msi_create_irq_domain - Create a fsl-mc MSI interrupt domain + * @np: Optional device-tree node of the interrupt controller + * @info: MSI domain info + * @parent: Parent irq domain + * + * Updates the domain and chip ops and creates a fsl-mc MSI + * interrupt domain. + * + * Returns: + * A domain pointer or NULL in case of failure. + */ +struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, + struct msi_domain_info *info, + struct irq_domain *parent) +{ + struct irq_domain *domain; + + if (info->flags & MSI_FLAG_USE_DEF_DOM_OPS) + fsl_mc_msi_update_dom_ops(info); + if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) + fsl_mc_msi_update_chip_ops(info); + + domain = msi_create_irq_domain(fwnode, info, parent); + if (domain) + domain->bus_token = DOMAIN_BUS_FSL_MC_MSI; + + return domain; +} + +int fsl_mc_find_msi_domain(struct device *mc_platform_dev, + struct irq_domain **mc_msi_domain) +{ + struct irq_domain *msi_domain; + struct device_node *mc_of_node = mc_platform_dev->of_node; + + msi_domain = of_msi_get_domain(mc_platform_dev, mc_of_node, + DOMAIN_BUS_FSL_MC_MSI); + if (!msi_domain) { + pr_err("Unable to find fsl-mc MSI domain for %s\n", + mc_of_node->full_name); + + return -ENOENT; + } + + *mc_msi_domain = msi_domain; + return 0; +} + +static void fsl_mc_msi_free_descs(struct device *dev) +{ + struct msi_desc *desc, *tmp; + + list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) { + list_del(&desc->list); + free_msi_entry(desc); + } +} + +static int fsl_mc_msi_alloc_descs(struct device *dev, unsigned int irq_count) + +{ + unsigned int i; + int error; + struct msi_desc *msi_desc; + + for (i = 0; i < irq_count; i++) { + msi_desc = alloc_msi_entry(dev); + if (!msi_desc) { + dev_err(dev, "Failed to allocate msi entry\n"); + error = -ENOMEM; + goto cleanup_msi_descs; + } + + msi_desc->fsl_mc.msi_index = i; + msi_desc->nvec_used = 1; + INIT_LIST_HEAD(&msi_desc->list); + list_add_tail(&msi_desc->list, dev_to_msi_list(dev)); + } + + return 0; + +cleanup_msi_descs: + fsl_mc_msi_free_descs(dev); + return error; +} + +int fsl_mc_msi_domain_alloc_irqs(struct device *dev, + unsigned int irq_count) +{ + struct irq_domain *msi_domain; + int error; + + if (WARN_ON(!list_empty(dev_to_msi_list(dev)))) + return -EINVAL; + + error = fsl_mc_msi_alloc_descs(dev, irq_count); + if (error < 0) + return error; + + msi_domain = dev_get_msi_domain(dev); + if (WARN_ON(!msi_domain)) { + error = -EINVAL; + goto cleanup_msi_descs; + } + + /* + * NOTE: Calling this function will trigger the invocation of the + * its_fsl_mc_msi_prepare() callback + */ + error = msi_domain_alloc_irqs(msi_domain, dev, irq_count); + + if (error) { + dev_err(dev, "Failed to allocate IRQs\n"); + goto cleanup_msi_descs; + } + + return 0; + +cleanup_msi_descs: + fsl_mc_msi_free_descs(dev); + return error; +} + +void fsl_mc_msi_domain_free_irqs(struct device *dev) +{ + struct irq_domain *msi_domain; + + msi_domain = dev_get_msi_domain(dev); + if (WARN_ON(!msi_domain)) + return; + + msi_domain_free_irqs(msi_domain, dev); + + if (WARN_ON(list_empty(dev_to_msi_list(dev)))) + return; + + fsl_mc_msi_free_descs(dev); +} diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c deleted file mode 100644 index 3ebaecbc1ec0..000000000000 --- a/drivers/staging/fsl-mc/bus/mc-allocator.c +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Freescale MC object device allocator driver - * - * Copyright (C) 2013 Freescale Semiconductor, Inc. - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ - -#include "../include/mc-bus.h" -#include "../include/mc-sys.h" -#include -#include "../include/dpbp-cmd.h" -#include "../include/dpcon-cmd.h" -#include "dpmcp-cmd.h" -#include "dpmcp.h" -#include - -/** - * fsl_mc_resource_pool_add_device - add allocatable device to a resource - * pool of a given MC bus - * - * @mc_bus: pointer to the MC bus - * @pool_type: MC bus pool type - * @mc_dev: Pointer to allocatable MC object device - * - * It adds an allocatable MC object device to a container's resource pool of - * the given resource type - */ -static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus - *mc_bus, - enum fsl_mc_pool_type - pool_type, - struct fsl_mc_device - *mc_dev) -{ - struct fsl_mc_resource_pool *res_pool; - struct fsl_mc_resource *resource; - struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; - int error = -EINVAL; - - if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) - goto out; - if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) - goto out; - if (WARN_ON(mc_dev->resource)) - goto out; - - res_pool = &mc_bus->resource_pools[pool_type]; - if (WARN_ON(res_pool->type != pool_type)) - goto out; - if (WARN_ON(res_pool->mc_bus != mc_bus)) - goto out; - - mutex_lock(&res_pool->mutex); - - if (WARN_ON(res_pool->max_count < 0)) - goto out_unlock; - if (WARN_ON(res_pool->free_count < 0 || - res_pool->free_count > res_pool->max_count)) - goto out_unlock; - - resource = devm_kzalloc(&mc_bus_dev->dev, sizeof(*resource), - GFP_KERNEL); - if (!resource) { - error = -ENOMEM; - dev_err(&mc_bus_dev->dev, - "Failed to allocate memory for fsl_mc_resource\n"); - goto out_unlock; - } - - resource->type = pool_type; - resource->id = mc_dev->obj_desc.id; - resource->data = mc_dev; - resource->parent_pool = res_pool; - INIT_LIST_HEAD(&resource->node); - list_add_tail(&resource->node, &res_pool->free_list); - mc_dev->resource = resource; - res_pool->free_count++; - res_pool->max_count++; - error = 0; -out_unlock: - mutex_unlock(&res_pool->mutex); -out: - return error; -} - -/** - * fsl_mc_resource_pool_remove_device - remove an allocatable device from a - * resource pool - * - * @mc_dev: Pointer to allocatable MC object device - * - * It permanently removes an allocatable MC object device from the resource - * pool, the device is currently in, as long as it is in the pool's free list. - */ -static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device - *mc_dev) -{ - struct fsl_mc_device *mc_bus_dev; - struct fsl_mc_bus *mc_bus; - struct fsl_mc_resource_pool *res_pool; - struct fsl_mc_resource *resource; - int error = -EINVAL; - - if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) - goto out; - - resource = mc_dev->resource; - if (WARN_ON(!resource || resource->data != mc_dev)) - goto out; - - mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - mc_bus = to_fsl_mc_bus(mc_bus_dev); - res_pool = resource->parent_pool; - if (WARN_ON(res_pool != &mc_bus->resource_pools[resource->type])) - goto out; - - mutex_lock(&res_pool->mutex); - - if (WARN_ON(res_pool->max_count <= 0)) - goto out_unlock; - if (WARN_ON(res_pool->free_count <= 0 || - res_pool->free_count > res_pool->max_count)) - goto out_unlock; - - /* - * If the device is currently allocated, its resource is not - * in the free list and thus, the device cannot be removed. - */ - if (list_empty(&resource->node)) { - error = -EBUSY; - dev_err(&mc_bus_dev->dev, - "Device %s cannot be removed from resource pool\n", - dev_name(&mc_dev->dev)); - goto out_unlock; - } - - list_del(&resource->node); - INIT_LIST_HEAD(&resource->node); - res_pool->free_count--; - res_pool->max_count--; - - devm_kfree(&mc_bus_dev->dev, resource); - mc_dev->resource = NULL; - error = 0; -out_unlock: - mutex_unlock(&res_pool->mutex); -out: - return error; -} - -static const char *const fsl_mc_pool_type_strings[] = { - [FSL_MC_POOL_DPMCP] = "dpmcp", - [FSL_MC_POOL_DPBP] = "dpbp", - [FSL_MC_POOL_DPCON] = "dpcon", - [FSL_MC_POOL_IRQ] = "irq", -}; - -static int __must_check object_type_to_pool_type(const char *object_type, - enum fsl_mc_pool_type - *pool_type) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) { - if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) { - *pool_type = i; - return 0; - } - } - - return -EINVAL; -} - -int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, - enum fsl_mc_pool_type pool_type, - struct fsl_mc_resource **new_resource) -{ - struct fsl_mc_resource_pool *res_pool; - struct fsl_mc_resource *resource; - struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; - int error = -EINVAL; - - BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) != - FSL_MC_NUM_POOL_TYPES); - - *new_resource = NULL; - if (WARN_ON(pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)) - goto out; - - res_pool = &mc_bus->resource_pools[pool_type]; - if (WARN_ON(res_pool->mc_bus != mc_bus)) - goto out; - - mutex_lock(&res_pool->mutex); - resource = list_first_entry_or_null(&res_pool->free_list, - struct fsl_mc_resource, node); - - if (!resource) { - WARN_ON(res_pool->free_count != 0); - error = -ENXIO; - dev_err(&mc_bus_dev->dev, - "No more resources of type %s left\n", - fsl_mc_pool_type_strings[pool_type]); - goto out_unlock; - } - - if (WARN_ON(resource->type != pool_type)) - goto out_unlock; - if (WARN_ON(resource->parent_pool != res_pool)) - goto out_unlock; - if (WARN_ON(res_pool->free_count <= 0 || - res_pool->free_count > res_pool->max_count)) - goto out_unlock; - - list_del(&resource->node); - INIT_LIST_HEAD(&resource->node); - - res_pool->free_count--; - error = 0; -out_unlock: - mutex_unlock(&res_pool->mutex); - *new_resource = resource; -out: - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate); - -void fsl_mc_resource_free(struct fsl_mc_resource *resource) -{ - struct fsl_mc_resource_pool *res_pool; - - res_pool = resource->parent_pool; - if (WARN_ON(resource->type != res_pool->type)) - return; - - mutex_lock(&res_pool->mutex); - if (WARN_ON(res_pool->free_count < 0 || - res_pool->free_count >= res_pool->max_count)) - goto out_unlock; - - if (WARN_ON(!list_empty(&resource->node))) - goto out_unlock; - - list_add_tail(&resource->node, &res_pool->free_list); - res_pool->free_count++; -out_unlock: - mutex_unlock(&res_pool->mutex); -} -EXPORT_SYMBOL_GPL(fsl_mc_resource_free); - -/** - * fsl_mc_portal_allocate - Allocates an MC portal - * - * @mc_dev: MC device for which the MC portal is to be allocated - * @mc_io_flags: Flags for the fsl_mc_io object that wraps the allocated - * MC portal. - * @new_mc_io: Pointer to area where the pointer to the fsl_mc_io object - * that wraps the allocated MC portal is to be returned - * - * This function allocates an MC portal from the device's parent DPRC, - * from the corresponding MC bus' pool of MC portals and wraps - * it in a new fsl_mc_io object. If 'mc_dev' is a DPRC itself, the - * portal is allocated from its own MC bus. - */ -int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, - u16 mc_io_flags, - struct fsl_mc_io **new_mc_io) -{ - struct fsl_mc_device *mc_bus_dev; - struct fsl_mc_bus *mc_bus; - phys_addr_t mc_portal_phys_addr; - size_t mc_portal_size; - struct fsl_mc_device *dpmcp_dev; - int error = -EINVAL; - struct fsl_mc_resource *resource = NULL; - struct fsl_mc_io *mc_io = NULL; - - if (mc_dev->flags & FSL_MC_IS_DPRC) { - mc_bus_dev = mc_dev; - } else { - if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) - return error; - - mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - } - - mc_bus = to_fsl_mc_bus(mc_bus_dev); - *new_mc_io = NULL; - error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_DPMCP, &resource); - if (error < 0) - return error; - - error = -EINVAL; - dpmcp_dev = resource->data; - if (WARN_ON(!dpmcp_dev)) - goto error_cleanup_resource; - - if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR || - (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR && - dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) { - dev_err(&dpmcp_dev->dev, - "ERROR: Version %d.%d of DPMCP not supported.\n", - dpmcp_dev->obj_desc.ver_major, - dpmcp_dev->obj_desc.ver_minor); - error = -ENOTSUPP; - goto error_cleanup_resource; - } - - if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0)) - goto error_cleanup_resource; - - mc_portal_phys_addr = dpmcp_dev->regions[0].start; - mc_portal_size = dpmcp_dev->regions[0].end - - dpmcp_dev->regions[0].start + 1; - - if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size)) - goto error_cleanup_resource; - - error = fsl_create_mc_io(&mc_bus_dev->dev, - mc_portal_phys_addr, - mc_portal_size, dpmcp_dev, - mc_io_flags, &mc_io); - if (error < 0) - goto error_cleanup_resource; - - *new_mc_io = mc_io; - return 0; - -error_cleanup_resource: - fsl_mc_resource_free(resource); - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate); - -/** - * fsl_mc_portal_free - Returns an MC portal to the pool of free MC portals - * of a given MC bus - * - * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free - */ -void fsl_mc_portal_free(struct fsl_mc_io *mc_io) -{ - struct fsl_mc_device *dpmcp_dev; - struct fsl_mc_resource *resource; - - /* - * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed - * to have a DPMCP object associated with. - */ - dpmcp_dev = mc_io->dpmcp_dev; - if (WARN_ON(!dpmcp_dev)) - return; - - resource = dpmcp_dev->resource; - if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP)) - return; - - if (WARN_ON(resource->data != dpmcp_dev)) - return; - - fsl_destroy_mc_io(mc_io); - fsl_mc_resource_free(resource); -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_free); - -/** - * fsl_mc_portal_reset - Resets the dpmcp object for a given fsl_mc_io object - * - * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free - */ -int fsl_mc_portal_reset(struct fsl_mc_io *mc_io) -{ - int error; - struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; - - if (WARN_ON(!dpmcp_dev)) - return -EINVAL; - - error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle); - if (error < 0) { - dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error); - return error; - } - - return 0; -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_reset); - -/** - * fsl_mc_object_allocate - Allocates a MC object device of the given - * pool type from a given MC bus - * - * @mc_dev: MC device for which the MC object device is to be allocated - * @pool_type: MC bus resource pool type - * @new_mc_dev: Pointer to area where the pointer to the allocated - * MC object device is to be returned - * - * This function allocates a MC object device from the device's parent DPRC, - * from the corresponding MC bus' pool of allocatable MC object devices of - * the given resource type. mc_dev cannot be a DPRC itself. - * - * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC - * portals are allocated using fsl_mc_portal_allocate(), instead of - * this function. - */ -int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, - enum fsl_mc_pool_type pool_type, - struct fsl_mc_device **new_mc_adev) -{ - struct fsl_mc_device *mc_bus_dev; - struct fsl_mc_bus *mc_bus; - struct fsl_mc_device *mc_adev; - int error = -EINVAL; - struct fsl_mc_resource *resource = NULL; - - *new_mc_adev = NULL; - if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC)) - goto error; - - if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) - goto error; - - if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP)) - goto error; - - mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - mc_bus = to_fsl_mc_bus(mc_bus_dev); - error = fsl_mc_resource_allocate(mc_bus, pool_type, &resource); - if (error < 0) - goto error; - - mc_adev = resource->data; - if (WARN_ON(!mc_adev)) - goto error; - - *new_mc_adev = mc_adev; - return 0; -error: - if (resource) - fsl_mc_resource_free(resource); - - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_object_allocate); - -/** - * fsl_mc_object_free - Returns an allocatable MC object device to the - * corresponding resource pool of a given MC bus. - * - * @mc_adev: Pointer to the MC object device - */ -void fsl_mc_object_free(struct fsl_mc_device *mc_adev) -{ - struct fsl_mc_resource *resource; - - resource = mc_adev->resource; - if (WARN_ON(resource->type == FSL_MC_POOL_DPMCP)) - return; - if (WARN_ON(resource->data != mc_adev)) - return; - - fsl_mc_resource_free(resource); -} -EXPORT_SYMBOL_GPL(fsl_mc_object_free); - -/* - * Initialize the interrupt pool associated with a MC bus. - * It allocates a block of IRQs from the GIC-ITS - */ -int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, - unsigned int irq_count) -{ - unsigned int i; - struct msi_desc *msi_desc; - struct fsl_mc_device_irq *irq_resources; - struct fsl_mc_device_irq *mc_dev_irq; - int error; - struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; - struct fsl_mc_resource_pool *res_pool = - &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; - - if (WARN_ON(irq_count == 0 || - irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS)) - return -EINVAL; - - error = fsl_mc_msi_domain_alloc_irqs(&mc_bus_dev->dev, irq_count); - if (error < 0) - return error; - - irq_resources = devm_kzalloc(&mc_bus_dev->dev, - sizeof(*irq_resources) * irq_count, - GFP_KERNEL); - if (!irq_resources) { - error = -ENOMEM; - goto cleanup_msi_irqs; - } - - for (i = 0; i < irq_count; i++) { - mc_dev_irq = &irq_resources[i]; - - /* - * NOTE: This mc_dev_irq's MSI addr/value pair will be set - * by the fsl_mc_msi_write_msg() callback - */ - mc_dev_irq->resource.type = res_pool->type; - mc_dev_irq->resource.data = mc_dev_irq; - mc_dev_irq->resource.parent_pool = res_pool; - INIT_LIST_HEAD(&mc_dev_irq->resource.node); - list_add_tail(&mc_dev_irq->resource.node, &res_pool->free_list); - } - - for_each_msi_entry(msi_desc, &mc_bus_dev->dev) { - mc_dev_irq = &irq_resources[msi_desc->fsl_mc.msi_index]; - mc_dev_irq->msi_desc = msi_desc; - mc_dev_irq->resource.id = msi_desc->irq; - } - - res_pool->max_count = irq_count; - res_pool->free_count = irq_count; - mc_bus->irq_resources = irq_resources; - return 0; - -cleanup_msi_irqs: - fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool); - -/** - * Teardown the interrupt pool associated with an MC bus. - * It frees the IRQs that were allocated to the pool, back to the GIC-ITS. - */ -void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus) -{ - struct fsl_mc_device *mc_bus_dev = &mc_bus->mc_dev; - struct fsl_mc_resource_pool *res_pool = - &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; - - if (WARN_ON(!mc_bus->irq_resources)) - return; - - if (WARN_ON(res_pool->max_count == 0)) - return; - - if (WARN_ON(res_pool->free_count != res_pool->max_count)) - return; - - INIT_LIST_HEAD(&res_pool->free_list); - res_pool->max_count = 0; - res_pool->free_count = 0; - mc_bus->irq_resources = NULL; - fsl_mc_msi_domain_free_irqs(&mc_bus_dev->dev); -} -EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool); - -/** - * It allocates the IRQs required by a given MC object device. The - * IRQs are allocated from the interrupt pool associated with the - * MC bus that contains the device, if the device is not a DPRC device. - * Otherwise, the IRQs are allocated from the interrupt pool associated - * with the MC bus that represents the DPRC device itself. - */ -int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev) -{ - int i; - int irq_count; - int res_allocated_count = 0; - int error = -EINVAL; - struct fsl_mc_device_irq **irqs = NULL; - struct fsl_mc_bus *mc_bus; - struct fsl_mc_resource_pool *res_pool; - - if (WARN_ON(mc_dev->irqs)) - return -EINVAL; - - irq_count = mc_dev->obj_desc.irq_count; - if (WARN_ON(irq_count == 0)) - return -EINVAL; - - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) - mc_bus = to_fsl_mc_bus(mc_dev); - else - mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); - - if (WARN_ON(!mc_bus->irq_resources)) - return -EINVAL; - - res_pool = &mc_bus->resource_pools[FSL_MC_POOL_IRQ]; - if (res_pool->free_count < irq_count) { - dev_err(&mc_dev->dev, - "Not able to allocate %u irqs for device\n", irq_count); - return -ENOSPC; - } - - irqs = devm_kzalloc(&mc_dev->dev, irq_count * sizeof(irqs[0]), - GFP_KERNEL); - if (!irqs) - return -ENOMEM; - - for (i = 0; i < irq_count; i++) { - struct fsl_mc_resource *resource; - - error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_IRQ, - &resource); - if (error < 0) - goto error_resource_alloc; - - irqs[i] = to_fsl_mc_irq(resource); - res_allocated_count++; - - WARN_ON(irqs[i]->mc_dev); - irqs[i]->mc_dev = mc_dev; - irqs[i]->dev_irq_index = i; - } - - mc_dev->irqs = irqs; - return 0; - -error_resource_alloc: - for (i = 0; i < res_allocated_count; i++) { - irqs[i]->mc_dev = NULL; - fsl_mc_resource_free(&irqs[i]->resource); - } - - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs); - -/* - * It frees the IRQs that were allocated for a MC object device, by - * returning them to the corresponding interrupt pool. - */ -void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev) -{ - int i; - int irq_count; - struct fsl_mc_bus *mc_bus; - struct fsl_mc_device_irq **irqs = mc_dev->irqs; - - if (WARN_ON(!irqs)) - return; - - irq_count = mc_dev->obj_desc.irq_count; - - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) - mc_bus = to_fsl_mc_bus(mc_dev); - else - mc_bus = to_fsl_mc_bus(to_fsl_mc_device(mc_dev->dev.parent)); - - if (WARN_ON(!mc_bus->irq_resources)) - return; - - for (i = 0; i < irq_count; i++) { - WARN_ON(!irqs[i]->mc_dev); - irqs[i]->mc_dev = NULL; - fsl_mc_resource_free(&irqs[i]->resource); - } - - mc_dev->irqs = NULL; -} -EXPORT_SYMBOL_GPL(fsl_mc_free_irqs); - -/** - * fsl_mc_allocator_probe - callback invoked when an allocatable device is - * being added to the system - */ -static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) -{ - enum fsl_mc_pool_type pool_type; - struct fsl_mc_device *mc_bus_dev; - struct fsl_mc_bus *mc_bus; - int error; - - if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) - return -EINVAL; - - mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev))) - return -EINVAL; - - mc_bus = to_fsl_mc_bus(mc_bus_dev); - error = object_type_to_pool_type(mc_dev->obj_desc.type, &pool_type); - if (error < 0) - return error; - - error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev); - if (error < 0) - return error; - - dev_dbg(&mc_dev->dev, - "Allocatable MC object device bound to fsl_mc_allocator driver"); - return 0; -} - -/** - * fsl_mc_allocator_remove - callback invoked when an allocatable device is - * being removed from the system - */ -static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev) -{ - int error; - - if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type))) - return -EINVAL; - - if (mc_dev->resource) { - error = fsl_mc_resource_pool_remove_device(mc_dev); - if (error < 0) - return error; - } - - dev_dbg(&mc_dev->dev, - "Allocatable MC object device unbound from fsl_mc_allocator driver"); - return 0; -} - -static const struct fsl_mc_device_id match_id_table[] = { - { - .vendor = FSL_MC_VENDOR_FREESCALE, - .obj_type = "dpbp", - }, - { - .vendor = FSL_MC_VENDOR_FREESCALE, - .obj_type = "dpmcp", - }, - { - .vendor = FSL_MC_VENDOR_FREESCALE, - .obj_type = "dpcon", - }, - {.vendor = 0x0}, -}; - -static struct fsl_mc_driver fsl_mc_allocator_driver = { - .driver = { - .name = "fsl_mc_allocator", - .owner = THIS_MODULE, - .pm = NULL, - }, - .match_id_table = match_id_table, - .probe = fsl_mc_allocator_probe, - .remove = fsl_mc_allocator_remove, -}; - -int __init fsl_mc_allocator_driver_init(void) -{ - return fsl_mc_driver_register(&fsl_mc_allocator_driver); -} - -void fsl_mc_allocator_driver_exit(void) -{ - fsl_mc_driver_unregister(&fsl_mc_allocator_driver); -} diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c deleted file mode 100644 index 975d30b8775e..000000000000 --- a/drivers/staging/fsl-mc/bus/mc-bus.c +++ /dev/null @@ -1,890 +0,0 @@ -/* - * Freescale Management Complex (MC) bus driver - * - * Copyright (C) 2014 Freescale Semiconductor, Inc. - * Author: German Rivera - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ - -#include "../include/mc-bus.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/dpmng.h" -#include "../include/mc-sys.h" -#include "dprc-cmd.h" - -static struct kmem_cache *mc_dev_cache; - -/** - * fsl_mc_bus_match - device to driver matching callback - * @dev: the MC object device structure to match against - * @drv: the device driver to search for matching MC object device id - * structures - * - * Returns 1 on success, 0 otherwise. - */ -static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) -{ - const struct fsl_mc_device_id *id; - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); - bool found = false; - - if (WARN_ON(!fsl_mc_bus_exists())) - goto out; - - if (!mc_drv->match_id_table) - goto out; - - /* - * If the object is not 'plugged' don't match. - * Only exception is the root DPRC, which is a special case. - */ - if ((mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED) == 0 && - !fsl_mc_is_root_dprc(&mc_dev->dev)) - goto out; - - /* - * Traverse the match_id table of the given driver, trying to find - * a matching for the given MC object device. - */ - for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) { - if (id->vendor == mc_dev->obj_desc.vendor && - strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) { - found = true; - - break; - } - } - -out: - dev_dbg(dev, "%smatched\n", found ? "" : "not "); - return found; -} - -/** - * fsl_mc_bus_uevent - callback invoked when a device is added - */ -static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) -{ - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - - if (add_uevent_var(env, "MODALIAS=fsl-mc:v%08Xd%s", - mc_dev->obj_desc.vendor, - mc_dev->obj_desc.type)) - return -ENOMEM; - - return 0; -} - -static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - - return sprintf(buf, "fsl-mc:v%08Xd%s\n", mc_dev->obj_desc.vendor, - mc_dev->obj_desc.type); -} -static DEVICE_ATTR_RO(modalias); - -static struct attribute *fsl_mc_dev_attrs[] = { - &dev_attr_modalias.attr, - NULL, -}; - -static const struct attribute_group fsl_mc_dev_group = { - .attrs = fsl_mc_dev_attrs, -}; - -static const struct attribute_group *fsl_mc_dev_groups[] = { - &fsl_mc_dev_group, - NULL, -}; - -struct bus_type fsl_mc_bus_type = { - .name = "fsl-mc", - .match = fsl_mc_bus_match, - .uevent = fsl_mc_bus_uevent, - .dev_groups = fsl_mc_dev_groups, -}; -EXPORT_SYMBOL_GPL(fsl_mc_bus_type); - -static atomic_t root_dprc_count = ATOMIC_INIT(0); - -static int fsl_mc_driver_probe(struct device *dev) -{ - struct fsl_mc_driver *mc_drv; - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - int error; - - if (WARN_ON(!dev->driver)) - return -EINVAL; - - mc_drv = to_fsl_mc_driver(dev->driver); - if (WARN_ON(!mc_drv->probe)) - return -EINVAL; - - error = mc_drv->probe(mc_dev); - if (error < 0) { - dev_err(dev, "MC object device probe callback failed: %d\n", - error); - return error; - } - - return 0; -} - -static int fsl_mc_driver_remove(struct device *dev) -{ - struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - int error; - - if (WARN_ON(!dev->driver)) - return -EINVAL; - - error = mc_drv->remove(mc_dev); - if (error < 0) { - dev_err(dev, - "MC object device remove callback failed: %d\n", - error); - return error; - } - - return 0; -} - -static void fsl_mc_driver_shutdown(struct device *dev) -{ - struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); - struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); - - mc_drv->shutdown(mc_dev); -} - -/** - * __fsl_mc_driver_register - registers a child device driver with the - * MC bus - * - * This function is implicitly invoked from the registration function of - * fsl_mc device drivers, which is generated by the - * module_fsl_mc_driver() macro. - */ -int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver, - struct module *owner) -{ - int error; - - mc_driver->driver.owner = owner; - mc_driver->driver.bus = &fsl_mc_bus_type; - - if (mc_driver->probe) - mc_driver->driver.probe = fsl_mc_driver_probe; - - if (mc_driver->remove) - mc_driver->driver.remove = fsl_mc_driver_remove; - - if (mc_driver->shutdown) - mc_driver->driver.shutdown = fsl_mc_driver_shutdown; - - error = driver_register(&mc_driver->driver); - if (error < 0) { - pr_err("driver_register() failed for %s: %d\n", - mc_driver->driver.name, error); - return error; - } - - pr_info("MC object device driver %s registered\n", - mc_driver->driver.name); - return 0; -} -EXPORT_SYMBOL_GPL(__fsl_mc_driver_register); - -/** - * fsl_mc_driver_unregister - unregisters a device driver from the - * MC bus - */ -void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver) -{ - driver_unregister(&mc_driver->driver); -} -EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); - -/** - * fsl_mc_bus_exists - check if a root dprc exists - */ -bool fsl_mc_bus_exists(void) -{ - return atomic_read(&root_dprc_count) > 0; -} -EXPORT_SYMBOL_GPL(fsl_mc_bus_exists); - -/** -* fsl_mc_get_root_dprc - function to traverse to the root dprc -*/ -static void fsl_mc_get_root_dprc(struct device *dev, - struct device **root_dprc_dev) -{ - if (WARN_ON(!dev)) { - *root_dprc_dev = NULL; - } else if (WARN_ON(!dev_is_fsl_mc(dev))) { - *root_dprc_dev = NULL; - } else { - *root_dprc_dev = dev; - while (dev_is_fsl_mc((*root_dprc_dev)->parent)) - *root_dprc_dev = (*root_dprc_dev)->parent; - } -} - -static int get_dprc_attr(struct fsl_mc_io *mc_io, - int container_id, struct dprc_attributes *attr) -{ - u16 dprc_handle; - int error; - - error = dprc_open(mc_io, 0, container_id, &dprc_handle); - if (error < 0) { - dev_err(mc_io->dev, "dprc_open() failed: %d\n", error); - return error; - } - - memset(attr, 0, sizeof(struct dprc_attributes)); - error = dprc_get_attributes(mc_io, 0, dprc_handle, attr); - if (error < 0) { - dev_err(mc_io->dev, "dprc_get_attributes() failed: %d\n", - error); - goto common_cleanup; - } - - error = 0; - -common_cleanup: - (void)dprc_close(mc_io, 0, dprc_handle); - return error; -} - -static int get_dprc_icid(struct fsl_mc_io *mc_io, - int container_id, u16 *icid) -{ - struct dprc_attributes attr; - int error; - - error = get_dprc_attr(mc_io, container_id, &attr); - if (error == 0) - *icid = attr.icid; - - return error; -} - -static int get_dprc_version(struct fsl_mc_io *mc_io, - int container_id, u16 *major, u16 *minor) -{ - struct dprc_attributes attr; - int error; - - error = get_dprc_attr(mc_io, container_id, &attr); - if (error == 0) { - *major = attr.version.major; - *minor = attr.version.minor; - } - - return error; -} - -static int translate_mc_addr(struct fsl_mc_device *mc_dev, - enum dprc_region_type mc_region_type, - u64 mc_offset, phys_addr_t *phys_addr) -{ - int i; - struct device *root_dprc_dev; - struct fsl_mc *mc; - - fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); - if (WARN_ON(!root_dprc_dev)) - return -EINVAL; - mc = dev_get_drvdata(root_dprc_dev->parent); - - if (mc->num_translation_ranges == 0) { - /* - * Do identity mapping: - */ - *phys_addr = mc_offset; - return 0; - } - - for (i = 0; i < mc->num_translation_ranges; i++) { - struct fsl_mc_addr_translation_range *range = - &mc->translation_ranges[i]; - - if (mc_region_type == range->mc_region_type && - mc_offset >= range->start_mc_offset && - mc_offset < range->end_mc_offset) { - *phys_addr = range->start_phys_addr + - (mc_offset - range->start_mc_offset); - return 0; - } - } - - return -EFAULT; -} - -static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, - struct fsl_mc_device *mc_bus_dev) -{ - int i; - int error; - struct resource *regions; - struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc; - struct device *parent_dev = mc_dev->dev.parent; - enum dprc_region_type mc_region_type; - - if (strcmp(obj_desc->type, "dprc") == 0 || - strcmp(obj_desc->type, "dpmcp") == 0) { - mc_region_type = DPRC_REGION_TYPE_MC_PORTAL; - } else if (strcmp(obj_desc->type, "dpio") == 0) { - mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL; - } else { - /* - * This function should not have been called for this MC object - * type, as this object type is not supposed to have MMIO - * regions - */ - WARN_ON(true); - return -EINVAL; - } - - regions = kmalloc_array(obj_desc->region_count, - sizeof(regions[0]), GFP_KERNEL); - if (!regions) - return -ENOMEM; - - for (i = 0; i < obj_desc->region_count; i++) { - struct dprc_region_desc region_desc; - - error = dprc_get_obj_region(mc_bus_dev->mc_io, - 0, - mc_bus_dev->mc_handle, - obj_desc->type, - obj_desc->id, i, ®ion_desc); - if (error < 0) { - dev_err(parent_dev, - "dprc_get_obj_region() failed: %d\n", error); - goto error_cleanup_regions; - } - - WARN_ON(region_desc.size == 0); - error = translate_mc_addr(mc_dev, mc_region_type, - region_desc.base_offset, - ®ions[i].start); - if (error < 0) { - dev_err(parent_dev, - "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", - region_desc.base_offset, - obj_desc->type, obj_desc->id, i); - goto error_cleanup_regions; - } - - regions[i].end = regions[i].start + region_desc.size - 1; - regions[i].name = "fsl-mc object MMIO region"; - regions[i].flags = IORESOURCE_IO; - if (region_desc.flags & DPRC_REGION_CACHEABLE) - regions[i].flags |= IORESOURCE_CACHEABLE; - } - - mc_dev->regions = regions; - return 0; - -error_cleanup_regions: - kfree(regions); - return error; -} - -/** - * fsl_mc_is_root_dprc - function to check if a given device is a root dprc - */ -bool fsl_mc_is_root_dprc(struct device *dev) -{ - struct device *root_dprc_dev; - - fsl_mc_get_root_dprc(dev, &root_dprc_dev); - if (!root_dprc_dev) - return false; - return dev == root_dprc_dev; -} - -/** - * Add a newly discovered MC object device to be visible in Linux - */ -int fsl_mc_device_add(struct dprc_obj_desc *obj_desc, - struct fsl_mc_io *mc_io, - struct device *parent_dev, - struct fsl_mc_device **new_mc_dev) -{ - int error; - struct fsl_mc_device *mc_dev = NULL; - struct fsl_mc_bus *mc_bus = NULL; - struct fsl_mc_device *parent_mc_dev; - - if (dev_is_fsl_mc(parent_dev)) - parent_mc_dev = to_fsl_mc_device(parent_dev); - else - parent_mc_dev = NULL; - - if (strcmp(obj_desc->type, "dprc") == 0) { - /* - * Allocate an MC bus device object: - */ - mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL); - if (!mc_bus) - return -ENOMEM; - - mc_dev = &mc_bus->mc_dev; - } else { - /* - * Allocate a regular fsl_mc_device object: - */ - mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL); - if (!mc_dev) - return -ENOMEM; - } - - mc_dev->obj_desc = *obj_desc; - mc_dev->mc_io = mc_io; - device_initialize(&mc_dev->dev); - mc_dev->dev.parent = parent_dev; - mc_dev->dev.bus = &fsl_mc_bus_type; - dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); - - if (strcmp(obj_desc->type, "dprc") == 0) { - struct fsl_mc_io *mc_io2; - - mc_dev->flags |= FSL_MC_IS_DPRC; - - /* - * To get the DPRC's ICID, we need to open the DPRC - * in get_dprc_icid(). For child DPRCs, we do so using the - * parent DPRC's MC portal instead of the child DPRC's MC - * portal, in case the child DPRC is already opened with - * its own portal (e.g., the DPRC used by AIOP). - * - * NOTE: There cannot be more than one active open for a - * given MC object, using the same MC portal. - */ - if (parent_mc_dev) { - /* - * device being added is a child DPRC device - */ - mc_io2 = parent_mc_dev->mc_io; - } else { - /* - * device being added is the root DPRC device - */ - if (WARN_ON(!mc_io)) { - error = -EINVAL; - goto error_cleanup_dev; - } - - mc_io2 = mc_io; - - atomic_inc(&root_dprc_count); - } - - error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); - if (error < 0) - goto error_cleanup_dev; - } else { - /* - * A non-DPRC MC object device has to be a child of another - * MC object (specifically a DPRC object) - */ - mc_dev->icid = parent_mc_dev->icid; - mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; - mc_dev->dev.dma_mask = &mc_dev->dma_mask; - dev_set_msi_domain(&mc_dev->dev, - dev_get_msi_domain(&parent_mc_dev->dev)); - } - - /* - * Get MMIO regions for the device from the MC: - * - * NOTE: the root DPRC is a special case as its MMIO region is - * obtained from the device tree - */ - if (parent_mc_dev && obj_desc->region_count != 0) { - error = fsl_mc_device_get_mmio_regions(mc_dev, - parent_mc_dev); - if (error < 0) - goto error_cleanup_dev; - } - - /* Objects are coherent, unless 'no shareability' flag set. */ - if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY)) - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true); - - /* - * The device-specific probe callback will get invoked by device_add() - */ - error = device_add(&mc_dev->dev); - if (error < 0) { - dev_err(parent_dev, - "device_add() failed for device %s: %d\n", - dev_name(&mc_dev->dev), error); - goto error_cleanup_dev; - } - - (void)get_device(&mc_dev->dev); - dev_dbg(parent_dev, "Added MC object device %s\n", - dev_name(&mc_dev->dev)); - - *new_mc_dev = mc_dev; - return 0; - -error_cleanup_dev: - kfree(mc_dev->regions); - if (mc_bus) - devm_kfree(parent_dev, mc_bus); - else - kmem_cache_free(mc_dev_cache, mc_dev); - - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_device_add); - -/** - * fsl_mc_device_remove - Remove a MC object device from being visible to - * Linux - * - * @mc_dev: Pointer to a MC object device object - */ -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) -{ - struct fsl_mc_bus *mc_bus = NULL; - - kfree(mc_dev->regions); - - /* - * The device-specific remove callback will get invoked by device_del() - */ - device_del(&mc_dev->dev); - put_device(&mc_dev->dev); - - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) { - mc_bus = to_fsl_mc_bus(mc_dev); - - if (fsl_mc_is_root_dprc(&mc_dev->dev)) { - if (atomic_read(&root_dprc_count) > 0) - atomic_dec(&root_dprc_count); - else - WARN_ON(1); - } - } - - if (mc_bus) - devm_kfree(mc_dev->dev.parent, mc_bus); - else - kmem_cache_free(mc_dev_cache, mc_dev); -} -EXPORT_SYMBOL_GPL(fsl_mc_device_remove); - -static int parse_mc_ranges(struct device *dev, - int *paddr_cells, - int *mc_addr_cells, - int *mc_size_cells, - const __be32 **ranges_start, - u8 *num_ranges) -{ - const __be32 *prop; - int range_tuple_cell_count; - int ranges_len; - int tuple_len; - struct device_node *mc_node = dev->of_node; - - *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); - if (!(*ranges_start) || !ranges_len) { - dev_warn(dev, - "missing or empty ranges property for device tree node '%s'\n", - mc_node->name); - - *num_ranges = 0; - return 0; - } - - *paddr_cells = of_n_addr_cells(mc_node); - - prop = of_get_property(mc_node, "#address-cells", NULL); - if (prop) - *mc_addr_cells = be32_to_cpup(prop); - else - *mc_addr_cells = *paddr_cells; - - prop = of_get_property(mc_node, "#size-cells", NULL); - if (prop) - *mc_size_cells = be32_to_cpup(prop); - else - *mc_size_cells = of_n_size_cells(mc_node); - - range_tuple_cell_count = *paddr_cells + *mc_addr_cells + - *mc_size_cells; - - tuple_len = range_tuple_cell_count * sizeof(__be32); - if (ranges_len % tuple_len != 0) { - dev_err(dev, "malformed ranges property '%s'\n", mc_node->name); - return -EINVAL; - } - - *num_ranges = ranges_len / tuple_len; - return 0; -} - -static int get_mc_addr_translation_ranges(struct device *dev, - struct fsl_mc_addr_translation_range - **ranges, - u8 *num_ranges) -{ - int error; - int paddr_cells; - int mc_addr_cells; - int mc_size_cells; - int i; - const __be32 *ranges_start; - const __be32 *cell; - - error = parse_mc_ranges(dev, - &paddr_cells, - &mc_addr_cells, - &mc_size_cells, - &ranges_start, - num_ranges); - if (error < 0) - return error; - - if (!(*num_ranges)) { - /* - * Missing or empty ranges property ("ranges;") for the - * 'fsl,qoriq-mc' node. In this case, identity mapping - * will be used. - */ - *ranges = NULL; - return 0; - } - - *ranges = devm_kcalloc(dev, *num_ranges, - sizeof(struct fsl_mc_addr_translation_range), - GFP_KERNEL); - if (!(*ranges)) - return -ENOMEM; - - cell = ranges_start; - for (i = 0; i < *num_ranges; ++i) { - struct fsl_mc_addr_translation_range *range = &(*ranges)[i]; - - range->mc_region_type = of_read_number(cell, 1); - range->start_mc_offset = of_read_number(cell + 1, - mc_addr_cells - 1); - cell += mc_addr_cells; - range->start_phys_addr = of_read_number(cell, paddr_cells); - cell += paddr_cells; - range->end_mc_offset = range->start_mc_offset + - of_read_number(cell, mc_size_cells); - - cell += mc_size_cells; - } - - return 0; -} - -/** - * fsl_mc_bus_probe - callback invoked when the root MC bus is being - * added - */ -static int fsl_mc_bus_probe(struct platform_device *pdev) -{ - struct dprc_obj_desc obj_desc; - int error; - struct fsl_mc *mc; - struct fsl_mc_device *mc_bus_dev = NULL; - struct fsl_mc_io *mc_io = NULL; - int container_id; - phys_addr_t mc_portal_phys_addr; - u32 mc_portal_size; - struct mc_version mc_version; - struct resource res; - - dev_info(&pdev->dev, "Root MC bus device probed"); - - mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); - if (!mc) - return -ENOMEM; - - platform_set_drvdata(pdev, mc); - - /* - * Get physical address of MC portal for the root DPRC: - */ - error = of_address_to_resource(pdev->dev.of_node, 0, &res); - if (error < 0) { - dev_err(&pdev->dev, - "of_address_to_resource() failed for %s\n", - pdev->dev.of_node->full_name); - return error; - } - - mc_portal_phys_addr = res.start; - mc_portal_size = resource_size(&res); - error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, - mc_portal_size, NULL, - FSL_MC_IO_ATOMIC_CONTEXT_PORTAL, &mc_io); - if (error < 0) - return error; - - error = mc_get_version(mc_io, 0, &mc_version); - if (error != 0) { - dev_err(&pdev->dev, - "mc_get_version() failed with error %d\n", error); - goto error_cleanup_mc_io; - } - - dev_info(&pdev->dev, - "Freescale Management Complex Firmware version: %u.%u.%u\n", - mc_version.major, mc_version.minor, mc_version.revision); - - error = get_mc_addr_translation_ranges(&pdev->dev, - &mc->translation_ranges, - &mc->num_translation_ranges); - if (error < 0) - goto error_cleanup_mc_io; - - error = dpmng_get_container_id(mc_io, 0, &container_id); - if (error < 0) { - dev_err(&pdev->dev, - "dpmng_get_container_id() failed: %d\n", error); - goto error_cleanup_mc_io; - } - - memset(&obj_desc, 0, sizeof(struct dprc_obj_desc)); - error = get_dprc_version(mc_io, container_id, - &obj_desc.ver_major, &obj_desc.ver_minor); - if (error < 0) - goto error_cleanup_mc_io; - - obj_desc.vendor = FSL_MC_VENDOR_FREESCALE; - strcpy(obj_desc.type, "dprc"); - obj_desc.id = container_id; - obj_desc.irq_count = 1; - obj_desc.region_count = 0; - - error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); - if (error < 0) - goto error_cleanup_mc_io; - - mc->root_mc_bus_dev = mc_bus_dev; - return 0; - -error_cleanup_mc_io: - fsl_destroy_mc_io(mc_io); - return error; -} - -/** - * fsl_mc_bus_remove - callback invoked when the root MC bus is being - * removed - */ -static int fsl_mc_bus_remove(struct platform_device *pdev) -{ - struct fsl_mc *mc = platform_get_drvdata(pdev); - - if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))) - return -EINVAL; - - fsl_mc_device_remove(mc->root_mc_bus_dev); - - fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io); - mc->root_mc_bus_dev->mc_io = NULL; - - dev_info(&pdev->dev, "Root MC bus device removed"); - return 0; -} - -static const struct of_device_id fsl_mc_bus_match_table[] = { - {.compatible = "fsl,qoriq-mc",}, - {}, -}; - -MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table); - -static struct platform_driver fsl_mc_bus_driver = { - .driver = { - .name = "fsl_mc_bus", - .pm = NULL, - .of_match_table = fsl_mc_bus_match_table, - }, - .probe = fsl_mc_bus_probe, - .remove = fsl_mc_bus_remove, -}; - -static int __init fsl_mc_bus_driver_init(void) -{ - int error; - - mc_dev_cache = kmem_cache_create("fsl_mc_device", - sizeof(struct fsl_mc_device), 0, 0, - NULL); - if (!mc_dev_cache) { - pr_err("Could not create fsl_mc_device cache\n"); - return -ENOMEM; - } - - error = bus_register(&fsl_mc_bus_type); - if (error < 0) { - pr_err("fsl-mc bus type registration failed: %d\n", error); - goto error_cleanup_cache; - } - - pr_info("fsl-mc bus type registered\n"); - - error = platform_driver_register(&fsl_mc_bus_driver); - if (error < 0) { - pr_err("platform_driver_register() failed: %d\n", error); - goto error_cleanup_bus; - } - - error = dprc_driver_init(); - if (error < 0) - goto error_cleanup_driver; - - error = fsl_mc_allocator_driver_init(); - if (error < 0) - goto error_cleanup_dprc_driver; - - error = its_fsl_mc_msi_init(); - if (error < 0) - goto error_cleanup_mc_allocator; - - return 0; - -error_cleanup_mc_allocator: - fsl_mc_allocator_driver_exit(); - -error_cleanup_dprc_driver: - dprc_driver_exit(); - -error_cleanup_driver: - platform_driver_unregister(&fsl_mc_bus_driver); - -error_cleanup_bus: - bus_unregister(&fsl_mc_bus_type); - -error_cleanup_cache: - kmem_cache_destroy(mc_dev_cache); - return error; -} -postcore_initcall(fsl_mc_bus_driver_init); diff --git a/drivers/staging/fsl-mc/bus/mc-msi.c b/drivers/staging/fsl-mc/bus/mc-msi.c deleted file mode 100644 index 6e39a983f8e3..000000000000 --- a/drivers/staging/fsl-mc/bus/mc-msi.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Freescale Management Complex (MC) bus driver MSI support - * - * Copyright (C) 2015 Freescale Semiconductor, Inc. - * Author: German Rivera - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ - -#include "../include/mc-bus.h" -#include -#include -#include -#include -#include -#include -#include -#include "../include/mc-sys.h" -#include "dprc-cmd.h" - -/* - * Generate a unique ID identifying the interrupt (only used within the MSI - * irqdomain. Combine the icid with the interrupt index. - */ -static irq_hw_number_t fsl_mc_domain_calc_hwirq(struct fsl_mc_device *dev, - struct msi_desc *desc) -{ - /* - * Make the base hwirq value for ICID*10000 so it is readable - * as a decimal value in /proc/interrupts. - */ - return (irq_hw_number_t)(desc->fsl_mc.msi_index + (dev->icid * 10000)); -} - -static void fsl_mc_msi_set_desc(msi_alloc_info_t *arg, - struct msi_desc *desc) -{ - arg->desc = desc; - arg->hwirq = fsl_mc_domain_calc_hwirq(to_fsl_mc_device(desc->dev), - desc); -} - -static void fsl_mc_msi_update_dom_ops(struct msi_domain_info *info) -{ - struct msi_domain_ops *ops = info->ops; - - if (WARN_ON(!ops)) - return; - - /* - * set_desc should not be set by the caller - */ - if (ops->set_desc == NULL) - ops->set_desc = fsl_mc_msi_set_desc; -} - -static void __fsl_mc_msi_write_msg(struct fsl_mc_device *mc_bus_dev, - struct fsl_mc_device_irq *mc_dev_irq) -{ - int error; - struct fsl_mc_device *owner_mc_dev = mc_dev_irq->mc_dev; - struct msi_desc *msi_desc = mc_dev_irq->msi_desc; - struct dprc_irq_cfg irq_cfg; - - /* - * msi_desc->msg.address is 0x0 when this function is invoked in - * the free_irq() code path. In this case, for the MC, we don't - * really need to "unprogram" the MSI, so we just return. - */ - if (msi_desc->msg.address_lo == 0x0 && msi_desc->msg.address_hi == 0x0) - return; - - if (WARN_ON(!owner_mc_dev)) - return; - - irq_cfg.paddr = ((u64)msi_desc->msg.address_hi << 32) | - msi_desc->msg.address_lo; - irq_cfg.val = msi_desc->msg.data; - irq_cfg.irq_num = msi_desc->irq; - - if (owner_mc_dev == mc_bus_dev) { - /* - * IRQ is for the mc_bus_dev's DPRC itself - */ - error = dprc_set_irq(mc_bus_dev->mc_io, - MC_CMD_FLAG_INTR_DIS | MC_CMD_FLAG_PRI, - mc_bus_dev->mc_handle, - mc_dev_irq->dev_irq_index, - &irq_cfg); - if (error < 0) { - dev_err(&owner_mc_dev->dev, - "dprc_set_irq() failed: %d\n", error); - } - } else { - /* - * IRQ is for for a child device of mc_bus_dev - */ - error = dprc_set_obj_irq(mc_bus_dev->mc_io, - MC_CMD_FLAG_INTR_DIS | MC_CMD_FLAG_PRI, - mc_bus_dev->mc_handle, - owner_mc_dev->obj_desc.type, - owner_mc_dev->obj_desc.id, - mc_dev_irq->dev_irq_index, - &irq_cfg); - if (error < 0) { - dev_err(&owner_mc_dev->dev, - "dprc_obj_set_irq() failed: %d\n", error); - } - } -} - -/* - * NOTE: This function is invoked with interrupts disabled - */ -static void fsl_mc_msi_write_msg(struct irq_data *irq_data, - struct msi_msg *msg) -{ - struct msi_desc *msi_desc = irq_data_get_msi_desc(irq_data); - struct fsl_mc_device *mc_bus_dev = to_fsl_mc_device(msi_desc->dev); - struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); - struct fsl_mc_device_irq *mc_dev_irq = - &mc_bus->irq_resources[msi_desc->fsl_mc.msi_index]; - - WARN_ON(mc_dev_irq->msi_desc != msi_desc); - msi_desc->msg = *msg; - - /* - * Program the MSI (paddr, value) pair in the device: - */ - __fsl_mc_msi_write_msg(mc_bus_dev, mc_dev_irq); -} - -static void fsl_mc_msi_update_chip_ops(struct msi_domain_info *info) -{ - struct irq_chip *chip = info->chip; - - if (WARN_ON((!chip))) - return; - - /* - * irq_write_msi_msg should not be set by the caller - */ - if (chip->irq_write_msi_msg == NULL) - chip->irq_write_msi_msg = fsl_mc_msi_write_msg; -} - -/** - * fsl_mc_msi_create_irq_domain - Create a fsl-mc MSI interrupt domain - * @np: Optional device-tree node of the interrupt controller - * @info: MSI domain info - * @parent: Parent irq domain - * - * Updates the domain and chip ops and creates a fsl-mc MSI - * interrupt domain. - * - * Returns: - * A domain pointer or NULL in case of failure. - */ -struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, - struct msi_domain_info *info, - struct irq_domain *parent) -{ - struct irq_domain *domain; - - if (info->flags & MSI_FLAG_USE_DEF_DOM_OPS) - fsl_mc_msi_update_dom_ops(info); - if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) - fsl_mc_msi_update_chip_ops(info); - - domain = msi_create_irq_domain(fwnode, info, parent); - if (domain) - domain->bus_token = DOMAIN_BUS_FSL_MC_MSI; - - return domain; -} - -int fsl_mc_find_msi_domain(struct device *mc_platform_dev, - struct irq_domain **mc_msi_domain) -{ - struct irq_domain *msi_domain; - struct device_node *mc_of_node = mc_platform_dev->of_node; - - msi_domain = of_msi_get_domain(mc_platform_dev, mc_of_node, - DOMAIN_BUS_FSL_MC_MSI); - if (!msi_domain) { - pr_err("Unable to find fsl-mc MSI domain for %s\n", - mc_of_node->full_name); - - return -ENOENT; - } - - *mc_msi_domain = msi_domain; - return 0; -} - -static void fsl_mc_msi_free_descs(struct device *dev) -{ - struct msi_desc *desc, *tmp; - - list_for_each_entry_safe(desc, tmp, dev_to_msi_list(dev), list) { - list_del(&desc->list); - free_msi_entry(desc); - } -} - -static int fsl_mc_msi_alloc_descs(struct device *dev, unsigned int irq_count) - -{ - unsigned int i; - int error; - struct msi_desc *msi_desc; - - for (i = 0; i < irq_count; i++) { - msi_desc = alloc_msi_entry(dev); - if (!msi_desc) { - dev_err(dev, "Failed to allocate msi entry\n"); - error = -ENOMEM; - goto cleanup_msi_descs; - } - - msi_desc->fsl_mc.msi_index = i; - msi_desc->nvec_used = 1; - INIT_LIST_HEAD(&msi_desc->list); - list_add_tail(&msi_desc->list, dev_to_msi_list(dev)); - } - - return 0; - -cleanup_msi_descs: - fsl_mc_msi_free_descs(dev); - return error; -} - -int fsl_mc_msi_domain_alloc_irqs(struct device *dev, - unsigned int irq_count) -{ - struct irq_domain *msi_domain; - int error; - - if (WARN_ON(!list_empty(dev_to_msi_list(dev)))) - return -EINVAL; - - error = fsl_mc_msi_alloc_descs(dev, irq_count); - if (error < 0) - return error; - - msi_domain = dev_get_msi_domain(dev); - if (WARN_ON(!msi_domain)) { - error = -EINVAL; - goto cleanup_msi_descs; - } - - /* - * NOTE: Calling this function will trigger the invocation of the - * its_fsl_mc_msi_prepare() callback - */ - error = msi_domain_alloc_irqs(msi_domain, dev, irq_count); - - if (error) { - dev_err(dev, "Failed to allocate IRQs\n"); - goto cleanup_msi_descs; - } - - return 0; - -cleanup_msi_descs: - fsl_mc_msi_free_descs(dev); - return error; -} - -void fsl_mc_msi_domain_free_irqs(struct device *dev) -{ - struct irq_domain *msi_domain; - - msi_domain = dev_get_msi_domain(dev); - if (WARN_ON(!msi_domain)) - return; - - msi_domain_free_irqs(msi_domain, dev); - - if (WARN_ON(list_empty(dev_to_msi_list(dev)))) - return; - - fsl_mc_msi_free_descs(dev); -} -- cgit v1.2.3-59-g8ed1b From e267dddd212e62190bcc42441ed189dfa323724c Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:17 -0500 Subject: staging: fsl-mc: move allocator private definitions out of mc-bus.h move definitions private to the allocator out of mc-bus.h and into allocator.c Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 5 +++++ drivers/staging/fsl-mc/include/mc-bus.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index 3ebaecbc1ec0..655056480414 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -17,6 +17,11 @@ #include "dpmcp.h" #include +#define FSL_MC_IS_ALLOCATABLE(_obj_type) \ + (strcmp(_obj_type, "dpbp") == 0 || \ + strcmp(_obj_type, "dpmcp") == 0 || \ + strcmp(_obj_type, "dpcon") == 0) + /** * fsl_mc_resource_pool_add_device - add allocatable device to a resource * pool of a given MC bus diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 7f847e6734f3..f192aa8f07b9 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -21,11 +21,6 @@ (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ (_mc_dev)->obj_desc.id == (_obj_desc)->id) -#define FSL_MC_IS_ALLOCATABLE(_obj_type) \ - (strcmp(_obj_type, "dpbp") == 0 || \ - strcmp(_obj_type, "dpmcp") == 0 || \ - strcmp(_obj_type, "dpcon") == 0) - struct irq_domain; struct msi_domain_info; -- cgit v1.2.3-59-g8ed1b From 3640695569016dd9a1734df2fe3692d49cffb7ba Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:24 -0500 Subject: staging: fsl-mc: move resource pool init/cleanup into allocator The resource pool init/cleanup functions logically belong in the allocator. Move them to the allocator and rename to reflect the move out of the dprc-driver. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-driver.c | 55 ++------------------------- drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 49 ++++++++++++++++++++++++ drivers/staging/fsl-mc/include/mc-bus.h | 4 ++ 3 files changed, 56 insertions(+), 52 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 83e72b3ed4c1..89d53daa3a32 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -190,55 +190,6 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev, } } -static void dprc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev) -{ - int pool_type; - struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); - - for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) { - struct fsl_mc_resource_pool *res_pool = - &mc_bus->resource_pools[pool_type]; - - res_pool->type = pool_type; - res_pool->max_count = 0; - res_pool->free_count = 0; - res_pool->mc_bus = mc_bus; - INIT_LIST_HEAD(&res_pool->free_list); - mutex_init(&res_pool->mutex); - } -} - -static void dprc_cleanup_resource_pool(struct fsl_mc_device *mc_bus_dev, - enum fsl_mc_pool_type pool_type) -{ - struct fsl_mc_resource *resource; - struct fsl_mc_resource *next; - struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); - struct fsl_mc_resource_pool *res_pool = - &mc_bus->resource_pools[pool_type]; - int free_count = 0; - - WARN_ON(res_pool->type != pool_type); - WARN_ON(res_pool->free_count != res_pool->max_count); - - list_for_each_entry_safe(resource, next, &res_pool->free_list, node) { - free_count++; - WARN_ON(resource->type != res_pool->type); - WARN_ON(resource->parent_pool != res_pool); - devm_kfree(&mc_bus_dev->dev, resource); - } - - WARN_ON(free_count != res_pool->free_count); -} - -static void dprc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev) -{ - int pool_type; - - for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) - dprc_cleanup_resource_pool(mc_bus_dev, pool_type); -} - /** * dprc_scan_objects - Discover objects in a DPRC * @@ -363,7 +314,7 @@ int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) unsigned int irq_count; struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); - dprc_init_all_resource_pools(mc_bus_dev); + fsl_mc_init_all_resource_pools(mc_bus_dev); /* * Discover objects in the DPRC: @@ -390,7 +341,7 @@ int dprc_scan_container(struct fsl_mc_device *mc_bus_dev) return 0; error: - dprc_cleanup_all_resource_pools(mc_bus_dev); + fsl_mc_cleanup_all_resource_pools(mc_bus_dev); return error; } EXPORT_SYMBOL_GPL(dprc_scan_container); @@ -802,7 +753,7 @@ static int dprc_remove(struct fsl_mc_device *mc_dev) dev_set_msi_domain(&mc_dev->dev, NULL); } - dprc_cleanup_all_resource_pools(mc_dev); + fsl_mc_cleanup_all_resource_pools(mc_dev); error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); if (error < 0) diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index 655056480414..9695f4425a19 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -668,6 +668,55 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev) } EXPORT_SYMBOL_GPL(fsl_mc_free_irqs); +void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev) +{ + int pool_type; + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); + + for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) { + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[pool_type]; + + res_pool->type = pool_type; + res_pool->max_count = 0; + res_pool->free_count = 0; + res_pool->mc_bus = mc_bus; + INIT_LIST_HEAD(&res_pool->free_list); + mutex_init(&res_pool->mutex); + } +} + +static void fsl_mc_cleanup_resource_pool(struct fsl_mc_device *mc_bus_dev, + enum fsl_mc_pool_type pool_type) +{ + struct fsl_mc_resource *resource; + struct fsl_mc_resource *next; + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev); + struct fsl_mc_resource_pool *res_pool = + &mc_bus->resource_pools[pool_type]; + int free_count = 0; + + WARN_ON(res_pool->type != pool_type); + WARN_ON(res_pool->free_count != res_pool->max_count); + + list_for_each_entry_safe(resource, next, &res_pool->free_list, node) { + free_count++; + WARN_ON(resource->type != res_pool->type); + WARN_ON(resource->parent_pool != res_pool); + devm_kfree(&mc_bus_dev->dev, resource); + } + + WARN_ON(free_count != res_pool->free_count); +} + +void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev) +{ + int pool_type; + + for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++) + fsl_mc_cleanup_resource_pool(mc_bus_dev, pool_type); +} + /** * fsl_mc_allocator_probe - callback invoked when an allocatable device is * being added to the system diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index f192aa8f07b9..2098b3c74317 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -150,4 +150,8 @@ int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); +void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev); + +void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev); + #endif /* _FSL_MC_MCBUS_H_ */ -- cgit v1.2.3-59-g8ed1b From 243444fb8cc0d066be81aee379f450a111f05dbd Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:30 -0500 Subject: staging: fsl-mc: create private include for fsl-mc bus components The mc-bus.h header file is intended to be public for system related drivers that may need to make fsl-mc bus specific calls-- gic its, smmu, vfio. But, currently it contains definitions private/internal to the fsl-mc bus itself. Split those definitions out into a new fsl-mc bus private header. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-driver.c | 1 + drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 1 + drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 1 + drivers/staging/fsl-mc/bus/fsl-mc-private.h | 44 +++++++++++++++++++++++++++ drivers/staging/fsl-mc/include/mc-bus.h | 23 -------------- 5 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-private.h (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 89d53daa3a32..576244bc18b8 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -16,6 +16,7 @@ #include #include #include "dprc-cmd.h" +#include "fsl-mc-private.h" struct dprc_child_objs { int child_count; diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index 9695f4425a19..e86537526637 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -15,6 +15,7 @@ #include "../include/dpcon-cmd.h" #include "dpmcp-cmd.h" #include "dpmcp.h" +#include "fsl-mc-private.h" #include #define FSL_MC_IS_ALLOCATABLE(_obj_type) \ diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 975d30b8775e..180ff07c0bea 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -20,6 +20,7 @@ #include #include "../include/dpmng.h" #include "../include/mc-sys.h" +#include "fsl-mc-private.h" #include "dprc-cmd.h" static struct kmem_cache *mc_dev_cache; diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-private.h b/drivers/staging/fsl-mc/bus/fsl-mc-private.h new file mode 100644 index 000000000000..14799347bfc3 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h @@ -0,0 +1,44 @@ +/* + * Freescale Management Complex (MC) bus private declarations + * + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#ifndef _FSL_MC_PRIVATE_H_ +#define _FSL_MC_PRIVATE_H_ + +int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, + struct fsl_mc_io *mc_io, + struct device *parent_dev, + struct fsl_mc_device **new_mc_dev); + +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); + +int __init dprc_driver_init(void); + +void dprc_driver_exit(void); + +int __init fsl_mc_allocator_driver_init(void); + +void fsl_mc_allocator_driver_exit(void); + +int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, + enum fsl_mc_pool_type pool_type, + struct fsl_mc_resource + **new_resource); + +void fsl_mc_resource_free(struct fsl_mc_resource *resource); + +int fsl_mc_msi_domain_alloc_irqs(struct device *dev, + unsigned int irq_count); + +void fsl_mc_msi_domain_free_irqs(struct device *dev); + +int __init its_fsl_mc_msi_init(void); + +void its_fsl_mc_msi_cleanup(void); + +#endif /* _FSL_MC_PRIVATE_H_ */ diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 2098b3c74317..8a32e557cd1d 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -102,13 +102,6 @@ struct fsl_mc_bus { #define to_fsl_mc_bus(_mc_dev) \ container_of(_mc_dev, struct fsl_mc_bus, mc_dev) -int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc, - struct fsl_mc_io *mc_io, - struct device *parent_dev, - struct fsl_mc_device **new_mc_dev); - -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); - int dprc_scan_container(struct fsl_mc_device *mc_bus_dev); int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, @@ -122,13 +115,6 @@ int __init fsl_mc_allocator_driver_init(void); void fsl_mc_allocator_driver_exit(void); -int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, - enum fsl_mc_pool_type pool_type, - struct fsl_mc_resource - **new_resource); - -void fsl_mc_resource_free(struct fsl_mc_resource *resource); - struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, struct msi_domain_info *info, struct irq_domain *parent); @@ -136,15 +122,6 @@ struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode, int fsl_mc_find_msi_domain(struct device *mc_platform_dev, struct irq_domain **mc_msi_domain); -int fsl_mc_msi_domain_alloc_irqs(struct device *dev, - unsigned int irq_count); - -void fsl_mc_msi_domain_free_irqs(struct device *dev); - -int __init its_fsl_mc_msi_init(void); - -void its_fsl_mc_msi_cleanup(void); - int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, unsigned int irq_count); -- cgit v1.2.3-59-g8ed1b From 2b0011d2bf5924f1509903f15bcb3359521c42bb Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:35 -0500 Subject: staging: fsl-mc: move dprc-driver private definitions out of mc-bus.h Move definitions that are private to dprc-driver.c out of the public mc-bus.h header. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-driver.c | 6 ++++++ drivers/staging/fsl-mc/include/mc-bus.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 576244bc18b8..5e347203161a 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -18,6 +18,12 @@ #include "dprc-cmd.h" #include "fsl-mc-private.h" +#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" + +#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \ + (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ + (_mc_dev)->obj_desc.id == (_obj_desc)->id) + struct dprc_child_objs { int child_count; struct dprc_obj_desc *child_array; diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 8a32e557cd1d..3f8050655047 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -15,12 +15,6 @@ #include #include -#define FSL_MC_DPRC_DRIVER_NAME "fsl_mc_dprc" - -#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \ - (strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \ - (_mc_dev)->obj_desc.id == (_obj_desc)->id) - struct irq_domain; struct msi_domain_info; -- cgit v1.2.3-59-g8ed1b From e730d86d7462c304f62596f8dd619f2ac9458f6a Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:40 -0500 Subject: staging: fsl-mc: move bus private definitions into fsl-mc-bus.c Move definitions that are private to fsl-mc-bus.c out of the public mc-bus.h and mc.h headers. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 33 +++++++++++++++++++++++++++++++++ drivers/staging/fsl-mc/include/mc-bus.h | 28 ---------------------------- drivers/staging/fsl-mc/include/mc.h | 5 ----- 3 files changed, 33 insertions(+), 33 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 180ff07c0bea..08363f8bd87f 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -25,6 +25,39 @@ static struct kmem_cache *mc_dev_cache; +/** + * Default DMA mask for devices on a fsl-mc bus + */ +#define FSL_MC_DEFAULT_DMA_MASK (~0ULL) + +/** + * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device + * @root_mc_bus_dev: MC object device representing the root DPRC + * @num_translation_ranges: number of entries in addr_translation_ranges + * @translation_ranges: array of bus to system address translation ranges + */ +struct fsl_mc { + struct fsl_mc_device *root_mc_bus_dev; + u8 num_translation_ranges; + struct fsl_mc_addr_translation_range *translation_ranges; +}; + +/** + * struct fsl_mc_addr_translation_range - bus to system address translation + * range + * @mc_region_type: Type of MC region for the range being translated + * @start_mc_offset: Start MC offset of the range being translated + * @end_mc_offset: MC offset of the first byte after the range (last MC + * offset of the range is end_mc_offset - 1) + * @start_phys_addr: system physical address corresponding to start_mc_addr + */ +struct fsl_mc_addr_translation_range { + enum dprc_region_type mc_region_type; + u64 start_mc_offset; + u64 end_mc_offset; + phys_addr_t start_phys_addr; +}; + /** * fsl_mc_bus_match - device to driver matching callback * @dev: the MC object device structure to match against diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 3f8050655047..9ea023b62e1d 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -28,34 +28,6 @@ struct device_node; struct irq_domain; struct msi_domain_info; -/** - * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device - * @root_mc_bus_dev: MC object device representing the root DPRC - * @num_translation_ranges: number of entries in addr_translation_ranges - * @translation_ranges: array of bus to system address translation ranges - */ -struct fsl_mc { - struct fsl_mc_device *root_mc_bus_dev; - u8 num_translation_ranges; - struct fsl_mc_addr_translation_range *translation_ranges; -}; - -/** - * struct fsl_mc_addr_translation_range - bus to system address translation - * range - * @mc_region_type: Type of MC region for the range being translated - * @start_mc_offset: Start MC offset of the range being translated - * @end_mc_offset: MC offset of the first byte after the range (last MC - * offset of the range is end_mc_offset - 1) - * @start_phys_addr: system physical address corresponding to start_mc_addr - */ -struct fsl_mc_addr_translation_range { - enum dprc_region_type mc_region_type; - u64 start_mc_offset; - u64 end_mc_offset; - phys_addr_t start_phys_addr; -}; - /** * struct fsl_mc_resource_pool - Pool of MC resources of a given * type diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index 2d6753532c96..ab439fae2311 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -111,11 +111,6 @@ struct fsl_mc_device_irq { */ #define FSL_MC_IS_DPRC 0x0001 -/** - * Default DMA mask for devices on a fsl-mc bus - */ -#define FSL_MC_DEFAULT_DMA_MASK (~0ULL) - /** * struct fsl_mc_device - MC object device object * @dev: Linux driver model device object -- cgit v1.2.3-59-g8ed1b From 27365d85cfb6cdf8e584764bfdca747d3087b21d Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:46 -0500 Subject: staging: fsl-mc: make fsl_mc_get_root_dprc public fsl_mc_get_root_dprc is needed by other components (e.g. vfio) to find the root dprc Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 5 +++-- drivers/staging/fsl-mc/include/mc.h | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 08363f8bd87f..fda6a98ba3c5 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -265,8 +265,8 @@ EXPORT_SYMBOL_GPL(fsl_mc_bus_exists); /** * fsl_mc_get_root_dprc - function to traverse to the root dprc */ -static void fsl_mc_get_root_dprc(struct device *dev, - struct device **root_dprc_dev) +void fsl_mc_get_root_dprc(struct device *dev, + struct device **root_dprc_dev) { if (WARN_ON(!dev)) { *root_dprc_dev = NULL; @@ -278,6 +278,7 @@ static void fsl_mc_get_root_dprc(struct device *dev, *root_dprc_dev = (*root_dprc_dev)->parent; } } +EXPORT_SYMBOL_GPL(fsl_mc_get_root_dprc); static int get_dprc_attr(struct fsl_mc_io *mc_io, int container_id, struct dprc_attributes *attr) diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index ab439fae2311..a71342d2c7b2 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -191,6 +191,9 @@ void fsl_mc_driver_unregister(struct fsl_mc_driver *driver); bool fsl_mc_bus_exists(void); +void fsl_mc_get_root_dprc(struct device *dev, + struct device **root_dprc_dev); + int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, u16 mc_io_flags, struct fsl_mc_io **new_mc_io); -- cgit v1.2.3-59-g8ed1b From c7743b423300abea99fafb7d7d897e558bf160cc Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:51 -0500 Subject: staging: fsl-mc: remove unneeded forward declarations Remove unneeded and duplicated forward declarations. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/include/mc-bus.h | 4 ---- drivers/staging/fsl-mc/include/mc.h | 1 - 2 files changed, 5 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 9ea023b62e1d..7eba588ad840 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -24,10 +24,6 @@ struct msi_domain_info; */ #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 -struct device_node; -struct irq_domain; -struct msi_domain_info; - /** * struct fsl_mc_resource_pool - Pool of MC resources of a given * type diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index a71342d2c7b2..b093abad374a 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -21,7 +21,6 @@ struct fsl_mc_device; struct fsl_mc_io; -struct fsl_mc_bus; /** * struct fsl_mc_driver - MC object device driver object -- cgit v1.2.3-59-g8ed1b From e744e45ab92ede6932b55298e9657f878c73fbb4 Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:13:59 -0500 Subject: staging: fsl-mc: move bus definitions from mc.h to mc-bus.h move public bus-related definitions to the proper mc-bus.h header. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/include/mc-bus.h | 16 ++++++++++++++++ drivers/staging/fsl-mc/include/mc.h | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 7eba588ad840..2cdb5382696c 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -24,6 +24,13 @@ struct msi_domain_info; */ #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 +#ifdef CONFIG_FSL_MC_BUS +#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type) +#else +/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */ +#define dev_is_fsl_mc(_dev) (0) +#endif + /** * struct fsl_mc_resource_pool - Pool of MC resources of a given * type @@ -93,4 +100,13 @@ void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev); void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev); +bool fsl_mc_bus_exists(void); + +void fsl_mc_get_root_dprc(struct device *dev, + struct device **root_dprc_dev); + +bool fsl_mc_is_root_dprc(struct device *dev); + +extern struct bus_type fsl_mc_bus_type; + #endif /* _FSL_MC_MCBUS_H_ */ diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index b093abad374a..789e6a8c79ef 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -160,13 +160,6 @@ struct fsl_mc_device { #define to_fsl_mc_device(_dev) \ container_of(_dev, struct fsl_mc_device, dev) -#ifdef CONFIG_FSL_MC_BUS -#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type) -#else -/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */ -#define dev_is_fsl_mc(_dev) (0) -#endif - /* * module_fsl_mc_driver() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of @@ -188,11 +181,6 @@ int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver, void fsl_mc_driver_unregister(struct fsl_mc_driver *driver); -bool fsl_mc_bus_exists(void); - -void fsl_mc_get_root_dprc(struct device *dev, - struct device **root_dprc_dev); - int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, u16 mc_io_flags, struct fsl_mc_io **new_mc_io); @@ -211,8 +199,4 @@ int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev); void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev); -bool fsl_mc_is_root_dprc(struct device *dev); - -extern struct bus_type fsl_mc_bus_type; - #endif /* _FSL_MC_H_ */ -- cgit v1.2.3-59-g8ed1b From 693c5a9d432d8f87ae494096189b209f75532d9a Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:14:08 -0500 Subject: staging: fsl-mc: remove unneeded includes Over time we've accumulated some includes that are no longer needed. Remove them. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 2 -- drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 -- drivers/staging/fsl-mc/include/mc-bus.h | 1 - drivers/staging/fsl-mc/include/mc.h | 1 - 4 files changed, 6 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c index 6e39a983f8e3..7c20f60a071a 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c @@ -17,8 +17,6 @@ #include #include #include -#include "../include/mc-sys.h" -#include "dprc-cmd.h" /* * Generate a unique ID identifying the interrupt (only used within the MSI diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c index aac437963446..25863284b592 100644 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c @@ -17,8 +17,6 @@ #include #include #include -#include "../include/mc-sys.h" -#include "dprc-cmd.h" static struct irq_chip its_msi_irq_chip = { .name = "fsl-mc-bus-msi", diff --git a/drivers/staging/fsl-mc/include/mc-bus.h b/drivers/staging/fsl-mc/include/mc-bus.h index 2cdb5382696c..170684a57ca2 100644 --- a/drivers/staging/fsl-mc/include/mc-bus.h +++ b/drivers/staging/fsl-mc/include/mc-bus.h @@ -13,7 +13,6 @@ #include "../include/mc.h" #include -#include struct irq_domain; struct msi_domain_info; diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h index 789e6a8c79ef..f6e720e84460 100644 --- a/drivers/staging/fsl-mc/include/mc.h +++ b/drivers/staging/fsl-mc/include/mc.h @@ -13,7 +13,6 @@ #include #include -#include #include #include "../include/dprc.h" -- cgit v1.2.3-59-g8ed1b From 7f59f4c71d727bd34dd604f368530cc36f4bfc93 Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:14:14 -0500 Subject: staging: fsl-mc: split mc-io definitions into a separate file An mc-io is a software abstraction of a dpmcp object (an MC portal). Routines to create/initialize/reset this portal abstraction were split between the allocator and mc-sys.c (MC command interface). Move mc-io/portal related definitions into one source file. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/Makefile | 1 + drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 140 ------------ drivers/staging/fsl-mc/bus/fsl-mc-private.h | 8 + drivers/staging/fsl-mc/bus/mc-io.c | 318 ++++++++++++++++++++++++++ drivers/staging/fsl-mc/bus/mc-sys.c | 147 ------------ drivers/staging/fsl-mc/include/mc-sys.h | 13 -- 6 files changed, 327 insertions(+), 300 deletions(-) create mode 100644 drivers/staging/fsl-mc/bus/mc-io.c (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/Makefile b/drivers/staging/fsl-mc/bus/Makefile index 5fb4c14b084d..38716fd5cb58 100644 --- a/drivers/staging/fsl-mc/bus/Makefile +++ b/drivers/staging/fsl-mc/bus/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_FSL_MC_BUS) += mc-bus-driver.o mc-bus-driver-objs := fsl-mc-bus.o \ mc-sys.o \ + mc-io.o \ dprc.o \ dpmng.o \ dprc-driver.o \ diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index e86537526637..edcb5cc9a95b 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -13,8 +13,6 @@ #include #include "../include/dpbp-cmd.h" #include "../include/dpcon-cmd.h" -#include "dpmcp-cmd.h" -#include "dpmcp.h" #include "fsl-mc-private.h" #include @@ -257,144 +255,6 @@ out_unlock: } EXPORT_SYMBOL_GPL(fsl_mc_resource_free); -/** - * fsl_mc_portal_allocate - Allocates an MC portal - * - * @mc_dev: MC device for which the MC portal is to be allocated - * @mc_io_flags: Flags for the fsl_mc_io object that wraps the allocated - * MC portal. - * @new_mc_io: Pointer to area where the pointer to the fsl_mc_io object - * that wraps the allocated MC portal is to be returned - * - * This function allocates an MC portal from the device's parent DPRC, - * from the corresponding MC bus' pool of MC portals and wraps - * it in a new fsl_mc_io object. If 'mc_dev' is a DPRC itself, the - * portal is allocated from its own MC bus. - */ -int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, - u16 mc_io_flags, - struct fsl_mc_io **new_mc_io) -{ - struct fsl_mc_device *mc_bus_dev; - struct fsl_mc_bus *mc_bus; - phys_addr_t mc_portal_phys_addr; - size_t mc_portal_size; - struct fsl_mc_device *dpmcp_dev; - int error = -EINVAL; - struct fsl_mc_resource *resource = NULL; - struct fsl_mc_io *mc_io = NULL; - - if (mc_dev->flags & FSL_MC_IS_DPRC) { - mc_bus_dev = mc_dev; - } else { - if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) - return error; - - mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); - } - - mc_bus = to_fsl_mc_bus(mc_bus_dev); - *new_mc_io = NULL; - error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_DPMCP, &resource); - if (error < 0) - return error; - - error = -EINVAL; - dpmcp_dev = resource->data; - if (WARN_ON(!dpmcp_dev)) - goto error_cleanup_resource; - - if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR || - (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR && - dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) { - dev_err(&dpmcp_dev->dev, - "ERROR: Version %d.%d of DPMCP not supported.\n", - dpmcp_dev->obj_desc.ver_major, - dpmcp_dev->obj_desc.ver_minor); - error = -ENOTSUPP; - goto error_cleanup_resource; - } - - if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0)) - goto error_cleanup_resource; - - mc_portal_phys_addr = dpmcp_dev->regions[0].start; - mc_portal_size = dpmcp_dev->regions[0].end - - dpmcp_dev->regions[0].start + 1; - - if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size)) - goto error_cleanup_resource; - - error = fsl_create_mc_io(&mc_bus_dev->dev, - mc_portal_phys_addr, - mc_portal_size, dpmcp_dev, - mc_io_flags, &mc_io); - if (error < 0) - goto error_cleanup_resource; - - *new_mc_io = mc_io; - return 0; - -error_cleanup_resource: - fsl_mc_resource_free(resource); - return error; -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate); - -/** - * fsl_mc_portal_free - Returns an MC portal to the pool of free MC portals - * of a given MC bus - * - * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free - */ -void fsl_mc_portal_free(struct fsl_mc_io *mc_io) -{ - struct fsl_mc_device *dpmcp_dev; - struct fsl_mc_resource *resource; - - /* - * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed - * to have a DPMCP object associated with. - */ - dpmcp_dev = mc_io->dpmcp_dev; - if (WARN_ON(!dpmcp_dev)) - return; - - resource = dpmcp_dev->resource; - if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP)) - return; - - if (WARN_ON(resource->data != dpmcp_dev)) - return; - - fsl_destroy_mc_io(mc_io); - fsl_mc_resource_free(resource); -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_free); - -/** - * fsl_mc_portal_reset - Resets the dpmcp object for a given fsl_mc_io object - * - * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free - */ -int fsl_mc_portal_reset(struct fsl_mc_io *mc_io) -{ - int error; - struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; - - if (WARN_ON(!dpmcp_dev)) - return -EINVAL; - - error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle); - if (error < 0) { - dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error); - return error; - } - - return 0; -} -EXPORT_SYMBOL_GPL(fsl_mc_portal_reset); - /** * fsl_mc_object_allocate - Allocates a MC object device of the given * pool type from a given MC bus diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-private.h b/drivers/staging/fsl-mc/bus/fsl-mc-private.h index 14799347bfc3..d459c2673f39 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-private.h +++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h @@ -41,4 +41,12 @@ int __init its_fsl_mc_msi_init(void); void its_fsl_mc_msi_cleanup(void); +int __must_check fsl_create_mc_io(struct device *dev, + phys_addr_t mc_portal_phys_addr, + u32 mc_portal_size, + struct fsl_mc_device *dpmcp_dev, + u32 flags, struct fsl_mc_io **new_mc_io); + +void fsl_destroy_mc_io(struct fsl_mc_io *mc_io); + #endif /* _FSL_MC_PRIVATE_H_ */ diff --git a/drivers/staging/fsl-mc/bus/mc-io.c b/drivers/staging/fsl-mc/bus/mc-io.c new file mode 100644 index 000000000000..c5edfc8db527 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/mc-io.c @@ -0,0 +1,318 @@ +/* Copyright 2013-2016 Freescale Semiconductor Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "../include/mc-bus.h" +#include "../include/mc-sys.h" +#include "fsl-mc-private.h" +#include "dpmcp.h" +#include "dpmcp-cmd.h" + +static int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io, + struct fsl_mc_device *dpmcp_dev) +{ + int error; + + if (WARN_ON(!dpmcp_dev)) + return -EINVAL; + + if (WARN_ON(mc_io->dpmcp_dev)) + return -EINVAL; + + if (WARN_ON(dpmcp_dev->mc_io)) + return -EINVAL; + + error = dpmcp_open(mc_io, + 0, + dpmcp_dev->obj_desc.id, + &dpmcp_dev->mc_handle); + if (error < 0) + return error; + + mc_io->dpmcp_dev = dpmcp_dev; + dpmcp_dev->mc_io = mc_io; + return 0; +} + +static void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io) +{ + int error; + struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; + + if (WARN_ON(!dpmcp_dev)) + return; + + if (WARN_ON(dpmcp_dev->mc_io != mc_io)) + return; + + error = dpmcp_close(mc_io, + 0, + dpmcp_dev->mc_handle); + if (error < 0) { + dev_err(&dpmcp_dev->dev, "dpmcp_close() failed: %d\n", + error); + } + + mc_io->dpmcp_dev = NULL; + dpmcp_dev->mc_io = NULL; +} + +/** + * Creates an MC I/O object + * + * @dev: device to be associated with the MC I/O object + * @mc_portal_phys_addr: physical address of the MC portal to use + * @mc_portal_size: size in bytes of the MC portal + * @dpmcp-dev: Pointer to the DPMCP object associated with this MC I/O + * object or NULL if none. + * @flags: flags for the new MC I/O object + * @new_mc_io: Area to return pointer to newly created MC I/O object + * + * Returns '0' on Success; Error code otherwise. + */ +int __must_check fsl_create_mc_io(struct device *dev, + phys_addr_t mc_portal_phys_addr, + u32 mc_portal_size, + struct fsl_mc_device *dpmcp_dev, + u32 flags, struct fsl_mc_io **new_mc_io) +{ + int error; + struct fsl_mc_io *mc_io; + void __iomem *mc_portal_virt_addr; + struct resource *res; + + mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL); + if (!mc_io) + return -ENOMEM; + + mc_io->dev = dev; + mc_io->flags = flags; + mc_io->portal_phys_addr = mc_portal_phys_addr; + mc_io->portal_size = mc_portal_size; + if (flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL) + spin_lock_init(&mc_io->spinlock); + else + mutex_init(&mc_io->mutex); + + res = devm_request_mem_region(dev, + mc_portal_phys_addr, + mc_portal_size, + "mc_portal"); + if (!res) { + dev_err(dev, + "devm_request_mem_region failed for MC portal %#llx\n", + mc_portal_phys_addr); + return -EBUSY; + } + + mc_portal_virt_addr = devm_ioremap_nocache(dev, + mc_portal_phys_addr, + mc_portal_size); + if (!mc_portal_virt_addr) { + dev_err(dev, + "devm_ioremap_nocache failed for MC portal %#llx\n", + mc_portal_phys_addr); + return -ENXIO; + } + + mc_io->portal_virt_addr = mc_portal_virt_addr; + if (dpmcp_dev) { + error = fsl_mc_io_set_dpmcp(mc_io, dpmcp_dev); + if (error < 0) + goto error_destroy_mc_io; + } + + *new_mc_io = mc_io; + return 0; + +error_destroy_mc_io: + fsl_destroy_mc_io(mc_io); + return error; +} + +/** + * Destroys an MC I/O object + * + * @mc_io: MC I/O object to destroy + */ +void fsl_destroy_mc_io(struct fsl_mc_io *mc_io) +{ + struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; + + if (dpmcp_dev) + fsl_mc_io_unset_dpmcp(mc_io); + + devm_iounmap(mc_io->dev, mc_io->portal_virt_addr); + devm_release_mem_region(mc_io->dev, + mc_io->portal_phys_addr, + mc_io->portal_size); + + mc_io->portal_virt_addr = NULL; + devm_kfree(mc_io->dev, mc_io); +} + +/** + * fsl_mc_portal_allocate - Allocates an MC portal + * + * @mc_dev: MC device for which the MC portal is to be allocated + * @mc_io_flags: Flags for the fsl_mc_io object that wraps the allocated + * MC portal. + * @new_mc_io: Pointer to area where the pointer to the fsl_mc_io object + * that wraps the allocated MC portal is to be returned + * + * This function allocates an MC portal from the device's parent DPRC, + * from the corresponding MC bus' pool of MC portals and wraps + * it in a new fsl_mc_io object. If 'mc_dev' is a DPRC itself, the + * portal is allocated from its own MC bus. + */ +int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, + u16 mc_io_flags, + struct fsl_mc_io **new_mc_io) +{ + struct fsl_mc_device *mc_bus_dev; + struct fsl_mc_bus *mc_bus; + phys_addr_t mc_portal_phys_addr; + size_t mc_portal_size; + struct fsl_mc_device *dpmcp_dev; + int error = -EINVAL; + struct fsl_mc_resource *resource = NULL; + struct fsl_mc_io *mc_io = NULL; + + if (mc_dev->flags & FSL_MC_IS_DPRC) { + mc_bus_dev = mc_dev; + } else { + if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent))) + return error; + + mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent); + } + + mc_bus = to_fsl_mc_bus(mc_bus_dev); + *new_mc_io = NULL; + error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_DPMCP, &resource); + if (error < 0) + return error; + + error = -EINVAL; + dpmcp_dev = resource->data; + if (WARN_ON(!dpmcp_dev)) + goto error_cleanup_resource; + + if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR || + (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR && + dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) { + dev_err(&dpmcp_dev->dev, + "ERROR: Version %d.%d of DPMCP not supported.\n", + dpmcp_dev->obj_desc.ver_major, + dpmcp_dev->obj_desc.ver_minor); + error = -ENOTSUPP; + goto error_cleanup_resource; + } + + if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0)) + goto error_cleanup_resource; + + mc_portal_phys_addr = dpmcp_dev->regions[0].start; + mc_portal_size = dpmcp_dev->regions[0].end - + dpmcp_dev->regions[0].start + 1; + + if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size)) + goto error_cleanup_resource; + + error = fsl_create_mc_io(&mc_bus_dev->dev, + mc_portal_phys_addr, + mc_portal_size, dpmcp_dev, + mc_io_flags, &mc_io); + if (error < 0) + goto error_cleanup_resource; + + *new_mc_io = mc_io; + return 0; + +error_cleanup_resource: + fsl_mc_resource_free(resource); + return error; +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate); + +/** + * fsl_mc_portal_free - Returns an MC portal to the pool of free MC portals + * of a given MC bus + * + * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free + */ +void fsl_mc_portal_free(struct fsl_mc_io *mc_io) +{ + struct fsl_mc_device *dpmcp_dev; + struct fsl_mc_resource *resource; + + /* + * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed + * to have a DPMCP object associated with. + */ + dpmcp_dev = mc_io->dpmcp_dev; + if (WARN_ON(!dpmcp_dev)) + return; + + resource = dpmcp_dev->resource; + if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP)) + return; + + if (WARN_ON(resource->data != dpmcp_dev)) + return; + + fsl_destroy_mc_io(mc_io); + fsl_mc_resource_free(resource); +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_free); + +/** + * fsl_mc_portal_reset - Resets the dpmcp object for a given fsl_mc_io object + * + * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free + */ +int fsl_mc_portal_reset(struct fsl_mc_io *mc_io) +{ + int error; + struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; + + if (WARN_ON(!dpmcp_dev)) + return -EINVAL; + + error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle); + if (error < 0) { + dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error); + return error; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fsl_mc_portal_reset); diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c index 0c185abe665e..23e82e4a7814 100644 --- a/drivers/staging/fsl-mc/bus/mc-sys.c +++ b/drivers/staging/fsl-mc/bus/mc-sys.c @@ -68,153 +68,6 @@ static u16 mc_cmd_hdr_read_cmdid(struct mc_command *cmd) return (cmd_id & MC_CMD_HDR_CMDID_MASK) >> MC_CMD_HDR_CMDID_SHIFT; } -/** - * Creates an MC I/O object - * - * @dev: device to be associated with the MC I/O object - * @mc_portal_phys_addr: physical address of the MC portal to use - * @mc_portal_size: size in bytes of the MC portal - * @dpmcp-dev: Pointer to the DPMCP object associated with this MC I/O - * object or NULL if none. - * @flags: flags for the new MC I/O object - * @new_mc_io: Area to return pointer to newly created MC I/O object - * - * Returns '0' on Success; Error code otherwise. - */ -int __must_check fsl_create_mc_io(struct device *dev, - phys_addr_t mc_portal_phys_addr, - u32 mc_portal_size, - struct fsl_mc_device *dpmcp_dev, - u32 flags, struct fsl_mc_io **new_mc_io) -{ - int error; - struct fsl_mc_io *mc_io; - void __iomem *mc_portal_virt_addr; - struct resource *res; - - mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL); - if (!mc_io) - return -ENOMEM; - - mc_io->dev = dev; - mc_io->flags = flags; - mc_io->portal_phys_addr = mc_portal_phys_addr; - mc_io->portal_size = mc_portal_size; - if (flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL) - spin_lock_init(&mc_io->spinlock); - else - mutex_init(&mc_io->mutex); - - res = devm_request_mem_region(dev, - mc_portal_phys_addr, - mc_portal_size, - "mc_portal"); - if (!res) { - dev_err(dev, - "devm_request_mem_region failed for MC portal %#llx\n", - mc_portal_phys_addr); - return -EBUSY; - } - - mc_portal_virt_addr = devm_ioremap_nocache(dev, - mc_portal_phys_addr, - mc_portal_size); - if (!mc_portal_virt_addr) { - dev_err(dev, - "devm_ioremap_nocache failed for MC portal %#llx\n", - mc_portal_phys_addr); - return -ENXIO; - } - - mc_io->portal_virt_addr = mc_portal_virt_addr; - if (dpmcp_dev) { - error = fsl_mc_io_set_dpmcp(mc_io, dpmcp_dev); - if (error < 0) - goto error_destroy_mc_io; - } - - *new_mc_io = mc_io; - return 0; - -error_destroy_mc_io: - fsl_destroy_mc_io(mc_io); - return error; -} -EXPORT_SYMBOL_GPL(fsl_create_mc_io); - -/** - * Destroys an MC I/O object - * - * @mc_io: MC I/O object to destroy - */ -void fsl_destroy_mc_io(struct fsl_mc_io *mc_io) -{ - struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; - - if (dpmcp_dev) - fsl_mc_io_unset_dpmcp(mc_io); - - devm_iounmap(mc_io->dev, mc_io->portal_virt_addr); - devm_release_mem_region(mc_io->dev, - mc_io->portal_phys_addr, - mc_io->portal_size); - - mc_io->portal_virt_addr = NULL; - devm_kfree(mc_io->dev, mc_io); -} -EXPORT_SYMBOL_GPL(fsl_destroy_mc_io); - -int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io, - struct fsl_mc_device *dpmcp_dev) -{ - int error; - - if (WARN_ON(!dpmcp_dev)) - return -EINVAL; - - if (WARN_ON(mc_io->dpmcp_dev)) - return -EINVAL; - - if (WARN_ON(dpmcp_dev->mc_io)) - return -EINVAL; - - error = dpmcp_open(mc_io, - 0, - dpmcp_dev->obj_desc.id, - &dpmcp_dev->mc_handle); - if (error < 0) - return error; - - mc_io->dpmcp_dev = dpmcp_dev; - dpmcp_dev->mc_io = mc_io; - return 0; -} -EXPORT_SYMBOL_GPL(fsl_mc_io_set_dpmcp); - -void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io) -{ - int error; - struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev; - - if (WARN_ON(!dpmcp_dev)) - return; - - if (WARN_ON(dpmcp_dev->mc_io != mc_io)) - return; - - error = dpmcp_close(mc_io, - 0, - dpmcp_dev->mc_handle); - if (error < 0) { - dev_err(&dpmcp_dev->dev, "dpmcp_close() failed: %d\n", - error); - } - - mc_io->dpmcp_dev = NULL; - dpmcp_dev->mc_io = NULL; -} -EXPORT_SYMBOL_GPL(fsl_mc_io_unset_dpmcp); - static int mc_status_to_error(enum mc_cmd_status status) { static const int mc_status_to_error_map[] = { diff --git a/drivers/staging/fsl-mc/include/mc-sys.h b/drivers/staging/fsl-mc/include/mc-sys.h index c5038cc77240..7a73cf6452f1 100644 --- a/drivers/staging/fsl-mc/include/mc-sys.h +++ b/drivers/staging/fsl-mc/include/mc-sys.h @@ -95,19 +95,6 @@ struct fsl_mc_io { }; }; -int __must_check fsl_create_mc_io(struct device *dev, - phys_addr_t mc_portal_phys_addr, - u32 mc_portal_size, - struct fsl_mc_device *dpmcp_dev, - u32 flags, struct fsl_mc_io **new_mc_io); - -void fsl_destroy_mc_io(struct fsl_mc_io *mc_io); - -int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io, - struct fsl_mc_device *dpmcp_dev); - -void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io); - int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd); #endif /* _FSL_MC_SYS_H */ -- cgit v1.2.3-59-g8ed1b From 5143ecf6db0a97b5d5028c0e9ac3a430b51ebb13 Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:14:18 -0500 Subject: staging: fsl-mc: explicitly include files where they are needed Instead of relying on mc-sys.h to include misc system headers, have the source files that need them explicitly do it themselves. Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 1 + drivers/staging/fsl-mc/bus/mc-io.c | 2 ++ drivers/staging/fsl-mc/bus/mc-sys.c | 2 ++ drivers/staging/fsl-mc/include/mc-sys.h | 2 -- 4 files changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index fda6a98ba3c5..9023df390957 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "../include/dpmng.h" #include "../include/mc-sys.h" #include "fsl-mc-private.h" diff --git a/drivers/staging/fsl-mc/bus/mc-io.c b/drivers/staging/fsl-mc/bus/mc-io.c index c5edfc8db527..fd032c15f9cc 100644 --- a/drivers/staging/fsl-mc/bus/mc-io.c +++ b/drivers/staging/fsl-mc/bus/mc-io.c @@ -32,6 +32,8 @@ #include "../include/mc-bus.h" #include "../include/mc-sys.h" +#include + #include "fsl-mc-private.h" #include "dpmcp.h" #include "dpmcp-cmd.h" diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c index 23e82e4a7814..461abaa0c6e1 100644 --- a/drivers/staging/fsl-mc/bus/mc-sys.c +++ b/drivers/staging/fsl-mc/bus/mc-sys.c @@ -39,6 +39,8 @@ #include #include #include +#include + #include "dpmcp.h" /** diff --git a/drivers/staging/fsl-mc/include/mc-sys.h b/drivers/staging/fsl-mc/include/mc-sys.h index 7a73cf6452f1..89ad0cf54702 100644 --- a/drivers/staging/fsl-mc/include/mc-sys.h +++ b/drivers/staging/fsl-mc/include/mc-sys.h @@ -37,8 +37,6 @@ #include #include -#include -#include #include #include -- cgit v1.2.3-59-g8ed1b From d4e75132bde743780084690b34da875b4402bd63 Mon Sep 17 00:00:00 2001 From: Stuart Yoder Date: Tue, 23 Aug 2016 17:14:23 -0500 Subject: staging: fsl-mc: make order of includes consistent There are 3 kinds of headers included in the bus driver components-- misc linux/include files, public bus driver includes, and includes private to the bus driver. Cleanup the order and formatting of includes in the bus driver to be consistent: #include #include ../include/[file].h // public bus driver includes (eventually // destined for: linux/include/fsl) [blank line] #include "[file].h" // private bus driver includes Signed-off-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dpmcp.c | 1 + drivers/staging/fsl-mc/bus/dpmng.c | 1 + drivers/staging/fsl-mc/bus/dprc-driver.c | 5 +++-- drivers/staging/fsl-mc/bus/dprc.c | 1 + drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 5 +++-- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 3 ++- drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 2 +- drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +- drivers/staging/fsl-mc/bus/mc-io.c | 2 +- drivers/staging/fsl-mc/bus/mc-sys.c | 6 +++--- 10 files changed, 17 insertions(+), 11 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dpmcp.c b/drivers/staging/fsl-mc/bus/dpmcp.c index 06440176243a..bd63baa00693 100644 --- a/drivers/staging/fsl-mc/bus/dpmcp.c +++ b/drivers/staging/fsl-mc/bus/dpmcp.c @@ -31,6 +31,7 @@ */ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" + #include "dpmcp.h" #include "dpmcp-cmd.h" diff --git a/drivers/staging/fsl-mc/bus/dpmng.c b/drivers/staging/fsl-mc/bus/dpmng.c index 660bbe7ea899..669f604ada7c 100644 --- a/drivers/staging/fsl-mc/bus/dpmng.c +++ b/drivers/staging/fsl-mc/bus/dpmng.c @@ -32,6 +32,7 @@ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" #include "../include/dpmng.h" + #include "dpmng-cmd.h" /** diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index 5e347203161a..c5ee4639682b 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -9,12 +9,13 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-bus.h" -#include "../include/mc-sys.h" #include #include #include #include +#include "../include/mc-bus.h" +#include "../include/mc-sys.h" + #include "dprc-cmd.h" #include "fsl-mc-private.h" diff --git a/drivers/staging/fsl-mc/bus/dprc.c b/drivers/staging/fsl-mc/bus/dprc.c index c26054981333..ac4ed3517084 100644 --- a/drivers/staging/fsl-mc/bus/dprc.c +++ b/drivers/staging/fsl-mc/bus/dprc.c @@ -32,6 +32,7 @@ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" #include "../include/dprc.h" + #include "dprc-cmd.h" /** diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index edcb5cc9a95b..2004fa7f5091 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -8,13 +8,14 @@ * warranty of any kind, whether express or implied. */ +#include +#include #include "../include/mc-bus.h" #include "../include/mc-sys.h" -#include #include "../include/dpbp-cmd.h" #include "../include/dpcon-cmd.h" + #include "fsl-mc-private.h" -#include #define FSL_MC_IS_ALLOCATABLE(_obj_type) \ (strcmp(_obj_type, "dpbp") == 0 || \ diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 9023df390957..03ebab8dd66d 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -9,7 +9,6 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-bus.h" #include #include #include @@ -19,8 +18,10 @@ #include #include #include +#include "../include/mc-bus.h" #include "../include/dpmng.h" #include "../include/mc-sys.h" + #include "fsl-mc-private.h" #include "dprc-cmd.h" diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c index 7c20f60a071a..cc190924deed 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c @@ -9,7 +9,6 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-bus.h" #include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include "../include/mc-bus.h" /* * Generate a unique ID identifying the interrupt (only used within the MSI diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c index 25863284b592..7a6ac640752f 100644 --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c @@ -9,7 +9,6 @@ * warranty of any kind, whether express or implied. */ -#include "../include/mc-bus.h" #include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include "../include/mc-bus.h" static struct irq_chip its_msi_irq_chip = { .name = "fsl-mc-bus-msi", diff --git a/drivers/staging/fsl-mc/bus/mc-io.c b/drivers/staging/fsl-mc/bus/mc-io.c index fd032c15f9cc..798c965fe203 100644 --- a/drivers/staging/fsl-mc/bus/mc-io.c +++ b/drivers/staging/fsl-mc/bus/mc-io.c @@ -30,9 +30,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include "../include/mc-bus.h" #include "../include/mc-sys.h" -#include #include "fsl-mc-private.h" #include "dpmcp.h" diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c index 461abaa0c6e1..285917c7c8e4 100644 --- a/drivers/staging/fsl-mc/bus/mc-sys.c +++ b/drivers/staging/fsl-mc/bus/mc-sys.c @@ -32,14 +32,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "../include/mc-sys.h" -#include "../include/mc-cmd.h" -#include "../include/mc.h" #include #include #include #include #include +#include "../include/mc-sys.h" +#include "../include/mc-cmd.h" +#include "../include/mc.h" #include "dpmcp.h" -- cgit v1.2.3-59-g8ed1b From 695b4adc326cc00808a96b2e8c3628de533a643a Mon Sep 17 00:00:00 2001 From: Anson Jacob Date: Fri, 26 Aug 2016 22:59:58 -0400 Subject: staging: fsl-mc: dpmng-cmd: Fix checkpatch warning Fix checkpatch.pl warning: Block comments use * on subsequent lines Fix Commenting Style Signed-off-by: Anson Jacob Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dpmng-cmd.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dpmng-cmd.h b/drivers/staging/fsl-mc/bus/dpmng-cmd.h index 779bf9c25bc0..a7b77d58c8cd 100644 --- a/drivers/staging/fsl-mc/bus/dpmng-cmd.h +++ b/drivers/staging/fsl-mc/bus/dpmng-cmd.h @@ -1,4 +1,5 @@ -/* Copyright 2013-2016 Freescale Semiconductor Inc. +/* + * Copyright 2013-2016 Freescale Semiconductor Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -30,12 +31,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*************************************************************************//* - dpmng-cmd.h - - defines portal commands - - *//**************************************************************************/ +/* + * dpmng-cmd.h + * + * defines portal commands + * + */ #ifndef __FSL_DPMNG_CMD_H #define __FSL_DPMNG_CMD_H -- cgit v1.2.3-59-g8ed1b From be1edb857ea48e7b7f5dd1ff278e79d4152def9e Mon Sep 17 00:00:00 2001 From: Anson Jacob Date: Fri, 26 Aug 2016 22:59:59 -0400 Subject: staging: fsl-mc: dprc-cmd: Fix checkpatch warning Fix checkpatch.pl warning: Block comments use * on subsequent lines Fix Commenting Style Signed-off-by: Anson Jacob Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dprc-cmd.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dprc-cmd.h b/drivers/staging/fsl-mc/bus/dprc-cmd.h index bb127f4a3ae7..009d65673155 100644 --- a/drivers/staging/fsl-mc/bus/dprc-cmd.h +++ b/drivers/staging/fsl-mc/bus/dprc-cmd.h @@ -1,4 +1,5 @@ -/* Copyright 2013-2016 Freescale Semiconductor Inc. +/* + * Copyright 2013-2016 Freescale Semiconductor Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -30,12 +31,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*************************************************************************//* - dprc-cmd.h - - defines dprc portal commands - - *//**************************************************************************/ +/* + * dprc-cmd.h + * + * defines dprc portal commands + * + */ #ifndef _FSL_DPRC_CMD_H #define _FSL_DPRC_CMD_H -- cgit v1.2.3-59-g8ed1b From a71a6d96a4d663c4e0a28128bba1b2febf0fe10c Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Sun, 28 Aug 2016 16:19:29 +0000 Subject: staging: fsl-mc: convert to use ATTRIBUTE_GROUPS macro Use ATTRIBUTE_GROUPS macro to reduce the number of lines of code. Generated by Coccinelle semantic patch. Signed-off-by: Wei Yongjun Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 03ebab8dd66d..3d687b51c9ff 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -137,14 +137,8 @@ static struct attribute *fsl_mc_dev_attrs[] = { NULL, }; -static const struct attribute_group fsl_mc_dev_group = { - .attrs = fsl_mc_dev_attrs, -}; +ATTRIBUTE_GROUPS(fsl_mc_dev); -static const struct attribute_group *fsl_mc_dev_groups[] = { - &fsl_mc_dev_group, - NULL, -}; struct bus_type fsl_mc_bus_type = { .name = "fsl-mc", -- cgit v1.2.3-59-g8ed1b From 9f4feef54d97529c095f27f131f2ae6a254645fd Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Thu, 15 Sep 2016 02:27:04 +0000 Subject: staging: fsl-mc: use list_del_init instead of list_del/INIT_LIST_HEAD Using list_del_init() instead of list_del() + INIT_LIST_HEAD(). Signed-off-by: Wei Yongjun Acked-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index 2004fa7f5091..1e06d28ac967 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -142,8 +142,7 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device goto out_unlock; } - list_del(&resource->node); - INIT_LIST_HEAD(&resource->node); + list_del_init(&resource->node); res_pool->free_count--; res_pool->max_count--; @@ -220,8 +219,7 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, res_pool->free_count > res_pool->max_count)) goto out_unlock; - list_del(&resource->node); - INIT_LIST_HEAD(&resource->node); + list_del_init(&resource->node); res_pool->free_count--; error = 0; -- cgit v1.2.3-59-g8ed1b From 053ead220203d3e742d8345d411ebb166f2aa6b4 Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Thu, 15 Sep 2016 02:27:27 +0000 Subject: staging: fsl-mc: remove .owner field for driver Remove .owner field if calls are used which set it automatically. Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci Signed-off-by: Wei Yongjun Acked-by: Stuart Yoder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c index 1e06d28ac967..e93ab53bae67 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c @@ -650,7 +650,6 @@ static const struct fsl_mc_device_id match_id_table[] = { static struct fsl_mc_driver fsl_mc_allocator_driver = { .driver = { .name = "fsl_mc_allocator", - .owner = THIS_MODULE, .pm = NULL, }, .match_id_table = match_id_table, -- cgit v1.2.3-59-g8ed1b From 905a672a2f97755c3d7787a125cda100096c999d Mon Sep 17 00:00:00 2001 From: Sandhya Bankar Date: Sun, 18 Sep 2016 05:07:21 +0530 Subject: Staging: fsl-mc: Use !x instead of x == NULL. Use !x instead of x == NULL. This issue was found by checkpatch. Signed-off-by: Sandhya Bankar Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c index cc190924deed..bc1ad1a85e85 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c @@ -50,7 +50,7 @@ static void fsl_mc_msi_update_dom_ops(struct msi_domain_info *info) /* * set_desc should not be set by the caller */ - if (ops->set_desc == NULL) + if (!ops->set_desc) ops->set_desc = fsl_mc_msi_set_desc; } @@ -140,7 +140,7 @@ static void fsl_mc_msi_update_chip_ops(struct msi_domain_info *info) /* * irq_write_msi_msg should not be set by the caller */ - if (chip->irq_write_msi_msg == NULL) + if (!chip->irq_write_msi_msg) chip->irq_write_msi_msg = fsl_mc_msi_write_msg; } -- cgit v1.2.3-59-g8ed1b From f86a180868a92ae57da8a716ec72d5303ba8faaa Mon Sep 17 00:00:00 2001 From: Ramiro Oliveira Date: Fri, 30 Sep 2016 15:01:21 +0100 Subject: Staging: fsl-mc: Fix unaligned * in block comments Align the * in some block comments as reported by checkpatch. Signed-off-by: Ramiro Oliveira Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dpbp.c | 60 ++++++++++----------- drivers/staging/fsl-mc/bus/dpmng.c | 60 ++++++++++----------- drivers/staging/fsl-mc/bus/dprc.c | 88 +++++++++++++++---------------- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 4 +- drivers/staging/fsl-mc/include/dpbp-cmd.h | 60 ++++++++++----------- 5 files changed, 136 insertions(+), 136 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dpbp.c b/drivers/staging/fsl-mc/bus/dpbp.c index fe271fbd629b..5d4cd812a400 100644 --- a/drivers/staging/fsl-mc/bus/dpbp.c +++ b/drivers/staging/fsl-mc/bus/dpbp.c @@ -1,34 +1,34 @@ /* Copyright 2013-2016 Freescale Semiconductor Inc. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the above-listed copyright holders nor the -* names of any contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* -* ALTERNATIVELY, this software may be distributed under the terms of the -* GNU General Public License ("GPL") as published by the Free Software -* Foundation, either version 2 of that License or (at your option) any -* later version. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" #include "../include/dpbp.h" diff --git a/drivers/staging/fsl-mc/bus/dpmng.c b/drivers/staging/fsl-mc/bus/dpmng.c index 669f604ada7c..96b1d67756fa 100644 --- a/drivers/staging/fsl-mc/bus/dpmng.c +++ b/drivers/staging/fsl-mc/bus/dpmng.c @@ -1,34 +1,34 @@ /* Copyright 2013-2016 Freescale Semiconductor Inc. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the above-listed copyright holders nor the -* names of any contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* -* ALTERNATIVELY, this software may be distributed under the terms of the -* GNU General Public License ("GPL") as published by the Free Software -* Foundation, either version 2 of that License or (at your option) any -* later version. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" #include "../include/dpmng.h" diff --git a/drivers/staging/fsl-mc/bus/dprc.c b/drivers/staging/fsl-mc/bus/dprc.c index ac4ed3517084..9fea3def6041 100644 --- a/drivers/staging/fsl-mc/bus/dprc.c +++ b/drivers/staging/fsl-mc/bus/dprc.c @@ -1,34 +1,34 @@ /* Copyright 2013-2016 Freescale Semiconductor Inc. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the above-listed copyright holders nor the -* names of any contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* -* ALTERNATIVELY, this software may be distributed under the terms of the -* GNU General Public License ("GPL") as published by the Free Software -* Foundation, either version 2 of that License or (at your option) any -* later version. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "../include/mc-sys.h" #include "../include/mc-cmd.h" #include "../include/dprc.h" @@ -1335,20 +1335,20 @@ int dprc_disconnect(struct fsl_mc_io *mc_io, } /** -* dprc_get_connection() - Get connected endpoint and link status if connection -* exists. -* @mc_io: Pointer to MC portal's I/O object -* @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' -* @token: Token of DPRC object -* @endpoint1: Endpoint 1 configuration parameters -* @endpoint2: Returned endpoint 2 configuration parameters -* @state: Returned link state: -* 1 - link is up; -* 0 - link is down; -* -1 - no connection (endpoint2 information is irrelevant) -* -* Return: '0' on Success; -ENAVAIL if connection does not exist. -*/ + * dprc_get_connection() - Get connected endpoint and link status if connection + * exists. + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPRC object + * @endpoint1: Endpoint 1 configuration parameters + * @endpoint2: Returned endpoint 2 configuration parameters + * @state: Returned link state: + * 1 - link is up; + * 0 - link is down; + * -1 - no connection (endpoint2 information is irrelevant) + * + * Return: '0' on Success; -ENAVAIL if connection does not exist. + */ int dprc_get_connection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 3d687b51c9ff..4ebc72fb7704 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -259,8 +259,8 @@ bool fsl_mc_bus_exists(void) EXPORT_SYMBOL_GPL(fsl_mc_bus_exists); /** -* fsl_mc_get_root_dprc - function to traverse to the root dprc -*/ + * fsl_mc_get_root_dprc - function to traverse to the root dprc + */ void fsl_mc_get_root_dprc(struct device *dev, struct device **root_dprc_dev) { diff --git a/drivers/staging/fsl-mc/include/dpbp-cmd.h b/drivers/staging/fsl-mc/include/dpbp-cmd.h index 4828ccd0cffd..2860411ddb51 100644 --- a/drivers/staging/fsl-mc/include/dpbp-cmd.h +++ b/drivers/staging/fsl-mc/include/dpbp-cmd.h @@ -1,34 +1,34 @@ /* Copyright 2013-2016 Freescale Semiconductor Inc. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the above-listed copyright holders nor the -* names of any contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* -* ALTERNATIVELY, this software may be distributed under the terms of the -* GNU General Public License ("GPL") as published by the Free Software -* Foundation, either version 2 of that License or (at your option) any -* later version. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _FSL_DPBP_CMD_H #define _FSL_DPBP_CMD_H -- cgit v1.2.3-59-g8ed1b From cb0b65556eb43b1465672d340be6de07baf85ecf Mon Sep 17 00:00:00 2001 From: Ramiro Oliveira Date: Fri, 30 Sep 2016 15:01:22 +0100 Subject: Staging: fsl-mc: Remove blank lines Remove multiple blank lines as reported by checkpatch Signed-off-by: Ramiro Oliveira Signed-off-by: Greg Kroah-Hartman --- drivers/staging/fsl-mc/bus/dpmcp.c | 1 - drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 1 - 2 files changed, 2 deletions(-) (limited to 'drivers/staging/fsl-mc') diff --git a/drivers/staging/fsl-mc/bus/dpmcp.c b/drivers/staging/fsl-mc/bus/dpmcp.c index bd63baa00693..55766f78a528 100644 --- a/drivers/staging/fsl-mc/bus/dpmcp.c +++ b/drivers/staging/fsl-mc/bus/dpmcp.c @@ -369,7 +369,6 @@ int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io, struct mc_command cmd = { 0 }; struct dpmcp_cmd_set_irq_mask *cmd_params; - /* prepare command */ cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK, cmd_flags, token); diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 4ebc72fb7704..44f64b6f0fc9 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -139,7 +139,6 @@ static struct attribute *fsl_mc_dev_attrs[] = { ATTRIBUTE_GROUPS(fsl_mc_dev); - struct bus_type fsl_mc_bus_type = { .name = "fsl-mc", .match = fsl_mc_bus_match, -- cgit v1.2.3-59-g8ed1b