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>
18 #define FSL_MC_VENDOR_FREESCALE 0x1957
21 struct msi_domain_info;
27 * struct fsl_mc_driver - MC object device driver object
28 * @driver: Generic device driver
29 * @match_id_table: table of supported device matching Ids
30 * @probe: Function called when a device is added
31 * @remove: Function called when a device is removed
32 * @shutdown: Function called at shutdown time to quiesce the device
33 * @suspend: Function called when a device is stopped
34 * @resume: Function called when a device is resumed
36 * Generic DPAA device driver object for device drivers that are registered
37 * with a DPRC bus. This structure is to be embedded in each device-specific
40 struct fsl_mc_driver {
41 struct device_driver driver;
42 const struct fsl_mc_device_id *match_id_table;
43 int (*probe)(struct fsl_mc_device *dev);
44 int (*remove)(struct fsl_mc_device *dev);
45 void (*shutdown)(struct fsl_mc_device *dev);
46 int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
47 int (*resume)(struct fsl_mc_device *dev);
50 #define to_fsl_mc_driver(_drv) \
51 container_of(_drv, struct fsl_mc_driver, driver)
54 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
56 * Entries in these enum are used as indices in the array of resource
57 * pools of an fsl_mc_bus object.
59 enum fsl_mc_pool_type {
60 FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */
61 FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */
62 FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */
66 * NOTE: New resource pool types must be added before this entry
72 * struct fsl_mc_resource - MC generic resource
73 * @type: type of resource
74 * @id: unique MC resource Id within the resources of the same type
75 * @data: pointer to resource-specific data if the resource is currently
76 * allocated, or NULL if the resource is not currently allocated.
77 * @parent_pool: pointer to the parent resource pool from which this
78 * resource is allocated from.
79 * @node: Node in the free list of the corresponding resource pool
81 * NOTE: This structure is to be embedded as a field of specific
82 * MC resource structures.
84 struct fsl_mc_resource {
85 enum fsl_mc_pool_type type;
88 struct fsl_mc_resource_pool *parent_pool;
89 struct list_head node;
93 * struct fsl_mc_device_irq - MC object device message-based interrupt
94 * @msi_desc: pointer to MSI descriptor allocated by fsl_mc_msi_alloc_descs()
95 * @mc_dev: MC object device that owns this interrupt
96 * @dev_irq_index: device-relative IRQ index
97 * @resource: MC generic resource associated with the interrupt
99 struct fsl_mc_device_irq {
100 struct msi_desc *msi_desc;
101 struct fsl_mc_device *mc_dev;
103 struct fsl_mc_resource resource;
106 #define to_fsl_mc_irq(_mc_resource) \
107 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
109 /* Opened state - Indicates that an object is open by at least one owner */
110 #define FSL_MC_OBJ_STATE_OPEN 0x00000001
111 /* Plugged state - Indicates that the object is plugged */
112 #define FSL_MC_OBJ_STATE_PLUGGED 0x00000002
115 * Shareability flag - Object flag indicating no memory shareability.
116 * the object generates memory accesses that are non coherent with other
118 * user is responsible for proper memory handling through IOMMU configuration.
120 #define FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
123 * struct fsl_mc_obj_desc - Object descriptor
124 * @type: Type of object: NULL terminated string
125 * @id: ID of logical object resource
126 * @vendor: Object vendor identifier
127 * @ver_major: Major version number
128 * @ver_minor: Minor version number
129 * @irq_count: Number of interrupts supported by the object
130 * @region_count: Number of mappable regions supported by the object
131 * @state: Object state: combination of FSL_MC_OBJ_STATE_ states
132 * @label: Object label: NULL terminated string
133 * @flags: Object's flags
135 struct fsl_mc_obj_desc {
149 * Bit masks for a MC object device (struct fsl_mc_device) flags
151 #define FSL_MC_IS_DPRC 0x0001
154 * struct fsl_mc_device - MC object device object
155 * @dev: Linux driver model device object
156 * @dma_mask: Default DMA mask
157 * @flags: MC object device flags
158 * @icid: Isolation context ID for the device
159 * @mc_handle: MC handle for the corresponding MC object opened
160 * @mc_io: Pointer to MC IO object assigned to this device or
162 * @obj_desc: MC description of the DPAA device
163 * @regions: pointer to array of MMIO region entries
164 * @irqs: pointer to array of pointers to interrupts allocated to this device
165 * @resource: generic resource associated with this MC object device, if any.
167 * Generic device object for MC object devices that are "attached" to a
171 * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
172 * - The SMMU notifier callback gets invoked after device_add() has been
173 * called for an MC object device, but before the device-specific probe
174 * callback gets called.
175 * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
176 * portals. For all other MC objects, their device drivers are responsible for
177 * allocating MC portals for them by calling fsl_mc_portal_allocate().
178 * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
179 * treated as resources that can be allocated/deallocated from the
180 * corresponding resource pool in the object's parent DPRC, using the
181 * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
182 * are known as "allocatable" objects. For them, the corresponding
183 * fsl_mc_device's 'resource' points to the associated resource object.
184 * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
185 * 'resource' is NULL.
187 struct fsl_mc_device {
193 struct fsl_mc_io *mc_io;
194 struct fsl_mc_obj_desc obj_desc;
195 struct resource *regions;
196 struct fsl_mc_device_irq **irqs;
197 struct fsl_mc_resource *resource;
200 #define to_fsl_mc_device(_dev) \
201 container_of(_dev, struct fsl_mc_device, dev)
203 #define MC_CMD_NUM_OF_PARAMS 7
205 struct mc_cmd_header {
216 u64 params[MC_CMD_NUM_OF_PARAMS];
220 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
221 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
222 MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
223 MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
224 MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
225 MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
226 MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
227 MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
228 MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
229 MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
230 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
231 MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
238 /* High priority flag */
239 #define MC_CMD_FLAG_PRI 0x80
240 /* Command completion flag */
241 #define MC_CMD_FLAG_INTR_DIS 0x01
243 static inline u64 mc_encode_cmd_header(u16 cmd_id,
248 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
250 hdr->cmd_id = cpu_to_le16(cmd_id);
251 hdr->token = cpu_to_le16(token);
252 hdr->status = MC_CMD_STATUS_READY;
253 if (cmd_flags & MC_CMD_FLAG_PRI)
254 hdr->flags_hw = MC_CMD_FLAG_PRI;
255 if (cmd_flags & MC_CMD_FLAG_INTR_DIS)
256 hdr->flags_sw = MC_CMD_FLAG_INTR_DIS;
261 static inline u16 mc_cmd_hdr_read_token(struct mc_command *cmd)
263 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
264 u16 token = le16_to_cpu(hdr->token);
269 struct mc_rsp_create {
273 struct mc_rsp_api_ver {
278 static inline u32 mc_cmd_read_object_id(struct mc_command *cmd)
280 struct mc_rsp_create *rsp_params;
282 rsp_params = (struct mc_rsp_create *)cmd->params;
283 return le32_to_cpu(rsp_params->object_id);
286 static inline void mc_cmd_read_api_version(struct mc_command *cmd,
290 struct mc_rsp_api_ver *rsp_params;
292 rsp_params = (struct mc_rsp_api_ver *)cmd->params;
293 *major_ver = le16_to_cpu(rsp_params->major_ver);
294 *minor_ver = le16_to_cpu(rsp_params->minor_ver);
298 * Bit masks for a MC I/O object (struct fsl_mc_io) flags
300 #define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL 0x0001
303 * struct fsl_mc_io - MC I/O object to be passed-in to mc_send_command()
304 * @dev: device associated with this Mc I/O object
305 * @flags: flags for mc_send_command()
306 * @portal_size: MC command portal size in bytes
307 * @portal_phys_addr: MC command portal physical address
308 * @portal_virt_addr: MC command portal virtual address
309 * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
311 * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not
313 * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
314 * portal, if the fsl_mc_io object was created with the
315 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
316 * fsl_mc_io object must be made only from non-atomic context.
318 * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is
320 * @spinlock: Spinlock to serialize mc_send_command() calls that use the same MC
321 * portal, if the fsl_mc_io object was created with the
322 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag on. mc_send_command() calls for this
323 * fsl_mc_io object can be made from atomic or non-atomic context.
329 phys_addr_t portal_phys_addr;
330 void __iomem *portal_virt_addr;
331 struct fsl_mc_device *dpmcp_dev;
334 * This field is only meaningful if the
335 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not set
337 struct mutex mutex; /* serializes mc_send_command() */
340 * This field is only meaningful if the
341 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is set
343 spinlock_t spinlock; /* serializes mc_send_command() */
347 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
349 #ifdef CONFIG_FSL_MC_BUS
350 #define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type)
352 /* If fsl-mc bus is not present device cannot belong to fsl-mc bus */
353 #define dev_is_fsl_mc(_dev) (0)
357 * module_fsl_mc_driver() - Helper macro for drivers that don't do
358 * anything special in module init/exit. This eliminates a lot of
359 * boilerplate. Each module may only use this macro once, and
360 * calling it replaces module_init() and module_exit()
362 #define module_fsl_mc_driver(__fsl_mc_driver) \
363 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
364 fsl_mc_driver_unregister)
367 * Macro to avoid include chaining to get THIS_MODULE
369 #define fsl_mc_driver_register(drv) \
370 __fsl_mc_driver_register(drv, THIS_MODULE)
372 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
373 struct module *owner);
375 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
377 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
379 struct fsl_mc_io **new_mc_io);
381 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
383 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
385 int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
386 enum fsl_mc_pool_type pool_type,
387 struct fsl_mc_device **new_mc_adev);
389 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
391 struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
392 struct msi_domain_info *info,
393 struct irq_domain *parent);
395 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
397 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
399 extern struct bus_type fsl_mc_bus_type;
401 #endif /* _FSL_MC_H_ */