2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
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; version 2 of the License.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <device/device.h> /* device_t */
22 #include <device/pci.h> /* device_operations */
23 #include <device/pci_ids.h>
24 #include <arch/ioapic.h>
25 #include <device/smbus.h> /* smbus_bus_operations */
26 #include <console/console.h> /* printk */
27 #include "lpc.h" /* lpc_read_resources */
28 #include "SBPLATFORM.h" /* Platfrom Specific Definitions */
29 #include "cfg.h" /* sb800 Cimx configuration */
30 #include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
31 #include "sb_cimx.h" /* AMD CIMX wrapper entries */
34 /*implement in mainboard.c*/
35 void set_pcie_reset(void);
36 void set_pcie_dereset(void);
39 static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
40 static AMDSBCFG *sb_config = &sb_late_cfg;
44 * @brief Entry point of Southbridge CIMx callout
46 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
48 * @param[in] func Southbridge CIMx Function ID.
49 * @param[in] data Southbridge Input Data.
50 * @param[in] sb_config Southbridge configuration structure pointer.
53 u32 sb800_callout_entry(u32 func, u32 data, void* config)
56 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
58 case CB_SBGPP_RESET_ASSERT:
62 case CB_SBGPP_RESET_DEASSERT:
66 case IMC_FIRMWARE_FAIL:
73 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
77 #define HOST_CAP 0x00 /* host capabilities */
78 #define HOST_CTL 0x04 /* global host control */
79 #define HOST_IRQ_STAT 0x08 /* interrupt status */
80 #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */
82 #define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */
83 static void ahci_raid_init(struct device *dev)
86 u32 bar5, caps, ports, val;
88 val = pci_read_config16(dev, PCI_CLASS_DEVICE);
89 if (val == PCI_CLASS_STORAGE_SATA) {
90 printk(BIOS_DEBUG, "AHCI controller ");
91 } else if (val == PCI_CLASS_STORAGE_RAID) {
92 printk(BIOS_DEBUG, "RAID controller ");
94 printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val);
98 irq = pci_read_config8(dev, PCI_INTERRUPT_LINE);
99 bar5 = pci_read_config32(dev, PCI_BASE_ADDRESS_5);
100 printk(BIOS_DEBUG, "IOMEM base: 0x%X, IRQ: 0x%X\n", bar5, irq);
102 caps = *(volatile u32 *)(bar5 + HOST_CAP);
103 caps = (caps & 0x1F) + 1;
104 ports= *(volatile u32 *)(bar5 + HOST_PORTS_IMPL);
105 printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports);
107 /* make sure ahci is enabled */
108 val = *(volatile u32 *)(bar5 + HOST_CTL);
109 if (!(val & HOST_CTL_AHCI_EN)) {
110 *(volatile u32 *)(bar5 + HOST_CTL) = val | HOST_CTL_AHCI_EN;
113 dev->command |= PCI_COMMAND_MASTER;
114 pci_write_config8(dev, PCI_COMMAND, dev->command);
115 printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n");
118 static struct pci_operations lops_pci = {
119 .set_subsystem = pci_dev_set_subsystem,
122 static struct device_operations lpc_ops = {
123 .read_resources = lpc_read_resources,
124 .set_resources = lpc_set_resources,
125 .enable_resources = pci_dev_enable_resources,
127 .scan_bus = scan_static_bus,
128 .ops_pci = &lops_pci,
131 static const struct pci_driver lpc_driver __pci_driver = {
133 .vendor = PCI_VENDOR_ID_ATI,
134 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
137 static struct device_operations sata_ops = {
138 .read_resources = pci_dev_read_resources,
139 .set_resources = pci_dev_set_resources,
140 .enable_resources = pci_dev_enable_resources,
141 .init = ahci_raid_init,
143 .ops_pci = &lops_pci,
146 static const struct pci_driver ahci_driver __pci_driver = {
148 .vendor = PCI_VENDOR_ID_ATI,
149 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
152 static const struct pci_driver raid_driver __pci_driver = {
154 .vendor = PCI_VENDOR_ID_ATI,
155 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID,
157 static const struct pci_driver raid5_driver __pci_driver = {
159 .vendor = PCI_VENDOR_ID_ATI,
160 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5,
163 #if CONFIG_USBDEBUG == 1
164 static void usb_set_resources(struct device *dev)
166 struct resource *res;
170 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
171 old_debug = get_ehci_debug();
174 pci_dev_set_resources(dev);
176 res = find_resource(dev, 0x10);
177 set_ehci_debug(old_debug);
182 report_resource_stored(dev, res, "");
183 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
187 static struct device_operations usb_ops = {
188 .read_resources = pci_dev_read_resources,
190 .set_resources = usb_set_resources,
192 .set_resources = pci_dev_set_resources,
194 .enable_resources = pci_dev_enable_resources,
197 .ops_pci = &lops_pci,
201 * The pci id of usb ctrl 0 and 1 are the same.
203 static const struct pci_driver usb_ohci123_driver __pci_driver = {
205 .vendor = PCI_VENDOR_ID_ATI,
206 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
209 static const struct pci_driver usb_ehci123_driver __pci_driver = {
211 .vendor = PCI_VENDOR_ID_ATI,
212 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
215 static const struct pci_driver usb_ohci4_driver __pci_driver = {
217 .vendor = PCI_VENDOR_ID_ATI,
218 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
222 static struct device_operations azalia_ops = {
223 .read_resources = pci_dev_read_resources,
224 .set_resources = pci_dev_set_resources,
225 .enable_resources = pci_dev_enable_resources,
228 .ops_pci = &lops_pci,
231 static const struct pci_driver azalia_driver __pci_driver = {
233 .vendor = PCI_VENDOR_ID_ATI,
234 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
238 static struct device_operations gec_ops = {
239 .read_resources = pci_dev_read_resources,
240 .set_resources = pci_dev_set_resources,
241 .enable_resources = pci_dev_enable_resources,
244 .ops_pci = &lops_pci,
247 static const struct pci_driver gec_driver __pci_driver = {
249 .vendor = PCI_VENDOR_ID_ATI,
250 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
254 * @brief Enable PCI Bridge
256 * PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
257 * 'PCIDisable' set to 0 to enable P2P bridge.
258 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
259 * to function as GPIO {GPIO 35:0}.
261 static void pci_init(device_t dev)
263 /* PCI Bridge SHOULD be enabled by default according to SB800 rrg,
264 * but actually was disabled in some platform, so I have to enabled it.
266 RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, 0);
270 static struct device_operations pci_ops = {
271 .read_resources = pci_bus_read_resources,
272 .set_resources = pci_dev_set_resources,
273 .enable_resources = pci_bus_enable_resources,
275 .scan_bus = pci_scan_bridge,
276 .reset_bus = pci_bus_reset,
277 .ops_pci = &lops_pci,
280 static const struct pci_driver pci_driver __pci_driver = {
282 .vendor = PCI_VENDOR_ID_ATI,
283 .device = PCI_DEVICE_ID_ATI_SB800_PCI,
287 struct device_operations bridge_ops = {
288 .read_resources = pci_bus_read_resources,
289 .set_resources = pci_dev_set_resources,
290 .enable_resources = pci_bus_enable_resources,
292 .scan_bus = pci_scan_bridge,
294 .reset_bus = pci_bus_reset,
295 .ops_pci = &lops_pci,
298 /* 0:15:0 PCIe PortA */
299 static const struct pci_driver PORTA_driver __pci_driver = {
301 .vendor = PCI_VENDOR_ID_ATI,
302 .device = PCI_DEVICE_ID_ATI_SB800_PCIEA,
305 /* 0:15:1 PCIe PortB */
306 static const struct pci_driver PORTB_driver __pci_driver = {
308 .vendor = PCI_VENDOR_ID_ATI,
309 .device = PCI_DEVICE_ID_ATI_SB800_PCIEB,
312 /* 0:15:2 PCIe PortC */
313 static const struct pci_driver PORTC_driver __pci_driver = {
315 .vendor = PCI_VENDOR_ID_ATI,
316 .device = PCI_DEVICE_ID_ATI_SB800_PCIEC,
319 /* 0:15:3 PCIe PortD */
320 static const struct pci_driver PORTD_driver __pci_driver = {
322 .vendor = PCI_VENDOR_ID_ATI,
323 .device = PCI_DEVICE_ID_ATI_SB800_PCIED,
328 * South Bridge CIMx ramstage entry point wrapper.
330 void sb_Before_Pci_Init(void)
332 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
333 AmdSbDispatcher(sb_config);
336 void sb_After_Pci_Init(void)
338 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
339 AmdSbDispatcher(sb_config);
342 void sb_Mid_Post_Init(void)
344 sb_config->StdHeader.Func = SB_MID_POST_INIT;
345 AmdSbDispatcher(sb_config);
348 void sb_Late_Post(void)
350 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
351 AmdSbDispatcher(sb_config);
356 * @brief SB Cimx entry point sbBeforePciInit wrapper
358 static void sb800_enable(device_t dev)
360 struct southbridge_amd_cimx_sb800_config *sb_chip =
361 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
363 printk(BIOS_DEBUG, "sb800_enable() ");
365 switch (dev->path.pci.devfn) {
366 case (0x11 << 3) | 0: /* 0:11.0 SATA */
367 /* the first sb800 device */
368 sb800_cimx_config(sb_config);
371 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
372 if (1 == sb_chip->boot_switch_sata_ide)
373 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
374 else if (0 == sb_chip->boot_switch_sata_ide)
375 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
377 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
381 case (0x14 << 3) | 0: /* 0:14:0 SMBUS */
382 printk(BIOS_INFO, "sm_init().\n");
383 clear_ioapic(IO_APIC_ADDR);
384 /* I/O APIC IDs are normally limited to 4-bits. Enforce this limit. */
385 #if (CONFIG_APIC_ID_OFFSET == 0 && CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS < 16)
386 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
387 setup_ioapic(IO_APIC_ADDR, CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS);
388 #elif (CONFIG_APIC_ID_OFFSET > 0)
389 /* Assign the ioapic ID the value 0. Processor APIC IDs follow. */
390 setup_ioapic(IO_APIC_ADDR, 0);
392 #error "The processor APIC IDs must be lifted to make room for the I/O APIC ID"
396 case (0x14 << 3) | 1: /* 0:14:1 IDE */
399 case (0x14 << 3) | 2: /* 0:14:2 HDA */
401 if (AZALIA_DISABLE == sb_config->AzaliaController) {
402 sb_config->AzaliaController = AZALIA_AUTO;
404 printk(BIOS_DEBUG, "hda enabled\n");
406 sb_config->AzaliaController = AZALIA_DISABLE;
407 printk(BIOS_DEBUG, "hda disabled\n");
412 case (0x14 << 3) | 3: /* 0:14:3 LPC */
415 case (0x14 << 3) | 4: /* 0:14:4 PCI */
418 case (0x14 << 3) | 6: /* 0:14:6 GEC */
420 sb_config->GecConfig = 0;
421 printk(BIOS_DEBUG, "gec enabled\n");
423 sb_config->GecConfig = 1;
424 printk(BIOS_DEBUG, "gec disabled\n");
428 case (0x15 << 3) | 0: /* 0:15:0 PCIe PortA */
431 for (device = dev; device; device = device->next) {
432 if (dev->path.type != DEVICE_PATH_PCI) continue;
433 if ((device->path.pci.devfn & ~7) != PCI_DEVFN(0x15,0)) break;
434 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
438 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
439 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
440 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
441 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
443 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
447 case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */
448 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
450 case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */
451 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
453 case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */
454 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
456 case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */
457 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
459 case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */
460 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
462 case (0x16 << 3) | 0: /* 0:16:0 OHCI-USB3 */
463 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
465 case (0x16 << 3) | 2: /* 0:16:2 EHCI-USB3 */
466 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
468 /* call the CIMX entry at the last sb800 device,
469 * so make sure the mainboard devicetree is complete
471 sb_Before_Pci_Init();
479 struct chip_operations southbridge_amd_cimx_sb800_ops = {
480 CHIP_NAME("ATI SB800")
481 .enable_dev = sb800_enable,