reset.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) Copyright 2012 Stephen Warren
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/wdog.h>
  11. #include <efi_loader.h>
  12. #define RESET_TIMEOUT 10
  13. /*
  14. * The Raspberry Pi firmware uses the RSTS register to know which partiton
  15. * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
  16. * Partiton 63 is a special partition used by the firmware to indicate halt.
  17. */
  18. #define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555
  19. /* max ticks timeout */
  20. #define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff
  21. #ifdef CONFIG_BCM2835_WDT
  22. extern void hw_watchdog_disable(void);
  23. #else
  24. void hw_watchdog_disable(void) {}
  25. #endif
  26. __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs =
  27. (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
  28. void __efi_runtime reset_cpu(ulong ticks)
  29. {
  30. uint32_t rstc, timeout;
  31. if (ticks == 0) {
  32. hw_watchdog_disable();
  33. timeout = RESET_TIMEOUT;
  34. } else
  35. timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
  36. rstc = readl(&wdog_regs->rstc);
  37. rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
  38. rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
  39. writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
  40. writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
  41. }
  42. #ifdef CONFIG_EFI_LOADER
  43. void __efi_runtime EFIAPI efi_reset_system(
  44. enum efi_reset_type reset_type,
  45. efi_status_t reset_status,
  46. unsigned long data_size, void *reset_data)
  47. {
  48. u32 val;
  49. if (reset_type == EFI_RESET_COLD ||
  50. reset_type == EFI_RESET_WARM ||
  51. reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
  52. reset_cpu(0);
  53. } else if (reset_type == EFI_RESET_SHUTDOWN) {
  54. /*
  55. * We set the watchdog hard reset bit here to distinguish this reset
  56. * from the normal (full) reset. bootcode.bin will not reboot after a
  57. * hard reset.
  58. */
  59. val = readl(&wdog_regs->rsts);
  60. val |= BCM2835_WDOG_PASSWORD;
  61. val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
  62. writel(val, &wdog_regs->rsts);
  63. reset_cpu(0);
  64. }
  65. while (1) { }
  66. }
  67. efi_status_t efi_reset_system_init(void)
  68. {
  69. return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
  70. }
  71. #endif