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