kernel: bump 5.4 to 5.4.40
[openwrt/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0142-bus-fsl-mc-Some-apis-are-made-public-for-vfio.patch
1 From e8dd5b8ee227cc60f10073faaa0f74b36aa4f40f Mon Sep 17 00:00:00 2001
2 From: Laurentiu Tudor <laurentiu.tudor@nxp.com>
3 Date: Mon, 16 Apr 2018 12:26:38 +0300
4 Subject: [PATCH] bus: fsl-mc: Some apis are made public for vfio
5
6 Some of the APIs and data-structures are required for VFIO.
7 This patch moves dprc.h to public header files.
8 Also some APIs of mc-bus are made public for vfio.
9
10 Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
11 Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
12 ---
13 drivers/bus/fsl-mc/fsl-mc-allocator.c | 2 +
14 drivers/bus/fsl-mc/fsl-mc-bus.c | 5 +-
15 drivers/bus/fsl-mc/fsl-mc-private.h | 414 ---------------------------------
16 include/linux/fsl/mc.h | 420 ++++++++++++++++++++++++++++++++++
17 4 files changed, 425 insertions(+), 416 deletions(-)
18
19 --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
20 +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
21 @@ -547,6 +547,7 @@ void fsl_mc_init_all_resource_pools(stru
22 mutex_init(&res_pool->mutex);
23 }
24 }
25 +EXPORT_SYMBOL_GPL(fsl_mc_init_all_resource_pools);
26
27 static void fsl_mc_cleanup_resource_pool(struct fsl_mc_device *mc_bus_dev,
28 enum fsl_mc_pool_type pool_type)
29 @@ -571,6 +572,7 @@ void fsl_mc_cleanup_all_resource_pools(s
30 for (pool_type = 0; pool_type < FSL_MC_NUM_POOL_TYPES; pool_type++)
31 fsl_mc_cleanup_resource_pool(mc_bus_dev, pool_type);
32 }
33 +EXPORT_SYMBOL_GPL(fsl_mc_cleanup_all_resource_pools);
34
35 /**
36 * fsl_mc_allocator_probe - callback invoked when an allocatable device is
37 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
38 +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
39 @@ -447,8 +447,8 @@ static int mc_get_version(struct fsl_mc_
40 /**
41 * fsl_mc_get_root_dprc - function to traverse to the root dprc
42 */
43 -static void fsl_mc_get_root_dprc(struct device *dev,
44 - struct device **root_dprc_dev)
45 +void fsl_mc_get_root_dprc(struct device *dev,
46 + struct device **root_dprc_dev)
47 {
48 if (!dev) {
49 *root_dprc_dev = NULL;
50 @@ -460,6 +460,7 @@ static void fsl_mc_get_root_dprc(struct
51 *root_dprc_dev = (*root_dprc_dev)->parent;
52 }
53 }
54 +EXPORT_SYMBOL_GPL(fsl_mc_get_root_dprc);
55
56 static int get_dprc_attr(struct fsl_mc_io *mc_io,
57 int container_id, struct dprc_attributes *attr)
58 --- a/drivers/bus/fsl-mc/fsl-mc-private.h
59 +++ b/drivers/bus/fsl-mc/fsl-mc-private.h
60 @@ -10,8 +10,6 @@
61
62 #include <linux/fsl/mc.h>
63 #include <linux/mutex.h>
64 -#include <linux/ioctl.h>
65 -#include <linux/miscdevice.h>
66
67 /*
68 * Data Path Management Complex (DPMNG) General API
69 @@ -72,339 +70,6 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
70 u16 token);
71
72 /*
73 - * Data Path Resource Container (DPRC) API
74 - */
75 -
76 -/* Minimal supported DPRC Version */
77 -#define DPRC_MIN_VER_MAJOR 6
78 -#define DPRC_MIN_VER_MINOR 0
79 -
80 -/* DPRC command versioning */
81 -#define DPRC_CMD_BASE_VERSION 1
82 -#define DPRC_CMD_2ND_VERSION 2
83 -#define DPRC_CMD_ID_OFFSET 4
84 -
85 -#define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
86 -#define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
87 -
88 -/* DPRC command IDs */
89 -#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
90 -#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
91 -#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
92 -
93 -#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
94 -#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
95 -
96 -#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
97 -#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
98 -#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
99 -#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
100 -#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
101 -
102 -#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
103 -#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
104 -#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
105 -#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
106 -#define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
107 -#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
108 -
109 -struct dprc_cmd_open {
110 - __le32 container_id;
111 -};
112 -
113 -struct dprc_cmd_reset_container {
114 - __le32 child_container_id;
115 -};
116 -
117 -struct dprc_cmd_set_irq {
118 - /* cmd word 0 */
119 - __le32 irq_val;
120 - u8 irq_index;
121 - u8 pad[3];
122 - /* cmd word 1 */
123 - __le64 irq_addr;
124 - /* cmd word 2 */
125 - __le32 irq_num;
126 -};
127 -
128 -#define DPRC_ENABLE 0x1
129 -
130 -struct dprc_cmd_set_irq_enable {
131 - u8 enable;
132 - u8 pad[3];
133 - u8 irq_index;
134 -};
135 -
136 -struct dprc_cmd_set_irq_mask {
137 - __le32 mask;
138 - u8 irq_index;
139 -};
140 -
141 -struct dprc_cmd_get_irq_status {
142 - __le32 status;
143 - u8 irq_index;
144 -};
145 -
146 -struct dprc_rsp_get_irq_status {
147 - __le32 status;
148 -};
149 -
150 -struct dprc_cmd_clear_irq_status {
151 - __le32 status;
152 - u8 irq_index;
153 -};
154 -
155 -struct dprc_rsp_get_attributes {
156 - /* response word 0 */
157 - __le32 container_id;
158 - __le32 icid;
159 - /* response word 1 */
160 - __le32 options;
161 - __le32 portal_id;
162 -};
163 -
164 -struct dprc_rsp_get_obj_count {
165 - __le32 pad;
166 - __le32 obj_count;
167 -};
168 -
169 -struct dprc_cmd_get_obj {
170 - __le32 obj_index;
171 -};
172 -
173 -struct dprc_rsp_get_obj {
174 - /* response word 0 */
175 - __le32 pad0;
176 - __le32 id;
177 - /* response word 1 */
178 - __le16 vendor;
179 - u8 irq_count;
180 - u8 region_count;
181 - __le32 state;
182 - /* response word 2 */
183 - __le16 version_major;
184 - __le16 version_minor;
185 - __le16 flags;
186 - __le16 pad1;
187 - /* response word 3-4 */
188 - u8 type[16];
189 - /* response word 5-6 */
190 - u8 label[16];
191 -};
192 -
193 -struct dprc_cmd_get_obj_region {
194 - /* cmd word 0 */
195 - __le32 obj_id;
196 - __le16 pad0;
197 - u8 region_index;
198 - u8 pad1;
199 - /* cmd word 1-2 */
200 - __le64 pad2[2];
201 - /* cmd word 3-4 */
202 - u8 obj_type[16];
203 -};
204 -
205 -struct dprc_rsp_get_obj_region {
206 - /* response word 0 */
207 - __le64 pad0;
208 - /* response word 1 */
209 - __le64 base_offset;
210 - /* response word 2 */
211 - __le32 size;
212 - u8 type;
213 - u8 pad2[3];
214 - /* response word 3 */
215 - __le32 flags;
216 - __le32 pad3;
217 - /* response word 4 */
218 - /* base_addr may be zero if older MC firmware is used */
219 - __le64 base_addr;
220 -};
221 -
222 -struct dprc_cmd_set_obj_irq {
223 - /* cmd word 0 */
224 - __le32 irq_val;
225 - u8 irq_index;
226 - u8 pad[3];
227 - /* cmd word 1 */
228 - __le64 irq_addr;
229 - /* cmd word 2 */
230 - __le32 irq_num;
231 - __le32 obj_id;
232 - /* cmd word 3-4 */
233 - u8 obj_type[16];
234 -};
235 -
236 -/*
237 - * DPRC API for managing and querying DPAA resources
238 - */
239 -int dprc_open(struct fsl_mc_io *mc_io,
240 - u32 cmd_flags,
241 - int container_id,
242 - u16 *token);
243 -
244 -int dprc_close(struct fsl_mc_io *mc_io,
245 - u32 cmd_flags,
246 - u16 token);
247 -
248 -/* DPRC IRQ events */
249 -
250 -/* IRQ event - Indicates that a new object added to the container */
251 -#define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
252 -/* IRQ event - Indicates that an object was removed from the container */
253 -#define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
254 -/*
255 - * IRQ event - Indicates that one of the descendant containers that opened by
256 - * this container is destroyed
257 - */
258 -#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
259 -
260 -/*
261 - * IRQ event - Indicates that on one of the container's opened object is
262 - * destroyed
263 - */
264 -#define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
265 -
266 -/* Irq event - Indicates that object is created at the container */
267 -#define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
268 -
269 -/**
270 - * struct dprc_irq_cfg - IRQ configuration
271 - * @paddr: Address that must be written to signal a message-based interrupt
272 - * @val: Value to write into irq_addr address
273 - * @irq_num: A user defined number associated with this IRQ
274 - */
275 -struct dprc_irq_cfg {
276 - phys_addr_t paddr;
277 - u32 val;
278 - int irq_num;
279 -};
280 -
281 -int dprc_set_irq(struct fsl_mc_io *mc_io,
282 - u32 cmd_flags,
283 - u16 token,
284 - u8 irq_index,
285 - struct dprc_irq_cfg *irq_cfg);
286 -
287 -int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
288 - u32 cmd_flags,
289 - u16 token,
290 - u8 irq_index,
291 - u8 en);
292 -
293 -int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
294 - u32 cmd_flags,
295 - u16 token,
296 - u8 irq_index,
297 - u32 mask);
298 -
299 -int dprc_get_irq_status(struct fsl_mc_io *mc_io,
300 - u32 cmd_flags,
301 - u16 token,
302 - u8 irq_index,
303 - u32 *status);
304 -
305 -int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
306 - u32 cmd_flags,
307 - u16 token,
308 - u8 irq_index,
309 - u32 status);
310 -
311 -/**
312 - * struct dprc_attributes - Container attributes
313 - * @container_id: Container's ID
314 - * @icid: Container's ICID
315 - * @portal_id: Container's portal ID
316 - * @options: Container's options as set at container's creation
317 - */
318 -struct dprc_attributes {
319 - int container_id;
320 - u32 icid;
321 - int portal_id;
322 - u64 options;
323 -};
324 -
325 -int dprc_get_attributes(struct fsl_mc_io *mc_io,
326 - u32 cmd_flags,
327 - u16 token,
328 - struct dprc_attributes *attributes);
329 -
330 -int dprc_get_obj_count(struct fsl_mc_io *mc_io,
331 - u32 cmd_flags,
332 - u16 token,
333 - int *obj_count);
334 -
335 -int dprc_get_obj(struct fsl_mc_io *mc_io,
336 - u32 cmd_flags,
337 - u16 token,
338 - int obj_index,
339 - struct fsl_mc_obj_desc *obj_desc);
340 -
341 -int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
342 - u32 cmd_flags,
343 - u16 token,
344 - char *obj_type,
345 - int obj_id,
346 - u8 irq_index,
347 - struct dprc_irq_cfg *irq_cfg);
348 -
349 -/* Region flags */
350 -/* Cacheable - Indicates that region should be mapped as cacheable */
351 -#define DPRC_REGION_CACHEABLE 0x00000001
352 -#define DPRC_REGION_SHAREABLE 0x00000002
353 -
354 -/**
355 - * enum dprc_region_type - Region type
356 - * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
357 - * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
358 - */
359 -enum dprc_region_type {
360 - DPRC_REGION_TYPE_MC_PORTAL,
361 - DPRC_REGION_TYPE_QBMAN_PORTAL,
362 - DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
363 -};
364 -
365 -/**
366 - * struct dprc_region_desc - Mappable region descriptor
367 - * @base_offset: Region offset from region's base address.
368 - * For DPMCP and DPRC objects, region base is offset from SoC MC portals
369 - * base address; For DPIO, region base is offset from SoC QMan portals
370 - * base address
371 - * @size: Region size (in bytes)
372 - * @flags: Region attributes
373 - * @type: Portal region type
374 - */
375 -struct dprc_region_desc {
376 - u32 base_offset;
377 - u32 size;
378 - u32 flags;
379 - enum dprc_region_type type;
380 - u64 base_address;
381 -};
382 -
383 -int dprc_get_obj_region(struct fsl_mc_io *mc_io,
384 - u32 cmd_flags,
385 - u16 token,
386 - char *obj_type,
387 - int obj_id,
388 - u8 region_index,
389 - struct dprc_region_desc *region_desc);
390 -
391 -int dprc_get_api_version(struct fsl_mc_io *mc_io,
392 - u32 cmd_flags,
393 - u16 *major_ver,
394 - u16 *minor_ver);
395 -
396 -int dprc_get_container_id(struct fsl_mc_io *mc_io,
397 - u32 cmd_flags,
398 - int *container_id);
399 -
400 -int dprc_reset_container(struct fsl_mc_io *mc_io,
401 - u32 cmd_flags,
402 - u16 token,
403 - int child_container_id);
404 -
405 -/*
406 * Data Path Buffer Pool (DPBP) API
407 */
408
409 @@ -491,70 +156,6 @@ struct dpcon_cmd_set_notification {
410 __le64 user_ctx;
411 };
412
413 -/**
414 - * Maximum number of total IRQs that can be pre-allocated for an MC bus'
415 - * IRQ pool
416 - */
417 -#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
418 -
419 -/**
420 - * struct fsl_mc_resource_pool - Pool of MC resources of a given
421 - * type
422 - * @type: type of resources in the pool
423 - * @max_count: maximum number of resources in the pool
424 - * @free_count: number of free resources in the pool
425 - * @mutex: mutex to serialize access to the pool's free list
426 - * @free_list: anchor node of list of free resources in the pool
427 - * @mc_bus: pointer to the MC bus that owns this resource pool
428 - */
429 -struct fsl_mc_resource_pool {
430 - enum fsl_mc_pool_type type;
431 - int max_count;
432 - int free_count;
433 - struct mutex mutex; /* serializes access to free_list */
434 - struct list_head free_list;
435 - struct fsl_mc_bus *mc_bus;
436 -};
437 -
438 -/**
439 - * struct fsl_mc_uapi - information associated with a device file
440 - * @misc: struct miscdevice linked to the root dprc
441 - * @device: newly created device in /dev
442 - * @mutex: mutex lock to serialize the open/release operations
443 - * @local_instance_in_use: local MC I/O instance in use or not
444 - * @static_mc_io: pointer to the static MC I/O object
445 - */
446 -struct fsl_mc_uapi {
447 - struct miscdevice misc;
448 - struct device *device;
449 - struct mutex mutex; /* serialize open/release operations */
450 - u32 local_instance_in_use;
451 - struct fsl_mc_io *static_mc_io;
452 -};
453 -
454 -/**
455 - * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
456 - * @mc_dev: fsl-mc device for the bus device itself.
457 - * @resource_pools: array of resource pools (one pool per resource type)
458 - * for this MC bus. These resources represent allocatable entities
459 - * from the physical DPRC.
460 - * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
461 - * @scan_mutex: Serializes bus scanning
462 - * @dprc_attr: DPRC attributes
463 - * @uapi_misc: struct that abstracts the interaction with userspace
464 - */
465 -struct fsl_mc_bus {
466 - struct fsl_mc_device mc_dev;
467 - struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
468 - struct fsl_mc_device_irq *irq_resources;
469 - struct mutex scan_mutex; /* serializes bus scanning */
470 - struct dprc_attributes dprc_attr;
471 - struct fsl_mc_uapi uapi_misc;
472 -};
473 -
474 -#define to_fsl_mc_bus(_mc_dev) \
475 - container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
476 -
477 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
478 struct fsl_mc_io *mc_io,
479 struct device *parent_dev,
480 @@ -565,17 +166,10 @@ int __init dprc_driver_init(void);
481
482 void dprc_driver_exit(void);
483
484 -int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
485 - const char *driver_override,
486 - unsigned int *total_irq_count);
487 int __init fsl_mc_allocator_driver_init(void);
488
489 void fsl_mc_allocator_driver_exit(void);
490
491 -void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
492 -
493 -void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
494 -
495 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
496 enum fsl_mc_pool_type pool_type,
497 struct fsl_mc_resource
498 @@ -588,14 +182,6 @@ int fsl_mc_msi_domain_alloc_irqs(struct
499
500 void fsl_mc_msi_domain_free_irqs(struct device *dev);
501
502 -int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
503 - struct irq_domain **mc_msi_domain);
504 -
505 -int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
506 - unsigned int irq_count);
507 -
508 -void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
509 -
510 int __must_check fsl_create_mc_io(struct device *dev,
511 phys_addr_t mc_portal_phys_addr,
512 u32 mc_portal_size,
513 --- a/include/linux/fsl/mc.h
514 +++ b/include/linux/fsl/mc.h
515 @@ -12,6 +12,8 @@
516 #include <linux/device.h>
517 #include <linux/mod_devicetable.h>
518 #include <linux/interrupt.h>
519 +#include <linux/ioctl.h>
520 +#include <linux/miscdevice.h>
521 #include <uapi/linux/fsl_mc.h>
522
523 #define FSL_MC_VENDOR_FREESCALE 0x1957
524 @@ -49,6 +51,9 @@ struct fsl_mc_driver {
525 #define to_fsl_mc_driver(_drv) \
526 container_of(_drv, struct fsl_mc_driver, driver)
527
528 +#define to_fsl_mc_bus(_mc_dev) \
529 + container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
530 +
531 /**
532 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
533 *
534 @@ -469,6 +474,339 @@ static inline bool is_fsl_mc_bus_dpseci(
535 }
536
537 /*
538 + * Data Path Resource Container (DPRC) API
539 + */
540 +
541 +/* Minimal supported DPRC Version */
542 +#define DPRC_MIN_VER_MAJOR 6
543 +#define DPRC_MIN_VER_MINOR 0
544 +
545 +/* DPRC command versioning */
546 +#define DPRC_CMD_BASE_VERSION 1
547 +#define DPRC_CMD_2ND_VERSION 2
548 +#define DPRC_CMD_ID_OFFSET 4
549 +
550 +#define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
551 +#define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
552 +
553 +/* DPRC command IDs */
554 +#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
555 +#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
556 +#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
557 +
558 +#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
559 +#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
560 +
561 +#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
562 +#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
563 +#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
564 +#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
565 +#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
566 +
567 +#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
568 +#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
569 +#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
570 +#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
571 +#define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
572 +#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
573 +
574 +struct dprc_cmd_open {
575 + __le32 container_id;
576 +};
577 +
578 +struct dprc_cmd_reset_container {
579 + __le32 child_container_id;
580 +};
581 +
582 +struct dprc_cmd_set_irq {
583 + /* cmd word 0 */
584 + __le32 irq_val;
585 + u8 irq_index;
586 + u8 pad[3];
587 + /* cmd word 1 */
588 + __le64 irq_addr;
589 + /* cmd word 2 */
590 + __le32 irq_num;
591 +};
592 +
593 +#define DPRC_ENABLE 0x1
594 +
595 +struct dprc_cmd_set_irq_enable {
596 + u8 enable;
597 + u8 pad[3];
598 + u8 irq_index;
599 +};
600 +
601 +struct dprc_cmd_set_irq_mask {
602 + __le32 mask;
603 + u8 irq_index;
604 +};
605 +
606 +struct dprc_cmd_get_irq_status {
607 + __le32 status;
608 + u8 irq_index;
609 +};
610 +
611 +struct dprc_rsp_get_irq_status {
612 + __le32 status;
613 +};
614 +
615 +struct dprc_cmd_clear_irq_status {
616 + __le32 status;
617 + u8 irq_index;
618 +};
619 +
620 +struct dprc_rsp_get_attributes {
621 + /* response word 0 */
622 + __le32 container_id;
623 + __le32 icid;
624 + /* response word 1 */
625 + __le32 options;
626 + __le32 portal_id;
627 +};
628 +
629 +struct dprc_rsp_get_obj_count {
630 + __le32 pad;
631 + __le32 obj_count;
632 +};
633 +
634 +struct dprc_cmd_get_obj {
635 + __le32 obj_index;
636 +};
637 +
638 +struct dprc_rsp_get_obj {
639 + /* response word 0 */
640 + __le32 pad0;
641 + __le32 id;
642 + /* response word 1 */
643 + __le16 vendor;
644 + u8 irq_count;
645 + u8 region_count;
646 + __le32 state;
647 + /* response word 2 */
648 + __le16 version_major;
649 + __le16 version_minor;
650 + __le16 flags;
651 + __le16 pad1;
652 + /* response word 3-4 */
653 + u8 type[16];
654 + /* response word 5-6 */
655 + u8 label[16];
656 +};
657 +
658 +struct dprc_cmd_get_obj_region {
659 + /* cmd word 0 */
660 + __le32 obj_id;
661 + __le16 pad0;
662 + u8 region_index;
663 + u8 pad1;
664 + /* cmd word 1-2 */
665 + __le64 pad2[2];
666 + /* cmd word 3-4 */
667 + u8 obj_type[16];
668 +};
669 +
670 +struct dprc_rsp_get_obj_region {
671 + /* response word 0 */
672 + __le64 pad0;
673 + /* response word 1 */
674 + __le64 base_offset;
675 + /* response word 2 */
676 + __le32 size;
677 + u8 type;
678 + u8 pad2[3];
679 + /* response word 3 */
680 + __le32 flags;
681 + __le32 pad3;
682 + /* response word 4 */
683 + /* base_addr may be zero if older MC firmware is used */
684 + __le64 base_addr;
685 +};
686 +
687 +struct dprc_cmd_set_obj_irq {
688 + /* cmd word 0 */
689 + __le32 irq_val;
690 + u8 irq_index;
691 + u8 pad[3];
692 + /* cmd word 1 */
693 + __le64 irq_addr;
694 + /* cmd word 2 */
695 + __le32 irq_num;
696 + __le32 obj_id;
697 + /* cmd word 3-4 */
698 + u8 obj_type[16];
699 +};
700 +
701 +/*
702 + * DPRC API for managing and querying DPAA resources
703 + */
704 +int dprc_open(struct fsl_mc_io *mc_io,
705 + u32 cmd_flags,
706 + int container_id,
707 + u16 *token);
708 +
709 +int dprc_close(struct fsl_mc_io *mc_io,
710 + u32 cmd_flags,
711 + u16 token);
712 +
713 +/* DPRC IRQ events */
714 +
715 +/* IRQ event - Indicates that a new object added to the container */
716 +#define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
717 +/* IRQ event - Indicates that an object was removed from the container */
718 +#define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
719 +/*
720 + * IRQ event - Indicates that one of the descendant containers that opened by
721 + * this container is destroyed
722 + */
723 +#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
724 +
725 +/*
726 + * IRQ event - Indicates that on one of the container's opened object is
727 + * destroyed
728 + */
729 +#define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
730 +
731 +/* Irq event - Indicates that object is created at the container */
732 +#define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
733 +
734 +/**
735 + * struct dprc_irq_cfg - IRQ configuration
736 + * @paddr: Address that must be written to signal a message-based interrupt
737 + * @val: Value to write into irq_addr address
738 + * @irq_num: A user defined number associated with this IRQ
739 + */
740 +struct dprc_irq_cfg {
741 + phys_addr_t paddr;
742 + u32 val;
743 + int irq_num;
744 +};
745 +
746 +int dprc_set_irq(struct fsl_mc_io *mc_io,
747 + u32 cmd_flags,
748 + u16 token,
749 + u8 irq_index,
750 + struct dprc_irq_cfg *irq_cfg);
751 +
752 +int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
753 + u32 cmd_flags,
754 + u16 token,
755 + u8 irq_index,
756 + u8 en);
757 +
758 +int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
759 + u32 cmd_flags,
760 + u16 token,
761 + u8 irq_index,
762 + u32 mask);
763 +
764 +int dprc_get_irq_status(struct fsl_mc_io *mc_io,
765 + u32 cmd_flags,
766 + u16 token,
767 + u8 irq_index,
768 + u32 *status);
769 +
770 +int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
771 + u32 cmd_flags,
772 + u16 token,
773 + u8 irq_index,
774 + u32 status);
775 +
776 +/**
777 + * struct dprc_attributes - Container attributes
778 + * @container_id: Container's ID
779 + * @icid: Container's ICID
780 + * @portal_id: Container's portal ID
781 + * @options: Container's options as set at container's creation
782 + */
783 +struct dprc_attributes {
784 + int container_id;
785 + u32 icid;
786 + int portal_id;
787 + u64 options;
788 +};
789 +
790 +int dprc_get_attributes(struct fsl_mc_io *mc_io,
791 + u32 cmd_flags,
792 + u16 token,
793 + struct dprc_attributes *attributes);
794 +
795 +int dprc_get_obj_count(struct fsl_mc_io *mc_io,
796 + u32 cmd_flags,
797 + u16 token,
798 + int *obj_count);
799 +
800 +int dprc_get_obj(struct fsl_mc_io *mc_io,
801 + u32 cmd_flags,
802 + u16 token,
803 + int obj_index,
804 + struct fsl_mc_obj_desc *obj_desc);
805 +
806 +int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
807 + u32 cmd_flags,
808 + u16 token,
809 + char *obj_type,
810 + int obj_id,
811 + u8 irq_index,
812 + struct dprc_irq_cfg *irq_cfg);
813 +
814 +/* Region flags */
815 +/* Cacheable - Indicates that region should be mapped as cacheable */
816 +#define DPRC_REGION_CACHEABLE 0x00000001
817 +#define DPRC_REGION_SHAREABLE 0x00000002
818 +
819 +/**
820 + * enum dprc_region_type - Region type
821 + * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
822 + * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
823 + */
824 +enum dprc_region_type {
825 + DPRC_REGION_TYPE_MC_PORTAL,
826 + DPRC_REGION_TYPE_QBMAN_PORTAL,
827 + DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
828 +};
829 +
830 +/**
831 + * struct dprc_region_desc - Mappable region descriptor
832 + * @base_offset: Region offset from region's base address.
833 + * For DPMCP and DPRC objects, region base is offset from SoC MC portals
834 + * base address; For DPIO, region base is offset from SoC QMan portals
835 + * base address
836 + * @size: Region size (in bytes)
837 + * @flags: Region attributes
838 + * @type: Portal region type
839 + */
840 +struct dprc_region_desc {
841 + u32 base_offset;
842 + u32 size;
843 + u32 flags;
844 + enum dprc_region_type type;
845 + u64 base_address;
846 +};
847 +
848 +int dprc_get_obj_region(struct fsl_mc_io *mc_io,
849 + u32 cmd_flags,
850 + u16 token,
851 + char *obj_type,
852 + int obj_id,
853 + u8 region_index,
854 + struct dprc_region_desc *region_desc);
855 +
856 +int dprc_get_api_version(struct fsl_mc_io *mc_io,
857 + u32 cmd_flags,
858 + u16 *major_ver,
859 + u16 *minor_ver);
860 +
861 +int dprc_get_container_id(struct fsl_mc_io *mc_io,
862 + u32 cmd_flags,
863 + int *container_id);
864 +
865 +int dprc_reset_container(struct fsl_mc_io *mc_io,
866 + u32 cmd_flags,
867 + u16 token,
868 + int child_container_id);
869 +
870 +/*
871 * Data Path Buffer Pool (DPBP) API
872 * Contains initialization APIs and runtime control APIs for DPBP
873 */
874 @@ -576,4 +914,86 @@ int dpcon_set_notification(struct fsl_mc
875 u16 token,
876 struct dpcon_notification_cfg *cfg);
877
878 +struct irq_domain;
879 +struct msi_domain_info;
880 +
881 +/**
882 + * Maximum number of total IRQs that can be pre-allocated for an MC bus'
883 + * IRQ pool
884 + */
885 +#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
886 +
887 +/**
888 + * struct fsl_mc_resource_pool - Pool of MC resources of a given
889 + * type
890 + * @type: type of resources in the pool
891 + * @max_count: maximum number of resources in the pool
892 + * @free_count: number of free resources in the pool
893 + * @mutex: mutex to serialize access to the pool's free list
894 + * @free_list: anchor node of list of free resources in the pool
895 + * @mc_bus: pointer to the MC bus that owns this resource pool
896 + */
897 +struct fsl_mc_resource_pool {
898 + enum fsl_mc_pool_type type;
899 + int max_count;
900 + int free_count;
901 + struct mutex mutex; /* serializes access to free_list */
902 + struct list_head free_list;
903 + struct fsl_mc_bus *mc_bus;
904 +};
905 +
906 +/**
907 + * struct fsl_mc_uapi - information associated with a device file
908 + * @misc: struct miscdevice linked to the root dprc
909 + * @device: newly created device in /dev
910 + * @mutex: mutex lock to serialize the open/release operations
911 + * @local_instance_in_use: local MC I/O instance in use or not
912 + * @static_mc_io: pointer to the static MC I/O object
913 + */
914 +struct fsl_mc_uapi {
915 + struct miscdevice misc;
916 + struct device *device;
917 + struct mutex mutex; /* serialize open/release operations */
918 + u32 local_instance_in_use;
919 + struct fsl_mc_io *static_mc_io;
920 +};
921 +
922 +/**
923 + * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
924 + * @mc_dev: fsl-mc device for the bus device itself.
925 + * @resource_pools: array of resource pools (one pool per resource type)
926 + * for this MC bus. These resources represent allocatable entities
927 + * from the physical DPRC.
928 + * @irq_resources: Pointer to array of IRQ objects for the IRQ pool
929 + * @scan_mutex: Serializes bus scanning
930 + * @dprc_attr: DPRC attributes
931 + * @uapi_misc: struct that abstracts the interaction with userspace
932 + */
933 +struct fsl_mc_bus {
934 + struct fsl_mc_device mc_dev;
935 + struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
936 + struct fsl_mc_device_irq *irq_resources;
937 + struct mutex scan_mutex; /* serializes bus scanning */
938 + struct dprc_attributes dprc_attr;
939 + struct fsl_mc_uapi uapi_misc;
940 +};
941 +
942 +int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
943 + const char *driver_override,
944 + unsigned int *total_irq_count);
945 +
946 +int fsl_mc_find_msi_domain(struct device *mc_platform_dev,
947 + struct irq_domain **mc_msi_domain);
948 +
949 +int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
950 + unsigned int irq_count);
951 +
952 +void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus);
953 +
954 +void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
955 +
956 +void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
957 +
958 +void fsl_mc_get_root_dprc(struct device *dev, struct device **root_dprc_dev);
959 +
960 #endif /* _FSL_MC_H_ */