blob: dea96f275d7253ef3c4e649a96694cf7bb599c2b [file] [log] [blame]
Stefan Reinauer597ff872013-01-07 13:21:22 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2004 Stefan Reinauer <stefan.reinauer@coreboot.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer597ff872013-01-07 13:21:22 -080014 */
15
16#include <cbmem.h>
Patrick Rudolph69d5ef92018-11-11 12:43:48 +010017#include <arch/io.h>
18#include "memory.h"
Stefan Reinauer597ff872013-01-07 13:21:22 -080019
20#define CMOS_ADDR_PORT 0x70
21#define CMOS_DATA_PORT 0x71
Gerd Hoffmann9839a382013-06-17 12:26:17 +020022
Stefan Reinauer597ff872013-01-07 13:21:22 -080023#define HIGH_RAM_ADDR 0x35
24#define LOW_RAM_ADDR 0x34
25
Gerd Hoffmann9839a382013-06-17 12:26:17 +020026#define HIGH_HIGHRAM_ADDR 0x5d
27#define MID_HIGHRAM_ADDR 0x5c
28#define LOW_HIGHRAM_ADDR 0x5b
29
Patrick Rudolph69d5ef92018-11-11 12:43:48 +010030unsigned long qemu_get_high_memory_size(void)
31{
32 unsigned long high;
33 outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT);
34 high = ((unsigned long) inb(CMOS_DATA_PORT)) << 22;
35 outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT);
36 high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 14;
37 outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT);
38 high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6;
39 return high;
40}
41
42unsigned long qemu_get_memory_size(void)
Stefan Reinauer597ff872013-01-07 13:21:22 -080043{
44 unsigned long tomk;
Patrick Rudolph69d5ef92018-11-11 12:43:48 +010045 outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
Stefan Reinauer597ff872013-01-07 13:21:22 -080046 tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14;
Patrick Rudolph69d5ef92018-11-11 12:43:48 +010047 outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
Stefan Reinauer597ff872013-01-07 13:21:22 -080048 tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6;
49 tomk += 16 * 1024;
50 return tomk;
51}
52
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020053void *cbmem_top(void)
Stefan Reinauer597ff872013-01-07 13:21:22 -080054{
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020055 return (void *) (qemu_get_memory_size() * 1024);
Stefan Reinauer597ff872013-01-07 13:21:22 -080056}