mb/google/nissa/var/rull: Configure Acoustic noise mitigation
[coreboot2.git] / src / soc / amd / common / block / acpimmio / biosram.c
blob76f24e00824376165621d87b1b0b95bd2aa2498e
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/acpimmio.h>
4 #include <amdblocks/biosram.h>
5 #include <device/mmio.h>
6 #include <stdint.h>
8 /* BiosRam Ranges at 0xfed80500 or I/O 0xcd4/0xcd5 */
9 #define BIOSRAM_AP_ENTRY 0xe8 /* 8 bytes */
10 #define BIOSRAM_CBMEM_TOP 0xf0 /* 4 bytes */
11 #define BIOSRAM_UMA_SIZE 0xf4 /* 4 bytes */
12 #define BIOSRAM_UMA_BASE 0xf8 /* 8 bytes */
14 static uint8_t biosram_read8(uint8_t reg)
16 return read8(acpimmio_biosram + reg);
19 static void biosram_write8(uint8_t reg, uint8_t value)
21 write8(acpimmio_biosram + reg, value);
24 static uint16_t biosram_read16(uint8_t reg) /* Must be 1 byte at a time */
26 return (biosram_read8(reg + sizeof(uint8_t)) << 8 | biosram_read8(reg));
29 static void biosram_write16(uint8_t reg, uint16_t value)
31 biosram_write8(reg, value & 0xff);
32 value >>= 8;
33 biosram_write8(reg + sizeof(uint8_t), value & 0xff);
36 static uint32_t biosram_read32(uint8_t reg)
38 uint32_t value = biosram_read16(reg + sizeof(uint16_t)) << 16;
39 return value | biosram_read16(reg);
42 static void biosram_write32(uint8_t reg, uint32_t value)
44 biosram_write16(reg, value & 0xffff);
45 value >>= 16;
46 biosram_write16(reg + sizeof(uint16_t), value & 0xffff);
49 /* Access to BIOSRAM is only allowed through the abstractions below. */
51 void *get_ap_entry_ptr(void)
53 return (void *)biosram_read32(BIOSRAM_AP_ENTRY);
56 void set_ap_entry_ptr(void *entry)
58 biosram_write32(BIOSRAM_AP_ENTRY, (uintptr_t)entry);
61 void backup_top_of_low_cacheable(uintptr_t ramtop)
63 biosram_write32(BIOSRAM_CBMEM_TOP, ramtop);
66 uintptr_t restore_top_of_low_cacheable(void)
68 return biosram_read32(BIOSRAM_CBMEM_TOP);
71 void save_uma_size(uint32_t size)
73 biosram_write32(BIOSRAM_UMA_SIZE, size);
76 void save_uma_base(uint64_t base)
78 biosram_write32(BIOSRAM_UMA_BASE, (uint32_t)base);
79 biosram_write32(BIOSRAM_UMA_BASE + 4, (uint32_t)(base >> 32));
82 uint32_t get_uma_size(void)
84 return biosram_read32(BIOSRAM_UMA_SIZE);
87 uint64_t get_uma_base(void)
89 uint64_t base;
90 base = biosram_read32(BIOSRAM_UMA_BASE);
91 base |= ((uint64_t)(biosram_read32(BIOSRAM_UMA_BASE + 4)) << 32);
92 return base;