Merge remote-tracking branch 'usb-chipidea-next/ci-for-usb-next'
[deliverable/linux.git] / drivers / staging / fsl-mc / include / mc.h
1 /*
2 * Freescale Management Complex (MC) bus public interface
3 *
4 * Copyright (C) 2014 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/list.h>
17 #include <linux/interrupt.h>
18 #include "../include/dprc.h"
19
20 #define FSL_MC_VENDOR_FREESCALE 0x1957
21
22 struct fsl_mc_device;
23 struct fsl_mc_io;
24 struct fsl_mc_bus;
25
26 /**
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
35 *
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
38 * driver structure.
39 */
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);
48 };
49
50 #define to_fsl_mc_driver(_drv) \
51 container_of(_drv, struct fsl_mc_driver, driver)
52
53 /**
54 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
55 *
56 * Entries in these enum are used as indices in the array of resource
57 * pools of an fsl_mc_bus object.
58 */
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 */
63 FSL_MC_POOL_IRQ,
64
65 /*
66 * NOTE: New resource pool types must be added before this entry
67 */
68 FSL_MC_NUM_POOL_TYPES
69 };
70
71 /**
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
80 *
81 * NOTE: This structure is to be embedded as a field of specific
82 * MC resource structures.
83 */
84 struct fsl_mc_resource {
85 enum fsl_mc_pool_type type;
86 int32_t id;
87 void *data;
88 struct fsl_mc_resource_pool *parent_pool;
89 struct list_head node;
90 };
91
92 /**
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
98 */
99 struct fsl_mc_device_irq {
100 struct msi_desc *msi_desc;
101 struct fsl_mc_device *mc_dev;
102 u8 dev_irq_index;
103 struct fsl_mc_resource resource;
104 };
105
106 #define to_fsl_mc_irq(_mc_resource) \
107 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
108
109 /**
110 * Bit masks for a MC object device (struct fsl_mc_device) flags
111 */
112 #define FSL_MC_IS_DPRC 0x0001
113
114 /**
115 * Default DMA mask for devices on a fsl-mc bus
116 */
117 #define FSL_MC_DEFAULT_DMA_MASK (~0ULL)
118
119 /**
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
127 * NULL if none.
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.
132 *
133 * Generic device object for MC object devices that are "attached" to a
134 * MC bus.
135 *
136 * NOTES:
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.
152 */
153 struct fsl_mc_device {
154 struct device dev;
155 u64 dma_mask;
156 u16 flags;
157 u16 icid;
158 u16 mc_handle;
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;
164 };
165
166 #define to_fsl_mc_device(_dev) \
167 container_of(_dev, struct fsl_mc_device, dev)
168
169 /*
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()
174 */
175 #define module_fsl_mc_driver(__fsl_mc_driver) \
176 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
177 fsl_mc_driver_unregister)
178
179 /*
180 * Macro to avoid include chaining to get THIS_MODULE
181 */
182 #define fsl_mc_driver_register(drv) \
183 __fsl_mc_driver_register(drv, THIS_MODULE)
184
185 int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
186 struct module *owner);
187
188 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
189
190 bool fsl_mc_bus_exists(void);
191
192 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
193 u16 mc_io_flags,
194 struct fsl_mc_io **new_mc_io);
195
196 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
197
198 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
199
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);
203
204 void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
205
206 int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
207
208 void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
209
210 bool fsl_mc_is_root_dprc(struct device *dev);
211
212 extern struct bus_type fsl_mc_bus_type;
213
214 #endif /* _FSL_MC_H_ */
This page took 0.034528 seconds and 5 git commands to generate.