blob: b6b52a183ec33278efa93e1e29487d67a4aa17a5 [file] [log] [blame]
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00003 *
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00007 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000014 */
15
16#include <device/device.h>
17#include <device/pci.h>
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000018#include <device/pci_ids.h>
19#include <console/console.h>
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020020#include <arch/acpi.h>
21#include <arch/acpigen.h>
Vladimir Serbinenko47432542014-10-05 14:54:26 +020022#include <cpu/amd/powernow.h>
Julius Werner7a8a4ab2015-05-22 16:26:40 -070023#include <lib.h>
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000024#include "k8t890.h"
25
Uwe Hermann70ab3232007-11-15 15:52:42 +000026static void mmconfig_set_resources(device_t dev)
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000027{
28 struct resource *resource;
29 u8 reg;
30
31 resource = find_resource(dev, K8T890_MMCONFIG_MBAR);
32 if (resource) {
33 report_resource_stored(dev, resource, "<mmconfig>");
34
35 /* Remember this resource has been stored. */
36 resource->flags |= IORESOURCE_STORED;
37 pci_write_config8(dev, K8T890_MMCONFIG_MBAR,
38 (resource->base >> 28));
39 reg = pci_read_config8(dev, 0x60);
40 reg |= 0x3;
41 /* Enable MMCONFIG decoding. */
42 pci_write_config8(dev, 0x60, reg);
43 }
44 pci_dev_set_resources(dev);
45}
46
47static void apic_mmconfig_read_resources(device_t dev)
48{
49 struct resource *res;
50 pci_dev_read_resources(dev);
51
52 res = new_resource(dev, 0x40);
53 /* NB APIC fixed to this address. */
54 res->base = K8T890_APIC_BASE;
55 res->size = 256;
56 res->limit = res->base + res->size - 1;
57 res->align = 8;
58 res->gran = 8;
Tobias Diedrich8520e012010-11-17 11:30:50 +000059 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE |
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000060 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
61
62 /* Add an MMCONFIG resource. */
63 res = new_resource(dev, K8T890_MMCONFIG_MBAR);
64 res->size = 256 * 1024 * 1024;
65 res->align = log2(res->size);
66 res->gran = log2(res->size);
67 res->limit = 0xffffffff; /* 4G */
Tobias Diedrich8520e012010-11-17 11:30:50 +000068 res->flags = IORESOURCE_MEM | IORESOURCE_RESERVE;
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000069}
70
Rudolf Marek316e07f2008-03-20 21:19:50 +000071static void traf_ctrl_enable_generic(struct device *dev)
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000072{
73 volatile u32 *apic;
74 u32 data;
75
Rudolf Marek316e07f2008-03-20 21:19:50 +000076 /* no device2 redirect, enable just one device behind
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000077 * bridge device 2 and device 3).
78 */
Rudolf Marek316e07f2008-03-20 21:19:50 +000079 pci_write_config8(dev, 0x60, 0x08);
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000080
81 /* Will enable MMCONFIG later. */
82 pci_write_config8(dev, 0x64, 0x23);
83 /* No extended RCRB Base Address. */
84 pci_write_config8(dev, 0x62, 0x00);
85
86 /* Offset80 ->95 bit 4 in 1 in Award. */
87
88 /* Enable APIC, to K8T890_APIC_BASE. */
89 pci_write_config8(dev, 0x41, 0x00);
90 pci_write_config8(dev, 0x40, 0x8c);
91 /* BT_INTR enable, APIC Nonshare Mode Enable. */
92 pci_write_config8(dev, 0x42, 0x5);
93
94 apic = (u32 *)K8T890_APIC_BASE;
95
96 /* Set APIC to FSB transported messages. */
97 apic[0] = 3;
98 data = apic[4];
99 apic[4] = (data & 0xFFFFFE) | 1;
100
101 /* Set APIC ID. */
102 apic[0] = 0;
103 data = apic[4];
104 apic[4] = (data & 0xF0FFFF) | (K8T890_APIC_ID << 24);
105}
106
Rudolf Marek316e07f2008-03-20 21:19:50 +0000107static void traf_ctrl_enable_k8m890(struct device *dev)
108{
109 traf_ctrl_enable_generic(dev);
110}
111
112static void traf_ctrl_enable_k8t890(struct device *dev)
113{
114 u8 reg;
115
116 traf_ctrl_enable_generic(dev);
117
118 /* Enable D3F1-D3F3 */
119 reg = pci_read_config8(dev, 0x60);
120 pci_write_config8(dev, 0x60, 0x80 | reg);
121}
122
Vladimir Serbinenkof21271e2014-10-16 18:00:27 +0200123#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200124
Alexander Couzens5eea4582015-04-12 22:18:55 +0200125static void southbridge_acpi_fill_ssdt_generator(device_t dev) {
Vladimir Serbinenko47432542014-10-05 14:54:26 +0200126 amd_generate_powernow(0, 0, 0);
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200127 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
128}
129
130#endif
131
Rudolf Marek316e07f2008-03-20 21:19:50 +0000132static const struct device_operations traf_ctrl_ops_m = {
Uwe Hermann70ab3232007-11-15 15:52:42 +0000133 .read_resources = apic_mmconfig_read_resources,
134 .set_resources = mmconfig_set_resources,
135 .enable_resources = pci_dev_enable_resources,
Rudolf Marek316e07f2008-03-20 21:19:50 +0000136 .enable = traf_ctrl_enable_k8m890,
Vladimir Serbinenkof21271e2014-10-16 18:00:27 +0200137#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200138 .write_acpi_tables = acpi_write_hpet,
139 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
140#endif
Uwe Hermann70ab3232007-11-15 15:52:42 +0000141 .ops_pci = 0,
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +0000142};
143
Rudolf Marek316e07f2008-03-20 21:19:50 +0000144static const struct device_operations traf_ctrl_ops_t = {
145 .read_resources = apic_mmconfig_read_resources,
146 .set_resources = mmconfig_set_resources,
147 .enable_resources = pci_dev_enable_resources,
148 .enable = traf_ctrl_enable_k8t890,
Vladimir Serbinenkof21271e2014-10-16 18:00:27 +0200149#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200150 .write_acpi_tables = acpi_write_hpet,
151#endif
Rudolf Marek316e07f2008-03-20 21:19:50 +0000152 .ops_pci = 0,
153};
154
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000155/* K8X800 chipsets have no APIC; no 800 PCI ids here */
156
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200157unsigned long acpi_fill_mcfg(unsigned long current)
158{
159 device_t dev;
160 struct resource *res;
161
162 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CE_5, 0);
163 if (!dev)
164 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CF_5, 0);
165 if (!dev)
166 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_5, 0);
167 if (!dev)
168 return current;
169
170 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
171 if (res) {
172 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
173 current, res->base, 0x0, 0x0, 0xff);
174 }
175 return current;
176}
177
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000178
Rudolf Marek316e07f2008-03-20 21:19:50 +0000179static const struct pci_driver northbridge_driver_t __pci_driver = {
180 .ops = &traf_ctrl_ops_t,
Uwe Hermann70ab3232007-11-15 15:52:42 +0000181 .vendor = PCI_VENDOR_ID_VIA,
182 .device = PCI_DEVICE_ID_VIA_K8T890CE_5,
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +0000183};
Rudolf Marek316e07f2008-03-20 21:19:50 +0000184
Tobias Diedrichd50b43a2010-11-02 20:54:37 +0000185static const struct pci_driver northbridge_driver_tcf __pci_driver = {
186 .ops = &traf_ctrl_ops_t,
187 .vendor = PCI_VENDOR_ID_VIA,
188 .device = PCI_DEVICE_ID_VIA_K8T890CF_5,
189};
190
Rudolf Marek316e07f2008-03-20 21:19:50 +0000191static const struct pci_driver northbridge_driver_m __pci_driver = {
192 .ops = &traf_ctrl_ops_m,
193 .vendor = PCI_VENDOR_ID_VIA,
194 .device = PCI_DEVICE_ID_VIA_K8M890CE_5,
195};