1150c2493STom Warren /* 2150c2493STom Warren * (C) Copyright 2010, 2011 3150c2493STom Warren * NVIDIA Corporation <www.nvidia.com> 4150c2493STom Warren * 5*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 6150c2493STom Warren */ 7150c2493STom Warren 8150c2493STom Warren #ifndef _WARM_BOOT_H_ 9150c2493STom Warren #define _WARM_BOOT_H_ 10150c2493STom Warren 11150c2493STom Warren #define STRAP_OPT_A_RAM_CODE_SHIFT 4 12150c2493STom Warren #define STRAP_OPT_A_RAM_CODE_MASK (0xf << STRAP_OPT_A_RAM_CODE_SHIFT) 13150c2493STom Warren 14150c2493STom Warren /* Defines the supported operating modes */ 15150c2493STom Warren enum fuse_operating_mode { 16150c2493STom Warren MODE_PRODUCTION = 3, 17150c2493STom Warren MODE_UNDEFINED, 18150c2493STom Warren }; 19150c2493STom Warren 20150c2493STom Warren /* Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) */ 21150c2493STom Warren enum { 22150c2493STom Warren HASH_LENGTH = 4 23150c2493STom Warren }; 24150c2493STom Warren 25150c2493STom Warren /* Defines the storage for a hash value (128 bits) */ 26150c2493STom Warren struct hash { 27150c2493STom Warren u32 hash[HASH_LENGTH]; 28150c2493STom Warren }; 29150c2493STom Warren 30150c2493STom Warren /* 31150c2493STom Warren * Defines the code header information for the boot rom. 32150c2493STom Warren * 33150c2493STom Warren * The code immediately follows the code header. 34150c2493STom Warren * 35150c2493STom Warren * Note that the code header needs to be 16 bytes aligned to preserve 36150c2493STom Warren * the alignment of relevant data for hash and decryption computations without 37150c2493STom Warren * requiring extra copies to temporary memory areas. 38150c2493STom Warren */ 39150c2493STom Warren struct wb_header { 40150c2493STom Warren u32 length_insecure; /* length of the code header */ 41150c2493STom Warren u32 reserved[3]; 42150c2493STom Warren struct hash hash; /* hash of header+code, starts next field*/ 43150c2493STom Warren struct hash random_aes_block; /* a data block to aid security. */ 44150c2493STom Warren u32 length_secure; /* length of the code header */ 45150c2493STom Warren u32 destination; /* destination address to put the wb code */ 46150c2493STom Warren u32 entry_point; /* execution address of the wb code */ 47150c2493STom Warren u32 code_length; /* length of the code */ 48150c2493STom Warren }; 49150c2493STom Warren 50150c2493STom Warren /* 51150c2493STom Warren * The warm boot code needs direct access to these registers since it runs in 52150c2493STom Warren * SRAM and cannot call other U-Boot code. 53150c2493STom Warren */ 54150c2493STom Warren union osc_ctrl_reg { 55150c2493STom Warren struct { 56150c2493STom Warren u32 xoe:1; 57150c2493STom Warren u32 xobp:1; 58150c2493STom Warren u32 reserved0:2; 59150c2493STom Warren u32 xofs:6; 60150c2493STom Warren u32 reserved1:2; 61150c2493STom Warren u32 xods:5; 62150c2493STom Warren u32 reserved2:3; 63150c2493STom Warren u32 oscfi_spare:8; 64150c2493STom Warren u32 pll_ref_div:2; 65150c2493STom Warren u32 osc_freq:2; 66150c2493STom Warren }; 67150c2493STom Warren u32 word; 68150c2493STom Warren }; 69150c2493STom Warren 70150c2493STom Warren union pllx_base_reg { 71150c2493STom Warren struct { 72150c2493STom Warren u32 divm:5; 73150c2493STom Warren u32 reserved0:3; 74150c2493STom Warren u32 divn:10; 75150c2493STom Warren u32 reserved1:2; 76150c2493STom Warren u32 divp:3; 77150c2493STom Warren u32 reserved2:4; 78150c2493STom Warren u32 lock:1; 79150c2493STom Warren u32 reserved3:1; 80150c2493STom Warren u32 ref_dis:1; 81150c2493STom Warren u32 enable:1; 82150c2493STom Warren u32 bypass:1; 83150c2493STom Warren }; 84150c2493STom Warren u32 word; 85150c2493STom Warren }; 86150c2493STom Warren 87150c2493STom Warren union pllx_misc_reg { 88150c2493STom Warren struct { 89150c2493STom Warren u32 vcocon:4; 90150c2493STom Warren u32 lfcon:4; 91150c2493STom Warren u32 cpcon:4; 92150c2493STom Warren u32 lock_sel:6; 93150c2493STom Warren u32 reserved0:1; 94150c2493STom Warren u32 lock_enable:1; 95150c2493STom Warren u32 reserved1:1; 96150c2493STom Warren u32 dccon:1; 97150c2493STom Warren u32 pts:2; 98150c2493STom Warren u32 reserved2:6; 99150c2493STom Warren u32 out1_div_byp:1; 100150c2493STom Warren u32 out1_inv_clk:1; 101150c2493STom Warren }; 102150c2493STom Warren u32 word; 103150c2493STom Warren }; 104150c2493STom Warren 105150c2493STom Warren /* 106150c2493STom Warren * TODO: This register is not documented in the TRM yet. We could move this 107150c2493STom Warren * into the EMC and give it a proper interface, but not while it is 108150c2493STom Warren * undocumented. 109150c2493STom Warren */ 110150c2493STom Warren union scratch3_reg { 111150c2493STom Warren struct { 112150c2493STom Warren u32 pllx_base_divm:5; 113150c2493STom Warren u32 pllx_base_divn:10; 114150c2493STom Warren u32 pllx_base_divp:3; 115150c2493STom Warren u32 pllx_misc_lfcon:4; 116150c2493STom Warren u32 pllx_misc_cpcon:4; 117150c2493STom Warren }; 118150c2493STom Warren u32 word; 119150c2493STom Warren }; 120150c2493STom Warren 121150c2493STom Warren 122150c2493STom Warren /** 123150c2493STom Warren * Save warmboot memory settings for a later resume 124150c2493STom Warren * 125150c2493STom Warren * @return 0 if ok, -1 on error 126150c2493STom Warren */ 127150c2493STom Warren int warmboot_save_sdram_params(void); 128150c2493STom Warren 129150c2493STom Warren int warmboot_prepare_code(u32 seg_address, u32 seg_length); 130150c2493STom Warren int sign_data_block(u8 *source, u32 length, u8 *signature); 131150c2493STom Warren void wb_start(void); /* Start of WB assembly code */ 132150c2493STom Warren void wb_end(void); /* End of WB assembly code */ 133150c2493STom Warren 134150c2493STom Warren #endif 135