blob: 834d1fe0c712ca7227c84f6f708334bb73abdce6 [file] [log] [blame]
Yinghai Luc34e3ab2006-10-12 00:58:20 +00001/*
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 Hermann74d1a6e2010-10-12 17:34:08 +000014#include <arch/ioapic.h>
Yinghai Luc34e3ab2006-10-12 00:58:20 +000015#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>
stepan8301d832010-12-08 07:07:33 +000020#include "northbridge/amd/amdk8/acpi.h"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000021#include "mb_sysconf.h"
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020022#include "mainboard.h"
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +020023#include <cbfs.h>
Stefan Reinauer2cb70142007-11-04 16:50:27 +000024
Yinghai Luc34e3ab2006-10-12 00:58:20 +000025unsigned long acpi_fill_madt(unsigned long current)
26{
27 unsigned int gsi_base=0x18;
28
29 struct mb_sysconf_t *m;
30
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020031 get_bus_conf();
32
Yinghai Luc34e3ab2006-10-12 00:58:20 +000033 m = sysconf.mb;
Stefan Reinauer14e22772010-04-27 06:56:47 +000034
Yinghai Luc34e3ab2006-10-12 00:58:20 +000035 /* create all subtables for processors */
36 current = acpi_create_madt_lapics(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +000037
Yinghai Luc34e3ab2006-10-12 00:58:20 +000038 /* 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 Reinauer50776fa2010-03-17 04:40:15 +000070 unsigned d = 0;
Yinghai Luc34e3ab2006-10-12 00:58:20 +000071 if(!(sysconf.pci1234[i] & 0x1) ) continue;
72 // 8131 need to use +4
Stefan Reinauer14e22772010-04-27 06:56:47 +000073
Yinghai Luc34e3ab2006-10-12 00:58:20 +000074 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 Reinauer14e22772010-04-27 06:56:47 +0000116 /* 2: APIC 2 */
Kyösti Mälkkid8747572014-06-26 05:30:54 +0300117 /* 5 mean: 0101 --> Edge-triggered, Active high*/
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000118
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 Serbinenko6985d4e2014-09-21 14:31:19 +0200128unsigned long mainboard_write_acpi_tables(unsigned long start, acpi_rsdp_t *rsdp)
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000129{
130 unsigned long current;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000131 acpi_header_t *ssdtx;
Edward O'Callaghanb3b79af2014-12-08 03:43:44 +1100132 const void *p;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200133 size_t p_size;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000134
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000135 int i;
136
137 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
138
139 /* Align ACPI tables to 16byte */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200140 start = ALIGN(start, 16);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000141 current = start;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000142
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000143 //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 Serbinenko36f8d272015-05-31 12:31:59 +0200146 const char *file_name;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000147 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 Reinauerc02b4fc2010-03-22 11:42:32 +0000155 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c Aka hcid = %d\n", c, sysconf.hcid[i]); //pci0 and pci1 are in dsdt
Patrick Georgi26b00e62012-04-20 19:19:47 +0200156 current = ALIGN(current, 8);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000157 ssdtx = (acpi_header_t *)current;
158 switch(sysconf.hcid[i]) {
159 case 1: //8132
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200160 file_name = CONFIG_CBFS_PREFIX "/ssdt2.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000161 break;
162 case 2: //8151
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200163 file_name = CONFIG_CBFS_PREFIX "/ssdt3.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000164 break;
165 case 3: //8131
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200166 file_name = CONFIG_CBFS_PREFIX "/ssdt4.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000167 break;
168 default:
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000169 //HTX no io apic
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200170 file_name = CONFIG_CBFS_PREFIX "/ssdt5.aml";
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000171 break;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000172 }
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200173 p = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
174 file_name,
175 CBFS_TYPE_RAW, &p_size);
176 if (!p || p_size < sizeof(acpi_header_t))
177 continue;
178
Myles Watsonae608552010-04-09 03:41:23 +0000179 memcpy(ssdtx, p, sizeof(acpi_header_t));
180 current += ssdtx->length;
181 memcpy(ssdtx, p, ssdtx->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000182 update_ssdtx((void *)ssdtx, i);
183 ssdtx->checksum = 0;
184 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000185 acpi_add_table(rsdp,ssdtx);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000186 }
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000187
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000188 return current;
189}