microcode.c revision a31148363f598def767ac48c5d82e1572e44b935
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * CDDL HEADER START
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * The contents of this file are subject to the terms of the
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Common Development and Distribution License (the "License").
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * You may not use this file except in compliance with the License.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * See the License for the specific language governing permissions
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * and limitations under the License.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * When distributing Covered Code, include this CDDL HEADER in each
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * If applicable, add the following below this CDDL HEADER, with the
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * fields enclosed by brackets "[]" replaced with your own identifying
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * information: Portions Copyright [yyyy] [name of copyright owner]
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * CDDL HEADER END
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Use is subject to license terms.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * AMD-specific equivalence table
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * mcpu_ucode_info for the boot CPU. Statically allocated.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void* ucode_zalloc(processorid_t, size_t);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void ucode_free(processorid_t, void *, size_t);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic ucode_errno_t ucode_extract_amd(ucode_update_t *, uint8_t *, int);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic ucode_errno_t ucode_extract_intel(ucode_update_t *, uint8_t *,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void ucode_file_reset_amd(ucode_file_t *, processorid_t);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void ucode_file_reset_intel(ucode_file_t *, processorid_t);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic uint32_t ucode_load_amd(ucode_file_t *, cpu_ucode_info_t *, cpu_t *);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic uint32_t ucode_load_intel(ucode_file_t *, cpu_ucode_info_t *, cpu_t *);
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnsonstatic int ucode_equiv_cpu_amd(cpu_t *, uint16_t *);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic ucode_errno_t ucode_locate_amd(cpu_t *, cpu_ucode_info_t *,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic ucode_errno_t ucode_locate_intel(cpu_t *, cpu_ucode_info_t *,
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnsonstatic ucode_errno_t ucode_match_amd(uint16_t, cpu_ucode_info_t *,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic ucode_errno_t ucode_match_intel(int, cpu_ucode_info_t *,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_header_intel_t *, ucode_ext_table_intel_t *);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void ucode_read_rev_amd(cpu_ucode_info_t *);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonstatic void ucode_read_rev_intel(cpu_ucode_info_t *);
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrymstatic const char ucode_failure_fmt[] =
88699bdd7d55fd959cedd294efadffd7589fb9fasherrym "cpu%d: failed to update microcode from version 0x%x to 0x%x\n";
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrymstatic const char ucode_success_fmt[] =
88699bdd7d55fd959cedd294efadffd7589fb9fasherrym "?cpu%d: microcode has been updated from version 0x%x to 0x%x\n";
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Force flag. If set, the first microcode binary that matches
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * signature and platform id will be used for microcode update,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * regardless of version. Should only be used for debugging.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Allocate space for mcpu_ucode_info in the machcpu structure
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * for all non-boot CPUs.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym kmem_zalloc(sizeof (*cp->cpu_m.mcpu_ucode_info), KM_SLEEP);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(cp->cpu_m.mcpu_ucode_info != &cpu_ucode_info0);
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Called when we are done with microcode update on all processors to free up
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * space allocated for the microcode file.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Allocate/free a buffer used to hold ucode data. Space for the boot CPU is
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * allocated with BOP_ALLOC() and does not require a free.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* BOP_ALLOC() failure results in panic */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson return (BOP_ALLOC(bootops, NULL, size, MMU_PAGESIZE));
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_free(processorid_t id, void* buf, size_t size)
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Check whether or not a processor is capable of microcode operations
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Returns 1 if it is capable, 0 if not.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * At this point we only support microcode update for:
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * - Intel processors family 6 and above, and
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * - AMD processors family 0x10 and above.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * We also assume that we don't support a mix of Intel and
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * AMD processors in the same box.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * An i86xpv guest domain can't update the microcode.
b9bfdccda8a7c490cc133ece2ab92d914e10b8d7Stuart Maybee if (hwenv == HW_XEN_HVM || (hwenv == HW_XEN_PV && !is_controldom())) {
843e19887f64dde75055cf8842fc4db2171eff45johnlev return (0);
b9bfdccda8a7c490cc133ece2ab92d914e10b8d7Stuart Maybee if (hwenv == HW_XEN_HVM || (hwenv == HW_XEN_PV && !is_controldom())) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Called when it is no longer necessary to keep the microcode around,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * or when the cached microcode doesn't match the CPU being processed.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_file_reset_amd(ucode_file_t *ufp, processorid_t id)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_free(id, ucodefp, sizeof (ucode_file_amd_t));
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_file_reset_intel(ucode_file_t *ufp, processorid_t id)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (ucodefp == NULL || ucodefp->uf_header == NULL)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson total_size = UCODE_TOTAL_SIZE_INTEL(ucodefp->uf_header->uh_total_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson body_size = UCODE_BODY_SIZE_INTEL(ucodefp->uf_header->uh_body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson int size = total_size - body_size - UCODE_HEADER_SIZE_INTEL;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_free(id, ucodefp->uf_header, UCODE_HEADER_SIZE_INTEL);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Find the equivalent CPU id in the equivalence table.
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnsonucode_equiv_cpu_amd(cpu_t *cp, uint16_t *eq_sig)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson (void) snprintf(name, MAXPATHLEN, "/%s/%s/equivalence-table",
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * No kmem_zalloc() etc. available on boot cpu.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* ucode_zalloc() cannot fail on boot cpu */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson eqtbl = ucode_zalloc(cp->cpu_id, sizeof (*eqtbl));
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson } while (eqtbl->ue_inst_cpu && eqtbl->ue_inst_cpu != cpi_sig);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * If not already done, load the equivalence table.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Not done on boot CPU.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if ((eq = kobj_open_file(name)) == (struct _buf *)-1)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_eqtbl_amd = kmem_zalloc(size, KM_NOSLEEP);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson count = kobj_read_file(eq, (char *)ucode_eqtbl_amd, size, 0);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* Get the equivalent CPU id. */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson eqtbl->ue_inst_cpu && eqtbl->ue_inst_cpu != cpi_sig;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* No equivalent CPU id found, assume outdated microcode file. */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * xVM cannot check for the presence of PCI devices. Look for chipset-
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * specific microcode patches in the container file and disable them
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * by setting their CPU revision to an invalid value.
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson /* skip to first microcode patch */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson ptr += 2; len = *ptr++; ptr += len >> 2; size -= len;
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson while (size >= sizeof (ucode_header_amd_t) + 8) {
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson cmn_err(CE_WARN, "ignoring northbridge-specific ucode: "
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson "chipset id %x, revision %x",
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson cmn_err(CE_WARN, "ignoring southbridge-specific ucode: "
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson "chipset id %x, revision %x",
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Populate the ucode file structure from microcode file corresponding to
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * this CPU, if exists.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Return EM_OK on success, corresponding error code on failure.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_locate_amd(cpu_t *cp, cpu_ucode_info_t *uinfop, ucode_file_t *ufp)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* get equivalent CPU id */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if ((rc = ucode_equiv_cpu_amd(cp, &eq_sig)) != EM_OK)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Allocate a buffer for the microcode patch. If the buffer has been
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * allocated before, check for a matching microcode to avoid loading
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * the file again.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucodefp = ucode_zalloc(cp->cpu_id, sizeof (*ucodefp));
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson else if (ucode_match_amd(eq_sig, uinfop, ucodefp, sizeof (*ucodefp))
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Find the patch for this CPU. The patch files are named XXXX-YY, where
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * XXXX is the equivalent CPU id and YY is the running patch number.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Patches specific to certain chipsets are guaranteed to have lower
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * numbers than less specific patches, so we can just load the first
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * patch that matches.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson for (i = 0; i < 0xff; i++) {
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson (void) snprintf(name, MAXPATHLEN, "/%s/%s/%04X-%02X",
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson UCODE_INSTALL_PATH, cpuid_getvendorstr(cp), eq_sig, i);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson count = kobj_read(fd, (char *)ucodefp, sizeof (*ucodefp), 0);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (ucode_match_amd(eq_sig, uinfop, ucodefp, count) == EM_OK)
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * The xVM case is special. To support mixed-revision systems, the
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * hypervisor will choose which patch to load for which CPU, so the
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * whole microcode patch container file will have to be loaded.
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * Since this code is only run on the boot cpu, we don't have to care
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * about failing ucode_zalloc() or freeing allocated memory.
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson (void) snprintf(name, MAXPATHLEN, "/%s/%s/container",
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson /* get the file size by counting bytes */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson ucodefp = ucode_zalloc(cp->cpu_id, sizeof (*ucodefp));
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson ucodefp->ucodep = ucode_zalloc(cp->cpu_id, size);
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson /* load the microcode patch container file */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson count = kobj_read(fd, (char *)ucodefp->ucodep, size, 0);
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson /* make sure the container file is valid */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson rc = ucode->validate(ucodefp->ucodep, ucodefp->usize);
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson /* disable chipset-specific patches */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson ucode_chipset_amd(ucodefp->ucodep, ucodefp->usize);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_locate_intel(cpu_t *cp, cpu_ucode_info_t *uinfop, ucode_file_t *ufp)
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * If the microcode matches the CPU we are processing, use it.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (ucode_match_intel(cpi_sig, uinfop, ucodefp->uf_header,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym ucodefp->uf_ext_table) == EM_OK && ucodefp->uf_body != NULL) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Look for microcode file with the right name.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym (void) snprintf(name, MAXPATHLEN, "/%s/%s/%08X-%02X",
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym UCODE_INSTALL_PATH, cpuid_getvendorstr(cp), cpi_sig,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * We found a microcode file for the CPU we are processing,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * reset the microcode data structure and read in the new
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucodefp->uf_header = ucode_zalloc(cp->cpu_id, header_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson count = kobj_read(fd, (char *)ucodefp->uf_header, header_size, 0);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_header_intel_t *uhp = ucodefp->uf_header;
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Make sure that the header contains valid fields.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if ((rc = ucode_header_validate_intel(uhp)) == EM_OK) {
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson total_size = UCODE_TOTAL_SIZE_INTEL(uhp->uh_total_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson body_size = UCODE_BODY_SIZE_INTEL(uhp->uh_body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucodefp->uf_body = ucode_zalloc(cp->cpu_id, body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (ucode_checksum_intel(sum, body_size, ucodefp->uf_body)) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Check to see if there is extended signature table.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucodefp->uf_ext_table = ucode_zalloc(cp->cpu_id, ext_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson rc = ucode_match_intel(cpi_sig, uinfop, ucodefp->uf_header,
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnsonucode_match_amd(uint16_t eq_sig, cpu_ucode_info_t *uinfop,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (ucodefp == NULL || size < sizeof (ucode_header_amd_t))
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Don't even think about loading patches that would require code
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * execution.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (size > offsetof(ucode_file_amd_t, uf_code_present) &&
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson cmn_err(CE_WARN, "ignoring northbridge-specific ucode: "
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson "chipset id %x, revision %x", uh->uh_nb_id, uh->uh_nb_rev);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson cmn_err(CE_WARN, "ignoring southbridge-specific ucode: "
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson "chipset id %x, revision %x", uh->uh_sb_id, uh->uh_sb_rev);
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Returns 1 if the microcode is for this processor; 0 otherwise.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_match_intel(int cpi_sig, cpu_ucode_info_t *uinfop,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_header_intel_t *uhp, ucode_ext_table_intel_t *uetp)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (UCODE_MATCH_INTEL(cpi_sig, uhp->uh_signature,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym if (uinfop->cui_rev >= uhp->uh_rev && !ucode_force_update)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if (UCODE_MATCH_INTEL(cpi_sig, uesp->ues_signature,
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym/*ARGSUSED*/
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrymucode_write(xc_arg_t arg1, xc_arg_t unused2, xc_arg_t unused3)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson cpu_ucode_info_t *uinfop = CPU->cpu_m.mcpu_ucode_info;
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Check one more time to see if it is really necessary to update
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * microcode just in case this is a hyperthreaded processor where
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * the threads share the same microcode.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym return (0);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson wrmsr(ucode->write_msr, (uintptr_t)uusp->ucodep);
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym return (0);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_load_amd(ucode_file_t *ufp, cpu_ucode_info_t *uinfop, cpu_t *cp)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson/*ARGSUSED2*/
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_load_intel(ucode_file_t *ufp, cpu_ucode_info_t *uinfop, cpu_t *cp)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * the hypervisor wants the header, data, and extended
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * signature tables. We can only get here from the boot
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * CPU (cpu #0), we don't need to free as ucode_zalloc() will
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * use BOP_ALLOC().
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson usize = UCODE_TOTAL_SIZE_INTEL(ucodefp->uf_header->uh_total_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson body_size = UCODE_BODY_SIZE_INTEL(ucodefp->uf_header->uh_body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ext_offset = body_size + UCODE_HEADER_SIZE_INTEL;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson (void) memcpy(ustart, ucodefp->uf_header, UCODE_HEADER_SIZE_INTEL);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson (void) memcpy(&ustart[UCODE_HEADER_SIZE_INTEL], ucodefp->uf_body,
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson wrmsr(ucode->write_msr, (uintptr_t)ucodefp->uf_body);
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson op.interface_version = XENPF_INTERFACE_VERSION;
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson /*LINTED: constant in conditional context*/
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson set_xen_guest_handle(op.u.microcode.data, uusp->ucodep);
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson if (e != 0) {
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson cmn_err(CE_WARN, "hypervisor failed to accept uCode update");
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson#endif /* __xpv */
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * The Intel 64 and IA-32 Architecture Software Developer's Manual
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * recommends that MSR_INTC_UCODE_REV be loaded with 0 first, then
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * execute cpuid to guarantee the correct reading of this register.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym uinfop->cui_rev = (rdmsr(MSR_INTC_UCODE_REV) >> INTC_UCODE_REV_SHIFT);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_extract_amd(ucode_update_t *uusp, uint8_t *ucodep, int size)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* skip over magic number & equivalence table header */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson eqtbl->ue_inst_cpu && eqtbl->ue_inst_cpu != uusp->sig;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* No equivalent CPU id found, assume outdated microcode file. */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* Use the first microcode patch that matches. */
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson rc = ucode_match_amd(eq_sig, &uusp->info, ufp, count);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson uusp->expected_rev = ufp->uf_header.uh_patch_id;
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * The hypervisor will choose the patch to load, so there is no way to
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * know the "expected revision" in advance. This is especially true on
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson * mixed-revision systems where more than one patch will be loaded.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnsonucode_extract_intel(ucode_update_t *uusp, uint8_t *ucodep, int size)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson uint32_t header_size = UCODE_HEADER_SIZE_INTEL;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_errno_t search_rc = EM_NOMATCH; /* search result */
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Go through the whole buffer in case there are
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * multiple versions of matching microcode for this
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * processor.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ucode_header_intel_t *uhp = (ucode_header_intel_t *)curbuf;
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson total_size = UCODE_TOTAL_SIZE_INTEL(uhp->uh_total_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson body_size = UCODE_BODY_SIZE_INTEL(uhp->uh_body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ext_size = total_size - (header_size + body_size);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson tmprc = ucode_match_intel(uusp->sig, &uusp->info, uhp, uetp);
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * Since we are searching through a big file
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * containing microcode for pretty much all the
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * processors, we are bound to get EM_NOMATCH
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * at one point. However, if we return
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * EM_NOMATCH to users, it will really confuse
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * them. Therefore, if we ever find a match of
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * a lower rev, we will set return code to
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson * EM_HIGHERREV.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson uusp->ucodep = (uint8_t *)&curbuf[header_size];
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Entry point to microcode update from the ucode_drv driver.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Returns EM_OK on success, corresponding error code on failure.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym ucode_errno_t search_rc = EM_NOMATCH; /* search result */
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * If there is no such CPU or it is not xcall ready, skip it.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * If the current CPU has the same signature and platform
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * id as the previous one we processed, reuse the information.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym cachedp->info.cui_platid == uusp->info.cui_platid) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Intuitively we should check here to see whether the
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * running microcode rev is >= the expected rev, and
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * quit if it is. But we choose to proceed with the
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * xcall regardless of the running version so that
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * the other threads in an HT processor can update
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * the cpu_ucode_info structure in machcpu.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson } else if ((search_rc = ucode->extract(uusp, ucodep, size))
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym /* Nothing to do */
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson * for i86xpv, the hypervisor will update all the CPUs.
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson * the hypervisor wants the header, data, and extended
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson * signature tables. ucode_write will just read in the
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson * updated version on all the CPUs after the update has
882a7af5ebaf4ff499b73f69bef1ae833f507418Mark Johnson * completed.
f34a71784df3fbc5d1227a7b6201fd318ad1667eJoe Bonasera xc_sync((xc_arg_t)uusp, 0, 0, CPUSET2BV(cpuset), ucode_write);
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson if (uusp->new_rev != 0 && uusp->info.cui_rev == uusp->new_rev) {
0ba6f73dcd1c9160a44b2872ed0e0d81b51d168fMark Johnson } else if ((uusp->new_rev == 0) || (uusp->expected_rev != 0 &&
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Initialize mcpu_ucode_info, and perform microcode update if necessary.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * This is the entry point from boot path where pointer to CPU structure
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * is available.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * cpuid_info must be initialized before ucode_check can be called.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Space statically allocated for BSP, ensure pointer is set
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (cp->cpu_id == 0 && cp->cpu_m.mcpu_ucode_info == NULL)
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson /* set up function pointers if not already done */
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * The MSR_INTC_PLATFORM_ID is supported in Celeron and Xeon
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * (Family 6, model 5 and above) and all processors after.
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if ((cpuid_getvendor(cp) == X86_VENDOR_Intel) &&
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson ((cpuid_getmodel(cp) >= 5) || (cpuid_getfamily(cp) > 6))) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym uinfop->cui_platid = 1 << ((rdmsr(MSR_INTC_PLATFORM_ID) >>
c9b5d7d22ea8bfd18ef2f988a885f1cb268f2ec7Mark Johnson * for i86xpv, the hypervisor will update all the CPUs. We only need
c9b5d7d22ea8bfd18ef2f988a885f1cb268f2ec7Mark Johnson * do do this on one of the CPUs (and there always is a CPU 0).
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Check to see if we need ucode update
adc586debf12d2592024c0b8b9e44ffa104f858cMark Johnson if ((rc = ucode->locate(cp, uinfop, &ucodefile)) == EM_OK) {
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * If we fail to find a match for any reason, free the file structure
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * just in case we have read in a partial file.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Since the scratch memory for holding the microcode for the boot CPU
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * came from BOP_ALLOC, we will reset the data structure as if we
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * never did the allocation so we don't have to keep track of this
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * special chunk of memory. We free the memory used for the rest
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * of the CPUs in start_other_cpus().
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym * Returns microcode revision from the machcpu structure.
2449e17f82f6097fd2c665b64723e31ceecbeca6sherrym for (i = 0; i < max_ncpus; i++) {