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