blob: 5b2b2b0452933b0062add7a7722ed9ae46db1b41 [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{
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060027 unsigned int gsi_base = 0x18;
Yinghai Luc34e3ab2006-10-12 00:58:20 +000028
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
Elyes HAOUAS531b87a2016-09-19 09:46:33 -060069 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
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200128unsigned long mainboard_write_acpi_tables(device_t device,
129 unsigned long start,
130 acpi_rsdp_t *rsdp)
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000131{
132 unsigned long current;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000133 acpi_header_t *ssdtx;
Edward O'Callaghanb3b79af2014-12-08 03:43:44 +1100134 const void *p;
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200135 size_t p_size;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000136
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000137 int i;
138
139 get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
140
141 /* Align ACPI tables to 16byte */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200142 start = ALIGN(start, 16);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000143 current = start;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000144
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000145 //same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table
146
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600147 for(i = 1; i < sysconf.hc_possible_num; i++) { // 0: is hc sblink
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200148 const char *file_name;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000149 if((sysconf.pci1234[i] & 1) != 1 ) continue;
150 uint8_t c;
Elyes HAOUAS531b87a2016-09-19 09:46:33 -0600151 if(i < 7) {
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000152 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
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200162 file_name = CONFIG_CBFS_PREFIX "/ssdt2.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000163 break;
164 case 2: //8151
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200165 file_name = CONFIG_CBFS_PREFIX "/ssdt3.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000166 break;
167 case 3: //8131
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200168 file_name = CONFIG_CBFS_PREFIX "/ssdt4.aml";
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000169 break;
170 default:
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000171 //HTX no io apic
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200172 file_name = CONFIG_CBFS_PREFIX "/ssdt5.aml";
Yinghai Lua5fc22f2006-12-20 20:21:05 +0000173 break;
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000174 }
Vladimir Serbinenkoa4cf83d2015-06-02 21:40:29 +0200175 p = cbfs_boot_map_with_leak(
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200176 file_name,
177 CBFS_TYPE_RAW, &p_size);
178 if (!p || p_size < sizeof(acpi_header_t))
179 continue;
180
Myles Watsonae608552010-04-09 03:41:23 +0000181 memcpy(ssdtx, p, sizeof(acpi_header_t));
182 current += ssdtx->length;
183 memcpy(ssdtx, p, ssdtx->length);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000184 update_ssdtx((void *)ssdtx, i);
185 ssdtx->checksum = 0;
186 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000187 acpi_add_table(rsdp,ssdtx);
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000188 }
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000189
Yinghai Luc34e3ab2006-10-12 00:58:20 +0000190 return current;
191}