summaryrefslogtreecommitdiff
path: root/src/soc/intel/fsp_broadwell_de/northcluster.c
blob: 2e27d37b16b93e116ee662d4fd0a835f4e242215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2013 Google Inc.
 * Copyright (C) 2015-2016 Intel Corp.
 * Copyright (C) 2016-2018 Siemens AG
 *
 * 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 <arch/acpi.h>
#include <console/console.h>
#include <cpu/x86/lapic.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_ids.h>
#include <drivers/intel/fsp1_0/fsp_util.h>
#include <soc/iomap.h>
#include <soc/pci_devs.h>
#include <soc/ramstage.h>
#include <soc/acpi.h>

static const int legacy_hole_base_k = 0xa0000 / 1024;
static const int legacy_hole_size_k = 384;

static int add_fixed_resources(struct device *dev, int index)
{
	struct resource *resource;
	u32 pcie_config_base, pcie_config_size;
	pcie_config_base = MCFG_BASE_ADDRESS;
	pcie_config_size = MCFG_BASE_SIZE;

	printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
		   "size=0x%x\n", pcie_config_base, pcie_config_size);
	resource = new_resource(dev, index++);
	resource->base = (resource_t) pcie_config_base;
	resource->size = (resource_t) pcie_config_size;
	resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
		IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;

	resource = new_resource(dev, index++); /* Local APIC */
	resource->base = LAPIC_DEFAULT_BASE;
	resource->size = 0x00001000;
	resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
			IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;

	mmio_resource(dev, index++, legacy_hole_base_k, legacy_hole_size_k);

	return index;
}

static void mc_add_dram_resources(struct device *dev)
{
	u32 fsp_mem_base, fsp_mem_len;
	u32 tseg_base, tseg_length;
	u32 rsv_base, rsv_length;
	u32 tolm;
	int index = 0;
	uint64_t highmem_size = 0;

	fsp_mem_base = GetFspReservedMemory(FspHobListPtr, &fsp_mem_len);
	highmem_size = GetUsableHighMemTop(FspHobListPtr) - 0x100000000L;
	tseg_base    = GetTsegReservedMemory(FspHobListPtr, &tseg_length);
	tolm         = GetPhysicalLowMemTop(FspHobListPtr);

	printk(BIOS_DEBUG, "\n\n");
	printk(BIOS_DEBUG, "fsp_mem_base:             0x%.8x\n", fsp_mem_base);
	printk(BIOS_DEBUG, "fsp_mem_len:              0x%.8x\n", fsp_mem_len);
	printk(BIOS_DEBUG, "tseg_base:                0x%.8x\n", tseg_base);
	printk(BIOS_DEBUG, "tseg_len:                 0x%.8x\n", tseg_length);
	printk(BIOS_DEBUG, "highmem_size:             0x%.8x %.8x\n",
	       (u32)(highmem_size>>32),
	       (u32)(highmem_size&0xffffffff));
	printk(BIOS_DEBUG, "tolm:                     0x%.8x\n", tolm);
	printk(BIOS_DEBUG, "Top of system low memory: 0x%08x\n", tolm);
	printk(BIOS_DEBUG, "FSP memory location:      0x%x\n (size: %dM)\n",
	       fsp_mem_base, fsp_mem_len >> 20);
	printk(BIOS_DEBUG, "tseg:                     0x%08x (size: 0x%.8x)\n",
	       tseg_base, tseg_length);

	/* Report the memory regions. */
	ram_resource(dev, index++, 0, legacy_hole_base_k);
	ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
		 ((fsp_mem_base >> 10) - (legacy_hole_base_k + legacy_hole_size_k)));

	/* Mark SMM & FSP regions reserved */
	mmio_resource(dev, index++, tseg_base >> 10, tseg_length >> 10);
	mmio_resource(dev, index++, fsp_mem_base >> 10, fsp_mem_len >> 10);

	/* Reserve MMIO space */
	rsv_base = fsp_mem_base + fsp_mem_len;
	rsv_length = tseg_base - rsv_base;
	if (rsv_length) {
		mmio_resource(dev, index++, rsv_base >> 10,	rsv_length >> 10);
		printk(BIOS_DEBUG, "Reserved MMIO : 0x%08x length 0x%08x\n",
		       rsv_base, rsv_length);
	}

	rsv_base = tseg_base + tseg_length;
	rsv_length = tolm - rsv_base;
	if (rsv_length) {
		mmio_resource(dev, index++, rsv_base >> 10,	rsv_length >> 10);
		printk(BIOS_DEBUG, "Reserved MMIO : 0x%08x length 0x%08x\n",
		       rsv_base, rsv_length);
	}

	if (highmem_size) {
		ram_resource(dev, index++, 0x100000000 >> 10, highmem_size >> 10);
	}
	printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
	       highmem_size >> 20);

	index = add_fixed_resources(dev, index);
}

static void nc_read_resources(struct device *dev)
{
	/* Call the normal read_resources */
	pci_dev_read_resources(dev);

	/* Calculate and add DRAM resources. */
	mc_add_dram_resources(dev);
}

static void nc_enable(struct device *dev)
{
	print_fsp_info();
}

static struct device_operations nc_ops = {
	.read_resources           = nc_read_resources,
	.acpi_fill_ssdt_generator = generate_cpu_entries,
	.set_resources            = pci_dev_set_resources,
	.enable_resources         = pci_dev_enable_resources,
	.init                     = NULL,
	.enable                   = &nc_enable,
	.scan_bus                 = 0,
	.ops_pci                  = &soc_pci_ops,
};

static const struct pci_driver nc_driver __pci_driver = {
	.ops    = &nc_ops,
	.vendor = PCI_VENDOR_ID_INTEL,
	.device = SOC_DEVID,
};

static const struct pci_driver nc_driver_es2 __pci_driver = {
	.ops    = &nc_ops,
	.vendor = PCI_VENDOR_ID_INTEL,
	.device = SOC_DEVID_ES2,
};