sys_proto.h 1.9 KB

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