blob: 170684a57ca238f15c5d427002204565edc084e4 [file] [log] [blame]
J. German Riverabbf9d172015-03-05 19:29:10 -06001/*
Stuart Yoderc37ebf82016-08-23 17:13:04 -05002 * Freescale Management Complex (MC) bus declarations
J. German Riverabbf9d172015-03-05 19:29:10 -06003 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
Stuart Yoderc37ebf82016-08-23 17:13:04 -050011#ifndef _FSL_MC_MCBUS_H_
12#define _FSL_MC_MCBUS_H_
J. German Riverabbf9d172015-03-05 19:29:10 -060013
14#include "../include/mc.h"
15#include <linux/mutex.h>
J. German Riverabbf9d172015-03-05 19:29:10 -060016
J. German Rivera679c2c72016-01-06 16:03:21 -060017struct irq_domain;
18struct msi_domain_info;
19
J. German Riverabbf9d172015-03-05 19:29:10 -060020/**
J. German Rivera89f067df2016-01-06 16:03:23 -060021 * Maximum number of total IRQs that can be pre-allocated for an MC bus'
22 * IRQ pool
23 */
24#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
25
Stuart Yodere744e452016-08-23 17:13:59 -050026#ifdef CONFIG_FSL_MC_BUS
27#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type)
28#else
29/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */
30#define dev_is_fsl_mc(_dev) (0)
31#endif
32
J. German Rivera89f067df2016-01-06 16:03:23 -060033/**
J. German Rivera197f4d62015-03-05 19:35:25 -060034 * struct fsl_mc_resource_pool - Pool of MC resources of a given
35 * type
36 * @type: type of resources in the pool
37 * @max_count: maximum number of resources in the pool
38 * @free_count: number of free resources in the pool
39 * @mutex: mutex to serialize access to the pool's free list
40 * @free_list: anchor node of list of free resources in the pool
41 * @mc_bus: pointer to the MC bus that owns this resource pool
42 */
43struct fsl_mc_resource_pool {
44 enum fsl_mc_pool_type type;
45 int16_t max_count;
46 int16_t free_count;
47 struct mutex mutex; /* serializes access to free_list */
48 struct list_head free_list;
49 struct fsl_mc_bus *mc_bus;
50};
51
52/**
53 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
54 * @mc_dev: fsl-mc device for the bus device itself.
55 * @resource_pools: array of resource pools (one pool per resource type)
56 * for this MC bus. These resources represent allocatable entities
57 * from the physical DPRC.
J. German Rivera679c2c72016-01-06 16:03:21 -060058 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
J. German Rivera197f4d62015-03-05 19:35:25 -060059 * @scan_mutex: Serializes bus scanning
Itai Katz1716cb42016-04-11 11:56:05 -050060 * @dprc_attr: DPRC attributes
J. German Rivera197f4d62015-03-05 19:35:25 -060061 */
62struct fsl_mc_bus {
63 struct fsl_mc_device mc_dev;
64 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
J. German Rivera679c2c72016-01-06 16:03:21 -060065 struct fsl_mc_device_irq *irq_resources;
J. German Rivera197f4d62015-03-05 19:35:25 -060066 struct mutex scan_mutex; /* serializes bus scanning */
Itai Katz1716cb42016-04-11 11:56:05 -050067 struct dprc_attributes dprc_attr;
J. German Rivera197f4d62015-03-05 19:35:25 -060068};
69
70#define to_fsl_mc_bus(_mc_dev) \
71 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
72
J. German Riveraf2f27262015-03-05 19:29:11 -060073int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
74
J. German Rivera1e4aa422016-01-06 16:03:25 -060075int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
76 unsigned int *total_irq_count);
J. German Riveraf2f27262015-03-05 19:29:11 -060077
78int __init dprc_driver_init(void);
79
Lijun Pan3c7b67f2015-10-25 17:41:19 -050080void dprc_driver_exit(void);
J. German Riveraf2f27262015-03-05 19:29:11 -060081
J. German Riverae91ffa92015-03-27 16:01:08 -050082int __init fsl_mc_allocator_driver_init(void);
83
Thierry Reding53360602016-02-15 14:22:23 +010084void fsl_mc_allocator_driver_exit(void);
J. German Riverae91ffa92015-03-27 16:01:08 -050085
J. German Rivera679c2c72016-01-06 16:03:21 -060086struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
87 struct msi_domain_info *info,
88 struct irq_domain *parent);
89
90int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
91 struct irq_domain **mc_msi_domain);
92
J. German Rivera89f067df2016-01-06 16:03:23 -060093int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
94 unsigned int irq_count);
95
96void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
97
Stuart Yoder36406952016-08-23 17:13:24 -050098void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
99
100void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
101
Stuart Yodere744e452016-08-23 17:13:59 -0500102bool fsl_mc_bus_exists(void);
103
104void fsl_mc_get_root_dprc(struct device *dev,
105 struct device **root_dprc_dev);
106
107bool fsl_mc_is_root_dprc(struct device *dev);
108
109extern struct bus_type fsl_mc_bus_type;
110
Stuart Yoderc37ebf82016-08-23 17:13:04 -0500111#endif /* _FSL_MC_MCBUS_H_ */