blob: a63d1f91e9697f5f52cdbddf7111f922b4cd8578 [file] [log] [blame]
Bin Menge159cdf2015-02-05 23:42:23 +08001/*
2 * Copyright (C) 2013, Intel Corporation
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * Ported from Intel released Quark UEFI BIOS
6 * QuarkSocPkg/QuarkNorthCluster/MemoryInit/Pei
7 *
8 * SPDX-License-Identifier: Intel
9 */
10
11#ifndef _MRC_UTIL_H_
12#define _MRC_UTIL_H_
13
14/* Turn on this macro to enable MRC debugging output */
15#undef MRC_DEBUG
16
17/* MRC Debug Support */
18#define DPF debug_cond
19
20/* debug print type */
21
22#ifdef MRC_DEBUG
23#define D_ERROR 0x0001
24#define D_INFO 0x0002
25#define D_REGRD 0x0004
26#define D_REGWR 0x0008
27#define D_FCALL 0x0010
28#define D_TRN 0x0020
29#define D_TIME 0x0040
30#else
31#define D_ERROR 0
32#define D_INFO 0
33#define D_REGRD 0
34#define D_REGWR 0
35#define D_FCALL 0
36#define D_TRN 0
37#define D_TIME 0
38#endif
39
40#define ENTERFN(...) debug_cond(D_FCALL, "<%s>\n", __func__)
41#define LEAVEFN(...) debug_cond(D_FCALL, "</%s>\n", __func__)
42#define REPORTFN(...) debug_cond(D_FCALL, "<%s/>\n", __func__)
43
Bin Menge159cdf2015-02-05 23:42:23 +080044/* Message Bus Port */
45#define MEM_CTLR 0x01
46#define HOST_BRIDGE 0x03
47#define MEM_MGR 0x05
48#define HTE 0x11
49#define DDRPHY 0x12
50
51/* number of sample points */
52#define SAMPLE_CNT 3
53/* number of PIs to increment per sample */
54#define SAMPLE_DLY 26
55
56enum {
57 /* indicates to decrease delays when looking for edge */
58 BACKWARD,
59 /* indicates to increase delays when looking for edge */
60 FORWARD
61};
62
63enum {
64 RCVN,
65 WDQS,
66 WDQX,
67 RDQS,
68 VREF,
69 WCMD,
70 WCTL,
71 WCLK,
72 MAX_ALGOS,
73};
74
75void mrc_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
76void mrc_alt_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
77void mrc_post_code(uint8_t major, uint8_t minor);
78void delay_n(uint32_t ns);
79void delay_u(uint32_t ms);
80void select_mem_mgr(void);
81void select_hte(void);
82void dram_init_command(uint32_t data);
83void dram_wake_command(void);
84void training_message(uint8_t channel, uint8_t rank, uint8_t byte_lane);
85
86void set_rcvn(uint8_t channel, uint8_t rank,
87 uint8_t byte_lane, uint32_t pi_count);
88uint32_t get_rcvn(uint8_t channel, uint8_t rank, uint8_t byte_lane);
89void set_rdqs(uint8_t channel, uint8_t rank,
90 uint8_t byte_lane, uint32_t pi_count);
91uint32_t get_rdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
92void set_wdqs(uint8_t channel, uint8_t rank,
93 uint8_t byte_lane, uint32_t pi_count);
94uint32_t get_wdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
95void set_wdq(uint8_t channel, uint8_t rank,
96 uint8_t byte_lane, uint32_t pi_count);
97uint32_t get_wdq(uint8_t channel, uint8_t rank, uint8_t byte_lane);
98void set_wcmd(uint8_t channel, uint32_t pi_count);
99uint32_t get_wcmd(uint8_t channel);
100void set_wclk(uint8_t channel, uint8_t rank, uint32_t pi_count);
101uint32_t get_wclk(uint8_t channel, uint8_t rank);
102void set_wctl(uint8_t channel, uint8_t rank, uint32_t pi_count);
103uint32_t get_wctl(uint8_t channel, uint8_t rank);
104void set_vref(uint8_t channel, uint8_t byte_lane, uint32_t setting);
105uint32_t get_vref(uint8_t channel, uint8_t byte_lane);
106
107uint32_t get_addr(uint8_t channel, uint8_t rank);
108uint32_t sample_dqs(struct mrc_params *mrc_params, uint8_t channel,
109 uint8_t rank, bool rcvn);
110void find_rising_edge(struct mrc_params *mrc_params, uint32_t delay[],
111 uint8_t channel, uint8_t rank, bool rcvn);
112uint32_t byte_lane_mask(struct mrc_params *mrc_params);
113uint32_t check_rw_coarse(struct mrc_params *mrc_params, uint32_t address);
114uint32_t check_bls_ex(struct mrc_params *mrc_params, uint32_t address);
115void lfsr32(uint32_t *lfsr_ptr);
116void clear_pointers(void);
117void print_timings(struct mrc_params *mrc_params);
118
119#endif /* _MRC_UTIL_H_ */