2 * Freescale Management Complex (MC) bus public interface
4 * Copyright (C) 2014 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
25 * struct fsl_mc_driver - MC object device driver object
26 * @driver: Generic device driver
27 * @match_id_table: table of supported device matching Ids
28 * @probe: Function called when a device is added
29 * @remove: Function called when a device is removed
30 * @shutdown: Function called at shutdown time to quiesce the device
31 * @suspend: Function called when a device is stopped
32 * @resume: Function called when a device is resumed
34 * Generic DPAA device driver object for device drivers that are registered
35 * with a DPRC bus. This structure is to be embedded in each device-specific
38 struct fsl_mc_driver {
39 struct device_driver driver;
40 const struct fsl_mc_device_id *match_id_table;
41 int (*probe)(struct fsl_mc_device *dev);
42 int (*remove)(struct fsl_mc_device *dev);
43 void (*shutdown)(struct fsl_mc_device *dev);
44 int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
45 int (*resume)(struct fsl_mc_device *dev);
48 #define to_fsl_mc_driver(_drv) \
49 container_of(_drv, struct fsl_mc_driver, driver)
52 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
54 * Entries in these enum are used as indices in the array of resource
55 * pools of an fsl_mc_bus object.
57 enum fsl_mc_pool_type {
58 FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */
59 FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */
60 FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */
64 * NOTE: New resource pool types must be added before this entry
70 * struct fsl_mc_resource - MC generic resource
71 * @type: type of resource
72 * @id: unique MC resource Id within the resources of the same type
73 * @data: pointer to resource-specific data if the resource is currently
74 * allocated, or NULL if the resource is not currently allocated.
75 * @parent_pool: pointer to the parent resource pool from which this
76 * resource is allocated from.
77 * @node: Node in the free list of the corresponding resource pool
79 * NOTE: This structure is to be embedded as a field of specific
80 * MC resource structures.
82 struct fsl_mc_resource {
83 enum fsl_mc_pool_type type;
86 struct fsl_mc_resource_pool *parent_pool;
87 struct list_head node;
91 * struct fsl_mc_device_irq - MC object device message-based interrupt
92 * @msi_desc: pointer to MSI descriptor allocated by fsl_mc_msi_alloc_descs()
93 * @mc_dev: MC object device that owns this interrupt
94 * @dev_irq_index: device-relative IRQ index
95 * @resource: MC generic resource associated with the interrupt
97 struct fsl_mc_device_irq {
98 struct msi_desc *msi_desc;
99 struct fsl_mc_device *mc_dev;
101 struct fsl_mc_resource resource;
104 #define to_fsl_mc_irq(_mc_resource) \
105 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
108 * Bit masks for a MC object device (struct fsl_mc_device) flags
110 #define FSL_MC_IS_DPRC 0x0001
113 * struct fsl_mc_device - MC object device object
114 * @dev: Linux driver model device object
115 * @dma_mask: Default DMA mask
116 * @flags: MC object device flags
117 * @icid: Isolation context ID for the device
118 * @mc_handle: MC handle for the corresponding MC object opened
119 * @mc_io: Pointer to MC IO object assigned to this device or
121 * @obj_desc: MC description of the DPAA device
122 * @regions: pointer to array of MMIO region entries
123 * @irqs: pointer to array of pointers to interrupts allocated to this device
124 * @resource: generic resource associated with this MC object device, if any.
126 * Generic device object for MC object devices that are "attached" to a
130 * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
131 * - The SMMU notifier callback gets invoked after device_add() has been
132 * called for an MC object device, but before the device-specific probe
133 * callback gets called.
134 * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
135 * portals. For all other MC objects, their device drivers are responsible for
136 * allocating MC portals for them by calling fsl_mc_portal_allocate().
137 * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
138 * treated as resources that can be allocated/deallocated from the
139 * corresponding resource pool in the object's parent DPRC, using the
140 * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
141 * are known as "allocatable" objects. For them, the corresponding
142 * fsl_mc_device's 'resource' points to the associated resource object.
143 * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
144 * 'resource' is NULL.
146 struct fsl_mc_device {
152 struct fsl_mc_io *mc_io;
153 struct dprc_obj_desc obj_desc;
154 struct resource *regions;
155 struct fsl_mc_device_irq **irqs;
156 struct fsl_mc_resource *resource;
159 #define to_fsl_mc_device(_dev) \
160 container_of(_dev, struct fsl_mc_device, dev)
163 * module_fsl_mc_driver() - Helper macro for drivers that don't do
164 * anything special in module init/exit. This eliminates a lot of
165 * boilerplate. Each module may only use this macro once, and
166 * calling it replaces module_init() and module_exit()
168 #define module_fsl_mc_driver(__fsl_mc_driver) \
169 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
170 fsl_mc_driver_unregister)
173 * Macro to avoid include chaining to get THIS_MODULE
175 #define fsl_mc_driver_register(drv) \
176 __fsl_mc_driver_register(drv, THIS_MODULE)
178 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
179 struct module *owner);
181 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
183 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
185 struct fsl_mc_io **new_mc_io);
187 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
189 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
191 int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
192 enum fsl_mc_pool_type pool_type,
193 struct fsl_mc_device **new_mc_adev);
195 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
197 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
199 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
201 #endif /* _FSL_MC_H_ */