Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 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> |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 11 | #include <fsl_sec.h> |
Laurentiu Tudor | 96a37ef | 2019-02-26 13:18:34 +0200 | [diff] [blame] | 12 | #include <asm/armv8/sec_firmware.h> |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 13 | |
| 14 | struct icid_id_table { |
Sean Anderson | c0ca4bc | 2022-10-17 11:45:11 -0400 | [diff] [blame] | 15 | #ifndef CONFIG_SPL_BUILD |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 16 | const char *compat; |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 17 | phys_addr_t compat_addr; |
Sean Anderson | c0ca4bc | 2022-10-17 11:45:11 -0400 | [diff] [blame] | 18 | #endif |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 19 | phys_addr_t reg_addr; |
Sean Anderson | c0ca4bc | 2022-10-17 11:45:11 -0400 | [diff] [blame] | 20 | u32 reg; |
| 21 | #ifndef CONFIG_SPL_BUILD |
| 22 | u32 id; |
| 23 | #endif |
Laurentiu Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 24 | bool le; |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 25 | }; |
| 26 | |
Laurentiu Tudor | dcb7f3d | 2018-08-09 15:19:48 +0300 | [diff] [blame] | 27 | struct fman_icid_id_table { |
| 28 | u32 port_id; |
| 29 | u32 icid; |
| 30 | }; |
| 31 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 32 | u32 get_ppid_icid(int ppid_tbl_idx, int ppid); |
| 33 | int fdt_get_smmu_phandle(void *blob); |
| 34 | int fdt_set_iommu_prop(void *blob, int off, int smmu_ph, u32 *ids, int num_ids); |
| 35 | void set_icids(void); |
| 36 | void fdt_fixup_icid(void *blob); |
| 37 | |
Sean Anderson | c0ca4bc | 2022-10-17 11:45:11 -0400 | [diff] [blame] | 38 | #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 Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 45 | #define SET_ICID_ENTRY(name, idA, regA, addr, compataddr, _le) \ |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 46 | { .compat = name, \ |
| 47 | .id = idA, \ |
| 48 | .reg = regA, \ |
| 49 | .compat_addr = compataddr, \ |
| 50 | .reg_addr = addr, \ |
Laurentiu Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 51 | .le = _le \ |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 52 | } |
Sean Anderson | c0ca4bc | 2022-10-17 11:45:11 -0400 | [diff] [blame] | 53 | #endif |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 54 | |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 55 | #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 Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 63 | #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 Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 69 | #define QDMA_IS_LE false |
| 70 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 71 | #define SET_SCFG_ICID(compat, streamid, name, compataddr) \ |
| 72 | SET_ICID_ENTRY(compat, streamid, (((streamid) << 24) | (1 << 23)), \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 73 | offsetof(struct ccsr_scfg, name) + CFG_SYS_FSL_SCFG_ADDR, \ |
Laurentiu Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 74 | compataddr, SCFG_IS_LE) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 75 | |
| 76 | #define SET_USB_ICID(usb_num, compat, streamid) \ |
| 77 | SET_SCFG_ICID(compat, streamid, usb##usb_num##_icid,\ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 78 | CFG_SYS_XHCI_USB##usb_num##_ADDR) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 79 | |
| 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 Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 86 | CFG_SYS_FSL_ESDHC_ADDR) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 87 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 88 | #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 Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 98 | #define SET_QE_ICID(streamid) \ |
| 99 | SET_SCFG_ICID("fsl,qe", streamid, qe_icid,\ |
| 100 | QE_BASE_ADDR) |
| 101 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 102 | #define SET_QMAN_ICID(streamid) \ |
| 103 | SET_ICID_ENTRY("fsl,qman", streamid, streamid, \ |
| 104 | offsetof(struct ccsr_qman, liodnr) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 105 | CFG_SYS_FSL_QMAN_ADDR, \ |
| 106 | CFG_SYS_FSL_QMAN_ADDR, false) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 107 | |
| 108 | #define SET_BMAN_ICID(streamid) \ |
| 109 | SET_ICID_ENTRY("fsl,bman", streamid, streamid, \ |
| 110 | offsetof(struct ccsr_bman, liodnr) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 111 | CFG_SYS_FSL_BMAN_ADDR, \ |
| 112 | CFG_SYS_FSL_BMAN_ADDR, false) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 113 | |
Laurentiu Tudor | dcb7f3d | 2018-08-09 15:19:48 +0300 | [diff] [blame] | 114 | #define SET_FMAN_ICID_ENTRY(_port_id, streamid) \ |
| 115 | { .port_id = (_port_id), .icid = (streamid) } |
| 116 | |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 117 | #define SEC_ICID_REG_VAL(streamid) (((streamid) << 16) | (streamid)) |
Laurentiu Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 118 | |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 119 | #define SET_SEC_QI_ICID(streamid) \ |
| 120 | SET_ICID_ENTRY("fsl,sec-v4.0", streamid, \ |
Laurentiu Tudor | 8aee3d6 | 2019-02-26 13:18:33 +0200 | [diff] [blame] | 121 | 0, offsetof(ccsr_sec_t, qilcr_ls) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 122 | CFG_SYS_FSL_SEC_ADDR, \ |
| 123 | CFG_SYS_FSL_SEC_ADDR, SEC_IS_LE) |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 124 | |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 125 | extern struct fman_icid_id_table fman_icid_tbl[]; |
| 126 | extern 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 Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 136 | #define QDMA_IS_LE true |
| 137 | |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 138 | #define SET_GUR_ICID(compat, streamid, name, compataddr) \ |
| 139 | SET_ICID_ENTRY(compat, streamid, streamid, \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 140 | offsetof(struct ccsr_gur, name) + CFG_SYS_FSL_GUTS_ADDR, \ |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 141 | 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 Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 145 | CFG_SYS_XHCI_USB##usb_num##_ADDR) |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 146 | |
| 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 Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 151 | #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 Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 166 | |
| 167 | #define SEC_ICID_REG_VAL(streamid) (streamid) |
| 168 | |
| 169 | #endif /* CONFIG_FSL_LSCH2 */ |
| 170 | |
Laurentiu Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 171 | #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 Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 179 | #define SET_SEC_JR_ICID_ENTRY(jr_num, streamid) \ |
Laurentiu Tudor | 96a37ef | 2019-02-26 13:18:34 +0200 | [diff] [blame] | 180 | SET_ICID_ENTRY( \ |
Laurentiu Tudor | 3383462 | 2019-10-18 09:01:53 +0000 | [diff] [blame] | 181 | (CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) && \ |
Laurentiu Tudor | 96a37ef | 2019-02-26 13:18:34 +0200 | [diff] [blame] | 182 | (FSL_SEC_JR##jr_num##_OFFSET == \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 183 | SEC_JR3_OFFSET + CFG_SYS_FSL_SEC_OFFSET) \ |
Laurentiu Tudor | 96a37ef | 2019-02-26 13:18:34 +0200 | [diff] [blame] | 184 | ? NULL \ |
| 185 | : "fsl,sec-v4.0-job-ring"), \ |
| 186 | streamid, \ |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 187 | SEC_ICID_REG_VAL(streamid), \ |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 188 | offsetof(ccsr_sec_t, jrliodnr[jr_num].ls) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 189 | CFG_SYS_FSL_SEC_ADDR, \ |
Laurentiu Tudor | 7c326ac | 2019-07-30 17:29:57 +0300 | [diff] [blame] | 190 | FSL_SEC_JR##jr_num##_BASE_ADDR, SEC_IS_LE) |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 191 | |
| 192 | #define SET_SEC_DECO_ICID_ENTRY(deco_num, streamid) \ |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 193 | SET_ICID_ENTRY(NULL, streamid, SEC_ICID_REG_VAL(streamid), \ |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 194 | offsetof(ccsr_sec_t, decoliodnr[deco_num].ls) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 195 | CFG_SYS_FSL_SEC_ADDR, 0, SEC_IS_LE) |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 196 | |
| 197 | #define SET_SEC_RTIC_ICID_ENTRY(rtic_num, streamid) \ |
Laurentiu Tudor | 7690ea7 | 2019-07-30 17:29:58 +0300 | [diff] [blame] | 198 | SET_ICID_ENTRY(NULL, streamid, SEC_ICID_REG_VAL(streamid), \ |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 199 | offsetof(ccsr_sec_t, rticliodnr[rtic_num].ls) + \ |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 200 | CFG_SYS_FSL_SEC_ADDR, 0, SEC_IS_LE) |
Laurentiu Tudor | 3987b04 | 2018-08-09 15:19:49 +0300 | [diff] [blame] | 201 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 202 | extern struct icid_id_table icid_tbl[]; |
| 203 | extern int icid_tbl_sz; |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 204 | |
| 205 | #endif |