Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
| 4 | #include <arch/io.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 5 | #include <amdblocks/acpimmio.h> |
| 6 | |
Kyösti Mälkki | 8c1e603 | 2020-06-22 18:16:39 +0300 | [diff] [blame] | 7 | #if ENV_X86 |
| 8 | #include <amdblocks/acpimmio_map.h> |
| 9 | #endif |
| 10 | |
| 11 | #if ENV_X86 && CONSTANT_ACPIMMIO_BASE_ADDRESS |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 12 | #define DECLARE_ACPIMMIO(ptr, bank) \ |
Kyösti Mälkki | 5f2f44a | 2020-06-29 23:56:50 +0300 | [diff] [blame] | 13 | uint8_t *const ptr = (void *)(uintptr_t)ACPIMMIO_BASE(bank) |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 14 | #else |
| 15 | #define DECLARE_ACPIMMIO(ptr, bank) uint8_t *ptr |
| 16 | #endif |
| 17 | |
Kyösti Mälkki | 8c1e603 | 2020-06-22 18:16:39 +0300 | [diff] [blame] | 18 | DECLARE_ACPIMMIO(acpimmio_aoac, AOAC); |
| 19 | DECLARE_ACPIMMIO(acpimmio_iomux, IOMUX); |
| 20 | DECLARE_ACPIMMIO(acpimmio_gpio0, GPIO0); |
| 21 | DECLARE_ACPIMMIO(acpimmio_misc, MISC); |
| 22 | |
| 23 | #if ENV_X86 |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 24 | DECLARE_ACPIMMIO(acpimmio_sm_pci, SM_PCI); |
| 25 | DECLARE_ACPIMMIO(acpimmio_gpio_100, GPIO_100); |
| 26 | DECLARE_ACPIMMIO(acpimmio_smi, SMI); |
| 27 | DECLARE_ACPIMMIO(acpimmio_pmio, PMIO); |
| 28 | DECLARE_ACPIMMIO(acpimmio_pmio2, PMIO2); |
| 29 | DECLARE_ACPIMMIO(acpimmio_biosram, BIOSRAM); |
| 30 | DECLARE_ACPIMMIO(acpimmio_cmosram, CMOSRAM); |
| 31 | DECLARE_ACPIMMIO(acpimmio_cmos, CMOS); |
| 32 | DECLARE_ACPIMMIO(acpimmio_acpi, ACPI); |
| 33 | DECLARE_ACPIMMIO(acpimmio_asf, ASF); |
| 34 | DECLARE_ACPIMMIO(acpimmio_smbus, SMBUS); |
| 35 | DECLARE_ACPIMMIO(acpimmio_wdt, WDT); |
| 36 | DECLARE_ACPIMMIO(acpimmio_hpet, HPET); |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 37 | DECLARE_ACPIMMIO(acpimmio_dpvga, DPVGA); |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 38 | DECLARE_ACPIMMIO(acpimmio_xhci_pm, XHCIPM); |
| 39 | DECLARE_ACPIMMIO(acpimmio_acdc_tmr, ACDCTMR); |
Kyösti Mälkki | 8c1e603 | 2020-06-22 18:16:39 +0300 | [diff] [blame] | 40 | #endif |
Kyösti Mälkki | be1ff7e | 2020-06-04 13:36:53 +0300 | [diff] [blame] | 41 | |
| 42 | #undef DECLARE_ACPIMMIO |
Kyösti Mälkki | 5b672d5 | 2019-11-25 21:23:37 +0200 | [diff] [blame] | 43 | |
Michał Żygowski | 73a544d | 2019-11-24 14:16:34 +0100 | [diff] [blame] | 44 | void enable_acpimmio_decode_pm24(void) |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 45 | { |
| 46 | uint32_t dw; |
| 47 | |
Michał Żygowski | 73a544d | 2019-11-24 14:16:34 +0100 | [diff] [blame] | 48 | dw = pm_io_read32(ACPIMMIO_DECODE_REGISTER_24); |
| 49 | dw |= PM_24_ACPIMMIO_DECODE_EN; |
| 50 | pm_io_write32(ACPIMMIO_DECODE_REGISTER_24, dw); |
| 51 | } |
| 52 | |
| 53 | void enable_acpimmio_decode_pm04(void) |
| 54 | { |
| 55 | uint32_t dw; |
| 56 | |
| 57 | dw = pm_io_read32(ACPIMMIO_DECODE_REGISTER_04); |
| 58 | dw |= PM_04_ACPIMMIO_DECODE_EN; |
| 59 | pm_io_write32(ACPIMMIO_DECODE_REGISTER_04, dw); |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 60 | } |
| 61 | |
Felix Held | 26935d1 | 2020-12-08 00:40:04 +0100 | [diff] [blame] | 62 | void fch_enable_cf9_io(void) |
| 63 | { |
| 64 | pm_write32(PM_DECODE_EN, pm_read32(PM_DECODE_EN) | CF9_IO_EN); |
| 65 | } |
| 66 | |
| 67 | void fch_enable_legacy_io(void) |
| 68 | { |
| 69 | pm_write32(PM_DECODE_EN, pm_read32(PM_DECODE_EN) | LEGACY_IO_EN); |
| 70 | } |
| 71 | |
Raul E Rangel | 69ff428 | 2021-02-24 16:17:54 -0700 | [diff] [blame^] | 72 | void fch_disable_legacy_dma_io(void) |
| 73 | { |
| 74 | pm_write32(PM_DECODE_EN, pm_read32(PM_DECODE_EN) & |
| 75 | ~(LEGACY_DMA_IO_EN | LEGACY_DMA_IO_80_EN)); |
| 76 | } |
| 77 | |
Felix Held | 26935d1 | 2020-12-08 00:40:04 +0100 | [diff] [blame] | 78 | void fch_io_enable_legacy_io(void) |
| 79 | { |
| 80 | pm_io_write32(PM_DECODE_EN, pm_io_read32(PM_DECODE_EN) | LEGACY_IO_EN); |
| 81 | } |
| 82 | |
Felix Held | 1b33205 | 2021-02-11 03:01:18 +0100 | [diff] [blame] | 83 | void fch_enable_ioapic_decode(void) |
| 84 | { |
| 85 | pm_write32(PM_DECODE_EN, pm_read32(PM_DECODE_EN) | FCH_IOAPIC_EN); |
| 86 | } |
| 87 | |
Felix Held | 34fc29a | 2021-02-11 02:43:07 +0100 | [diff] [blame] | 88 | void fch_configure_hpet(void) |
| 89 | { |
| 90 | uint32_t reg = pm_read32(PM_DECODE_EN); |
| 91 | reg |= HPET_EN | HPET_MSI_EN; |
| 92 | reg &= ~HPET_WIDTH_SEL; /* 32 bit HPET */ |
| 93 | pm_write32(PM_DECODE_EN, reg); |
| 94 | } |
| 95 | |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 96 | /* PM registers are accessed a byte at a time via CD6/CD7 */ |
| 97 | uint8_t pm_io_read8(uint8_t reg) |
| 98 | { |
| 99 | outb(reg, PM_INDEX); |
| 100 | return inb(PM_DATA); |
| 101 | } |
| 102 | |
| 103 | uint16_t pm_io_read16(uint8_t reg) |
| 104 | { |
| 105 | return (pm_io_read8(reg + sizeof(uint8_t)) << 8) | pm_io_read8(reg); |
| 106 | } |
| 107 | |
| 108 | uint32_t pm_io_read32(uint8_t reg) |
| 109 | { |
| 110 | return (pm_io_read16(reg + sizeof(uint16_t)) << 16) | pm_io_read16(reg); |
| 111 | } |
| 112 | |
| 113 | void pm_io_write8(uint8_t reg, uint8_t value) |
| 114 | { |
| 115 | outb(reg, PM_INDEX); |
| 116 | outb(value, PM_DATA); |
| 117 | } |
| 118 | |
| 119 | void pm_io_write16(uint8_t reg, uint16_t value) |
| 120 | { |
| 121 | pm_io_write8(reg, value & 0xff); |
| 122 | value >>= 8; |
| 123 | pm_io_write8(reg + sizeof(uint8_t), value & 0xff); |
| 124 | } |
| 125 | |
| 126 | void pm_io_write32(uint8_t reg, uint32_t value) |
| 127 | { |
| 128 | pm_io_write16(reg, value & 0xffff); |
| 129 | value >>= 16; |
| 130 | pm_io_write16(reg + sizeof(uint16_t), value & 0xffff); |
| 131 | } |