sys_proto.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2014
  4. * Texas Instruments, <www.ti.com>
  5. */
  6. #ifndef _TI_COMMON_SYS_PROTO_H_
  7. #define _TI_COMMON_SYS_PROTO_H_
  8. #include <asm/global_data.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. #ifdef CONFIG_ARCH_OMAP2PLUS
  11. #define TI_ARMV7_DRAM_ADDR_SPACE_START 0x80000000
  12. #define TI_ARMV7_DRAM_ADDR_SPACE_END 0xFFFFFFFF
  13. #define OMAP_INIT_CONTEXT_SPL 0
  14. #define OMAP_INIT_CONTEXT_UBOOT_FROM_NOR 1
  15. #define OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL 2
  16. #define OMAP_INIT_CONTEXT_UBOOT_AFTER_CH 3
  17. static inline u32 running_from_sdram(void)
  18. {
  19. u32 pc;
  20. asm volatile ("mov %0, pc" : "=r" (pc));
  21. return ((pc >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
  22. (pc < TI_ARMV7_DRAM_ADDR_SPACE_END));
  23. }
  24. static inline u8 uboot_loaded_by_spl(void)
  25. {
  26. /*
  27. * u-boot can be running from sdram either because of configuration
  28. * Header or by SPL. If because of CH, then the romcode sets the
  29. * CHSETTINGS executed bit to true in the boot parameter structure that
  30. * it passes to the bootloader.This parameter is stored in the ch_flags
  31. * variable by both SPL and u-boot.Check out for CHSETTINGS, which is a
  32. * mandatory section if CH is present.
  33. */
  34. if (gd->arch.omap_ch_flags & CH_FLAGS_CHSETTINGS)
  35. return 0;
  36. else
  37. return running_from_sdram();
  38. }
  39. /*
  40. * The basic hardware init of OMAP(s_init()) can happen in 4
  41. * different contexts:
  42. * 1. SPL running from SRAM
  43. * 2. U-Boot running from FLASH
  44. * 3. Non-XIP U-Boot loaded to SDRAM by SPL
  45. * 4. Non-XIP U-Boot loaded to SDRAM by ROM code using the
  46. * Configuration Header feature
  47. *
  48. * This function finds this context.
  49. * Defining as inline may help in compiling out unused functions in SPL
  50. */
  51. static inline u32 omap_hw_init_context(void)
  52. {
  53. #ifdef CONFIG_SPL_BUILD
  54. return OMAP_INIT_CONTEXT_SPL;
  55. #else
  56. if (uboot_loaded_by_spl())
  57. return OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL;
  58. else if (running_from_sdram())
  59. return OMAP_INIT_CONTEXT_UBOOT_AFTER_CH;
  60. else
  61. return OMAP_INIT_CONTEXT_UBOOT_FROM_NOR;
  62. #endif
  63. }
  64. #endif
  65. #endif