License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6-block.git] / arch / x86 / kernel / cpu / match.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
644e9cbb 2#include <asm/cpu_device_id.h>
cd4d09ec 3#include <asm/cpufeature.h>
644e9cbb 4#include <linux/cpu.h>
186f4360 5#include <linux/export.h>
fad12ac8 6#include <linux/slab.h>
644e9cbb
AK
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 * { X86_VENDOR_INTEL, 6, 0x12 }
20 * or to match a specific CPU feature
21 * { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) }
22 *
23 * Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
24 * %X86_MODEL_ANY, %X86_FEATURE_ANY or 0 (except for vendor)
25 *
26 * Arrays used to match for this should also be declared using
a7e0e4e9 27 * MODULE_DEVICE_TABLE(x86cpu, ...)
644e9cbb
AK
28 *
29 * This always matches against the boot cpu, assuming models and features are
30 * consistent over all CPUs.
31 */
32const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
33{
34 const struct x86_cpu_id *m;
35 struct cpuinfo_x86 *c = &boot_cpu_data;
36
37 for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
38 if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
39 continue;
40 if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
41 continue;
42 if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
43 continue;
44 if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
45 continue;
46 return m;
47 }
48 return NULL;
49}
50EXPORT_SYMBOL(x86_match_cpu);