sbsa.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2019-2023, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdint.h>
  8. #include <drivers/arm/sbsa.h>
  9. #include <lib/mmio.h>
  10. #include <plat/common/platform.h>
  11. void sbsa_watchdog_offset_reg_write(uintptr_t base, uint64_t value)
  12. {
  13. assert((value >> SBSA_WDOG_WOR_WIDTH) == 0);
  14. mmio_write_32(base + SBSA_WDOG_WOR_LOW_OFFSET,
  15. ((uint32_t)value & UINT32_MAX));
  16. mmio_write_32(base + SBSA_WDOG_WOR_HIGH_OFFSET, (uint32_t)(value >> 32));
  17. }
  18. /*
  19. * Start the watchdog timer at base address "base" for a
  20. * period of "ms" milliseconds.The watchdog has to be
  21. * refreshed within this time period.
  22. */
  23. void sbsa_wdog_start(uintptr_t base, uint64_t ms)
  24. {
  25. uint64_t counter_freq;
  26. uint64_t offset_reg_value;
  27. counter_freq = (uint64_t)plat_get_syscnt_freq2();
  28. offset_reg_value = ms * counter_freq / 1000;
  29. sbsa_watchdog_offset_reg_write(base, offset_reg_value);
  30. mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, SBSA_WDOG_WCS_EN);
  31. }
  32. /* Stop the watchdog */
  33. void sbsa_wdog_stop(uintptr_t base)
  34. {
  35. mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, (0x0));
  36. }
  37. /* Refresh the secure watchdog timer explicitly */
  38. void sbsa_wdog_refresh(uintptr_t refresh_base)
  39. {
  40. mmio_write_32(refresh_base + SBSA_WDOG_WRR_OFFSET, SBSA_WDOG_WRR_REFRESH);
  41. }