blob: d5f63f4a7ed76f3e9a665a0b0cddb05c2bc20ccb [file] [log] [blame]
Laurentiu Tudor512d13e2018-08-09 15:19:46 +03001/* 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>
Laurentiu Tudor3987b042018-08-09 15:19:49 +030011#include <fsl_sec.h>
Laurentiu Tudor96a37ef2019-02-26 13:18:34 +020012#include <asm/armv8/sec_firmware.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030013
14struct icid_id_table {
Sean Andersonc0ca4bc2022-10-17 11:45:11 -040015#ifndef CONFIG_SPL_BUILD
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030016 const char *compat;
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030017 phys_addr_t compat_addr;
Sean Andersonc0ca4bc2022-10-17 11:45:11 -040018#endif
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030019 phys_addr_t reg_addr;
Sean Andersonc0ca4bc2022-10-17 11:45:11 -040020 u32 reg;
21#ifndef CONFIG_SPL_BUILD
22 u32 id;
23#endif
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +030024 bool le;
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030025};
26
Laurentiu Tudordcb7f3d2018-08-09 15:19:48 +030027struct fman_icid_id_table {
28 u32 port_id;
29 u32 icid;
30};
31
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030032u32 get_ppid_icid(int ppid_tbl_idx, int ppid);
33int fdt_get_smmu_phandle(void *blob);
34int fdt_set_iommu_prop(void *blob, int off, int smmu_ph, u32 *ids, int num_ids);
35void set_icids(void);
36void fdt_fixup_icid(void *blob);
37
Sean Andersonc0ca4bc2022-10-17 11:45:11 -040038#ifdef CONFIG_SPL_BUILD
39#define SET_ICID_ENTRY(name, idA, regA, addr, compataddr, _le) \
40 { .reg = regA, \
41 .reg_addr = addr, \
42 .le = _le \
43 }
44#else
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +030045#define SET_ICID_ENTRY(name, idA, regA, addr, compataddr, _le) \
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030046 { .compat = name, \
47 .id = idA, \
48 .reg = regA, \
49 .compat_addr = compataddr, \
50 .reg_addr = addr, \
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +030051 .le = _le \
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030052 }
Sean Andersonc0ca4bc2022-10-17 11:45:11 -040053#endif
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030054
Laurentiu Tudor7690ea72019-07-30 17:29:58 +030055#ifdef CONFIG_SYS_FSL_SEC_LE
56#define SEC_IS_LE true
57#elif defined(CONFIG_SYS_FSL_SEC_BE)
58#define SEC_IS_LE false
59#endif
60
61#ifdef CONFIG_FSL_LSCH2
62
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +030063#ifdef CONFIG_SYS_FSL_CCSR_SCFG_LE
64#define SCFG_IS_LE true
65#elif defined(CONFIG_SYS_FSL_CCSR_SCFG_BE)
66#define SCFG_IS_LE false
67#endif
68
Laurentiu Tudor01dc5472019-07-30 17:29:59 +030069#define QDMA_IS_LE false
70
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030071#define SET_SCFG_ICID(compat, streamid, name, compataddr) \
72 SET_ICID_ENTRY(compat, streamid, (((streamid) << 24) | (1 << 23)), \
Tom Rini376b88a2022-10-28 20:27:13 -040073 offsetof(struct ccsr_scfg, name) + CFG_SYS_FSL_SCFG_ADDR, \
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +030074 compataddr, SCFG_IS_LE)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030075
76#define SET_USB_ICID(usb_num, compat, streamid) \
77 SET_SCFG_ICID(compat, streamid, usb##usb_num##_icid,\
Tom Rini6a5dccc2022-11-16 13:10:41 -050078 CFG_SYS_XHCI_USB##usb_num##_ADDR)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030079
80#define SET_SATA_ICID(compat, streamid) \
81 SET_SCFG_ICID(compat, streamid, sata_icid,\
82 AHCI_BASE_ADDR)
83
84#define SET_SDHC_ICID(streamid) \
85 SET_SCFG_ICID("fsl,esdhc", streamid, sdhc_icid,\
Tom Rini376b88a2022-10-28 20:27:13 -040086 CFG_SYS_FSL_ESDHC_ADDR)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030087
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030088#define SET_EDMA_ICID(streamid) \
89 SET_SCFG_ICID("fsl,vf610-edma", streamid, edma_icid,\
90 EDMA_BASE_ADDR)
91
92#define SET_ETR_ICID(streamid) \
93 SET_SCFG_ICID(NULL, streamid, etr_icid, 0)
94
95#define SET_DEBUG_ICID(streamid) \
96 SET_SCFG_ICID(NULL, streamid, debug_icid, 0)
97
Laurentiu Tudor22012d52018-08-27 17:33:59 +030098#define SET_QE_ICID(streamid) \
99 SET_SCFG_ICID("fsl,qe", streamid, qe_icid,\
100 QE_BASE_ADDR)
101
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300102#define SET_QMAN_ICID(streamid) \
103 SET_ICID_ENTRY("fsl,qman", streamid, streamid, \
104 offsetof(struct ccsr_qman, liodnr) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400105 CFG_SYS_FSL_QMAN_ADDR, \
106 CFG_SYS_FSL_QMAN_ADDR, false)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300107
108#define SET_BMAN_ICID(streamid) \
109 SET_ICID_ENTRY("fsl,bman", streamid, streamid, \
110 offsetof(struct ccsr_bman, liodnr) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400111 CFG_SYS_FSL_BMAN_ADDR, \
112 CFG_SYS_FSL_BMAN_ADDR, false)
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300113
Laurentiu Tudordcb7f3d2018-08-09 15:19:48 +0300114#define SET_FMAN_ICID_ENTRY(_port_id, streamid) \
115 { .port_id = (_port_id), .icid = (streamid) }
116
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300117#define SEC_ICID_REG_VAL(streamid) (((streamid) << 16) | (streamid))
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +0300118
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300119#define SET_SEC_QI_ICID(streamid) \
120 SET_ICID_ENTRY("fsl,sec-v4.0", streamid, \
Laurentiu Tudor8aee3d62019-02-26 13:18:33 +0200121 0, offsetof(ccsr_sec_t, qilcr_ls) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400122 CFG_SYS_FSL_SEC_ADDR, \
123 CFG_SYS_FSL_SEC_ADDR, SEC_IS_LE)
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300124
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300125extern struct fman_icid_id_table fman_icid_tbl[];
126extern int fman_icid_tbl_sz;
127
128#else /* CONFIG_FSL_LSCH2 */
129
130#ifdef CONFIG_SYS_FSL_CCSR_GUR_LE
131#define GUR_IS_LE true
132#elif defined(CONFIG_SYS_FSL_CCSR_GUR_BE)
133#define GUR_IS_LE false
134#endif
135
Laurentiu Tudor01dc5472019-07-30 17:29:59 +0300136#define QDMA_IS_LE true
137
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300138#define SET_GUR_ICID(compat, streamid, name, compataddr) \
139 SET_ICID_ENTRY(compat, streamid, streamid, \
Tom Rini376b88a2022-10-28 20:27:13 -0400140 offsetof(struct ccsr_gur, name) + CFG_SYS_FSL_GUTS_ADDR, \
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300141 compataddr, GUR_IS_LE)
142
143#define SET_USB_ICID(usb_num, compat, streamid) \
144 SET_GUR_ICID(compat, streamid, usb##usb_num##_amqr,\
Tom Rini6a5dccc2022-11-16 13:10:41 -0500145 CFG_SYS_XHCI_USB##usb_num##_ADDR)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300146
147#define SET_SATA_ICID(sata_num, compat, streamid) \
148 SET_GUR_ICID(compat, streamid, sata##sata_num##_amqr, \
149 AHCI_BASE_ADDR##sata_num)
150
Laurentiu Tudor01dc5472019-07-30 17:29:59 +0300151#define SET_SDHC_ICID(sdhc_num, streamid) \
152 SET_GUR_ICID("fsl,esdhc", streamid, sdmm##sdhc_num##_amqr,\
153 FSL_ESDHC##sdhc_num##_BASE_ADDR)
154
155#define SET_EDMA_ICID(streamid) \
156 SET_GUR_ICID("fsl,vf610-edma", streamid, spare3_amqr,\
157 EDMA_BASE_ADDR)
158
159#define SET_GPU_ICID(compat, streamid) \
160 SET_GUR_ICID(compat, streamid, misc1_amqr,\
161 GPU_BASE_ADDR)
162
163#define SET_DISPLAY_ICID(streamid) \
164 SET_GUR_ICID("arm,mali-dp500", streamid, spare2_amqr,\
165 DISPLAY_BASE_ADDR)
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300166
167#define SEC_ICID_REG_VAL(streamid) (streamid)
168
169#endif /* CONFIG_FSL_LSCH2 */
170
Laurentiu Tudor01dc5472019-07-30 17:29:59 +0300171#define SET_QDMA_ICID(compat, streamid) \
172 SET_ICID_ENTRY(compat, streamid, (1 << 31) | (streamid), \
173 QDMA_BASE_ADDR + QMAN_CQSIDR_REG, \
174 QDMA_BASE_ADDR, QDMA_IS_LE), \
175 SET_ICID_ENTRY(NULL, streamid, (1 << 31) | (streamid), \
176 QDMA_BASE_ADDR + QMAN_CQSIDR_REG + 4, \
177 QDMA_BASE_ADDR, QDMA_IS_LE)
178
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300179#define SET_SEC_JR_ICID_ENTRY(jr_num, streamid) \
Laurentiu Tudor96a37ef2019-02-26 13:18:34 +0200180 SET_ICID_ENTRY( \
Laurentiu Tudor33834622019-10-18 09:01:53 +0000181 (CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) && \
Laurentiu Tudor96a37ef2019-02-26 13:18:34 +0200182 (FSL_SEC_JR##jr_num##_OFFSET == \
Tom Rini376b88a2022-10-28 20:27:13 -0400183 SEC_JR3_OFFSET + CFG_SYS_FSL_SEC_OFFSET) \
Laurentiu Tudor96a37ef2019-02-26 13:18:34 +0200184 ? NULL \
185 : "fsl,sec-v4.0-job-ring"), \
186 streamid, \
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300187 SEC_ICID_REG_VAL(streamid), \
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300188 offsetof(ccsr_sec_t, jrliodnr[jr_num].ls) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400189 CFG_SYS_FSL_SEC_ADDR, \
Laurentiu Tudor7c326ac2019-07-30 17:29:57 +0300190 FSL_SEC_JR##jr_num##_BASE_ADDR, SEC_IS_LE)
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300191
192#define SET_SEC_DECO_ICID_ENTRY(deco_num, streamid) \
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300193 SET_ICID_ENTRY(NULL, streamid, SEC_ICID_REG_VAL(streamid), \
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300194 offsetof(ccsr_sec_t, decoliodnr[deco_num].ls) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400195 CFG_SYS_FSL_SEC_ADDR, 0, SEC_IS_LE)
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300196
197#define SET_SEC_RTIC_ICID_ENTRY(rtic_num, streamid) \
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300198 SET_ICID_ENTRY(NULL, streamid, SEC_ICID_REG_VAL(streamid), \
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300199 offsetof(ccsr_sec_t, rticliodnr[rtic_num].ls) + \
Tom Rini376b88a2022-10-28 20:27:13 -0400200 CFG_SYS_FSL_SEC_ADDR, 0, SEC_IS_LE)
Laurentiu Tudor3987b042018-08-09 15:19:49 +0300201
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300202extern struct icid_id_table icid_tbl[];
203extern int icid_tbl_sz;
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300204
205#endif