blob: e1c5c8039baae18655be5abb48f10ddfe49d98d4 [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"
Yinghai Luc34e3ab2006-10-12 00:58:20 +000023
Myles Watsonae608552010-04-09 03:41:23 +000024extern const unsigned char AmlCode_ssdt2[];
25extern const unsigned char AmlCode_ssdt3[];
26extern const unsigned char AmlCode_ssdt4[];
27extern const unsigned char AmlCode_ssdt5[];
Stefan Reinauer2cb70142007-11-04 16:50:27 +000028
Yinghai Luc34e3ab2006-10-12 00:58:20 +000029unsigned long acpi_fill_madt(unsigned long current)
30{
31 unsigned int gsi_base=0x18;
32
33 struct mb_sysconf_t *m;
34
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020035 get_bus_conf();
36
Yinghai Luc34e3ab2006-10-12 00:58:20 +000037 m = sysconf.mb;
Stefan Reinauer14e22772010-04-27 06:56:47 +000038
Yinghai Luc34e3ab2006-10-12 00:58:20 +000039 /* create all subtables for processors */
40 current = acpi_create_madt_lapics(current);
Stefan Reinauer14e22772010-04-27 06:56:47 +000041
Yinghai Luc34e3ab2006-10-12 00:58:20 +000042 /* 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 Reinauer50776fa2010-03-17 04:40:15 +000074 unsigned d = 0;
Yinghai Luc34e3ab2006-10-12 00:58:20 +000075 if(!(sysconf.pci1234[i] & 0x1) ) continue;
76 // 8131 need to use +4
Stefan Reinauer14e22772010-04-27 06:56:47 +000077
Yinghai Luc34e3ab2006-10-12 00:58:20 +000078 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 Reinauer14e22772010-04-27 06:56:47 +0000120 /* 2: APIC 2 */
Kyösti Mälkkid8747572014-06-26 05:30:54 +0300121 /* 5 mean: 0101 --> Edge-triggered, Active high*/
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000122
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 Serbinenko6985d4e2014-09-21 14:31:19 +0200132unsigned long mainboard_write_acpi_tables(unsigned long start, acpi_rsdp_t *rsdp)
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000133{
134 unsigned long current;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000135 acpi_header_t *ssdtx;
Edward O'Callaghanb3b79af2014-12-08 03:43:44 +1100136 const void *p;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000137
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000138 int i;
139
140 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
141
142 /* Align ACPI tables to 16byte */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200143 start = ALIGN(start, 16);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000144 current = start;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000145
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000146 //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 Reinauerc02b4fc2010-03-22 11:42:32 +0000157 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 +0200158 current = ALIGN(current, 8);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000159 ssdtx = (acpi_header_t *)current;
160 switch(sysconf.hcid[i]) {
161 case 1: //8132
Myles Watson565a2812010-03-24 22:02:53 +0000162 p = &AmlCode_ssdt2;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000163 break;
164 case 2: //8151
Myles Watson565a2812010-03-24 22:02:53 +0000165 p = &AmlCode_ssdt3;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000166 break;
167 case 3: //8131
Myles Watson565a2812010-03-24 22:02:53 +0000168 p = &AmlCode_ssdt4;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000169 break;
170 default:
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000171 //HTX no io apic
Myles Watson565a2812010-03-24 22:02:53 +0000172 p = &AmlCode_ssdt5;
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000173 break;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000174 }
Myles Watsonae608552010-04-09 03:41:23 +0000175 memcpy(ssdtx, p, sizeof(acpi_header_t));
176 current += ssdtx->length;
177 memcpy(ssdtx, p, ssdtx->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000178 update_ssdtx((void *)ssdtx, i);
179 ssdtx->checksum = 0;
180 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000181 acpi_add_table(rsdp,ssdtx);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000182 }
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000183
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000184 return current;
185}