blob: 393eda0090a324b055c7545da6f27348f3b32a9a [file] [log] [blame]
Frank Vibrans63e62b02011-02-14 18:38:14 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
Mike Loptienc93a75a2014-06-06 15:16:29 -06005 * Copyright (C) 2014 Sage Electronic Engineering, LLC.
Frank Vibrans63e62b02011-02-14 18:38:14 +00006 *
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.
Frank Vibrans63e62b02011-02-14 18:38:14 +000015 */
16
17
18#include <device/device.h> /* device_t */
19#include <device/pci.h> /* device_operations */
20#include <device/pci_ids.h>
Mike Loptienc93a75a2014-06-06 15:16:29 -060021#include <bootstate.h>
Kerry She991f8802011-06-01 01:56:49 +000022#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000023#include <device/smbus.h> /* smbus_bus_operations */
zbao366f0fc2012-08-03 16:58:53 +080024#include <pc80/mc146818rtc.h>
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +100025#include <pc80/i8254.h>
26#include <pc80/i8259.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000027#include <console/console.h> /* printk */
zbao9bcdbf82012-04-05 13:18:49 +080028#include <arch/acpi.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020029#include <device/pci_ehci.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000030#include "lpc.h" /* lpc_read_resources */
Martin Roth3c3a50c2014-12-16 20:50:26 -070031#include "SBPLATFORM.h" /* Platform Specific Definitions */
Frank Vibrans63e62b02011-02-14 18:38:14 +000032#include "cfg.h" /* sb800 Cimx configuration */
efdesign9805a89ab2011-06-20 17:38:49 -070033#include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
Kerry Shefeed3292011-08-18 18:03:44 +080034#include "sb_cimx.h" /* AMD CIMX wrapper entries */
Dave Frodin23023a52012-11-13 07:09:12 -070035#include "smbus.h"
Martin Rothe899e512012-12-05 16:07:11 -070036#include "fan.h"
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +010037#include "pci_devs.h"
Stefan Reinauer13e41822015-04-27 14:02:36 -070038#include <southbridge/amd/common/amd_pci_util.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000039
Frank Vibrans63e62b02011-02-14 18:38:14 +000040static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
41static AMDSBCFG *sb_config = &sb_late_cfg;
42
Frank Vibrans63e62b02011-02-14 18:38:14 +000043/**
44 * @brief Entry point of Southbridge CIMx callout
45 *
46 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
47 *
48 * @param[in] func Southbridge CIMx Function ID.
49 * @param[in] data Southbridge Input Data.
Martin Roth6355cbf2015-01-04 15:22:26 -070050 * @param[in] config Southbridge configuration structure pointer.
Frank Vibrans63e62b02011-02-14 18:38:14 +000051 *
52 */
Kyösti Mälkki41cd0472015-02-07 11:20:54 +020053static u32 sb800_callout_entry(u32 func, u32 data, void* config)
Frank Vibrans63e62b02011-02-14 18:38:14 +000054{
55 u32 ret = 0;
Kerry Shefeed3292011-08-18 18:03:44 +080056 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000057 switch (func) {
58 case CB_SBGPP_RESET_ASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000059 break;
60
61 case CB_SBGPP_RESET_DEASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000062 break;
63
64 case IMC_FIRMWARE_FAIL:
65 break;
66
67 default:
68 break;
69 }
70
Kerry Shefeed3292011-08-18 18:03:44 +080071 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000072 return ret;
73}
74
Kerry Sheh0e6344e2011-10-12 11:42:59 +080075#define HOST_CAP 0x00 /* host capabilities */
76#define HOST_CTL 0x04 /* global host control */
77#define HOST_IRQ_STAT 0x08 /* interrupt status */
78#define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */
79
80#define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */
81static void ahci_raid_init(struct device *dev)
82{
83 u8 irq = 0;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070084 void *bar5;
85 u32 caps, ports, val;
Kerry Sheh0e6344e2011-10-12 11:42:59 +080086
87 val = pci_read_config16(dev, PCI_CLASS_DEVICE);
88 if (val == PCI_CLASS_STORAGE_SATA) {
89 printk(BIOS_DEBUG, "AHCI controller ");
90 } else if (val == PCI_CLASS_STORAGE_RAID) {
91 printk(BIOS_DEBUG, "RAID controller ");
92 } else {
93 printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val);
94 return;
95 }
96
97 irq = pci_read_config8(dev, PCI_INTERRUPT_LINE);
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070098 bar5 = (void *)(uintptr_t)pci_read_config32(dev, PCI_BASE_ADDRESS_5);
99 printk(BIOS_DEBUG, "IOMEM base: %p, IRQ: 0x%X\n", bar5, irq);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800100
Stefan Reinauer12bce3f2015-06-18 01:17:38 -0700101 caps = read32(bar5 + HOST_CAP);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800102 caps = (caps & 0x1F) + 1;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -0700103 ports= read32(bar5 + HOST_PORTS_IMPL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800104 printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports);
105
106 /* make sure ahci is enabled */
Stefan Reinauer12bce3f2015-06-18 01:17:38 -0700107 val = read32(bar5 + HOST_CTL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800108 if (!(val & HOST_CTL_AHCI_EN)) {
Stefan Reinauer12bce3f2015-06-18 01:17:38 -0700109 write32(bar5 + HOST_CTL, val | HOST_CTL_AHCI_EN);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800110 }
111
112 dev->command |= PCI_COMMAND_MASTER;
113 pci_write_config8(dev, PCI_COMMAND, dev->command);
114 printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n");
115}
Frank Vibrans63e62b02011-02-14 18:38:14 +0000116
117static struct pci_operations lops_pci = {
Kerry Shefeed3292011-08-18 18:03:44 +0800118 .set_subsystem = pci_dev_set_subsystem,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000119};
120
zbao366f0fc2012-08-03 16:58:53 +0800121static void lpc_init(device_t dev)
122{
123 printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - Start.\n");
124
Gabe Black03abaee212014-04-30 21:31:44 -0700125 cmos_check_update_date();
zbao366f0fc2012-08-03 16:58:53 +0800126
Mike Loptienac529b12013-02-22 13:18:31 -0700127 /* Initialize the real time clock.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700128 * The 0 argument tells cmos_init not to
Mike Loptienac529b12013-02-22 13:18:31 -0700129 * update CMOS unless it is invalid.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700130 * 1 tells cmos_init to always initialize the CMOS.
Mike Loptienac529b12013-02-22 13:18:31 -0700131 */
Gabe Blackb3f08c62014-04-30 17:12:25 -0700132 cmos_init(0);
Mike Loptienac529b12013-02-22 13:18:31 -0700133
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +1000134 setup_i8259(); /* Initialize i8259 pic */
135 setup_i8254(); /* Initialize i8254 timers */
136
zbao366f0fc2012-08-03 16:58:53 +0800137 printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - End.\n");
138}
139
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200140unsigned long acpi_fill_mcfg(unsigned long current)
141{
142 /* Just a dummy */
143 return current;
144}
145
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600146static const char *lpc_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100147{
148 if (dev->path.type != DEVICE_PATH_PCI)
149 return NULL;
150
151 switch (dev->path.pci.devfn) {
152 /* DSDT: acpi/lpc.asl */
153 case LPC_DEVFN:
154 return "LIBR";
155 }
156
157 return NULL;
158}
159
Frank Vibrans63e62b02011-02-14 18:38:14 +0000160static struct device_operations lpc_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200161 .read_resources = lpc_read_resources,
162 .set_resources = lpc_set_resources,
163 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko83f81ca2014-11-09 13:30:50 +0100164#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200165 .write_acpi_tables = acpi_write_hpet,
166#endif
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200167 .init = lpc_init,
168 .scan_bus = scan_lpc_bus,
169 .ops_pci = &lops_pci,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100170 .acpi_name = lpc_acpi_name,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000171};
172
173static const struct pci_driver lpc_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200174 .ops = &lpc_ops,
175 .vendor = PCI_VENDOR_ID_ATI,
176 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000177};
178
Frank Vibrans63e62b02011-02-14 18:38:14 +0000179static struct device_operations sata_ops = {
180 .read_resources = pci_dev_read_resources,
181 .set_resources = pci_dev_set_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800182 .enable_resources = pci_dev_enable_resources,
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800183 .init = ahci_raid_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000184 .scan_bus = 0,
185 .ops_pci = &lops_pci,
186};
187
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800188static const struct pci_driver ahci_driver __pci_driver = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000189 .ops = &sata_ops,
190 .vendor = PCI_VENDOR_ID_ATI,
Scott Duplichanf191c722011-05-15 21:38:08 +0000191 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000192};
193
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800194static const struct pci_driver raid_driver __pci_driver = {
195 .ops = &sata_ops,
196 .vendor = PCI_VENDOR_ID_ATI,
197 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID,
198};
199static const struct pci_driver raid5_driver __pci_driver = {
200 .ops = &sata_ops,
201 .vendor = PCI_VENDOR_ID_ATI,
202 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5,
203};
204
Frank Vibrans63e62b02011-02-14 18:38:14 +0000205static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300206 .read_resources = pci_ehci_read_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000207 .set_resources = pci_dev_set_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000208 .enable_resources = pci_dev_enable_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800209 .init = 0,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000210 .scan_bus = 0,
211 .ops_pci = &lops_pci,
212};
213
214/*
215 * The pci id of usb ctrl 0 and 1 are the same.
216 */
217static const struct pci_driver usb_ohci123_driver __pci_driver = {
218 .ops = &usb_ops,
219 .vendor = PCI_VENDOR_ID_ATI,
220 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
221};
222
223static const struct pci_driver usb_ehci123_driver __pci_driver = {
224 .ops = &usb_ops,
225 .vendor = PCI_VENDOR_ID_ATI,
226 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
227};
228
229static const struct pci_driver usb_ohci4_driver __pci_driver = {
230 .ops = &usb_ops,
231 .vendor = PCI_VENDOR_ID_ATI,
232 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
233};
234
235
Frank Vibrans63e62b02011-02-14 18:38:14 +0000236static struct device_operations azalia_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200237 .read_resources = pci_dev_read_resources,
238 .set_resources = pci_dev_set_resources,
239 .enable_resources = pci_dev_enable_resources,
240 .init = 0,
241 .scan_bus = 0,
242 .ops_pci = &lops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000243};
244
245static const struct pci_driver azalia_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200246 .ops = &azalia_ops,
247 .vendor = PCI_VENDOR_ID_ATI,
248 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000249};
250
251
Frank Vibrans63e62b02011-02-14 18:38:14 +0000252static struct device_operations gec_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200253 .read_resources = pci_dev_read_resources,
254 .set_resources = pci_dev_set_resources,
255 .enable_resources = pci_dev_enable_resources,
256 .init = 0,
257 .scan_bus = 0,
258 .ops_pci = &lops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000259};
260
261static const struct pci_driver gec_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200262 .ops = &gec_ops,
263 .vendor = PCI_VENDOR_ID_ATI,
264 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000265};
266
Kerry She3e706b62011-06-24 22:52:15 +0800267/**
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200268 * Fill build time defaults.
269 */
270static void sb800_init(void *chip_info)
271{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200272 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200273 sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry;
274 sb800_cimx_config(sb_config);
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200275
Paul Menzel114a9482015-10-25 22:27:42 +0100276 /* Initially enable all GPP ports 0 to 3 */
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200277 abcfg_reg(0xc0, 0x01FF, 0x0F4);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200278}
279
280/**
Kerry Shefeed3292011-08-18 18:03:44 +0800281 * South Bridge CIMx ramstage entry point wrapper.
282 */
283void sb_Before_Pci_Init(void)
284{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200285 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800286 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
287 AmdSbDispatcher(sb_config);
288}
289
290void sb_After_Pci_Init(void)
291{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200292 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800293 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
294 AmdSbDispatcher(sb_config);
295}
296
297void sb_Mid_Post_Init(void)
298{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200299 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800300 sb_config->StdHeader.Func = SB_MID_POST_INIT;
301 AmdSbDispatcher(sb_config);
302}
303
304void sb_Late_Post(void)
305{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200306 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800307 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
308 AmdSbDispatcher(sb_config);
309}
310
zbao9bcdbf82012-04-05 13:18:49 +0800311void sb_Before_Pci_Restore_Init(void)
312{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200313 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800314 sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT;
315 AmdSbDispatcher(sb_config);
316}
317
318void sb_After_Pci_Restore_Init(void)
319{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200320 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800321 sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT;
322 AmdSbDispatcher(sb_config);
323}
Kerry Shefeed3292011-08-18 18:03:44 +0800324
Mike Loptienc93a75a2014-06-06 15:16:29 -0600325/*
326 * Update the PCI devices with a valid IRQ number
327 * that is set in the mainboard PCI_IRQ structures.
328 */
329static void set_pci_irqs(void *unused)
330{
331 /* Write PCI_INTR regs 0xC00/0xC01 */
332 write_pci_int_table();
333
334 /* Write IRQs for all devicetree enabled devices */
335 write_pci_cfg_irqs();
336}
337
338/*
339 * Hook this function into the PCI state machine
340 * on entry into BS_DEV_ENABLE.
341 */
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500342BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);
Mike Loptienc93a75a2014-06-06 15:16:29 -0600343
Kerry Shefeed3292011-08-18 18:03:44 +0800344/**
Frank Vibrans63e62b02011-02-14 18:38:14 +0000345 * @brief SB Cimx entry point sbBeforePciInit wrapper
346 */
347static void sb800_enable(device_t dev)
348{
efdesign9805a89ab2011-06-20 17:38:49 -0700349 struct southbridge_amd_cimx_sb800_config *sb_chip =
350 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000351
Frank Vibrans63e62b02011-02-14 18:38:14 +0000352 switch (dev->path.pci.devfn) {
353 case (0x11 << 3) | 0: /* 0:11.0 SATA */
354 if (dev->enabled) {
Kerry She991f8802011-06-01 01:56:49 +0000355 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000356 if (1 == sb_chip->boot_switch_sata_ide)
357 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
358 else if (0 == sb_chip->boot_switch_sata_ide)
359 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
360 } else {
Kerry She991f8802011-06-01 01:56:49 +0000361 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000362 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000363 break;
364
365 case (0x14 << 3) | 0: /* 0:14:0 SMBUS */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800366 clear_ioapic(VIO_APIC_VADDR);
Martin Roth083504b2017-06-24 21:30:14 -0600367#if IS_ENABLED(CONFIG_CPU_AMD_AGESA)
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300368 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800369 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300370#else
Kerry Shefeed3292011-08-18 18:03:44 +0800371 /* I/O APIC IDs are normally limited to 4-bits. Enforce this limit. */
372#if (CONFIG_APIC_ID_OFFSET == 0 && CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS < 16)
373 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800374 setup_ioapic(VIO_APIC_VADDR,
375 CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS);
Kerry Shefeed3292011-08-18 18:03:44 +0800376#elif (CONFIG_APIC_ID_OFFSET > 0)
377 /* Assign the ioapic ID the value 0. Processor APIC IDs follow. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800378 setup_ioapic(VIO_APIC_VADDR, 0);
Kerry Shefeed3292011-08-18 18:03:44 +0800379#else
380#error "The processor APIC IDs must be lifted to make room for the I/O APIC ID"
381#endif
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300382#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000383 break;
384
385 case (0x14 << 3) | 1: /* 0:14:1 IDE */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000386 break;
387
388 case (0x14 << 3) | 2: /* 0:14:2 HDA */
389 if (dev->enabled) {
390 if (AZALIA_DISABLE == sb_config->AzaliaController) {
391 sb_config->AzaliaController = AZALIA_AUTO;
392 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000393 } else {
394 sb_config->AzaliaController = AZALIA_DISABLE;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000395 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000396 break;
397
398
399 case (0x14 << 3) | 3: /* 0:14:3 LPC */
Martin Rothe899e512012-12-05 16:07:11 -0700400 /* Initialize the fans */
Martin Roth083504b2017-06-24 21:30:14 -0600401#if IS_ENABLED(CONFIG_SB800_IMC_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700402 init_sb800_IMC_fans(dev);
Martin Roth083504b2017-06-24 21:30:14 -0600403#elif IS_ENABLED(CONFIG_SB800_MANUAL_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700404 init_sb800_MANUAL_fans(dev);
405#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000406 break;
407
408 case (0x14 << 3) | 4: /* 0:14:4 PCI */
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200409 /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
410 * 'PCIDisable' set to 0 to enable P2P bridge.
411 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
412 * to function as GPIO {GPIO 35:0}.
413 */
Kyösti Mälkki0b87bb72014-11-11 17:22:23 +0200414 if (!sb_chip->disconnect_pcib && dev->enabled)
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200415 RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, 0);
416 else
417 RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, BIT0);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000418 break;
419
420 case (0x14 << 3) | 6: /* 0:14:6 GEC */
421 if (dev->enabled) {
422 sb_config->GecConfig = 0;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000423 } else {
424 sb_config->GecConfig = 1;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000425 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000426 break;
427
428 case (0x15 << 3) | 0: /* 0:15:0 PCIe PortA */
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500429 {
Kerry Shefeed3292011-08-18 18:03:44 +0800430 device_t device;
Paul Menzele4a016f2013-03-01 13:05:04 +0100431 for (device = dev; device; device = device->sibling) {
432 if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
Kerry Shefeed3292011-08-18 18:03:44 +0800433 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
434 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000435
Kerry Shefeed3292011-08-18 18:03:44 +0800436 /*
437 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
438 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
439 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
440 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
441 */
442 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500443 }
Kerry Shefeed3292011-08-18 18:03:44 +0800444 break;
445
446 case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */
447 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
448 break;
449 case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */
450 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
451 break;
452 case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */
453 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
454 break;
455 case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */
456 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
457 break;
458 case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */
459 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
460 break;
461 case (0x16 << 3) | 0: /* 0:16:0 OHCI-USB3 */
462 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
463 break;
464 case (0x16 << 3) | 2: /* 0:16:2 EHCI-USB3 */
465 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
466
Kyösti Mälkki9de8ab92017-09-09 16:51:34 +0300467 /* FIXME: Find better callsites for these.
468 * call the CIMX entry at the last sb800 device,
Kerry Sheh75df1062011-10-10 19:19:46 +0800469 * so make sure the mainboard devicetree is complete
470 */
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300471 if (!acpi_is_wakeup_s3())
zbao9bcdbf82012-04-05 13:18:49 +0800472 sb_Before_Pci_Init();
473 else
474 sb_Before_Pci_Restore_Init();
Kerry Shefeed3292011-08-18 18:03:44 +0800475 break;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000476
477 default:
478 break;
479 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000480}
481
efdesign9805a89ab2011-06-20 17:38:49 -0700482struct chip_operations southbridge_amd_cimx_sb800_ops = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000483 CHIP_NAME("ATI SB800")
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200484 .init = sb800_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000485 .enable_dev = sb800_enable,
486};