Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 5 | #include <arch/ebda.h> |
Ryan Salsamendi | f511c1f | 2017-06-16 13:15:31 -0700 | [diff] [blame] | 6 | #include <commonlib/endian.h> |
Subrata Banik | 19dbffd | 2017-09-10 20:06:22 +0530 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | |
| 9 | static void *get_ebda_start(void) |
| 10 | { |
| 11 | return (void *)((uintptr_t)DEFAULT_EBDA_SEGMENT << 4); |
| 12 | } |
| 13 | |
Subrata Banik | 19dbffd | 2017-09-10 20:06:22 +0530 | [diff] [blame] | 14 | /* |
| 15 | * EBDA area is representing a 1KB memory area just below |
| 16 | * the top of conventional memory (below 1MB) |
| 17 | */ |
| 18 | |
Arthur Heymans | 8b7cd43 | 2019-10-26 20:31:41 +0200 | [diff] [blame] | 19 | static void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size) |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 20 | { |
Ryan Salsamendi | f0b0712 | 2017-06-09 12:01:39 -0700 | [diff] [blame] | 21 | u16 low_memory_kb; |
| 22 | u16 ebda_kb; |
| 23 | void *ebda; |
| 24 | |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 25 | if (!low_memory_size || !ebda_segment || !ebda_size) |
| 26 | return; |
| 27 | |
Ryan Salsamendi | f0b0712 | 2017-06-09 12:01:39 -0700 | [diff] [blame] | 28 | low_memory_kb = low_memory_size >> 10; |
| 29 | ebda_kb = ebda_size >> 10; |
Subrata Banik | 19dbffd | 2017-09-10 20:06:22 +0530 | [diff] [blame] | 30 | ebda = get_ebda_start(); |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 31 | |
Ryan Salsamendi | f0b0712 | 2017-06-09 12:01:39 -0700 | [diff] [blame] | 32 | /* clear BIOS DATA AREA */ |
Ryan Salsamendi | f511c1f | 2017-06-16 13:15:31 -0700 | [diff] [blame] | 33 | zero_n(X86_BDA_BASE, X86_BDA_SIZE); |
Ryan Salsamendi | f0b0712 | 2017-06-09 12:01:39 -0700 | [diff] [blame] | 34 | |
| 35 | /* Avoid unaligned write16() since it's undefined behavior */ |
Ryan Salsamendi | f511c1f | 2017-06-16 13:15:31 -0700 | [diff] [blame] | 36 | write_le16(X86_EBDA_LOWMEM, low_memory_kb); |
| 37 | write_le16(X86_EBDA_SEGMENT, ebda_segment); |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 38 | |
| 39 | /* Set up EBDA */ |
Ryan Salsamendi | f511c1f | 2017-06-16 13:15:31 -0700 | [diff] [blame] | 40 | zero_n(ebda, ebda_size); |
| 41 | write_le16(ebda, ebda_kb); |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void setup_default_ebda(void) |
| 45 | { |
Arthur Heymans | 804adaa | 2019-01-09 18:30:33 +0100 | [diff] [blame] | 46 | if (acpi_is_wakeup_s3()) |
| 47 | return; |
| 48 | |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 49 | setup_ebda(DEFAULT_EBDA_LOWMEM, |
| 50 | DEFAULT_EBDA_SEGMENT, |
| 51 | DEFAULT_EBDA_SIZE); |
| 52 | } |