blob: 0ff7917c7d78355491c0ee450e9456bb3e2382ed [file] [log] [blame]
Marc Jones734daf62007-05-04 18:58:42 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Jordan Crouseb29209f2007-05-10 17:57:03 +00003 *
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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.
Jordan Crouseb29209f2007-05-10 17:57:03 +000015 */
Marc Jones734daf62007-05-04 18:58:42 +000016
Ron Minnich5e9dc232006-07-28 16:06:16 +000017#include <console/console.h>
18#include <arch/io.h>
19#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <stdlib.h>
24#include <string.h>
Indrek Kruusa8e346412006-08-03 16:48:18 +000025#include <cpu/cpu.h>
Ron Minnich5e9dc232006-07-28 16:06:16 +000026#include <cpu/amd/lxdef.h>
27#include <cpu/x86/msr.h>
28#include <cpu/x86/cache.h>
29#include <cpu/amd/vr.h>
Corey Osgoode562f722008-12-19 03:36:48 +000030#include <cpu/cpu.h>
Marc Jones734daf62007-05-04 18:58:42 +000031#include "northbridge.h"
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +000032#include "../../../southbridge/amd/cs5536/cs5536.h"
33
Ron Minnich5e9dc232006-07-28 16:06:16 +000034
Ron Minnich5e9dc232006-07-28 16:06:16 +000035/* here is programming for the various MSRs.*/
36#define IM_QWAIT 0x100000
37
Jordan Crousef8030bd2007-05-10 18:16:03 +000038#define DMCF_WRITE_SERIALIZE_REQUEST (2<<12) /* 2 outstanding */ /* in high */
39#define DMCF_SERIAL_LOAD_MISSES (2) /* enabled */
Ron Minnich5e9dc232006-07-28 16:06:16 +000040
41/* these are the 8-bit attributes for controlling RCONF registers */
42#define CACHE_DISABLE (1<<0)
43#define WRITE_ALLOCATE (1<<1)
44#define WRITE_PROTECT (1<<2)
45#define WRITE_THROUGH (1<<3)
46#define WRITE_COMBINE (1<<4)
47#define WRITE_SERIALIZE (1<<5)
48
49/* ram has none of this stuff */
50#define RAM_PROPERTIES (0)
51#define DEVICE_PROPERTIES (WRITE_SERIALIZE|CACHE_DISABLE)
52#define ROM_PROPERTIES (WRITE_SERIALIZE|WRITE_PROTECT|CACHE_DISABLE)
53#define MSR_WS_CD_DEFAULT (0x21212121)
54
55/* 1810-1817 give you 8 registers with which to program protection regions */
56/* the are region configuration range registers, or RRCF */
57/* in msr terms, the are a straight base, top address assign, since they are 4k aligned. */
58/* so no left-shift needed for top or base */
59#define RRCF_LOW(base,properties) (base|(1<<8)|properties)
60#define RRCF_LOW_CD(base) RRCF_LOW(base, CACHE_DISABLE)
61
62/* build initializer for P2D MSR */
63#define P2D_BM(msr, pdid1, bizarro, pbase, pmask) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(pbase>>24), .lo=(pbase<<8)|pmask}}
64#define P2D_BMO(msr, pdid1, bizarro, poffset, pbase, pmask) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(poffset<<8)|(pbase>>24), .lo=(pbase<<8)|pmask}}
65#define P2D_R(msr, pdid1, bizarro, pmax, pmin) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(pmax>>12), .lo=(pmax<<20)|pmin}}
66#define P2D_RO(msr, pdid1, bizarro, poffset, pmax, pmin) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(poffset<<8)|(pmax>>12), .lo=(pmax<<20)|pmin}}
67#define P2D_SC(msr, pdid1, bizarro, wen, ren,pscbase) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(wen), .lo=(ren<<16)|(pscbase>>18)}}
68#define IOD_BM(msr, pdid1, bizarro, ibase, imask) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(ibase>>12), .lo=(ibase<<20)|imask}}
69#define IOD_SC(msr, pdid1, bizarro, en, wen, ren, ibase) {msr, {.hi=(pdid1<<29)|(bizarro<<28), .lo=(en<<24)|(wen<<21)|(ren<<20)|(ibase<<3)}}
70
Stefan Reinauer9839cbd2010-04-21 20:06:10 +000071void print_conf(void);
72void graphics_init(void);
Indrek Kruusa7d944122006-09-13 21:59:09 +000073void do_vsmbios(void);
Ron Minnich5e9dc232006-07-28 16:06:16 +000074
75struct msr_defaults {
76 int msr_no;
77 msr_t msr;
Jordan Crousef8030bd2007-05-10 18:16:03 +000078} msr_defaults[] = {
79 {
80 0x1700, {
81 .hi = 0,.lo = IM_QWAIT}}, {
82 0x1800, {
83 .hi = DMCF_WRITE_SERIALIZE_REQUEST,.lo =
84 DMCF_SERIAL_LOAD_MISSES}},
85 /* 1808 will be done down below, so we have to do 180a->1817 (well, 1813 really) */
86 /* for 180a, for now, we assume VSM will configure it */
87 /* 180b is left at reset value,a0000-bffff is non-cacheable */
88 /* 180c, c0000-dffff is set to write serialize and non-cachable */
89 /* oops, 180c will be set by cpu bug handling in cpubug.c */
90 //{0x180c, {.hi = MSR_WS_CD_DEFAULT, .lo = MSR_WS_CD_DEFAULT}},
91 /* 180d is left at default, e0000-fffff is non-cached */
92 /* we will assume 180e, the ssm region configuration, is left at default or set by VSM */
93 /* we will not set 0x180f, the DMM,yet */
94 //{0x1810, {.hi=0xee7ff000, .lo=RRCF_LOW(0xee000000, WRITE_COMBINE|CACHE_DISABLE)}},
95 //{0x1811, {.hi = 0xefffb000, .lo = RRCF_LOW_CD(0xefff8000)}},
96 //{0x1812, {.hi = 0xefff7000, .lo = RRCF_LOW_CD(0xefff4000)}},
97 //{0x1813, {.hi = 0xefff3000, .lo = RRCF_LOW_CD(0xefff0000)}},
98 /* now for GLPCI routing */
99 /* GLIU0 */
100 P2D_BM(MSR_GLIU0_BASE1, 0x1, 0x0, 0x0, 0xfff80),
101 P2D_BM(MSR_GLIU0_BASE2, 0x1, 0x0, 0x80000, 0xfffe0),
102 P2D_SC(MSR_GLIU0_SHADOW, 0x1, 0x0, 0x0, 0xff03, 0xC0000),
103 /* GLIU1 */
104 P2D_BM(MSR_GLIU1_BASE1, 0x1, 0x0, 0x0, 0xfff80),
105 P2D_BM(MSR_GLIU1_BASE2, 0x1, 0x0, 0x80000, 0xfffe0),
106 P2D_SC(MSR_GLIU1_SHADOW, 0x1, 0x0, 0x0, 0xff03, 0xC0000), {
107 0}
Ron Minnich5e9dc232006-07-28 16:06:16 +0000108};
109
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000110/* Print the platform configuration - do before PCI init or it will not
111 * work right.
112 */
113void print_conf(void)
114{
Stefan Reinauer08670622009-06-30 15:17:49 +0000115#if CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_ERR
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000116 int i;
117 unsigned long iol;
118 msr_t msr;
119
120 int cpu_msr_defs[] = { CPU_BC_L2_CONF, CPU_IM_CONFIG, CPU_DM_CONFIG0,
121 CPU_RCONF_DEFAULT, CPU_RCONF_BYPASS, CPU_RCONF_A0_BF,
122 CPU_RCONF_C0_DF, CPU_RCONF_E0_FF, CPU_RCONF_SMM, CPU_RCONF_DMM,
123 GLCP_DELAY_CONTROLS, GL_END
124 };
125
126 int gliu0_msr_defs[] = { MSR_GLIU0_BASE1, MSR_GLIU0_BASE2,
127 MSR_GLIU0_BASE4, MSR_GLIU0_BASE5, MSR_GLIU0_BASE6,
128 GLIU0_P2D_BMO_0, GLIU0_P2D_BMO_1, MSR_GLIU0_SYSMEM,
129 GLIU0_P2D_RO_0, GLIU0_P2D_RO_1, GLIU0_P2D_RO_2,
130 MSR_GLIU0_SHADOW, GLIU0_IOD_BM_0, GLIU0_IOD_BM_1,
131 GLIU0_IOD_BM_2, GLIU0_IOD_SC_0, GLIU0_IOD_SC_1, GLIU0_IOD_SC_2,
132 GLIU0_IOD_SC_3, GLIU0_IOD_SC_4, GLIU0_IOD_SC_5,
133 GLIU0_GLD_MSR_COH, GL_END
134 };
135
136 int gliu1_msr_defs[] = { MSR_GLIU1_BASE1, MSR_GLIU1_BASE2,
137 MSR_GLIU1_BASE3, MSR_GLIU1_BASE4, MSR_GLIU1_BASE5,
138 MSR_GLIU1_BASE6, MSR_GLIU1_BASE7, MSR_GLIU1_BASE8,
139 MSR_GLIU1_BASE9, MSR_GLIU1_BASE10, GLIU1_P2D_R_0,
140 GLIU1_P2D_R_1, GLIU1_P2D_R_2, GLIU1_P2D_R_3, MSR_GLIU1_SHADOW,
141 GLIU1_IOD_BM_0, GLIU1_IOD_BM_1, GLIU1_IOD_BM_2, GLIU1_IOD_SC_0,
142 GLIU1_IOD_SC_1, GLIU1_IOD_SC_2, GLIU1_IOD_SC_3,
143 GLIU1_GLD_MSR_COH, GL_END
144 };
145
146 int rconf_msr[] = { CPU_RCONF0, CPU_RCONF1, CPU_RCONF2, CPU_RCONF3,
147 CPU_RCONF4, CPU_RCONF5, CPU_RCONF6, CPU_RCONF7, GL_END
148 };
149
150 int cs5536_msr[] = { MDD_LBAR_GPIO, MDD_LBAR_FLSH0, MDD_LBAR_FLSH1,
151 MDD_LEG_IO, MDD_PIN_OPT, MDD_IRQM_ZLOW, MDD_IRQM_ZHIGH,
152 MDD_IRQM_PRIM, GL_END
153 };
154
155 int pci_msr[] = { GLPCI_CTRL, GLPCI_ARB, GLPCI_REN, GLPCI_A0_BF,
156 GLPCI_C0_DF, GLPCI_E0_FF, GLPCI_RC0, GLPCI_RC1, GLPCI_RC2,
157 GLPCI_RC3, GLPCI_ExtMSR, GLPCI_SPARE, GL_END
158 };
159
160 int dma_msr[] = { MDD_DMA_MAP, MDD_DMA_SHAD1, MDD_DMA_SHAD2,
161 MDD_DMA_SHAD3, MDD_DMA_SHAD4, MDD_DMA_SHAD5, MDD_DMA_SHAD6,
162 MDD_DMA_SHAD7, MDD_DMA_SHAD8, MDD_DMA_SHAD9, GL_END
163 };
164
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000165 printk(BIOS_DEBUG, "---------- CPU ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000166
167 for (i = 0; cpu_msr_defs[i] != GL_END; i++) {
168 msr = rdmsr(cpu_msr_defs[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000169 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000170 cpu_msr_defs[i], msr.hi, msr.lo);
171 }
172
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000173 printk(BIOS_DEBUG, "---------- GLIU 0 ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000174
175 for (i = 0; gliu0_msr_defs[i] != GL_END; i++) {
176 msr = rdmsr(gliu0_msr_defs[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000177 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000178 gliu0_msr_defs[i], msr.hi, msr.lo);
179 }
180
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000181 printk(BIOS_DEBUG, "---------- GLIU 1 ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000182
183 for (i = 0; gliu1_msr_defs[i] != GL_END; i++) {
184 msr = rdmsr(gliu1_msr_defs[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000185 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000186 gliu1_msr_defs[i], msr.hi, msr.lo);
187 }
188
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000189 printk(BIOS_DEBUG, "---------- RCONF ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000190
191 for (i = 0; rconf_msr[i] != GL_END; i++) {
192 msr = rdmsr(rconf_msr[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000193 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", rconf_msr[i],
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000194 msr.hi, msr.lo);
195 }
196
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000197 printk(BIOS_DEBUG, "---------- VARIA ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000198 msr = rdmsr(0x51300010);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000199 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", 0x51300010, msr.hi,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000200 msr.lo);
201
202 msr = rdmsr(0x51400015);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000203 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", 0x51400015, msr.hi,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000204 msr.lo);
205
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000206 printk(BIOS_DEBUG, "---------- DIVIL IRQ ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000207 msr = rdmsr(MDD_IRQM_YLOW);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000208 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MDD_IRQM_YLOW, msr.hi,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000209 msr.lo);
210 msr = rdmsr(MDD_IRQM_YHIGH);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000211 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MDD_IRQM_YHIGH,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000212 msr.hi, msr.lo);
213 msr = rdmsr(MDD_IRQM_ZLOW);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000214 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MDD_IRQM_ZLOW, msr.hi,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000215 msr.lo);
216 msr = rdmsr(MDD_IRQM_ZHIGH);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000217 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MDD_IRQM_ZHIGH,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000218 msr.hi, msr.lo);
219
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000220 printk(BIOS_DEBUG, "---------- PCI ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000221
222 for (i = 0; pci_msr[i] != GL_END; i++) {
223 msr = rdmsr(pci_msr[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000224 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", pci_msr[i],
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000225 msr.hi, msr.lo);
226 }
227
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000228 printk(BIOS_DEBUG, "---------- LPC/UART DMA ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000229
230 for (i = 0; dma_msr[i] != GL_END; i++) {
231 msr = rdmsr(dma_msr[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000232 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", dma_msr[i],
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000233 msr.hi, msr.lo);
234 }
235
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000236 printk(BIOS_DEBUG, "---------- CS5536 ------------\n");
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000237
238 for (i = 0; cs5536_msr[i] != GL_END; i++) {
239 msr = rdmsr(cs5536_msr[i]);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000240 printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", cs5536_msr[i],
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000241 msr.hi, msr.lo);
242 }
243
244 iol = inl(GPIO_IO_BASE + GPIOL_INPUT_ENABLE);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000245 printk(BIOS_DEBUG, "IOR 0x%08X is now 0x%08lX\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000246 GPIO_IO_BASE + GPIOL_INPUT_ENABLE, iol);
247 iol = inl(GPIOL_EVENTS_ENABLE);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000248 printk(BIOS_DEBUG, "IOR 0x%08X is now 0x%08lX\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000249 GPIO_IO_BASE + GPIOL_EVENTS_ENABLE, iol);
250 iol = inl(GPIOL_INPUT_INVERT_ENABLE);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000251 printk(BIOS_DEBUG, "IOR 0x%08X is now 0x%08lX\n",
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000252 GPIO_IO_BASE + GPIOL_INPUT_INVERT_ENABLE, iol);
253 iol = inl(GPIO_MAPPER_X);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000254 printk(BIOS_DEBUG, "IOR 0x%08X is now 0x%08lX\n", GPIO_IO_BASE + GPIO_MAPPER_X,
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000255 iol);
Stefan Reinauer08670622009-06-30 15:17:49 +0000256#endif //CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_ERR
Carl-Daniel Hailfingercb5c9fb2008-02-05 09:21:46 +0000257}
258
Stefan Reinauer14e22772010-04-27 06:56:47 +0000259/* todo: add a resource record. We don't do this here because this may be called when
Indrek Kruusa7d944122006-09-13 21:59:09 +0000260 * very little of the platform is actually working.
261 */
Marc Jones734daf62007-05-04 18:58:42 +0000262int sizeram(void)
Indrek Kruusa7d944122006-09-13 21:59:09 +0000263{
264 msr_t msr;
265 int sizem = 0;
266 unsigned short dimm;
267
Marc Jonesddf845f2007-05-10 23:22:27 +0000268 /* Get the RAM size from the memory controller as calculated and set by auto_size_dimm() */
Marc Jones734daf62007-05-04 18:58:42 +0000269 msr = rdmsr(MC_CF07_DATA);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000270 printk(BIOS_DEBUG, "sizeram: _MSR MC_CF07_DATA: %08x:%08x\n", msr.hi, msr.lo);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000271
272 /* dimm 0 */
273 dimm = msr.hi;
Marc Jones734daf62007-05-04 18:58:42 +0000274 /* installed? */
Jordan Crousef8030bd2007-05-10 18:16:03 +0000275 if ((dimm & 7) != 7) {
Marc Jonesddf845f2007-05-10 23:22:27 +0000276 sizem = 4 << ((dimm >> 12) & 0x0F); /* 1:8MB, 2:16MB, 3:32MB, 4:64MB, ... 7:512MB, 8:1GB */
Marc Jones734daf62007-05-04 18:58:42 +0000277 }
Indrek Kruusa7d944122006-09-13 21:59:09 +0000278
Jordan Crousef8030bd2007-05-10 18:16:03 +0000279 /* dimm 1 */
Indrek Kruusa7d944122006-09-13 21:59:09 +0000280 dimm = msr.hi >> 16;
281 /* installed? */
Jordan Crousef8030bd2007-05-10 18:16:03 +0000282 if ((dimm & 7) != 7) {
Marc Jonesddf845f2007-05-10 23:22:27 +0000283 sizem += 4 << ((dimm >> 12) & 0x0F); /* 1:8MB, 2:16MB, 3:32MB, 4:64MB, ... 7:512MB, 8:1GB */
Marc Jones734daf62007-05-04 18:58:42 +0000284 }
Indrek Kruusa7d944122006-09-13 21:59:09 +0000285
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000286 printk(BIOS_DEBUG, "sizeram: sizem 0x%xMB\n", sizem);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000287 return sizem;
288}
289
Ron Minnich5e9dc232006-07-28 16:06:16 +0000290static void enable_shadow(device_t dev)
291{
Ron Minnich5e9dc232006-07-28 16:06:16 +0000292}
293
Jordan Crousef8030bd2007-05-10 18:16:03 +0000294static void northbridge_init(device_t dev)
Ron Minnich5e9dc232006-07-28 16:06:16 +0000295{
Indrek Kruusa7d944122006-09-13 21:59:09 +0000296 //msr_t msr;
Indrek Kruusa7d944122006-09-13 21:59:09 +0000297
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000298 printk(BIOS_SPEW, ">> Entering northbridge.c: %s\n", __func__);
Jordan Crousef8030bd2007-05-10 18:16:03 +0000299
Ron Minnich5e9dc232006-07-28 16:06:16 +0000300 enable_shadow(dev);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000301 /*
302 * Swiss cheese
303 */
304 //msr = rdmsr(MSR_GLIU0_SHADOW);
Jordan Crousef8030bd2007-05-10 18:16:03 +0000305
Indrek Kruusa7d944122006-09-13 21:59:09 +0000306 //msr.hi |= 0x3;
307 //msr.lo |= 0x30000;
Indrek Kruusa7d944122006-09-13 21:59:09 +0000308
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000309 //printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MSR_GLIU0_SHADOW, msr.hi, msr.lo);
310 //printk(BIOS_DEBUG, "MSR 0x%08X is now 0x%08X:0x%08X\n", MSR_GLIU1_SHADOW, msr.hi, msr.lo);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000311}
312
Stefan Reinauer9839cbd2010-04-21 20:06:10 +0000313static void northbridge_set_resources(struct device *dev)
Indrek Kruusa7d944122006-09-13 21:59:09 +0000314{
Indrek Kruusa7d944122006-09-13 21:59:09 +0000315 uint8_t line;
316
Myles Watsonc25cc112010-05-21 14:33:48 +0000317#if 0
318 struct resource *res;
319 for (res = dev->resource_list; res; res = res->next) {
Indrek Kruusa7d944122006-09-13 21:59:09 +0000320
321 // andrei: do not change the base address, it will make the VSA virtual registers unusable
Myles Watsonc25cc112010-05-21 14:33:48 +0000322 //pci_set_resource(dev, res);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000323 // FIXME: static allocation may conflict with dynamic mappings!
324 }
Myles Watsonc25cc112010-05-21 14:33:48 +0000325#endif
Indrek Kruusa7d944122006-09-13 21:59:09 +0000326
Myles Watson894a3472010-06-09 22:41:35 +0000327 struct bus *bus;
328 for (bus = dev->link_list; bus; bus = bus->next) {
Indrek Kruusa7d944122006-09-13 21:59:09 +0000329 if (bus->children) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000330 printk(BIOS_DEBUG, "my_dev_set_resources: assign_resources %d\n",
Myles Watson08e0fb82010-03-22 16:33:25 +0000331 bus->secondary);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000332 assign_resources(bus);
333 }
334 }
335
336 /* set a default latency timer */
337 pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40);
338
339 /* set a default secondary latency timer */
340 if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) {
341 pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40);
342 }
343
344 /* zero the irq settings */
345 line = pci_read_config8(dev, PCI_INTERRUPT_PIN);
346 if (line) {
347 pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
348 }
Jordan Crousef8030bd2007-05-10 18:16:03 +0000349
Indrek Kruusa7d944122006-09-13 21:59:09 +0000350 /* set the cache line size, so far 64 bytes is good for everyone */
351 pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2);
Ron Minnich5e9dc232006-07-28 16:06:16 +0000352}
353
354static struct device_operations northbridge_operations = {
Jordan Crousef8030bd2007-05-10 18:16:03 +0000355 .read_resources = pci_dev_read_resources,
356 .set_resources = northbridge_set_resources,
Ron Minnich5e9dc232006-07-28 16:06:16 +0000357 .enable_resources = pci_dev_enable_resources,
Jordan Crousef8030bd2007-05-10 18:16:03 +0000358 .init = northbridge_init,
359 .enable = 0,
360 .ops_pci = 0,
Ron Minnich5e9dc232006-07-28 16:06:16 +0000361};
362
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +0000363static const struct pci_driver northbridge_driver __pci_driver = {
Ron Minnich5e9dc232006-07-28 16:06:16 +0000364 .ops = &northbridge_operations,
365 .vendor = PCI_VENDOR_ID_AMD,
Indrek Kruusa7d944122006-09-13 21:59:09 +0000366 .device = PCI_DEVICE_ID_AMD_LXBRIDGE,
Ron Minnich5e9dc232006-07-28 16:06:16 +0000367};
368
Rudolf Marek97be27e2010-12-13 19:50:25 +0000369#include <cbmem.h>
Stefan Reinauerb5fb0c52009-04-30 13:58:42 +0000370
Ron Minnich5e9dc232006-07-28 16:06:16 +0000371static void pci_domain_set_resources(device_t dev)
372{
Indrek Kruusa7d944122006-09-13 21:59:09 +0000373 int idx;
Stefan Reinauerb5fb0c52009-04-30 13:58:42 +0000374 u32 tomk;
Ron Minnich5e9dc232006-07-28 16:06:16 +0000375 device_t mc_dev;
Ron Minnich5e9dc232006-07-28 16:06:16 +0000376
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000377 printk(BIOS_SPEW, ">> Entering northbridge.c: %s\n", __func__);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000378
Myles Watson894a3472010-06-09 22:41:35 +0000379 mc_dev = dev->link_list->children;
Jordan Crousef8030bd2007-05-10 18:16:03 +0000380 if (mc_dev) {
Christian Gmeinere2dc80c2013-06-04 16:23:43 +0200381 tomk = get_top_of_ram() / 1024;
Edwin Beasant87d0c542010-01-27 18:19:33 +0000382 /* Report the memory regions
383 All memory up to systop except 0xa0000-0xbffff */
Ron Minnich5e9dc232006-07-28 16:06:16 +0000384 idx = 10;
Indrek Kruusa7d944122006-09-13 21:59:09 +0000385 ram_resource(dev, idx++, 0, 640);
Edwin Beasant87d0c542010-01-27 18:19:33 +0000386 ram_resource(dev, idx++, 768, tomk - 768); // Systop - 0xc0000 -> KB
Stefan Reinauerb5fb0c52009-04-30 13:58:42 +0000387
Kyösti Mälkki42f46512013-06-27 08:20:09 +0300388 set_top_of_ram(tomk * 1024);
Ron Minnich5e9dc232006-07-28 16:06:16 +0000389 }
Indrek Kruusa7d944122006-09-13 21:59:09 +0000390
Myles Watson894a3472010-06-09 22:41:35 +0000391 assign_resources(dev->link_list);
Ron Minnich5e9dc232006-07-28 16:06:16 +0000392}
393
Indrek Kruusa7d944122006-09-13 21:59:09 +0000394static void pci_domain_enable(device_t dev)
395{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000396 printk(BIOS_SPEW, ">> Entering northbridge.c: %s\n", __func__);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000397
398 // do this here for now -- this chip really breaks our device model
Indrek Kruusa7d944122006-09-13 21:59:09 +0000399 northbridge_init_early();
400 cpubug();
Marc Jones734daf62007-05-04 18:58:42 +0000401 chipsetinit();
402
Marc Jones734daf62007-05-04 18:58:42 +0000403 // print_conf();
Indrek Kruusa7d944122006-09-13 21:59:09 +0000404
Jordan Crousef8030bd2007-05-10 18:16:03 +0000405 do_vsmbios(); // do the magic stuff here, so prepare your tambourine ;)
406
Marc Jones734daf62007-05-04 18:58:42 +0000407 // print_conf();
Indrek Kruusa7d944122006-09-13 21:59:09 +0000408
409 graphics_init();
Indrek Kruusa7d944122006-09-13 21:59:09 +0000410}
411
Ron Minnich5e9dc232006-07-28 16:06:16 +0000412static struct device_operations pci_domain_ops = {
Jordan Crousef8030bd2007-05-10 18:16:03 +0000413 .read_resources = pci_domain_read_resources,
414 .set_resources = pci_domain_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000415 .enable_resources = NULL,
Jordan Crousef8030bd2007-05-10 18:16:03 +0000416 .scan_bus = pci_domain_scan_bus,
417 .enable = pci_domain_enable,
Kyösti Mälkki33e5df32013-07-03 10:51:34 +0300418 .ops_pci_bus = pci_bus_default_ops,
Jordan Crousef8030bd2007-05-10 18:16:03 +0000419};
Ron Minnich5e9dc232006-07-28 16:06:16 +0000420
421static void cpu_bus_init(device_t dev)
422{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000423 printk(BIOS_SPEW, ">> Entering northbridge.c: %s\n", __func__);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000424
Myles Watson894a3472010-06-09 22:41:35 +0000425 initialize_cpus(dev->link_list);
Ron Minnich5e9dc232006-07-28 16:06:16 +0000426}
427
Ron Minnich5e9dc232006-07-28 16:06:16 +0000428static struct device_operations cpu_bus_ops = {
Edward O'Callaghan812d2a42014-10-31 08:17:23 +1100429 .read_resources = DEVICE_NOOP,
430 .set_resources = DEVICE_NOOP,
431 .enable_resources = DEVICE_NOOP,
Jordan Crousef8030bd2007-05-10 18:16:03 +0000432 .init = cpu_bus_init,
433 .scan_bus = 0,
Ron Minnich5e9dc232006-07-28 16:06:16 +0000434};
435
Ron Minnich5e9dc232006-07-28 16:06:16 +0000436static void enable_dev(struct device *dev)
437{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000438 printk(BIOS_SPEW, ">> Entering northbridge.c: %s with path %d\n",
Myles Watson552b3272009-02-12 21:30:06 +0000439 __func__, dev->path.type);
Indrek Kruusa7d944122006-09-13 21:59:09 +0000440
Jordan Crousef8030bd2007-05-10 18:16:03 +0000441 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800442 if (dev->path.type == DEVICE_PATH_DOMAIN)
Ron Minnich5e9dc232006-07-28 16:06:16 +0000443 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800444 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Jordan Crousef8030bd2007-05-10 18:16:03 +0000445 dev->ops = &cpu_bus_ops;
Ron Minnich5e9dc232006-07-28 16:06:16 +0000446}
447
448struct chip_operations northbridge_amd_lx_ops = {
449 CHIP_NAME("AMD LX Northbridge")
Jordan Crousef8030bd2007-05-10 18:16:03 +0000450 .enable_dev = enable_dev,
Ron Minnich5e9dc232006-07-28 16:06:16 +0000451};