staging: fsl-mc: move irq domain creation prototype to public header
[platform/kernel/linux-starfive.git] / drivers / staging / fsl-mc / include / mc.h
1 /*
2  * Freescale Management Complex (MC) bus public interface
3  *
4  * Copyright (C) 2014-2016 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  */
11 #ifndef _FSL_MC_H_
12 #define _FSL_MC_H_
13
14 #include <linux/device.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/interrupt.h>
17 #include "../include/dprc.h"
18
19 #define FSL_MC_VENDOR_FREESCALE 0x1957
20
21 struct irq_domain;
22 struct msi_domain_info;
23
24 struct fsl_mc_device;
25 struct fsl_mc_io;
26
27 /**
28  * struct fsl_mc_driver - MC object device driver object
29  * @driver: Generic device driver
30  * @match_id_table: table of supported device matching Ids
31  * @probe: Function called when a device is added
32  * @remove: Function called when a device is removed
33  * @shutdown: Function called at shutdown time to quiesce the device
34  * @suspend: Function called when a device is stopped
35  * @resume: Function called when a device is resumed
36  *
37  * Generic DPAA device driver object for device drivers that are registered
38  * with a DPRC bus. This structure is to be embedded in each device-specific
39  * driver structure.
40  */
41 struct fsl_mc_driver {
42         struct device_driver driver;
43         const struct fsl_mc_device_id *match_id_table;
44         int (*probe)(struct fsl_mc_device *dev);
45         int (*remove)(struct fsl_mc_device *dev);
46         void (*shutdown)(struct fsl_mc_device *dev);
47         int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
48         int (*resume)(struct fsl_mc_device *dev);
49 };
50
51 #define to_fsl_mc_driver(_drv) \
52         container_of(_drv, struct fsl_mc_driver, driver)
53
54 /**
55  * enum fsl_mc_pool_type - Types of allocatable MC bus resources
56  *
57  * Entries in these enum are used as indices in the array of resource
58  * pools of an fsl_mc_bus object.
59  */
60 enum fsl_mc_pool_type {
61         FSL_MC_POOL_DPMCP = 0x0,    /* corresponds to "dpmcp" in the MC */
62         FSL_MC_POOL_DPBP,           /* corresponds to "dpbp" in the MC */
63         FSL_MC_POOL_DPCON,          /* corresponds to "dpcon" in the MC */
64         FSL_MC_POOL_IRQ,
65
66         /*
67          * NOTE: New resource pool types must be added before this entry
68          */
69         FSL_MC_NUM_POOL_TYPES
70 };
71
72 /**
73  * struct fsl_mc_resource - MC generic resource
74  * @type: type of resource
75  * @id: unique MC resource Id within the resources of the same type
76  * @data: pointer to resource-specific data if the resource is currently
77  * allocated, or NULL if the resource is not currently allocated.
78  * @parent_pool: pointer to the parent resource pool from which this
79  * resource is allocated from.
80  * @node: Node in the free list of the corresponding resource pool
81  *
82  * NOTE: This structure is to be embedded as a field of specific
83  * MC resource structures.
84  */
85 struct fsl_mc_resource {
86         enum fsl_mc_pool_type type;
87         s32 id;
88         void *data;
89         struct fsl_mc_resource_pool *parent_pool;
90         struct list_head node;
91 };
92
93 /**
94  * struct fsl_mc_device_irq - MC object device message-based interrupt
95  * @msi_desc: pointer to MSI descriptor allocated by fsl_mc_msi_alloc_descs()
96  * @mc_dev: MC object device that owns this interrupt
97  * @dev_irq_index: device-relative IRQ index
98  * @resource: MC generic resource associated with the interrupt
99  */
100 struct fsl_mc_device_irq {
101         struct msi_desc *msi_desc;
102         struct fsl_mc_device *mc_dev;
103         u8 dev_irq_index;
104         struct fsl_mc_resource resource;
105 };
106
107 #define to_fsl_mc_irq(_mc_resource) \
108         container_of(_mc_resource, struct fsl_mc_device_irq, resource)
109
110 /* Opened state - Indicates that an object is open by at least one owner */
111 #define FSL_MC_OBJ_STATE_OPEN           0x00000001
112 /* Plugged state - Indicates that the object is plugged */
113 #define FSL_MC_OBJ_STATE_PLUGGED        0x00000002
114
115 /**
116  * Shareability flag - Object flag indicating no memory shareability.
117  * the object generates memory accesses that are non coherent with other
118  * masters;
119  * user is responsible for proper memory handling through IOMMU configuration.
120  */
121 #define FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY     0x0001
122
123 /**
124  * struct fsl_mc_obj_desc - Object descriptor
125  * @type: Type of object: NULL terminated string
126  * @id: ID of logical object resource
127  * @vendor: Object vendor identifier
128  * @ver_major: Major version number
129  * @ver_minor:  Minor version number
130  * @irq_count: Number of interrupts supported by the object
131  * @region_count: Number of mappable regions supported by the object
132  * @state: Object state: combination of FSL_MC_OBJ_STATE_ states
133  * @label: Object label: NULL terminated string
134  * @flags: Object's flags
135  */
136 struct fsl_mc_obj_desc {
137         char type[16];
138         int id;
139         u16 vendor;
140         u16 ver_major;
141         u16 ver_minor;
142         u8 irq_count;
143         u8 region_count;
144         u32 state;
145         char label[16];
146         u16 flags;
147 };
148
149 /**
150  * Bit masks for a MC object device (struct fsl_mc_device) flags
151  */
152 #define FSL_MC_IS_DPRC  0x0001
153
154 /**
155  * struct fsl_mc_device - MC object device object
156  * @dev: Linux driver model device object
157  * @dma_mask: Default DMA mask
158  * @flags: MC object device flags
159  * @icid: Isolation context ID for the device
160  * @mc_handle: MC handle for the corresponding MC object opened
161  * @mc_io: Pointer to MC IO object assigned to this device or
162  * NULL if none.
163  * @obj_desc: MC description of the DPAA device
164  * @regions: pointer to array of MMIO region entries
165  * @irqs: pointer to array of pointers to interrupts allocated to this device
166  * @resource: generic resource associated with this MC object device, if any.
167  *
168  * Generic device object for MC object devices that are "attached" to a
169  * MC bus.
170  *
171  * NOTES:
172  * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
173  * - The SMMU notifier callback gets invoked after device_add() has been
174  *   called for an MC object device, but before the device-specific probe
175  *   callback gets called.
176  * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
177  *   portals. For all other MC objects, their device drivers are responsible for
178  *   allocating MC portals for them by calling fsl_mc_portal_allocate().
179  * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
180  *   treated as resources that can be allocated/deallocated from the
181  *   corresponding resource pool in the object's parent DPRC, using the
182  *   fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
183  *   are known as "allocatable" objects. For them, the corresponding
184  *   fsl_mc_device's 'resource' points to the associated resource object.
185  *   For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
186  *   'resource' is NULL.
187  */
188 struct fsl_mc_device {
189         struct device dev;
190         u64 dma_mask;
191         u16 flags;
192         u16 icid;
193         u16 mc_handle;
194         struct fsl_mc_io *mc_io;
195         struct fsl_mc_obj_desc obj_desc;
196         struct resource *regions;
197         struct fsl_mc_device_irq **irqs;
198         struct fsl_mc_resource *resource;
199 };
200
201 #define to_fsl_mc_device(_dev) \
202         container_of(_dev, struct fsl_mc_device, dev)
203
204 /*
205  * module_fsl_mc_driver() - Helper macro for drivers that don't do
206  * anything special in module init/exit.  This eliminates a lot of
207  * boilerplate.  Each module may only use this macro once, and
208  * calling it replaces module_init() and module_exit()
209  */
210 #define module_fsl_mc_driver(__fsl_mc_driver) \
211         module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
212                       fsl_mc_driver_unregister)
213
214 /*
215  * Macro to avoid include chaining to get THIS_MODULE
216  */
217 #define fsl_mc_driver_register(drv) \
218         __fsl_mc_driver_register(drv, THIS_MODULE)
219
220 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
221                                           struct module *owner);
222
223 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
224
225 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
226                                         u16 mc_io_flags,
227                                         struct fsl_mc_io **new_mc_io);
228
229 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
230
231 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
232
233 int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
234                                         enum fsl_mc_pool_type pool_type,
235                                         struct fsl_mc_device **new_mc_adev);
236
237 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
238
239 struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
240                                                 struct msi_domain_info *info,
241                                                 struct irq_domain *parent);
242
243 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
244
245 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
246
247 #endif /* _FSL_MC_H_ */