2010-12-18 08:48:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2009 coresystems GmbH
|
|
|
|
*
|
|
|
|
* 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <arch/io.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-02-27 23:45:20 +01:00
|
|
|
#include <cbmem.h>
|
2010-12-18 08:48:43 +01:00
|
|
|
#include <cpu/cpu.h>
|
2011-10-15 00:18:29 +02:00
|
|
|
#include <arch/acpi.h>
|
2010-12-18 08:48:43 +01:00
|
|
|
#include "sch.h"
|
|
|
|
|
2016-12-02 07:56:05 +01:00
|
|
|
static int get_pcie_bar(u32 *base)
|
2010-12-18 08:48:43 +01:00
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
u32 pciexbar_reg;
|
|
|
|
|
|
|
|
dev = dev_find_slot(0, PCI_DEVFN(0, 0));
|
|
|
|
if (!dev)
|
|
|
|
return 0;
|
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/* FIXME: Determine at runtime. */
|
2010-12-18 08:48:43 +01:00
|
|
|
#ifdef POULSBO_PRE_B1
|
2010-12-18 14:22:37 +01:00
|
|
|
pciexbar_reg = sch_port_access_read(0, 0, 4);
|
2010-12-18 08:48:43 +01:00
|
|
|
#else
|
2010-12-18 14:22:37 +01:00
|
|
|
pciexbar_reg = sch_port_access_read(2, 9, 4);
|
2010-12-18 08:48:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!(pciexbar_reg & (1 << 0)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch ((pciexbar_reg >> 1) & 3) {
|
2010-12-18 14:22:37 +01:00
|
|
|
case 0: /* 256MB */
|
|
|
|
*base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
|
|
|
|
(1 << 28));
|
2016-12-02 07:56:05 +01:00
|
|
|
return 256;
|
2010-12-18 14:22:37 +01:00
|
|
|
case 1: /* 128M */
|
|
|
|
*base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
|
|
|
|
(1 << 28) | (1 << 27));
|
2016-12-02 07:56:05 +01:00
|
|
|
return 128;
|
2010-12-18 14:22:37 +01:00
|
|
|
case 2: /* 64M */
|
|
|
|
*base = pciexbar_reg & ((1 << 31) | (1 << 30) | (1 << 29) |
|
|
|
|
(1 << 28) | (1 << 27) | (1 << 26));
|
2016-12-02 07:56:05 +01:00
|
|
|
return 64;
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_fixed_resources(struct device *dev, int index)
|
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "Adding CMC shadow area\n");
|
2012-07-18 09:05:01 +02:00
|
|
|
resource = new_resource(dev, index++);
|
2010-12-18 08:48:43 +01:00
|
|
|
resource->base = (resource_t) CMC_SHADOW;
|
|
|
|
resource->size = (resource_t) (64 * 1024);
|
|
|
|
resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
|
|
|
|
IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pci_domain_set_resources(device_t dev)
|
|
|
|
{
|
2010-12-18 14:22:37 +01:00
|
|
|
u32 pci_tolm;
|
|
|
|
u8 reg8;
|
|
|
|
u16 reg16;
|
2012-07-27 07:42:20 +02:00
|
|
|
unsigned long long tomk, tolud, tomk_stolen;
|
2013-10-18 10:02:46 +02:00
|
|
|
uint64_t uma_memory_base = 0, uma_memory_size = 0;
|
2012-07-27 07:42:20 +02:00
|
|
|
uint64_t tseg_memory_base = 0, tseg_memory_size = 0;
|
2010-12-18 14:22:37 +01:00
|
|
|
|
|
|
|
/* Can we find out how much memory we can use at most this way? */
|
2010-12-18 08:48:43 +01:00
|
|
|
pci_tolm = find_pci_tolm(dev->link_list);
|
|
|
|
printk(BIOS_DEBUG, "pci_tolm: 0x%x\n", pci_tolm);
|
|
|
|
printk(BIOS_SPEW, "Base of stolen memory: 0x%08x\n",
|
2010-12-18 14:22:37 +01:00
|
|
|
pci_read_config32(dev_find_slot(0, PCI_DEVFN(2, 0)), 0x5c));
|
2010-12-18 08:48:43 +01:00
|
|
|
|
2012-10-26 19:01:45 +02:00
|
|
|
tolud = sch_port_access_read(2, 8, 4);
|
|
|
|
printk(BIOS_SPEW, "Top of Low Used DRAM: 0x%08llx\n", tolud);
|
2010-12-18 08:48:43 +01:00
|
|
|
|
2012-10-26 19:01:45 +02:00
|
|
|
tomk = tolud / 1024;
|
2012-07-27 07:42:20 +02:00
|
|
|
tomk_stolen = tomk;
|
2010-12-18 08:48:43 +01:00
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/* Note: subtract IGD device and TSEG. */
|
2010-12-18 08:48:43 +01:00
|
|
|
reg8 = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), 0x9e);
|
2010-12-18 14:22:37 +01:00
|
|
|
if (reg8 & 1) {
|
2010-12-18 08:48:43 +01:00
|
|
|
int tseg_size = 0;
|
|
|
|
printk(BIOS_DEBUG, "TSEG decoded, subtracting ");
|
|
|
|
reg8 >>= 1;
|
|
|
|
reg8 &= 3;
|
|
|
|
switch (reg8) {
|
|
|
|
case 0:
|
2010-12-18 14:22:37 +01:00
|
|
|
tseg_size = 1024; /* TSEG = 1M */
|
|
|
|
break;
|
2010-12-18 08:48:43 +01:00
|
|
|
case 1:
|
2010-12-18 14:22:37 +01:00
|
|
|
tseg_size = 2048; /* TSEG = 2M */
|
|
|
|
break;
|
2010-12-18 08:48:43 +01:00
|
|
|
case 2:
|
2010-12-18 14:22:37 +01:00
|
|
|
tseg_size = 8192; /* TSEG = 8M */
|
|
|
|
break;
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "%dM\n", tseg_size >> 10);
|
2012-07-27 07:42:20 +02:00
|
|
|
tomk_stolen -= tseg_size;
|
|
|
|
|
|
|
|
/* For reserving TSEG memory in the memory map */
|
|
|
|
tseg_memory_base = tomk_stolen * 1024ULL;
|
|
|
|
tseg_memory_size = tseg_size * 1024ULL;
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
|
2012-10-26 19:01:17 +02:00
|
|
|
reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(2, 0)), GGC);
|
2010-12-18 14:22:37 +01:00
|
|
|
if (!(reg16 & 2)) {
|
2010-12-18 08:48:43 +01:00
|
|
|
int uma_size = 0;
|
|
|
|
printk(BIOS_DEBUG, "IGD decoded, subtracting ");
|
|
|
|
reg16 >>= 4;
|
|
|
|
reg16 &= 7;
|
2010-12-18 14:22:37 +01:00
|
|
|
switch (reg16) {
|
|
|
|
case 1:
|
|
|
|
uma_size = 1024;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
uma_size = 4096;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
uma_size = 8192;
|
|
|
|
break;
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
|
2012-07-27 07:42:20 +02:00
|
|
|
tomk_stolen -= uma_size;
|
2010-12-18 08:48:43 +01:00
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/* For reserving UMA memory in the memory map. */
|
2012-07-27 07:42:20 +02:00
|
|
|
uma_memory_base = tomk_stolen * 1024ULL;
|
2010-12-18 08:48:43 +01:00
|
|
|
uma_memory_size = uma_size * 1024ULL;
|
|
|
|
}
|
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/*
|
|
|
|
* The following needs to be 2 lines, otherwise the second
|
|
|
|
* number is always 0.
|
2010-12-18 08:48:43 +01:00
|
|
|
*/
|
2010-12-18 14:22:37 +01:00
|
|
|
printk(BIOS_INFO, "Available memory: %dK", (u32) tomk);
|
|
|
|
printk(BIOS_INFO, " (%dM)\n", (u32) (tomk >> 10));
|
2010-12-18 08:48:43 +01:00
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/* Report the memory regions. */
|
2010-12-18 08:48:43 +01:00
|
|
|
ram_resource(dev, 3, 0, 640);
|
|
|
|
ram_resource(dev, 4, 768, (tomk - 768));
|
2012-07-27 07:42:20 +02:00
|
|
|
uma_resource(dev, 5, uma_memory_base >> 10, uma_memory_size >> 10);
|
|
|
|
mmio_resource(dev, 6, tseg_memory_base >> 10, tseg_memory_size >> 10);
|
|
|
|
|
|
|
|
add_fixed_resources(dev, 7);
|
2010-12-18 08:48:43 +01:00
|
|
|
|
|
|
|
assign_resources(dev->link_list);
|
|
|
|
|
2013-06-27 07:20:09 +02:00
|
|
|
set_top_of_ram(tomk * 1024 - uma_memory_size - tseg_memory_base);
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/*
|
|
|
|
* TODO: We could determine how many PCIe busses we need in the bar. For now
|
|
|
|
* that number is hardcoded to a max of 64.
|
|
|
|
* See e7525/northbridge.c for an example.
|
|
|
|
*/
|
2010-12-18 08:48:43 +01:00
|
|
|
static struct device_operations pci_domain_ops = {
|
2010-12-18 14:22:37 +01:00
|
|
|
.read_resources = pci_domain_read_resources,
|
|
|
|
.set_resources = pci_domain_set_resources,
|
|
|
|
.enable_resources = NULL,
|
|
|
|
.init = NULL,
|
|
|
|
.scan_bus = pci_domain_scan_bus,
|
2013-07-03 08:44:28 +02:00
|
|
|
.ops_pci_bus = pci_bus_default_ops,
|
2010-12-18 08:48:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void mc_read_resources(device_t dev)
|
|
|
|
{
|
2016-12-02 07:56:05 +01:00
|
|
|
u32 pcie_config_base;
|
|
|
|
int buses;
|
2010-12-18 08:48:43 +01:00
|
|
|
|
|
|
|
pci_dev_read_resources(dev);
|
|
|
|
|
2010-12-18 14:22:37 +01:00
|
|
|
/*
|
|
|
|
* We use 0xcf as an unused index for our PCIe bar so that we find
|
|
|
|
* it again.
|
|
|
|
*/
|
2016-12-02 07:56:05 +01:00
|
|
|
buses = get_pcie_bar(&pcie_config_base);
|
|
|
|
if (buses) {
|
|
|
|
struct resource *resource = new_resource(dev, 0xcf);
|
|
|
|
mmconf_resource_init(resource, pcie_config_base, buses);
|
|
|
|
}
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
|
|
|
|
{
|
|
|
|
if (!vendor || !device) {
|
|
|
|
pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
|
2010-12-18 14:22:37 +01:00
|
|
|
pci_read_config32(dev, PCI_VENDOR_ID));
|
2010-12-18 08:48:43 +01:00
|
|
|
} else {
|
|
|
|
pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
|
2010-12-18 14:22:37 +01:00
|
|
|
((device & 0xffff) << 16) | (vendor & 0xffff));
|
2010-12-18 08:48:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_operations intel_pci_ops = {
|
2010-12-18 14:22:37 +01:00
|
|
|
.set_subsystem = intel_set_subsystem,
|
2010-12-18 08:48:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct device_operations mc_ops = {
|
2010-12-18 14:22:37 +01:00
|
|
|
.read_resources = mc_read_resources,
|
2016-12-02 13:38:13 +01:00
|
|
|
.set_resources = pci_dev_set_resources,
|
2010-12-18 14:22:37 +01:00
|
|
|
.enable_resources = pci_dev_enable_resources,
|
2014-08-31 02:21:43 +02:00
|
|
|
.acpi_fill_ssdt_generator = generate_cpu_entries,
|
2010-12-18 14:22:37 +01:00
|
|
|
.scan_bus = 0,
|
|
|
|
.ops_pci = &intel_pci_ops,
|
2010-12-18 08:48:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pci_driver mc_driver __pci_driver = {
|
2010-12-18 14:22:37 +01:00
|
|
|
.ops = &mc_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device = 0x8100,
|
2010-12-18 08:48:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void cpu_bus_init(device_t dev)
|
|
|
|
{
|
|
|
|
initialize_cpus(dev->link_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_operations cpu_bus_ops = {
|
2014-10-30 22:12:34 +01:00
|
|
|
.read_resources = DEVICE_NOOP,
|
|
|
|
.set_resources = DEVICE_NOOP,
|
|
|
|
.enable_resources = DEVICE_NOOP,
|
2010-12-18 14:22:37 +01:00
|
|
|
.init = cpu_bus_init,
|
|
|
|
.scan_bus = 0,
|
2010-12-18 08:48:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void enable_dev(device_t dev)
|
|
|
|
{
|
2010-12-18 14:22:37 +01:00
|
|
|
/* Set the operations if it is a special bus type. */
|
2013-02-12 23:17:15 +01:00
|
|
|
if (dev->path.type == DEVICE_PATH_DOMAIN) {
|
2010-12-18 08:48:43 +01:00
|
|
|
dev->ops = &pci_domain_ops;
|
2013-02-13 00:20:54 +01:00
|
|
|
} else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
|
2010-12-18 08:48:43 +01:00
|
|
|
dev->ops = &cpu_bus_ops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct chip_operations northbridge_intel_sch_ops = {
|
|
|
|
CHIP_NAME("Intel SCH Northbridge")
|
|
|
|
.enable_dev = enable_dev,
|
|
|
|
};
|