|
14 | 14 | #include "soc/hp_apm_struct.h" |
15 | 15 | #include "soc/lp_apm_reg.h" |
16 | 16 | #include "soc/lp_apm_struct.h" |
| 17 | +#include "soc/cpu_apm_reg.h" |
| 18 | +#include "soc/cpu_apm_struct.h" |
17 | 19 |
|
18 | 20 | #include "soc/pcr_reg.h" |
19 | 21 | #include "soc/interrupts.h" |
@@ -448,6 +450,195 @@ static inline int apm_ll_lp_apm_get_ctrl_intr_src(apm_ctrl_access_path_t path) |
448 | 450 | return ETS_LP_APM_M0_INTR_SOURCE; |
449 | 451 | } |
450 | 452 |
|
| 453 | +/** |
| 454 | + * @brief Enable/disable controller filter for specific path in CPU-APM |
| 455 | + * |
| 456 | + * @param path Access path |
| 457 | + * @param enable True to enable, false to disable |
| 458 | + */ |
| 459 | +static inline void apm_ll_cpu_apm_enable_ctrl_filter(apm_ctrl_access_path_t path, bool enable) |
| 460 | +{ |
| 461 | + if (enable) { |
| 462 | + REG_SET_BIT(CPU_APM_FUNC_CTRL_REG, BIT(path)); |
| 463 | + } else { |
| 464 | + REG_CLR_BIT(CPU_APM_FUNC_CTRL_REG, BIT(path)); |
| 465 | + } |
| 466 | +} |
| 467 | + |
| 468 | +/** |
| 469 | + * @brief Enable/disable all controller filters in CPU-APM |
| 470 | + * |
| 471 | + * @param enable True to enable, false to disable |
| 472 | + */ |
| 473 | +static inline void apm_ll_cpu_apm_enable_ctrl_filter_all(bool enable) |
| 474 | +{ |
| 475 | + REG_WRITE(CPU_APM_FUNC_CTRL_REG, enable ? UINT32_MAX : 0); |
| 476 | +} |
| 477 | + |
| 478 | +/** |
| 479 | + * @brief Enable/disable region filter in CPU-APM |
| 480 | + * |
| 481 | + * @param regn_num Region number |
| 482 | + * @param enable True to enable, false to disable |
| 483 | + */ |
| 484 | +static inline void apm_ll_cpu_apm_enable_region_filter(uint32_t regn_num, bool enable) |
| 485 | +{ |
| 486 | + if (enable) { |
| 487 | + REG_SET_BIT(CPU_APM_REGION_FILTER_EN_REG, BIT(regn_num)); |
| 488 | + } else { |
| 489 | + REG_CLR_BIT(CPU_APM_REGION_FILTER_EN_REG, BIT(regn_num)); |
| 490 | + } |
| 491 | +} |
| 492 | + |
| 493 | +/** |
| 494 | + * @brief Set region start address in CPU-APM |
| 495 | + * |
| 496 | + * @param regn_num Region number |
| 497 | + * @param addr Start address |
| 498 | + */ |
| 499 | +static inline void apm_ll_cpu_apm_set_region_start_addr(uint32_t regn_num, uint32_t addr) |
| 500 | +{ |
| 501 | + REG_WRITE(CPU_APM_REGION0_ADDR_START_REG + APM_REGION_ADDR_OFFSET * regn_num, addr); |
| 502 | +} |
| 503 | + |
| 504 | +/** |
| 505 | + * @brief Set region end address in CPU-APM |
| 506 | + * |
| 507 | + * @param regn_num Region number |
| 508 | + * @param addr End address |
| 509 | + */ |
| 510 | +static inline void apm_ll_cpu_apm_set_region_end_addr(uint32_t regn_num, uint32_t addr) |
| 511 | +{ |
| 512 | + REG_WRITE(CPU_APM_REGION0_ADDR_END_REG + APM_REGION_ADDR_OFFSET * regn_num, addr); |
| 513 | +} |
| 514 | + |
| 515 | +/** |
| 516 | + * @brief Set security mode region attributes in CPU-APM |
| 517 | + * |
| 518 | + * @param regn_num Region number |
| 519 | + * @param mode Security mode |
| 520 | + * @param regn_pms Region PMS attributes |
| 521 | + */ |
| 522 | +static inline void apm_ll_cpu_apm_set_sec_mode_region_attr(uint32_t regn_num, apm_security_mode_t mode, uint32_t regn_pms) |
| 523 | +{ |
| 524 | + uint32_t reg = CPU_APM_REGION0_ATTR_REG + APM_REGION_ATTR_OFFSET * regn_num; |
| 525 | + uint32_t val = REG_READ(reg); |
| 526 | + val &= ~APM_REGION_PMS_MASK(mode); |
| 527 | + val |= APM_REGION_PMS_FIELD(mode, regn_pms); |
| 528 | + REG_WRITE(reg, val); |
| 529 | +} |
| 530 | + |
| 531 | +/** |
| 532 | + * @brief Lock security mode region attributes in CPU-APM |
| 533 | + * |
| 534 | + * @param regn_num Region number |
| 535 | + */ |
| 536 | +static inline void apm_ll_cpu_apm_lock_sec_mode_region_attr(uint32_t regn_num) |
| 537 | +{ |
| 538 | + REG_SET_BIT(CPU_APM_REGION0_ATTR_REG + APM_REGION_ATTR_OFFSET * regn_num, APM_REGION_LOCK_BIT); |
| 539 | +} |
| 540 | + |
| 541 | +/** |
| 542 | + * @brief Get exception data (regn, master, security mode) from CPU-APM |
| 543 | + * |
| 544 | + * @param path Access path |
| 545 | + * @return Exception data |
| 546 | + */ |
| 547 | +static inline uint32_t apm_ll_cpu_apm_get_excp_data(apm_ctrl_access_path_t path) |
| 548 | +{ |
| 549 | + return REG_READ(CPU_APM_M0_EXCEPTION_INFO0_REG + APM_EXCP_INFO_OFFSET * path); |
| 550 | +} |
| 551 | + |
| 552 | +/** |
| 553 | + * @brief Get exception status from CPU-APM |
| 554 | + * |
| 555 | + * @param path Access path |
| 556 | + * @return Exception type |
| 557 | + */ |
| 558 | +static inline uint32_t apm_ll_cpu_apm_get_excp_type(apm_ctrl_access_path_t path) |
| 559 | +{ |
| 560 | + return REG_READ(CPU_APM_M0_STATUS_REG + APM_EXCP_INFO_OFFSET * path); |
| 561 | +} |
| 562 | + |
| 563 | +/** |
| 564 | + * @brief Get exception address from CPU-APM |
| 565 | + * |
| 566 | + * @param path Access path |
| 567 | + * @return Exception address |
| 568 | + */ |
| 569 | +static inline uint32_t apm_ll_cpu_apm_get_excp_addr(apm_ctrl_access_path_t path) |
| 570 | +{ |
| 571 | + return REG_READ(CPU_APM_M0_EXCEPTION_INFO1_REG + APM_EXCP_INFO_OFFSET * path); |
| 572 | +} |
| 573 | + |
| 574 | +/** |
| 575 | + * @brief Get exception information from CPU-APM |
| 576 | + * |
| 577 | + * @param path Access path |
| 578 | + * @param info Pointer to store exception information |
| 579 | + */ |
| 580 | +static inline void apm_ll_cpu_apm_get_excp_info(apm_ctrl_access_path_t path, apm_ctrl_exception_info_t *info) |
| 581 | +{ |
| 582 | + cpu_apm_m0_exception_info0_reg_t reg; |
| 583 | + reg.val = apm_ll_cpu_apm_get_excp_data(path); |
| 584 | + info->regn = reg.apm_m0_exception_region; |
| 585 | + info->mode = reg.apm_m0_exception_mode; |
| 586 | + info->id = reg.apm_m0_exception_id; |
| 587 | + |
| 588 | + info->type = apm_ll_cpu_apm_get_excp_type(path); |
| 589 | + info->addr = apm_ll_cpu_apm_get_excp_addr(path); |
| 590 | +} |
| 591 | + |
| 592 | +/** |
| 593 | + * @brief Clear controller exception status in CPU-APM |
| 594 | + * |
| 595 | + * @param path Access path |
| 596 | + */ |
| 597 | +static inline void apm_ll_cpu_apm_clear_ctrl_excp_status(apm_ctrl_access_path_t path) |
| 598 | +{ |
| 599 | + REG_SET_BIT(CPU_APM_M0_STATUS_CLR_REG + APM_EXCP_INFO_OFFSET * path, APM_EXCP_STATUS_CLR_BIT); |
| 600 | +} |
| 601 | + |
| 602 | +/** |
| 603 | + * @brief Enable/disable controller interrupt in CPU-APM |
| 604 | + * |
| 605 | + * @param path Access path |
| 606 | + * @param enable True to enable, false to disable |
| 607 | + */ |
| 608 | +static inline void apm_ll_cpu_apm_enable_ctrl_intr(apm_ctrl_access_path_t path, bool enable) |
| 609 | +{ |
| 610 | + if (enable) { |
| 611 | + REG_SET_BIT(CPU_APM_INT_EN_REG, BIT(path)); |
| 612 | + } else { |
| 613 | + REG_CLR_BIT(CPU_APM_INT_EN_REG, BIT(path)); |
| 614 | + } |
| 615 | +} |
| 616 | + |
| 617 | +/** |
| 618 | + * @brief Enable/disable controller clock gating in CPU-APM |
| 619 | + * |
| 620 | + * @param enable True to enable, false to disable |
| 621 | + */ |
| 622 | +static inline void apm_ll_cpu_apm_enable_ctrl_clk_gating(bool enable) |
| 623 | +{ |
| 624 | + if (enable) { |
| 625 | + REG_CLR_BIT(CPU_APM_CLOCK_GATE_REG, CPU_APM_CLK_EN); |
| 626 | + } else { |
| 627 | + REG_SET_BIT(CPU_APM_CLOCK_GATE_REG, CPU_APM_CLK_EN); |
| 628 | + } |
| 629 | +} |
| 630 | + |
| 631 | +/** |
| 632 | + * @brief Get controller interrupt source number from CPU-APM |
| 633 | + * |
| 634 | + * @param path Access path |
| 635 | + * @return Interrupt source number |
| 636 | + */ |
| 637 | +static inline int apm_ll_cpu_apm_get_ctrl_intr_src(apm_ctrl_access_path_t path) |
| 638 | +{ |
| 639 | + return ETS_CPU_APM_M0_INTR_SOURCE + path; |
| 640 | +} |
| 641 | + |
451 | 642 | /** |
452 | 643 | * @brief Enable/disable APM reset event bypass |
453 | 644 | * |
|
0 commit comments