2 * Freescale Management Complex (MC) bus public interface
4 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com>
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.
14 #include <linux/device.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/interrupt.h>
17 #include "../include/dprc.h"
19 #define FSL_MC_VENDOR_FREESCALE 0x1957
22 struct msi_domain_info;
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
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
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);
51 #define to_fsl_mc_driver(_drv) \
52 container_of(_drv, struct fsl_mc_driver, driver)
55 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
57 * Entries in these enum are used as indices in the array of resource
58 * pools of an fsl_mc_bus object.
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 */
67 * NOTE: New resource pool types must be added before this entry
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
82 * NOTE: This structure is to be embedded as a field of specific
83 * MC resource structures.
85 struct fsl_mc_resource {
86 enum fsl_mc_pool_type type;
89 struct fsl_mc_resource_pool *parent_pool;
90 struct list_head node;
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
100 struct fsl_mc_device_irq {
101 struct msi_desc *msi_desc;
102 struct fsl_mc_device *mc_dev;
104 struct fsl_mc_resource resource;
107 #define to_fsl_mc_irq(_mc_resource) \
108 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
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
116 * Shareability flag - Object flag indicating no memory shareability.
117 * the object generates memory accesses that are non coherent with other
119 * user is responsible for proper memory handling through IOMMU configuration.
121 #define FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
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
136 struct fsl_mc_obj_desc {
150 * Bit masks for a MC object device (struct fsl_mc_device) flags
152 #define FSL_MC_IS_DPRC 0x0001
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
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.
168 * Generic device object for MC object devices that are "attached" to a
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.
188 struct fsl_mc_device {
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;
201 #define to_fsl_mc_device(_dev) \
202 container_of(_dev, struct fsl_mc_device, dev)
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()
210 #define module_fsl_mc_driver(__fsl_mc_driver) \
211 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
212 fsl_mc_driver_unregister)
215 * Macro to avoid include chaining to get THIS_MODULE
217 #define fsl_mc_driver_register(drv) \
218 __fsl_mc_driver_register(drv, THIS_MODULE)
220 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
221 struct module *owner);
223 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
225 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
227 struct fsl_mc_io **new_mc_io);
229 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
231 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
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);
237 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
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);
243 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
245 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
247 #endif /* _FSL_MC_H_ */