Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 3 | * |
| 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 Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 9 | * |
| 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 Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 18 | #include <device/pci_ids.h> |
| 19 | #include <console/console.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 20 | #include <arch/acpi.h> |
| 21 | #include <arch/acpigen.h> |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 22 | #include <cpu/amd/powernow.h> |
Julius Werner | 7a8a4ab | 2015-05-22 16:26:40 -0700 | [diff] [blame] | 23 | #include <lib.h> |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 24 | #include "k8t890.h" |
| 25 | |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 26 | static void mmconfig_set_resources(device_t dev) |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 27 | { |
| 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 | |
| 47 | static 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 Diedrich | 8520e01 | 2010-11-17 11:30:50 +0000 | [diff] [blame] | 59 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 60 | 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 Diedrich | 8520e01 | 2010-11-17 11:30:50 +0000 | [diff] [blame] | 68 | res->flags = IORESOURCE_MEM | IORESOURCE_RESERVE; |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 71 | static void traf_ctrl_enable_generic(struct device *dev) |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 72 | { |
| 73 | volatile u32 *apic; |
| 74 | u32 data; |
| 75 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 76 | /* no device2 redirect, enable just one device behind |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 77 | * bridge device 2 and device 3). |
| 78 | */ |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 79 | pci_write_config8(dev, 0x60, 0x08); |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 80 | |
| 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 Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 107 | static void traf_ctrl_enable_k8m890(struct device *dev) |
| 108 | { |
| 109 | traf_ctrl_enable_generic(dev); |
| 110 | } |
| 111 | |
| 112 | static 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 Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 123 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 124 | |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 125 | static void southbridge_acpi_fill_ssdt_generator(device_t dev) { |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 126 | amd_generate_powernow(0, 0, 0); |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 127 | acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS"); |
| 128 | } |
| 129 | |
| 130 | #endif |
| 131 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 132 | static const struct device_operations traf_ctrl_ops_m = { |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 133 | .read_resources = apic_mmconfig_read_resources, |
| 134 | .set_resources = mmconfig_set_resources, |
| 135 | .enable_resources = pci_dev_enable_resources, |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 136 | .enable = traf_ctrl_enable_k8m890, |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 137 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 138 | .write_acpi_tables = acpi_write_hpet, |
| 139 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
| 140 | #endif |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 141 | .ops_pci = 0, |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 144 | static 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 Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 149 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 150 | .write_acpi_tables = acpi_write_hpet, |
| 151 | #endif |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 152 | .ops_pci = 0, |
| 153 | }; |
| 154 | |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 155 | /* K8X800 chipsets have no APIC; no 800 PCI ids here */ |
| 156 | |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 157 | unsigned 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 Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 178 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 179 | static const struct pci_driver northbridge_driver_t __pci_driver = { |
| 180 | .ops = &traf_ctrl_ops_t, |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 181 | .vendor = PCI_VENDOR_ID_VIA, |
| 182 | .device = PCI_DEVICE_ID_VIA_K8T890CE_5, |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 183 | }; |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 184 | |
Tobias Diedrich | d50b43a | 2010-11-02 20:54:37 +0000 | [diff] [blame] | 185 | static 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 Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 191 | static 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 | }; |