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