1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2018 NXP
4  */
5 
6 #ifndef _FSL_ICID_H_
7 #define _FSL_ICID_H_
8 
9 #include <asm/types.h>
10 #include <fsl_qbman.h>
11 #include <fsl_sec.h>
12 
13 struct icid_id_table {
14 	const char *compat;
15 	u32 id;
16 	u32 reg;
17 	phys_addr_t compat_addr;
18 	phys_addr_t reg_addr;
19 };
20 
21 struct fman_icid_id_table {
22 	u32 port_id;
23 	u32 icid;
24 };
25 
26 u32 get_ppid_icid(int ppid_tbl_idx, int ppid);
27 int fdt_get_smmu_phandle(void *blob);
28 int fdt_set_iommu_prop(void *blob, int off, int smmu_ph, u32 *ids, int num_ids);
29 void set_icids(void);
30 void fdt_fixup_icid(void *blob);
31 
32 #define SET_ICID_ENTRY(name, idA, regA, addr, compataddr) \
33 	{ .compat = name, \
34 	  .id = idA, \
35 	  .reg = regA, \
36 	  .compat_addr = compataddr, \
37 	  .reg_addr = addr, \
38 	}
39 
40 #define SET_SCFG_ICID(compat, streamid, name, compataddr) \
41 	SET_ICID_ENTRY(compat, streamid, (((streamid) << 24) | (1 << 23)), \
42 		offsetof(struct ccsr_scfg, name) + CONFIG_SYS_FSL_SCFG_ADDR, \
43 		compataddr)
44 
45 #define SET_USB_ICID(usb_num, compat, streamid) \
46 	SET_SCFG_ICID(compat, streamid, usb##usb_num##_icid,\
47 		CONFIG_SYS_XHCI_USB##usb_num##_ADDR)
48 
49 #define SET_SATA_ICID(compat, streamid) \
50 	SET_SCFG_ICID(compat, streamid, sata_icid,\
51 		AHCI_BASE_ADDR)
52 
53 #define SET_SDHC_ICID(streamid) \
54 	SET_SCFG_ICID("fsl,esdhc", streamid, sdhc_icid,\
55 		CONFIG_SYS_FSL_ESDHC_ADDR)
56 
57 #define SET_QDMA_ICID(compat, streamid) \
58 	SET_SCFG_ICID(compat, streamid, dma_icid,\
59 		QDMA_BASE_ADDR)
60 
61 #define SET_EDMA_ICID(streamid) \
62 	SET_SCFG_ICID("fsl,vf610-edma", streamid, edma_icid,\
63 		EDMA_BASE_ADDR)
64 
65 #define SET_ETR_ICID(streamid) \
66 	SET_SCFG_ICID(NULL, streamid, etr_icid, 0)
67 
68 #define SET_DEBUG_ICID(streamid) \
69 	SET_SCFG_ICID(NULL, streamid, debug_icid, 0)
70 
71 #define SET_QE_ICID(streamid) \
72 	SET_SCFG_ICID("fsl,qe", streamid, qe_icid,\
73 		QE_BASE_ADDR)
74 
75 #define SET_QMAN_ICID(streamid) \
76 	SET_ICID_ENTRY("fsl,qman", streamid, streamid, \
77 		offsetof(struct ccsr_qman, liodnr) + \
78 		CONFIG_SYS_FSL_QMAN_ADDR, \
79 		CONFIG_SYS_FSL_QMAN_ADDR)
80 
81 #define SET_BMAN_ICID(streamid) \
82 	SET_ICID_ENTRY("fsl,bman", streamid, streamid, \
83 		offsetof(struct ccsr_bman, liodnr) + \
84 		CONFIG_SYS_FSL_BMAN_ADDR, \
85 		CONFIG_SYS_FSL_BMAN_ADDR)
86 
87 #define SET_FMAN_ICID_ENTRY(_port_id, streamid) \
88 	{ .port_id = (_port_id), .icid = (streamid) }
89 
90 #define SET_SEC_QI_ICID(streamid) \
91 	SET_ICID_ENTRY("fsl,sec-v4.0", streamid, \
92 		(((streamid) << 16) | (streamid)), \
93 		offsetof(ccsr_sec_t, qilcr_ls) + \
94 		CONFIG_SYS_FSL_SEC_ADDR, \
95 		CONFIG_SYS_FSL_SEC_ADDR)
96 
97 #define SET_SEC_JR_ICID_ENTRY(jr_num, streamid) \
98 	SET_ICID_ENTRY("fsl,sec-v4.0-job-ring", streamid, \
99 		(((streamid) << 16) | (streamid)), \
100 		offsetof(ccsr_sec_t, jrliodnr[jr_num].ls) + \
101 		CONFIG_SYS_FSL_SEC_ADDR, \
102 		FSL_SEC_JR##jr_num##_BASE_ADDR)
103 
104 #define SET_SEC_DECO_ICID_ENTRY(deco_num, streamid) \
105 	SET_ICID_ENTRY(NULL, streamid, (((streamid) << 16) | (streamid)), \
106 		offsetof(ccsr_sec_t, decoliodnr[deco_num].ls) + \
107 		CONFIG_SYS_FSL_SEC_ADDR, 0)
108 
109 #define SET_SEC_RTIC_ICID_ENTRY(rtic_num, streamid) \
110 	SET_ICID_ENTRY(NULL, streamid, (((streamid) << 16) | (streamid)), \
111 		offsetof(ccsr_sec_t, rticliodnr[rtic_num].ls) + \
112 		CONFIG_SYS_FSL_SEC_ADDR, 0)
113 
114 extern struct icid_id_table icid_tbl[];
115 extern struct fman_icid_id_table fman_icid_tbl[];
116 extern int icid_tbl_sz;
117 extern int fman_icid_tbl_sz;
118 
119 #endif
120