* [patch 00/11] x86: AMD microcode patch loading support v2
@ 2008-07-28 16:44 Peter Oruba
2008-07-28 16:44 ` [patch 02/11] [PATCH 02/11] x86: Moved Intel microcode patch loader declarations to seperate header file Peter Oruba
` (10 more replies)
0 siblings, 11 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML
AMD microcode patch loader v2, rebased to Linux master.
Thanks,
Peter Oruba
>From peter.oruba@amd.com Mon Jul 28 18:44:47 2008
Message-Id: <20080728164447.259144113@amd.com>
User-Agent: quilt/0.46_cvs20080326-19.1
Date: Mon, 28 Jul 2008 18:44:12 +0200
From: Peter Oruba <peter.oruba@amd.com>
To: Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>,
Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
Cc: LKML <linux-kernel@vger.kernel.org>,
Peter Oruba <peter.oruba@amd.com>
Bcc: osrc-patches@elbe.amd.com
Subject: [patch 01/11] [PATCH 01/11] x86: Add entry to MAINTAINERS file
References: <20080728164411.490752571@amd.com>
Content-Disposition: inline; filename=0001-x86-Add-entry-to-MAINTAINERS-file.patch
Add an entry to the MAINTAINERS file for AMD CPU microcode
patch loading support.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
MAINTAINERS | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 03c5d6c..28f867d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -384,6 +384,11 @@ M: joerg.roedel@amd.com
L: iommu@lists.linux-foundation.org
S: Supported
+AMD MICROCODE UPDATE SUPPORT
+P: Peter Oruba
+M: peter.oruba@amd.com
+S: Supported
+
AMS (Apple Motion Sensor) DRIVER
P: Stelian Pop
M: stelian@popies.net
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 02/11] [PATCH 02/11] x86: Moved Intel microcode patch loader declarations to seperate header file.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 03/11] [PATCH 03/11] x86: Typedef removal Peter Oruba
` (9 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0002-x86-Moved-Intel-microcode-patch-loader-declarations.patch --]
[-- Type: text/plain, Size: 3123 bytes --]
Intel specific microcode declarations have been moved to a seperate header file.
There are no code changes to the code itself and no side effects to other parts.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/kernel/microcode.c | 1 +
include/asm-x86/microcode.h | 34 ++++++++++++++++++++++++++++++++++
include/asm-x86/processor.h | 35 -----------------------------------
3 files changed, 35 insertions(+), 35 deletions(-)
create mode 100644 include/asm-x86/microcode.h
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 6994c75..0d654bd 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -93,6 +93,7 @@
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
+#include <asm/microcode.h>
MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver");
MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
new file mode 100644
index 0000000..5a05568
--- /dev/null
+++ b/include/asm-x86/microcode.h
@@ -0,0 +1,34 @@
+struct microcode_header {
+ unsigned int hdrver;
+ unsigned int rev;
+ unsigned int date;
+ unsigned int sig;
+ unsigned int cksum;
+ unsigned int ldrver;
+ unsigned int pf;
+ unsigned int datasize;
+ unsigned int totalsize;
+ unsigned int reserved[3];
+};
+
+struct microcode {
+ struct microcode_header hdr;
+ unsigned int bits[0];
+};
+
+typedef struct microcode microcode_t;
+typedef struct microcode_header microcode_header_t;
+
+/* microcode format is extended from prescott processors */
+struct extended_signature {
+ unsigned int sig;
+ unsigned int pf;
+ unsigned int cksum;
+};
+
+struct extended_sigtable {
+ unsigned int count;
+ unsigned int cksum;
+ unsigned int reserved[3];
+ struct extended_signature sigs[0];
+};
diff --git a/include/asm-x86/processor.h b/include/asm-x86/processor.h
index 5f58da4..58a76f6 100644
--- a/include/asm-x86/processor.h
+++ b/include/asm-x86/processor.h
@@ -561,41 +561,6 @@ static inline void clear_in_cr4(unsigned long mask)
write_cr4(cr4);
}
-struct microcode_header {
- unsigned int hdrver;
- unsigned int rev;
- unsigned int date;
- unsigned int sig;
- unsigned int cksum;
- unsigned int ldrver;
- unsigned int pf;
- unsigned int datasize;
- unsigned int totalsize;
- unsigned int reserved[3];
-};
-
-struct microcode {
- struct microcode_header hdr;
- unsigned int bits[0];
-};
-
-typedef struct microcode microcode_t;
-typedef struct microcode_header microcode_header_t;
-
-/* microcode format is extended from prescott processors */
-struct extended_signature {
- unsigned int sig;
- unsigned int pf;
- unsigned int cksum;
-};
-
-struct extended_sigtable {
- unsigned int count;
- unsigned int cksum;
- unsigned int reserved[3];
- struct extended_signature sigs[0];
-};
-
typedef struct {
unsigned long seg;
} mm_segment_t;
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 03/11] [PATCH 03/11] x86: Typedef removal.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
2008-07-28 16:44 ` [patch 02/11] [PATCH 02/11] x86: Moved Intel microcode patch loader declarations to seperate header file Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 04/11] [PATCH 04/11] x86: Moved per CPU microcode structure declaration to header file Peter Oruba
` (8 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0003-x86-Typedef-removal.patch --]
[-- Type: text/plain, Size: 4097 bytes --]
Removed typedefs. No functional changes to the code.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/kernel/microcode.c | 24 ++++++++++++------------
include/asm-x86/microcode.h | 3 ---
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 0d654bd..74e6a77 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -102,17 +102,17 @@ MODULE_LICENSE("GPL");
#define MICROCODE_VERSION "1.14a"
#define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
-#define MC_HEADER_SIZE (sizeof (microcode_header_t)) /* 48 bytes */
+#define MC_HEADER_SIZE (sizeof (struct microcode_header)) /* 48 bytes */
#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
#define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */
#define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */
#define DWSIZE (sizeof (u32))
#define get_totalsize(mc) \
- (((microcode_t *)mc)->hdr.totalsize ? \
- ((microcode_t *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
+ (((struct microcode *)mc)->hdr.totalsize ? \
+ ((struct microcode *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
#define get_datasize(mc) \
- (((microcode_t *)mc)->hdr.datasize ? \
- ((microcode_t *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
+ (((struct microcode *)mc)->hdr.datasize ? \
+ ((struct microcode *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
#define sigmatch(s1, s2, p1, p2) \
(((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))
@@ -130,7 +130,7 @@ static struct ucode_cpu_info {
unsigned int sig;
unsigned int pf;
unsigned int rev;
- microcode_t *mc;
+ struct microcode *mc;
} ucode_cpu_info[NR_CPUS];
static void collect_cpu_info(int cpu_num)
@@ -171,7 +171,7 @@ static void collect_cpu_info(int cpu_num)
}
static inline int microcode_update_match(int cpu_num,
- microcode_header_t *mc_header, int sig, int pf)
+ struct microcode_header *mc_header, int sig, int pf)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -183,7 +183,7 @@ static inline int microcode_update_match(int cpu_num,
static int microcode_sanity_check(void *mc)
{
- microcode_header_t *mc_header = mc;
+ struct microcode_header *mc_header = mc;
struct extended_sigtable *ext_header = NULL;
struct extended_signature *ext_sig;
unsigned long total_size, data_size, ext_table_size;
@@ -268,7 +268,7 @@ static int microcode_sanity_check(void *mc)
static int get_maching_microcode(void *mc, int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- microcode_header_t *mc_header = mc;
+ struct microcode_header *mc_header = mc;
struct extended_sigtable *ext_header;
unsigned long total_size = get_totalsize(mc_header);
int ext_sigcount, i;
@@ -355,7 +355,7 @@ static unsigned int user_buffer_size; /* it's size */
static long get_next_ucode(void **mc, long offset)
{
- microcode_header_t mc_header;
+ struct microcode_header mc_header;
unsigned long total_size;
/* No more data */
@@ -497,13 +497,13 @@ MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
unsigned long size, long offset)
{
- microcode_header_t *mc_header;
+ struct microcode_header *mc_header;
unsigned long total_size;
/* No more data */
if (offset >= size)
return 0;
- mc_header = (microcode_header_t *)(buf + offset);
+ mc_header = (struct microcode_header *)(buf + offset);
total_size = get_totalsize(mc_header);
if (offset + total_size > size) {
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index 5a05568..1519ef0 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -16,9 +16,6 @@ struct microcode {
unsigned int bits[0];
};
-typedef struct microcode microcode_t;
-typedef struct microcode_header microcode_header_t;
-
/* microcode format is extended from prescott processors */
struct extended_signature {
unsigned int sig;
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 04/11] [PATCH 04/11] x86: Moved per CPU microcode structure declaration to header file.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
2008-07-28 16:44 ` [patch 02/11] [PATCH 02/11] x86: Moved Intel microcode patch loader declarations to seperate header file Peter Oruba
2008-07-28 16:44 ` [patch 03/11] [PATCH 03/11] x86: Typedef removal Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c Peter Oruba
` (7 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0004-x86-Moved-per-CPU-microcode-structure-declaration-t.patch --]
[-- Type: text/plain, Size: 1348 bytes --]
This structure will be later used by other modules as well and
needs therfore to be moved out to a header file.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/kernel/microcode.c | 8 +-------
include/asm-x86/microcode.h | 8 ++++++++
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 74e6a77..4e7b2f6 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -125,13 +125,7 @@ static DEFINE_SPINLOCK(microcode_update_lock);
/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
static DEFINE_MUTEX(microcode_mutex);
-static struct ucode_cpu_info {
- int valid;
- unsigned int sig;
- unsigned int pf;
- unsigned int rev;
- struct microcode *mc;
-} ucode_cpu_info[NR_CPUS];
+static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
static void collect_cpu_info(int cpu_num)
{
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index 1519ef0..d34a1fc 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -29,3 +29,11 @@ struct extended_sigtable {
unsigned int reserved[3];
struct extended_signature sigs[0];
};
+
+struct ucode_cpu_info {
+ int valid;
+ unsigned int sig;
+ unsigned int pf;
+ unsigned int rev;
+ struct microcode *mc;
+};
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (2 preceding siblings ...)
2008-07-28 16:44 ` [patch 04/11] [PATCH 04/11] x86: Moved per CPU microcode structure declaration to header file Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-09-07 19:08 ` Arjan van de Ven
2008-07-28 16:44 ` [patch 06/11] [PATCH 06/11] x86: Code split to two parts Peter Oruba
` (6 subsequent siblings)
10 siblings, 1 reply; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0005-x86-Moved-microcode.c-to-microcode_intel.c.patch --]
[-- Type: text/plain, Size: 49413 bytes --]
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/kernel/Makefile | 2 +-
arch/x86/kernel/microcode.c | 855 -------------------------------------
arch/x86/kernel/microcode_intel.c | 855 +++++++++++++++++++++++++++++++++++++
3 files changed, 856 insertions(+), 856 deletions(-)
delete mode 100644 arch/x86/kernel/microcode.c
create mode 100644 arch/x86/kernel/microcode_intel.c
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 3db651f..a9be2a0 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -51,7 +51,7 @@ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
obj-$(CONFIG_MCA) += mca_32.o
obj-$(CONFIG_X86_MSR) += msr.o
obj-$(CONFIG_X86_CPUID) += cpuid.o
-obj-$(CONFIG_MICROCODE) += microcode.o
+obj-$(CONFIG_MICROCODE) += microcode_intel.o
obj-$(CONFIG_PCI) += early-quirks.o
apm-y := apm_32.o
obj-$(CONFIG_APM) += apm.o
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
deleted file mode 100644
index 4e7b2f6..0000000
--- a/arch/x86/kernel/microcode.c
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
- * Intel CPU Microcode Update Driver for Linux
- *
- * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
- * 2006 Shaohua Li <shaohua.li@intel.com>
- *
- * This driver allows to upgrade microcode on Intel processors
- * belonging to IA-32 family - PentiumPro, Pentium II,
- * Pentium III, Xeon, Pentium 4, etc.
- *
- * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
- * Software Developer's Manual
- * Order Number 253668 or free download from:
- *
- * http://developer.intel.com/design/pentium4/manuals/253668.htm
- *
- * For more information, go to http://www.urbanmyth.org/microcode
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com>
- * Initial release.
- * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com>
- * Added read() support + cleanups.
- * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com>
- * Added 'device trimming' support. open(O_WRONLY) zeroes
- * and frees the saved copy of applied microcode.
- * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com>
- * Made to use devfs (/dev/cpu/microcode) + cleanups.
- * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com>
- * Added misc device support (now uses both devfs and misc).
- * Added MICROCODE_IOCFREE ioctl to clear memory.
- * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com>
- * Messages for error cases (non Intel & no suitable microcode).
- * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com>
- * Removed ->release(). Removed exclusive open and status bitmap.
- * Added microcode_rwsem to serialize read()/write()/ioctl().
- * Removed global kernel lock usage.
- * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com>
- * Write 0 to 0x8B msr and then cpuid before reading revision,
- * so that it works even if there were no update done by the
- * BIOS. Otherwise, reading from 0x8B gives junk (which happened
- * to be 0 on my machine which is why it worked even when I
- * disabled update by the BIOS)
- * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix.
- * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and
- * Tigran Aivazian <tigran@veritas.com>
- * Intel Pentium 4 processor support and bugfixes.
- * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com>
- * Bugfix for HT (Hyper-Threading) enabled processors
- * whereby processor resources are shared by all logical processors
- * in a single CPU package.
- * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and
- * Tigran Aivazian <tigran@veritas.com>,
- * Serialize updates as required on HT processors due to speculative
- * nature of implementation.
- * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
- * Fix the panic when writing zero-length microcode chunk.
- * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
- * Jun Nakajima <jun.nakajima@intel.com>
- * Support for the microcode updates in the new format.
- * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
- * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
- * because we no longer hold a copy of applied microcode
- * in kernel memory.
- * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
- * Fix sigmatch() macro to handle old CPUs with pf == 0.
- * Thanks to Stuart Swales for pointing out this bug.
- */
-
-//#define DEBUG /* pr_debug */
-#include <linux/capability.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/sched.h>
-#include <linux/smp_lock.h>
-#include <linux/cpumask.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/miscdevice.h>
-#include <linux/spinlock.h>
-#include <linux/mm.h>
-#include <linux/fs.h>
-#include <linux/mutex.h>
-#include <linux/cpu.h>
-#include <linux/firmware.h>
-#include <linux/platform_device.h>
-
-#include <asm/msr.h>
-#include <asm/uaccess.h>
-#include <asm/processor.h>
-#include <asm/microcode.h>
-
-MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver");
-MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
-MODULE_LICENSE("GPL");
-
-#define MICROCODE_VERSION "1.14a"
-
-#define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
-#define MC_HEADER_SIZE (sizeof (struct microcode_header)) /* 48 bytes */
-#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
-#define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */
-#define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */
-#define DWSIZE (sizeof (u32))
-#define get_totalsize(mc) \
- (((struct microcode *)mc)->hdr.totalsize ? \
- ((struct microcode *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
-#define get_datasize(mc) \
- (((struct microcode *)mc)->hdr.datasize ? \
- ((struct microcode *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
-
-#define sigmatch(s1, s2, p1, p2) \
- (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))
-
-#define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
-
-/* serialize access to the physical write to MSR 0x79 */
-static DEFINE_SPINLOCK(microcode_update_lock);
-
-/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
-static DEFINE_MUTEX(microcode_mutex);
-
-static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
-
-static void collect_cpu_info(int cpu_num)
-{
- struct cpuinfo_x86 *c = &cpu_data(cpu_num);
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
- unsigned int val[2];
-
- /* We should bind the task to the CPU */
- BUG_ON(raw_smp_processor_id() != cpu_num);
- uci->pf = uci->rev = 0;
- uci->mc = NULL;
- uci->valid = 1;
-
- if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
- cpu_has(c, X86_FEATURE_IA64)) {
- printk(KERN_ERR "microcode: CPU%d not a capable Intel "
- "processor\n", cpu_num);
- uci->valid = 0;
- return;
- }
-
- uci->sig = cpuid_eax(0x00000001);
-
- if ((c->x86_model >= 5) || (c->x86 > 6)) {
- /* get processor flags from MSR 0x17 */
- rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
- uci->pf = 1 << ((val[1] >> 18) & 7);
- }
-
- wrmsr(MSR_IA32_UCODE_REV, 0, 0);
- /* see notes above for revision 1.07. Apparent chip bug */
- sync_core();
- /* get the current revision from MSR 0x8B */
- rdmsr(MSR_IA32_UCODE_REV, val[0], uci->rev);
- pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n",
- uci->sig, uci->pf, uci->rev);
-}
-
-static inline int microcode_update_match(int cpu_num,
- struct microcode_header *mc_header, int sig, int pf)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
-
- if (!sigmatch(sig, uci->sig, pf, uci->pf)
- || mc_header->rev <= uci->rev)
- return 0;
- return 1;
-}
-
-static int microcode_sanity_check(void *mc)
-{
- struct microcode_header *mc_header = mc;
- struct extended_sigtable *ext_header = NULL;
- struct extended_signature *ext_sig;
- unsigned long total_size, data_size, ext_table_size;
- int sum, orig_sum, ext_sigcount = 0, i;
-
- total_size = get_totalsize(mc_header);
- data_size = get_datasize(mc_header);
- if (data_size + MC_HEADER_SIZE > total_size) {
- printk(KERN_ERR "microcode: error! "
- "Bad data size in microcode data file\n");
- return -EINVAL;
- }
-
- if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
- printk(KERN_ERR "microcode: error! "
- "Unknown microcode update format\n");
- return -EINVAL;
- }
- ext_table_size = total_size - (MC_HEADER_SIZE + data_size);
- if (ext_table_size) {
- if ((ext_table_size < EXT_HEADER_SIZE)
- || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) {
- printk(KERN_ERR "microcode: error! "
- "Small exttable size in microcode data file\n");
- return -EINVAL;
- }
- ext_header = mc + MC_HEADER_SIZE + data_size;
- if (ext_table_size != exttable_size(ext_header)) {
- printk(KERN_ERR "microcode: error! "
- "Bad exttable size in microcode data file\n");
- return -EFAULT;
- }
- ext_sigcount = ext_header->count;
- }
-
- /* check extended table checksum */
- if (ext_table_size) {
- int ext_table_sum = 0;
- int *ext_tablep = (int *)ext_header;
-
- i = ext_table_size / DWSIZE;
- while (i--)
- ext_table_sum += ext_tablep[i];
- if (ext_table_sum) {
- printk(KERN_WARNING "microcode: aborting, "
- "bad extended signature table checksum\n");
- return -EINVAL;
- }
- }
-
- /* calculate the checksum */
- orig_sum = 0;
- i = (MC_HEADER_SIZE + data_size) / DWSIZE;
- while (i--)
- orig_sum += ((int *)mc)[i];
- if (orig_sum) {
- printk(KERN_ERR "microcode: aborting, bad checksum\n");
- return -EINVAL;
- }
- if (!ext_table_size)
- return 0;
- /* check extended signature checksum */
- for (i = 0; i < ext_sigcount; i++) {
- ext_sig = (void *)ext_header + EXT_HEADER_SIZE +
- EXT_SIGNATURE_SIZE * i;
- sum = orig_sum
- - (mc_header->sig + mc_header->pf + mc_header->cksum)
- + (ext_sig->sig + ext_sig->pf + ext_sig->cksum);
- if (sum) {
- printk(KERN_ERR "microcode: aborting, bad checksum\n");
- return -EINVAL;
- }
- }
- return 0;
-}
-
-/*
- * return 0 - no update found
- * return 1 - found update
- * return < 0 - error
- */
-static int get_maching_microcode(void *mc, int cpu)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- struct microcode_header *mc_header = mc;
- struct extended_sigtable *ext_header;
- unsigned long total_size = get_totalsize(mc_header);
- int ext_sigcount, i;
- struct extended_signature *ext_sig;
- void *new_mc;
-
- if (microcode_update_match(cpu, mc_header,
- mc_header->sig, mc_header->pf))
- goto find;
-
- if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE)
- return 0;
-
- ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE;
- ext_sigcount = ext_header->count;
- ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
- for (i = 0; i < ext_sigcount; i++) {
- if (microcode_update_match(cpu, mc_header,
- ext_sig->sig, ext_sig->pf))
- goto find;
- ext_sig++;
- }
- return 0;
-find:
- pr_debug("microcode: CPU%d found a matching microcode update with"
- " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev);
- new_mc = vmalloc(total_size);
- if (!new_mc) {
- printk(KERN_ERR "microcode: error! Can not allocate memory\n");
- return -ENOMEM;
- }
-
- /* free previous update file */
- vfree(uci->mc);
-
- memcpy(new_mc, mc, total_size);
- uci->mc = new_mc;
- return 1;
-}
-
-static void apply_microcode(int cpu)
-{
- unsigned long flags;
- unsigned int val[2];
- int cpu_num = raw_smp_processor_id();
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
-
- /* We should bind the task to the CPU */
- BUG_ON(cpu_num != cpu);
-
- if (uci->mc == NULL)
- return;
-
- /* serialize access to the physical write to MSR 0x79 */
- spin_lock_irqsave(µcode_update_lock, flags);
-
- /* write microcode via MSR 0x79 */
- wrmsr(MSR_IA32_UCODE_WRITE,
- (unsigned long) uci->mc->bits,
- (unsigned long) uci->mc->bits >> 16 >> 16);
- wrmsr(MSR_IA32_UCODE_REV, 0, 0);
-
- /* see notes above for revision 1.07. Apparent chip bug */
- sync_core();
-
- /* get the current revision from MSR 0x8B */
- rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
-
- spin_unlock_irqrestore(µcode_update_lock, flags);
- if (val[1] != uci->mc->hdr.rev) {
- printk(KERN_ERR "microcode: CPU%d update from revision "
- "0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]);
- return;
- }
- printk(KERN_INFO "microcode: CPU%d updated from revision "
- "0x%x to 0x%x, date = %08x \n",
- cpu_num, uci->rev, val[1], uci->mc->hdr.date);
- uci->rev = val[1];
-}
-
-#ifdef CONFIG_MICROCODE_OLD_INTERFACE
-static void __user *user_buffer; /* user area microcode data buffer */
-static unsigned int user_buffer_size; /* it's size */
-
-static long get_next_ucode(void **mc, long offset)
-{
- struct microcode_header mc_header;
- unsigned long total_size;
-
- /* No more data */
- if (offset >= user_buffer_size)
- return 0;
- if (copy_from_user(&mc_header, user_buffer + offset, MC_HEADER_SIZE)) {
- printk(KERN_ERR "microcode: error! Can not read user data\n");
- return -EFAULT;
- }
- total_size = get_totalsize(&mc_header);
- if (offset + total_size > user_buffer_size) {
- printk(KERN_ERR "microcode: error! Bad total size in microcode "
- "data file\n");
- return -EINVAL;
- }
- *mc = vmalloc(total_size);
- if (!*mc)
- return -ENOMEM;
- if (copy_from_user(*mc, user_buffer + offset, total_size)) {
- printk(KERN_ERR "microcode: error! Can not read user data\n");
- vfree(*mc);
- return -EFAULT;
- }
- return offset + total_size;
-}
-
-static int do_microcode_update (void)
-{
- long cursor = 0;
- int error = 0;
- void *new_mc = NULL;
- int cpu;
- cpumask_t old;
- cpumask_of_cpu_ptr_declare(newmask);
-
- old = current->cpus_allowed;
-
- while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) {
- error = microcode_sanity_check(new_mc);
- if (error)
- goto out;
- /*
- * It's possible the data file has multiple matching ucode,
- * lets keep searching till the latest version
- */
- for_each_online_cpu(cpu) {
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- if (!uci->valid)
- continue;
- cpumask_of_cpu_ptr_next(newmask, cpu);
- set_cpus_allowed_ptr(current, newmask);
- error = get_maching_microcode(new_mc, cpu);
- if (error < 0)
- goto out;
- if (error == 1)
- apply_microcode(cpu);
- }
- vfree(new_mc);
- }
-out:
- if (cursor > 0)
- vfree(new_mc);
- if (cursor < 0)
- error = cursor;
- set_cpus_allowed_ptr(current, &old);
- return error;
-}
-
-static int microcode_open (struct inode *unused1, struct file *unused2)
-{
- cycle_kernel_lock();
- return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
-}
-
-static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos)
-{
- ssize_t ret;
-
- if ((len >> PAGE_SHIFT) > num_physpages) {
- printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages);
- return -EINVAL;
- }
-
- get_online_cpus();
- mutex_lock(µcode_mutex);
-
- user_buffer = (void __user *) buf;
- user_buffer_size = (int) len;
-
- ret = do_microcode_update();
- if (!ret)
- ret = (ssize_t)len;
-
- mutex_unlock(µcode_mutex);
- put_online_cpus();
-
- return ret;
-}
-
-static const struct file_operations microcode_fops = {
- .owner = THIS_MODULE,
- .write = microcode_write,
- .open = microcode_open,
-};
-
-static struct miscdevice microcode_dev = {
- .minor = MICROCODE_MINOR,
- .name = "microcode",
- .fops = µcode_fops,
-};
-
-static int __init microcode_dev_init (void)
-{
- int error;
-
- error = misc_register(µcode_dev);
- if (error) {
- printk(KERN_ERR
- "microcode: can't misc_register on minor=%d\n",
- MICROCODE_MINOR);
- return error;
- }
-
- return 0;
-}
-
-static void microcode_dev_exit (void)
-{
- misc_deregister(µcode_dev);
-}
-
-MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
-#else
-#define microcode_dev_init() 0
-#define microcode_dev_exit() do { } while(0)
-#endif
-
-static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
- unsigned long size, long offset)
-{
- struct microcode_header *mc_header;
- unsigned long total_size;
-
- /* No more data */
- if (offset >= size)
- return 0;
- mc_header = (struct microcode_header *)(buf + offset);
- total_size = get_totalsize(mc_header);
-
- if (offset + total_size > size) {
- printk(KERN_ERR "microcode: error! Bad data in microcode data file\n");
- return -EINVAL;
- }
-
- *mc = vmalloc(total_size);
- if (!*mc) {
- printk(KERN_ERR "microcode: error! Can not allocate memory\n");
- return -ENOMEM;
- }
- memcpy(*mc, buf + offset, total_size);
- return offset + total_size;
-}
-
-/* fake device for request_firmware */
-static struct platform_device *microcode_pdev;
-
-static int cpu_request_microcode(int cpu)
-{
- char name[30];
- struct cpuinfo_x86 *c = &cpu_data(cpu);
- const struct firmware *firmware;
- const u8 *buf;
- unsigned long size;
- long offset = 0;
- int error;
- void *mc;
-
- /* We should bind the task to the CPU */
- BUG_ON(cpu != raw_smp_processor_id());
- sprintf(name,"intel-ucode/%02x-%02x-%02x",
- c->x86, c->x86_model, c->x86_mask);
- error = request_firmware(&firmware, name, µcode_pdev->dev);
- if (error) {
- pr_debug("microcode: data file %s load failed\n", name);
- return error;
- }
- buf = firmware->data;
- size = firmware->size;
- while ((offset = get_next_ucode_from_buffer(&mc, buf, size, offset))
- > 0) {
- error = microcode_sanity_check(mc);
- if (error)
- break;
- error = get_maching_microcode(mc, cpu);
- if (error < 0)
- break;
- /*
- * It's possible the data file has multiple matching ucode,
- * lets keep searching till the latest version
- */
- if (error == 1) {
- apply_microcode(cpu);
- error = 0;
- }
- vfree(mc);
- }
- if (offset > 0)
- vfree(mc);
- if (offset < 0)
- error = offset;
- release_firmware(firmware);
-
- return error;
-}
-
-static int apply_microcode_check_cpu(int cpu)
-{
- struct cpuinfo_x86 *c = &cpu_data(cpu);
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- cpumask_t old;
- cpumask_of_cpu_ptr(newmask, cpu);
- unsigned int val[2];
- int err = 0;
-
- /* Check if the microcode is available */
- if (!uci->mc)
- return 0;
-
- old = current->cpus_allowed;
- set_cpus_allowed_ptr(current, newmask);
-
- /* Check if the microcode we have in memory matches the CPU */
- if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
- cpu_has(c, X86_FEATURE_IA64) || uci->sig != cpuid_eax(0x00000001))
- err = -EINVAL;
-
- if (!err && ((c->x86_model >= 5) || (c->x86 > 6))) {
- /* get processor flags from MSR 0x17 */
- rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
- if (uci->pf != (1 << ((val[1] >> 18) & 7)))
- err = -EINVAL;
- }
-
- if (!err) {
- wrmsr(MSR_IA32_UCODE_REV, 0, 0);
- /* see notes above for revision 1.07. Apparent chip bug */
- sync_core();
- /* get the current revision from MSR 0x8B */
- rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
- if (uci->rev != val[1])
- err = -EINVAL;
- }
-
- if (!err)
- apply_microcode(cpu);
- else
- printk(KERN_ERR "microcode: Could not apply microcode to CPU%d:"
- " sig=0x%x, pf=0x%x, rev=0x%x\n",
- cpu, uci->sig, uci->pf, uci->rev);
-
- set_cpus_allowed_ptr(current, &old);
- return err;
-}
-
-static void microcode_init_cpu(int cpu, int resume)
-{
- cpumask_t old;
- cpumask_of_cpu_ptr(newmask, cpu);
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- old = current->cpus_allowed;
-
- set_cpus_allowed_ptr(current, newmask);
- mutex_lock(µcode_mutex);
- collect_cpu_info(cpu);
- if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
- cpu_request_microcode(cpu);
- mutex_unlock(µcode_mutex);
- set_cpus_allowed_ptr(current, &old);
-}
-
-static void microcode_fini_cpu(int cpu)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- mutex_lock(µcode_mutex);
- uci->valid = 0;
- vfree(uci->mc);
- uci->mc = NULL;
- mutex_unlock(µcode_mutex);
-}
-
-static ssize_t reload_store(struct sys_device *dev,
- struct sysdev_attribute *attr,
- const char *buf, size_t sz)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
- char *end;
- unsigned long val = simple_strtoul(buf, &end, 0);
- int err = 0;
- int cpu = dev->id;
-
- if (end == buf)
- return -EINVAL;
- if (val == 1) {
- cpumask_t old;
- cpumask_of_cpu_ptr(newmask, cpu);
-
- old = current->cpus_allowed;
-
- get_online_cpus();
- set_cpus_allowed_ptr(current, newmask);
-
- mutex_lock(µcode_mutex);
- if (uci->valid)
- err = cpu_request_microcode(cpu);
- mutex_unlock(µcode_mutex);
- put_online_cpus();
- set_cpus_allowed_ptr(current, &old);
- }
- if (err)
- return err;
- return sz;
-}
-
-static ssize_t version_show(struct sys_device *dev,
- struct sysdev_attribute *attr, char *buf)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
-
- return sprintf(buf, "0x%x\n", uci->rev);
-}
-
-static ssize_t pf_show(struct sys_device *dev,
- struct sysdev_attribute *attr, char *buf)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
-
- return sprintf(buf, "0x%x\n", uci->pf);
-}
-
-static SYSDEV_ATTR(reload, 0200, NULL, reload_store);
-static SYSDEV_ATTR(version, 0400, version_show, NULL);
-static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL);
-
-static struct attribute *mc_default_attrs[] = {
- &attr_reload.attr,
- &attr_version.attr,
- &attr_processor_flags.attr,
- NULL
-};
-
-static struct attribute_group mc_attr_group = {
- .attrs = mc_default_attrs,
- .name = "microcode",
-};
-
-static int __mc_sysdev_add(struct sys_device *sys_dev, int resume)
-{
- int err, cpu = sys_dev->id;
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- if (!cpu_online(cpu))
- return 0;
-
- pr_debug("microcode: CPU%d added\n", cpu);
- memset(uci, 0, sizeof(*uci));
-
- err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group);
- if (err)
- return err;
-
- microcode_init_cpu(cpu, resume);
-
- return 0;
-}
-
-static int mc_sysdev_add(struct sys_device *sys_dev)
-{
- return __mc_sysdev_add(sys_dev, 0);
-}
-
-static int mc_sysdev_remove(struct sys_device *sys_dev)
-{
- int cpu = sys_dev->id;
-
- if (!cpu_online(cpu))
- return 0;
-
- pr_debug("microcode: CPU%d removed\n", cpu);
- microcode_fini_cpu(cpu);
- sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
- return 0;
-}
-
-static int mc_sysdev_resume(struct sys_device *dev)
-{
- int cpu = dev->id;
-
- if (!cpu_online(cpu))
- return 0;
- pr_debug("microcode: CPU%d resumed\n", cpu);
- /* only CPU 0 will apply ucode here */
- apply_microcode(0);
- return 0;
-}
-
-static struct sysdev_driver mc_sysdev_driver = {
- .add = mc_sysdev_add,
- .remove = mc_sysdev_remove,
- .resume = mc_sysdev_resume,
-};
-
-static __cpuinit int
-mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
-{
- unsigned int cpu = (unsigned long)hcpu;
- struct sys_device *sys_dev;
-
- sys_dev = get_cpu_sysdev(cpu);
- switch (action) {
- case CPU_UP_CANCELED_FROZEN:
- /* The CPU refused to come up during a system resume */
- microcode_fini_cpu(cpu);
- break;
- case CPU_ONLINE:
- case CPU_DOWN_FAILED:
- mc_sysdev_add(sys_dev);
- break;
- case CPU_ONLINE_FROZEN:
- /* System-wide resume is in progress, try to apply microcode */
- if (apply_microcode_check_cpu(cpu)) {
- /* The application of microcode failed */
- microcode_fini_cpu(cpu);
- __mc_sysdev_add(sys_dev, 1);
- break;
- }
- case CPU_DOWN_FAILED_FROZEN:
- if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group))
- printk(KERN_ERR "microcode: Failed to create the sysfs "
- "group for CPU%d\n", cpu);
- break;
- case CPU_DOWN_PREPARE:
- mc_sysdev_remove(sys_dev);
- break;
- case CPU_DOWN_PREPARE_FROZEN:
- /* Suspend is in progress, only remove the interface */
- sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
- break;
- }
- return NOTIFY_OK;
-}
-
-static struct notifier_block __refdata mc_cpu_notifier = {
- .notifier_call = mc_cpu_callback,
-};
-
-static int __init microcode_init (void)
-{
- int error;
-
- printk(KERN_INFO
- "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
-
- error = microcode_dev_init();
- if (error)
- return error;
- microcode_pdev = platform_device_register_simple("microcode", -1,
- NULL, 0);
- if (IS_ERR(microcode_pdev)) {
- microcode_dev_exit();
- return PTR_ERR(microcode_pdev);
- }
-
- get_online_cpus();
- error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver);
- put_online_cpus();
- if (error) {
- microcode_dev_exit();
- platform_device_unregister(microcode_pdev);
- return error;
- }
-
- register_hotcpu_notifier(&mc_cpu_notifier);
- return 0;
-}
-
-static void __exit microcode_exit (void)
-{
- microcode_dev_exit();
-
- unregister_hotcpu_notifier(&mc_cpu_notifier);
-
- get_online_cpus();
- sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);
- put_online_cpus();
-
- platform_device_unregister(microcode_pdev);
-}
-
-module_init(microcode_init)
-module_exit(microcode_exit)
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
new file mode 100644
index 0000000..4e7b2f6
--- /dev/null
+++ b/arch/x86/kernel/microcode_intel.c
@@ -0,0 +1,855 @@
+/*
+ * Intel CPU Microcode Update Driver for Linux
+ *
+ * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
+ * 2006 Shaohua Li <shaohua.li@intel.com>
+ *
+ * This driver allows to upgrade microcode on Intel processors
+ * belonging to IA-32 family - PentiumPro, Pentium II,
+ * Pentium III, Xeon, Pentium 4, etc.
+ *
+ * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
+ * Software Developer's Manual
+ * Order Number 253668 or free download from:
+ *
+ * http://developer.intel.com/design/pentium4/manuals/253668.htm
+ *
+ * For more information, go to http://www.urbanmyth.org/microcode
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Initial release.
+ * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Added read() support + cleanups.
+ * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Added 'device trimming' support. open(O_WRONLY) zeroes
+ * and frees the saved copy of applied microcode.
+ * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Made to use devfs (/dev/cpu/microcode) + cleanups.
+ * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com>
+ * Added misc device support (now uses both devfs and misc).
+ * Added MICROCODE_IOCFREE ioctl to clear memory.
+ * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com>
+ * Messages for error cases (non Intel & no suitable microcode).
+ * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com>
+ * Removed ->release(). Removed exclusive open and status bitmap.
+ * Added microcode_rwsem to serialize read()/write()/ioctl().
+ * Removed global kernel lock usage.
+ * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com>
+ * Write 0 to 0x8B msr and then cpuid before reading revision,
+ * so that it works even if there were no update done by the
+ * BIOS. Otherwise, reading from 0x8B gives junk (which happened
+ * to be 0 on my machine which is why it worked even when I
+ * disabled update by the BIOS)
+ * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix.
+ * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and
+ * Tigran Aivazian <tigran@veritas.com>
+ * Intel Pentium 4 processor support and bugfixes.
+ * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com>
+ * Bugfix for HT (Hyper-Threading) enabled processors
+ * whereby processor resources are shared by all logical processors
+ * in a single CPU package.
+ * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and
+ * Tigran Aivazian <tigran@veritas.com>,
+ * Serialize updates as required on HT processors due to speculative
+ * nature of implementation.
+ * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
+ * Fix the panic when writing zero-length microcode chunk.
+ * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
+ * Jun Nakajima <jun.nakajima@intel.com>
+ * Support for the microcode updates in the new format.
+ * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
+ * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
+ * because we no longer hold a copy of applied microcode
+ * in kernel memory.
+ * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
+ * Fix sigmatch() macro to handle old CPUs with pf == 0.
+ * Thanks to Stuart Swales for pointing out this bug.
+ */
+
+//#define DEBUG /* pr_debug */
+#include <linux/capability.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
+#include <linux/cpumask.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/miscdevice.h>
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/mutex.h>
+#include <linux/cpu.h>
+#include <linux/firmware.h>
+#include <linux/platform_device.h>
+
+#include <asm/msr.h>
+#include <asm/uaccess.h>
+#include <asm/processor.h>
+#include <asm/microcode.h>
+
+MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver");
+MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
+MODULE_LICENSE("GPL");
+
+#define MICROCODE_VERSION "1.14a"
+
+#define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
+#define MC_HEADER_SIZE (sizeof (struct microcode_header)) /* 48 bytes */
+#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
+#define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */
+#define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */
+#define DWSIZE (sizeof (u32))
+#define get_totalsize(mc) \
+ (((struct microcode *)mc)->hdr.totalsize ? \
+ ((struct microcode *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
+#define get_datasize(mc) \
+ (((struct microcode *)mc)->hdr.datasize ? \
+ ((struct microcode *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
+
+#define sigmatch(s1, s2, p1, p2) \
+ (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))
+
+#define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
+
+/* serialize access to the physical write to MSR 0x79 */
+static DEFINE_SPINLOCK(microcode_update_lock);
+
+/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
+static DEFINE_MUTEX(microcode_mutex);
+
+static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+
+static void collect_cpu_info(int cpu_num)
+{
+ struct cpuinfo_x86 *c = &cpu_data(cpu_num);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
+ unsigned int val[2];
+
+ /* We should bind the task to the CPU */
+ BUG_ON(raw_smp_processor_id() != cpu_num);
+ uci->pf = uci->rev = 0;
+ uci->mc = NULL;
+ uci->valid = 1;
+
+ if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
+ cpu_has(c, X86_FEATURE_IA64)) {
+ printk(KERN_ERR "microcode: CPU%d not a capable Intel "
+ "processor\n", cpu_num);
+ uci->valid = 0;
+ return;
+ }
+
+ uci->sig = cpuid_eax(0x00000001);
+
+ if ((c->x86_model >= 5) || (c->x86 > 6)) {
+ /* get processor flags from MSR 0x17 */
+ rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+ uci->pf = 1 << ((val[1] >> 18) & 7);
+ }
+
+ wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+ /* see notes above for revision 1.07. Apparent chip bug */
+ sync_core();
+ /* get the current revision from MSR 0x8B */
+ rdmsr(MSR_IA32_UCODE_REV, val[0], uci->rev);
+ pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n",
+ uci->sig, uci->pf, uci->rev);
+}
+
+static inline int microcode_update_match(int cpu_num,
+ struct microcode_header *mc_header, int sig, int pf)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
+
+ if (!sigmatch(sig, uci->sig, pf, uci->pf)
+ || mc_header->rev <= uci->rev)
+ return 0;
+ return 1;
+}
+
+static int microcode_sanity_check(void *mc)
+{
+ struct microcode_header *mc_header = mc;
+ struct extended_sigtable *ext_header = NULL;
+ struct extended_signature *ext_sig;
+ unsigned long total_size, data_size, ext_table_size;
+ int sum, orig_sum, ext_sigcount = 0, i;
+
+ total_size = get_totalsize(mc_header);
+ data_size = get_datasize(mc_header);
+ if (data_size + MC_HEADER_SIZE > total_size) {
+ printk(KERN_ERR "microcode: error! "
+ "Bad data size in microcode data file\n");
+ return -EINVAL;
+ }
+
+ if (mc_header->ldrver != 1 || mc_header->hdrver != 1) {
+ printk(KERN_ERR "microcode: error! "
+ "Unknown microcode update format\n");
+ return -EINVAL;
+ }
+ ext_table_size = total_size - (MC_HEADER_SIZE + data_size);
+ if (ext_table_size) {
+ if ((ext_table_size < EXT_HEADER_SIZE)
+ || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) {
+ printk(KERN_ERR "microcode: error! "
+ "Small exttable size in microcode data file\n");
+ return -EINVAL;
+ }
+ ext_header = mc + MC_HEADER_SIZE + data_size;
+ if (ext_table_size != exttable_size(ext_header)) {
+ printk(KERN_ERR "microcode: error! "
+ "Bad exttable size in microcode data file\n");
+ return -EFAULT;
+ }
+ ext_sigcount = ext_header->count;
+ }
+
+ /* check extended table checksum */
+ if (ext_table_size) {
+ int ext_table_sum = 0;
+ int *ext_tablep = (int *)ext_header;
+
+ i = ext_table_size / DWSIZE;
+ while (i--)
+ ext_table_sum += ext_tablep[i];
+ if (ext_table_sum) {
+ printk(KERN_WARNING "microcode: aborting, "
+ "bad extended signature table checksum\n");
+ return -EINVAL;
+ }
+ }
+
+ /* calculate the checksum */
+ orig_sum = 0;
+ i = (MC_HEADER_SIZE + data_size) / DWSIZE;
+ while (i--)
+ orig_sum += ((int *)mc)[i];
+ if (orig_sum) {
+ printk(KERN_ERR "microcode: aborting, bad checksum\n");
+ return -EINVAL;
+ }
+ if (!ext_table_size)
+ return 0;
+ /* check extended signature checksum */
+ for (i = 0; i < ext_sigcount; i++) {
+ ext_sig = (void *)ext_header + EXT_HEADER_SIZE +
+ EXT_SIGNATURE_SIZE * i;
+ sum = orig_sum
+ - (mc_header->sig + mc_header->pf + mc_header->cksum)
+ + (ext_sig->sig + ext_sig->pf + ext_sig->cksum);
+ if (sum) {
+ printk(KERN_ERR "microcode: aborting, bad checksum\n");
+ return -EINVAL;
+ }
+ }
+ return 0;
+}
+
+/*
+ * return 0 - no update found
+ * return 1 - found update
+ * return < 0 - error
+ */
+static int get_maching_microcode(void *mc, int cpu)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ struct microcode_header *mc_header = mc;
+ struct extended_sigtable *ext_header;
+ unsigned long total_size = get_totalsize(mc_header);
+ int ext_sigcount, i;
+ struct extended_signature *ext_sig;
+ void *new_mc;
+
+ if (microcode_update_match(cpu, mc_header,
+ mc_header->sig, mc_header->pf))
+ goto find;
+
+ if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE)
+ return 0;
+
+ ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE;
+ ext_sigcount = ext_header->count;
+ ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
+ for (i = 0; i < ext_sigcount; i++) {
+ if (microcode_update_match(cpu, mc_header,
+ ext_sig->sig, ext_sig->pf))
+ goto find;
+ ext_sig++;
+ }
+ return 0;
+find:
+ pr_debug("microcode: CPU%d found a matching microcode update with"
+ " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev);
+ new_mc = vmalloc(total_size);
+ if (!new_mc) {
+ printk(KERN_ERR "microcode: error! Can not allocate memory\n");
+ return -ENOMEM;
+ }
+
+ /* free previous update file */
+ vfree(uci->mc);
+
+ memcpy(new_mc, mc, total_size);
+ uci->mc = new_mc;
+ return 1;
+}
+
+static void apply_microcode(int cpu)
+{
+ unsigned long flags;
+ unsigned int val[2];
+ int cpu_num = raw_smp_processor_id();
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(cpu_num != cpu);
+
+ if (uci->mc == NULL)
+ return;
+
+ /* serialize access to the physical write to MSR 0x79 */
+ spin_lock_irqsave(µcode_update_lock, flags);
+
+ /* write microcode via MSR 0x79 */
+ wrmsr(MSR_IA32_UCODE_WRITE,
+ (unsigned long) uci->mc->bits,
+ (unsigned long) uci->mc->bits >> 16 >> 16);
+ wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+
+ /* see notes above for revision 1.07. Apparent chip bug */
+ sync_core();
+
+ /* get the current revision from MSR 0x8B */
+ rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
+
+ spin_unlock_irqrestore(µcode_update_lock, flags);
+ if (val[1] != uci->mc->hdr.rev) {
+ printk(KERN_ERR "microcode: CPU%d update from revision "
+ "0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]);
+ return;
+ }
+ printk(KERN_INFO "microcode: CPU%d updated from revision "
+ "0x%x to 0x%x, date = %08x \n",
+ cpu_num, uci->rev, val[1], uci->mc->hdr.date);
+ uci->rev = val[1];
+}
+
+#ifdef CONFIG_MICROCODE_OLD_INTERFACE
+static void __user *user_buffer; /* user area microcode data buffer */
+static unsigned int user_buffer_size; /* it's size */
+
+static long get_next_ucode(void **mc, long offset)
+{
+ struct microcode_header mc_header;
+ unsigned long total_size;
+
+ /* No more data */
+ if (offset >= user_buffer_size)
+ return 0;
+ if (copy_from_user(&mc_header, user_buffer + offset, MC_HEADER_SIZE)) {
+ printk(KERN_ERR "microcode: error! Can not read user data\n");
+ return -EFAULT;
+ }
+ total_size = get_totalsize(&mc_header);
+ if (offset + total_size > user_buffer_size) {
+ printk(KERN_ERR "microcode: error! Bad total size in microcode "
+ "data file\n");
+ return -EINVAL;
+ }
+ *mc = vmalloc(total_size);
+ if (!*mc)
+ return -ENOMEM;
+ if (copy_from_user(*mc, user_buffer + offset, total_size)) {
+ printk(KERN_ERR "microcode: error! Can not read user data\n");
+ vfree(*mc);
+ return -EFAULT;
+ }
+ return offset + total_size;
+}
+
+static int do_microcode_update (void)
+{
+ long cursor = 0;
+ int error = 0;
+ void *new_mc = NULL;
+ int cpu;
+ cpumask_t old;
+ cpumask_of_cpu_ptr_declare(newmask);
+
+ old = current->cpus_allowed;
+
+ while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) {
+ error = microcode_sanity_check(new_mc);
+ if (error)
+ goto out;
+ /*
+ * It's possible the data file has multiple matching ucode,
+ * lets keep searching till the latest version
+ */
+ for_each_online_cpu(cpu) {
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ if (!uci->valid)
+ continue;
+ cpumask_of_cpu_ptr_next(newmask, cpu);
+ set_cpus_allowed_ptr(current, newmask);
+ error = get_maching_microcode(new_mc, cpu);
+ if (error < 0)
+ goto out;
+ if (error == 1)
+ apply_microcode(cpu);
+ }
+ vfree(new_mc);
+ }
+out:
+ if (cursor > 0)
+ vfree(new_mc);
+ if (cursor < 0)
+ error = cursor;
+ set_cpus_allowed_ptr(current, &old);
+ return error;
+}
+
+static int microcode_open (struct inode *unused1, struct file *unused2)
+{
+ cycle_kernel_lock();
+ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
+}
+
+static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos)
+{
+ ssize_t ret;
+
+ if ((len >> PAGE_SHIFT) > num_physpages) {
+ printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages);
+ return -EINVAL;
+ }
+
+ get_online_cpus();
+ mutex_lock(µcode_mutex);
+
+ user_buffer = (void __user *) buf;
+ user_buffer_size = (int) len;
+
+ ret = do_microcode_update();
+ if (!ret)
+ ret = (ssize_t)len;
+
+ mutex_unlock(µcode_mutex);
+ put_online_cpus();
+
+ return ret;
+}
+
+static const struct file_operations microcode_fops = {
+ .owner = THIS_MODULE,
+ .write = microcode_write,
+ .open = microcode_open,
+};
+
+static struct miscdevice microcode_dev = {
+ .minor = MICROCODE_MINOR,
+ .name = "microcode",
+ .fops = µcode_fops,
+};
+
+static int __init microcode_dev_init (void)
+{
+ int error;
+
+ error = misc_register(µcode_dev);
+ if (error) {
+ printk(KERN_ERR
+ "microcode: can't misc_register on minor=%d\n",
+ MICROCODE_MINOR);
+ return error;
+ }
+
+ return 0;
+}
+
+static void microcode_dev_exit (void)
+{
+ misc_deregister(µcode_dev);
+}
+
+MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
+#else
+#define microcode_dev_init() 0
+#define microcode_dev_exit() do { } while(0)
+#endif
+
+static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
+ unsigned long size, long offset)
+{
+ struct microcode_header *mc_header;
+ unsigned long total_size;
+
+ /* No more data */
+ if (offset >= size)
+ return 0;
+ mc_header = (struct microcode_header *)(buf + offset);
+ total_size = get_totalsize(mc_header);
+
+ if (offset + total_size > size) {
+ printk(KERN_ERR "microcode: error! Bad data in microcode data file\n");
+ return -EINVAL;
+ }
+
+ *mc = vmalloc(total_size);
+ if (!*mc) {
+ printk(KERN_ERR "microcode: error! Can not allocate memory\n");
+ return -ENOMEM;
+ }
+ memcpy(*mc, buf + offset, total_size);
+ return offset + total_size;
+}
+
+/* fake device for request_firmware */
+static struct platform_device *microcode_pdev;
+
+static int cpu_request_microcode(int cpu)
+{
+ char name[30];
+ struct cpuinfo_x86 *c = &cpu_data(cpu);
+ const struct firmware *firmware;
+ const u8 *buf;
+ unsigned long size;
+ long offset = 0;
+ int error;
+ void *mc;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(cpu != raw_smp_processor_id());
+ sprintf(name,"intel-ucode/%02x-%02x-%02x",
+ c->x86, c->x86_model, c->x86_mask);
+ error = request_firmware(&firmware, name, µcode_pdev->dev);
+ if (error) {
+ pr_debug("microcode: data file %s load failed\n", name);
+ return error;
+ }
+ buf = firmware->data;
+ size = firmware->size;
+ while ((offset = get_next_ucode_from_buffer(&mc, buf, size, offset))
+ > 0) {
+ error = microcode_sanity_check(mc);
+ if (error)
+ break;
+ error = get_maching_microcode(mc, cpu);
+ if (error < 0)
+ break;
+ /*
+ * It's possible the data file has multiple matching ucode,
+ * lets keep searching till the latest version
+ */
+ if (error == 1) {
+ apply_microcode(cpu);
+ error = 0;
+ }
+ vfree(mc);
+ }
+ if (offset > 0)
+ vfree(mc);
+ if (offset < 0)
+ error = offset;
+ release_firmware(firmware);
+
+ return error;
+}
+
+static int apply_microcode_check_cpu(int cpu)
+{
+ struct cpuinfo_x86 *c = &cpu_data(cpu);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+ unsigned int val[2];
+ int err = 0;
+
+ /* Check if the microcode is available */
+ if (!uci->mc)
+ return 0;
+
+ old = current->cpus_allowed;
+ set_cpus_allowed_ptr(current, newmask);
+
+ /* Check if the microcode we have in memory matches the CPU */
+ if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
+ cpu_has(c, X86_FEATURE_IA64) || uci->sig != cpuid_eax(0x00000001))
+ err = -EINVAL;
+
+ if (!err && ((c->x86_model >= 5) || (c->x86 > 6))) {
+ /* get processor flags from MSR 0x17 */
+ rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
+ if (uci->pf != (1 << ((val[1] >> 18) & 7)))
+ err = -EINVAL;
+ }
+
+ if (!err) {
+ wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+ /* see notes above for revision 1.07. Apparent chip bug */
+ sync_core();
+ /* get the current revision from MSR 0x8B */
+ rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
+ if (uci->rev != val[1])
+ err = -EINVAL;
+ }
+
+ if (!err)
+ apply_microcode(cpu);
+ else
+ printk(KERN_ERR "microcode: Could not apply microcode to CPU%d:"
+ " sig=0x%x, pf=0x%x, rev=0x%x\n",
+ cpu, uci->sig, uci->pf, uci->rev);
+
+ set_cpus_allowed_ptr(current, &old);
+ return err;
+}
+
+static void microcode_init_cpu(int cpu, int resume)
+{
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ old = current->cpus_allowed;
+
+ set_cpus_allowed_ptr(current, newmask);
+ mutex_lock(µcode_mutex);
+ collect_cpu_info(cpu);
+ if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
+ cpu_request_microcode(cpu);
+ mutex_unlock(µcode_mutex);
+ set_cpus_allowed_ptr(current, &old);
+}
+
+static void microcode_fini_cpu(int cpu)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ mutex_lock(µcode_mutex);
+ uci->valid = 0;
+ vfree(uci->mc);
+ uci->mc = NULL;
+ mutex_unlock(µcode_mutex);
+}
+
+static ssize_t reload_store(struct sys_device *dev,
+ struct sysdev_attribute *attr,
+ const char *buf, size_t sz)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+ char *end;
+ unsigned long val = simple_strtoul(buf, &end, 0);
+ int err = 0;
+ int cpu = dev->id;
+
+ if (end == buf)
+ return -EINVAL;
+ if (val == 1) {
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+
+ old = current->cpus_allowed;
+
+ get_online_cpus();
+ set_cpus_allowed_ptr(current, newmask);
+
+ mutex_lock(µcode_mutex);
+ if (uci->valid)
+ err = cpu_request_microcode(cpu);
+ mutex_unlock(µcode_mutex);
+ put_online_cpus();
+ set_cpus_allowed_ptr(current, &old);
+ }
+ if (err)
+ return err;
+ return sz;
+}
+
+static ssize_t version_show(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+
+ return sprintf(buf, "0x%x\n", uci->rev);
+}
+
+static ssize_t pf_show(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+
+ return sprintf(buf, "0x%x\n", uci->pf);
+}
+
+static SYSDEV_ATTR(reload, 0200, NULL, reload_store);
+static SYSDEV_ATTR(version, 0400, version_show, NULL);
+static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL);
+
+static struct attribute *mc_default_attrs[] = {
+ &attr_reload.attr,
+ &attr_version.attr,
+ &attr_processor_flags.attr,
+ NULL
+};
+
+static struct attribute_group mc_attr_group = {
+ .attrs = mc_default_attrs,
+ .name = "microcode",
+};
+
+static int __mc_sysdev_add(struct sys_device *sys_dev, int resume)
+{
+ int err, cpu = sys_dev->id;
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ if (!cpu_online(cpu))
+ return 0;
+
+ pr_debug("microcode: CPU%d added\n", cpu);
+ memset(uci, 0, sizeof(*uci));
+
+ err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group);
+ if (err)
+ return err;
+
+ microcode_init_cpu(cpu, resume);
+
+ return 0;
+}
+
+static int mc_sysdev_add(struct sys_device *sys_dev)
+{
+ return __mc_sysdev_add(sys_dev, 0);
+}
+
+static int mc_sysdev_remove(struct sys_device *sys_dev)
+{
+ int cpu = sys_dev->id;
+
+ if (!cpu_online(cpu))
+ return 0;
+
+ pr_debug("microcode: CPU%d removed\n", cpu);
+ microcode_fini_cpu(cpu);
+ sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
+ return 0;
+}
+
+static int mc_sysdev_resume(struct sys_device *dev)
+{
+ int cpu = dev->id;
+
+ if (!cpu_online(cpu))
+ return 0;
+ pr_debug("microcode: CPU%d resumed\n", cpu);
+ /* only CPU 0 will apply ucode here */
+ apply_microcode(0);
+ return 0;
+}
+
+static struct sysdev_driver mc_sysdev_driver = {
+ .add = mc_sysdev_add,
+ .remove = mc_sysdev_remove,
+ .resume = mc_sysdev_resume,
+};
+
+static __cpuinit int
+mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
+{
+ unsigned int cpu = (unsigned long)hcpu;
+ struct sys_device *sys_dev;
+
+ sys_dev = get_cpu_sysdev(cpu);
+ switch (action) {
+ case CPU_UP_CANCELED_FROZEN:
+ /* The CPU refused to come up during a system resume */
+ microcode_fini_cpu(cpu);
+ break;
+ case CPU_ONLINE:
+ case CPU_DOWN_FAILED:
+ mc_sysdev_add(sys_dev);
+ break;
+ case CPU_ONLINE_FROZEN:
+ /* System-wide resume is in progress, try to apply microcode */
+ if (apply_microcode_check_cpu(cpu)) {
+ /* The application of microcode failed */
+ microcode_fini_cpu(cpu);
+ __mc_sysdev_add(sys_dev, 1);
+ break;
+ }
+ case CPU_DOWN_FAILED_FROZEN:
+ if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group))
+ printk(KERN_ERR "microcode: Failed to create the sysfs "
+ "group for CPU%d\n", cpu);
+ break;
+ case CPU_DOWN_PREPARE:
+ mc_sysdev_remove(sys_dev);
+ break;
+ case CPU_DOWN_PREPARE_FROZEN:
+ /* Suspend is in progress, only remove the interface */
+ sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
+ break;
+ }
+ return NOTIFY_OK;
+}
+
+static struct notifier_block __refdata mc_cpu_notifier = {
+ .notifier_call = mc_cpu_callback,
+};
+
+static int __init microcode_init (void)
+{
+ int error;
+
+ printk(KERN_INFO
+ "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
+
+ error = microcode_dev_init();
+ if (error)
+ return error;
+ microcode_pdev = platform_device_register_simple("microcode", -1,
+ NULL, 0);
+ if (IS_ERR(microcode_pdev)) {
+ microcode_dev_exit();
+ return PTR_ERR(microcode_pdev);
+ }
+
+ get_online_cpus();
+ error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver);
+ put_online_cpus();
+ if (error) {
+ microcode_dev_exit();
+ platform_device_unregister(microcode_pdev);
+ return error;
+ }
+
+ register_hotcpu_notifier(&mc_cpu_notifier);
+ return 0;
+}
+
+static void __exit microcode_exit (void)
+{
+ microcode_dev_exit();
+
+ unregister_hotcpu_notifier(&mc_cpu_notifier);
+
+ get_online_cpus();
+ sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);
+ put_online_cpus();
+
+ platform_device_unregister(microcode_pdev);
+}
+
+module_init(microcode_init)
+module_exit(microcode_exit)
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 06/11] [PATCH 06/11] x86: Code split to two parts.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (3 preceding siblings ...)
2008-07-28 16:44 ` [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 07/11] [PATCH 07/11] x86: Structure declaration renaming Peter Oruba
` (5 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0006-x86-Code-split-to-two-parts.patch --]
[-- Type: text/plain, Size: 27934 bytes --]
Split off existing code into two seperate files. One file holds general
code, the other file vendor specific parts. No functional changes, only
refactoring. Temporarily Introduced a new module name 'ucode' for result,
due to already taken name 'microcode'.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/kernel/Makefile | 3 +-
arch/x86/kernel/microcode.c | 463 +++++++++++++++++++++++++++++++++++++
arch/x86/kernel/microcode_intel.c | 387 ++-----------------------------
3 files changed, 488 insertions(+), 365 deletions(-)
create mode 100644 arch/x86/kernel/microcode.c
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index a9be2a0..abb32ae 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -51,7 +51,8 @@ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
obj-$(CONFIG_MCA) += mca_32.o
obj-$(CONFIG_X86_MSR) += msr.o
obj-$(CONFIG_X86_CPUID) += cpuid.o
-obj-$(CONFIG_MICROCODE) += microcode_intel.o
+obj-$(CONFIG_MICROCODE) += ucode.o
+ucode-objs := microcode.o microcode_intel.o
obj-$(CONFIG_PCI) += early-quirks.o
apm-y := apm_32.o
obj-$(CONFIG_APM) += apm.o
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
new file mode 100644
index 0000000..c1047d7
--- /dev/null
+++ b/arch/x86/kernel/microcode.c
@@ -0,0 +1,463 @@
+/*
+ * Intel CPU Microcode Update Driver for Linux
+ *
+ * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
+ * 2006 Shaohua Li <shaohua.li@intel.com>
+ *
+ * This driver allows to upgrade microcode on Intel processors
+ * belonging to IA-32 family - PentiumPro, Pentium II,
+ * Pentium III, Xeon, Pentium 4, etc.
+ *
+ * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
+ * Software Developer's Manual
+ * Order Number 253668 or free download from:
+ *
+ * http://developer.intel.com/design/pentium4/manuals/253668.htm
+ *
+ * For more information, go to http://www.urbanmyth.org/microcode
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Initial release.
+ * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Added read() support + cleanups.
+ * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Added 'device trimming' support. open(O_WRONLY) zeroes
+ * and frees the saved copy of applied microcode.
+ * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com>
+ * Made to use devfs (/dev/cpu/microcode) + cleanups.
+ * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com>
+ * Added misc device support (now uses both devfs and misc).
+ * Added MICROCODE_IOCFREE ioctl to clear memory.
+ * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com>
+ * Messages for error cases (non Intel & no suitable microcode).
+ * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com>
+ * Removed ->release(). Removed exclusive open and status bitmap.
+ * Added microcode_rwsem to serialize read()/write()/ioctl().
+ * Removed global kernel lock usage.
+ * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com>
+ * Write 0 to 0x8B msr and then cpuid before reading revision,
+ * so that it works even if there were no update done by the
+ * BIOS. Otherwise, reading from 0x8B gives junk (which happened
+ * to be 0 on my machine which is why it worked even when I
+ * disabled update by the BIOS)
+ * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix.
+ * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and
+ * Tigran Aivazian <tigran@veritas.com>
+ * Intel Pentium 4 processor support and bugfixes.
+ * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com>
+ * Bugfix for HT (Hyper-Threading) enabled processors
+ * whereby processor resources are shared by all logical processors
+ * in a single CPU package.
+ * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and
+ * Tigran Aivazian <tigran@veritas.com>,
+ * Serialize updates as required on HT processors due to speculative
+ * nature of implementation.
+ * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
+ * Fix the panic when writing zero-length microcode chunk.
+ * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
+ * Jun Nakajima <jun.nakajima@intel.com>
+ * Support for the microcode updates in the new format.
+ * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
+ * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
+ * because we no longer hold a copy of applied microcode
+ * in kernel memory.
+ * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
+ * Fix sigmatch() macro to handle old CPUs with pf == 0.
+ * Thanks to Stuart Swales for pointing out this bug.
+ */
+
+//#define DEBUG /* pr_debug */
+#include <linux/capability.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
+#include <linux/cpumask.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/miscdevice.h>
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/mutex.h>
+#include <linux/cpu.h>
+#include <linux/firmware.h>
+#include <linux/platform_device.h>
+
+#include <asm/msr.h>
+#include <asm/uaccess.h>
+#include <asm/processor.h>
+#include <asm/microcode.h>
+
+MODULE_DESCRIPTION("Microcode Update Driver");
+MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
+MODULE_LICENSE("GPL");
+
+#define MICROCODE_VERSION "1.14a"
+
+/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
+DEFINE_MUTEX(microcode_mutex);
+
+struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+
+extern long get_next_ucode(void **mc, long offset);
+extern int microcode_sanity_check(void *mc);
+extern int get_matching_microcode(void *mc, int cpu);
+extern void collect_cpu_info(int cpu_num);
+extern int cpu_request_microcode(int cpu);
+extern void microcode_fini_cpu(int cpu);
+extern void apply_microcode(int cpu);
+extern int apply_microcode_check_cpu(int cpu);
+
+#ifdef CONFIG_MICROCODE_OLD_INTERFACE
+void __user *user_buffer; /* user area microcode data buffer */
+unsigned int user_buffer_size; /* it's size */
+
+static int do_microcode_update (void)
+{
+ long cursor = 0;
+ int error = 0;
+ void *new_mc = NULL;
+ int cpu;
+ cpumask_t old;
+ cpumask_of_cpu_ptr_declare(newmask);
+
+ old = current->cpus_allowed;
+
+ while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) {
+ error = microcode_sanity_check(new_mc);
+ if (error)
+ goto out;
+ /*
+ * It's possible the data file has multiple matching ucode,
+ * lets keep searching till the latest version
+ */
+ for_each_online_cpu(cpu) {
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ if (!uci->valid)
+ continue;
+ cpumask_of_cpu_ptr_next(newmask, cpu);
+ set_cpus_allowed_ptr(current, newmask);
+ error = get_maching_microcode(new_mc, cpu);
+ if (error < 0)
+ goto out;
+ if (error == 1)
+ apply_microcode(cpu);
+ }
+ vfree(new_mc);
+ }
+out:
+ if (cursor > 0)
+ vfree(new_mc);
+ if (cursor < 0)
+ error = cursor;
+ set_cpus_allowed_ptr(current, &old);
+ return error;
+}
+
+static int microcode_open (struct inode *unused1, struct file *unused2)
+{
+ cycle_kernel_lock();
+ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
+}
+
+static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos)
+{
+ ssize_t ret;
+
+ if ((len >> PAGE_SHIFT) > num_physpages) {
+ printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages);
+ return -EINVAL;
+ }
+
+ get_online_cpus();
+ mutex_lock(µcode_mutex);
+
+ user_buffer = (void __user *) buf;
+ user_buffer_size = (int) len;
+
+ ret = do_microcode_update();
+ if (!ret)
+ ret = (ssize_t)len;
+
+ mutex_unlock(µcode_mutex);
+ put_online_cpus();
+
+ return ret;
+}
+
+static const struct file_operations microcode_fops = {
+ .owner = THIS_MODULE,
+ .write = microcode_write,
+ .open = microcode_open,
+};
+
+static struct miscdevice microcode_dev = {
+ .minor = MICROCODE_MINOR,
+ .name = "microcode",
+ .fops = µcode_fops,
+};
+
+static int __init microcode_dev_init (void)
+{
+ int error;
+
+ error = misc_register(µcode_dev);
+ if (error) {
+ printk(KERN_ERR
+ "microcode: can't misc_register on minor=%d\n",
+ MICROCODE_MINOR);
+ return error;
+ }
+
+ return 0;
+}
+
+static void microcode_dev_exit (void)
+{
+ misc_deregister(µcode_dev);
+}
+
+MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
+#else
+#define microcode_dev_init() 0
+#define microcode_dev_exit() do { } while(0)
+#endif
+
+/* fake device for request_firmware */
+struct platform_device *microcode_pdev;
+
+static void microcode_init_cpu(int cpu, int resume)
+{
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ old = current->cpus_allowed;
+
+ set_cpus_allowed_ptr(current, newmask);
+ mutex_lock(µcode_mutex);
+ collect_cpu_info(cpu);
+ if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
+ cpu_request_microcode(cpu);
+ mutex_unlock(µcode_mutex);
+ set_cpus_allowed_ptr(current, &old);
+}
+
+static ssize_t reload_store(struct sys_device *dev,
+ struct sysdev_attribute *attr,
+ const char *buf, size_t sz)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+ char *end;
+ unsigned long val = simple_strtoul(buf, &end, 0);
+ int err = 0;
+ int cpu = dev->id;
+
+ if (end == buf)
+ return -EINVAL;
+ if (val == 1) {
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+
+ old = current->cpus_allowed;
+
+ get_online_cpus();
+ set_cpus_allowed_ptr(current, newmask);
+
+ mutex_lock(µcode_mutex);
+ if (uci->valid)
+ err = cpu_request_microcode(cpu);
+ mutex_unlock(µcode_mutex);
+ put_online_cpus();
+ set_cpus_allowed_ptr(current, &old);
+ }
+ if (err)
+ return err;
+ return sz;
+}
+
+static ssize_t version_show(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+
+ return sprintf(buf, "0x%x\n", uci->rev);
+}
+
+static ssize_t pf_show(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
+
+ return sprintf(buf, "0x%x\n", uci->pf);
+}
+
+static SYSDEV_ATTR(reload, 0200, NULL, reload_store);
+static SYSDEV_ATTR(version, 0400, version_show, NULL);
+static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL);
+
+static struct attribute *mc_default_attrs[] = {
+ &attr_reload.attr,
+ &attr_version.attr,
+ &attr_processor_flags.attr,
+ NULL
+};
+
+static struct attribute_group mc_attr_group = {
+ .attrs = mc_default_attrs,
+ .name = "microcode",
+};
+
+static int __mc_sysdev_add(struct sys_device *sys_dev, int resume)
+{
+ int err, cpu = sys_dev->id;
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ if (!cpu_online(cpu))
+ return 0;
+
+ pr_debug("microcode: CPU%d added\n", cpu);
+ memset(uci, 0, sizeof(*uci));
+
+ err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group);
+ if (err)
+ return err;
+
+ microcode_init_cpu(cpu, resume);
+
+ return 0;
+}
+
+static int mc_sysdev_add(struct sys_device *sys_dev)
+{
+ return __mc_sysdev_add(sys_dev, 0);
+}
+
+static int mc_sysdev_remove(struct sys_device *sys_dev)
+{
+ int cpu = sys_dev->id;
+
+ if (!cpu_online(cpu))
+ return 0;
+
+ pr_debug("microcode: CPU%d removed\n", cpu);
+ microcode_fini_cpu(cpu);
+ sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
+ return 0;
+}
+
+static int mc_sysdev_resume(struct sys_device *dev)
+{
+ int cpu = dev->id;
+
+ if (!cpu_online(cpu))
+ return 0;
+ pr_debug("microcode: CPU%d resumed\n", cpu);
+ /* only CPU 0 will apply ucode here */
+ apply_microcode(0);
+ return 0;
+}
+
+static struct sysdev_driver mc_sysdev_driver = {
+ .add = mc_sysdev_add,
+ .remove = mc_sysdev_remove,
+ .resume = mc_sysdev_resume,
+};
+
+static __cpuinit int
+mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
+{
+ unsigned int cpu = (unsigned long)hcpu;
+ struct sys_device *sys_dev;
+
+ sys_dev = get_cpu_sysdev(cpu);
+ switch (action) {
+ case CPU_UP_CANCELED_FROZEN:
+ /* The CPU refused to come up during a system resume */
+ microcode_fini_cpu(cpu);
+ break;
+ case CPU_ONLINE:
+ case CPU_DOWN_FAILED:
+ mc_sysdev_add(sys_dev);
+ break;
+ case CPU_ONLINE_FROZEN:
+ /* System-wide resume is in progress, try to apply microcode */
+ if (apply_microcode_check_cpu(cpu)) {
+ /* The application of microcode failed */
+ microcode_fini_cpu(cpu);
+ __mc_sysdev_add(sys_dev, 1);
+ break;
+ }
+ case CPU_DOWN_FAILED_FROZEN:
+ if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group))
+ printk(KERN_ERR "microcode: Failed to create the sysfs "
+ "group for CPU%d\n", cpu);
+ break;
+ case CPU_DOWN_PREPARE:
+ mc_sysdev_remove(sys_dev);
+ break;
+ case CPU_DOWN_PREPARE_FROZEN:
+ /* Suspend is in progress, only remove the interface */
+ sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
+ break;
+ }
+ return NOTIFY_OK;
+}
+
+static struct notifier_block __refdata mc_cpu_notifier = {
+ .notifier_call = mc_cpu_callback,
+};
+
+static int __init microcode_init (void)
+{
+ int error;
+
+ printk(KERN_INFO
+ "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
+
+ error = microcode_dev_init();
+ if (error)
+ return error;
+ microcode_pdev = platform_device_register_simple("microcode", -1,
+ NULL, 0);
+ if (IS_ERR(microcode_pdev)) {
+ microcode_dev_exit();
+ return PTR_ERR(microcode_pdev);
+ }
+
+ get_online_cpus();
+ error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver);
+ put_online_cpus();
+ if (error) {
+ microcode_dev_exit();
+ platform_device_unregister(microcode_pdev);
+ return error;
+ }
+
+ register_hotcpu_notifier(&mc_cpu_notifier);
+ return 0;
+}
+
+static void __exit microcode_exit (void)
+{
+ microcode_dev_exit();
+
+ unregister_hotcpu_notifier(&mc_cpu_notifier);
+
+ get_online_cpus();
+ sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);
+ put_online_cpus();
+
+ platform_device_unregister(microcode_pdev);
+}
+
+module_init(microcode_init)
+module_exit(microcode_exit)
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
index 4e7b2f6..eded0a1 100644
--- a/arch/x86/kernel/microcode_intel.c
+++ b/arch/x86/kernel/microcode_intel.c
@@ -95,18 +95,16 @@
#include <asm/processor.h>
#include <asm/microcode.h>
-MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver");
+MODULE_DESCRIPTION("Microcode Update Driver");
MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
MODULE_LICENSE("GPL");
-#define MICROCODE_VERSION "1.14a"
-
#define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
-#define MC_HEADER_SIZE (sizeof (struct microcode_header)) /* 48 bytes */
+#define MC_HEADER_SIZE (sizeof(struct microcode_header)) /* 48 bytes */
#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
-#define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */
-#define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */
-#define DWSIZE (sizeof (u32))
+#define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) /* 20 bytes */
+#define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) /* 12 bytes */
+#define DWSIZE (sizeof(u32))
#define get_totalsize(mc) \
(((struct microcode *)mc)->hdr.totalsize ? \
((struct microcode *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
@@ -123,11 +121,11 @@ MODULE_LICENSE("GPL");
static DEFINE_SPINLOCK(microcode_update_lock);
/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
-static DEFINE_MUTEX(microcode_mutex);
+extern struct mutex microcode_mutex;
-static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+extern struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
-static void collect_cpu_info(int cpu_num)
+void collect_cpu_info(int cpu_num)
{
struct cpuinfo_x86 *c = &cpu_data(cpu_num);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -140,7 +138,7 @@ static void collect_cpu_info(int cpu_num)
uci->valid = 1;
if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
- cpu_has(c, X86_FEATURE_IA64)) {
+ cpu_has(c, X86_FEATURE_IA64)) {
printk(KERN_ERR "microcode: CPU%d not a capable Intel "
"processor\n", cpu_num);
uci->valid = 0;
@@ -175,7 +173,7 @@ static inline int microcode_update_match(int cpu_num,
return 1;
}
-static int microcode_sanity_check(void *mc)
+int microcode_sanity_check(void *mc)
{
struct microcode_header *mc_header = mc;
struct extended_sigtable *ext_header = NULL;
@@ -259,7 +257,7 @@ static int microcode_sanity_check(void *mc)
* return 1 - found update
* return < 0 - error
*/
-static int get_maching_microcode(void *mc, int cpu)
+int get_matching_microcode(void *mc, int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
struct microcode_header *mc_header = mc;
@@ -288,7 +286,7 @@ static int get_maching_microcode(void *mc, int cpu)
return 0;
find:
pr_debug("microcode: CPU%d found a matching microcode update with"
- " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev);
+ " version 0x%x (current=0x%x)\n", cpu, mc_header->rev, uci->rev);
new_mc = vmalloc(total_size);
if (!new_mc) {
printk(KERN_ERR "microcode: error! Can not allocate memory\n");
@@ -303,7 +301,7 @@ find:
return 1;
}
-static void apply_microcode(int cpu)
+void apply_microcode(int cpu)
{
unsigned long flags;
unsigned int val[2];
@@ -344,10 +342,10 @@ static void apply_microcode(int cpu)
}
#ifdef CONFIG_MICROCODE_OLD_INTERFACE
-static void __user *user_buffer; /* user area microcode data buffer */
-static unsigned int user_buffer_size; /* it's size */
+extern void __user *user_buffer; /* user area microcode data buffer */
+extern unsigned int user_buffer_size; /* it's size */
-static long get_next_ucode(void **mc, long offset)
+long get_next_ucode(void **mc, long offset)
{
struct microcode_header mc_header;
unsigned long total_size;
@@ -375,117 +373,6 @@ static long get_next_ucode(void **mc, long offset)
}
return offset + total_size;
}
-
-static int do_microcode_update (void)
-{
- long cursor = 0;
- int error = 0;
- void *new_mc = NULL;
- int cpu;
- cpumask_t old;
- cpumask_of_cpu_ptr_declare(newmask);
-
- old = current->cpus_allowed;
-
- while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) {
- error = microcode_sanity_check(new_mc);
- if (error)
- goto out;
- /*
- * It's possible the data file has multiple matching ucode,
- * lets keep searching till the latest version
- */
- for_each_online_cpu(cpu) {
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- if (!uci->valid)
- continue;
- cpumask_of_cpu_ptr_next(newmask, cpu);
- set_cpus_allowed_ptr(current, newmask);
- error = get_maching_microcode(new_mc, cpu);
- if (error < 0)
- goto out;
- if (error == 1)
- apply_microcode(cpu);
- }
- vfree(new_mc);
- }
-out:
- if (cursor > 0)
- vfree(new_mc);
- if (cursor < 0)
- error = cursor;
- set_cpus_allowed_ptr(current, &old);
- return error;
-}
-
-static int microcode_open (struct inode *unused1, struct file *unused2)
-{
- cycle_kernel_lock();
- return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
-}
-
-static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos)
-{
- ssize_t ret;
-
- if ((len >> PAGE_SHIFT) > num_physpages) {
- printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages);
- return -EINVAL;
- }
-
- get_online_cpus();
- mutex_lock(µcode_mutex);
-
- user_buffer = (void __user *) buf;
- user_buffer_size = (int) len;
-
- ret = do_microcode_update();
- if (!ret)
- ret = (ssize_t)len;
-
- mutex_unlock(µcode_mutex);
- put_online_cpus();
-
- return ret;
-}
-
-static const struct file_operations microcode_fops = {
- .owner = THIS_MODULE,
- .write = microcode_write,
- .open = microcode_open,
-};
-
-static struct miscdevice microcode_dev = {
- .minor = MICROCODE_MINOR,
- .name = "microcode",
- .fops = µcode_fops,
-};
-
-static int __init microcode_dev_init (void)
-{
- int error;
-
- error = misc_register(µcode_dev);
- if (error) {
- printk(KERN_ERR
- "microcode: can't misc_register on minor=%d\n",
- MICROCODE_MINOR);
- return error;
- }
-
- return 0;
-}
-
-static void microcode_dev_exit (void)
-{
- misc_deregister(µcode_dev);
-}
-
-MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
-#else
-#define microcode_dev_init() 0
-#define microcode_dev_exit() do { } while(0)
#endif
static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
@@ -515,9 +402,9 @@ static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
}
/* fake device for request_firmware */
-static struct platform_device *microcode_pdev;
+extern struct platform_device *microcode_pdev;
-static int cpu_request_microcode(int cpu)
+int cpu_request_microcode(int cpu)
{
char name[30];
struct cpuinfo_x86 *c = &cpu_data(cpu);
@@ -530,7 +417,7 @@ static int cpu_request_microcode(int cpu)
/* We should bind the task to the CPU */
BUG_ON(cpu != raw_smp_processor_id());
- sprintf(name,"intel-ucode/%02x-%02x-%02x",
+ sprintf(name, "intel-ucode/%02x-%02x-%02x",
c->x86, c->x86_model, c->x86_mask);
error = request_firmware(&firmware, name, µcode_pdev->dev);
if (error) {
@@ -544,7 +431,7 @@ static int cpu_request_microcode(int cpu)
error = microcode_sanity_check(mc);
if (error)
break;
- error = get_maching_microcode(mc, cpu);
+ error = get_matching_microcode(mc, cpu);
if (error < 0)
break;
/*
@@ -566,7 +453,7 @@ static int cpu_request_microcode(int cpu)
return error;
}
-static int apply_microcode_check_cpu(int cpu)
+int apply_microcode_check_cpu(int cpu)
{
struct cpuinfo_x86 *c = &cpu_data(cpu);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -615,241 +502,13 @@ static int apply_microcode_check_cpu(int cpu)
return err;
}
-static void microcode_init_cpu(int cpu, int resume)
-{
- cpumask_t old;
- cpumask_of_cpu_ptr(newmask, cpu);
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- old = current->cpus_allowed;
-
- set_cpus_allowed_ptr(current, newmask);
- mutex_lock(µcode_mutex);
- collect_cpu_info(cpu);
- if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
- cpu_request_microcode(cpu);
- mutex_unlock(µcode_mutex);
- set_cpus_allowed_ptr(current, &old);
-}
-
-static void microcode_fini_cpu(int cpu)
+void microcode_fini_cpu(int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
mutex_lock(µcode_mutex);
uci->valid = 0;
- vfree(uci->mc);
+ kfree(uci->mc);
uci->mc = NULL;
mutex_unlock(µcode_mutex);
}
-
-static ssize_t reload_store(struct sys_device *dev,
- struct sysdev_attribute *attr,
- const char *buf, size_t sz)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
- char *end;
- unsigned long val = simple_strtoul(buf, &end, 0);
- int err = 0;
- int cpu = dev->id;
-
- if (end == buf)
- return -EINVAL;
- if (val == 1) {
- cpumask_t old;
- cpumask_of_cpu_ptr(newmask, cpu);
-
- old = current->cpus_allowed;
-
- get_online_cpus();
- set_cpus_allowed_ptr(current, newmask);
-
- mutex_lock(µcode_mutex);
- if (uci->valid)
- err = cpu_request_microcode(cpu);
- mutex_unlock(µcode_mutex);
- put_online_cpus();
- set_cpus_allowed_ptr(current, &old);
- }
- if (err)
- return err;
- return sz;
-}
-
-static ssize_t version_show(struct sys_device *dev,
- struct sysdev_attribute *attr, char *buf)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
-
- return sprintf(buf, "0x%x\n", uci->rev);
-}
-
-static ssize_t pf_show(struct sys_device *dev,
- struct sysdev_attribute *attr, char *buf)
-{
- struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
-
- return sprintf(buf, "0x%x\n", uci->pf);
-}
-
-static SYSDEV_ATTR(reload, 0200, NULL, reload_store);
-static SYSDEV_ATTR(version, 0400, version_show, NULL);
-static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL);
-
-static struct attribute *mc_default_attrs[] = {
- &attr_reload.attr,
- &attr_version.attr,
- &attr_processor_flags.attr,
- NULL
-};
-
-static struct attribute_group mc_attr_group = {
- .attrs = mc_default_attrs,
- .name = "microcode",
-};
-
-static int __mc_sysdev_add(struct sys_device *sys_dev, int resume)
-{
- int err, cpu = sys_dev->id;
- struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-
- if (!cpu_online(cpu))
- return 0;
-
- pr_debug("microcode: CPU%d added\n", cpu);
- memset(uci, 0, sizeof(*uci));
-
- err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group);
- if (err)
- return err;
-
- microcode_init_cpu(cpu, resume);
-
- return 0;
-}
-
-static int mc_sysdev_add(struct sys_device *sys_dev)
-{
- return __mc_sysdev_add(sys_dev, 0);
-}
-
-static int mc_sysdev_remove(struct sys_device *sys_dev)
-{
- int cpu = sys_dev->id;
-
- if (!cpu_online(cpu))
- return 0;
-
- pr_debug("microcode: CPU%d removed\n", cpu);
- microcode_fini_cpu(cpu);
- sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
- return 0;
-}
-
-static int mc_sysdev_resume(struct sys_device *dev)
-{
- int cpu = dev->id;
-
- if (!cpu_online(cpu))
- return 0;
- pr_debug("microcode: CPU%d resumed\n", cpu);
- /* only CPU 0 will apply ucode here */
- apply_microcode(0);
- return 0;
-}
-
-static struct sysdev_driver mc_sysdev_driver = {
- .add = mc_sysdev_add,
- .remove = mc_sysdev_remove,
- .resume = mc_sysdev_resume,
-};
-
-static __cpuinit int
-mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
-{
- unsigned int cpu = (unsigned long)hcpu;
- struct sys_device *sys_dev;
-
- sys_dev = get_cpu_sysdev(cpu);
- switch (action) {
- case CPU_UP_CANCELED_FROZEN:
- /* The CPU refused to come up during a system resume */
- microcode_fini_cpu(cpu);
- break;
- case CPU_ONLINE:
- case CPU_DOWN_FAILED:
- mc_sysdev_add(sys_dev);
- break;
- case CPU_ONLINE_FROZEN:
- /* System-wide resume is in progress, try to apply microcode */
- if (apply_microcode_check_cpu(cpu)) {
- /* The application of microcode failed */
- microcode_fini_cpu(cpu);
- __mc_sysdev_add(sys_dev, 1);
- break;
- }
- case CPU_DOWN_FAILED_FROZEN:
- if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group))
- printk(KERN_ERR "microcode: Failed to create the sysfs "
- "group for CPU%d\n", cpu);
- break;
- case CPU_DOWN_PREPARE:
- mc_sysdev_remove(sys_dev);
- break;
- case CPU_DOWN_PREPARE_FROZEN:
- /* Suspend is in progress, only remove the interface */
- sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
- break;
- }
- return NOTIFY_OK;
-}
-
-static struct notifier_block __refdata mc_cpu_notifier = {
- .notifier_call = mc_cpu_callback,
-};
-
-static int __init microcode_init (void)
-{
- int error;
-
- printk(KERN_INFO
- "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
-
- error = microcode_dev_init();
- if (error)
- return error;
- microcode_pdev = platform_device_register_simple("microcode", -1,
- NULL, 0);
- if (IS_ERR(microcode_pdev)) {
- microcode_dev_exit();
- return PTR_ERR(microcode_pdev);
- }
-
- get_online_cpus();
- error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver);
- put_online_cpus();
- if (error) {
- microcode_dev_exit();
- platform_device_unregister(microcode_pdev);
- return error;
- }
-
- register_hotcpu_notifier(&mc_cpu_notifier);
- return 0;
-}
-
-static void __exit microcode_exit (void)
-{
- microcode_dev_exit();
-
- unregister_hotcpu_notifier(&mc_cpu_notifier);
-
- get_online_cpus();
- sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver);
- put_online_cpus();
-
- platform_device_unregister(microcode_pdev);
-}
-
-module_init(microcode_init)
-module_exit(microcode_exit)
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 07/11] [PATCH 07/11] x86: Structure declaration renaming.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (4 preceding siblings ...)
2008-07-28 16:44 ` [patch 06/11] [PATCH 06/11] x86: Code split to two parts Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 08/11] [PATCH 08/11] x86: Add AMD specific declarations Peter Oruba
` (4 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0007-x86-Structure-declaration-renaming.patch --]
[-- Type: text/plain, Size: 6644 bytes --]
Renamed common structures to vendor specific naming scheme
so other vendors will be able to use the same naming
convention.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
Conflicts:
---
arch/x86/kernel/microcode_intel.c | 46 +++++++++++++++++++-----------------
include/asm-x86/microcode.h | 10 +++++---
2 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
index eded0a1..ca9861b 100644
--- a/arch/x86/kernel/microcode_intel.c
+++ b/arch/x86/kernel/microcode_intel.c
@@ -100,17 +100,19 @@ MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
MODULE_LICENSE("GPL");
#define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
-#define MC_HEADER_SIZE (sizeof(struct microcode_header)) /* 48 bytes */
+#define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) /* 48 bytes */
#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
#define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) /* 20 bytes */
#define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) /* 12 bytes */
#define DWSIZE (sizeof(u32))
#define get_totalsize(mc) \
- (((struct microcode *)mc)->hdr.totalsize ? \
- ((struct microcode *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
+ (((struct microcode_intel *)mc)->hdr.totalsize ? \
+ ((struct microcode_intel *)mc)->hdr.totalsize : \
+ DEFAULT_UCODE_TOTALSIZE)
+
#define get_datasize(mc) \
- (((struct microcode *)mc)->hdr.datasize ? \
- ((struct microcode *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
+ (((struct microcode_intel *)mc)->hdr.datasize ? \
+ ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
#define sigmatch(s1, s2, p1, p2) \
(((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))
@@ -134,7 +136,7 @@ void collect_cpu_info(int cpu_num)
/* We should bind the task to the CPU */
BUG_ON(raw_smp_processor_id() != cpu_num);
uci->pf = uci->rev = 0;
- uci->mc = NULL;
+ uci->mc.mc_intel = NULL;
uci->valid = 1;
if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
@@ -163,7 +165,7 @@ void collect_cpu_info(int cpu_num)
}
static inline int microcode_update_match(int cpu_num,
- struct microcode_header *mc_header, int sig, int pf)
+ struct microcode_header_intel *mc_header, int sig, int pf)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -175,7 +177,7 @@ static inline int microcode_update_match(int cpu_num,
int microcode_sanity_check(void *mc)
{
- struct microcode_header *mc_header = mc;
+ struct microcode_header_intel *mc_header = mc;
struct extended_sigtable *ext_header = NULL;
struct extended_signature *ext_sig;
unsigned long total_size, data_size, ext_table_size;
@@ -260,7 +262,7 @@ int microcode_sanity_check(void *mc)
int get_matching_microcode(void *mc, int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
- struct microcode_header *mc_header = mc;
+ struct microcode_header_intel *mc_header = mc;
struct extended_sigtable *ext_header;
unsigned long total_size = get_totalsize(mc_header);
int ext_sigcount, i;
@@ -294,10 +296,10 @@ find:
}
/* free previous update file */
- vfree(uci->mc);
+ vfree(uci->mc.mc_intel);
memcpy(new_mc, mc, total_size);
- uci->mc = new_mc;
+ uci->mc.mc_intel = new_mc;
return 1;
}
@@ -311,7 +313,7 @@ void apply_microcode(int cpu)
/* We should bind the task to the CPU */
BUG_ON(cpu_num != cpu);
- if (uci->mc == NULL)
+ if (uci->mc.mc_intel == NULL)
return;
/* serialize access to the physical write to MSR 0x79 */
@@ -319,8 +321,8 @@ void apply_microcode(int cpu)
/* write microcode via MSR 0x79 */
wrmsr(MSR_IA32_UCODE_WRITE,
- (unsigned long) uci->mc->bits,
- (unsigned long) uci->mc->bits >> 16 >> 16);
+ (unsigned long) uci->mc.mc_intel->bits,
+ (unsigned long) uci->mc.mc_intel->bits >> 16 >> 16);
wrmsr(MSR_IA32_UCODE_REV, 0, 0);
/* see notes above for revision 1.07. Apparent chip bug */
@@ -330,14 +332,14 @@ void apply_microcode(int cpu)
rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
spin_unlock_irqrestore(µcode_update_lock, flags);
- if (val[1] != uci->mc->hdr.rev) {
+ if (val[1] != uci->mc.mc_intel->hdr.rev) {
printk(KERN_ERR "microcode: CPU%d update from revision "
"0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]);
return;
}
printk(KERN_INFO "microcode: CPU%d updated from revision "
"0x%x to 0x%x, date = %08x \n",
- cpu_num, uci->rev, val[1], uci->mc->hdr.date);
+ cpu_num, uci->rev, val[1], uci->mc.mc_intel->hdr.date);
uci->rev = val[1];
}
@@ -347,7 +349,7 @@ extern unsigned int user_buffer_size; /* it's size */
long get_next_ucode(void **mc, long offset)
{
- struct microcode_header mc_header;
+ struct microcode_header_intel mc_header;
unsigned long total_size;
/* No more data */
@@ -378,13 +380,13 @@ long get_next_ucode(void **mc, long offset)
static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
unsigned long size, long offset)
{
- struct microcode_header *mc_header;
+ struct microcode_header_intel *mc_header;
unsigned long total_size;
/* No more data */
if (offset >= size)
return 0;
- mc_header = (struct microcode_header *)(buf + offset);
+ mc_header = (struct microcode_header_intel *)(buf + offset);
total_size = get_totalsize(mc_header);
if (offset + total_size > size) {
@@ -463,7 +465,7 @@ int apply_microcode_check_cpu(int cpu)
int err = 0;
/* Check if the microcode is available */
- if (!uci->mc)
+ if (!uci->mc.mc_intel)
return 0;
old = current->cpus_allowed;
@@ -508,7 +510,7 @@ void microcode_fini_cpu(int cpu)
mutex_lock(µcode_mutex);
uci->valid = 0;
- kfree(uci->mc);
- uci->mc = NULL;
+ kfree(uci->mc.mc_intel);
+ uci->mc.mc_intel = NULL;
mutex_unlock(µcode_mutex);
}
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index d34a1fc..ef77c6f 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -1,4 +1,4 @@
-struct microcode_header {
+struct microcode_header_intel {
unsigned int hdrver;
unsigned int rev;
unsigned int date;
@@ -11,8 +11,8 @@ struct microcode_header {
unsigned int reserved[3];
};
-struct microcode {
- struct microcode_header hdr;
+struct microcode_intel {
+ struct microcode_header_intel hdr;
unsigned int bits[0];
};
@@ -35,5 +35,7 @@ struct ucode_cpu_info {
unsigned int sig;
unsigned int pf;
unsigned int rev;
- struct microcode *mc;
+ union {
+ struct microcode_intel *mc_intel;
+ } mc;
};
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 08/11] [PATCH 08/11] x86: Add AMD specific declarations.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (5 preceding siblings ...)
2008-07-28 16:44 ` [patch 07/11] [PATCH 07/11] x86: Structure declaration renaming Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 09/11] [PATCH 09/11] x86: First step of refactoring, introducing microcode_ops Peter Oruba
` (3 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0008-x86-Add-AMD-specific-declarations.patch --]
[-- Type: text/plain, Size: 1418 bytes --]
Added AMD specific declarations to header file.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
include/asm-x86/microcode.h | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index ef77c6f..4e94172 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -30,6 +30,35 @@ struct extended_sigtable {
struct extended_signature sigs[0];
};
+struct equiv_cpu_entry {
+ unsigned int installed_cpu;
+ unsigned int fixed_errata_mask;
+ unsigned int fixed_errata_compare;
+ unsigned int equiv_cpu;
+};
+
+struct microcode_header_amd {
+ unsigned int data_code;
+ unsigned int patch_id;
+ unsigned char mc_patch_data_id[2];
+ unsigned char mc_patch_data_len;
+ unsigned char init_flag;
+ unsigned int mc_patch_data_checksum;
+ unsigned int nb_dev_id;
+ unsigned int sb_dev_id;
+ unsigned char processor_rev_id[2];
+ unsigned char nb_rev_id;
+ unsigned char sb_rev_id;
+ unsigned char bios_api_rev;
+ unsigned char reserved1[3];
+ unsigned int match_reg[8];
+};
+
+struct microcode_amd {
+ struct microcode_header_amd hdr;
+ unsigned int mpb[0];
+};
+
struct ucode_cpu_info {
int valid;
unsigned int sig;
@@ -37,5 +66,6 @@ struct ucode_cpu_info {
unsigned int rev;
union {
struct microcode_intel *mc_intel;
+ struct microcode_amd *mc_amd;
} mc;
};
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 09/11] [PATCH 09/11] x86: First step of refactoring, introducing microcode_ops.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (6 preceding siblings ...)
2008-07-28 16:44 ` [patch 08/11] [PATCH 08/11] x86: Add AMD specific declarations Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 16:44 ` [patch 10/11] [PATCH 10/11] x86: Major refactoring Peter Oruba
` (2 subsequent siblings)
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0009-x86-First-step-of-refactoring-introducing-microcod.patch --]
[-- Type: text/plain, Size: 1239 bytes --]
Refactoring with the goal of having one general module and separate
vendor specific modules that hook into the general one.
Microcode_ops is a function pointer structure in which vendor
specific modules will enter all functions that differ between
vendors and that need to be accessed from the general module.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
include/asm-x86/microcode.h | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index 4e94172..9231c87 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -1,3 +1,16 @@
+struct microcode_ops {
+ long (*get_next_ucode)(void **mc, long offset);
+ long (*microcode_get_next_ucode)(void **mc, long offset);
+ int (*get_matching_microcode)(void *mc, int cpu);
+ int (*apply_microcode_check_cpu)(int cpu);
+ int (*microcode_sanity_check)(void *mc);
+ int (*cpu_request_microcode)(int cpu);
+ void (*collect_cpu_info)(int cpu_num);
+ void (*apply_microcode)(int cpu);
+ void (*microcode_fini_cpu)(int cpu);
+ void (*clear_patch)(void *data);
+};
+
struct microcode_header_intel {
unsigned int hdrver;
unsigned int rev;
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 10/11] [PATCH 10/11] x86: Major refactoring.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (7 preceding siblings ...)
2008-07-28 16:44 ` [patch 09/11] [PATCH 09/11] x86: First step of refactoring, introducing microcode_ops Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 19:36 ` Max Krasnyansky
2008-07-28 16:44 ` [patch 11/11] [PATCH 11/11] x86: AMD microcode patch loading support Peter Oruba
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
10 siblings, 1 reply; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0010-x86-Major-refactoring.patch --]
[-- Type: text/plain, Size: 13484 bytes --]
Refactored code by introducing a two-module solution. There is one
general module in which vendor specific modules can hook into.
However, that is exclusive, there is only one vendor specific module
allowed at a time. A CPU vendor check makes sure only the corect
module for the underlying system gets called. Functinally in terms
of patch loading itself there are no changes. This refactoring
provides a basis for future implementations of other vendors'
patch loaders.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/Kconfig | 25 +++++++++--
arch/x86/kernel/Makefile | 4 +-
arch/x86/kernel/microcode.c | 80 +++++++++++++++++++++---------------
arch/x86/kernel/microcode_intel.c | 50 ++++++++++++++++++-----
include/asm-x86/microcode.h | 3 +
5 files changed, 112 insertions(+), 50 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index b6fa287..6b0b885 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -782,7 +782,7 @@ config X86_REBOOTFIXUPS
Say N otherwise.
config MICROCODE
- tristate "/dev/cpu/microcode - Intel IA32 CPU microcode support"
+ tristate "/dev/cpu/microcode - microcode support"
select FW_LOADER
---help---
If you say Y here, you will be able to update the microcode on
@@ -791,14 +791,29 @@ config MICROCODE
actual microcode binary data itself which is not shipped with the
Linux kernel.
- For latest news and information on obtaining all the required
- ingredients for this driver, check:
- <http://www.urbanmyth.org/microcode/>.
+ This option selects the general module only, you need to select
+ at least one vendor specific module as well.
To compile this driver as a module, choose M here: the
module will be called microcode.
-config MICROCODE_OLD_INTERFACE
+config MICROCODE_INTEL
+ tristate "Intel microcode patch loading support"
+ depends on MICROCODE
+ default MICROCODE
+ select FW_LOADER
+ --help---
+ This options enables microcode patch loading support for Intel
+ processors.
+
+ For latest news and information on obtaining all the required
+ Intel ingredients for this driver, check:
+ <http://www.urbanmyth.org/microcode/>.
+
+ This driver is only available as a module: the module
+ will be called microcode_intel.
+
+ config MICROCODE_OLD_INTERFACE
def_bool y
depends on MICROCODE
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index abb32ae..f2f9f6d 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -51,8 +51,8 @@ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
obj-$(CONFIG_MCA) += mca_32.o
obj-$(CONFIG_X86_MSR) += msr.o
obj-$(CONFIG_X86_CPUID) += cpuid.o
-obj-$(CONFIG_MICROCODE) += ucode.o
-ucode-objs := microcode.o microcode_intel.o
+obj-$(CONFIG_MICROCODE) += microcode.o
+obj-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o
obj-$(CONFIG_PCI) += early-quirks.o
apm-y := apm_32.o
obj-$(CONFIG_APM) += apm.o
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index c1047d7..1e42e79 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -99,25 +99,22 @@ MODULE_DESCRIPTION("Microcode Update Driver");
MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
MODULE_LICENSE("GPL");
-#define MICROCODE_VERSION "1.14a"
+#define MICROCODE_VERSION "2.00"
-/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
-DEFINE_MUTEX(microcode_mutex);
+struct microcode_ops *microcode_ops;
-struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
+static DEFINE_MUTEX(microcode_mutex);
+EXPORT_SYMBOL_GPL(microcode_mutex);
-extern long get_next_ucode(void **mc, long offset);
-extern int microcode_sanity_check(void *mc);
-extern int get_matching_microcode(void *mc, int cpu);
-extern void collect_cpu_info(int cpu_num);
-extern int cpu_request_microcode(int cpu);
-extern void microcode_fini_cpu(int cpu);
-extern void apply_microcode(int cpu);
-extern int apply_microcode_check_cpu(int cpu);
+static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+EXPORT_SYMBOL_GPL(ucode_cpu_info);
#ifdef CONFIG_MICROCODE_OLD_INTERFACE
-void __user *user_buffer; /* user area microcode data buffer */
-unsigned int user_buffer_size; /* it's size */
+static void __user *user_buffer; /* user area microcode data buffer */
+EXPORT_SYMBOL_GPL(user_buffer);
+static unsigned int user_buffer_size; /* it's size */
+EXPORT_SYMBOL_GPL(user_buffer_size);
static int do_microcode_update (void)
{
@@ -130,8 +127,8 @@ static int do_microcode_update (void)
old = current->cpus_allowed;
- while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) {
- error = microcode_sanity_check(new_mc);
+ while ((cursor = microcode_ops->get_next_ucode(&new_mc, cursor)) > 0) {
+ error = microcode_ops->microcode_sanity_check(new_mc);
if (error)
goto out;
/*
@@ -145,11 +142,12 @@ static int do_microcode_update (void)
continue;
cpumask_of_cpu_ptr_next(newmask, cpu);
set_cpus_allowed_ptr(current, newmask);
- error = get_maching_microcode(new_mc, cpu);
+ error = microcode_ops->get_matching_microcode(new_mc,
+ cpu);
if (error < 0)
goto out;
if (error == 1)
- apply_microcode(cpu);
+ microcode_ops->apply_microcode(cpu);
}
vfree(new_mc);
}
@@ -232,7 +230,8 @@ MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
#endif
/* fake device for request_firmware */
-struct platform_device *microcode_pdev;
+static struct platform_device *microcode_pdev;
+EXPORT_SYMBOL_GPL(microcode_pdev);
static void microcode_init_cpu(int cpu, int resume)
{
@@ -244,9 +243,9 @@ static void microcode_init_cpu(int cpu, int resume)
set_cpus_allowed_ptr(current, newmask);
mutex_lock(µcode_mutex);
- collect_cpu_info(cpu);
+ microcode_ops->collect_cpu_info(cpu);
if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
- cpu_request_microcode(cpu);
+ microcode_ops->cpu_request_microcode(cpu);
mutex_unlock(µcode_mutex);
set_cpus_allowed_ptr(current, &old);
}
@@ -274,7 +273,7 @@ static ssize_t reload_store(struct sys_device *dev,
mutex_lock(µcode_mutex);
if (uci->valid)
- err = cpu_request_microcode(cpu);
+ err = microcode_ops->cpu_request_microcode(cpu);
mutex_unlock(µcode_mutex);
put_online_cpus();
set_cpus_allowed_ptr(current, &old);
@@ -349,7 +348,7 @@ static int mc_sysdev_remove(struct sys_device *sys_dev)
return 0;
pr_debug("microcode: CPU%d removed\n", cpu);
- microcode_fini_cpu(cpu);
+ microcode_ops->microcode_fini_cpu(cpu);
sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
return 0;
}
@@ -362,7 +361,7 @@ static int mc_sysdev_resume(struct sys_device *dev)
return 0;
pr_debug("microcode: CPU%d resumed\n", cpu);
/* only CPU 0 will apply ucode here */
- apply_microcode(0);
+ microcode_ops->apply_microcode(0);
return 0;
}
@@ -382,7 +381,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
switch (action) {
case CPU_UP_CANCELED_FROZEN:
/* The CPU refused to come up during a system resume */
- microcode_fini_cpu(cpu);
+ microcode_ops->microcode_fini_cpu(cpu);
break;
case CPU_ONLINE:
case CPU_DOWN_FAILED:
@@ -390,9 +389,9 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
break;
case CPU_ONLINE_FROZEN:
/* System-wide resume is in progress, try to apply microcode */
- if (apply_microcode_check_cpu(cpu)) {
+ if (microcode_ops->apply_microcode_check_cpu(cpu)) {
/* The application of microcode failed */
- microcode_fini_cpu(cpu);
+ microcode_ops->microcode_fini_cpu(cpu);
__mc_sysdev_add(sys_dev, 1);
break;
}
@@ -416,12 +415,17 @@ static struct notifier_block __refdata mc_cpu_notifier = {
.notifier_call = mc_cpu_callback,
};
-static int __init microcode_init (void)
+static int microcode_init(void *opaque, struct module *module)
{
+ struct microcode_ops *ops = (struct microcode_ops *)opaque;
int error;
- printk(KERN_INFO
- "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
+ if (microcode_ops) {
+ printk(KERN_ERR "microcode: already loaded the other module\n");
+ return -EEXIST;
+ }
+
+ microcode_ops = ops;
error = microcode_dev_init();
if (error)
@@ -443,8 +447,15 @@ static int __init microcode_init (void)
}
register_hotcpu_notifier(&mc_cpu_notifier);
+
+ printk(KERN_INFO
+ "Microcode Update Driver: v" MICROCODE_VERSION
+ " <tigran@aivazian.fsnet.co.uk>"
+ " <peter.oruba@amd.com>\n");
+
return 0;
}
+EXPORT_SYMBOL_GPL(microcode_init);
static void __exit microcode_exit (void)
{
@@ -457,7 +468,10 @@ static void __exit microcode_exit (void)
put_online_cpus();
platform_device_unregister(microcode_pdev);
-}
-module_init(microcode_init)
-module_exit(microcode_exit)
+ microcode_ops = NULL;
+
+ printk(KERN_INFO
+ "Microcode Update Driver: v" MICROCODE_VERSION " removed.\n");
+}
+EXPORT_SYMBOL_GPL(microcode_exit);
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
index ca9861b..831db53 100644
--- a/arch/x86/kernel/microcode_intel.c
+++ b/arch/x86/kernel/microcode_intel.c
@@ -127,7 +127,7 @@ extern struct mutex microcode_mutex;
extern struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
-void collect_cpu_info(int cpu_num)
+static void collect_cpu_info(int cpu_num)
{
struct cpuinfo_x86 *c = &cpu_data(cpu_num);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -175,7 +175,7 @@ static inline int microcode_update_match(int cpu_num,
return 1;
}
-int microcode_sanity_check(void *mc)
+static int microcode_sanity_check(void *mc)
{
struct microcode_header_intel *mc_header = mc;
struct extended_sigtable *ext_header = NULL;
@@ -259,7 +259,7 @@ int microcode_sanity_check(void *mc)
* return 1 - found update
* return < 0 - error
*/
-int get_matching_microcode(void *mc, int cpu)
+static int get_matching_microcode(void *mc, int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
struct microcode_header_intel *mc_header = mc;
@@ -288,7 +288,8 @@ int get_matching_microcode(void *mc, int cpu)
return 0;
find:
pr_debug("microcode: CPU%d found a matching microcode update with"
- " version 0x%x (current=0x%x)\n", cpu, mc_header->rev, uci->rev);
+ " version 0x%x (current=0x%x)\n",
+ cpu, mc_header->rev, uci->rev);
new_mc = vmalloc(total_size);
if (!new_mc) {
printk(KERN_ERR "microcode: error! Can not allocate memory\n");
@@ -303,7 +304,7 @@ find:
return 1;
}
-void apply_microcode(int cpu)
+static void apply_microcode(int cpu)
{
unsigned long flags;
unsigned int val[2];
@@ -347,7 +348,7 @@ void apply_microcode(int cpu)
extern void __user *user_buffer; /* user area microcode data buffer */
extern unsigned int user_buffer_size; /* it's size */
-long get_next_ucode(void **mc, long offset)
+static long get_next_ucode(void **mc, long offset)
{
struct microcode_header_intel mc_header;
unsigned long total_size;
@@ -406,7 +407,7 @@ static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
/* fake device for request_firmware */
extern struct platform_device *microcode_pdev;
-int cpu_request_microcode(int cpu)
+static int cpu_request_microcode(int cpu)
{
char name[30];
struct cpuinfo_x86 *c = &cpu_data(cpu);
@@ -455,7 +456,7 @@ int cpu_request_microcode(int cpu)
return error;
}
-int apply_microcode_check_cpu(int cpu)
+static int apply_microcode_check_cpu(int cpu)
{
struct cpuinfo_x86 *c = &cpu_data(cpu);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -504,13 +505,42 @@ int apply_microcode_check_cpu(int cpu)
return err;
}
-void microcode_fini_cpu(int cpu)
+static void microcode_fini_cpu(int cpu)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
mutex_lock(µcode_mutex);
uci->valid = 0;
- kfree(uci->mc.mc_intel);
+ vfree(uci->mc.mc_intel);
uci->mc.mc_intel = NULL;
mutex_unlock(µcode_mutex);
}
+
+static struct microcode_ops microcode_intel_ops = {
+ .get_next_ucode = get_next_ucode,
+ .get_matching_microcode = get_matching_microcode,
+ .microcode_sanity_check = microcode_sanity_check,
+ .apply_microcode_check_cpu = apply_microcode_check_cpu,
+ .cpu_request_microcode = cpu_request_microcode,
+ .collect_cpu_info = collect_cpu_info,
+ .apply_microcode = apply_microcode,
+ .microcode_fini_cpu = microcode_fini_cpu,
+};
+
+static int __init microcode_intel_module_init(void)
+{
+ struct cpuinfo_x86 *c = &cpu_data(get_cpu());
+
+ if (c->x86_vendor == X86_VENDOR_INTEL)
+ return microcode_init(µcode_intel_ops, THIS_MODULE);
+ else
+ return -ENODEV;
+}
+
+static void __exit microcode_intel_module_exit(void)
+{
+ microcode_exit();
+}
+
+module_init(microcode_intel_module_init)
+module_exit(microcode_intel_module_exit)
diff --git a/include/asm-x86/microcode.h b/include/asm-x86/microcode.h
index 9231c87..18b2aee 100644
--- a/include/asm-x86/microcode.h
+++ b/include/asm-x86/microcode.h
@@ -1,3 +1,6 @@
+extern int microcode_init(void *opaque, struct module *module);
+extern void microcode_exit(void);
+
struct microcode_ops {
long (*get_next_ucode)(void **mc, long offset);
long (*microcode_get_next_ucode)(void **mc, long offset);
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [patch 11/11] [PATCH 11/11] x86: AMD microcode patch loading support.
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (8 preceding siblings ...)
2008-07-28 16:44 ` [patch 10/11] [PATCH 10/11] x86: Major refactoring Peter Oruba
@ 2008-07-28 16:44 ` Peter Oruba
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
10 siblings, 0 replies; 32+ messages in thread
From: Peter Oruba @ 2008-07-28 16:44 UTC (permalink / raw)
To: Ingo Molnar, Thomas Gleixner, Tigran Aivazian; +Cc: LKML, Peter Oruba
[-- Attachment #1: 0011-x86-AMD-microcode-patch-loading-support.patch --]
[-- Type: text/plain, Size: 17448 bytes --]
This patch introduces microcode patch loading for AMD
processors. It is based on previous corresponding work
for Intel processors.
It hooks into the general patch loading module. Main
difference is that a container file format is used to hold
all patch data for multiple processors as well as an
equivalent CPU table, which comes seperately, as opposed
to Intel's microcode patching solution.
Kconfig and Makefile have been changed provice config
and build option for new source file.
Signed-off-by: Peter Oruba <peter.oruba@amd.com>
---
arch/x86/Kconfig | 21 ++-
arch/x86/kernel/Makefile | 1 +
arch/x86/kernel/microcode_amd.c | 521 +++++++++++++++++++++++++++++++++++++++
3 files changed, 539 insertions(+), 4 deletions(-)
create mode 100644 arch/x86/kernel/microcode_amd.c
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 6b0b885..7bb4617 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -786,10 +786,12 @@ config MICROCODE
select FW_LOADER
---help---
If you say Y here, you will be able to update the microcode on
- Intel processors in the IA32 family, e.g. Pentium Pro, Pentium II,
- Pentium III, Pentium 4, Xeon etc. You will obviously need the
- actual microcode binary data itself which is not shipped with the
- Linux kernel.
+ certain Intel and AMD processors. The Intel support is for the
+ IA32 family, e.g. Pentium Pro, Pentium II, Pentium III,
+ Pentium 4, Xeon etc. The AMD support is for family 0x10 and
+ 0x11 processors, e.g. Opteron, Phenom and Turion 64 Ultra.
+ You will obviously need the actual microcode binary data itself
+ which is not shipped with the Linux kernel.
This option selects the general module only, you need to select
at least one vendor specific module as well.
@@ -813,6 +815,17 @@ config MICROCODE_INTEL
This driver is only available as a module: the module
will be called microcode_intel.
+config MICROCODE_AMD
+ tristate "AMD microcode patch loading support"
+ depends on MICROCODE
+ select FW_LOADER
+ --help---
+ If you select this option, microcode patch loading support for AMD
+ processors will be enabled.
+
+ This driver is only available as a module: the module
+ will be called microcode_amd.
+
config MICROCODE_OLD_INTERFACE
def_bool y
depends on MICROCODE
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index f2f9f6d..be454f3 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_X86_MSR) += msr.o
obj-$(CONFIG_X86_CPUID) += cpuid.o
obj-$(CONFIG_MICROCODE) += microcode.o
obj-$(CONFIG_MICROCODE_INTEL) += microcode_intel.o
+obj-$(CONFIG_MICROCODE_AMD) += microcode_amd.o
obj-$(CONFIG_PCI) += early-quirks.o
apm-y := apm_32.o
obj-$(CONFIG_APM) += apm.o
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
new file mode 100644
index 0000000..db199e3
--- /dev/null
+++ b/arch/x86/kernel/microcode_amd.c
@@ -0,0 +1,521 @@
+/*
+ * AMD CPU Microcode Update Driver for Linux
+ * Copyright (C) 2008 Advanced Micro Devices Inc.
+ *
+ * Author: Peter Oruba <peter.oruba@amd.com>
+ *
+ * Based on work by:
+ * Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
+ *
+ * This driver allows to upgrade microcode on AMD
+ * family 0x10 and 0x11 processors.
+ *
+ * Licensed unter the terms of the GNU General Public
+ * License version 2. See file COPYING for details.
+*/
+
+#include <linux/capability.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/cpumask.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/miscdevice.h>
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/mutex.h>
+#include <linux/cpu.h>
+#include <linux/firmware.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/pci_ids.h>
+
+#include <asm/msr.h>
+#include <asm/uaccess.h>
+#include <asm/processor.h>
+#include <asm/microcode.h>
+
+MODULE_DESCRIPTION("AMD Microcode Update Driver");
+MODULE_AUTHOR("Peter Oruba <peter.oruba@amd.com>");
+MODULE_LICENSE("GPLv2");
+
+#define UCODE_MAGIC 0x00414d44
+#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
+#define UCODE_UCODE_TYPE 0x00000001
+
+#define UCODE_MAX_SIZE (2048)
+#define DEFAULT_UCODE_DATASIZE (896) /* 896 bytes */
+#define MC_HEADER_SIZE (sizeof(struct microcode_header_amd)) /* 64 bytes */
+#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 960 bytes */
+#define DWSIZE (sizeof(u32))
+/* For now we support a fixed ucode total size only */
+#define get_totalsize(mc) \
+ ((((struct microcode_amd *)mc)->hdr.mc_patch_data_len * 28) \
+ + MC_HEADER_SIZE)
+
+extern int microcode_init(void *opaque, struct module *module);
+extern void microcode_exit(void);
+
+/* serialize access to the physical write */
+static DEFINE_SPINLOCK(microcode_update_lock);
+
+/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
+extern struct mutex (microcode_mutex);
+
+struct equiv_cpu_entry *equiv_cpu_table;
+
+extern struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+
+static void collect_cpu_info_amd(int cpu)
+{
+ struct cpuinfo_x86 *c = &cpu_data(cpu);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(raw_smp_processor_id() != cpu);
+ uci->rev = 0;
+ uci->pf = 0;
+ uci->mc.mc_amd = NULL;
+ uci->valid = 1;
+
+ if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) {
+ printk(KERN_ERR "microcode: CPU%d not a capable AMD processor\n",
+ cpu);
+ uci->valid = 0;
+ return;
+ }
+
+ asm volatile("movl %1, %%ecx; rdmsr"
+ : "=a" (uci->rev)
+ : "i" (0x0000008B) : "ecx");
+
+ printk(KERN_INFO "microcode: collect_cpu_info_amd : patch_id=0x%x\n",
+ uci->rev);
+}
+
+static int get_matching_microcode_amd(void *mc, int cpu)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ struct microcode_header_amd *mc_header = mc;
+ unsigned long total_size = get_totalsize(mc_header);
+ void *new_mc;
+ struct pci_dev *nb_pci_dev, *sb_pci_dev;
+ unsigned int current_cpu_id;
+ unsigned int equiv_cpu_id = 0x00;
+ unsigned int i = 0;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(cpu != raw_smp_processor_id());
+
+ /* This is a tricky part. We might be called from a write operation */
+ /* to the device file instead of the usual process of firmware */
+ /* loading. This routine needs to be able to distinguish both */
+/* cases. This is done by checking if there alread is a equivalent */
+ /* CPU table installed. If not, we're written through */
+ /* /dev/cpu/microcode. */
+/* Since we ignore all checks. The error case in which going through */
+/* firmware loading and that table is not loaded has already been */
+ /* checked earlier. */
+ if (equiv_cpu_table == NULL) {
+ printk(KERN_INFO "microcode: CPU%d microcode update with "
+ "version 0x%x (current=0x%x)\n",
+ cpu, mc_header->patch_id, uci->rev);
+ goto out;
+ }
+
+ current_cpu_id = cpuid_eax(0x00000001);
+
+ while (equiv_cpu_table[i].installed_cpu != 0) {
+ if (current_cpu_id == equiv_cpu_table[i].installed_cpu) {
+ equiv_cpu_id = equiv_cpu_table[i].equiv_cpu;
+ break;
+ }
+ i++;
+ }
+
+ if (!equiv_cpu_id) {
+ printk(KERN_ERR "microcode: CPU%d cpu_id "
+ "not found in equivalent cpu table \n", cpu);
+ return 0;
+ }
+
+ if ((mc_header->processor_rev_id[0]) != (equiv_cpu_id & 0xff)) {
+ printk(KERN_ERR
+ "microcode: CPU%d patch does not match "
+ "(patch is %x, cpu extended is %x) \n",
+ cpu, mc_header->processor_rev_id[0],
+ (equiv_cpu_id & 0xff));
+ return 0;
+ }
+
+ if ((mc_header->processor_rev_id[1]) != ((equiv_cpu_id >> 16) & 0xff)) {
+ printk(KERN_ERR "microcode: CPU%d patch does not match "
+ "(patch is %x, cpu base id is %x) \n",
+ cpu, mc_header->processor_rev_id[1],
+ ((equiv_cpu_id >> 16) & 0xff));
+
+ return 0;
+ }
+
+ /* ucode may be northbridge specific */
+ if (mc_header->nb_dev_id) {
+ nb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD,
+ (mc_header->nb_dev_id & 0xff),
+ NULL);
+ if ((!nb_pci_dev) ||
+ (mc_header->nb_rev_id != nb_pci_dev->revision)) {
+ printk(KERN_ERR "microcode: CPU%d NB mismatch \n", cpu);
+ pci_dev_put(nb_pci_dev);
+ return 0;
+ }
+ pci_dev_put(nb_pci_dev);
+ }
+
+ /* ucode may be southbridge specific */
+ if (mc_header->sb_dev_id) {
+ sb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD,
+ (mc_header->sb_dev_id & 0xff),
+ NULL);
+ if ((!sb_pci_dev) ||
+ (mc_header->sb_rev_id != sb_pci_dev->revision)) {
+ printk(KERN_ERR "microcode: CPU%d SB mismatch \n", cpu);
+ pci_dev_put(sb_pci_dev);
+ return 0;
+ }
+ pci_dev_put(sb_pci_dev);
+ }
+
+ if (mc_header->patch_id <= uci->rev)
+ return 0;
+
+ printk(KERN_INFO "microcode: CPU%d found a matching microcode "
+ "update with version 0x%x (current=0x%x)\n",
+ cpu, mc_header->patch_id, uci->rev);
+
+out:
+ new_mc = vmalloc(UCODE_MAX_SIZE);
+ if (!new_mc) {
+ printk(KERN_ERR "microcode: error, can't allocate memory\n");
+ return -ENOMEM;
+ }
+ memset(new_mc, 0, UCODE_MAX_SIZE);
+
+ /* free previous update file */
+ vfree(uci->mc.mc_amd);
+
+ memcpy(new_mc, mc, total_size);
+
+ uci->mc.mc_amd = new_mc;
+ return 1;
+}
+
+static void apply_microcode_amd(int cpu)
+{
+ unsigned long flags;
+ unsigned int eax, edx;
+ unsigned int rev;
+ int cpu_num = raw_smp_processor_id();
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(cpu_num != cpu);
+
+ if (uci->mc.mc_amd == NULL)
+ return;
+
+ spin_lock_irqsave(µcode_update_lock, flags);
+
+ edx = (unsigned int)(((unsigned long)
+ &(uci->mc.mc_amd->hdr.data_code)) >> 32);
+ eax = (unsigned int)(((unsigned long)
+ &(uci->mc.mc_amd->hdr.data_code)) & 0xffffffffL);
+
+ asm volatile("movl %0, %%ecx; wrmsr" :
+ : "i" (0xc0010020), "a" (eax), "d" (edx) : "ecx");
+
+ /* get patch id after patching */
+ asm volatile("movl %1, %%ecx; rdmsr"
+ : "=a" (rev)
+ : "i" (0x0000008B) : "ecx");
+
+ spin_unlock_irqrestore(µcode_update_lock, flags);
+
+ /* check current patch id and patch's id for match */
+ if (rev != uci->mc.mc_amd->hdr.patch_id) {
+ printk(KERN_ERR "microcode: CPU%d update from revision "
+ "0x%x to 0x%x failed\n", cpu_num,
+ uci->mc.mc_amd->hdr.patch_id, rev);
+ return;
+ }
+
+ printk(KERN_INFO "microcode: CPU%d updated from revision "
+ "0x%x to 0x%x \n",
+ cpu_num, uci->rev, uci->mc.mc_amd->hdr.patch_id);
+
+ uci->rev = rev;
+}
+
+#ifdef CONFIG_MICROCODE_OLD_INTERFACE
+extern void __user *user_buffer; /* user area microcode data buffer */
+extern unsigned int user_buffer_size; /* it's size */
+
+static long get_next_ucode_amd(void **mc, long offset)
+{
+ struct microcode_header_amd mc_header;
+ unsigned long total_size;
+
+ /* No more data */
+ if (offset >= user_buffer_size)
+ return 0;
+ if (copy_from_user(&mc_header, user_buffer + offset, MC_HEADER_SIZE)) {
+ printk(KERN_ERR "microcode: error! Can not read user data\n");
+ return -EFAULT;
+ }
+ total_size = get_totalsize(&mc_header);
+ if (offset + total_size > user_buffer_size) {
+ printk(KERN_ERR "microcode: error! Bad total size in microcode "
+ "data file\n");
+ return -EINVAL;
+ }
+ *mc = vmalloc(UCODE_MAX_SIZE);
+ if (!*mc)
+ return -ENOMEM;
+ memset(*mc, 0, UCODE_MAX_SIZE);
+
+ if (copy_from_user(*mc, user_buffer + offset, total_size)) {
+ printk(KERN_ERR "microcode: error! Can not read user data\n");
+ vfree(*mc);
+ return -EFAULT;
+ }
+ return offset + total_size;
+}
+#else
+#define get_next_ucode_amd() NULL
+#endif
+
+static long get_next_ucode_from_buffer_amd(void **mc, void *buf,
+ unsigned long size, long offset)
+{
+ struct microcode_header_amd *mc_header;
+ unsigned long total_size;
+ unsigned char *buf_pos = buf;
+
+ /* No more data */
+ if (offset >= size)
+ return 0;
+
+ if (buf_pos[offset] != UCODE_UCODE_TYPE) {
+ printk(KERN_ERR "microcode: error! "
+ "Wrong microcode payload type field\n");
+ return -EINVAL;
+ }
+
+ mc_header = (struct microcode_header_amd *)(&buf_pos[offset+8]);
+
+ total_size = (unsigned long) (buf_pos[offset+4] +
+ (buf_pos[offset+5] << 8));
+
+ printk(KERN_INFO "microcode: size %lu, total_size %lu, offset %ld\n",
+ size, total_size, offset);
+
+ if (offset + total_size > size) {
+ printk(KERN_ERR "microcode: error! Bad data in microcode data file\n");
+ return -EINVAL;
+ }
+
+ *mc = vmalloc(UCODE_MAX_SIZE);
+ if (!*mc) {
+ printk(KERN_ERR "microcode: error! "
+ "Can not allocate memory for microcode patch\n");
+ return -ENOMEM;
+ }
+
+ memset(*mc, 0, UCODE_MAX_SIZE);
+ memcpy(*mc, buf + offset + 8, total_size);
+
+ return offset + total_size + 8;
+}
+
+static long install_equiv_cpu_table(void *buf, unsigned long size, long offset)
+{
+ unsigned int *buf_pos = buf;
+
+ /* No more data */
+ if (offset >= size)
+ return 0;
+
+ if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE) {
+ printk(KERN_ERR "microcode: error! "
+ "Wrong microcode equivalnet cpu table type field\n");
+ return 0;
+ }
+
+ if (size == 0) {
+ printk(KERN_ERR "microcode: error! "
+ "Wrong microcode equivalnet cpu table length\n");
+ return 0;
+ }
+
+ equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size);
+ if (!equiv_cpu_table) {
+ printk(KERN_ERR "microcode: error, can't allocate memory for equiv CPU table\n");
+ return 0;
+ }
+
+ memset(equiv_cpu_table, 0, size);
+ memcpy(equiv_cpu_table, &buf_pos[3], size);
+
+ return size + 12; /* add header length */
+}
+
+/* fake device for request_firmware */
+extern struct platform_device *microcode_pdev;
+
+static int cpu_request_microcode_amd(int cpu)
+{
+ char name[30];
+ const struct firmware *firmware;
+ void *buf;
+ unsigned int *buf_pos;
+ unsigned long size;
+ long offset = 0;
+ int error;
+ void *mc;
+
+ /* We should bind the task to the CPU */
+ BUG_ON(cpu != raw_smp_processor_id());
+
+ sprintf(name, "amd-ucode/microcode_amd.bin");
+ error = request_firmware(&firmware, "amd-ucode/microcode_amd.bin",
+ µcode_pdev->dev);
+ if (error) {
+ printk(KERN_ERR "microcode: ucode data file %s load failed\n",
+ name);
+ return error;
+ }
+
+ buf_pos = buf = firmware->data;
+ size = firmware->size;
+
+ if (buf_pos[0] != UCODE_MAGIC) {
+ printk(KERN_ERR "microcode: error! Wrong microcode patch file magic\n");
+ return -EINVAL;
+ }
+
+ offset = install_equiv_cpu_table(buf, buf_pos[2], offset);
+
+ if (!offset) {
+ printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
+ return -EINVAL;
+ }
+
+ while ((offset =
+ get_next_ucode_from_buffer_amd(&mc, buf, size, offset)) > 0) {
+ error = get_matching_microcode_amd(mc, cpu);
+ if (error < 0)
+ break;
+ /*
+ * It's possible the data file has multiple matching ucode,
+ * lets keep searching till the latest version
+ */
+ if (error == 1) {
+ apply_microcode_amd(cpu);
+ error = 0;
+ }
+ vfree(mc);
+ }
+ if (offset > 0) {
+ vfree(mc);
+ vfree(equiv_cpu_table);
+ equiv_cpu_table = NULL;
+ }
+ if (offset < 0)
+ error = offset;
+ release_firmware(firmware);
+
+ return error;
+}
+
+static int apply_microcode_check_cpu_amd(int cpu)
+{
+ struct cpuinfo_x86 *c = &cpu_data(cpu);
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ unsigned int rev;
+ cpumask_t old;
+ cpumask_of_cpu_ptr(newmask, cpu);
+ int err = 0;
+
+ /* Check if the microcode is available */
+ if (!uci->mc.mc_amd)
+ return 0;
+
+ old = current->cpus_allowed;
+ set_cpus_allowed(current, newmask);
+
+ /* Check if the microcode we have in memory matches the CPU */
+ if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 16)
+ err = -EINVAL;
+
+ if (!err) {
+ asm volatile("movl %1, %%ecx; rdmsr"
+ : "=a" (rev)
+ : "i" (0x0000008B) : "ecx");
+
+ if (uci->rev != rev)
+ err = -EINVAL;
+ }
+
+ if (!err)
+ apply_microcode_amd(cpu);
+ else
+ printk(KERN_ERR "microcode: Could not apply microcode to CPU%d:"
+ " rev=0x%x\n",
+ cpu, uci->rev);
+
+ set_cpus_allowed(current, old);
+ return err;
+}
+
+static void microcode_fini_cpu_amd(int cpu)
+{
+ struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+
+ mutex_lock(µcode_mutex);
+ uci->valid = 0;
+ vfree(uci->mc.mc_amd);
+ uci->mc.mc_amd = NULL;
+ mutex_unlock(µcode_mutex);
+}
+
+static struct microcode_ops microcode_amd_ops = {
+ .get_next_ucode = get_next_ucode_amd,
+ .get_matching_microcode = get_matching_microcode_amd,
+ .microcode_sanity_check = NULL,
+ .apply_microcode_check_cpu = apply_microcode_check_cpu_amd,
+ .cpu_request_microcode = cpu_request_microcode_amd,
+ .collect_cpu_info = collect_cpu_info_amd,
+ .apply_microcode = apply_microcode_amd,
+ .microcode_fini_cpu = microcode_fini_cpu_amd,
+};
+
+static int __init microcode_amd_module_init(void)
+{
+ struct cpuinfo_x86 *c = &cpu_data(get_cpu());
+
+ equiv_cpu_table = NULL;
+ if (c->x86_vendor == X86_VENDOR_AMD)
+ return microcode_init(µcode_amd_ops, THIS_MODULE);
+ else
+ return -ENODEV;
+}
+
+static void __exit microcode_amd_module_exit(void)
+{
+ microcode_exit();
+}
+
+module_init(microcode_amd_module_init)
+module_exit(microcode_amd_module_exit)
--
1.5.4.5
^ permalink raw reply related [flat|nested] 32+ messages in thread
* Re: [patch 00/11] x86: AMD microcode patch loading support v2
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
` (9 preceding siblings ...)
2008-07-28 16:44 ` [patch 11/11] [PATCH 11/11] x86: AMD microcode patch loading support Peter Oruba
@ 2008-07-28 18:01 ` Ingo Molnar
2008-07-29 8:10 ` [PATCH] x86, microcode support: fix build error Ingo Molnar
` (3 more replies)
10 siblings, 4 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-07-28 18:01 UTC (permalink / raw)
To: Peter Oruba; +Cc: Thomas Gleixner, Tigran Aivazian, LKML, H. Peter Anvin
* Peter Oruba <peter.oruba@amd.com> wrote:
> AMD microcode patch loader v2, rebased to Linux master.
applied to tip/x86/microcode - thanks Peter.
One open issue i noticed is the checkpatch warnings:
$ scripts/checkpatch.pl --file arch/x86/kernel/microcode_amd.c
total: 0 errors, 10 warnings, 1 checks, 521 lines checked
$ scripts/checkpatch.pl --file arch/x86/kernel/microcode.c
total: 2 errors, 12 warnings, 477 lines checked
$ scripts/checkpatch.pl --file arch/x86/kernel/microcode_intel.c
total: 1 errors, 11 warnings, 546 lines checked
Could you send delta patch(es) to fix them up? You can pick up the
committed patches via:
http://people.redhat.com/mingo/tip.git/README
and do something like:
git-checkout tip/master
git-merge tip/x86/microcode
to get the latest code plus your changes.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 10/11] [PATCH 10/11] x86: Major refactoring.
2008-07-28 16:44 ` [patch 10/11] [PATCH 10/11] x86: Major refactoring Peter Oruba
@ 2008-07-28 19:36 ` Max Krasnyansky
2008-07-28 19:50 ` Tigran Aivazian
0 siblings, 1 reply; 32+ messages in thread
From: Max Krasnyansky @ 2008-07-28 19:36 UTC (permalink / raw)
To: Peter Oruba; +Cc: Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML
Peter Oruba wrote:
> Refactored code by introducing a two-module solution. There is one
> general module in which vendor specific modules can hook into.
> However, that is exclusive, there is only one vendor specific module
> allowed at a time. A CPU vendor check makes sure only the corect
> module for the underlying system gets called. Functinally in terms
> of patch loading itself there are no changes. This refactoring
> provides a basis for future implementations of other vendors'
> patch loaders.
>
> Signed-off-by: Peter Oruba <peter.oruba@amd.com>
<snip>
> diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
> index c1047d7..1e42e79 100644
> --- a/arch/x86/kernel/microcode.c
> +++ b/arch/x86/kernel/microcode.c
<snip>
> @@ -244,9 +243,9 @@ static void microcode_init_cpu(int cpu, int resume)
>
> set_cpus_allowed_ptr(current, newmask);
> mutex_lock(µcode_mutex);
> - collect_cpu_info(cpu);
> + microcode_ops->collect_cpu_info(cpu);
> if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
> - cpu_request_microcode(cpu);
> + microcode_ops->cpu_request_microcode(cpu);
> mutex_unlock(µcode_mutex);
> set_cpus_allowed_ptr(current, &old);
> @@ -274,7 +273,7 @@ static ssize_t reload_store(struct sys_device *dev,
>
> mutex_lock(µcode_mutex);
> if (uci->valid)
> - err = cpu_request_microcode(cpu);
> + err = microcode_ops->cpu_request_microcode(cpu);
> mutex_unlock(µcode_mutex);
> put_online_cpus();
> set_cpus_allowed_ptr(current, &old);
Peter, question while we're at it. This came up in another thread and I
asked the same question to Tigran but he is either on vacation or not
paying attention :).
Microcode cpu hotplug handler is messing with the cps_allowed flags of a
random process and can race with sched_setaffinity() (pointed by
Dmitry). It also makes some assumptions on the overall cpu hotplug
sequence which is bad.
It's easy to fix but the question is - does the microcode update need to
happen synchronously ? I'm thinking that it does not but I wanted to
verify that. If it does not need to be synchronous then we can simply
schedule a work queue and do the update there. If it does we could do
collect_cpu_info() and load_microcode() in the IPIs.
Max
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 10/11] [PATCH 10/11] x86: Major refactoring.
2008-07-28 19:36 ` Max Krasnyansky
@ 2008-07-28 19:50 ` Tigran Aivazian
0 siblings, 0 replies; 32+ messages in thread
From: Tigran Aivazian @ 2008-07-28 19:50 UTC (permalink / raw)
To: Max Krasnyansky; +Cc: Peter Oruba, Ingo Molnar, Thomas Gleixner, LKML
Hi Max,
On Mon, 28 Jul 2008, Max Krasnyansky wrote:
> Peter, question while we're at it. This came up in another thread and I asked
> the same question to Tigran but he is either on vacation or not paying
> attention :).
I am neither on vacation nor not paying attention. I simply didn't know
the answer to your question :)
Kind regards
Tigran
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH] x86, microcode support: fix build error
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
@ 2008-07-29 8:10 ` Ingo Molnar
2008-07-29 8:10 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
` (2 subsequent siblings)
3 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-07-29 8:10 UTC (permalink / raw)
To: Peter Oruba; +Cc: Thomas Gleixner, Tigran Aivazian, LKML, H. Peter Anvin
>From 45b1e23eca1c53fa79a611a2bc8c93697ede6c97 Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@elte.hu>
Date: Tue, 29 Jul 2008 09:42:17 +0200
Subject: [PATCH] x86, microcode support: fix build error
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
fix:
arch/x86/kernel/microcode.c:412: error: static declaration of ‘microcode_init’ follows non-static declaration
include/asm/microcode.h:1: error: previous declaration of ‘microcode_init’ was here
arch/x86/kernel/microcode.c:454: error: static declaration of ‘microcode_exit’ follows non-static declaration
include/asm/microcode.h:2: error: previous declaration of ‘microcode_exit’ was here
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/microcode.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 1e42e79..9a88184 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -415,7 +415,7 @@ static struct notifier_block __refdata mc_cpu_notifier = {
.notifier_call = mc_cpu_callback,
};
-static int microcode_init(void *opaque, struct module *module)
+int microcode_init(void *opaque, struct module *module)
{
struct microcode_ops *ops = (struct microcode_ops *)opaque;
int error;
@@ -457,7 +457,7 @@ static int microcode_init(void *opaque, struct module *module)
}
EXPORT_SYMBOL_GPL(microcode_init);
-static void __exit microcode_exit (void)
+void __exit microcode_exit (void)
{
microcode_dev_exit();
^ permalink raw reply related [flat|nested] 32+ messages in thread
* Re: [patch 00/11] x86: AMD microcode patch loading support v2
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
2008-07-29 8:10 ` [PATCH] x86, microcode support: fix build error Ingo Molnar
@ 2008-07-29 8:10 ` Ingo Molnar
2008-07-29 8:10 ` Ingo Molnar
2008-07-29 8:12 ` Ingo Molnar
3 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-07-29 8:10 UTC (permalink / raw)
To: Peter Oruba; +Cc: Thomas Gleixner, Tigran Aivazian, LKML, H. Peter Anvin
>From 224e946b81166d732f3e9b414cb69612072fb500 Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@elte.hu>
Date: Tue, 29 Jul 2008 09:52:55 +0200
Subject: [PATCH] x86, microcode: fix symbol exports
fix tons of build errors:
arch/x86/kernel/built-in.o: In function `microcode_fini_cpu':
microcode_intel.c:(.text+0x11598): undefined reference to `microcode_mutex'
microcode_intel.c:(.text+0x115a4): undefined reference to `ucode_cpu_info'
microcode_intel.c:(.text+0x115ae): undefined reference to `ucode_cpu_info'
microcode_intel.c:(.text+0x115bc): undefined reference to `microcode_mutex'
[...]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/microcode.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 9a88184..758b958 100644
--- a/arch/x86/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
@@ -104,16 +104,16 @@ MODULE_LICENSE("GPL");
struct microcode_ops *microcode_ops;
/* no concurrent ->write()s are allowed on /dev/cpu/microcode */
-static DEFINE_MUTEX(microcode_mutex);
+DEFINE_MUTEX(microcode_mutex);
EXPORT_SYMBOL_GPL(microcode_mutex);
-static struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
+struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
EXPORT_SYMBOL_GPL(ucode_cpu_info);
#ifdef CONFIG_MICROCODE_OLD_INTERFACE
-static void __user *user_buffer; /* user area microcode data buffer */
+void __user *user_buffer; /* user area microcode data buffer */
EXPORT_SYMBOL_GPL(user_buffer);
-static unsigned int user_buffer_size; /* it's size */
+unsigned int user_buffer_size; /* it's size */
EXPORT_SYMBOL_GPL(user_buffer_size);
static int do_microcode_update (void)
@@ -230,7 +230,7 @@ MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
#endif
/* fake device for request_firmware */
-static struct platform_device *microcode_pdev;
+struct platform_device *microcode_pdev;
EXPORT_SYMBOL_GPL(microcode_pdev);
static void microcode_init_cpu(int cpu, int resume)
^ permalink raw reply related [flat|nested] 32+ messages in thread
* Re: [patch 00/11] x86: AMD microcode patch loading support v2
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
2008-07-29 8:10 ` [PATCH] x86, microcode support: fix build error Ingo Molnar
2008-07-29 8:10 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
@ 2008-07-29 8:10 ` Ingo Molnar
2008-07-29 8:12 ` Ingo Molnar
3 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-07-29 8:10 UTC (permalink / raw)
To: Peter Oruba; +Cc: Thomas Gleixner, Tigran Aivazian, LKML, H. Peter Anvin
>From 5d7b605245b1aa1a9cd6549b1f57d69273eb0c37 Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@elte.hu>
Date: Tue, 29 Jul 2008 10:07:36 +0200
Subject: [PATCH] x86, microcode: fix module license string
fix:
FATAL: modpost: GPL-incompatible module microcode_amd.ko uses GPL-only symbol 'set_cpus_allowed_ptr'
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/microcode_amd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index db199e3..fd9e68e 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -40,7 +40,7 @@
MODULE_DESCRIPTION("AMD Microcode Update Driver");
MODULE_AUTHOR("Peter Oruba <peter.oruba@amd.com>");
-MODULE_LICENSE("GPLv2");
+MODULE_LICENSE("GPL v2");
#define UCODE_MAGIC 0x00414d44
#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
^ permalink raw reply related [flat|nested] 32+ messages in thread
* Re: [patch 00/11] x86: AMD microcode patch loading support v2
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
` (2 preceding siblings ...)
2008-07-29 8:10 ` Ingo Molnar
@ 2008-07-29 8:12 ` Ingo Molnar
3 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-07-29 8:12 UTC (permalink / raw)
To: Peter Oruba; +Cc: Thomas Gleixner, Tigran Aivazian, LKML, H. Peter Anvin
* Ingo Molnar <mingo@elte.hu> wrote:
> and do something like:
>
> git-checkout tip/master
> git-merge tip/x86/microcode
>
> to get the latest code plus your changes.
i've pushed out 3 build fixes into tip/x86/microcode and test-merged it
into tip/master. I'll test it some more today before pushing out its
integration.
Ingo
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-07-28 16:44 ` [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c Peter Oruba
@ 2008-09-07 19:08 ` Arjan van de Ven
2008-09-12 11:54 ` Peter Oruba
0 siblings, 1 reply; 32+ messages in thread
From: Arjan van de Ven @ 2008-09-07 19:08 UTC (permalink / raw)
To: Peter Oruba
Cc: Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML, Peter Oruba
On Mon, 28 Jul 2008 18:44:16 +0200
Peter Oruba <peter.oruba@amd.com> wrote:
> Signed-off-by: Peter Oruba <peter.oruba@amd.com>
> ---
> arch/x86/kernel/Makefile | 2 +-
> arch/x86/kernel/microcode.c | 855
\
unfortunately this patch breaks userland for me; the Fedora initscripts
suddenly fail (with a [FAILED] that will alarm users) because of this
rename....
(well it also fails to update the microcode, and if you load the new
module name by hand first it still fails in many ways ;-( )
That is a regression in -tip unfortunately....
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-07 19:08 ` Arjan van de Ven
@ 2008-09-12 11:54 ` Peter Oruba
2008-09-12 13:35 ` Arjan van de Ven
0 siblings, 1 reply; 32+ messages in thread
From: Peter Oruba @ 2008-09-12 11:54 UTC (permalink / raw)
To: Arjan van de Ven; +Cc: Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML
Arjan,
could you please provide some more information about that issue?
Thanks,
Peter
Arjan van de Ven schrieb:
> On Mon, 28 Jul 2008 18:44:16 +0200
> Peter Oruba <peter.oruba@amd.com> wrote:
>
>> Signed-off-by: Peter Oruba <peter.oruba@amd.com>
>> ---
>> arch/x86/kernel/Makefile | 2 +-
>> arch/x86/kernel/microcode.c | 855
>
> \
>
>
> unfortunately this patch breaks userland for me; the Fedora initscripts
> suddenly fail (with a [FAILED] that will alarm users) because of this
> rename....
> (well it also fails to update the microcode, and if you load the new
> module name by hand first it still fails in many ways ;-( )
>
> That is a regression in -tip unfortunately....
>
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-12 11:54 ` Peter Oruba
@ 2008-09-12 13:35 ` Arjan van de Ven
2008-09-12 13:53 ` Giacomo A. Catenazzi
2008-09-19 11:59 ` Peter Oruba
0 siblings, 2 replies; 32+ messages in thread
From: Arjan van de Ven @ 2008-09-12 13:35 UTC (permalink / raw)
To: Peter Oruba; +Cc: Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML
On Fri, 12 Sep 2008 13:54:20 +0200
Peter Oruba <peter.oruba@amd.com> wrote:
> Arjan,
>
> could you please provide some more information about that issue?
well.. the fedora boot script just plain fails.
I suspect it manually loads microcode.ko or something if CPUID says
intel; and this now stops working...
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-12 13:35 ` Arjan van de Ven
@ 2008-09-12 13:53 ` Giacomo A. Catenazzi
2008-09-19 11:59 ` Peter Oruba
1 sibling, 0 replies; 32+ messages in thread
From: Giacomo A. Catenazzi @ 2008-09-12 13:53 UTC (permalink / raw)
To: Arjan van de Ven
Cc: Peter Oruba, Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML
Arjan van de Ven wrote:
> On Fri, 12 Sep 2008 13:54:20 +0200
> Peter Oruba <peter.oruba@amd.com> wrote:
>
>> Arjan,
>>
>> could you please provide some more information about that issue?
>
> well.. the fedora boot script just plain fails.
> I suspect it manually loads microcode.ko or something if CPUID says
> intel; and this now stops working...
Also Debian manually load the module, and it remove it
after upgrading microcode (no need to have the
driver loaded after boot), so changing the name of
module is not so fortunate, also considering the
long releases cycle of Debian.
I would like to have a single microcode module for the
two drivers: generic kernel need both (thus reduce
overhead); specialized kernel are configured only with
the relevant driver, so no additional overhead.
ciao
cate
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-12 13:35 ` Arjan van de Ven
2008-09-12 13:53 ` Giacomo A. Catenazzi
@ 2008-09-19 11:59 ` Peter Oruba
2008-09-19 12:37 ` Dmitry Adamushko
2008-09-19 13:07 ` Arjan van de Ven
1 sibling, 2 replies; 32+ messages in thread
From: Peter Oruba @ 2008-09-19 11:59 UTC (permalink / raw)
To: Arjan van de Ven, cate
Cc: Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML,
Dmitry Adamushko
Some additonal words regarding the current user space issues:
IMHO the most convenient way to update microcode is through the firmware loading
interface instead of microcode_ctl. This reduces user-space responsibilities to
loading the correct module at boot time and to place the microcode patch file at
the right location via package installation. The problems mentioned in this
thread would then probably disappear as well. What do you guys think?
Thanks,
Peter
Arjan van de Ven schrieb:
> On Fri, 12 Sep 2008 13:54:20 +0200
> Peter Oruba <peter.oruba@amd.com> wrote:
>
>> Arjan,
>>
>> could you please provide some more information about that issue?
>
> well.. the fedora boot script just plain fails.
> I suspect it manually loads microcode.ko or something if CPUID says
> intel; and this now stops working...
>
>
--
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 11:59 ` Peter Oruba
@ 2008-09-19 12:37 ` Dmitry Adamushko
2008-09-19 12:58 ` Giacomo A. Catenazzi
2008-09-19 13:07 ` Arjan van de Ven
1 sibling, 1 reply; 32+ messages in thread
From: Dmitry Adamushko @ 2008-09-19 12:37 UTC (permalink / raw)
To: Peter Oruba
Cc: Arjan van de Ven, cate, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
2008/9/19 Peter Oruba <peter.oruba@amd.com>:
> Some additonal words regarding the current user space issues:
>
> IMHO the most convenient way to update microcode is through the firmware loading
> interface instead of microcode_ctl. This reduces user-space responsibilities to
> loading the correct module at boot time and to place the microcode patch file at
> the right location via package installation. The problems mentioned in this
> thread would then probably disappear as well. What do you guys think?
It'd still require changes for all the setups that currently rely on
the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
to the 'microcode_ctl' per se but due to the altered kernel module
name. After all, we can't break the established interface this way.
We can either reserve 'microcode' as a legacy name for intel cpus (==
microcode_intel), or maybe we can use request_module() from
microcode.ko to load a proper arch-specific module (I guess, it's not
ok for !KMOD-enabled kernels).
>
> Thanks,
> Peter
>
--
Best regards,
Dmitry Adamushko
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 12:37 ` Dmitry Adamushko
@ 2008-09-19 12:58 ` Giacomo A. Catenazzi
2008-09-19 13:03 ` Peter Oruba
0 siblings, 1 reply; 32+ messages in thread
From: Giacomo A. Catenazzi @ 2008-09-19 12:58 UTC (permalink / raw)
To: Dmitry Adamushko
Cc: Peter Oruba, Arjan van de Ven, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
Dmitry Adamushko wrote:
> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
>> Some additonal words regarding the current user space issues:
>>
>> IMHO the most convenient way to update microcode is through the firmware loading
>> interface instead of microcode_ctl. This reduces user-space responsibilities to
>> loading the correct module at boot time and to place the microcode patch file at
>> the right location via package installation. The problems mentioned in this
>> thread would then probably disappear as well. What do you guys think?
>
> It'd still require changes for all the setups that currently rely on
> the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
> to the 'microcode_ctl' per se but due to the altered kernel module
> name. After all, we can't break the established interface this way.
>
> We can either reserve 'microcode' as a legacy name for intel cpus (==
> microcode_intel), or maybe we can use request_module() from
> microcode.ko to load a proper arch-specific module (I guess, it's not
> ok for !KMOD-enabled kernels).
I agree. A wrapper "microcode.ko" module would be nice, in order
to allow independent kernel and user space upgrades.
The module name is important also on udev method: only a module
load triggers the microcode request in udev, thus also the
new method should have stable kernel module name.
ciao
cate
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 12:58 ` Giacomo A. Catenazzi
@ 2008-09-19 13:03 ` Peter Oruba
2008-09-19 13:52 ` Giacomo A. Catenazzi
` (2 more replies)
0 siblings, 3 replies; 32+ messages in thread
From: Peter Oruba @ 2008-09-19 13:03 UTC (permalink / raw)
To: Giacomo A. Catenazzi
Cc: Dmitry Adamushko, Arjan van de Ven, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
Giacomo A. Catenazzi schrieb:
> Dmitry Adamushko wrote:
>> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
>>> Some additonal words regarding the current user space issues:
>>>
>>> IMHO the most convenient way to update microcode is through the
>>> firmware loading
>>> interface instead of microcode_ctl. This reduces user-space
>>> responsibilities to
>>> loading the correct module at boot time and to place the microcode
>>> patch file at
>>> the right location via package installation. The problems mentioned
>>> in this
>>> thread would then probably disappear as well. What do you guys think?
>>
>> It'd still require changes for all the setups that currently rely on
>> the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
>> to the 'microcode_ctl' per se but due to the altered kernel module
>> name. After all, we can't break the established interface this way.
>>
>> We can either reserve 'microcode' as a legacy name for intel cpus (==
>> microcode_intel), or maybe we can use request_module() from
>> microcode.ko to load a proper arch-specific module (I guess, it's not
>> ok for !KMOD-enabled kernels).
>
> I agree. A wrapper "microcode.ko" module would be nice, in order
> to allow independent kernel and user space upgrades.
>
> The module name is important also on udev method: only a module
> load triggers the microcode request in udev, thus also the
> new method should have stable kernel module name.
>
> ciao
> cate
>
That sounds like a single-module solution would be the best way to go. All
dependencies would then be handled inside the module.
-Peter
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 11:59 ` Peter Oruba
2008-09-19 12:37 ` Dmitry Adamushko
@ 2008-09-19 13:07 ` Arjan van de Ven
1 sibling, 0 replies; 32+ messages in thread
From: Arjan van de Ven @ 2008-09-19 13:07 UTC (permalink / raw)
To: Peter Oruba
Cc: cate, Ingo Molnar, Thomas Gleixner, Tigran Aivazian, LKML,
Dmitry Adamushko
On Fri, 19 Sep 2008 13:59:39 +0200
Peter Oruba <peter.oruba@amd.com> wrote:
> Some additonal words regarding the current user space issues:
>
> IMHO the most convenient way to update microcode is through the
> firmware loading interface instead of microcode_ctl. This reduces
> user-space responsibilities to loading the correct module at boot
> time and to place the microcode patch file at the right location via
> package installation. The problems mentioned in this thread would
> then probably disappear as well. What do you guys think?
while I absolutely don't disagree with what you say, breaking existing
userspace is not an option.
Yes I very much would like for microcode_ctl to die as well (in fact,
that was one of the reasons we had the microcode code use
request_firmware), but that doesn't mean we can just ditch
compatibility ;(
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 13:03 ` Peter Oruba
@ 2008-09-19 13:52 ` Giacomo A. Catenazzi
2008-09-20 6:11 ` Ingo Molnar
2008-09-19 14:06 ` Giacomo A. Catenazzi
2008-09-20 6:07 ` Ingo Molnar
2 siblings, 1 reply; 32+ messages in thread
From: Giacomo A. Catenazzi @ 2008-09-19 13:52 UTC (permalink / raw)
To: Peter Oruba
Cc: Dmitry Adamushko, Arjan van de Ven, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
Peter Oruba wrote:
> Giacomo A. Catenazzi schrieb:
>> Dmitry Adamushko wrote:
>>> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
>>>> Some additonal words regarding the current user space issues:
>>>>
>>>> IMHO the most convenient way to update microcode is through the
>>>> firmware loading
>>>> interface instead of microcode_ctl. This reduces user-space
>>>> responsibilities to
>>>> loading the correct module at boot time and to place the microcode
>>>> patch file at
>>>> the right location via package installation. The problems mentioned
>>>> in this
>>>> thread would then probably disappear as well. What do you guys think?
>>> It'd still require changes for all the setups that currently rely on
>>> the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
>>> to the 'microcode_ctl' per se but due to the altered kernel module
>>> name. After all, we can't break the established interface this way.
>>>
>>> We can either reserve 'microcode' as a legacy name for intel cpus (==
>>> microcode_intel), or maybe we can use request_module() from
>>> microcode.ko to load a proper arch-specific module (I guess, it's not
>>> ok for !KMOD-enabled kernels).
>> I agree. A wrapper "microcode.ko" module would be nice, in order
>> to allow independent kernel and user space upgrades.
>>
>> The module name is important also on udev method: only a module
>> load triggers the microcode request in udev, thus also the
>> new method should have stable kernel module name.
>>
>> ciao
>> cate
>>
>
> That sounds like a single-module solution would be the best way to go. All
> dependencies would then be handled inside the module.
Single module probably is more difficult to maintain.
I was thinking about a very simple additional module:
Check the cpu: load the relevant module, and wrapper the calls to the
relevant module.
So every vendor could develop easier the own driver. Only the interface
should be stable.
Eventually we could solve it in the distribution scripts (using module
aliases), but it would be kernel version dependent, and it would works
only on the new method (or a new microcode_ctl version, but people
upgrade more often kernel than packages).
ciao
cate
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 13:03 ` Peter Oruba
2008-09-19 13:52 ` Giacomo A. Catenazzi
@ 2008-09-19 14:06 ` Giacomo A. Catenazzi
2008-09-19 14:29 ` Arjan van de Ven
2008-09-20 6:07 ` Ingo Molnar
2 siblings, 1 reply; 32+ messages in thread
From: Giacomo A. Catenazzi @ 2008-09-19 14:06 UTC (permalink / raw)
To: Peter Oruba
Cc: Dmitry Adamushko, Arjan van de Ven, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
Peter Oruba wrote:
> Giacomo A. Catenazzi schrieb:
>> Dmitry Adamushko wrote:
>>> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
>>>> Some additonal words regarding the current user space issues:
>>>>
>>>> IMHO the most convenient way to update microcode is through the
>>>> firmware loading
>>>> interface instead of microcode_ctl. This reduces user-space
>>>> responsibilities to
>>>> loading the correct module at boot time and to place the microcode
>>>> patch file at
>>>> the right location via package installation. The problems mentioned
>>>> in this
>>>> thread would then probably disappear as well. What do you guys think?
>>> It'd still require changes for all the setups that currently rely on
>>> the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
>>> to the 'microcode_ctl' per se but due to the altered kernel module
>>> name. After all, we can't break the established interface this way.
>>>
>>> We can either reserve 'microcode' as a legacy name for intel cpus (==
>>> microcode_intel), or maybe we can use request_module() from
>>> microcode.ko to load a proper arch-specific module (I guess, it's not
>>> ok for !KMOD-enabled kernels).
>> I agree. A wrapper "microcode.ko" module would be nice, in order
>> to allow independent kernel and user space upgrades.
>>
>> The module name is important also on udev method: only a module
>> load triggers the microcode request in udev, thus also the
>> new method should have stable kernel module name.
>>
>> ciao
>> cate
>>
>
> That sounds like a single-module solution would be the best way to go. All
> dependencies would then be handled inside the module.
Single module probably is more difficult to maintain.
I was thinking about a very simple additional module:
It checks the cpu: load the relevant module, and wrapper the
calls to the relevant module.
So every vendor could develop easier the own driver. Only the interface
should be stable.
Eventually we could solve it in the distribution scripts (using module
aliases), but it would be kernel version dependent, and it would works
only on the new method (or a new microcode_ctl version, but people
upgrade more often kernel than packages).
ciao
cate
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 14:06 ` Giacomo A. Catenazzi
@ 2008-09-19 14:29 ` Arjan van de Ven
0 siblings, 0 replies; 32+ messages in thread
From: Arjan van de Ven @ 2008-09-19 14:29 UTC (permalink / raw)
To: Giacomo A. Catenazzi
Cc: Peter Oruba, Dmitry Adamushko, Ingo Molnar, Thomas Gleixner,
Tigran Aivazian, LKML
On Fri, 19 Sep 2008 16:06:53 +0200
"Giacomo A. Catenazzi" <cate@debian.org> wrote:
> Peter Oruba wrote:
> > Giacomo A. Catenazzi schrieb:
> >> Dmitry Adamushko wrote:
> >>> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
> >>>> Some additonal words regarding the current user space issues:
> >>>>
> >>>> IMHO the most convenient way to update microcode is through the
> >>>> firmware loading
> >>>> interface instead of microcode_ctl. This reduces user-space
> >>>> responsibilities to
> >>>> loading the correct module at boot time and to place the
> >>>> microcode patch file at
> >>>> the right location via package installation. The problems
> >>>> mentioned in this
> >>>> thread would then probably disappear as well. What do you guys
> >>>> think?
> >>> It'd still require changes for all the setups that currently rely
> >>> on the 'microcode_ctl' interface. Moreover, Arjan's setup failed
> >>> not due to the 'microcode_ctl' per se but due to the altered
> >>> kernel module name. After all, we can't break the established
> >>> interface this way.
> >>>
> >>> We can either reserve 'microcode' as a legacy name for intel cpus
> >>> (== microcode_intel), or maybe we can use request_module() from
> >>> microcode.ko to load a proper arch-specific module (I guess, it's
> >>> not ok for !KMOD-enabled kernels).
> >> I agree. A wrapper "microcode.ko" module would be nice, in order
> >> to allow independent kernel and user space upgrades.
> >>
> >> The module name is important also on udev method: only a module
> >> load triggers the microcode request in udev, thus also the
> >> new method should have stable kernel module name.
> >>
> >> ciao
> >> cate
> >>
> >
> > That sounds like a single-module solution would be the best way to
> > go. All dependencies would then be handled inside the module.
>
> Single module probably is more difficult to maintain.
>
> I was thinking about a very simple additional module:
> It checks the cpu: load the relevant module, and wrapper the
> calls to the relevant module.
>
> So every vendor could develop easier the own driver. Only the
> interface should be stable.
>
> Eventually we could solve it in the distribution scripts (using module
> aliases), but it would be kernel version dependent, and it would works
> only on the new method (or a new microcode_ctl version, but people
> upgrade more often kernel than packages).
this would still fail the fedora microcode_ctl scripts; those also do
an rmmod afterwards, which now will fail with our method
what a mess ;-(
--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 13:03 ` Peter Oruba
2008-09-19 13:52 ` Giacomo A. Catenazzi
2008-09-19 14:06 ` Giacomo A. Catenazzi
@ 2008-09-20 6:07 ` Ingo Molnar
2 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-09-20 6:07 UTC (permalink / raw)
To: Peter Oruba
Cc: Giacomo A. Catenazzi, Dmitry Adamushko, Arjan van de Ven,
Thomas Gleixner, Tigran Aivazian, LKML
* Peter Oruba <peter.oruba@amd.com> wrote:
> Giacomo A. Catenazzi schrieb:
> > Dmitry Adamushko wrote:
> >> 2008/9/19 Peter Oruba <peter.oruba@amd.com>:
> >>> Some additonal words regarding the current user space issues:
> >>>
> >>> IMHO the most convenient way to update microcode is through the
> >>> firmware loading
> >>> interface instead of microcode_ctl. This reduces user-space
> >>> responsibilities to
> >>> loading the correct module at boot time and to place the microcode
> >>> patch file at
> >>> the right location via package installation. The problems mentioned
> >>> in this
> >>> thread would then probably disappear as well. What do you guys think?
> >>
> >> It'd still require changes for all the setups that currently rely on
> >> the 'microcode_ctl' interface. Moreover, Arjan's setup failed not due
> >> to the 'microcode_ctl' per se but due to the altered kernel module
> >> name. After all, we can't break the established interface this way.
> >>
> >> We can either reserve 'microcode' as a legacy name for intel cpus (==
> >> microcode_intel), or maybe we can use request_module() from
> >> microcode.ko to load a proper arch-specific module (I guess, it's not
> >> ok for !KMOD-enabled kernels).
> >
> > I agree. A wrapper "microcode.ko" module would be nice, in order
> > to allow independent kernel and user space upgrades.
> >
> > The module name is important also on udev method: only a module
> > load triggers the microcode request in udev, thus also the
> > new method should have stable kernel module name.
> >
> > ciao
> > cate
> >
>
> That sounds like a single-module solution would be the best way to go.
> All dependencies would then be handled inside the module.
yes - as long as the internal abstraction is clean (and it is rather
clean with Dmitry's changes applied too), that should be fine and
maintainable.
Ingo
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c.
2008-09-19 13:52 ` Giacomo A. Catenazzi
@ 2008-09-20 6:11 ` Ingo Molnar
0 siblings, 0 replies; 32+ messages in thread
From: Ingo Molnar @ 2008-09-20 6:11 UTC (permalink / raw)
To: Giacomo A. Catenazzi
Cc: Peter Oruba, Dmitry Adamushko, Arjan van de Ven, Thomas Gleixner,
Tigran Aivazian, LKML
* Giacomo A. Catenazzi <cate@debian.org> wrote:
>> That sounds like a single-module solution would be the best way to
>> go. All dependencies would then be handled inside the module.
>
> Single module probably is more difficult to maintain.
why? In this case we have just two relevant CPU microcode drivers - and
we dont expect their number to grow significantly. So it should be
perfectly clean to link everything into a single module.
In fact as this example has shown it a single-module solution has
numerous advantages, as it simplifies userspace interactions.
Taken to the extreme, a single-image (bzImage) kernel has many
advantages over a many-modules kernel as well. So we only want to
modularize when we absolutely have to, and this is not one of those
cases.
Ingo
^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~2008-09-20 6:12 UTC | newest]
Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-28 16:44 [patch 00/11] x86: AMD microcode patch loading support v2 Peter Oruba
2008-07-28 16:44 ` [patch 02/11] [PATCH 02/11] x86: Moved Intel microcode patch loader declarations to seperate header file Peter Oruba
2008-07-28 16:44 ` [patch 03/11] [PATCH 03/11] x86: Typedef removal Peter Oruba
2008-07-28 16:44 ` [patch 04/11] [PATCH 04/11] x86: Moved per CPU microcode structure declaration to header file Peter Oruba
2008-07-28 16:44 ` [patch 05/11] [PATCH 05/11] x86: Moved microcode.c to microcode_intel.c Peter Oruba
2008-09-07 19:08 ` Arjan van de Ven
2008-09-12 11:54 ` Peter Oruba
2008-09-12 13:35 ` Arjan van de Ven
2008-09-12 13:53 ` Giacomo A. Catenazzi
2008-09-19 11:59 ` Peter Oruba
2008-09-19 12:37 ` Dmitry Adamushko
2008-09-19 12:58 ` Giacomo A. Catenazzi
2008-09-19 13:03 ` Peter Oruba
2008-09-19 13:52 ` Giacomo A. Catenazzi
2008-09-20 6:11 ` Ingo Molnar
2008-09-19 14:06 ` Giacomo A. Catenazzi
2008-09-19 14:29 ` Arjan van de Ven
2008-09-20 6:07 ` Ingo Molnar
2008-09-19 13:07 ` Arjan van de Ven
2008-07-28 16:44 ` [patch 06/11] [PATCH 06/11] x86: Code split to two parts Peter Oruba
2008-07-28 16:44 ` [patch 07/11] [PATCH 07/11] x86: Structure declaration renaming Peter Oruba
2008-07-28 16:44 ` [patch 08/11] [PATCH 08/11] x86: Add AMD specific declarations Peter Oruba
2008-07-28 16:44 ` [patch 09/11] [PATCH 09/11] x86: First step of refactoring, introducing microcode_ops Peter Oruba
2008-07-28 16:44 ` [patch 10/11] [PATCH 10/11] x86: Major refactoring Peter Oruba
2008-07-28 19:36 ` Max Krasnyansky
2008-07-28 19:50 ` Tigran Aivazian
2008-07-28 16:44 ` [patch 11/11] [PATCH 11/11] x86: AMD microcode patch loading support Peter Oruba
2008-07-28 18:01 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
2008-07-29 8:10 ` [PATCH] x86, microcode support: fix build error Ingo Molnar
2008-07-29 8:10 ` [patch 00/11] x86: AMD microcode patch loading support v2 Ingo Molnar
2008-07-29 8:10 ` Ingo Molnar
2008-07-29 8:12 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox