2005-11-26 17:56:05 +01:00
|
|
|
/*
|
2010-06-04 09:49:53 +02:00
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright (C) 2010 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2013-02-23 18:37:27 +01:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-11-26 17:56:05 +01:00
|
|
|
*/
|
|
|
|
|
2010-06-04 09:49:53 +02:00
|
|
|
/*
|
|
|
|
* Description: Add madt lapic creat dynamically and SRAT related by yhlu
|
|
|
|
*/
|
|
|
|
|
2005-11-26 17:56:05 +01:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <arch/acpi.h>
|
2009-03-01 19:05:25 +01:00
|
|
|
#include <arch/acpigen.h>
|
2005-11-26 17:56:05 +01:00
|
|
|
#include <device/pci.h>
|
|
|
|
#include <cpu/x86/msr.h>
|
|
|
|
#include <cpu/amd/mtrr.h>
|
2006-10-04 22:46:15 +02:00
|
|
|
#include <cpu/amd/amdk8_sysconf.h>
|
2010-12-08 08:07:33 +01:00
|
|
|
#include "acpi.h"
|
2005-11-26 17:56:05 +01:00
|
|
|
|
2010-12-11 21:33:41 +01:00
|
|
|
//it seems some functions can be moved arch/x86/boot/acpi.c
|
2005-11-26 17:56:05 +01:00
|
|
|
|
|
|
|
unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags, u8 lint)
|
|
|
|
{
|
2008-10-02 21:20:22 +02:00
|
|
|
device_t cpu;
|
|
|
|
int cpu_index = 0;
|
|
|
|
|
|
|
|
for(cpu = all_devices; cpu; cpu = cpu->next) {
|
|
|
|
if ((cpu->path.type != DEVICE_PATH_APIC) ||
|
2013-02-13 00:20:54 +01:00
|
|
|
(cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
|
2008-10-02 21:20:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!cpu->enabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, cpu_index, flags, lint);
|
|
|
|
cpu_index++;
|
|
|
|
}
|
|
|
|
return current;
|
2005-11-26 17:56:05 +01:00
|
|
|
}
|
2008-10-02 21:20:22 +02:00
|
|
|
|
2005-11-26 17:56:05 +01:00
|
|
|
unsigned long acpi_create_srat_lapics(unsigned long current)
|
|
|
|
{
|
2008-10-02 21:20:22 +02:00
|
|
|
device_t cpu;
|
|
|
|
int cpu_index = 0;
|
|
|
|
|
|
|
|
for(cpu = all_devices; cpu; cpu = cpu->next) {
|
|
|
|
if ((cpu->path.type != DEVICE_PATH_APIC) ||
|
2013-02-13 00:20:54 +01:00
|
|
|
(cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
|
2008-10-02 21:20:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!cpu->enabled) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "SRAT: lapic cpu_index=%02x, node_id=%02x, apic_id=%02x\n", cpu_index, cpu->path.apic.node_id, cpu->path.apic.apic_id);
|
2009-02-28 21:10:20 +01:00
|
|
|
current += acpi_create_srat_lapic((acpi_srat_lapic_t *)current, cpu->path.apic.node_id, cpu->path.apic.apic_id);
|
2008-10-02 21:20:22 +02:00
|
|
|
cpu_index++;
|
|
|
|
}
|
|
|
|
return current;
|
|
|
|
}
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2005-11-26 17:56:05 +01:00
|
|
|
static unsigned long resk(uint64_t value)
|
|
|
|
{
|
2008-10-02 21:20:22 +02:00
|
|
|
unsigned long resultk;
|
|
|
|
if (value < (1ULL << 42)) {
|
|
|
|
resultk = value >> 10;
|
2009-01-30 03:05:20 +01:00
|
|
|
} else {
|
2008-10-02 21:20:22 +02:00
|
|
|
resultk = 0xffffffff;
|
|
|
|
}
|
|
|
|
return resultk;
|
2005-11-26 17:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_srat_mem_state {
|
2008-10-02 21:20:22 +02:00
|
|
|
unsigned long current;
|
2005-11-26 17:56:05 +01:00
|
|
|
};
|
|
|
|
|
2009-10-30 03:08:07 +01:00
|
|
|
static void set_srat_mem(void *gp, struct device *dev, struct resource *res)
|
2005-11-26 17:56:05 +01:00
|
|
|
{
|
2008-10-02 21:20:22 +02:00
|
|
|
struct acpi_srat_mem_state *state = gp;
|
|
|
|
unsigned long basek, sizek;
|
|
|
|
basek = resk(res->base);
|
|
|
|
sizek = resk(res->size);
|
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "set_srat_mem: dev %s, res->index=%04lx startk=%08lx, sizek=%08lx\n",
|
2008-10-02 21:20:22 +02:00
|
|
|
dev_path(dev), res->index, basek, sizek);
|
|
|
|
/*
|
2009-01-30 03:05:20 +01:00
|
|
|
* 0-640K must be on node 0
|
|
|
|
* next range is from 1M---
|
|
|
|
* So will cut off before 1M in the mem range
|
|
|
|
*/
|
2008-10-02 21:20:22 +02:00
|
|
|
if((basek+sizek)<1024) return;
|
|
|
|
|
|
|
|
if(basek<1024) {
|
|
|
|
sizek -= 1024 - basek;
|
|
|
|
basek = 1024;
|
|
|
|
}
|
|
|
|
|
2009-01-30 03:05:20 +01:00
|
|
|
// need to figure out NV
|
|
|
|
state->current += acpi_create_srat_mem((acpi_srat_mem_t *)state->current, (res->index & 0xf), basek, sizek, 1);
|
2005-11-26 17:56:05 +01:00
|
|
|
}
|
|
|
|
|
2014-10-11 23:45:40 +02:00
|
|
|
static unsigned long acpi_fill_srat(unsigned long current)
|
2005-11-26 17:56:05 +01:00
|
|
|
{
|
2008-10-02 21:20:22 +02:00
|
|
|
struct acpi_srat_mem_state srat_mem_state;
|
2005-11-26 17:56:05 +01:00
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
/* create all subtables for processors */
|
|
|
|
current = acpi_create_srat_lapics(current);
|
2005-11-26 17:56:05 +01:00
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
/* create all subteble for memory range */
|
2005-11-26 17:56:05 +01:00
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
/* 0-640K must be on node 0 */
|
|
|
|
current += acpi_create_srat_mem((acpi_srat_mem_t *)current, 0, 0, 640, 1);//enable
|
2005-11-26 17:56:05 +01:00
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
srat_mem_state.current = current;
|
|
|
|
search_global_resources(
|
|
|
|
IORESOURCE_MEM | IORESOURCE_CACHEABLE, IORESOURCE_MEM | IORESOURCE_CACHEABLE,
|
|
|
|
set_srat_mem, &srat_mem_state);
|
|
|
|
|
|
|
|
current = srat_mem_state.current;
|
|
|
|
return current;
|
2005-11-26 17:56:05 +01:00
|
|
|
}
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2014-10-11 23:45:40 +02:00
|
|
|
static unsigned long acpi_fill_slit(unsigned long current)
|
2006-10-04 22:46:15 +02:00
|
|
|
{
|
|
|
|
/* need to find out the node num at first */
|
|
|
|
/* fill the first 8 byte with that num */
|
|
|
|
/* fill the next num*num byte with distance, local is 10, 1 hop mean 20, and 2 hop with 30.... */
|
2008-10-02 21:20:22 +02:00
|
|
|
|
2006-10-04 22:46:15 +02:00
|
|
|
/* because We has assume that we know the topology of the HT connection, So we can have set if we know the node_num */
|
2009-01-30 03:05:20 +01:00
|
|
|
static u8 hops_8[] = { 0, 1, 1, 2, 2, 3, 3, 4,
|
2006-10-04 22:46:15 +02:00
|
|
|
1, 0, 2, 1, 3, 2, 4, 3,
|
|
|
|
1, 2, 0, 1, 1, 2, 2, 3,
|
|
|
|
2, 1, 1, 0, 2, 1, 3, 2,
|
|
|
|
2, 3, 1, 2, 0, 1, 1, 2,
|
|
|
|
3, 2, 2, 1, 1, 0, 2, 1,
|
2008-10-02 21:20:22 +02:00
|
|
|
3, 4, 2, 3, 1, 2, 0, 1,
|
2006-10-04 22:46:15 +02:00
|
|
|
4, 4, 3, 2, 2, 1, 1, 0 };
|
|
|
|
|
2009-01-30 03:05:20 +01:00
|
|
|
// u8 outer_node[8];
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2009-01-30 03:05:20 +01:00
|
|
|
u8 *p = (u8 *)current;
|
2006-10-04 22:46:15 +02:00
|
|
|
int nodes = sysconf.nodes;
|
|
|
|
int i,j;
|
|
|
|
memset(p, 0, 8+nodes*nodes);
|
2009-01-30 03:05:20 +01:00
|
|
|
// memset((u8 *)outer_node, 0, 8);
|
|
|
|
*p = (u8) nodes;
|
2006-10-04 22:46:15 +02:00
|
|
|
p += 8;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
for(i=0;i<sysconf.hc_possible_num;i++) {
|
|
|
|
if((sysconf.pci1234[i]&1) !=1 ) continue;
|
2008-10-02 21:20:22 +02:00
|
|
|
outer_node[(sysconf.pci1234[i] >> 4) & 0xf] = 1; // mark the outer node
|
2006-10-04 22:46:15 +02:00
|
|
|
}
|
|
|
|
#endif
|
2008-10-02 21:20:22 +02:00
|
|
|
|
2006-10-04 22:46:15 +02:00
|
|
|
for(i=0;i<nodes;i++) {
|
|
|
|
for(j=0;j<nodes; j++) {
|
2009-01-30 03:05:20 +01:00
|
|
|
if(i==j) {
|
|
|
|
p[i*nodes+j] = 10;
|
|
|
|
} else {
|
2006-10-04 22:46:15 +02:00
|
|
|
#if 0
|
|
|
|
int k;
|
2009-01-30 03:05:20 +01:00
|
|
|
u8 latency_factor = 0;
|
2006-10-04 22:46:15 +02:00
|
|
|
int k_start, k_end;
|
|
|
|
if(i<j) {
|
|
|
|
k_start = i;
|
|
|
|
k_end = j;
|
|
|
|
} else {
|
|
|
|
k_start = j;
|
|
|
|
k_end = i;
|
|
|
|
}
|
|
|
|
for(k=k_start;k<=k_end; k++) {
|
|
|
|
if(outer_node[k]) {
|
|
|
|
latency_factor = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p[i*nodes+j] = hops_8[i*nodes+j] * 2 + latency_factor + 10;
|
2008-10-02 21:20:22 +02:00
|
|
|
#else
|
2006-10-04 22:46:15 +02:00
|
|
|
p[i*nodes+j] = hops_8[i*nodes+j] * 2 + 10;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
current += 8+nodes*nodes;
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2008-10-02 21:20:22 +02:00
|
|
|
return current;
|
2006-10-04 22:46:15 +02:00
|
|
|
}
|
|
|
|
|
2014-10-11 23:45:40 +02:00
|
|
|
unsigned long northbridge_write_acpi_tables(unsigned long start, acpi_rsdp_t *rsdp)
|
|
|
|
{
|
|
|
|
unsigned long current;
|
|
|
|
acpi_srat_t *srat;
|
|
|
|
acpi_slit_t *slit;
|
|
|
|
|
|
|
|
current = start;
|
|
|
|
|
|
|
|
/* Fills sysconf structure needed for SRAT and SLIT. */
|
|
|
|
get_bus_conf();
|
|
|
|
|
|
|
|
current = ALIGN(current, 16);
|
|
|
|
srat = (acpi_srat_t *) current;
|
|
|
|
printk(BIOS_DEBUG, "ACPI: * SRAT @ %p\n", srat);
|
|
|
|
acpi_create_srat(srat, acpi_fill_srat);
|
|
|
|
current += srat->header.length;
|
|
|
|
acpi_add_table(rsdp, srat);
|
|
|
|
|
|
|
|
/* SLIT */
|
|
|
|
current = ALIGN(current, 16);
|
|
|
|
slit = (acpi_slit_t *) current;
|
|
|
|
printk(BIOS_DEBUG, "ACPI: * SLIT @ %p\n", slit);
|
|
|
|
acpi_create_slit(slit, acpi_fill_slit);
|
|
|
|
current+=slit->header.length;
|
|
|
|
acpi_add_table(rsdp,slit);
|
|
|
|
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
static void k8acpi_write_HT(void) {
|
|
|
|
int i;
|
2009-02-01 19:35:15 +01:00
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name("HCLK");
|
|
|
|
acpigen_write_package(HC_POSSIBLE_NUM);
|
2009-02-01 19:35:15 +01:00
|
|
|
|
|
|
|
for(i=0;i<sysconf.hc_possible_num;i++) {
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_dword(sysconf.pci1234[i]);
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
for(i=sysconf.hc_possible_num; i<HC_POSSIBLE_NUM; i++) { // in case we set array size to other than 8
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_dword(0x0);
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_pop_len();
|
2009-02-01 19:35:15 +01:00
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name("HCDN");
|
|
|
|
acpigen_write_package(HC_POSSIBLE_NUM);
|
2009-02-01 19:35:15 +01:00
|
|
|
|
|
|
|
for(i=0;i<sysconf.hc_possible_num;i++) {
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_dword(sysconf.hcdn[i]);
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
for(i=sysconf.hc_possible_num; i<HC_POSSIBLE_NUM; i++) { // in case we set array size to other than 8
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_dword(0x20202020);
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_pop_len();
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
static void k8acpi_write_pci_data(int dlen, const char *name, int offset) {
|
2009-02-01 19:35:15 +01:00
|
|
|
device_t dev;
|
|
|
|
uint32_t dword;
|
2014-11-04 21:18:25 +01:00
|
|
|
int i;
|
2009-02-01 19:35:15 +01:00
|
|
|
|
|
|
|
dev = dev_find_slot(0, PCI_DEVFN(0x18, 1));
|
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name(name);
|
|
|
|
acpigen_write_package(dlen);
|
2009-02-01 19:35:15 +01:00
|
|
|
for(i=0; i<dlen; i++) {
|
|
|
|
dword = pci_read_config32(dev, offset+i*4);
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_dword(dword);
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
// minus the opcode
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_pop_len();
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
|
|
|
|
2014-09-21 14:31:19 +02:00
|
|
|
void k8acpi_write_vars(void)
|
2009-02-01 19:35:15 +01:00
|
|
|
{
|
|
|
|
msr_t msr;
|
2009-06-21 22:26:13 +02:00
|
|
|
char pscope[] = "\\_SB.PCI0";
|
2009-02-01 19:35:15 +01:00
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_scope(pscope);
|
|
|
|
k8acpi_write_pci_data(4, "BUSN", 0xe0);
|
|
|
|
k8acpi_write_pci_data(8, "PCIO", 0xc0);
|
|
|
|
k8acpi_write_pci_data(16, "MMIO", 0x80);
|
|
|
|
acpigen_write_name_byte("SBLK", sysconf.sblk);
|
|
|
|
acpigen_write_name_byte("CBST",
|
2009-02-01 19:35:15 +01:00
|
|
|
((sysconf.pci1234[0] >> 12) & 0xff) ? 0xf : 0x0);
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name_dword("SBDN", sysconf.sbdn);
|
2009-02-01 19:35:15 +01:00
|
|
|
msr = rdmsr(TOP_MEM);
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name_dword("TOM1", msr.lo);
|
2009-02-17 22:38:51 +01:00
|
|
|
msr = rdmsr(TOP_MEM2);
|
2010-11-17 12:02:05 +01:00
|
|
|
/*
|
|
|
|
* Since XP only implements parts of ACPI 2.0, we can't use a qword
|
|
|
|
* here.
|
|
|
|
* See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
|
|
|
|
* slide 22ff.
|
|
|
|
* Shift value right by 20 bit to make it fit into 32bit,
|
|
|
|
* giving us 1MB granularity and a limit of almost 4Exabyte of memory.
|
|
|
|
*/
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
|
2009-02-01 19:35:15 +01:00
|
|
|
|
2014-11-04 21:18:25 +01:00
|
|
|
k8acpi_write_HT();
|
2009-02-01 19:35:15 +01:00
|
|
|
//minus opcode
|
2014-11-04 21:18:25 +01:00
|
|
|
acpigen_pop_len();
|
2009-02-01 19:35:15 +01:00
|
|
|
}
|
2010-04-14 18:50:16 +02:00
|
|
|
|
|
|
|
void update_ssdtx(void *ssdtx, int i)
|
|
|
|
{
|
|
|
|
u8 *PCI;
|
|
|
|
u8 *HCIN;
|
|
|
|
u8 *UID;
|
|
|
|
|
|
|
|
PCI = ssdtx + 0x32;
|
|
|
|
HCIN = ssdtx + 0x39;
|
|
|
|
UID = ssdtx + 0x40;
|
|
|
|
|
|
|
|
if (i < 7) {
|
|
|
|
*PCI = (u8) ('4' + i - 1);
|
|
|
|
} else {
|
|
|
|
*PCI = (u8) ('A' + i - 1 - 6);
|
|
|
|
}
|
|
|
|
*HCIN = (u8) i;
|
|
|
|
*UID = (u8) (i + 3);
|
|
|
|
|
|
|
|
/* FIXME: need to update the GSI id in the ssdtx too */
|
|
|
|
|
|
|
|
}
|