GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / fsl-mc / bus / fsl-mc-private.h
1 /*
2  * Freescale Management Complex (MC) bus private declarations
3  *
4  * Copyright (C) 2016 Freescale Semiconductor, Inc.
5  *
6  * This file is licensed under the terms of the GNU General Public
7  * License version 2. This program is licensed "as is" without any
8  * warranty of any kind, whether express or implied.
9  */
10 #ifndef _FSL_MC_PRIVATE_H_
11 #define _FSL_MC_PRIVATE_H_
12
13 #include "../include/mc.h"
14 #include "dprc.h"
15 #include <linux/mutex.h>
16
17 /**
18  * Maximum number of total IRQs that can be pre-allocated for an MC bus'
19  * IRQ pool
20  */
21 #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS  256
22
23 /**
24  * struct fsl_mc_resource_pool - Pool of MC resources of a given
25  * type
26  * @type: type of resources in the pool
27  * @max_count: maximum number of resources in the pool
28  * @free_count: number of free resources in the pool
29  * @mutex: mutex to serialize access to the pool's free list
30  * @free_list: anchor node of list of free resources in the pool
31  * @mc_bus: pointer to the MC bus that owns this resource pool
32  */
33 struct fsl_mc_resource_pool {
34         enum fsl_mc_pool_type type;
35         int max_count;
36         int free_count;
37         struct mutex mutex;     /* serializes access to free_list */
38         struct list_head free_list;
39         struct fsl_mc_bus *mc_bus;
40 };
41
42 /**
43  * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
44  * @mc_dev: fsl-mc device for the bus device itself.
45  * @resource_pools: array of resource pools (one pool per resource type)
46  * for this MC bus. These resources represent allocatable entities
47  * from the physical DPRC.
48  * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
49  * @scan_mutex: Serializes bus scanning
50  * @dprc_attr: DPRC attributes
51  */
52 struct fsl_mc_bus {
53         struct fsl_mc_device mc_dev;
54         struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
55         struct fsl_mc_device_irq *irq_resources;
56         struct mutex scan_mutex;    /* serializes bus scanning */
57         struct dprc_attributes dprc_attr;
58 };
59
60 #define to_fsl_mc_bus(_mc_dev) \
61         container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
62
63 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
64                                    struct fsl_mc_io *mc_io,
65                                    struct device *parent_dev,
66                                    struct fsl_mc_device **new_mc_dev);
67
68 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
69
70 int __init dprc_driver_init(void);
71
72 void dprc_driver_exit(void);
73
74 int __init fsl_mc_allocator_driver_init(void);
75
76 void fsl_mc_allocator_driver_exit(void);
77
78 void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
79
80 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
81
82 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
83                                           enum fsl_mc_pool_type pool_type,
84                                           struct fsl_mc_resource
85                                                           **new_resource);
86
87 void fsl_mc_resource_free(struct fsl_mc_resource *resource);
88
89 int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
90                                  unsigned int irq_count);
91
92 void fsl_mc_msi_domain_free_irqs(struct device *dev);
93
94 int __init its_fsl_mc_msi_init(void);
95
96 void its_fsl_mc_msi_cleanup(void);
97
98 int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
99                            struct irq_domain **mc_msi_domain);
100
101 int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
102                              unsigned int irq_count);
103
104 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
105
106 int __must_check fsl_create_mc_io(struct device *dev,
107                                   phys_addr_t mc_portal_phys_addr,
108                                   u32 mc_portal_size,
109                                   struct fsl_mc_device *dpmcp_dev,
110                                   u32 flags, struct fsl_mc_io **new_mc_io);
111
112 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
113
114 bool fsl_mc_is_root_dprc(struct device *dev);
115
116 #endif /* _FSL_MC_PRIVATE_H_ */