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