blob: 3ee50b037482e33de9ade1ab7fbfdc17fab7b200 [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
Patrick Georgi2efc8802012-11-06 11:03:53 +01004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Patrick Georgi2efc8802012-11-06 11:03:53 +010013 */
14
15#ifndef __NORTHBRIDGE_INTEL_GM45_GM45_H__
Edward O'Callaghan089a5102015-01-06 02:48:57 +110016#define __NORTHBRIDGE_INTEL_GM45_GM45_H__
Patrick Georgi2efc8802012-11-06 11:03:53 +010017
Elyes HAOUAS21b71ce62018-06-16 18:43:52 +020018#include <southbridge/intel/i82801ix/i82801ix.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010019
20#ifndef __ACPI__
21
22#include <stdint.h>
23
24typedef enum {
25 FSB_CLOCK_1067MHz = 0,
26 FSB_CLOCK_800MHz = 1,
27 FSB_CLOCK_667MHz = 2,
28} fsb_clock_t;
29
30typedef enum { /* Steppings below B1 were pre-production,
31 conversion stepping A1 is... ?
32 We'll support B1, B2, B3, and conversion stepping A1. */
33 STEPPING_A0 = 0,
34 STEPPING_A1 = 1,
35 STEPPING_A2 = 2,
36 STEPPING_A3 = 3,
37 STEPPING_B0 = 4,
38 STEPPING_B1 = 5,
39 STEPPING_B2 = 6,
40 STEPPING_B3 = 7,
41 STEPPING_CONVERSION_A1 = 9,
42} stepping_t;
43
44typedef enum {
45 GMCH_GM45 = 0,
46 GMCH_GM47,
47 GMCH_GM49,
48 GMCH_GE45,
49 GMCH_GL40,
50 GMCH_GL43,
51 GMCH_GS40,
52 GMCH_GS45,
53 GMCH_PM45,
54 GMCH_UNKNOWN
55} gmch_gfx_t;
56
57typedef enum {
58 MEM_CLOCK_533MHz = 0,
59 MEM_CLOCK_400MHz = 1,
60 MEM_CLOCK_333MHz = 2,
61 MEM_CLOCK_1067MT = 0,
62 MEM_CLOCK_800MT = 1,
63 MEM_CLOCK_667MT = 2,
64} mem_clock_t;
65
66typedef enum {
67 DDR1 = 1,
68 DDR2 = 2,
69 DDR3 = 3,
70} ddr_t;
71
72typedef enum {
73 CHANNEL_MODE_SINGLE,
74 CHANNEL_MODE_DUAL_ASYNC,
75 CHANNEL_MODE_DUAL_INTERLEAVED,
76} channel_mode_t;
77
78typedef enum { /* as in DDR3 spd */
79 CHIP_WIDTH_x4 = 0,
80 CHIP_WIDTH_x8 = 1,
81 CHIP_WIDTH_x16 = 2,
82 CHIP_WIDTH_x32 = 3,
83} chip_width_t;
84
85typedef enum { /* as in DDR3 spd */
86 CHIP_CAP_256M = 0,
87 CHIP_CAP_512M = 1,
88 CHIP_CAP_1G = 2,
89 CHIP_CAP_2G = 3,
90 CHIP_CAP_4G = 4,
91 CHIP_CAP_8G = 5,
92 CHIP_CAP_16G = 6,
93} chip_capacity_t;
94
95typedef struct {
96 unsigned int CAS;
97 fsb_clock_t fsb_clock;
98 mem_clock_t mem_clock;
99 channel_mode_t channel_mode;
100 unsigned int tRAS;
101 unsigned int tRP;
102 unsigned int tRCD;
103 unsigned int tRFC;
104 unsigned int tWR;
105 unsigned int tRD;
106 unsigned int tRRD;
107 unsigned int tFAW;
108 unsigned int tWL;
109} timings_t;
110
111typedef struct {
112 unsigned int card_type; /* 0x0: unpopulated,
113 0xa - 0xf: raw card type A - F */
114 chip_width_t chip_width;
115 chip_capacity_t chip_capacity;
116 unsigned int page_size; /* of whole DIMM in Bytes (4096 or 8192) */
117 unsigned int banks;
118 unsigned int ranks;
Martin Roth128c1042016-11-18 09:29:03 -0700119 unsigned int rank_capacity_mb; /* per rank in Megabytes */
Patrick Georgi2efc8802012-11-06 11:03:53 +0100120} dimminfo_t;
121
122/* The setup is one DIMM per channel, so there's no need to find a
123 common timing setup between multiple chips (but chip and controller
124 still need to be coordinated */
125typedef struct {
126 stepping_t stepping;
127 int txt_enabled;
128 int cores;
129 gmch_gfx_t gfx_type;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100130 int max_ddr2_mhz;
131 int max_ddr3_mt;
132 fsb_clock_t max_fsb;
133 int max_fsb_mhz;
134 int max_render_mhz;
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200135 int enable_igd;
136 int enable_peg;
137 u16 ggc;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100138
Nico Huber5aaeb272015-12-30 00:17:27 +0100139 /* to be filled in romstage main: */
Patrick Georgi2efc8802012-11-06 11:03:53 +0100140 int spd_type;
141 timings_t selected_timings;
142 dimminfo_t dimms[2];
Vladimir Serbinenkoc4d89482014-06-05 09:14:48 +0200143 u8 spd_map[4];
Nico Huber5aaeb272015-12-30 00:17:27 +0100144 int gs45_low_power_mode; /* low power mode of GMCH_GS45 */
145 int sff; /* small form factor option (soldered down DIMM) */
Patrick Georgi2efc8802012-11-06 11:03:53 +0100146} sysinfo_t;
147#define TOTAL_CHANNELS 2
148#define CHANNEL_IS_POPULATED(dimms, idx) (dimms[idx].card_type != 0)
149#define CHANNEL_IS_CARDF(dimms, idx) (dimms[idx].card_type == 0xf)
150#define IF_CHANNEL_POPULATED(dimms, idx) if (dimms[idx].card_type != 0)
151#define FOR_EACH_CHANNEL(idx) \
152 for (idx = 0; idx < TOTAL_CHANNELS; ++idx)
153#define FOR_EACH_POPULATED_CHANNEL(dimms, idx) \
154 FOR_EACH_CHANNEL(idx) IF_CHANNEL_POPULATED(dimms, idx)
155
156#define RANKS_PER_CHANNEL 4 /* Only two may be populated */
157#define IF_RANK_POPULATED(dimms, ch, r) \
158 if (dimms[ch].card_type && ((r) < dimms[ch].ranks))
159#define FOR_EACH_RANK_IN_CHANNEL(r) \
160 for (r = 0; r < RANKS_PER_CHANNEL; ++r)
161#define FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) \
162 FOR_EACH_RANK_IN_CHANNEL(r) IF_RANK_POPULATED(dimms, ch, r)
163#define FOR_EACH_RANK(ch, r) \
164 FOR_EACH_CHANNEL(ch) FOR_EACH_RANK_IN_CHANNEL(r)
165#define FOR_EACH_POPULATED_RANK(dimms, ch, r) \
166 FOR_EACH_RANK(ch, r) IF_RANK_POPULATED(dimms, ch, r)
167
168#define DDR3_MAX_CAS 18
169
170enum {
171 VCO_2666 = 4,
172 VCO_3200 = 0,
173 VCO_4000 = 1,
174 VCO_5333 = 2,
175};
176
177#endif
178
179/* Offsets of read/write training results in CMOS.
180 They will be restored upon S3 resumes. */
181#define CMOS_READ_TRAINING 0x80 /* 16 bytes */
182#define CMOS_WRITE_TRAINING 0x90 /* 16 bytes
183 (could be reduced to 10 bytes) */
184
185
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800186#ifndef __ACPI__
187#define DEFAULT_MCHBAR ((u8 *)0xfed14000)
188#define DEFAULT_DMIBAR ((u8 *)0xfed18000)
189#else
Patrick Georgi2efc8802012-11-06 11:03:53 +0100190#define DEFAULT_MCHBAR 0xfed14000
191#define DEFAULT_DMIBAR 0xfed18000
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800192#endif
Patrick Georgi2efc8802012-11-06 11:03:53 +0100193#define DEFAULT_EPBAR 0xfed19000
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800194#define DEFAULT_HECIBAR ((u8 *)0xfed1a000)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100195
Patrick Georgi2efc8802012-11-06 11:03:53 +0100196
197#define IOMMU_BASE1 0xfed90000
198#define IOMMU_BASE2 0xfed91000
199#define IOMMU_BASE3 0xfed92000
200#define IOMMU_BASE4 0xfed93000
201
202/*
203 * D0:F0
204 */
205#define D0F0_EPBAR_LO 0x40
206#define D0F0_EPBAR_HI 0x44
207#define D0F0_MCHBAR_LO 0x48
208#define D0F0_MCHBAR_HI 0x4c
209#define D0F0_GGC 0x52
210#define D0F0_DEVEN 0x54
211#define D0F0_PCIEXBAR_LO 0x60
212#define D0F0_PCIEXBAR_HI 0x64
213#define D0F0_DMIBAR_LO 0x68
214#define D0F0_DMIBAR_HI 0x6c
215#define D0F0_PMBASE 0x78
216#define D0F0_PAM(x) (0x90+(x)) /* 0-6*/
217#define D0F0_REMAPBASE 0x98
218#define D0F0_REMAPLIMIT 0x9a
219#define D0F0_SMRAM 0x9d
220#define D0F0_ESMRAMC 0x9e
221#define D0F0_TOM 0xa0
222#define D0F0_TOUUD 0xa2
223#define D0F0_TOLUD 0xb0
224#define D0F0_SKPD 0xdc /* Scratchpad Data */
225#define D0F0_CAPID0 0xe0
226
227/*
228 * D1:F0 PEG
229 */
230#define PEG_CAP 0xa2
231#define SLOTCAP 0xb4
232#define PEGLC 0xec
233#define D1F0_VCCAP 0x104
234#define D1F0_VC0RCTL 0x114
235
236/*
237 * Graphics frequencies
238 */
239#define GCFGC_PCIDEV PCI_DEV(0, 2, 0)
240#define GCFGC_OFFSET 0xf0
241#define GCFGC_CR_SHIFT 0
242#define GCFGC_CR_MASK (0xf << GCFGC_CR_SHIFT)
243#define GCFGC_CS_SHIFT 8
244#define GCFGC_CS_MASK (0xf << GCFGC_CS_SHIFT)
245#define GCFGC_CD_SHIFT 12
246#define GCFGC_CD_MASK (0x1 << GCFGC_CD_SHIFT)
247#define GCFGC_UPDATE_SHIFT 5
248#define GCFGC_UPDATE (0x1 << GCFGC_UPDATE_SHIFT)
249
250/*
251 * MCHBAR
252 */
253
254#define MCHBAR8(x) *((volatile u8 *)(DEFAULT_MCHBAR + x))
255#define MCHBAR16(x) *((volatile u16 *)(DEFAULT_MCHBAR + x))
256#define MCHBAR32(x) *((volatile u32 *)(DEFAULT_MCHBAR + x))
257
Nico Huberd85a71a2016-11-27 14:43:12 +0100258#define HPLLVCO_MCHBAR 0x0c0f
259
Patrick Georgi2efc8802012-11-06 11:03:53 +0100260#define PMSTS_MCHBAR 0x0f14 /* Self refresh channel status */
261#define PMSTS_WARM_RESET (1 << 1)
262#define PMSTS_BOTH_SELFREFRESH (1 << 0)
263
264#define CLKCFG_MCHBAR 0x0c00
265#define CLKCFG_FSBCLK_SHIFT 0
266#define CLKCFG_FSBCLK_MASK (7 << CLKCFG_FSBCLK_SHIFT)
267#define CLKCFG_MEMCLK_SHIFT 4
268#define CLKCFG_MEMCLK_MASK (7 << CLKCFG_MEMCLK_SHIFT)
269#define CLKCFG_UPDATE (1 << 12)
270
271#define SSKPD_MCHBAR 0x0c1c
272#define SSKPD_CLK_SHIFT 0
273#define SSKPD_CLK_MASK (7 << SSKPD_CLK_SHIFT)
274
275#define DCC_MCHBAR 0x200
276#define DCC_NO_CHANXOR (1 << 10)
277#define DCC_INTERLEAVED (1 << 1)
278#define DCC_CMD_SHIFT 16
279#define DCC_CMD_MASK (7 << DCC_CMD_SHIFT)
280#define DCC_CMD_NOP (1 << DCC_CMD_SHIFT)
281 /* For mode register mr0: */
282#define DCC_SET_MREG (3 << DCC_CMD_SHIFT)
283 /* For extended mode registers mr1 to mr3: */
284#define DCC_SET_EREG (4 << DCC_CMD_SHIFT)
285#define DCC_SET_EREG_SHIFT 21
286#define DCC_SET_EREG_MASK (DCC_CMD_MASK | (3 << DCC_SET_EREG_SHIFT))
287#define DCC_SET_EREGx(x) ((DCC_SET_EREG | \
288 ((x - 1) << DCC_SET_EREG_SHIFT)) & \
289 DCC_SET_EREG_MASK)
290
291/* Per channel DRAM Row Attribute registers (32-bit) */
292#define CxDRA_MCHBAR(x) (0x1208 + (x * 0x0100))
293#define CxDRA_PAGESIZE_SHIFT(r) (r * 4) /* Per rank r */
294#define CxDRA_PAGESIZE_MASKr(r) (0x7 << CxDRA_PAGESIZE_SHIFT(r))
295#define CxDRA_PAGESIZE_MASK 0x0000ffff
296#define CxDRA_PAGESIZE(r, p) /* for log2(dimm page size in bytes) p */ \
297 (((p - 10) << CxDRA_PAGESIZE_SHIFT(r)) & CxDRA_PAGESIZE_MASKr(r))
298#define CxDRA_BANKS_SHIFT(r) ((r * 3) + 16)
299#define CxDRA_BANKS_MASKr(r) (0x3 << CxDRA_BANKS_SHIFT(r))
300#define CxDRA_BANKS_MASK 0x07ff0000
301#define CxDRA_BANKS(r, b) /* for number of banks b */ \
302 ((b << (CxDRA_BANKS_SHIFT(r) - 3)) & CxDRA_BANKS_MASKr(r))
303
304/*
305 * Per channel DRAM Row Boundary registers (32-bit)
306 * Every two ranks share one register and must be programmed at the same time.
307 * All registers (4 ranks per channel) have to be set.
308 */
309#define CxDRBy_MCHBAR(x, r) (0x1200 + (x * 0x0100) + ((r/2) * 4))
310#define CxDRBy_BOUND_SHIFT(r) ((r % 2) * 16)
311#define CxDRBy_BOUND_MASK(r) (0x1fc << CxDRBy_BOUND_SHIFT(r))
312#define CxDRBy_BOUND_MB(r, b) /* for boundary in MB b */ \
313 (((b >> 5) << CxDRBy_BOUND_SHIFT(r)) & CxDRBy_BOUND_MASK(r))
314
315#define CxDRC0_MCHBAR(x) (0x1230 + (x * 0x0100))
316#define CxDRC0_RANKEN0 (1 << 24) /* Rank Enable */
317#define CxDRC0_RANKEN1 (1 << 25)
318#define CxDRC0_RANKEN2 (1 << 26)
319#define CxDRC0_RANKEN3 (1 << 27)
320#define CxDRC0_RANKEN(r) (1 << (24 + r))
321#define CxDRC0_RANKEN_MASK (0xf << 24)
322#define CxDRC0_RMS_SHIFT 8 /* Refresh Mode Select */
323#define CxDRC0_RMS_MASK (7 << CxDRC0_RMS_SHIFT)
324#define CxDRC0_RMS_78US (2 << CxDRC0_RMS_SHIFT)
325#define CxDRC0_RMS_39US (3 << CxDRC0_RMS_SHIFT)
326
327#define CxDRC1_MCHBAR(x) (0x1234 + (x * 0x0100))
328#define CxDRC1_SSDS_SHIFT 24
329#define CxDRC1_SSDS_MASK (0xff << CxDRC1_SSDS_SHIFT)
330#define CxDRC1_DS (0x91 << CxDRC1_SSDS_SHIFT)
331#define CxDRC1_SS (0xb1 << CxDRC1_SSDS_SHIFT)
332#define CxDRC1_NOTPOP(r) (1 << (16 + r)) /* Write 1 for Not Populated */
333#define CxDRC1_NOTPOP_MASK (0xf << 16)
334#define CxDRC1_MUSTWR (3 << 11)
335
336#define CxDRC2_MCHBAR(x) (0x1238 + (x * 0x0100))
337#define CxDRC2_NOTPOP(r) (1 << (24 + r)) /* Write 1 for Not Populated */
338#define CxDRC2_NOTPOP_MASK (0xf << 24)
339#define CxDRC2_MUSTWR (1 << 12)
340#define CxDRC2_CLK1067MT (1 << 0)
341
342/* DRAM Timing registers (32-bit each) */
343#define CxDRT0_MCHBAR(x) (0x1210 + (x * 0x0100))
344#define CxDRT0_BtB_WtP_SHIFT 26
345#define CxDRT0_BtB_WtP_MASK (0x1f << CxDRT0_BtB_WtP_SHIFT)
346#define CxDRT0_BtB_WtR_SHIFT 20
347#define CxDRT0_BtB_WtR_MASK (0x1f << CxDRT0_BtB_WtR_SHIFT)
348#define CxDRT1_MCHBAR(x) (0x1214 + (x * 0x0100))
349#define CxDRT2_MCHBAR(x) (0x1218 + (x * 0x0100))
350#define CxDRT3_MCHBAR(x) (0x121c + (x * 0x0100))
351#define CxDRT4_MCHBAR(x) (0x1220 + (x * 0x0100))
352#define CxDRT5_MCHBAR(x) (0x1224 + (x * 0x0100))
353#define CxDRT6_MCHBAR(x) (0x1228 + (x * 0x0100))
354
355/* Clock disable registers (32-bit each) */
356#define CxDCLKDIS_MCHBAR(x) (0x120c + (x * 0x0100))
357#define CxDCLKDIS_MASK 3
358#define CxDCLKDIS_ENABLE 3 /* Always enable both clock pairs. */
359
360/* On-Die-Termination registers (2x 32-bit per channel) */
361#define CxODT_HIGH(x) (0x124c + (x * 0x0100))
362#define CxODT_LOW(x) (0x1248 + (x * 0x0100))
363
364/* Write Training registers. */
365#define CxWRTy_MCHBAR(ch, s) (0x1470 + (ch * 0x0100) + ((3 - s) * 4))
366
367#define CxGTEW(x) (0x1270+(x*0x100))
368#define CxGTC(x) (0x1274+(x*0x100))
369#define CxDTPEW(x) (0x1278+(x*0x100))
370#define CxDTAEW(x) (0x1280+(x*0x100))
371#define CxDTC(x) (0x1288+(x*0x100))
372
373
374/*
375 * DMIBAR
376 */
377
378#define DMIBAR8(x) *((volatile u8 *)(DEFAULT_DMIBAR + x))
379#define DMIBAR16(x) *((volatile u16 *)(DEFAULT_DMIBAR + x))
380#define DMIBAR32(x) *((volatile u32 *)(DEFAULT_DMIBAR + x))
381
382#define DMIVC0RCTL 0x14
383#define DMIVC1RCTL 0x20
384#define DMIVC1RSTS 0x26
385#define DMIESD 0x44
386#define DMILE1D 0x50
387#define DMILE1A 0x58
388#define DMILE2D 0x60
389#define DMILE2A 0x68
390
391
392/*
393 * EPBAR
394 */
395
396#define EPBAR8(x) *((volatile u8 *)(DEFAULT_EPBAR + x))
397#define EPBAR16(x) *((volatile u16 *)(DEFAULT_EPBAR + x))
398#define EPBAR32(x) *((volatile u32 *)(DEFAULT_EPBAR + x))
399
400#define EPESD 0x44
401#define EPLE1D 0x50
402#define EPLE1A 0x58
403#define EPLE2D 0x60
404
405
406#ifndef __ACPI__
407void gm45_early_init(void);
408void gm45_early_reset(void);
409
410void enter_raminit_or_reset(void);
411void get_gmch_info(sysinfo_t *);
412void raminit(sysinfo_t *, int s3resume);
413void raminit_thermal(const sysinfo_t *);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200414void init_igd(const sysinfo_t *const);
Vladimir Serbinenko020dc0e2014-08-12 22:50:40 +0200415void init_pm(const sysinfo_t *, int do_freq_scaling_cfg);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200416void igd_compute_ggc(sysinfo_t *const sysinfo);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100417
418int raminit_read_vco_index(void);
419u32 raminit_get_rank_addr(unsigned int channel, unsigned int rank);
420
421void raminit_rcomp_calibration(stepping_t stepping);
422void raminit_reset_readwrite_pointers(void);
423void raminit_receive_enable_calibration(const timings_t *, const dimminfo_t *);
424void raminit_write_training(const mem_clock_t, const dimminfo_t *, int s3resume);
425void raminit_read_training(const dimminfo_t *, int s3resume);
426
427void gm45_late_init(stepping_t);
428
429u32 decode_igd_memory_size(u32 gms);
430u32 decode_igd_gtt_size(u32 gsm);
Arthur Heymans8b766052018-01-24 23:25:13 +0100431u32 decode_tseg_size(u8 esmramc);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100432
433void init_iommu(void);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200434
Arthur Heymans3b0eb602019-01-31 22:47:09 +0100435/* romstage mainboard hookups */
Arthur Heymans3b0eb602019-01-31 22:47:09 +0100436void mb_setup_superio(void); /* optional */
437void get_mb_spd_addrmap(u8 spd_addrmap[4]);
438void mb_pre_raminit_setup(sysinfo_t *); /* optional */
439void mb_post_raminit_setup(void); /* optional */
440
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200441struct blc_pwm_t {
442 char ascii_string[13];
443 int pwm_freq; /* In Hz */
444};
445int get_blc_values(const struct blc_pwm_t **entries);
Arthur Heymans4d2d1712018-11-29 12:25:31 +0100446u16 get_blc_pwm_freq_value(const char *edid_ascii_string);
Arthur Heymans20cb85f2017-04-29 14:31:32 +0200447
448
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200449#include <device/device.h>
450
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200451struct acpi_rsdp;
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100452unsigned long northbridge_write_acpi_tables(struct device *device, unsigned long start, struct acpi_rsdp *rsdp);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100453
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200454#endif /* !__ACPI__ */
Edward O'Callaghan089a5102015-01-06 02:48:57 +1100455#endif /* __NORTHBRIDGE_INTEL_GM45_GM45_H__ */