| 1 |
|
| 2 |
|
| 3 |
#include <commonlib/helpers.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <device/pci_ops.h> |
| 6 |
#include <acpi/acpi.h> |
| 7 |
#include <acpi/acpi_ivrs.h> |
| 8 |
#include <arch/ioapic.h> |
| 9 |
#include <arch/vga.h> |
| 10 |
#include <types.h> |
| 11 |
#include <device/device.h> |
| 12 |
#include <device/pci.h> |
| 13 |
#include <device/pci_ids.h> |
| 14 |
#include <static.h> |
| 15 |
#include <string.h> |
| 16 |
#include <stdlib.h> |
| 17 |
#include <cpu/x86/mp.h> |
| 18 |
#include <Porting.h> |
| 19 |
#include <Topology.h> |
| 20 |
#include <cpu/amd/msr.h> |
| 21 |
#include <cpu/amd/mtrr.h> |
| 22 |
#include <acpi/acpigen.h> |
| 23 |
#include <northbridge/amd/nb_common.h> |
| 24 |
#include <northbridge/amd/agesa/agesa_helper.h> |
| 25 |
#include <southbridge/amd/pi/hudson/pci_devs.h> |
| 26 |
#include <amdblocks/cpu.h> |
| 27 |
|
| 28 |
#define PCIE_CAP_AER BIT(5) |
| 29 |
#define PCIE_CAP_ACS BIT(6) |
| 30 |
|
| 31 |
static int get_dram_base_limit(resource_t *basek, resource_t *limitk) |
| 32 |
{ |
| 33 |
u32 temp; |
| 34 |
|
| 35 |
temp = pci_read_config32(DEV_PTR(ht_1), 0x40); |
| 36 |
if (!(temp & 1)) |
| 37 |
return 0; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
*basek = ((temp & 0xffff0000)) >> (10 - 8); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
temp = pci_read_config32(DEV_PTR(ht_1), 0x44); |
| 48 |
*limitk = ((temp & 0xffff0000) | 0xffff) >> (10 - 8); |
| 49 |
*limitk += 1; |
| 50 |
|
| 51 |
return 1; |
| 52 |
} |
| 53 |
|
| 54 |
static void add_fixed_resources(struct device *dev, int index) |
| 55 |
{ |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
mmio_resource_kb(dev, index++, VGA_MMIO_BASE >> 10, VGA_MMIO_SIZE >> 10); |
| 62 |
reserved_ram_resource_kb(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10); |
| 63 |
|
| 64 |
|
| 65 |
if (pci_read_config32(DEV_PTR(ht_2), 0x118) & (1 << 18)) { |
| 66 |
|
| 67 |
resource_t basek, limitk; |
| 68 |
if (!get_dram_base_limit(&basek, &limitk)) |
| 69 |
return; |
| 70 |
mmio_resource_kb(dev, index++, limitk, 16 * 1024); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
static void nb_read_resources(struct device *dev) |
| 75 |
{ |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
mmconf_resource(dev, MMIO_CONF_BASE); |
| 82 |
|
| 83 |
|
| 84 |
mmio_range(dev, IO_APIC2_ADDR, IO_APIC2_ADDR, 0x1000); |
| 85 |
|
| 86 |
add_fixed_resources(dev, 0); |
| 87 |
} |
| 88 |
|
| 89 |
static void northbridge_init(struct device *dev) |
| 90 |
{ |
| 91 |
register_new_ioapic(IO_APIC2_ADDR); |
| 92 |
} |
| 93 |
|
| 94 |
static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 95 |
{ |
| 96 |
void *addr, *current; |
| 97 |
|
| 98 |
|
| 99 |
current = (void *)(hest + 1); |
| 100 |
|
| 101 |
addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 102 |
if (addr != NULL) |
| 103 |
current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 104 |
|
| 105 |
addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 106 |
if (addr != NULL) |
| 107 |
current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 108 |
|
| 109 |
return (unsigned long)current; |
| 110 |
} |
| 111 |
|
| 112 |
static unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current) |
| 113 |
{ |
| 114 |
|
| 115 |
current = ALIGN_UP(current, 8); |
| 116 |
ivrs_ivhd_special_t *ivhd_ioapic = (ivrs_ivhd_special_t *)current; |
| 117 |
|
| 118 |
ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 119 |
ivhd_ioapic->reserved = 0x0000; |
| 120 |
ivhd_ioapic->dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS | |
| 121 |
IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS | |
| 122 |
IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS; |
| 123 |
ivhd_ioapic->handle = get_ioapic_id(IO_APIC_ADDR); |
| 124 |
ivhd_ioapic->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC); |
| 125 |
ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC; |
| 126 |
current += sizeof(ivrs_ivhd_special_t); |
| 127 |
|
| 128 |
ivhd_ioapic = (ivrs_ivhd_special_t *)current; |
| 129 |
ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 130 |
ivhd_ioapic->reserved = 0x0000; |
| 131 |
ivhd_ioapic->dte_setting = 0x00; |
| 132 |
ivhd_ioapic->handle = get_ioapic_id(IO_APIC2_ADDR); |
| 133 |
ivhd_ioapic->source_dev_id = PCI_DEVFN(0, 1); |
| 134 |
ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC; |
| 135 |
current += sizeof(ivrs_ivhd_special_t); |
| 136 |
|
| 137 |
return current; |
| 138 |
} |
| 139 |
|
| 140 |
static unsigned long ivhd_describe_hpet(unsigned long current) |
| 141 |
{ |
| 142 |
|
| 143 |
current = ALIGN_UP(current, 8); |
| 144 |
ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current; |
| 145 |
|
| 146 |
ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 147 |
ivhd_hpet->reserved = 0x0000; |
| 148 |
ivhd_hpet->dte_setting = 0x00; |
| 149 |
ivhd_hpet->handle = 0x00; |
| 150 |
ivhd_hpet->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC); |
| 151 |
ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET; |
| 152 |
current += sizeof(ivrs_ivhd_special_t); |
| 153 |
|
| 154 |
return current; |
| 155 |
} |
| 156 |
|
| 157 |
static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid, |
| 158 |
uint16_t end_devid, uint8_t setting) |
| 159 |
{ |
| 160 |
|
| 161 |
current = ALIGN_UP(current, 4); |
| 162 |
ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current; |
| 163 |
|
| 164 |
|
| 165 |
ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE; |
| 166 |
ivhd_range->dev_id = start_devid; |
| 167 |
ivhd_range->dte_setting = setting; |
| 168 |
current += sizeof(ivrs_ivhd_generic_t); |
| 169 |
|
| 170 |
|
| 171 |
ivhd_range = (ivrs_ivhd_generic_t *)current; |
| 172 |
ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE; |
| 173 |
ivhd_range->dev_id = end_devid; |
| 174 |
ivhd_range->dte_setting = setting; |
| 175 |
current += sizeof(ivrs_ivhd_generic_t); |
| 176 |
|
| 177 |
return current; |
| 178 |
} |
| 179 |
|
| 180 |
static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev, |
| 181 |
unsigned long *current, uint8_t type, uint8_t data) |
| 182 |
{ |
| 183 |
if (type == IVHD_DEV_4_BYTE_SELECT) { |
| 184 |
|
| 185 |
*current = ALIGN_UP(*current, 4); |
| 186 |
ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current; |
| 187 |
|
| 188 |
ivhd_entry->type = type; |
| 189 |
ivhd_entry->dev_id = dev->path.pci.devfn | (dev->upstream->secondary << 8); |
| 190 |
ivhd_entry->dte_setting = data; |
| 191 |
*current += sizeof(ivrs_ivhd_generic_t); |
| 192 |
} else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) { |
| 193 |
|
| 194 |
*current = ALIGN_UP(*current, 8); |
| 195 |
ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current; |
| 196 |
|
| 197 |
ivhd_entry->type = type; |
| 198 |
ivhd_entry->dev_id = dev->path.pci.devfn | (dev->upstream->secondary << 8); |
| 199 |
ivhd_entry->dte_setting = data; |
| 200 |
ivhd_entry->reserved1 = 0; |
| 201 |
ivhd_entry->reserved2 = 0; |
| 202 |
ivhd_entry->source_dev_id = parent->path.pci.devfn | |
| 203 |
(parent->upstream->secondary << 8); |
| 204 |
*current += sizeof(ivrs_ivhd_alias_t); |
| 205 |
} |
| 206 |
|
| 207 |
return *current; |
| 208 |
} |
| 209 |
|
| 210 |
static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev, |
| 211 |
unsigned long *current, uint16_t *ivhd_length) |
| 212 |
{ |
| 213 |
unsigned int header_type, is_pcie; |
| 214 |
unsigned long current_backup; |
| 215 |
|
| 216 |
header_type = dev->hdr_type & 0x7f; |
| 217 |
is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 218 |
|
| 219 |
if (((header_type == PCI_HEADER_TYPE_NORMAL) || |
| 220 |
(header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) { |
| 221 |
|
| 222 |
current_backup = *current; |
| 223 |
add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0); |
| 224 |
*ivhd_length += (*current - current_backup); |
| 225 |
} else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) { |
| 226 |
|
| 227 |
current_backup = *current; |
| 228 |
add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0); |
| 229 |
*ivhd_length += (*current - current_backup); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
static void add_ivhd_device_entries(struct device *parent, struct device *dev, |
| 234 |
unsigned int depth, int linknum, int8_t *root_level, |
| 235 |
unsigned long *current, uint16_t *ivhd_length) |
| 236 |
{ |
| 237 |
struct device *sibling; |
| 238 |
|
| 239 |
if (!root_level) { |
| 240 |
root_level = malloc(sizeof(int8_t)); |
| 241 |
*root_level = -1; |
| 242 |
} |
| 243 |
|
| 244 |
if (dev->path.type == DEVICE_PATH_PCI) { |
| 245 |
if ((dev->upstream->secondary == 0x0) && |
| 246 |
(dev->path.pci.devfn == 0x0)) |
| 247 |
*root_level = depth; |
| 248 |
|
| 249 |
if ((*root_level != -1) && (dev->enabled)) { |
| 250 |
if (depth != *root_level) |
| 251 |
ivrs_add_device_or_bridge(parent, dev, current, ivhd_length); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
if (dev->downstream) { |
| 256 |
for (sibling = dev->downstream->children; sibling; sibling = sibling->sibling) |
| 257 |
add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level, |
| 258 |
current, ivhd_length); |
| 259 |
} |
| 260 |
|
| 261 |
free(root_level); |
| 262 |
} |
| 263 |
|
| 264 |
#define IOMMU_MMIO32(x) (*((volatile uint32_t *)(x))) |
| 265 |
#define EFR_SUPPORT BIT(27) |
| 266 |
|
| 267 |
static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_t *ivrs_agesa) |
| 268 |
{ |
| 269 |
acpi_ivrs_ivhd11_t *ivhd_11; |
| 270 |
unsigned long current_backup; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
struct device *nb_dev = pcidev_on_root(0, 0); |
| 277 |
struct device *iommu_dev = pcidev_on_root(0, 2); |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
memset((void *)current, 0, sizeof(acpi_ivrs_ivhd11_t)); |
| 284 |
ivhd_11 = (acpi_ivrs_ivhd11_t *)current; |
| 285 |
|
| 286 |
|
| 287 |
ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED; |
| 288 |
|
| 289 |
ivhd_11->flags = ivrs_agesa->ivhd.flags & 0x3f; |
| 290 |
ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11); |
| 291 |
|
| 292 |
ivhd_11->device_id = 0x02 | (nb_dev->upstream->secondary << 8); |
| 293 |
|
| 294 |
ivhd_11->capability_offset = 0x40; |
| 295 |
ivhd_11->iommu_base_low = ivrs_agesa->ivhd.iommu_base_low; |
| 296 |
ivhd_11->iommu_base_high = ivrs_agesa->ivhd.iommu_base_high; |
| 297 |
ivhd_11->pci_segment_group = nb_dev->upstream->segment_group; |
| 298 |
ivhd_11->iommu_info = ivrs_agesa->ivhd.iommu_info; |
| 299 |
ivhd_11->iommu_attributes.perf_counters = |
| 300 |
(IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 7) & 0xf; |
| 301 |
ivhd_11->iommu_attributes.perf_counter_banks = |
| 302 |
(IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 12) & 0x3f; |
| 303 |
ivhd_11->iommu_attributes.msi_num_ppr = |
| 304 |
(pci_read_config32(iommu_dev, ivhd_11->capability_offset + 0x10) >> 27) & 0x1f; |
| 305 |
|
| 306 |
if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_SUPPORT) { |
| 307 |
ivhd_11->efr_reg_image_low = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x30); |
| 308 |
ivhd_11->efr_reg_image_high = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x34); |
| 309 |
} |
| 310 |
|
| 311 |
current += sizeof(acpi_ivrs_ivhd11_t); |
| 312 |
|
| 313 |
|
| 314 |
current_backup = current; |
| 315 |
current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0); |
| 316 |
ivhd_11->length += (current - current_backup); |
| 317 |
add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, ¤t, &ivhd_11->length); |
| 318 |
|
| 319 |
|
| 320 |
current_backup = current; |
| 321 |
current = ivhd_describe_hpet(current); |
| 322 |
ivhd_11->length += (current - current_backup); |
| 323 |
|
| 324 |
|
| 325 |
current_backup = current; |
| 326 |
current = acpi_fill_ivrs_ioapic(ivrs_agesa, current); |
| 327 |
ivhd_11->length += (current - current_backup); |
| 328 |
|
| 329 |
return current; |
| 330 |
} |
| 331 |
|
| 332 |
static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current) |
| 333 |
{ |
| 334 |
acpi_ivrs_t *ivrs_agesa; |
| 335 |
unsigned long current_backup; |
| 336 |
|
| 337 |
struct device *nb_dev = pcidev_on_root(0, 0); |
| 338 |
if (!nb_dev) { |
| 339 |
printk(BIOS_WARNING, "%s: G-series northbridge device not present!\n", __func__); |
| 340 |
printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__); |
| 341 |
|
| 342 |
return (unsigned long)ivrs; |
| 343 |
} |
| 344 |
|
| 345 |
struct device *iommu_dev = pcidev_on_root(0, 2); |
| 346 |
|
| 347 |
if (!iommu_dev) { |
| 348 |
printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__); |
| 349 |
|
| 350 |
return (unsigned long)ivrs; |
| 351 |
} |
| 352 |
|
| 353 |
ivrs_agesa = agesawrapper_getlateinitptr(PICK_IVRS); |
| 354 |
if (ivrs_agesa != NULL) { |
| 355 |
ivrs->iv_info = ivrs_agesa->iv_info; |
| 356 |
ivrs->ivhd.type = IVHD_BLOCK_TYPE_LEGACY__FIXED; |
| 357 |
ivrs->ivhd.flags = ivrs_agesa->ivhd.flags; |
| 358 |
ivrs->ivhd.length = sizeof(struct acpi_ivrs_ivhd); |
| 359 |
|
| 360 |
ivrs->ivhd.device_id = 0x02 | (nb_dev->upstream->secondary << 8); |
| 361 |
|
| 362 |
ivrs->ivhd.capability_offset = 0x40; |
| 363 |
ivrs->ivhd.iommu_base_low = ivrs_agesa->ivhd.iommu_base_low; |
| 364 |
ivrs->ivhd.iommu_base_high = ivrs_agesa->ivhd.iommu_base_high; |
| 365 |
ivrs->ivhd.pci_segment_group = nb_dev->upstream->segment_group; |
| 366 |
ivrs->ivhd.iommu_info = ivrs_agesa->ivhd.iommu_info; |
| 367 |
ivrs->ivhd.iommu_feature_info = ivrs_agesa->ivhd.iommu_feature_info; |
| 368 |
|
| 369 |
if (pci_read_config32(iommu_dev, ivrs->ivhd.capability_offset) & EFR_SUPPORT) |
| 370 |
ivrs->iv_info |= IVINFO_EFR_SUPPORTED; |
| 371 |
} else { |
| 372 |
printk(BIOS_WARNING, "%s: AGESA returned NULL IVRS\n", __func__); |
| 373 |
|
| 374 |
return (unsigned long)ivrs; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
current_backup = current; |
| 383 |
current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0); |
| 384 |
ivrs->ivhd.length += (current - current_backup); |
| 385 |
add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, ¤t, &ivrs->ivhd.length); |
| 386 |
|
| 387 |
|
| 388 |
current_backup = current; |
| 389 |
current = ivhd_describe_hpet(current); |
| 390 |
ivrs->ivhd.length += (current - current_backup); |
| 391 |
|
| 392 |
|
| 393 |
current_backup = current; |
| 394 |
current = acpi_fill_ivrs_ioapic(ivrs_agesa, current); |
| 395 |
ivrs->ivhd.length += (current - current_backup); |
| 396 |
|
| 397 |
|
| 398 |
if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED)) |
| 399 |
return current; |
| 400 |
|
| 401 |
return acpi_fill_ivrs11(current, ivrs_agesa); |
| 402 |
} |
| 403 |
|
| 404 |
static void northbridge_fill_ssdt_generator(const struct device *device) |
| 405 |
{ |
| 406 |
char pscope[] = "\\_SB.PCI0"; |
| 407 |
|
| 408 |
acpigen_write_scope(pscope); |
| 409 |
acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb()); |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20); |
| 420 |
acpigen_pop_len(); |
| 421 |
} |
| 422 |
|
| 423 |
static unsigned long agesa_write_acpi_tables(const struct device *device, |
| 424 |
unsigned long current, |
| 425 |
acpi_rsdp_t *rsdp) |
| 426 |
{ |
| 427 |
acpi_srat_t *srat; |
| 428 |
acpi_slit_t *slit; |
| 429 |
acpi_header_t *ssdt; |
| 430 |
acpi_header_t *alib; |
| 431 |
acpi_ivrs_t *ivrs; |
| 432 |
|
| 433 |
|
| 434 |
current = ALIGN_UP(current, 8); |
| 435 |
acpi_write_hest((void *)current, acpi_fill_hest); |
| 436 |
acpi_add_table(rsdp, (void *)current); |
| 437 |
current += ((acpi_header_t *)current)->length; |
| 438 |
|
| 439 |
|
| 440 |
if (is_dev_enabled(DEV_PTR(iommu))) { |
| 441 |
current = ALIGN_UP(current, 8); |
| 442 |
printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 443 |
ivrs = (acpi_ivrs_t *)current; |
| 444 |
acpi_create_ivrs(ivrs, acpi_fill_ivrs); |
| 445 |
current += ivrs->header.length; |
| 446 |
acpi_add_table(rsdp, ivrs); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
current = ALIGN_UP(current, 8); |
| 451 |
printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 452 |
srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT); |
| 453 |
if (srat != NULL) { |
| 454 |
memcpy((void *)current, srat, srat->header.length); |
| 455 |
srat = (acpi_srat_t *)current; |
| 456 |
current += srat->header.length; |
| 457 |
acpi_add_table(rsdp, srat); |
| 458 |
} else { |
| 459 |
printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
current = ALIGN_UP(current, 8); |
| 464 |
printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 465 |
slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT); |
| 466 |
if (slit != NULL) { |
| 467 |
memcpy((void *)current, slit, slit->header.length); |
| 468 |
slit = (acpi_slit_t *)current; |
| 469 |
current += slit->header.length; |
| 470 |
acpi_add_table(rsdp, slit); |
| 471 |
} else { |
| 472 |
printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
current = ALIGN_UP(current, 16); |
| 477 |
printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 478 |
alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB); |
| 479 |
if (alib != NULL) { |
| 480 |
memcpy((void *)current, alib, alib->length); |
| 481 |
alib = (acpi_header_t *)current; |
| 482 |
current += alib->length; |
| 483 |
acpi_add_table(rsdp, (void *)alib); |
| 484 |
} |
| 485 |
else { |
| 486 |
printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
current = ALIGN_UP(current, 16); |
| 492 |
printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 493 |
ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE); |
| 494 |
if (ssdt != NULL) { |
| 495 |
memcpy((void *)current, ssdt, ssdt->length); |
| 496 |
ssdt = (acpi_header_t *)current; |
| 497 |
current += ssdt->length; |
| 498 |
} |
| 499 |
else { |
| 500 |
printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 501 |
} |
| 502 |
acpi_add_table(rsdp, ssdt); |
| 503 |
|
| 504 |
printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 505 |
return current; |
| 506 |
} |
| 507 |
|
| 508 |
struct device_operations amd_pi_northbridge_ops = { |
| 509 |
.read_resources = nb_read_resources, |
| 510 |
.set_resources = pci_dev_set_resources, |
| 511 |
.enable_resources = pci_dev_enable_resources, |
| 512 |
.init = northbridge_init, |
| 513 |
.ops_pci = &pci_dev_ops_pci, |
| 514 |
.acpi_fill_ssdt = northbridge_fill_ssdt_generator, |
| 515 |
.write_acpi_tables = agesa_write_acpi_tables, |
| 516 |
}; |
| 517 |
|
| 518 |
static void fam16_finalize(void *chip_info) |
| 519 |
{ |
| 520 |
struct device *dev; |
| 521 |
dev = pcidev_on_root(0, 0); |
| 522 |
|
| 523 |
pci_write_config32(dev, 0xF8, 0); |
| 524 |
pci_write_config32(dev, 0xFC, 5); |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
pci_write_config32(dev, 0xE0, 0x014000B0); |
| 537 |
|
| 538 |
|
| 539 |
pci_or_config32(dev, 0xE4, PCIE_CAP_AER | PCIE_CAP_ACS); |
| 540 |
|
| 541 |
|
| 542 |
pci_write_config32(dev, 0xE0, 0x01300000); |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
pci_or_config32(dev, 0xE4, (BIT(24) | BIT(25) | BIT(26))); |
| 550 |
|
| 551 |
|
| 552 |
dev = pcidev_on_root(1, 1); |
| 553 |
if (dev != NULL) { |
| 554 |
pci_and_config32(dev, 0x60, ~(1 << 11)); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
struct hw_mem_hole_info { |
| 559 |
unsigned int hole_startk; |
| 560 |
int node_id; |
| 561 |
}; |
| 562 |
static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 563 |
{ |
| 564 |
struct hw_mem_hole_info mem_hole; |
| 565 |
mem_hole.node_id = -1; |
| 566 |
|
| 567 |
resource_t basek, limitk; |
| 568 |
if (get_dram_base_limit(&basek, &limitk)) { |
| 569 |
u32 hole = pci_read_config32(DEV_PTR(ht_1), 0xf0); |
| 570 |
if (hole & 2) { |
| 571 |
mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
| 572 |
mem_hole.node_id = 0; |
| 573 |
} |
| 574 |
} |
| 575 |
return mem_hole; |
| 576 |
} |
| 577 |
|
| 578 |
static void domain_read_resources(struct device *dev) |
| 579 |
{ |
| 580 |
unsigned long mmio_basek; |
| 581 |
unsigned long idx = 0; |
| 582 |
struct hw_mem_hole_info mem_hole; |
| 583 |
resource_t basek = 0; |
| 584 |
resource_t limitk = 0; |
| 585 |
resource_t sizek; |
| 586 |
|
| 587 |
pci_domain_read_resources(dev); |
| 588 |
|
| 589 |
|
| 590 |
mmio_basek = get_top_of_mem_below_4gb() >> 10; |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
mem_hole = get_hw_mem_hole_info(); |
| 599 |
|
| 600 |
|
| 601 |
if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 602 |
mmio_basek = mem_hole.hole_startk; |
| 603 |
} |
| 604 |
|
| 605 |
get_dram_base_limit(&basek, &limitk); |
| 606 |
sizek = limitk - basek; |
| 607 |
|
| 608 |
printk(BIOS_DEBUG, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n", |
| 609 |
basek, limitk, sizek); |
| 610 |
|
| 611 |
|
| 612 |
if (basek < 640 && sizek > 1024) { |
| 613 |
ram_resource_kb(dev, idx++, basek, 640 - basek); |
| 614 |
basek = 1024; |
| 615 |
sizek = limitk - basek; |
| 616 |
} |
| 617 |
|
| 618 |
printk(BIOS_DEBUG, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n", |
| 619 |
basek, limitk, sizek); |
| 620 |
|
| 621 |
|
| 622 |
if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) { |
| 623 |
if (basek <= mmio_basek) { |
| 624 |
unsigned int pre_sizek; |
| 625 |
pre_sizek = mmio_basek - basek; |
| 626 |
if (pre_sizek > 0) { |
| 627 |
ram_resource_kb(dev, idx++, basek, pre_sizek); |
| 628 |
sizek -= pre_sizek; |
| 629 |
} |
| 630 |
basek = mmio_basek; |
| 631 |
} |
| 632 |
if ((basek + sizek) <= 4 * 1024 * 1024) { |
| 633 |
sizek = 0; |
| 634 |
} else { |
| 635 |
uint64_t topmem2 = get_top_of_mem_above_4gb(); |
| 636 |
basek = 4 * 1024 * 1024; |
| 637 |
sizek = topmem2 / 1024 - basek; |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
ram_resource_kb(dev, idx++, basek, sizek); |
| 642 |
printk(BIOS_DEBUG, "mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 643 |
mmio_basek, basek, limitk); |
| 644 |
|
| 645 |
add_uma_resource_below_tolm(dev, idx++); |
| 646 |
} |
| 647 |
|
| 648 |
static const char *domain_acpi_name(const struct device *dev) |
| 649 |
{ |
| 650 |
if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 651 |
return "PCI0"; |
| 652 |
|
| 653 |
return NULL; |
| 654 |
} |
| 655 |
|
| 656 |
struct device_operations amd_fam16_mod30_pci_domain_ops = { |
| 657 |
.read_resources = domain_read_resources, |
| 658 |
.set_resources = pci_domain_set_resources, |
| 659 |
.scan_bus = pci_host_bridge_scan_bus, |
| 660 |
.acpi_name = domain_acpi_name, |
| 661 |
}; |
| 662 |
|
| 663 |
void mp_init_cpus(struct bus *cpu_bus) |
| 664 |
{ |
| 665 |
extern const struct mp_ops amd_mp_ops_no_smm; |
| 666 |
|
| 667 |
mp_init_with_smm(cpu_bus, &amd_mp_ops_no_smm); |
| 668 |
|
| 669 |
|
| 670 |
mtrr_use_temp_range(OPTIMAL_CACHE_ROM_BASE, OPTIMAL_CACHE_ROM_SIZE, |
| 671 |
MTRR_TYPE_WRPROT); |
| 672 |
} |
| 673 |
|
| 674 |
void generate_cpu_entries(const struct device *device) |
| 675 |
{ |
| 676 |
int cpu; |
| 677 |
const int cores = get_cpu_count(); |
| 678 |
|
| 679 |
printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores); |
| 680 |
|
| 681 |
|
| 682 |
for (cpu = 0; cpu < cores; cpu++) { |
| 683 |
acpigen_write_processor_device(cpu); |
| 684 |
acpigen_write_processor_device_end(); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
struct device_operations amd_fam16_mod30_cpu_bus_ops = { |
| 689 |
.read_resources = noop_read_resources, |
| 690 |
.set_resources = noop_set_resources, |
| 691 |
.init = mp_cpu_bus_init, |
| 692 |
.acpi_fill_ssdt = generate_cpu_entries, |
| 693 |
}; |
| 694 |
|
| 695 |
struct chip_operations northbridge_amd_pi_00730F01_ops = { |
| 696 |
.name = "AMD FAM16 Root Complex", |
| 697 |
.final = fam16_finalize, |
| 698 |
}; |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
u32 map_oprom_vendev(u32 vendev) |
| 704 |
{ |
| 705 |
u32 new_vendev; |
| 706 |
new_vendev = |
| 707 |
((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev; |
| 708 |
|
| 709 |
if (vendev != new_vendev) |
| 710 |
printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev); |
| 711 |
|
| 712 |
return new_vendev; |
| 713 |
} |