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