Andrey Petrov | a2176d8 | 2016-01-15 18:05:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corp. |
| 5 | * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.) |
| 6 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <console/console.h> |
| 15 | #include <soc/iomap.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
| 18 | #include <soc/northbridge.h> |
| 19 | #include <soc/pci_ids.h> |
| 20 | |
| 21 | static uint32_t get_bar(device_t dev, unsigned int index) |
| 22 | { |
| 23 | uint32_t bar; |
| 24 | |
| 25 | bar = pci_read_config32(dev, index); |
| 26 | |
| 27 | /* If not enabled return 0 else strip enabled bit */ |
| 28 | return (bar & 1) ? (bar & ~1) : 0; |
| 29 | } |
| 30 | |
| 31 | static int mc_add_fixed_mmio_resources(device_t dev, int index) |
| 32 | { |
Andrey Petrov | 15c736b | 2016-03-30 18:15:30 -0700 | [diff] [blame^] | 33 | unsigned long addr; |
| 34 | |
Andrey Petrov | a2176d8 | 2016-01-15 18:05:12 -0800 | [diff] [blame] | 35 | /* PCI extended config region */ |
Andrey Petrov | 15c736b | 2016-03-30 18:15:30 -0700 | [diff] [blame^] | 36 | addr = ALIGN_DOWN(get_bar(dev, PCIEXBAR), 256*MiB) / KiB; |
| 37 | mmio_resource(dev, index++, addr, PCIEX_SIZE / KiB); |
Andrey Petrov | a2176d8 | 2016-01-15 18:05:12 -0800 | [diff] [blame] | 38 | |
| 39 | /* Memory Controller Hub */ |
Andrey Petrov | 15c736b | 2016-03-30 18:15:30 -0700 | [diff] [blame^] | 40 | addr = ALIGN_DOWN(get_bar(dev, MCHBAR), 32*KiB) / KiB; |
| 41 | mmio_resource(dev, index++, addr, MCH_BASE_SIZE / KiB); |
Andrey Petrov | a2176d8 | 2016-01-15 18:05:12 -0800 | [diff] [blame] | 42 | |
| 43 | return index; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | static int mc_add_dram_resources(device_t dev, int index) |
| 48 | { |
| 49 | unsigned long base_k, size_k; |
| 50 | uint32_t bgsm, bdsm, tolud, tseg; |
| 51 | uint64_t touud; |
| 52 | |
| 53 | bgsm = ALIGN_DOWN(pci_read_config32(dev, BGSM), MiB); |
| 54 | bdsm = ALIGN_DOWN(pci_read_config32(dev, BDSM), MiB); |
| 55 | tolud = ALIGN_DOWN(pci_read_config32(dev, TOLUD), MiB); |
| 56 | tseg = ALIGN_DOWN(pci_read_config32(dev, TSEG), MiB); |
| 57 | |
| 58 | /* TOUUD is naturally a 64 bit integer */ |
| 59 | touud = pci_read_config32(dev, TOUUD + sizeof(uint32_t)); |
| 60 | touud <<= 32; |
| 61 | touud |= ALIGN_DOWN(pci_read_config32(dev, TOUUD), MiB); |
| 62 | |
| 63 | /* 0 - > 0xa0000: 640kb of DOS memory. Not enough for anybody nowadays */ |
| 64 | ram_resource(dev, index++, 0, 640); |
| 65 | |
| 66 | /* 0xc0000 -> top_of_ram, skipping the legacy VGA region */ |
| 67 | base_k = 768; |
| 68 | size_k = (tseg / KiB) - base_k; |
| 69 | ram_resource(dev, index++, base_k, size_k); |
| 70 | |
| 71 | /* TSEG -> BGSM */ |
| 72 | reserved_ram_resource(dev, index++, tseg / KiB, (bgsm - tseg) / KiB); |
| 73 | |
| 74 | /* BGSM -> BDSM */ |
| 75 | mmio_resource(dev, index++, bgsm / KiB, (bdsm - bgsm) / KiB); |
| 76 | |
| 77 | /* BDSM -> TOLUD */ |
| 78 | mmio_resource(dev, index++, tolud / KiB, (tolud - bdsm) / KiB); |
| 79 | |
| 80 | /* 4G -> TOUUD */ |
| 81 | base_k = 4ULL*GiB / KiB; |
| 82 | size_k = (touud / KiB) - base_k; |
| 83 | ram_resource(dev, index++, base_k, size_k); |
| 84 | |
| 85 | /* 0xa0000 - 0xbffff: legacy VGA */ |
| 86 | mmio_resource(dev, index++, 640, 128); |
| 87 | |
| 88 | return index; |
| 89 | } |
| 90 | |
| 91 | static void northbridge_read_resources(device_t dev) |
| 92 | { |
| 93 | |
| 94 | int index = 0; |
| 95 | /* Read standard PCI resources. */ |
| 96 | pci_dev_read_resources(dev); |
| 97 | |
| 98 | /* Add all fixed MMIO resources. */ |
| 99 | index = mc_add_fixed_mmio_resources(dev, index); |
| 100 | |
| 101 | /* Calculate and add DRAM resources. */ |
| 102 | mc_add_dram_resources(dev, index); |
| 103 | } |
| 104 | |
| 105 | static struct device_operations northbridge_ops = { |
| 106 | .read_resources = northbridge_read_resources, |
| 107 | .set_resources = pci_dev_set_resources, |
| 108 | .enable_resources = pci_dev_enable_resources, |
| 109 | .init = DEVICE_NOOP, |
| 110 | .enable = DEVICE_NOOP |
| 111 | }; |
| 112 | |
| 113 | static const struct pci_driver northbridge_driver __pci_driver = { |
| 114 | .ops = &northbridge_ops, |
| 115 | .vendor = PCI_VENDOR_ID_INTEL, |
| 116 | .device = PCI_DEVICE_ID_APOLLOLAKE_NB |
| 117 | }; |