Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Rudolf Marek <r.marek@assembler.cz> |
| 5 | * |
| 6 | * Based on qemu-x86/northbridge.c |
| 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; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 19 | * Foundation, Inc. |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | |
| 23 | #include <console/console.h> |
| 24 | #include <arch/io.h> |
| 25 | #include <stdint.h> |
| 26 | #include <device/device.h> |
| 27 | #include <device/pci.h> |
| 28 | #include <device/pci_ids.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 31 | #include <smbios.h> |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 32 | #include <cbmem.h> |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 33 | |
| 34 | static unsigned long get_memory_size(void) |
| 35 | { |
| 36 | device_t nb_dev; |
| 37 | u8 size; |
| 38 | |
| 39 | nb_dev = dev_find_device(PCI_VENDOR_ID_RDC, |
| 40 | PCI_DEVICE_ID_RDC_R8610_NB, 0); |
| 41 | size = pci_read_config8(nb_dev, 0x6d) & 0xf; |
| 42 | return (2 * 1024) << size; |
| 43 | } |
| 44 | |
| 45 | static void cpu_pci_domain_set_resources(device_t dev) |
| 46 | { |
| 47 | u32 pci_tolm = find_pci_tolm(dev->link_list); |
| 48 | unsigned long tomk = 0, tolmk; |
| 49 | int idx; |
| 50 | |
| 51 | tomk = get_memory_size(); |
| 52 | printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n", |
| 53 | tomk, tomk / 1024); |
| 54 | |
| 55 | /* Compute the top of Low memory */ |
| 56 | tolmk = pci_tolm >> 10; |
| 57 | if (tolmk >= tomk) { |
| 58 | /* The PCI hole does not overlap the memory. */ |
| 59 | tolmk = tomk; |
| 60 | } |
| 61 | |
| 62 | /* Report the memory regions. */ |
| 63 | idx = 10; |
| 64 | ram_resource(dev, idx++, 0, 640); |
| 65 | ram_resource(dev, idx++, 768, tolmk - 768); |
| 66 | |
Kyösti Mälkki | 42f4651 | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 67 | set_top_of_ram(tomk * 1024); |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 68 | |
| 69 | assign_resources(dev->link_list); |
| 70 | } |
| 71 | |
| 72 | static void cpu_pci_domain_read_resources(struct device *dev) |
| 73 | { |
| 74 | pci_domain_read_resources(dev); |
| 75 | } |
| 76 | |
| 77 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 78 | static int rdc_get_smbios_data16(int handle, unsigned long *current) |
| 79 | { |
| 80 | struct smbios_type16 *t = (struct smbios_type16 *)*current; |
| 81 | int len = sizeof(struct smbios_type16); |
| 82 | |
| 83 | memset(t, 0, sizeof(struct smbios_type16)); |
| 84 | t->type = SMBIOS_PHYS_MEMORY_ARRAY; |
| 85 | t->handle = handle; |
| 86 | t->length = len - 2; |
| 87 | t->location = 3; /* Location: System Board */ |
| 88 | t->use = 3; /* System memory */ |
| 89 | t->memory_error_correction = 3; /* No error correction */ |
| 90 | t->maximum_capacity = get_memory_size(); |
| 91 | *current += len; |
| 92 | return len; |
| 93 | } |
| 94 | |
| 95 | static int rdc_get_smbios_data(device_t dev, int *handle, unsigned long *current) |
| 96 | { |
| 97 | int len; |
| 98 | len = rdc_get_smbios_data16(*handle, current); |
| 99 | *handle += 1; |
| 100 | return len; |
| 101 | } |
| 102 | #endif |
| 103 | static struct device_operations pci_domain_ops = { |
| 104 | .read_resources = cpu_pci_domain_read_resources, |
| 105 | .set_resources = cpu_pci_domain_set_resources, |
| 106 | .enable_resources = NULL, |
| 107 | .init = NULL, |
| 108 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 33e5df3 | 2013-07-03 10:51:34 +0300 | [diff] [blame] | 109 | .ops_pci_bus = pci_bus_default_ops, |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 110 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 111 | .get_smbios_data = rdc_get_smbios_data, |
| 112 | #endif |
| 113 | }; |
| 114 | |
| 115 | static void enable_dev(struct device *dev) |
| 116 | { |
| 117 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 118 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 119 | dev->ops = &pci_domain_ops; |
Rudolf Marek | c0c5ac7 | 2012-03-25 18:14:02 +0200 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | struct chip_operations northbridge_rdc_r8610_ops = { |
| 124 | CHIP_NAME("RDC R8610 Northbridge") |
| 125 | .enable_dev = enable_dev, |
| 126 | }; |