Marc Jones | 5a4554a | 2015-09-15 12:44:37 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 The Chromium OS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc. |
| 19 | */ |
| 20 | |
| 21 | #include <arch/io.h> |
| 22 | #include <console/console.h> |
| 23 | #include <delay.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <halt.h> |
| 26 | #include <string.h> |
| 27 | #include "me.h" |
| 28 | #include "pch.h" |
| 29 | |
| 30 | static const char *me_ack_values[] = { |
| 31 | [ME_HFS_ACK_NO_DID] = "No DID Ack received", |
| 32 | [ME_HFS_ACK_RESET] = "Non-power cycle reset", |
| 33 | [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset", |
| 34 | [ME_HFS_ACK_S3] = "Go to S3", |
| 35 | [ME_HFS_ACK_S4] = "Go to S4", |
| 36 | [ME_HFS_ACK_S5] = "Go to S5", |
| 37 | [ME_HFS_ACK_GBL_RESET] = "Global Reset", |
| 38 | [ME_HFS_ACK_CONTINUE] = "Continue to boot" |
| 39 | }; |
| 40 | |
| 41 | static inline void pci_read_dword_ptr(void *ptr, int offset) |
| 42 | { |
| 43 | u32 dword = pci_read_config32(PCH_ME_DEV, offset); |
| 44 | memcpy(ptr, &dword, sizeof(dword)); |
| 45 | } |
| 46 | |
| 47 | static inline void pci_write_dword_ptr(void *ptr, int offset) |
| 48 | { |
| 49 | u32 dword = 0; |
| 50 | memcpy(&dword, ptr, sizeof(dword)); |
| 51 | pci_write_config32(PCH_ME_DEV, offset, dword); |
| 52 | } |
| 53 | |
| 54 | void intel_early_me_status(void) |
| 55 | { |
| 56 | struct me_hfs hfs; |
| 57 | struct me_gmes gmes; |
| 58 | |
| 59 | pci_read_dword_ptr(&hfs, PCI_ME_HFS); |
| 60 | pci_read_dword_ptr(&gmes, PCI_ME_GMES); |
| 61 | |
| 62 | intel_me_status(&hfs, &gmes); |
| 63 | } |
| 64 | |
| 65 | int intel_early_me_init(void) |
| 66 | { |
| 67 | int count; |
| 68 | struct me_uma uma; |
| 69 | struct me_hfs hfs; |
| 70 | |
| 71 | printk(BIOS_INFO, "Intel ME early init\n"); |
| 72 | |
| 73 | /* Wait for ME UMA SIZE VALID bit to be set */ |
| 74 | for (count = ME_RETRY; count > 0; --count) { |
| 75 | pci_read_dword_ptr(&uma, PCI_ME_UMA); |
| 76 | if (uma.valid) |
| 77 | break; |
| 78 | udelay(ME_DELAY); |
| 79 | } |
| 80 | if (!count) { |
| 81 | printk(BIOS_ERR, "ERROR: ME is not ready!\n"); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | /* Check for valid firmware */ |
| 86 | pci_read_dword_ptr(&hfs, PCI_ME_HFS); |
| 87 | if (hfs.fpt_bad) { |
| 88 | printk(BIOS_WARNING, "WARNING: ME has bad firmware\n"); |
| 89 | return -1; |
| 90 | } |
| 91 | |
| 92 | printk(BIOS_INFO, "Intel ME firmware is ready\n"); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int intel_early_me_uma_size(void) |
| 97 | { |
| 98 | struct me_uma uma; |
| 99 | |
| 100 | pci_read_dword_ptr(&uma, PCI_ME_UMA); |
| 101 | if (uma.valid) { |
| 102 | printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size); |
| 103 | return uma.size; |
| 104 | } |
| 105 | |
| 106 | printk(BIOS_DEBUG, "ME: Invalid UMA size\n"); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static inline void set_global_reset(int enable) |
| 111 | { |
| 112 | u32 etr3 = pci_read_config32(PCH_LPC_DEV, ETR3); |
| 113 | |
| 114 | /* Clear CF9 Without Resume Well Reset Enable */ |
| 115 | etr3 &= ~ETR3_CWORWRE; |
| 116 | |
| 117 | /* CF9GR indicates a Global Reset */ |
| 118 | if (enable) |
| 119 | etr3 |= ETR3_CF9GR; |
| 120 | else |
| 121 | etr3 &= ~ETR3_CF9GR; |
| 122 | |
| 123 | pci_write_config32(PCH_LPC_DEV, ETR3, etr3); |
| 124 | } |
| 125 | |
| 126 | int intel_early_me_init_done(u8 status) |
| 127 | { |
| 128 | u8 reset; |
| 129 | int count; |
| 130 | u32 mebase_l, mebase_h; |
| 131 | struct me_hfs hfs; |
| 132 | struct me_did did = { |
| 133 | .init_done = ME_INIT_DONE, |
| 134 | .status = status |
| 135 | }; |
| 136 | |
| 137 | /* MEBASE from MESEG_BASE[35:20] */ |
| 138 | mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L); |
| 139 | mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf; |
| 140 | did.uma_base = (mebase_l >> 20) | (mebase_h << 12); |
| 141 | |
| 142 | /* Send message to ME */ |
| 143 | printk(BIOS_DEBUG, "ME: Sending Init Done with status: %d, " |
| 144 | "UMA base: 0x%04x\n", status, did.uma_base); |
| 145 | |
| 146 | pci_write_dword_ptr(&did, PCI_ME_H_GS); |
| 147 | |
| 148 | /* Must wait for ME acknowledgement */ |
| 149 | for (count = ME_RETRY; count > 0; --count) { |
| 150 | pci_read_dword_ptr(&hfs, PCI_ME_HFS); |
| 151 | if (hfs.bios_msg_ack) |
| 152 | break; |
| 153 | udelay(ME_DELAY); |
| 154 | } |
| 155 | if (!count) { |
| 156 | printk(BIOS_ERR, "ERROR: ME failed to respond\n"); |
| 157 | return -1; |
| 158 | } |
| 159 | |
| 160 | /* Return the requested BIOS action */ |
| 161 | printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n", |
| 162 | me_ack_values[hfs.ack_data]); |
| 163 | |
| 164 | /* Check status after acknowledgement */ |
| 165 | intel_early_me_status(); |
| 166 | |
| 167 | reset = 0; |
| 168 | switch (hfs.ack_data) { |
| 169 | case ME_HFS_ACK_CONTINUE: |
| 170 | /* Continue to boot */ |
| 171 | return 0; |
| 172 | case ME_HFS_ACK_RESET: |
| 173 | /* Non-power cycle reset */ |
| 174 | set_global_reset(0); |
| 175 | reset = 0x06; |
| 176 | break; |
| 177 | case ME_HFS_ACK_PWR_CYCLE: |
| 178 | /* Power cycle reset */ |
| 179 | set_global_reset(0); |
| 180 | reset = 0x0e; |
| 181 | break; |
| 182 | case ME_HFS_ACK_GBL_RESET: |
| 183 | /* Global reset */ |
| 184 | set_global_reset(1); |
| 185 | reset = 0x0e; |
| 186 | break; |
| 187 | case ME_HFS_ACK_S3: |
| 188 | case ME_HFS_ACK_S4: |
| 189 | case ME_HFS_ACK_S5: |
| 190 | break; |
| 191 | } |
| 192 | |
| 193 | /* Perform the requested reset */ |
| 194 | if (reset) { |
| 195 | outb(reset, 0xcf9); |
| 196 | halt(); |
| 197 | } |
| 198 | return -1; |
| 199 | } |