ia64/xen-unstable

changeset 18499:3eb7a0cfffc2

x86, microcode: More code cleanups.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Sep 16 13:09:04 2008 +0100 (2008-09-16)
parents f03b0cc33576
children 4a381ddc764a 88445b184dc6
files xen/arch/x86/microcode.c xen/arch/x86/microcode_amd.c xen/arch/x86/microcode_intel.c xen/include/asm-x86/microcode.h
line diff
     1.1 --- a/xen/arch/x86/microcode.c	Tue Sep 16 12:44:26 2008 +0100
     1.2 +++ b/xen/arch/x86/microcode.c	Tue Sep 16 13:09:04 2008 +0100
     1.3 @@ -36,9 +36,6 @@
     1.4  #include <asm/processor.h>
     1.5  #include <asm/microcode.h>
     1.6  
     1.7 -static int verbose;
     1.8 -boolean_param("microcode.verbose", verbose);
     1.9 -
    1.10  const struct microcode_ops *microcode_ops;
    1.11  
    1.12  static DEFINE_SPINLOCK(microcode_mutex);
    1.13 @@ -58,7 +55,8 @@ static void microcode_fini_cpu(int cpu)
    1.14      struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
    1.15  
    1.16      spin_lock(&microcode_mutex);
    1.17 -    microcode_ops->microcode_fini_cpu(cpu);
    1.18 +    xfree(uci->mc.valid_mc);
    1.19 +    uci->mc.valid_mc = NULL;
    1.20      uci->valid = 0;
    1.21      spin_unlock(&microcode_mutex);
    1.22  }
    1.23 @@ -142,36 +140,23 @@ static int microcode_update_cpu(int cpu,
    1.24  
    1.25  static void do_microcode_update_one(void *info)
    1.26  {
    1.27 -    int error;
    1.28 -
    1.29 -    error = microcode_update_cpu(
    1.30 +    int error = microcode_update_cpu(
    1.31          smp_processor_id(), microcode_buffer.buf, microcode_buffer.size);
    1.32 -
    1.33      if ( error )
    1.34          microcode_error = error;
    1.35  }
    1.36  
    1.37  static int do_microcode_update(void)
    1.38  {
    1.39 -    int error = 0;
    1.40 -
    1.41      microcode_error = 0;
    1.42  
    1.43      if ( on_each_cpu(do_microcode_update_one, NULL, 1, 1) != 0 )
    1.44      {
    1.45          printk(KERN_ERR "microcode: Error! Could not run on all processors\n");
    1.46 -        error = -EIO;
    1.47 -        goto out;
    1.48 +        return -EIO;
    1.49      }
    1.50  
    1.51 -    if ( microcode_error )
    1.52 -    {
    1.53 -        error = microcode_error;
    1.54 -        goto out;
    1.55 -    }
    1.56 -
    1.57 - out:
    1.58 -    return error;
    1.59 +    return microcode_error;
    1.60  }
    1.61  
    1.62  int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len)
    1.63 @@ -187,7 +172,7 @@ int microcode_update(XEN_GUEST_HANDLE(co
    1.64          return -E2BIG;
    1.65      }
    1.66  
    1.67 -    if (microcode_ops == NULL)
    1.68 +    if ( microcode_ops == NULL )
    1.69          return -EINVAL;
    1.70  
    1.71      microcode_buffer.buf = xmalloc_array(uint8_t, len);
     2.1 --- a/xen/arch/x86/microcode_amd.c	Tue Sep 16 12:44:26 2008 +0100
     2.2 +++ b/xen/arch/x86/microcode_amd.c	Tue Sep 16 13:09:04 2008 +0100
     2.3 @@ -63,9 +63,10 @@ static int collect_cpu_info(int cpu, str
     2.4          return -1;
     2.5      }
     2.6  
     2.7 -    asm volatile("movl %1, %%ecx; rdmsr"
     2.8 -                 : "=a" (csig->rev)
     2.9 -                 : "i" (MSR_AMD_PATCHLEVEL) : "ecx");
    2.10 +    asm volatile (
    2.11 +        "movl %1, %%ecx; rdmsr"
    2.12 +        : "=a" (csig->rev)
    2.13 +        : "i" (MSR_AMD_PATCHLEVEL) : "ecx" );
    2.14  
    2.15      printk(KERN_INFO "microcode: collect_cpu_info: patch_id=0x%x\n",
    2.16             csig->rev);
    2.17 @@ -81,7 +82,7 @@ static int get_matching_microcode(void *
    2.18      void *new_mc;
    2.19      unsigned int current_cpu_id;
    2.20      unsigned int equiv_cpu_id = 0x00;
    2.21 -    unsigned int i = 0;
    2.22 +    unsigned int i;
    2.23  
    2.24      /* We should bind the task to the CPU */
    2.25      BUG_ON(cpu != raw_smp_processor_id());
    2.26 @@ -106,14 +107,13 @@ static int get_matching_microcode(void *
    2.27  
    2.28      current_cpu_id = cpuid_eax(0x00000001);
    2.29  
    2.30 -    while ( equiv_cpu_table[i].installed_cpu != 0 )
    2.31 +    for ( i = 0; equiv_cpu_table[i].installed_cpu != 0; i++ )
    2.32      {
    2.33          if ( current_cpu_id == equiv_cpu_table[i].installed_cpu )
    2.34          {
    2.35              equiv_cpu_id = equiv_cpu_table[i].equiv_cpu;
    2.36              break;
    2.37          }
    2.38 -        i++;
    2.39      }
    2.40  
    2.41      if ( !equiv_cpu_id )
    2.42 @@ -187,13 +187,15 @@ static int apply_microcode(int cpu)
    2.43      edx = (uint32_t)(addr >> 32);
    2.44      eax = (uint32_t)addr;
    2.45  
    2.46 -    asm volatile("movl %0, %%ecx; wrmsr" :
    2.47 -                 : "i" (MSR_AMD_PATCHLOADER), "a" (eax), "d" (edx) : "ecx");
    2.48 +    asm volatile (
    2.49 +        "movl %0, %%ecx; wrmsr" :
    2.50 +        : "i" (MSR_AMD_PATCHLOADER), "a" (eax), "d" (edx) : "ecx" );
    2.51  
    2.52      /* get patch id after patching */
    2.53 -    asm volatile("movl %1, %%ecx; rdmsr"
    2.54 -                 : "=a" (rev)
    2.55 -                 : "i" (MSR_AMD_PATCHLEVEL) : "ecx");
    2.56 +    asm volatile (
    2.57 +        "movl %1, %%ecx; rdmsr"
    2.58 +        : "=a" (rev)
    2.59 +        : "i" (MSR_AMD_PATCHLEVEL) : "ecx");
    2.60  
    2.61      spin_unlock_irqrestore(&microcode_update_lock, flags);
    2.62  
    2.63 @@ -353,21 +355,11 @@ static int cpu_request_microcode(int cpu
    2.64      return error;
    2.65  }
    2.66  
    2.67 -static void microcode_fini_cpu(int cpu)
    2.68 -{
    2.69 -    struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
    2.70 -
    2.71 -    xfree(uci->mc.mc_amd);
    2.72 -    uci->mc.mc_amd = NULL;
    2.73 -}
    2.74 -
    2.75  static struct microcode_ops microcode_amd_ops = {
    2.76      .get_matching_microcode           = get_matching_microcode,
    2.77 -    .microcode_sanity_check           = NULL,
    2.78      .cpu_request_microcode            = cpu_request_microcode,
    2.79      .collect_cpu_info                 = collect_cpu_info,
    2.80      .apply_microcode                  = apply_microcode,
    2.81 -    .microcode_fini_cpu               = microcode_fini_cpu,
    2.82  };
    2.83  
    2.84  static __init int microcode_init_amd(void)
     3.1 --- a/xen/arch/x86/microcode_intel.c	Tue Sep 16 12:44:26 2008 +0100
     3.2 +++ b/xen/arch/x86/microcode_intel.c	Tue Sep 16 13:09:04 2008 +0100
     3.3 @@ -318,9 +318,6 @@ static long get_next_ucode_from_buffer(v
     3.4      return offset + total_size;
     3.5  }
     3.6  
     3.7 -/* fake device for request_firmware */
     3.8 -extern struct platform_device *microcode_pdev;
     3.9 -
    3.10  static int cpu_request_microcode(int cpu, const void *buf, size_t size)
    3.11  {
    3.12      long offset = 0;
    3.13 @@ -357,21 +354,11 @@ static int cpu_request_microcode(int cpu
    3.14      return error;
    3.15  }
    3.16  
    3.17 -static void microcode_fini_cpu(int cpu)
    3.18 -{
    3.19 -    struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
    3.20 -
    3.21 -    xfree(uci->mc.mc_intel);
    3.22 -    uci->mc.mc_intel = NULL;
    3.23 -}
    3.24 -
    3.25  static struct microcode_ops microcode_intel_ops = {
    3.26      .get_matching_microcode           = get_matching_microcode,
    3.27 -    .microcode_sanity_check           = microcode_sanity_check,
    3.28      .cpu_request_microcode            = cpu_request_microcode,
    3.29      .collect_cpu_info                 = collect_cpu_info,
    3.30      .apply_microcode                  = apply_microcode,
    3.31 -    .microcode_fini_cpu               = microcode_fini_cpu,
    3.32  };
    3.33  
    3.34  static __init int microcode_init_intel(void)
     4.1 --- a/xen/include/asm-x86/microcode.h	Tue Sep 16 12:44:26 2008 +0100
     4.2 +++ b/xen/include/asm-x86/microcode.h	Tue Sep 16 13:09:04 2008 +0100
     4.3 @@ -4,91 +4,87 @@
     4.4  struct cpu_signature;
     4.5  
     4.6  struct microcode_ops {
     4.7 -	long (*microcode_get_next_ucode)(void **mc, long offset);
     4.8 -	int (*get_matching_microcode)(void *mc, int cpu);
     4.9 -	int (*microcode_sanity_check)(void *mc);
    4.10 -	int (*cpu_request_microcode)(int cpu, const void *buf, size_t size);
    4.11 -	int (*collect_cpu_info)(int cpu_num, struct cpu_signature *csig);
    4.12 -	int (*apply_microcode)(int cpu);
    4.13 -	void (*microcode_fini_cpu)(int cpu);
    4.14 -	void (*clear_patch)(void *data);
    4.15 +    int (*get_matching_microcode)(void *mc, int cpu);
    4.16 +    int (*cpu_request_microcode)(int cpu, const void *buf, size_t size);
    4.17 +    int (*collect_cpu_info)(int cpu_num, struct cpu_signature *csig);
    4.18 +    int (*apply_microcode)(int cpu);
    4.19  };
    4.20  
    4.21  struct microcode_header_intel {
    4.22 -	unsigned int            hdrver;
    4.23 -	unsigned int            rev;
    4.24 -	unsigned int            date;
    4.25 -	unsigned int            sig;
    4.26 -	unsigned int            cksum;
    4.27 -	unsigned int            ldrver;
    4.28 -	unsigned int            pf;
    4.29 -	unsigned int            datasize;
    4.30 -	unsigned int            totalsize;
    4.31 -	unsigned int            reserved[3];
    4.32 +    unsigned int hdrver;
    4.33 +    unsigned int rev;
    4.34 +    unsigned int date;
    4.35 +    unsigned int sig;
    4.36 +    unsigned int cksum;
    4.37 +    unsigned int ldrver;
    4.38 +    unsigned int pf;
    4.39 +    unsigned int datasize;
    4.40 +    unsigned int totalsize;
    4.41 +    unsigned int reserved[3];
    4.42  };
    4.43  
    4.44  struct microcode_intel {
    4.45 -	struct microcode_header_intel hdr;
    4.46 -	unsigned int            bits[0];
    4.47 +    struct microcode_header_intel hdr;
    4.48 +    unsigned int bits[0];
    4.49  };
    4.50  
    4.51  /* microcode format is extended from prescott processors */
    4.52  struct extended_signature {
    4.53 -	unsigned int            sig;
    4.54 -	unsigned int            pf;
    4.55 -	unsigned int            cksum;
    4.56 +    unsigned int sig;
    4.57 +    unsigned int pf;
    4.58 +    unsigned int cksum;
    4.59  };
    4.60  
    4.61  struct extended_sigtable {
    4.62 -	unsigned int            count;
    4.63 -	unsigned int            cksum;
    4.64 -	unsigned int            reserved[3];
    4.65 -	struct extended_signature sigs[0];
    4.66 +    unsigned int count;
    4.67 +    unsigned int cksum;
    4.68 +    unsigned int reserved[3];
    4.69 +    struct extended_signature sigs[0];
    4.70  };
    4.71  
    4.72  struct equiv_cpu_entry {
    4.73 -	unsigned int installed_cpu;
    4.74 -	unsigned int fixed_errata_mask;
    4.75 -	unsigned int fixed_errata_compare;
    4.76 -	unsigned int equiv_cpu;
    4.77 +    unsigned int installed_cpu;
    4.78 +    unsigned int fixed_errata_mask;
    4.79 +    unsigned int fixed_errata_compare;
    4.80 +    unsigned int equiv_cpu;
    4.81  };
    4.82  
    4.83  struct microcode_header_amd {
    4.84 -	unsigned int  data_code;
    4.85 -	unsigned int  patch_id;
    4.86 -	unsigned char mc_patch_data_id[2];
    4.87 -	unsigned char mc_patch_data_len;
    4.88 -	unsigned char init_flag;
    4.89 -	unsigned int  mc_patch_data_checksum;
    4.90 -	unsigned int  nb_dev_id;
    4.91 -	unsigned int  sb_dev_id;
    4.92 -	unsigned char processor_rev_id[2];
    4.93 -	unsigned char nb_rev_id;
    4.94 -	unsigned char sb_rev_id;
    4.95 -	unsigned char bios_api_rev;
    4.96 -	unsigned char reserved1[3];
    4.97 -	unsigned int  match_reg[8];
    4.98 +    unsigned int  data_code;
    4.99 +    unsigned int  patch_id;
   4.100 +    unsigned char mc_patch_data_id[2];
   4.101 +    unsigned char mc_patch_data_len;
   4.102 +    unsigned char init_flag;
   4.103 +    unsigned int  mc_patch_data_checksum;
   4.104 +    unsigned int  nb_dev_id;
   4.105 +    unsigned int  sb_dev_id;
   4.106 +    unsigned char processor_rev_id[2];
   4.107 +    unsigned char nb_rev_id;
   4.108 +    unsigned char sb_rev_id;
   4.109 +    unsigned char bios_api_rev;
   4.110 +    unsigned char reserved1[3];
   4.111 +    unsigned int  match_reg[8];
   4.112  };
   4.113  
   4.114  struct microcode_amd {
   4.115 -	struct microcode_header_amd hdr;
   4.116 -	unsigned int mpb[0];
   4.117 +    struct microcode_header_amd hdr;
   4.118 +    unsigned int mpb[0];
   4.119  };
   4.120  
   4.121  struct cpu_signature {
   4.122 -	unsigned int sig;
   4.123 -	unsigned int pf;
   4.124 -	unsigned int rev;
   4.125 +    unsigned int sig;
   4.126 +    unsigned int pf;
   4.127 +    unsigned int rev;
   4.128  };
   4.129  
   4.130  struct ucode_cpu_info {
   4.131 -	struct cpu_signature cpu_sig;
   4.132 -	int valid;
   4.133 -	union {
   4.134 -		struct microcode_intel *mc_intel;
   4.135 -		struct microcode_amd *mc_amd;
   4.136 -		void *valid_mc;
   4.137 -	} mc;
   4.138 +    struct cpu_signature cpu_sig;
   4.139 +    int valid;
   4.140 +    union {
   4.141 +        struct microcode_intel *mc_intel;
   4.142 +        struct microcode_amd *mc_amd;
   4.143 +        void *valid_mc;
   4.144 +    } mc;
   4.145  };
   4.146  
   4.147  extern struct ucode_cpu_info ucode_cpu_info[];