LCOV - code coverage report
Current view: top level - arch/x86/kernel/cpu - match.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 26 33 78.8 %
Date: 2021-04-22 12:43:58 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : #include <asm/cpu_device_id.h>
       3             : #include <asm/cpufeature.h>
       4             : #include <linux/cpu.h>
       5             : #include <linux/export.h>
       6             : #include <linux/slab.h>
       7             : 
       8             : /**
       9             :  * x86_match_cpu - match current CPU again an array of x86_cpu_ids
      10             :  * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
      11             :  *         {}.
      12             :  *
      13             :  * Return the entry if the current CPU matches the entries in the
      14             :  * passed x86_cpu_id match table. Otherwise NULL.  The match table
      15             :  * contains vendor (X86_VENDOR_*), family, model and feature bits or
      16             :  * respective wildcard entries.
      17             :  *
      18             :  * A typical table entry would be to match a specific CPU
      19             :  *
      20             :  * X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, INTEL_FAM6_BROADWELL,
      21             :  *                                    X86_FEATURE_ANY, NULL);
      22             :  *
      23             :  * Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
      24             :  * %X86_MODEL_ANY, %X86_FEATURE_ANY (except for vendor)
      25             :  *
      26             :  * asm/cpu_device_id.h contains a set of useful macros which are shortcuts
      27             :  * for various common selections. The above can be shortened to:
      28             :  *
      29             :  * X86_MATCH_INTEL_FAM6_MODEL(BROADWELL, NULL);
      30             :  *
      31             :  * Arrays used to match for this should also be declared using
      32             :  * MODULE_DEVICE_TABLE(x86cpu, ...)
      33             :  *
      34             :  * This always matches against the boot cpu, assuming models and features are
      35             :  * consistent over all CPUs.
      36             :  */
      37          10 : const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
      38             : {
      39          10 :         const struct x86_cpu_id *m;
      40          10 :         struct cpuinfo_x86 *c = &boot_cpu_data;
      41             : 
      42          10 :         for (m = match;
      43         282 :              m->vendor | m->family | m->model | m->steppings | m->feature;
      44         272 :              m++) {
      45         273 :                 if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
      46          90 :                         continue;
      47         183 :                 if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
      48          18 :                         continue;
      49         165 :                 if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
      50         164 :                         continue;
      51           1 :                 if (m->steppings != X86_STEPPING_ANY &&
      52           0 :                     !(BIT(c->x86_stepping) & m->steppings))
      53           0 :                         continue;
      54           1 :                 if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
      55           0 :                         continue;
      56             :                 return m;
      57             :         }
      58             :         return NULL;
      59             : }
      60             : EXPORT_SYMBOL(x86_match_cpu);
      61             : 
      62             : static const struct x86_cpu_desc *
      63           1 : x86_match_cpu_with_stepping(const struct x86_cpu_desc *match)
      64             : {
      65           1 :         struct cpuinfo_x86 *c = &boot_cpu_data;
      66           1 :         const struct x86_cpu_desc *m;
      67             : 
      68           2 :         for (m = match; m->x86_family | m->x86_model; m++) {
      69           2 :                 if (c->x86_vendor != m->x86_vendor)
      70           0 :                         continue;
      71           2 :                 if (c->x86 != m->x86_family)
      72           0 :                         continue;
      73           2 :                 if (c->x86_model != m->x86_model)
      74           1 :                         continue;
      75           1 :                 if (c->x86_stepping != m->x86_stepping)
      76           0 :                         continue;
      77             :                 return m;
      78             :         }
      79             :         return NULL;
      80             : }
      81             : 
      82           1 : bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table)
      83             : {
      84           1 :         const struct x86_cpu_desc *res = x86_match_cpu_with_stepping(table);
      85             : 
      86           1 :         if (!res || res->x86_microcode_rev > boot_cpu_data.microcode)
      87           0 :                 return false;
      88             : 
      89             :         return true;
      90             : }
      91             : EXPORT_SYMBOL_GPL(x86_cpu_has_min_microcode_rev);

Generated by: LCOV version 1.14