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