Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 2 | /* |
| 3 | * From Coreboot src/southbridge/intel/bd82x6x/early_me.c |
| 4 | * |
| 5 | * Copyright (C) 2011 The Chromium OS Authors. All rights reserved. |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Bin Meng | af5b8d2 | 2018-07-19 03:07:33 -0700 | [diff] [blame] | 12 | #include <sysreset.h> |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 13 | #include <asm/pci.h> |
Simon Glass | 43a5034 | 2016-01-17 16:11:58 -0700 | [diff] [blame] | 14 | #include <asm/cpu.h> |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 15 | #include <asm/processor.h> |
| 16 | #include <asm/arch/me.h> |
| 17 | #include <asm/arch/pch.h> |
| 18 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 20 | |
| 21 | static const char *const me_ack_values[] = { |
| 22 | [ME_HFS_ACK_NO_DID] = "No DID Ack received", |
| 23 | [ME_HFS_ACK_RESET] = "Non-power cycle reset", |
| 24 | [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset", |
| 25 | [ME_HFS_ACK_S3] = "Go to S3", |
| 26 | [ME_HFS_ACK_S4] = "Go to S4", |
| 27 | [ME_HFS_ACK_S5] = "Go to S5", |
| 28 | [ME_HFS_ACK_GBL_RESET] = "Global Reset", |
| 29 | [ME_HFS_ACK_CONTINUE] = "Continue to boot" |
| 30 | }; |
| 31 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 32 | int intel_early_me_init(struct udevice *me_dev) |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 33 | { |
| 34 | int count; |
| 35 | struct me_uma uma; |
| 36 | struct me_hfs hfs; |
| 37 | |
| 38 | debug("Intel ME early init\n"); |
| 39 | |
| 40 | /* Wait for ME UMA SIZE VALID bit to be set */ |
| 41 | for (count = ME_RETRY; count > 0; --count) { |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 42 | pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 43 | if (uma.valid) |
| 44 | break; |
| 45 | udelay(ME_DELAY); |
| 46 | } |
| 47 | if (!count) { |
| 48 | printf("ERROR: ME is not ready!\n"); |
| 49 | return -EBUSY; |
| 50 | } |
| 51 | |
| 52 | /* Check for valid firmware */ |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 53 | pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 54 | if (hfs.fpt_bad) { |
| 55 | printf("WARNING: ME has bad firmware\n"); |
| 56 | return -EBADF; |
| 57 | } |
| 58 | |
| 59 | debug("Intel ME firmware is ready\n"); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 64 | int intel_early_me_uma_size(struct udevice *me_dev) |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 65 | { |
| 66 | struct me_uma uma; |
| 67 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 68 | pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 69 | if (uma.valid) { |
| 70 | debug("ME: Requested %uMB UMA\n", uma.size); |
| 71 | return uma.size; |
| 72 | } |
| 73 | |
| 74 | debug("ME: Invalid UMA size\n"); |
| 75 | return -EINVAL; |
| 76 | } |
| 77 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 78 | static inline void set_global_reset(struct udevice *dev, int enable) |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 79 | { |
| 80 | u32 etr3; |
| 81 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 82 | dm_pci_read_config32(dev, ETR3, &etr3); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 83 | |
| 84 | /* Clear CF9 Without Resume Well Reset Enable */ |
| 85 | etr3 &= ~ETR3_CWORWRE; |
| 86 | |
| 87 | /* CF9GR indicates a Global Reset */ |
| 88 | if (enable) |
| 89 | etr3 |= ETR3_CF9GR; |
| 90 | else |
| 91 | etr3 &= ~ETR3_CF9GR; |
| 92 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 93 | dm_pci_write_config32(dev, ETR3, etr3); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 96 | int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev, |
| 97 | uint status) |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 98 | { |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 99 | int count; |
| 100 | u32 mebase_l, mebase_h; |
| 101 | struct me_hfs hfs; |
| 102 | struct me_did did = { |
| 103 | .init_done = ME_INIT_DONE, |
| 104 | .status = status |
| 105 | }; |
| 106 | |
| 107 | /* MEBASE from MESEG_BASE[35:20] */ |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 108 | dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l); |
| 109 | dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 110 | mebase_h &= 0xf; |
| 111 | did.uma_base = (mebase_l >> 20) | (mebase_h << 12); |
| 112 | |
| 113 | /* Send message to ME */ |
| 114 | debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n", |
| 115 | status, did.uma_base); |
| 116 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 117 | pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 118 | |
| 119 | /* Must wait for ME acknowledgement */ |
| 120 | for (count = ME_RETRY; count > 0; --count) { |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 121 | pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 122 | if (hfs.bios_msg_ack) |
| 123 | break; |
| 124 | udelay(ME_DELAY); |
| 125 | } |
| 126 | if (!count) { |
| 127 | printf("ERROR: ME failed to respond\n"); |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 128 | return -ETIMEDOUT; |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* Return the requested BIOS action */ |
| 132 | debug("ME: Requested BIOS Action: %s\n", me_ack_values[hfs.ack_data]); |
| 133 | |
| 134 | /* Check status after acknowledgement */ |
Simon Glass | b67be7e | 2016-03-11 22:07:00 -0700 | [diff] [blame] | 135 | intel_me_status(me_dev); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 136 | |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 137 | switch (hfs.ack_data) { |
| 138 | case ME_HFS_ACK_CONTINUE: |
| 139 | /* Continue to boot */ |
| 140 | return 0; |
| 141 | case ME_HFS_ACK_RESET: |
| 142 | /* Non-power cycle reset */ |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 143 | set_global_reset(dev, 0); |
Bin Meng | af5b8d2 | 2018-07-19 03:07:33 -0700 | [diff] [blame] | 144 | sysreset_walk_halt(SYSRESET_COLD); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 145 | break; |
| 146 | case ME_HFS_ACK_PWR_CYCLE: |
| 147 | /* Power cycle reset */ |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 148 | set_global_reset(dev, 0); |
Bin Meng | af5b8d2 | 2018-07-19 03:07:33 -0700 | [diff] [blame] | 149 | sysreset_walk_halt(SYSRESET_COLD); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 150 | break; |
| 151 | case ME_HFS_ACK_GBL_RESET: |
| 152 | /* Global reset */ |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 153 | set_global_reset(dev, 1); |
Bin Meng | af5b8d2 | 2018-07-19 03:07:33 -0700 | [diff] [blame] | 154 | sysreset_walk_halt(SYSRESET_COLD); |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 155 | break; |
| 156 | case ME_HFS_ACK_S3: |
| 157 | case ME_HFS_ACK_S4: |
| 158 | case ME_HFS_ACK_S5: |
| 159 | break; |
| 160 | } |
| 161 | |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 162 | return -EINVAL; |
Simon Glass | 268eefd | 2014-11-12 22:42:28 -0700 | [diff] [blame] | 163 | } |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 164 | |
| 165 | static const struct udevice_id ivybridge_syscon_ids[] = { |
Simon Glass | 43a5034 | 2016-01-17 16:11:58 -0700 | [diff] [blame] | 166 | { .compatible = "intel,me", .data = X86_SYSCON_ME }, |
Simon Glass | 37a91ff | 2016-01-17 16:11:50 -0700 | [diff] [blame] | 167 | { } |
| 168 | }; |
| 169 | |
| 170 | U_BOOT_DRIVER(syscon_intel_me) = { |
| 171 | .name = "intel_me_syscon", |
| 172 | .id = UCLASS_SYSCON, |
| 173 | .of_match = ivybridge_syscon_ids, |
| 174 | }; |