Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 5 | * Copyright (C) 2014 Sage Electronic Engineering, LLC. |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <device/device.h> /* device_t */ |
| 23 | #include <device/pci.h> /* device_operations */ |
| 24 | #include <device/pci_ids.h> |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 25 | #include <bootstate.h> |
Kerry She | 991f880 | 2011-06-01 01:56:49 +0000 | [diff] [blame] | 26 | #include <arch/ioapic.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 27 | #include <device/smbus.h> /* smbus_bus_operations */ |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 28 | #include <pc80/mc146818rtc.h> |
Edward O'Callaghan | e61dd0f | 2014-05-06 23:53:09 +1000 | [diff] [blame] | 29 | #include <pc80/i8254.h> |
| 30 | #include <pc80/i8259.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 31 | #include <console/console.h> /* printk */ |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 32 | #include <arch/acpi.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 33 | #include <device/pci_ehci.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 34 | #include "lpc.h" /* lpc_read_resources */ |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame] | 35 | #include "SBPLATFORM.h" /* Platform Specific Definitions */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 36 | #include "cfg.h" /* sb800 Cimx configuration */ |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 37 | #include "chip.h" /* struct southbridge_amd_cimx_sb800_config */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 38 | #include "sb_cimx.h" /* AMD CIMX wrapper entries */ |
Dave Frodin | 23023a5 | 2012-11-13 07:09:12 -0700 | [diff] [blame] | 39 | #include "smbus.h" |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 40 | #include "fan.h" |
Stefan Reinauer | 13e4182 | 2015-04-27 14:02:36 -0700 | [diff] [blame] | 41 | #include <southbridge/amd/common/amd_pci_util.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 42 | |
| 43 | /*implement in mainboard.c*/ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 44 | void set_pcie_reset(void); |
| 45 | void set_pcie_dereset(void); |
| 46 | |
| 47 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 48 | static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config |
| 49 | static AMDSBCFG *sb_config = &sb_late_cfg; |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * @brief Entry point of Southbridge CIMx callout |
| 54 | * |
| 55 | * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig) |
| 56 | * |
| 57 | * @param[in] func Southbridge CIMx Function ID. |
| 58 | * @param[in] data Southbridge Input Data. |
Martin Roth | 6355cbf | 2015-01-04 15:22:26 -0700 | [diff] [blame] | 59 | * @param[in] config Southbridge configuration structure pointer. |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 60 | * |
| 61 | */ |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 62 | static u32 sb800_callout_entry(u32 func, u32 data, void* config) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 63 | { |
| 64 | u32 ret = 0; |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 65 | printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 66 | switch (func) { |
| 67 | case CB_SBGPP_RESET_ASSERT: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 68 | set_pcie_reset(); |
| 69 | break; |
| 70 | |
| 71 | case CB_SBGPP_RESET_DEASSERT: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 72 | set_pcie_dereset(); |
| 73 | break; |
| 74 | |
| 75 | case IMC_FIRMWARE_FAIL: |
| 76 | break; |
| 77 | |
| 78 | default: |
| 79 | break; |
| 80 | } |
| 81 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 83 | return ret; |
| 84 | } |
| 85 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 86 | #define HOST_CAP 0x00 /* host capabilities */ |
| 87 | #define HOST_CTL 0x04 /* global host control */ |
| 88 | #define HOST_IRQ_STAT 0x08 /* interrupt status */ |
| 89 | #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */ |
| 90 | |
| 91 | #define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */ |
| 92 | static void ahci_raid_init(struct device *dev) |
| 93 | { |
| 94 | u8 irq = 0; |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 95 | void *bar5; |
| 96 | u32 caps, ports, val; |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 97 | |
| 98 | val = pci_read_config16(dev, PCI_CLASS_DEVICE); |
| 99 | if (val == PCI_CLASS_STORAGE_SATA) { |
| 100 | printk(BIOS_DEBUG, "AHCI controller "); |
| 101 | } else if (val == PCI_CLASS_STORAGE_RAID) { |
| 102 | printk(BIOS_DEBUG, "RAID controller "); |
| 103 | } else { |
| 104 | printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | irq = pci_read_config8(dev, PCI_INTERRUPT_LINE); |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 109 | bar5 = (void *)(uintptr_t)pci_read_config32(dev, PCI_BASE_ADDRESS_5); |
| 110 | printk(BIOS_DEBUG, "IOMEM base: %p, IRQ: 0x%X\n", bar5, irq); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 111 | |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 112 | caps = read32(bar5 + HOST_CAP); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 113 | caps = (caps & 0x1F) + 1; |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 114 | ports= read32(bar5 + HOST_PORTS_IMPL); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 115 | printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports); |
| 116 | |
| 117 | /* make sure ahci is enabled */ |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 118 | val = read32(bar5 + HOST_CTL); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 119 | if (!(val & HOST_CTL_AHCI_EN)) { |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame^] | 120 | write32(bar5 + HOST_CTL, val | HOST_CTL_AHCI_EN); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | dev->command |= PCI_COMMAND_MASTER; |
| 124 | pci_write_config8(dev, PCI_COMMAND, dev->command); |
| 125 | printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n"); |
| 126 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 127 | |
| 128 | static struct pci_operations lops_pci = { |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 129 | .set_subsystem = pci_dev_set_subsystem, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 132 | static void lpc_init(device_t dev) |
| 133 | { |
| 134 | printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - Start.\n"); |
| 135 | |
Gabe Black | 03abaee21 | 2014-04-30 21:31:44 -0700 | [diff] [blame] | 136 | cmos_check_update_date(); |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 137 | |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 138 | /* Initialize the real time clock. |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 139 | * The 0 argument tells cmos_init not to |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 140 | * update CMOS unless it is invalid. |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 141 | * 1 tells cmos_init to always initialize the CMOS. |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 142 | */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 143 | cmos_init(0); |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 144 | |
Edward O'Callaghan | e61dd0f | 2014-05-06 23:53:09 +1000 | [diff] [blame] | 145 | setup_i8259(); /* Initialize i8259 pic */ |
| 146 | setup_i8254(); /* Initialize i8254 timers */ |
| 147 | |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 148 | printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - End.\n"); |
| 149 | } |
| 150 | |
Vladimir Serbinenko | 2a19fb1 | 2014-10-02 20:09:19 +0200 | [diff] [blame] | 151 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 152 | { |
| 153 | /* Just a dummy */ |
| 154 | return current; |
| 155 | } |
| 156 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 157 | static struct device_operations lpc_ops = { |
| 158 | .read_resources = lpc_read_resources, |
| 159 | .set_resources = lpc_set_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 160 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | 83f81ca | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 161 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 2a19fb1 | 2014-10-02 20:09:19 +0200 | [diff] [blame] | 162 | .write_acpi_tables = acpi_write_hpet, |
| 163 | #endif |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 164 | .init = lpc_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 165 | .scan_bus = scan_lpc_bus, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 166 | .ops_pci = &lops_pci, |
| 167 | }; |
| 168 | |
| 169 | static const struct pci_driver lpc_driver __pci_driver = { |
| 170 | .ops = &lpc_ops, |
| 171 | .vendor = PCI_VENDOR_ID_ATI, |
| 172 | .device = PCI_DEVICE_ID_ATI_SB800_LPC, |
| 173 | }; |
| 174 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 175 | static struct device_operations sata_ops = { |
| 176 | .read_resources = pci_dev_read_resources, |
| 177 | .set_resources = pci_dev_set_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 178 | .enable_resources = pci_dev_enable_resources, |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 179 | .init = ahci_raid_init, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 180 | .scan_bus = 0, |
| 181 | .ops_pci = &lops_pci, |
| 182 | }; |
| 183 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 184 | static const struct pci_driver ahci_driver __pci_driver = { |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 185 | .ops = &sata_ops, |
| 186 | .vendor = PCI_VENDOR_ID_ATI, |
Scott Duplichan | f191c72 | 2011-05-15 21:38:08 +0000 | [diff] [blame] | 187 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 190 | static const struct pci_driver raid_driver __pci_driver = { |
| 191 | .ops = &sata_ops, |
| 192 | .vendor = PCI_VENDOR_ID_ATI, |
| 193 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID, |
| 194 | }; |
| 195 | static const struct pci_driver raid5_driver __pci_driver = { |
| 196 | .ops = &sata_ops, |
| 197 | .vendor = PCI_VENDOR_ID_ATI, |
| 198 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5, |
| 199 | }; |
| 200 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 201 | static struct device_operations usb_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 202 | .read_resources = pci_ehci_read_resources, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 203 | .set_resources = pci_dev_set_resources, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 204 | .enable_resources = pci_dev_enable_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 205 | .init = 0, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 206 | .scan_bus = 0, |
| 207 | .ops_pci = &lops_pci, |
| 208 | }; |
| 209 | |
| 210 | /* |
| 211 | * The pci id of usb ctrl 0 and 1 are the same. |
| 212 | */ |
| 213 | static const struct pci_driver usb_ohci123_driver __pci_driver = { |
| 214 | .ops = &usb_ops, |
| 215 | .vendor = PCI_VENDOR_ID_ATI, |
| 216 | .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */ |
| 217 | }; |
| 218 | |
| 219 | static const struct pci_driver usb_ehci123_driver __pci_driver = { |
| 220 | .ops = &usb_ops, |
| 221 | .vendor = PCI_VENDOR_ID_ATI, |
| 222 | .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */ |
| 223 | }; |
| 224 | |
| 225 | static const struct pci_driver usb_ohci4_driver __pci_driver = { |
| 226 | .ops = &usb_ops, |
| 227 | .vendor = PCI_VENDOR_ID_ATI, |
| 228 | .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */ |
| 229 | }; |
| 230 | |
| 231 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 232 | static struct device_operations azalia_ops = { |
| 233 | .read_resources = pci_dev_read_resources, |
| 234 | .set_resources = pci_dev_set_resources, |
| 235 | .enable_resources = pci_dev_enable_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 236 | .init = 0, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 237 | .scan_bus = 0, |
| 238 | .ops_pci = &lops_pci, |
| 239 | }; |
| 240 | |
| 241 | static const struct pci_driver azalia_driver __pci_driver = { |
| 242 | .ops = &azalia_ops, |
| 243 | .vendor = PCI_VENDOR_ID_ATI, |
| 244 | .device = PCI_DEVICE_ID_ATI_SB800_HDA, |
| 245 | }; |
| 246 | |
| 247 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 248 | static struct device_operations gec_ops = { |
| 249 | .read_resources = pci_dev_read_resources, |
| 250 | .set_resources = pci_dev_set_resources, |
| 251 | .enable_resources = pci_dev_enable_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 252 | .init = 0, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 253 | .scan_bus = 0, |
| 254 | .ops_pci = &lops_pci, |
| 255 | }; |
| 256 | |
| 257 | static const struct pci_driver gec_driver __pci_driver = { |
| 258 | .ops = &gec_ops, |
| 259 | .vendor = PCI_VENDOR_ID_ATI, |
| 260 | .device = PCI_DEVICE_ID_ATI_SB800_GEC, |
| 261 | }; |
| 262 | |
Kerry She | 3e706b6 | 2011-06-24 22:52:15 +0800 | [diff] [blame] | 263 | /** |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 264 | * Fill build time defaults. |
| 265 | */ |
| 266 | static void sb800_init(void *chip_info) |
| 267 | { |
| 268 | sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry; |
| 269 | sb800_cimx_config(sb_config); |
Kyösti Mälkki | 24501ca | 2015-02-07 17:38:45 +0200 | [diff] [blame] | 270 | |
| 271 | abcfg_reg(0xc0, 0x01FF, 0x0F4); |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 275 | * South Bridge CIMx ramstage entry point wrapper. |
| 276 | */ |
| 277 | void sb_Before_Pci_Init(void) |
| 278 | { |
| 279 | sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT; |
| 280 | AmdSbDispatcher(sb_config); |
| 281 | } |
| 282 | |
| 283 | void sb_After_Pci_Init(void) |
| 284 | { |
| 285 | sb_config->StdHeader.Func = SB_AFTER_PCI_INIT; |
| 286 | AmdSbDispatcher(sb_config); |
| 287 | } |
| 288 | |
| 289 | void sb_Mid_Post_Init(void) |
| 290 | { |
| 291 | sb_config->StdHeader.Func = SB_MID_POST_INIT; |
| 292 | AmdSbDispatcher(sb_config); |
| 293 | } |
| 294 | |
| 295 | void sb_Late_Post(void) |
| 296 | { |
| 297 | sb_config->StdHeader.Func = SB_LATE_POST_INIT; |
| 298 | AmdSbDispatcher(sb_config); |
| 299 | } |
| 300 | |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 301 | void sb_Before_Pci_Restore_Init(void) |
| 302 | { |
| 303 | sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT; |
| 304 | AmdSbDispatcher(sb_config); |
| 305 | } |
| 306 | |
| 307 | void sb_After_Pci_Restore_Init(void) |
| 308 | { |
| 309 | sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT; |
| 310 | AmdSbDispatcher(sb_config); |
| 311 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 312 | |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 313 | /* |
| 314 | * Update the PCI devices with a valid IRQ number |
| 315 | * that is set in the mainboard PCI_IRQ structures. |
| 316 | */ |
| 317 | static void set_pci_irqs(void *unused) |
| 318 | { |
| 319 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 320 | write_pci_int_table(); |
| 321 | |
| 322 | /* Write IRQs for all devicetree enabled devices */ |
| 323 | write_pci_cfg_irqs(); |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Hook this function into the PCI state machine |
| 328 | * on entry into BS_DEV_ENABLE. |
| 329 | */ |
Aaron Durbin | 9ef9d85 | 2015-03-16 17:30:09 -0500 | [diff] [blame] | 330 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 331 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 332 | /** |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 333 | * @brief SB Cimx entry point sbBeforePciInit wrapper |
| 334 | */ |
| 335 | static void sb800_enable(device_t dev) |
| 336 | { |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 337 | struct southbridge_amd_cimx_sb800_config *sb_chip = |
| 338 | (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 339 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 340 | switch (dev->path.pci.devfn) { |
| 341 | case (0x11 << 3) | 0: /* 0:11.0 SATA */ |
| 342 | if (dev->enabled) { |
Kerry She | 991f880 | 2011-06-01 01:56:49 +0000 | [diff] [blame] | 343 | sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 344 | if (1 == sb_chip->boot_switch_sata_ide) |
| 345 | sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary. |
| 346 | else if (0 == sb_chip->boot_switch_sata_ide) |
| 347 | sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary. |
| 348 | } else { |
Kerry She | 991f880 | 2011-06-01 01:56:49 +0000 | [diff] [blame] | 349 | sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 350 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 351 | break; |
| 352 | |
| 353 | case (0x14 << 3) | 0: /* 0:14:0 SMBUS */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 354 | clear_ioapic(VIO_APIC_VADDR); |
Kyösti Mälkki | 35546de | 2014-04-17 15:07:32 +0300 | [diff] [blame] | 355 | #if CONFIG_CPU_AMD_AGESA |
| 356 | /* Assign the ioapic ID the next available number after the processor core local APIC IDs */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 357 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Kyösti Mälkki | 35546de | 2014-04-17 15:07:32 +0300 | [diff] [blame] | 358 | #else |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 359 | /* I/O APIC IDs are normally limited to 4-bits. Enforce this limit. */ |
| 360 | #if (CONFIG_APIC_ID_OFFSET == 0 && CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS < 16) |
| 361 | /* Assign the ioapic ID the next available number after the processor core local APIC IDs */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 362 | setup_ioapic(VIO_APIC_VADDR, |
| 363 | CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 364 | #elif (CONFIG_APIC_ID_OFFSET > 0) |
| 365 | /* Assign the ioapic ID the value 0. Processor APIC IDs follow. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 366 | setup_ioapic(VIO_APIC_VADDR, 0); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 367 | #else |
| 368 | #error "The processor APIC IDs must be lifted to make room for the I/O APIC ID" |
| 369 | #endif |
Kyösti Mälkki | 35546de | 2014-04-17 15:07:32 +0300 | [diff] [blame] | 370 | #endif |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 371 | break; |
| 372 | |
| 373 | case (0x14 << 3) | 1: /* 0:14:1 IDE */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 374 | break; |
| 375 | |
| 376 | case (0x14 << 3) | 2: /* 0:14:2 HDA */ |
| 377 | if (dev->enabled) { |
| 378 | if (AZALIA_DISABLE == sb_config->AzaliaController) { |
| 379 | sb_config->AzaliaController = AZALIA_AUTO; |
| 380 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 381 | } else { |
| 382 | sb_config->AzaliaController = AZALIA_DISABLE; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 383 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 384 | break; |
| 385 | |
| 386 | |
| 387 | case (0x14 << 3) | 3: /* 0:14:3 LPC */ |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 388 | /* Initialize the fans */ |
| 389 | #if CONFIG_SB800_IMC_FAN_CONTROL |
| 390 | init_sb800_IMC_fans(dev); |
| 391 | #elif CONFIG_SB800_MANUAL_FAN_CONTROL |
| 392 | init_sb800_MANUAL_fans(dev); |
| 393 | #endif |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 394 | break; |
| 395 | |
| 396 | case (0x14 << 3) | 4: /* 0:14:4 PCI */ |
Kyösti Mälkki | 486c05f | 2015-01-17 18:08:40 +0200 | [diff] [blame] | 397 | /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0] |
| 398 | * 'PCIDisable' set to 0 to enable P2P bridge. |
| 399 | * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins |
| 400 | * to function as GPIO {GPIO 35:0}. |
| 401 | */ |
Kyösti Mälkki | 0b87bb7 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 402 | if (!sb_chip->disconnect_pcib && dev->enabled) |
Kyösti Mälkki | 486c05f | 2015-01-17 18:08:40 +0200 | [diff] [blame] | 403 | RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, 0); |
| 404 | else |
| 405 | RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, BIT0); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 406 | break; |
| 407 | |
| 408 | case (0x14 << 3) | 6: /* 0:14:6 GEC */ |
| 409 | if (dev->enabled) { |
| 410 | sb_config->GecConfig = 0; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 411 | } else { |
| 412 | sb_config->GecConfig = 1; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 413 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 414 | break; |
| 415 | |
| 416 | case (0x15 << 3) | 0: /* 0:15:0 PCIe PortA */ |
Scott Duplichan | 8fed77a | 2011-06-18 10:46:45 -0500 | [diff] [blame] | 417 | { |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 418 | device_t device; |
| 419 | for (device = dev; device; device = device->next) { |
| 420 | if (dev->path.type != DEVICE_PATH_PCI) continue; |
| 421 | if ((device->path.pci.devfn & ~7) != PCI_DEVFN(0x15,0)) break; |
| 422 | sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled; |
| 423 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 424 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 425 | /* |
| 426 | * GPP_CFGMODE_X4000: PortA Lanes[3:0] |
| 427 | * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2] |
| 428 | * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3 |
| 429 | * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3 |
| 430 | */ |
| 431 | sb_config->GppLinkConfig = sb_chip->gpp_configuration; |
Scott Duplichan | 8fed77a | 2011-06-18 10:46:45 -0500 | [diff] [blame] | 432 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 433 | break; |
| 434 | |
| 435 | case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */ |
| 436 | sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled; |
| 437 | break; |
| 438 | case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */ |
| 439 | sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled; |
| 440 | break; |
| 441 | case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */ |
| 442 | sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled; |
| 443 | break; |
| 444 | case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */ |
| 445 | sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled; |
| 446 | break; |
| 447 | case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */ |
| 448 | sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled; |
| 449 | break; |
| 450 | case (0x16 << 3) | 0: /* 0:16:0 OHCI-USB3 */ |
| 451 | sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled; |
| 452 | break; |
| 453 | case (0x16 << 3) | 2: /* 0:16:2 EHCI-USB3 */ |
| 454 | sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled; |
| 455 | |
Kerry Sheh | 75df106 | 2011-10-10 19:19:46 +0800 | [diff] [blame] | 456 | /* call the CIMX entry at the last sb800 device, |
| 457 | * so make sure the mainboard devicetree is complete |
| 458 | */ |
Kyösti Mälkki | c551caa | 2014-06-20 12:31:23 +0300 | [diff] [blame] | 459 | if (!acpi_is_wakeup_s3()) |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 460 | sb_Before_Pci_Init(); |
| 461 | else |
| 462 | sb_Before_Pci_Restore_Init(); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 463 | break; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 464 | |
| 465 | default: |
| 466 | break; |
| 467 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 468 | } |
| 469 | |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 470 | struct chip_operations southbridge_amd_cimx_sb800_ops = { |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 471 | CHIP_NAME("ATI SB800") |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 472 | .init = sb800_init, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 473 | .enable_dev = sb800_enable, |
| 474 | }; |