Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'stm32-bus-firewall-for-v6.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/atorgue/stm32 into soc/drivers

STM32 Firewall bus for v6.19, round 1

Highlights:
----------

The STM32MP21x platforms have a slightly different RIFSC. Add support
for these platforms.

Also, the RIF is a complex firewall framework which can be tricky
to debug. To facilitate the latter, add a debugfs entry that can
be used to display the whole RIFSC firewall configuration at runtime.

* tag 'stm32-bus-firewall-for-v6.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/atorgue/stm32:
bus: rifsc: add debugfs entry to dump the firewall configuration
dt-bindings: bus: add stm32mp21 RIFSC compatible

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+599 -6
+6 -2
Documentation/devicetree/bindings/bus/st,stm32mp25-rifsc.yaml
··· 33 33 properties: 34 34 compatible: 35 35 contains: 36 - const: st,stm32mp25-rifsc 36 + enum: 37 + - st,stm32mp21-rifsc 38 + - st,stm32mp25-rifsc 37 39 required: 38 40 - compatible 39 41 40 42 properties: 41 43 compatible: 42 44 items: 43 - - const: st,stm32mp25-rifsc 45 + - enum: 46 + - st,stm32mp21-rifsc 47 + - st,stm32mp25-rifsc 44 48 - const: simple-bus 45 49 46 50 reg:
+593 -4
drivers/bus/stm32_rifsc.c
··· 5 5 6 6 #include <linux/bitfield.h> 7 7 #include <linux/bits.h> 8 + #include <linux/debugfs.h> 8 9 #include <linux/device.h> 9 10 #include <linux/err.h> 10 11 #include <linux/init.h> ··· 26 25 #define RIFSC_RISC_PRIVCFGR0 0x30 27 26 #define RIFSC_RISC_PER0_CIDCFGR 0x100 28 27 #define RIFSC_RISC_PER0_SEMCR 0x104 28 + #define RIFSC_RISC_REG0_ACFGR 0x900 29 + #define RIFSC_RISC_REG3_AADDR 0x924 29 30 #define RIFSC_RISC_HWCFGR2 0xFEC 30 31 31 32 /* ··· 72 69 /* Compartiment IDs */ 73 70 #define RIF_CID0 0x0 74 71 #define RIF_CID1 0x1 72 + 73 + #if defined(CONFIG_DEBUG_FS) 74 + #define RIFSC_RISUP_ENTRIES 128 75 + #define RIFSC_RIMU_ENTRIES 16 76 + #define RIFSC_RISAL_SUBREGIONS 2 77 + #define RIFSC_RISAL_GRANULARITY 8 78 + 79 + #define RIFSC_RIMC_ATTR0 0xC10 80 + 81 + #define RIFSC_RIMC_CIDSEL BIT(2) 82 + #define RIFSC_RIMC_MCID_MASK GENMASK(6, 4) 83 + #define RIFSC_RIMC_MSEC BIT(8) 84 + #define RIFSC_RIMC_MPRIV BIT(9) 85 + 86 + #define RIFSC_RISC_SRCID_MASK GENMASK(6, 4) 87 + #define RIFSC_RISC_SRPRIV BIT(9) 88 + #define RIFSC_RISC_SRSEC BIT(8) 89 + #define RIFSC_RISC_SRRLOCK BIT(1) 90 + #define RIFSC_RISC_SREN BIT(0) 91 + #define RIFSC_RISC_SRLENGTH_MASK GENMASK(27, 16) 92 + #define RIFSC_RISC_SRSTART_MASK GENMASK(10, 0) 93 + 94 + static const char *stm32mp21_rifsc_rimu_names[RIFSC_RIMU_ENTRIES] = { 95 + "ETR", 96 + "SDMMC1", 97 + "SDMMC2", 98 + "SDMMC3", 99 + "OTG_HS", 100 + "USBH", 101 + "ETH1", 102 + "ETH2", 103 + "RESERVED", 104 + "RESERVED", 105 + "DCMIPP", 106 + "LTDC_L1/L2", 107 + "LTDC_L3", 108 + "RESERVED", 109 + "RESERVED", 110 + "RESERVED", 111 + }; 112 + 113 + static const char *stm32mp25_rifsc_rimu_names[RIFSC_RIMU_ENTRIES] = { 114 + "ETR", 115 + "SDMMC1", 116 + "SDMMC2", 117 + "SDMMC3", 118 + "USB3DR", 119 + "USBH", 120 + "ETH1", 121 + "ETH2", 122 + "PCIE", 123 + "GPU", 124 + "DMCIPP", 125 + "LTDC_L0/L1", 126 + "LTDC_L2", 127 + "LTDC_ROT", 128 + "VDEC", 129 + "VENC" 130 + }; 131 + 132 + static const char *stm32mp21_rifsc_risup_names[RIFSC_RISUP_ENTRIES] = { 133 + "TIM1", 134 + "TIM2", 135 + "TIM3", 136 + "TIM4", 137 + "TIM5", 138 + "TIM6", 139 + "TIM7", 140 + "TIM8", 141 + "TIM10", 142 + "TIM11", 143 + "TIM12", 144 + "TIM13", 145 + "TIM14", 146 + "TIM15", 147 + "TIM16", 148 + "TIM17", 149 + "RESERVED", 150 + "LPTIM1", 151 + "LPTIM2", 152 + "LPTIM3", 153 + "LPTIM4", 154 + "LPTIM5", 155 + "SPI1", 156 + "SPI2", 157 + "SPI3", 158 + "SPI4", 159 + "SPI5", 160 + "SPI6", 161 + "RESERVED", 162 + "RESERVED", 163 + "SPDIFRX", 164 + "USART1", 165 + "USART2", 166 + "USART3", 167 + "UART4", 168 + "UART5", 169 + "USART6", 170 + "UART7", 171 + "RESERVED", 172 + "RESERVED", 173 + "LPUART1", 174 + "I2C1", 175 + "I2C2", 176 + "I2C3", 177 + "RESERVED", 178 + "RESERVED", 179 + "RESERVED", 180 + "RESERVED", 181 + "RESERVED", 182 + "SAI1", 183 + "SAI2", 184 + "SAI3", 185 + "SAI4", 186 + "RESERVED", 187 + "MDF1", 188 + "RESERVED", 189 + "FDCAN", 190 + "HDP", 191 + "ADC1", 192 + "ADC2", 193 + "ETH1", 194 + "ETH2", 195 + "RESERVED", 196 + "USBH", 197 + "RESERVED", 198 + "RESERVED", 199 + "OTG_HS", 200 + "DDRPERFM", 201 + "RESERVED", 202 + "RESERVED", 203 + "RESERVED", 204 + "RESERVED", 205 + "RESERVED", 206 + "STGEN", 207 + "OCTOSPI1", 208 + "RESERVED", 209 + "SDMMC1", 210 + "SDMMC2", 211 + "SDMMC3", 212 + "RESERVED", 213 + "LTDC_CMN", 214 + "RESERVED", 215 + "RESERVED", 216 + "RESERVED", 217 + "RESERVED", 218 + "RESERVED", 219 + "CSI", 220 + "DCMIPP", 221 + "DCMI_PSSI", 222 + "RESERVED", 223 + "RESERVED", 224 + "RESERVED", 225 + "RNG1", 226 + "RNG2", 227 + "PKA", 228 + "SAES", 229 + "HASH1", 230 + "HASH2", 231 + "CRYP1", 232 + "CRYP2", 233 + "IWDG1", 234 + "IWDG2", 235 + "IWDG3", 236 + "IWDG4", 237 + "WWDG1", 238 + "RESERVED", 239 + "VREFBUF", 240 + "DTS", 241 + "RAMCFG", 242 + "CRC", 243 + "SERC", 244 + "RESERVED", 245 + "RESERVED", 246 + "RESERVED", 247 + "I3C1", 248 + "I3C2", 249 + "I3C3", 250 + "RESERVED", 251 + "ICACHE_DCACHE", 252 + "LTDC_L1L2", 253 + "LTDC_L3", 254 + "RESERVED", 255 + "RESERVED", 256 + "RESERVED", 257 + "RESERVED", 258 + "OTFDEC1", 259 + "RESERVED", 260 + "IAC", 261 + }; 262 + 263 + static const char *stm32mp25_rifsc_risup_names[RIFSC_RISUP_ENTRIES] = { 264 + "TIM1", 265 + "TIM2", 266 + "TIM3", 267 + "TIM4", 268 + "TIM5", 269 + "TIM6", 270 + "TIM7", 271 + "TIM8", 272 + "TIM10", 273 + "TIM11", 274 + "TIM12", 275 + "TIM13", 276 + "TIM14", 277 + "TIM15", 278 + "TIM16", 279 + "TIM17", 280 + "TIM20", 281 + "LPTIM1", 282 + "LPTIM2", 283 + "LPTIM3", 284 + "LPTIM4", 285 + "LPTIM5", 286 + "SPI1", 287 + "SPI2", 288 + "SPI3", 289 + "SPI4", 290 + "SPI5", 291 + "SPI6", 292 + "SPI7", 293 + "SPI8", 294 + "SPDIFRX", 295 + "USART1", 296 + "USART2", 297 + "USART3", 298 + "UART4", 299 + "UART5", 300 + "USART6", 301 + "UART7", 302 + "UART8", 303 + "UART9", 304 + "LPUART1", 305 + "I2C1", 306 + "I2C2", 307 + "I2C3", 308 + "I2C4", 309 + "I2C5", 310 + "I2C6", 311 + "I2C7", 312 + "I2C8", 313 + "SAI1", 314 + "SAI2", 315 + "SAI3", 316 + "SAI4", 317 + "RESERVED", 318 + "MDF1", 319 + "ADF1", 320 + "FDCAN", 321 + "HDP", 322 + "ADC12", 323 + "ADC3", 324 + "ETH1", 325 + "ETH2", 326 + "RESERVED", 327 + "USBH", 328 + "RESERVED", 329 + "RESERVED", 330 + "USB3DR", 331 + "COMBOPHY", 332 + "PCIE", 333 + "UCPD1", 334 + "ETHSW_DEIP", 335 + "ETHSW_ACM_CF", 336 + "ETHSW_ACM_MSGBU", 337 + "STGEN", 338 + "OCTOSPI1", 339 + "OCTOSPI2", 340 + "SDMMC1", 341 + "SDMMC2", 342 + "SDMMC3", 343 + "GPU", 344 + "LTDC_CMN", 345 + "DSI_CMN", 346 + "RESERVED", 347 + "RESERVED", 348 + "LVDS", 349 + "RESERVED", 350 + "CSI", 351 + "DCMIPP", 352 + "DCMI_PSSI", 353 + "VDEC", 354 + "VENC", 355 + "RESERVED", 356 + "RNG", 357 + "PKA", 358 + "SAES", 359 + "HASH", 360 + "CRYP1", 361 + "CRYP2", 362 + "IWDG1", 363 + "IWDG2", 364 + "IWDG3", 365 + "IWDG4", 366 + "IWDG5", 367 + "WWDG1", 368 + "WWDG2", 369 + "RESERVED", 370 + "VREFBUF", 371 + "DTS", 372 + "RAMCFG", 373 + "CRC", 374 + "SERC", 375 + "OCTOSPIM", 376 + "GICV2M", 377 + "RESERVED", 378 + "I3C1", 379 + "I3C2", 380 + "I3C3", 381 + "I3C4", 382 + "ICACHE_DCACHE", 383 + "LTDC_L0L1", 384 + "LTDC_L2", 385 + "LTDC_ROT", 386 + "DSI_TRIG", 387 + "DSI_RDFIFO", 388 + "RESERVED", 389 + "OTFDEC1", 390 + "OTFDEC2", 391 + "IAC", 392 + }; 393 + struct rifsc_risup_debug_data { 394 + char dev_name[15]; 395 + u8 dev_cid; 396 + u8 dev_sem_cids; 397 + u8 dev_id; 398 + bool dev_cid_filt_en; 399 + bool dev_sem_en; 400 + bool dev_priv; 401 + bool dev_sec; 402 + }; 403 + 404 + struct rifsc_rimu_debug_data { 405 + char m_name[11]; 406 + u8 m_cid; 407 + bool cidsel; 408 + bool m_sec; 409 + bool m_priv; 410 + }; 411 + 412 + struct rifsc_subreg_debug_data { 413 + bool sr_sec; 414 + bool sr_priv; 415 + u8 sr_cid; 416 + bool sr_rlock; 417 + bool sr_enable; 418 + u16 sr_start; 419 + u16 sr_length; 420 + }; 421 + 422 + struct stm32_rifsc_resources_names { 423 + const char **device_names; 424 + const char **initiator_names; 425 + }; 426 + struct rifsc_dbg_private { 427 + const struct stm32_rifsc_resources_names *res_names; 428 + void __iomem *mmio; 429 + unsigned int nb_risup; 430 + unsigned int nb_rimu; 431 + unsigned int nb_risal; 432 + }; 433 + 434 + static const struct stm32_rifsc_resources_names rifsc_mp21_res_names = { 435 + .device_names = stm32mp21_rifsc_risup_names, 436 + .initiator_names = stm32mp21_rifsc_rimu_names, 437 + }; 438 + 439 + static const struct stm32_rifsc_resources_names rifsc_mp25_res_names = { 440 + .device_names = stm32mp25_rifsc_risup_names, 441 + .initiator_names = stm32mp25_rifsc_rimu_names, 442 + }; 443 + 444 + static void stm32_rifsc_fill_rimu_dbg_entry(struct rifsc_dbg_private *rifsc, 445 + struct rifsc_rimu_debug_data *dbg_entry, int i) 446 + { 447 + const struct stm32_rifsc_resources_names *dbg_names = rifsc->res_names; 448 + u32 rimc_attr = readl_relaxed(rifsc->mmio + RIFSC_RIMC_ATTR0 + 0x4 * i); 449 + 450 + snprintf(dbg_entry->m_name, sizeof(dbg_entry->m_name), "%s", dbg_names->initiator_names[i]); 451 + dbg_entry->m_cid = FIELD_GET(RIFSC_RIMC_MCID_MASK, rimc_attr); 452 + dbg_entry->cidsel = rimc_attr & RIFSC_RIMC_CIDSEL; 453 + dbg_entry->m_sec = rimc_attr & RIFSC_RIMC_MSEC; 454 + dbg_entry->m_priv = rimc_attr & RIFSC_RIMC_MPRIV; 455 + } 456 + 457 + static void stm32_rifsc_fill_dev_dbg_entry(struct rifsc_dbg_private *rifsc, 458 + struct rifsc_risup_debug_data *dbg_entry, int i) 459 + { 460 + const struct stm32_rifsc_resources_names *dbg_names = rifsc->res_names; 461 + u32 cid_cfgr, sec_cfgr, priv_cfgr; 462 + u8 reg_id = i / IDS_PER_RISC_SEC_PRIV_REGS; 463 + u8 reg_offset = i % IDS_PER_RISC_SEC_PRIV_REGS; 464 + 465 + cid_cfgr = readl_relaxed(rifsc->mmio + RIFSC_RISC_PER0_CIDCFGR + 0x8 * i); 466 + sec_cfgr = readl_relaxed(rifsc->mmio + RIFSC_RISC_SECCFGR0 + 0x4 * reg_id); 467 + priv_cfgr = readl_relaxed(rifsc->mmio + RIFSC_RISC_PRIVCFGR0 + 0x4 * reg_id); 468 + 469 + snprintf(dbg_entry->dev_name, sizeof(dbg_entry->dev_name), "%s", 470 + dbg_names->device_names[i]); 471 + dbg_entry->dev_id = i; 472 + dbg_entry->dev_cid_filt_en = cid_cfgr & CIDCFGR_CFEN; 473 + dbg_entry->dev_sem_en = cid_cfgr & CIDCFGR_SEMEN; 474 + dbg_entry->dev_cid = FIELD_GET(RIFSC_RISC_SCID_MASK, cid_cfgr); 475 + dbg_entry->dev_sem_cids = FIELD_GET(RIFSC_RISC_SEMWL_MASK, cid_cfgr); 476 + dbg_entry->dev_sec = sec_cfgr & BIT(reg_offset) ? true : false; 477 + dbg_entry->dev_priv = priv_cfgr & BIT(reg_offset) ? true : false; 478 + } 479 + 480 + 481 + static void stm32_rifsc_fill_subreg_dbg_entry(struct rifsc_dbg_private *rifsc, 482 + struct rifsc_subreg_debug_data *dbg_entry, int i, 483 + int j) 484 + { 485 + u32 risc_xcfgr = readl_relaxed(rifsc->mmio + RIFSC_RISC_REG0_ACFGR + 0x10 * i + 0x8 * j); 486 + u32 risc_xaddr; 487 + 488 + dbg_entry->sr_sec = risc_xcfgr & RIFSC_RISC_SRSEC; 489 + dbg_entry->sr_priv = risc_xcfgr & RIFSC_RISC_SRPRIV; 490 + dbg_entry->sr_cid = FIELD_GET(RIFSC_RISC_SRCID_MASK, risc_xcfgr); 491 + dbg_entry->sr_rlock = risc_xcfgr & RIFSC_RISC_SRRLOCK; 492 + dbg_entry->sr_enable = risc_xcfgr & RIFSC_RISC_SREN; 493 + if (i == 2) { 494 + risc_xaddr = readl_relaxed(rifsc->mmio + RIFSC_RISC_REG3_AADDR + 0x8 * j); 495 + dbg_entry->sr_length = FIELD_GET(RIFSC_RISC_SRLENGTH_MASK, risc_xaddr); 496 + dbg_entry->sr_start = FIELD_GET(RIFSC_RISC_SRSTART_MASK, risc_xaddr); 497 + } else { 498 + dbg_entry->sr_start = 0; 499 + dbg_entry->sr_length = U16_MAX; 500 + } 501 + } 502 + 503 + static int stm32_rifsc_conf_dump_show(struct seq_file *s, void *data) 504 + { 505 + struct rifsc_dbg_private *rifsc = (struct rifsc_dbg_private *)s->private; 506 + int i, j; 507 + 508 + seq_puts(s, "\n=============================================\n"); 509 + seq_puts(s, " RIFSC dump\n"); 510 + seq_puts(s, "=============================================\n\n"); 511 + 512 + seq_puts(s, "\n=============================================\n"); 513 + seq_puts(s, " RISUP dump\n"); 514 + seq_puts(s, "=============================================\n"); 515 + 516 + seq_printf(s, "\n| %-15s |", "Peripheral name"); 517 + seq_puts(s, "| Firewall ID |"); 518 + seq_puts(s, "| N/SECURE |"); 519 + seq_puts(s, "| N/PRIVILEGED |"); 520 + seq_puts(s, "| CID filtering |"); 521 + seq_puts(s, "| Semaphore mode |"); 522 + seq_puts(s, "| SCID |"); 523 + seq_printf(s, "| %7s |\n", "SEMWL"); 524 + 525 + for (i = 0; i < RIFSC_RISUP_ENTRIES && i < rifsc->nb_risup; i++) { 526 + struct rifsc_risup_debug_data d_dbg_entry; 527 + 528 + stm32_rifsc_fill_dev_dbg_entry(rifsc, &d_dbg_entry, i); 529 + 530 + seq_printf(s, "| %-15s |", d_dbg_entry.dev_name); 531 + seq_printf(s, "| %-11d |", d_dbg_entry.dev_id); 532 + seq_printf(s, "| %-8s |", d_dbg_entry.dev_sec ? "SEC" : "NSEC"); 533 + seq_printf(s, "| %-12s |", d_dbg_entry.dev_priv ? "PRIV" : "NPRIV"); 534 + seq_printf(s, "| %-13s |", str_enabled_disabled(d_dbg_entry.dev_cid_filt_en)); 535 + seq_printf(s, "| %-14s |", str_enabled_disabled(d_dbg_entry.dev_sem_en)); 536 + seq_printf(s, "| %-4d |", d_dbg_entry.dev_cid); 537 + seq_printf(s, "| %#-7x |\n", d_dbg_entry.dev_sem_cids); 538 + } 539 + 540 + seq_puts(s, "\n=============================================\n"); 541 + seq_puts(s, " RIMU dump\n"); 542 + seq_puts(s, "=============================================\n"); 543 + 544 + seq_puts(s, "| RIMU's name |"); 545 + seq_puts(s, "| CIDSEL |"); 546 + seq_puts(s, "| MCID |"); 547 + seq_puts(s, "| N/SECURE |"); 548 + seq_puts(s, "| N/PRIVILEGED |\n"); 549 + 550 + for (i = 0; i < RIFSC_RIMU_ENTRIES && rifsc->nb_rimu; i++) { 551 + struct rifsc_rimu_debug_data m_dbg_entry; 552 + 553 + stm32_rifsc_fill_rimu_dbg_entry(rifsc, &m_dbg_entry, i); 554 + 555 + seq_printf(s, "| %-11s |", m_dbg_entry.m_name); 556 + seq_printf(s, "| %-6s |", m_dbg_entry.cidsel ? "CIDSEL" : ""); 557 + seq_printf(s, "| %-4d |", m_dbg_entry.m_cid); 558 + seq_printf(s, "| %-8s |", m_dbg_entry.m_sec ? "SEC" : "NSEC"); 559 + seq_printf(s, "| %-12s |\n", m_dbg_entry.m_priv ? "PRIV" : "NPRIV"); 560 + } 561 + 562 + if (rifsc->nb_risal > 0) { 563 + seq_puts(s, "\n=============================================\n"); 564 + seq_puts(s, " RISAL dump\n"); 565 + seq_puts(s, "=============================================\n"); 566 + 567 + seq_puts(s, "| Memory |"); 568 + seq_puts(s, "| Subreg. |"); 569 + seq_puts(s, "| N/SECURE |"); 570 + seq_puts(s, "| N/PRIVILEGED |"); 571 + seq_puts(s, "| Subreg. CID |"); 572 + seq_puts(s, "| Resource lock |"); 573 + seq_puts(s, "| Subreg. enable |"); 574 + seq_puts(s, "| Subreg. start |"); 575 + seq_puts(s, "| Subreg. end |\n"); 576 + 577 + for (i = 0; i < rifsc->nb_risal; i++) { 578 + for (j = 0; j < RIFSC_RISAL_SUBREGIONS; j++) { 579 + struct rifsc_subreg_debug_data sr_dbg_entry; 580 + 581 + stm32_rifsc_fill_subreg_dbg_entry(rifsc, &sr_dbg_entry, i, j); 582 + 583 + seq_printf(s, "| LPSRAM%1d |", i + 1); 584 + seq_printf(s, "| %1s |", (j == 0) ? "A" : "B"); 585 + seq_printf(s, "| %-8s |", sr_dbg_entry.sr_sec ? "SEC" : "NSEC"); 586 + seq_printf(s, "| %-12s |", sr_dbg_entry.sr_priv ? "PRIV" : "NPRIV"); 587 + seq_printf(s, "| 0x%-9x |", sr_dbg_entry.sr_cid); 588 + seq_printf(s, "| %-13s |", 589 + sr_dbg_entry.sr_rlock ? "locked (1)" : "unlocked (0)"); 590 + seq_printf(s, "| %-14s |", 591 + str_enabled_disabled(sr_dbg_entry.sr_enable)); 592 + seq_printf(s, "| 0x%-11x |", sr_dbg_entry.sr_start); 593 + seq_printf(s, "| 0x%-11x |\n", sr_dbg_entry.sr_start + 594 + sr_dbg_entry.sr_length - 1); 595 + } 596 + } 597 + } 598 + 599 + return 0; 600 + } 601 + DEFINE_SHOW_ATTRIBUTE(stm32_rifsc_conf_dump); 602 + 603 + static int stm32_rifsc_register_debugfs(struct stm32_firewall_controller *rifsc_controller, 604 + u32 nb_risup, u32 nb_rimu, u32 nb_risal) 605 + { 606 + struct rifsc_dbg_private *rifsc_priv; 607 + struct dentry *root = NULL; 608 + 609 + rifsc_priv = devm_kzalloc(rifsc_controller->dev, sizeof(*rifsc_priv), GFP_KERNEL); 610 + if (!rifsc_priv) 611 + return -ENOMEM; 612 + 613 + rifsc_priv->mmio = rifsc_controller->mmio; 614 + rifsc_priv->nb_risup = nb_risup; 615 + rifsc_priv->nb_rimu = nb_rimu; 616 + rifsc_priv->nb_risal = nb_risal; 617 + rifsc_priv->res_names = of_device_get_match_data(rifsc_controller->dev); 618 + 619 + root = debugfs_lookup("stm32_firewall", NULL); 620 + if (!root) 621 + root = debugfs_create_dir("stm32_firewall", NULL); 622 + 623 + if (IS_ERR(root)) 624 + return PTR_ERR(root); 625 + 626 + debugfs_create_file("rifsc", 0444, root, rifsc_priv, &stm32_rifsc_conf_dump_fops); 627 + 628 + return 0; 629 + } 630 + #endif /* defined(CONFIG_DEBUG_FS) */ 75 631 76 632 static bool stm32_rifsc_is_semaphore_available(void __iomem *addr) 77 633 { ··· 769 207 rifsc_controller->release_access = stm32_rifsc_release_access; 770 208 771 209 /* Get number of RIFSC entries*/ 772 - nb_risup = readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2) & HWCFGR2_CONF1_MASK; 773 - nb_rimu = readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2) & HWCFGR2_CONF2_MASK; 774 - nb_risal = readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2) & HWCFGR2_CONF3_MASK; 210 + nb_risup = FIELD_GET(HWCFGR2_CONF1_MASK, 211 + readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2)); 212 + nb_rimu = FIELD_GET(HWCFGR2_CONF2_MASK, 213 + readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2)); 214 + nb_risal = FIELD_GET(HWCFGR2_CONF3_MASK, 215 + readl(rifsc_controller->mmio + RIFSC_RISC_HWCFGR2)); 216 + /* 217 + * On STM32MP21, RIFSC_RISC_HWCFGR2 shows an incorrect number of RISAL (NUM_RISAL is 3 218 + * instead of 0). A software workaround is implemented using the st,mem-map property in the 219 + * device tree. This property is absent or left empty if there is no RISAL. 220 + */ 221 + if (of_device_is_compatible(np, "st,stm32mp21-rifsc")) 222 + nb_risal = 0; 775 223 rifsc_controller->max_entries = nb_risup + nb_rimu + nb_risal; 776 224 777 225 platform_set_drvdata(pdev, rifsc_controller); ··· 800 228 return rc; 801 229 } 802 230 231 + #if defined(CONFIG_DEBUG_FS) 232 + rc = stm32_rifsc_register_debugfs(rifsc_controller, nb_risup, nb_rimu, nb_risal); 233 + if (rc) 234 + return dev_err_probe(rifsc_controller->dev, rc, "Failed creating debugfs entry\n"); 235 + #endif 236 + 803 237 /* Populate all allowed nodes */ 804 238 return of_platform_populate(np, NULL, NULL, &pdev->dev); 805 239 } 806 240 807 241 static const struct of_device_id stm32_rifsc_of_match[] = { 808 - { .compatible = "st,stm32mp25-rifsc" }, 242 + { 243 + .compatible = "st,stm32mp25-rifsc", 244 + #if defined(CONFIG_DEBUG_FS) 245 + .data = &rifsc_mp25_res_names, 246 + #endif 247 + }, 248 + { 249 + .compatible = "st,stm32mp21-rifsc", 250 + #if defined(CONFIG_DEBUG_FS) 251 + .data = &rifsc_mp21_res_names, 252 + #endif 253 + }, 809 254 {} 810 255 }; 811 256 MODULE_DEVICE_TABLE(of, stm32_rifsc_of_match);