Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Island Aruma ACPI support |
| 3 | * written by Stefan Reinauer <stepan@openbios.org> |
| 4 | * (C) 2005 Stefan Reinauer |
| 5 | * |
| 6 | * |
| 7 | * Copyright 2005 AMD |
| 8 | * 2005.9 yhlu modify that to more dynamic for AMD Opteron Based MB |
| 9 | */ |
| 10 | |
| 11 | #include <console/console.h> |
| 12 | #include <string.h> |
| 13 | #include <arch/acpi.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 14 | #include <arch/ioapic.h> |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 15 | #include <device/pci.h> |
| 16 | #include <device/pci_ids.h> |
| 17 | #include <cpu/x86/msr.h> |
| 18 | #include <cpu/amd/mtrr.h> |
| 19 | #include <cpu/amd/amdk8_sysconf.h> |
stepan | 8301d83 | 2010-12-08 07:07:33 +0000 | [diff] [blame] | 20 | #include "northbridge/amd/amdk8/acpi.h" |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 21 | #include "mb_sysconf.h" |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 22 | #include "mainboard.h" |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 23 | |
Myles Watson | ae60855 | 2010-04-09 03:41:23 +0000 | [diff] [blame] | 24 | extern const unsigned char AmlCode_ssdt2[]; |
| 25 | extern const unsigned char AmlCode_ssdt3[]; |
| 26 | extern const unsigned char AmlCode_ssdt4[]; |
| 27 | extern const unsigned char AmlCode_ssdt5[]; |
Stefan Reinauer | 2cb7014 | 2007-11-04 16:50:27 +0000 | [diff] [blame] | 28 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 29 | unsigned long acpi_fill_madt(unsigned long current) |
| 30 | { |
| 31 | unsigned int gsi_base=0x18; |
| 32 | |
| 33 | struct mb_sysconf_t *m; |
| 34 | |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 35 | get_bus_conf(); |
| 36 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 37 | m = sysconf.mb; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 38 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 39 | /* create all subtables for processors */ |
| 40 | current = acpi_create_madt_lapics(current); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 41 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 42 | /* Write 8111 IOAPIC */ |
| 43 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8111, |
| 44 | IO_APIC_ADDR, 0); |
| 45 | |
| 46 | /* Write all 8131 IOAPICs */ |
| 47 | { |
| 48 | device_t dev; |
| 49 | struct resource *res; |
| 50 | dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0]&0xff), 1)); |
| 51 | if (dev) { |
| 52 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 53 | if (res) { |
| 54 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_1, |
| 55 | res->base, gsi_base ); |
| 56 | gsi_base+=4; |
| 57 | |
| 58 | } |
| 59 | } |
| 60 | dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN((sysconf.hcdn[0] & 0xff)+1, 1)); |
| 61 | if (dev) { |
| 62 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 63 | if (res) { |
| 64 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132_2, |
| 65 | res->base, gsi_base ); |
| 66 | gsi_base+=4; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | int i; |
| 71 | int j = 0; |
| 72 | |
| 73 | for(i=1; i< sysconf.hc_possible_num; i++) { |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 74 | unsigned d = 0; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 75 | if(!(sysconf.pci1234[i] & 0x1) ) continue; |
| 76 | // 8131 need to use +4 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 77 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 78 | switch (sysconf.hcid[i]) { |
| 79 | case 1: |
| 80 | d = 7; |
| 81 | break; |
| 82 | case 3: |
| 83 | d = 4; |
| 84 | break; |
| 85 | } |
| 86 | switch (sysconf.hcid[i]) { |
| 87 | case 1: |
| 88 | case 3: |
| 89 | dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j], 1)); |
| 90 | if (dev) { |
| 91 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 92 | if (res) { |
| 93 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][0], |
| 94 | res->base, gsi_base ); |
| 95 | gsi_base+=d; |
| 96 | } |
| 97 | } |
| 98 | dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1, 1)); |
| 99 | if (dev) { |
| 100 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 101 | if (res) { |
| 102 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, m->apicid_8132a[j][1], |
| 103 | res->base, gsi_base ); |
| 104 | gsi_base+=d; |
| 105 | |
| 106 | } |
| 107 | } |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | j++; |
| 112 | } |
| 113 | |
| 114 | } |
| 115 | |
| 116 | current += acpi_create_madt_irqoverride( (acpi_madt_irqoverride_t *) |
| 117 | current, 0, 0, 2, 5 ); |
| 118 | /* 0: mean bus 0--->ISA */ |
| 119 | /* 0: PIC 0 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 120 | /* 2: APIC 2 */ |
Kyösti Mälkki | d874757 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 121 | /* 5 mean: 0101 --> Edge-triggered, Active high*/ |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 122 | |
| 123 | |
| 124 | /* create all subtables for processors */ |
| 125 | current = acpi_create_madt_lapic_nmis(current, 5, 1); |
| 126 | /* 1: LINT1 connect to NMI */ |
| 127 | |
| 128 | |
| 129 | return current; |
| 130 | } |
| 131 | |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 132 | unsigned long mainboard_write_acpi_tables(unsigned long start, acpi_rsdp_t *rsdp) |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 133 | { |
| 134 | unsigned long current; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 135 | acpi_header_t *ssdtx; |
Edward O'Callaghan | b3b79af | 2014-12-08 03:43:44 +1100 | [diff] [blame^] | 136 | const void *p; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 137 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 138 | int i; |
| 139 | |
| 140 | get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn |
| 141 | |
| 142 | /* Align ACPI tables to 16byte */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 143 | start = ALIGN(start, 16); |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 144 | current = start; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 145 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 146 | //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table |
| 147 | |
| 148 | for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink |
| 149 | if((sysconf.pci1234[i] & 1) != 1 ) continue; |
| 150 | uint8_t c; |
| 151 | if(i<7) { |
| 152 | c = (uint8_t) ('4' + i - 1); |
| 153 | } |
| 154 | else { |
| 155 | c = (uint8_t) ('A' + i - 1 - 6); |
| 156 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 157 | printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 158 | current = ALIGN(current, 8); |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 159 | ssdtx = (acpi_header_t *)current; |
| 160 | switch(sysconf.hcid[i]) { |
| 161 | case 1: //8132 |
Myles Watson | 565a281 | 2010-03-24 22:02:53 +0000 | [diff] [blame] | 162 | p = &AmlCode_ssdt2; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 163 | break; |
| 164 | case 2: //8151 |
Myles Watson | 565a281 | 2010-03-24 22:02:53 +0000 | [diff] [blame] | 165 | p = &AmlCode_ssdt3; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 166 | break; |
| 167 | case 3: //8131 |
Myles Watson | 565a281 | 2010-03-24 22:02:53 +0000 | [diff] [blame] | 168 | p = &AmlCode_ssdt4; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 169 | break; |
| 170 | default: |
Yinghai Lu | a5fc22f | 2006-12-20 20:21:05 +0000 | [diff] [blame] | 171 | //HTX no io apic |
Myles Watson | 565a281 | 2010-03-24 22:02:53 +0000 | [diff] [blame] | 172 | p = &AmlCode_ssdt5; |
Yinghai Lu | a5fc22f | 2006-12-20 20:21:05 +0000 | [diff] [blame] | 173 | break; |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 174 | } |
Myles Watson | ae60855 | 2010-04-09 03:41:23 +0000 | [diff] [blame] | 175 | memcpy(ssdtx, p, sizeof(acpi_header_t)); |
| 176 | current += ssdtx->length; |
| 177 | memcpy(ssdtx, p, ssdtx->length); |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 178 | update_ssdtx((void *)ssdtx, i); |
| 179 | ssdtx->checksum = 0; |
| 180 | ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 181 | acpi_add_table(rsdp,ssdtx); |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 182 | } |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 183 | |
Yinghai Lu | c34e3ab | 2006-10-12 00:58:20 +0000 | [diff] [blame] | 184 | return current; |
| 185 | } |