Commit | Line | Data |
---|---|---|
bbf9d17d GR |
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 "../include/dprc.h" | |
18 | ||
19 | #define FSL_MC_VENDOR_FREESCALE 0x1957 | |
20 | ||
21 | struct fsl_mc_device; | |
22 | struct fsl_mc_io; | |
23 | ||
24 | /** | |
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 | |
33 | * | |
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 | |
36 | * driver structure. | |
37 | */ | |
38 | struct fsl_mc_driver { | |
39 | struct device_driver driver; | |
40 | const struct fsl_mc_device_match_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); | |
46 | }; | |
47 | ||
48 | #define to_fsl_mc_driver(_drv) \ | |
49 | container_of(_drv, struct fsl_mc_driver, driver) | |
50 | ||
51 | /** | |
52 | * struct fsl_mc_device_match_id - MC object device Id entry for driver matching | |
53 | * @vendor: vendor ID | |
54 | * @obj_type: MC object type | |
55 | * @ver_major: MC object version major number | |
56 | * @ver_minor: MC object version minor number | |
57 | * | |
58 | * Type of entries in the "device Id" table for MC object devices supported by | |
59 | * a MC object device driver. The last entry of the table has vendor set to 0x0 | |
60 | */ | |
61 | struct fsl_mc_device_match_id { | |
62 | uint16_t vendor; | |
63 | const char obj_type[16]; | |
64 | uint32_t ver_major; | |
65 | uint32_t ver_minor; | |
66 | }; | |
67 | ||
197f4d6a GR |
68 | /** |
69 | * enum fsl_mc_pool_type - Types of allocatable MC bus resources | |
70 | * | |
71 | * Entries in these enum are used as indices in the array of resource | |
72 | * pools of an fsl_mc_bus object. | |
73 | */ | |
74 | enum fsl_mc_pool_type { | |
75 | FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */ | |
76 | FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */ | |
77 | FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */ | |
78 | ||
79 | /* | |
80 | * NOTE: New resource pool types must be added before this entry | |
81 | */ | |
82 | FSL_MC_NUM_POOL_TYPES | |
83 | }; | |
84 | ||
85 | /** | |
86 | * struct fsl_mc_resource - MC generic resource | |
87 | * @type: type of resource | |
88 | * @id: unique MC resource Id within the resources of the same type | |
89 | * @data: pointer to resource-specific data if the resource is currently | |
90 | * allocated, or NULL if the resource is not currently allocated. | |
91 | * @parent_pool: pointer to the parent resource pool from which this | |
92 | * resource is allocated from. | |
93 | * @node: Node in the free list of the corresponding resource pool | |
94 | * | |
95 | * NOTE: This structure is to be embedded as a field of specific | |
96 | * MC resource structures. | |
97 | */ | |
98 | struct fsl_mc_resource { | |
99 | enum fsl_mc_pool_type type; | |
100 | int32_t id; | |
101 | void *data; | |
102 | struct fsl_mc_resource_pool *parent_pool; | |
103 | struct list_head node; | |
104 | }; | |
105 | ||
bbf9d17d GR |
106 | /** |
107 | * Bit masks for a MC object device (struct fsl_mc_device) flags | |
108 | */ | |
109 | #define FSL_MC_IS_DPRC 0x0001 | |
110 | ||
111 | /** | |
112 | * Default DMA mask for devices on a fsl-mc bus | |
113 | */ | |
114 | #define FSL_MC_DEFAULT_DMA_MASK (~0ULL) | |
115 | ||
116 | /** | |
117 | * struct fsl_mc_device - MC object device object | |
118 | * @dev: Linux driver model device object | |
119 | * @dma_mask: Default DMA mask | |
120 | * @flags: MC object device flags | |
121 | * @icid: Isolation context ID for the device | |
122 | * @mc_handle: MC handle for the corresponding MC object opened | |
123 | * @mc_io: Pointer to MC IO object assigned to this device or | |
124 | * NULL if none. | |
125 | * @obj_desc: MC description of the DPAA device | |
126 | * @regions: pointer to array of MMIO region entries | |
197f4d6a | 127 | * @resource: generic resource associated with this MC object device, if any. |
bbf9d17d GR |
128 | * |
129 | * Generic device object for MC object devices that are "attached" to a | |
130 | * MC bus. | |
131 | * | |
132 | * NOTES: | |
133 | * - For a non-DPRC object its icid is the same as its parent DPRC's icid. | |
134 | * - The SMMU notifier callback gets invoked after device_add() has been | |
135 | * called for an MC object device, but before the device-specific probe | |
136 | * callback gets called. | |
197f4d6a GR |
137 | * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC |
138 | * portals. For all other MC objects, their device drivers are responsible for | |
139 | * allocating MC portals for them by calling fsl_mc_portal_allocate(). | |
140 | * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are | |
141 | * treated as resources that can be allocated/deallocated from the | |
142 | * corresponding resource pool in the object's parent DPRC, using the | |
143 | * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects | |
144 | * are known as "allocatable" objects. For them, the corresponding | |
145 | * fsl_mc_device's 'resource' points to the associated resource object. | |
146 | * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI), | |
147 | * 'resource' is NULL. | |
bbf9d17d GR |
148 | */ |
149 | struct fsl_mc_device { | |
150 | struct device dev; | |
151 | uint64_t dma_mask; | |
152 | uint16_t flags; | |
153 | uint16_t icid; | |
154 | uint16_t mc_handle; | |
155 | struct fsl_mc_io *mc_io; | |
156 | struct dprc_obj_desc obj_desc; | |
157 | struct resource *regions; | |
197f4d6a | 158 | struct fsl_mc_resource *resource; |
bbf9d17d GR |
159 | }; |
160 | ||
161 | #define to_fsl_mc_device(_dev) \ | |
162 | container_of(_dev, struct fsl_mc_device, dev) | |
163 | ||
164 | /* | |
165 | * module_fsl_mc_driver() - Helper macro for drivers that don't do | |
166 | * anything special in module init/exit. This eliminates a lot of | |
167 | * boilerplate. Each module may only use this macro once, and | |
168 | * calling it replaces module_init() and module_exit() | |
169 | */ | |
170 | #define module_fsl_mc_driver(__fsl_mc_driver) \ | |
171 | module_driver(__fsl_mc_driver, fsl_mc_driver_register, \ | |
172 | fsl_mc_driver_unregister) | |
173 | ||
174 | /* | |
175 | * Macro to avoid include chaining to get THIS_MODULE | |
176 | */ | |
177 | #define fsl_mc_driver_register(drv) \ | |
178 | __fsl_mc_driver_register(drv, THIS_MODULE) | |
179 | ||
180 | int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver, | |
181 | struct module *owner); | |
182 | ||
183 | void fsl_mc_driver_unregister(struct fsl_mc_driver *driver); | |
184 | ||
197f4d6a GR |
185 | int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, |
186 | uint16_t mc_io_flags, | |
187 | struct fsl_mc_io **new_mc_io); | |
188 | ||
189 | void fsl_mc_portal_free(struct fsl_mc_io *mc_io); | |
190 | ||
191 | int fsl_mc_portal_reset(struct fsl_mc_io *mc_io); | |
192 | ||
193 | int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev, | |
194 | enum fsl_mc_pool_type pool_type, | |
195 | struct fsl_mc_device **new_mc_adev); | |
196 | ||
197 | void fsl_mc_object_free(struct fsl_mc_device *mc_adev); | |
198 | ||
bbf9d17d GR |
199 | extern struct bus_type fsl_mc_bus_type; |
200 | ||
201 | #endif /* _FSL_MC_H_ */ |