1
2
3
4
5
6
7
8#ifndef _FSL_MC_PRIVATE_H_
9#define _FSL_MC_PRIVATE_H_
10
11#include <linux/fsl/mc.h>
12#include <linux/mutex.h>
13#include <linux/ioctl.h>
14#include <linux/miscdevice.h>
15
16
17
18
19
20
21#define DPMNG_CMD_BASE_VERSION 1
22#define DPMNG_CMD_ID_OFFSET 4
23
24#define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
25
26
27#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
28
29struct dpmng_rsp_get_version {
30 __le32 revision;
31 __le32 version_major;
32 __le32 version_minor;
33};
34
35
36
37
38
39
40#define DPMCP_MIN_VER_MAJOR 3
41#define DPMCP_MIN_VER_MINOR 0
42
43
44#define DPMCP_CMD_BASE_VERSION 1
45#define DPMCP_CMD_ID_OFFSET 4
46
47#define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
48
49
50#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
51#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
52#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
53
54struct dpmcp_cmd_open {
55 __le32 dpmcp_id;
56};
57
58
59
60
61int dpmcp_open(struct fsl_mc_io *mc_io,
62 u32 cmd_flags,
63 int dpmcp_id,
64 u16 *token);
65
66int dpmcp_close(struct fsl_mc_io *mc_io,
67 u32 cmd_flags,
68 u16 token);
69
70int dpmcp_reset(struct fsl_mc_io *mc_io,
71 u32 cmd_flags,
72 u16 token);
73
74
75
76
77
78
79#define DPRC_MIN_VER_MAJOR 6
80#define DPRC_MIN_VER_MINOR 0
81
82
83#define DPRC_CMD_BASE_VERSION 1
84#define DPRC_CMD_2ND_VERSION 2
85#define DPRC_CMD_3RD_VERSION 3
86#define DPRC_CMD_ID_OFFSET 4
87
88#define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
89#define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION)
90#define DPRC_CMD_V3(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_3RD_VERSION)
91
92
93#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
94#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
95#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
96
97#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
98#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
99#define DPRC_CMDID_RESET_CONT_V2 DPRC_CMD_V2(0x005)
100
101#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
102#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
103#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
104#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
105#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
106
107#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
108#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
109#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
110#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
111#define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E)
112#define DPRC_CMDID_GET_OBJ_REG_V3 DPRC_CMD_V3(0x15E)
113#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
114
115#define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C)
116
117struct dprc_cmd_open {
118 __le32 container_id;
119};
120
121struct dprc_cmd_reset_container {
122 __le32 child_container_id;
123 __le32 options;
124};
125
126struct dprc_cmd_set_irq {
127
128 __le32 irq_val;
129 u8 irq_index;
130 u8 pad[3];
131
132 __le64 irq_addr;
133
134 __le32 irq_num;
135};
136
137#define DPRC_ENABLE 0x1
138
139struct dprc_cmd_set_irq_enable {
140 u8 enable;
141 u8 pad[3];
142 u8 irq_index;
143};
144
145struct dprc_cmd_set_irq_mask {
146 __le32 mask;
147 u8 irq_index;
148};
149
150struct dprc_cmd_get_irq_status {
151 __le32 status;
152 u8 irq_index;
153};
154
155struct dprc_rsp_get_irq_status {
156 __le32 status;
157};
158
159struct dprc_cmd_clear_irq_status {
160 __le32 status;
161 u8 irq_index;
162};
163
164struct dprc_rsp_get_attributes {
165
166 __le32 container_id;
167 __le32 icid;
168
169 __le32 options;
170 __le32 portal_id;
171};
172
173struct dprc_rsp_get_obj_count {
174 __le32 pad;
175 __le32 obj_count;
176};
177
178struct dprc_cmd_get_obj {
179 __le32 obj_index;
180};
181
182struct dprc_rsp_get_obj {
183
184 __le32 pad0;
185 __le32 id;
186
187 __le16 vendor;
188 u8 irq_count;
189 u8 region_count;
190 __le32 state;
191
192 __le16 version_major;
193 __le16 version_minor;
194 __le16 flags;
195 __le16 pad1;
196
197 u8 type[16];
198
199 u8 label[16];
200};
201
202struct dprc_cmd_get_obj_region {
203
204 __le32 obj_id;
205 __le16 pad0;
206 u8 region_index;
207 u8 pad1;
208
209 __le64 pad2[2];
210
211 u8 obj_type[16];
212};
213
214struct dprc_rsp_get_obj_region {
215
216 __le64 pad0;
217
218 __le64 base_offset;
219
220 __le32 size;
221 u8 type;
222 u8 pad2[3];
223
224 __le32 flags;
225 __le32 pad3;
226
227
228 __le64 base_addr;
229};
230
231struct dprc_cmd_set_obj_irq {
232
233 __le32 irq_val;
234 u8 irq_index;
235 u8 pad[3];
236
237 __le64 irq_addr;
238
239 __le32 irq_num;
240 __le32 obj_id;
241
242 u8 obj_type[16];
243};
244
245struct dprc_cmd_get_connection {
246 __le32 ep1_id;
247 __le16 ep1_interface_id;
248 u8 pad[2];
249 u8 ep1_type[16];
250};
251
252struct dprc_rsp_get_connection {
253 __le64 pad[3];
254 __le32 ep2_id;
255 __le16 ep2_interface_id;
256 __le16 pad1;
257 u8 ep2_type[16];
258 __le32 state;
259};
260
261
262
263
264int dprc_open(struct fsl_mc_io *mc_io,
265 u32 cmd_flags,
266 int container_id,
267 u16 *token);
268
269int dprc_close(struct fsl_mc_io *mc_io,
270 u32 cmd_flags,
271 u16 token);
272
273
274
275
276#define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001
277
278#define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002
279
280
281
282
283#define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
284
285
286
287
288
289#define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
290
291
292#define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040
293
294
295
296
297
298
299
300struct dprc_irq_cfg {
301 phys_addr_t paddr;
302 u32 val;
303 int irq_num;
304};
305
306int dprc_set_irq(struct fsl_mc_io *mc_io,
307 u32 cmd_flags,
308 u16 token,
309 u8 irq_index,
310 struct dprc_irq_cfg *irq_cfg);
311
312int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
313 u32 cmd_flags,
314 u16 token,
315 u8 irq_index,
316 u8 en);
317
318int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
319 u32 cmd_flags,
320 u16 token,
321 u8 irq_index,
322 u32 mask);
323
324int dprc_get_irq_status(struct fsl_mc_io *mc_io,
325 u32 cmd_flags,
326 u16 token,
327 u8 irq_index,
328 u32 *status);
329
330int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
331 u32 cmd_flags,
332 u16 token,
333 u8 irq_index,
334 u32 status);
335
336
337
338
339
340
341
342
343struct dprc_attributes {
344 int container_id;
345 u32 icid;
346 int portal_id;
347 u64 options;
348};
349
350int dprc_get_attributes(struct fsl_mc_io *mc_io,
351 u32 cmd_flags,
352 u16 token,
353 struct dprc_attributes *attributes);
354
355int dprc_get_obj_count(struct fsl_mc_io *mc_io,
356 u32 cmd_flags,
357 u16 token,
358 int *obj_count);
359
360int dprc_get_obj(struct fsl_mc_io *mc_io,
361 u32 cmd_flags,
362 u16 token,
363 int obj_index,
364 struct fsl_mc_obj_desc *obj_desc);
365
366int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
367 u32 cmd_flags,
368 u16 token,
369 char *obj_type,
370 int obj_id,
371 u8 irq_index,
372 struct dprc_irq_cfg *irq_cfg);
373
374
375
376
377
378enum dprc_region_type {
379 DPRC_REGION_TYPE_MC_PORTAL,
380 DPRC_REGION_TYPE_QBMAN_PORTAL,
381 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL
382};
383
384
385
386
387
388
389
390
391
392
393
394struct dprc_region_desc {
395 u32 base_offset;
396 u32 size;
397 u32 flags;
398 enum dprc_region_type type;
399 u64 base_address;
400};
401
402int dprc_get_obj_region(struct fsl_mc_io *mc_io,
403 u32 cmd_flags,
404 u16 token,
405 char *obj_type,
406 int obj_id,
407 u8 region_index,
408 struct dprc_region_desc *region_desc);
409
410int dprc_get_api_version(struct fsl_mc_io *mc_io,
411 u32 cmd_flags,
412 u16 *major_ver,
413 u16 *minor_ver);
414
415int dprc_get_container_id(struct fsl_mc_io *mc_io,
416 u32 cmd_flags,
417 int *container_id);
418
419
420
421
422
423
424
425
426
427struct dprc_endpoint {
428 char type[16];
429 int id;
430 u16 if_id;
431};
432
433int dprc_get_connection(struct fsl_mc_io *mc_io,
434 u32 cmd_flags,
435 u16 token,
436 const struct dprc_endpoint *endpoint1,
437 struct dprc_endpoint *endpoint2,
438 int *state);
439
440
441
442
443
444
445#define DPBP_VER_MAJOR 3
446#define DPBP_VER_MINOR 2
447
448
449#define DPBP_CMD_BASE_VERSION 1
450#define DPBP_CMD_ID_OFFSET 4
451
452#define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
453
454
455#define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
456#define DPBP_CMDID_OPEN DPBP_CMD(0x804)
457
458#define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
459#define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
460#define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
461#define DPBP_CMDID_RESET DPBP_CMD(0x005)
462
463struct dpbp_cmd_open {
464 __le32 dpbp_id;
465};
466
467#define DPBP_ENABLE 0x1
468
469struct dpbp_rsp_get_attributes {
470
471 __le16 pad;
472 __le16 bpid;
473 __le32 id;
474
475 __le16 version_major;
476 __le16 version_minor;
477};
478
479
480
481
482
483
484#define DPCON_VER_MAJOR 3
485#define DPCON_VER_MINOR 2
486
487
488#define DPCON_CMD_BASE_VERSION 1
489#define DPCON_CMD_ID_OFFSET 4
490
491#define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
492
493
494#define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
495#define DPCON_CMDID_OPEN DPCON_CMD(0x808)
496
497#define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
498#define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
499#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
500#define DPCON_CMDID_RESET DPCON_CMD(0x005)
501
502#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
503
504struct dpcon_cmd_open {
505 __le32 dpcon_id;
506};
507
508#define DPCON_ENABLE 1
509
510struct dpcon_rsp_get_attr {
511
512 __le32 id;
513 __le16 qbman_ch_id;
514 u8 num_priorities;
515 u8 pad;
516};
517
518struct dpcon_cmd_set_notification {
519
520 __le32 dpio_id;
521 u8 priority;
522 u8 pad[3];
523
524 __le64 user_ctx;
525};
526
527
528
529
530
531
532
533
534
535
536
537
538struct fsl_mc_resource_pool {
539 enum fsl_mc_pool_type type;
540 int max_count;
541 int free_count;
542 struct mutex mutex;
543 struct list_head free_list;
544 struct fsl_mc_bus *mc_bus;
545};
546
547
548
549
550
551
552
553
554
555struct fsl_mc_uapi {
556 struct miscdevice misc;
557 struct device *device;
558 struct mutex mutex;
559 u32 local_instance_in_use;
560 struct fsl_mc_io *static_mc_io;
561};
562
563
564
565
566
567
568
569
570
571
572
573
574struct fsl_mc_bus {
575 struct fsl_mc_device mc_dev;
576 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
577 struct fsl_mc_device_irq *irq_resources;
578 struct mutex scan_mutex;
579 struct dprc_attributes dprc_attr;
580 struct fsl_mc_uapi uapi_misc;
581 int irq_enabled;
582};
583
584#define to_fsl_mc_bus(_mc_dev) \
585 container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
586
587int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
588 struct fsl_mc_io *mc_io,
589 struct device *parent_dev,
590 struct fsl_mc_device **new_mc_dev);
591
592void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
593
594int __init dprc_driver_init(void);
595
596void dprc_driver_exit(void);
597
598int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
599 bool alloc_interrupts);
600
601int __init fsl_mc_allocator_driver_init(void);
602
603void fsl_mc_allocator_driver_exit(void);
604
605void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
606
607void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev);
608
609int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
610 enum fsl_mc_pool_type pool_type,
611 struct fsl_mc_resource
612 **new_resource);
613
614void fsl_mc_resource_free(struct fsl_mc_resource *resource);
615
616int fsl_mc_msi_domain_alloc_irqs(struct device *dev,
617 unsigned int irq_count);
618
619void fsl_mc_msi_domain_free_irqs(struct device *dev);
620
621struct irq_domain *fsl_mc_find_msi_domain(struct device *dev);
622
623int __must_check fsl_create_mc_io(struct device *dev,
624 phys_addr_t mc_portal_phys_addr,
625 u32 mc_portal_size,
626 struct fsl_mc_device *dpmcp_dev,
627 u32 flags, struct fsl_mc_io **new_mc_io);
628
629void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
630
631bool fsl_mc_is_root_dprc(struct device *dev);
632
633void fsl_mc_get_root_dprc(struct device *dev,
634 struct device **root_dprc_dev);
635
636struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc,
637 struct fsl_mc_device *mc_bus_dev);
638
639u16 mc_cmd_hdr_read_cmdid(struct fsl_mc_command *cmd);
640
641#ifdef CONFIG_FSL_MC_UAPI_SUPPORT
642
643int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus);
644
645void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus);
646
647#else
648
649static inline int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus)
650{
651 return 0;
652}
653
654static inline void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus)
655{
656}
657
658#endif
659
660int disable_dprc_irq(struct fsl_mc_device *mc_dev);
661int enable_dprc_irq(struct fsl_mc_device *mc_dev);
662int get_dprc_irq_state(struct fsl_mc_device *mc_dev);
663
664#endif
665