blob: b53662693694a3e66d879b488585f5929be80517 [file] [log] [blame]
Rudolf Marekc0c5ac72012-03-25 18:14:02 +02001/*
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.
Rudolf Marekc0c5ac72012-03-25 18:14:02 +020016 */
17
18
19#include <console/console.h>
20#include <arch/io.h>
21#include <stdint.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <stdlib.h>
26#include <string.h>
Rudolf Marekc0c5ac72012-03-25 18:14:02 +020027#include <smbios.h>
Rudolf Marekc0c5ac72012-03-25 18:14:02 +020028#include <cbmem.h>
Rudolf Marekc0c5ac72012-03-25 18:14:02 +020029
30static unsigned long get_memory_size(void)
31{
32 device_t nb_dev;
33 u8 size;
34
35 nb_dev = dev_find_device(PCI_VENDOR_ID_RDC,
36 PCI_DEVICE_ID_RDC_R8610_NB, 0);
37 size = pci_read_config8(nb_dev, 0x6d) & 0xf;
38 return (2 * 1024) << size;
39}
40
41static void cpu_pci_domain_set_resources(device_t dev)
42{
43 u32 pci_tolm = find_pci_tolm(dev->link_list);
44 unsigned long tomk = 0, tolmk;
45 int idx;
46
47 tomk = get_memory_size();
48 printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n",
49 tomk, tomk / 1024);
50
51 /* Compute the top of Low memory */
52 tolmk = pci_tolm >> 10;
53 if (tolmk >= tomk) {
54 /* The PCI hole does not overlap the memory. */
55 tolmk = tomk;
56 }
57
58 /* Report the memory regions. */
59 idx = 10;
60 ram_resource(dev, idx++, 0, 640);
61 ram_resource(dev, idx++, 768, tolmk - 768);
62
Kyösti Mälkki42f46512013-06-27 08:20:09 +030063 set_top_of_ram(tomk * 1024);
Rudolf Marekc0c5ac72012-03-25 18:14:02 +020064
65 assign_resources(dev->link_list);
66}
67
68static void cpu_pci_domain_read_resources(struct device *dev)
69{
70 pci_domain_read_resources(dev);
71}
72
73#if CONFIG_GENERATE_SMBIOS_TABLES
74static int rdc_get_smbios_data16(int handle, unsigned long *current)
75{
76 struct smbios_type16 *t = (struct smbios_type16 *)*current;
77 int len = sizeof(struct smbios_type16);
78
79 memset(t, 0, sizeof(struct smbios_type16));
80 t->type = SMBIOS_PHYS_MEMORY_ARRAY;
81 t->handle = handle;
82 t->length = len - 2;
83 t->location = 3; /* Location: System Board */
84 t->use = 3; /* System memory */
85 t->memory_error_correction = 3; /* No error correction */
86 t->maximum_capacity = get_memory_size();
87 *current += len;
88 return len;
89}
90
91static int rdc_get_smbios_data(device_t dev, int *handle, unsigned long *current)
92{
93 int len;
94 len = rdc_get_smbios_data16(*handle, current);
95 *handle += 1;
96 return len;
97}
98#endif
99static struct device_operations pci_domain_ops = {
100 .read_resources = cpu_pci_domain_read_resources,
101 .set_resources = cpu_pci_domain_set_resources,
102 .enable_resources = NULL,
103 .init = NULL,
104 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki33e5df32013-07-03 10:51:34 +0300105 .ops_pci_bus = pci_bus_default_ops,
Rudolf Marekc0c5ac72012-03-25 18:14:02 +0200106#if CONFIG_GENERATE_SMBIOS_TABLES
107 .get_smbios_data = rdc_get_smbios_data,
108#endif
109};
110
111static void enable_dev(struct device *dev)
112{
113 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800114 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Rudolf Marekc0c5ac72012-03-25 18:14:02 +0200115 dev->ops = &pci_domain_ops;
Rudolf Marekc0c5ac72012-03-25 18:14:02 +0200116 }
117}
118
119struct chip_operations northbridge_rdc_r8610_ops = {
120 CHIP_NAME("RDC R8610 Northbridge")
121 .enable_dev = enable_dev,
122};