Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 1 | /* |
Eric Biederman | 8d9c123 | 2003-06-17 08:42:17 +0000 | [diff] [blame] | 2 | * (C) 2003 Linux Networx, SuSE Linux AG |
Yinghai Lu | eef3f95 | 2006-01-06 01:56:25 +0000 | [diff] [blame] | 3 | * 2006.1 yhlu add dest apicid for IRQ0 |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 4 | */ |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
| 8 | #include <device/pci_ids.h> |
| 9 | #include <device/pci_ops.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 10 | #include <pc80/mc146818rtc.h> |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 11 | #include <pc80/isa-dma.h> |
Yinghai Lu | eef3f95 | 2006-01-06 01:56:25 +0000 | [diff] [blame] | 12 | #include <cpu/x86/lapic.h> |
Stefan Reinauer | 0401bd8 | 2010-01-16 18:31:34 +0000 | [diff] [blame] | 13 | #include <arch/ioapic.h> |
Vladimir Serbinenko | 83f81ca | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 14 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 15 | #include <arch/acpi.h> |
| 16 | #include <arch/acpigen.h> |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 17 | #include <cpu/amd/powernow.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 18 | #endif |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 19 | #include <stdlib.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 20 | #include <string.h> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 21 | #include "amd8111.h" |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 22 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 23 | #define NMI_OFF 0 |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 24 | |
Stefan Reinauer | bd8e17a | 2004-02-05 10:00:35 +0000 | [diff] [blame] | 25 | static void enable_hpet(struct device *dev) |
| 26 | { |
| 27 | unsigned long hpet_address; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 28 | |
Jonathan A. Kollasch | 6f0e8bd | 2015-07-15 13:47:33 -0500 | [diff] [blame] | 29 | pci_write_config32(dev, 0xa0, CONFIG_HPET_ADDRESS|1); |
Yinghai Lu | eef3f95 | 2006-01-06 01:56:25 +0000 | [diff] [blame] | 30 | hpet_address = pci_read_config32(dev,0xa0)& 0xfffffffe; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 31 | printk(BIOS_DEBUG, "enabling HPET @0x%lx\n", hpet_address); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 32 | |
Stefan Reinauer | bd8e17a | 2004-02-05 10:00:35 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 35 | static void lpc_init(struct device *dev) |
| 36 | { |
| 37 | uint8_t byte; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 38 | int nmi_option; |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 39 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 40 | /* IO APIC initialization */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 41 | byte = pci_read_config8(dev, 0x4B); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 42 | byte |= 1; |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 43 | pci_write_config8(dev, 0x4B, byte); |
Stefan Reinauer | 0401bd8 | 2010-01-16 18:31:34 +0000 | [diff] [blame] | 44 | /* Don't rename IO APIC */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 45 | setup_ioapic(VIO_APIC_VADDR, 0); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 46 | |
| 47 | /* posted memory write enable */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 48 | byte = pci_read_config8(dev, 0x46); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 49 | pci_write_config8(dev, 0x46, byte | (1<<0)); |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 50 | |
Jason Schildt | c9c4dd6 | 2005-10-25 21:04:09 +0000 | [diff] [blame] | 51 | /* Enable 5Mib Rom window */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 52 | byte = pci_read_config8(dev, 0x43); |
Yinghai Lu | eef3f95 | 2006-01-06 01:56:25 +0000 | [diff] [blame] | 53 | byte |= 0xc0; |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 54 | pci_write_config8(dev, 0x43, byte); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 55 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 56 | /* Enable Port 92 fast reset */ |
| 57 | byte = pci_read_config8(dev, 0x41); |
| 58 | byte |= (1 << 5); |
| 59 | pci_write_config8(dev, 0x41, byte); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 60 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 61 | /* Enable Error reporting */ |
| 62 | /* Set up sync flood detected */ |
| 63 | byte = pci_read_config8(dev, 0x47); |
| 64 | byte |= (1 << 1); |
| 65 | pci_write_config8(dev, 0x47, byte); |
| 66 | |
| 67 | /* Set up NMI on errors */ |
| 68 | byte = pci_read_config8(dev, 0x40); |
| 69 | byte |= (1 << 1); /* clear PW2LPC error */ |
| 70 | byte |= (1 << 6); /* clear LPCERR */ |
| 71 | pci_write_config8(dev, 0x40, byte); |
| 72 | nmi_option = NMI_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 73 | get_option(&nmi_option, "nmi"); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 74 | if (nmi_option) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 75 | byte |= (1 << 7); /* set NMI */ |
| 76 | pci_write_config8(dev, 0x40, byte); |
| 77 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 78 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 79 | /* Initialize the real time clock */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 80 | cmos_init(0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 81 | |
| 82 | /* Initialize isa dma */ |
| 83 | isa_dma_init(); |
| 84 | |
| 85 | /* Initialize the High Precision Event Timers */ |
Stefan Reinauer | bd8e17a | 2004-02-05 10:00:35 +0000 | [diff] [blame] | 86 | enable_hpet(dev); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 89 | static void amd8111_lpc_read_resources(device_t dev) |
| 90 | { |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 91 | struct resource *res; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 92 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 93 | /* Get the normal PCI resources of this device. */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 94 | pci_dev_read_resources(dev); |
| 95 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 96 | /* Add an extra subtractive resource for both memory and I/O. */ |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 97 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 98 | res->base = 0; |
| 99 | res->size = 0x1000; |
| 100 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 101 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 102 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 103 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 104 | res->base = 0xff800000; |
| 105 | res->size = 0x00800000; /* 8 MB for flash */ |
| 106 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 107 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 108 | |
| 109 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 110 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 111 | res->size = 0x00001000; |
| 112 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 115 | static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 116 | { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 117 | pci_write_config32(dev, 0x70, |
Yinghai Lu | 9a791df | 2006-04-03 20:38:34 +0000 | [diff] [blame] | 118 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 119 | } |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 120 | |
Vladimir Serbinenko | 83f81ca | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 121 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 122 | |
| 123 | extern u16 pm_base; |
| 124 | |
| 125 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 126 | { |
| 127 | /* Just a dummy */ |
| 128 | return current; |
| 129 | } |
| 130 | |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 131 | static void southbridge_acpi_fill_ssdt_generator(device_t device) { |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 132 | #if CONFIG_SET_FIDVID |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 133 | amd_generate_powernow(pm_base + 0x10, 6, 1); |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 134 | acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS"); |
| 135 | #endif |
| 136 | } |
| 137 | |
| 138 | #endif |
| 139 | |
| 140 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 141 | static struct pci_operations lops_pci = { |
| 142 | .set_subsystem = lpci_set_subsystem, |
| 143 | }; |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 144 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 145 | static struct device_operations lpc_ops = { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 146 | .read_resources = amd8111_lpc_read_resources, |
| 147 | .set_resources = pci_dev_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 148 | .enable_resources = pci_dev_enable_resources, |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 149 | .init = lpc_init, |
Vladimir Serbinenko | 83f81ca | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 150 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 151 | .write_acpi_tables = acpi_write_hpet, |
| 152 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
| 153 | #endif |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 154 | .scan_bus = scan_lpc_bus, |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 155 | .enable = amd8111_enable, |
| 156 | .ops_pci = &lops_pci, |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 159 | static const struct pci_driver lpc_driver __pci_driver = { |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 160 | .ops = &lpc_ops, |
| 161 | .vendor = PCI_VENDOR_ID_AMD, |
| 162 | .device = PCI_DEVICE_ID_AMD_8111_ISA, |
| 163 | }; |