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