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/list.h>
17 #include <linux/interrupt.h>
18 #include "../include/dprc.h"
20 #define FSL_MC_VENDOR_FREESCALE 0x1957
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)
110 * Bit masks for a MC object device (struct fsl_mc_device) flags
112 #define FSL_MC_IS_DPRC 0x0001
115 * Default DMA mask for devices on a fsl-mc bus
117 #define FSL_MC_DEFAULT_DMA_MASK (~0ULL)
120 * struct fsl_mc_device - MC object device object
121 * @dev: Linux driver model device object
122 * @dma_mask: Default DMA mask
123 * @flags: MC object device flags
124 * @icid: Isolation context ID for the device
125 * @mc_handle: MC handle for the corresponding MC object opened
126 * @mc_io: Pointer to MC IO object assigned to this device or
128 * @obj_desc: MC description of the DPAA device
129 * @regions: pointer to array of MMIO region entries
130 * @irqs: pointer to array of pointers to interrupts allocated to this device
131 * @resource: generic resource associated with this MC object device, if any.
133 * Generic device object for MC object devices that are "attached" to a
137 * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
138 * - The SMMU notifier callback gets invoked after device_add() has been
139 * called for an MC object device, but before the device-specific probe
140 * callback gets called.
141 * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
142 * portals. For all other MC objects, their device drivers are responsible for
143 * allocating MC portals for them by calling fsl_mc_portal_allocate().
144 * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
145 * treated as resources that can be allocated/deallocated from the
146 * corresponding resource pool in the object's parent DPRC, using the
147 * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
148 * are known as "allocatable" objects. For them, the corresponding
149 * fsl_mc_device's 'resource' points to the associated resource object.
150 * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
151 * 'resource' is NULL.
153 struct fsl_mc_device
{
159 struct fsl_mc_io
*mc_io
;
160 struct dprc_obj_desc obj_desc
;
161 struct resource
*regions
;
162 struct fsl_mc_device_irq
**irqs
;
163 struct fsl_mc_resource
*resource
;
166 #define to_fsl_mc_device(_dev) \
167 container_of(_dev, struct fsl_mc_device, dev)
170 * module_fsl_mc_driver() - Helper macro for drivers that don't do
171 * anything special in module init/exit. This eliminates a lot of
172 * boilerplate. Each module may only use this macro once, and
173 * calling it replaces module_init() and module_exit()
175 #define module_fsl_mc_driver(__fsl_mc_driver) \
176 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
177 fsl_mc_driver_unregister)
180 * Macro to avoid include chaining to get THIS_MODULE
182 #define fsl_mc_driver_register(drv) \
183 __fsl_mc_driver_register(drv, THIS_MODULE)
185 int __must_check
__fsl_mc_driver_register(struct fsl_mc_driver
*fsl_mc_driver
,
186 struct module
*owner
);
188 void fsl_mc_driver_unregister(struct fsl_mc_driver
*driver
);
190 bool fsl_mc_bus_exists(void);
192 int __must_check
fsl_mc_portal_allocate(struct fsl_mc_device
*mc_dev
,
194 struct fsl_mc_io
**new_mc_io
);
196 void fsl_mc_portal_free(struct fsl_mc_io
*mc_io
);
198 int fsl_mc_portal_reset(struct fsl_mc_io
*mc_io
);
200 int __must_check
fsl_mc_object_allocate(struct fsl_mc_device
*mc_dev
,
201 enum fsl_mc_pool_type pool_type
,
202 struct fsl_mc_device
**new_mc_adev
);
204 void fsl_mc_object_free(struct fsl_mc_device
*mc_adev
);
206 int __must_check
fsl_mc_allocate_irqs(struct fsl_mc_device
*mc_dev
);
208 void fsl_mc_free_irqs(struct fsl_mc_device
*mc_dev
);
210 bool fsl_mc_is_root_dprc(struct device
*dev
);
212 extern struct bus_type fsl_mc_bus_type
;
214 #endif /* _FSL_MC_H_ */