1 /************************************************************************ 2 * 3 * Copyright (c) 2013-2015 Intel Corporation. 4 * 5 * This program and the accompanying materials 6 * are licensed and made available under the terms and conditions of the BSD License 7 * which accompanies this distribution. The full text of the license may be found at 8 * http://opensource.org/licenses/bsd-license.php 9 * 10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 * 13 ***************************************************************************/ 14 #ifndef _MEMINIT_UTILS_H_ 15 #define _MEMINIT_UTILS_H_ 16 17 // General Definitions: 18 #ifdef QUICKSIM 19 #define SAMPLE_SIZE 4 // reduce number of training samples in simulation env 20 #else 21 #define SAMPLE_SIZE 6 // must be odd number 22 #endif 23 24 #define EARLY_DB (0x12) // must be less than this number to enable early deadband 25 #define LATE_DB (0x34) // must be greater than this number to enable late deadband 26 #define CHX_REGS (11*4) 27 #define FULL_CLK 128 28 #define HALF_CLK 64 29 #define QRTR_CLK 32 30 31 32 33 #define MCEIL(num,den) ((uint8_t)((num+den-1)/den)) 34 #define MMAX(a,b) ((((int32_t)(a))>((int32_t)(b)))?(a):(b)) 35 #define MCOUNT(a) (sizeof(a)/sizeof(*a)) 36 37 typedef enum ALGOS_enum { 38 eRCVN = 0, 39 eWDQS, 40 eWDQx, 41 eRDQS, 42 eVREF, 43 eWCMD, 44 eWCTL, 45 eWCLK, 46 eMAX_ALGOS, 47 } ALGOs_t; 48 49 50 // Prototypes: 51 void set_rcvn(uint8_t channel, uint8_t rank, uint8_t byte_lane, uint32_t pi_count); 52 void set_rdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane, uint32_t pi_count); 53 void set_wdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane, uint32_t pi_count); 54 void set_wdq(uint8_t channel, uint8_t rank, uint8_t byte_lane, uint32_t pi_count); 55 void set_wcmd(uint8_t channel, uint32_t pi_count); 56 void set_wclk(uint8_t channel, uint8_t grp, uint32_t pi_count); 57 void set_wctl(uint8_t channel, uint8_t rank, uint32_t pi_count); 58 void set_vref(uint8_t channel, uint8_t byte_lane, uint32_t setting); 59 uint32_t get_rcvn(uint8_t channel, uint8_t rank, uint8_t byte_lane); 60 uint32_t get_rdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane); 61 uint32_t get_wdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane); 62 uint32_t get_wdq(uint8_t channel, uint8_t rank, uint8_t byte_lane); 63 uint32_t get_wcmd(uint8_t channel); 64 uint32_t get_wclk(uint8_t channel, uint8_t group); 65 uint32_t get_wctl(uint8_t channel, uint8_t rank); 66 uint32_t get_vref(uint8_t channel, uint8_t byte_lane); 67 68 void clear_pointers(void); 69 void enable_cache(void); 70 void disable_cache(void); 71 void find_rising_edge(MRCParams_t *mrc_params, uint32_t delay[], uint8_t channel, uint8_t rank, bool rcvn); 72 uint32_t sample_dqs(MRCParams_t *mrc_params, uint8_t channel, uint8_t rank, bool rcvn); 73 uint32_t get_addr(MRCParams_t *mrc_params, uint8_t channel, uint8_t rank); 74 uint32_t byte_lane_mask(MRCParams_t *mrc_params); 75 76 uint64_t read_tsc(void); 77 uint32_t get_tsc_freq(void); 78 void delay_n(uint32_t nanoseconds); 79 void delay_u(uint32_t microseconds); 80 void delay_m(uint32_t milliseconds); 81 void delay_s(uint32_t seconds); 82 83 void post_code(uint8_t major, uint8_t minor); 84 void training_message(uint8_t channel, uint8_t rank, uint8_t byte_lane); 85 void print_timings(MRCParams_t *mrc_params); 86 87 void enable_scrambling(MRCParams_t *mrc_params); 88 void store_timings(MRCParams_t *mrc_params); 89 void restore_timings(MRCParams_t *mrc_params); 90 void default_timings(MRCParams_t *mrc_params); 91 92 #ifndef SIM 93 void *memset(void *d, int c, size_t n); 94 void *memcpy(void *d, const void *s, size_t n); 95 #endif 96 97 #endif // _MEMINIT_UTILS_H_ 98