#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
#define UCODE_UCODE_TYPE 0x00000001
-struct microcode_amd {
+struct microcode_patch {
void *mpb;
size_t mpb_size;
struct equiv_cpu_entry *equiv_cpu_table;
size_t equiv_cpu_table_size;
};
+/* Temporary, until the microcode_* structure are disentangled. */
+#define microcode_amd microcode_patch
+
struct mpbhdr {
uint32_t type;
uint32_t len;
static bool match_cpu(const struct microcode_patch *patch)
{
- return patch && (microcode_fits(patch->mc_amd) == NEW_UCODE);
+ return patch && (microcode_fits(patch) == NEW_UCODE);
}
-static void free_patch(void *mc)
+static void free_patch(struct microcode_patch *mc_amd)
{
- struct microcode_amd *mc_amd = mc;
-
if ( mc_amd )
{
xfree(mc_amd->equiv_cpu_table);
static enum microcode_match_result compare_patch(
const struct microcode_patch *new, const struct microcode_patch *old)
{
- const struct microcode_header_amd *new_header = new->mc_amd->mpb;
- const struct microcode_header_amd *old_header = old->mc_amd->mpb;
+ const struct microcode_header_amd *new_header = new->mpb;
+ const struct microcode_header_amd *old_header = old->mpb;
/* Both patches to compare are supposed to be applicable to local CPU. */
- ASSERT(microcode_fits(new->mc_amd) != MIS_UCODE);
- ASSERT(microcode_fits(old->mc_amd) != MIS_UCODE);
+ ASSERT(microcode_fits(new) != MIS_UCODE);
+ ASSERT(microcode_fits(old) != MIS_UCODE);
return compare_header(new_header, old_header);
}
if ( !match_cpu(patch) )
return -EINVAL;
- hdr = patch->mc_amd->mpb;
+ hdr = patch->mpb;
hw_err = wrmsr_safe(MSR_AMD_PATCHLOADER, (unsigned long)hdr);
{
mc_amd->mpb = saved;
mc_amd->mpb_size = saved_size;
- patch = xmalloc(struct microcode_patch);
- if ( patch )
- patch->mc_amd = mc_amd;
- else
- {
- free_patch(mc_amd);
- error = -ENOMEM;
- }
+ patch = mc_amd;
}
else
free_patch(mc_amd);
static void microcode_free_patch(struct microcode_patch *microcode_patch)
{
- microcode_ops->free_patch(microcode_patch->mc);
- xfree(microcode_patch);
+ microcode_ops->free_patch(microcode_patch);
}
/* Return true if cache gets updated. Otherwise, return false */
unsigned int reserved[3];
};
-struct microcode_intel {
+struct microcode_patch {
struct microcode_header_intel hdr;
unsigned int bits[0];
};
+/* Temporary, until the microcode_* structure are disentangled. */
+#define microcode_intel microcode_patch
+
/* microcode format is extended from prescott processors */
struct extended_signature {
unsigned int sig;
if ( !patch )
return false;
- return microcode_update_match(&patch->mc_intel->hdr) == NEW_UCODE;
+ return microcode_update_match(&patch->hdr) == NEW_UCODE;
}
-static void free_patch(void *mc)
+static void free_patch(struct microcode_patch *patch)
{
- xfree(mc);
+ xfree(patch);
}
static enum microcode_match_result compare_patch(
* Both patches to compare are supposed to be applicable to local CPU.
* Just compare the revision number.
*/
- ASSERT(microcode_update_match(&old->mc_intel->hdr) != MIS_UCODE);
- ASSERT(microcode_update_match(&new->mc_intel->hdr) != MIS_UCODE);
+ ASSERT(microcode_update_match(&old->hdr) != MIS_UCODE);
+ ASSERT(microcode_update_match(&new->hdr) != MIS_UCODE);
- return (new->mc_intel->hdr.rev > old->mc_intel->hdr.rev) ? NEW_UCODE
- : OLD_UCODE;
+ return (new->hdr.rev > old->hdr.rev) ? NEW_UCODE : OLD_UCODE;
}
static int apply_microcode(const struct microcode_patch *patch)
if ( !match_cpu(patch) )
return -EINVAL;
- mc_intel = patch->mc_intel;
+ mc_intel = patch;
/* write microcode via MSR 0x79 */
wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc_intel->bits);
error = offset;
if ( saved )
- {
- patch = xmalloc(struct microcode_patch);
- if ( patch )
- patch->mc_intel = saved;
- else
- {
- xfree(saved);
- error = -ENOMEM;
- }
- }
+ patch = saved;
if ( error && !patch )
patch = ERR_PTR(error);
MIS_UCODE, /* signature mismatched */
};
-struct microcode_patch {
- union {
- struct microcode_intel *mc_intel;
- struct microcode_amd *mc_amd;
- void *mc;
- };
-};
+/* Opaque. Internals are vendor-specific. */
+struct microcode_patch;
struct microcode_ops {
/*
void (*end_update_percpu)(void);
/* Free a patch previously allocated by cpu_request_microcode(). */
- void (*free_patch)(void *mc);
+ void (*free_patch)(struct microcode_patch *patch);
/*
* Is the microcode patch applicable for the current CPU, and newer than