1fa082a7cSKate Hsuan // SPDX-License-Identifier: GPL-2.0
2fa082a7cSKate Hsuan
3fa082a7cSKate Hsuan /*
4fa082a7cSKate Hsuan * Intel PMC Core platform init
5fa082a7cSKate Hsuan * Copyright (c) 2019, Google Inc.
6fa082a7cSKate Hsuan * Author - Rajat Jain
7fa082a7cSKate Hsuan *
8fa082a7cSKate Hsuan * This code instantiates platform devices for intel_pmc_core driver, only
9fa082a7cSKate Hsuan * on supported platforms that may not have the ACPI devices in the ACPI tables.
10fa082a7cSKate Hsuan * No new platforms should be added here, because we expect that new platforms
11fa082a7cSKate Hsuan * should all have the ACPI device, which is the preferred way of enumeration.
12fa082a7cSKate Hsuan */
13fa082a7cSKate Hsuan
14fa082a7cSKate Hsuan #include <linux/acpi.h>
15fa082a7cSKate Hsuan #include <linux/module.h>
16fa082a7cSKate Hsuan #include <linux/platform_device.h>
17fa082a7cSKate Hsuan
18fa082a7cSKate Hsuan #include <asm/cpu_device_id.h>
19fa082a7cSKate Hsuan #include <asm/intel-family.h>
20fa082a7cSKate Hsuan
212dbfb3f3SRoger Pau Monné #include <xen/xen.h>
222dbfb3f3SRoger Pau Monné
intel_pmc_core_release(struct device * dev)23fa082a7cSKate Hsuan static void intel_pmc_core_release(struct device *dev)
24fa082a7cSKate Hsuan {
25fa082a7cSKate Hsuan kfree(dev);
26fa082a7cSKate Hsuan }
27fa082a7cSKate Hsuan
28fa082a7cSKate Hsuan static struct platform_device *pmc_core_device;
29fa082a7cSKate Hsuan
30fa082a7cSKate Hsuan /*
31fa082a7cSKate Hsuan * intel_pmc_core_platform_ids is the list of platforms where we want to
32fa082a7cSKate Hsuan * instantiate the platform_device if not already instantiated. This is
33fa082a7cSKate Hsuan * different than intel_pmc_core_ids in intel_pmc_core.c which is the
34fa082a7cSKate Hsuan * list of platforms that the driver supports for pmc_core device. The
35fa082a7cSKate Hsuan * other list may grow, but this list should not.
36fa082a7cSKate Hsuan */
37fa082a7cSKate Hsuan static const struct x86_cpu_id intel_pmc_core_platform_ids[] = {
38*33af65adSTony Luck X86_MATCH_VFM(INTEL_SKYLAKE_L, &pmc_core_device),
39*33af65adSTony Luck X86_MATCH_VFM(INTEL_SKYLAKE, &pmc_core_device),
40*33af65adSTony Luck X86_MATCH_VFM(INTEL_KABYLAKE_L, &pmc_core_device),
41*33af65adSTony Luck X86_MATCH_VFM(INTEL_KABYLAKE, &pmc_core_device),
42*33af65adSTony Luck X86_MATCH_VFM(INTEL_CANNONLAKE_L, &pmc_core_device),
43*33af65adSTony Luck X86_MATCH_VFM(INTEL_ICELAKE_L, &pmc_core_device),
44*33af65adSTony Luck X86_MATCH_VFM(INTEL_COMETLAKE, &pmc_core_device),
45*33af65adSTony Luck X86_MATCH_VFM(INTEL_COMETLAKE_L, &pmc_core_device),
46fa082a7cSKate Hsuan {}
47fa082a7cSKate Hsuan };
48fa082a7cSKate Hsuan MODULE_DEVICE_TABLE(x86cpu, intel_pmc_core_platform_ids);
49fa082a7cSKate Hsuan
pmc_core_platform_init(void)50fa082a7cSKate Hsuan static int __init pmc_core_platform_init(void)
51fa082a7cSKate Hsuan {
52fa082a7cSKate Hsuan int retval;
53fa082a7cSKate Hsuan
54fa082a7cSKate Hsuan /* Skip creating the platform device if ACPI already has a device */
55fa082a7cSKate Hsuan if (acpi_dev_present("INT33A1", NULL, -1))
56fa082a7cSKate Hsuan return -ENODEV;
57fa082a7cSKate Hsuan
582dbfb3f3SRoger Pau Monné /*
592dbfb3f3SRoger Pau Monné * Skip forcefully attaching the device for VMs. Make an exception for
602dbfb3f3SRoger Pau Monné * Xen dom0, which does have full hardware access.
612dbfb3f3SRoger Pau Monné */
622dbfb3f3SRoger Pau Monné if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR) && !xen_initial_domain())
632dbfb3f3SRoger Pau Monné return -ENODEV;
642dbfb3f3SRoger Pau Monné
65fa082a7cSKate Hsuan if (!x86_match_cpu(intel_pmc_core_platform_ids))
66fa082a7cSKate Hsuan return -ENODEV;
67fa082a7cSKate Hsuan
68fa082a7cSKate Hsuan pmc_core_device = kzalloc(sizeof(*pmc_core_device), GFP_KERNEL);
69fa082a7cSKate Hsuan if (!pmc_core_device)
70fa082a7cSKate Hsuan return -ENOMEM;
71fa082a7cSKate Hsuan
72fa082a7cSKate Hsuan pmc_core_device->name = "intel_pmc_core";
73fa082a7cSKate Hsuan pmc_core_device->dev.release = intel_pmc_core_release;
74fa082a7cSKate Hsuan
75fa082a7cSKate Hsuan retval = platform_device_register(pmc_core_device);
76fa082a7cSKate Hsuan if (retval)
7726a8b094SJohan Hovold platform_device_put(pmc_core_device);
78fa082a7cSKate Hsuan
79fa082a7cSKate Hsuan return retval;
80fa082a7cSKate Hsuan }
81fa082a7cSKate Hsuan
pmc_core_platform_exit(void)82fa082a7cSKate Hsuan static void __exit pmc_core_platform_exit(void)
83fa082a7cSKate Hsuan {
84fa082a7cSKate Hsuan platform_device_unregister(pmc_core_device);
85fa082a7cSKate Hsuan }
86fa082a7cSKate Hsuan
87fa082a7cSKate Hsuan module_init(pmc_core_platform_init);
88fa082a7cSKate Hsuan module_exit(pmc_core_platform_exit);
8941ab81ceSJeff Johnson MODULE_DESCRIPTION("Intel PMC Core platform driver");
90fa082a7cSKate Hsuan MODULE_LICENSE("GPL v2");
91