Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 /*
0004  * Intel PMC Core platform init
0005  * Copyright (c) 2019, Google Inc.
0006  * Author - Rajat Jain
0007  *
0008  * This code instantiates platform devices for intel_pmc_core driver, only
0009  * on supported platforms that may not have the ACPI devices in the ACPI tables.
0010  * No new platforms should be added here, because we expect that new platforms
0011  * should all have the ACPI device, which is the preferred way of enumeration.
0012  */
0013 
0014 #include <linux/acpi.h>
0015 #include <linux/module.h>
0016 #include <linux/platform_device.h>
0017 
0018 #include <asm/cpu_device_id.h>
0019 #include <asm/intel-family.h>
0020 
0021 static void intel_pmc_core_release(struct device *dev)
0022 {
0023     kfree(dev);
0024 }
0025 
0026 static struct platform_device *pmc_core_device;
0027 
0028 /*
0029  * intel_pmc_core_platform_ids is the list of platforms where we want to
0030  * instantiate the platform_device if not already instantiated. This is
0031  * different than intel_pmc_core_ids in intel_pmc_core.c which is the
0032  * list of platforms that the driver supports for pmc_core device. The
0033  * other list may grow, but this list should not.
0034  */
0035 static const struct x86_cpu_id intel_pmc_core_platform_ids[] = {
0036     X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_L,       &pmc_core_device),
0037     X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE,     &pmc_core_device),
0038     X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE_L,      &pmc_core_device),
0039     X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE,        &pmc_core_device),
0040     X86_MATCH_INTEL_FAM6_MODEL(CANNONLAKE_L,    &pmc_core_device),
0041     X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L,       &pmc_core_device),
0042     X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE,       &pmc_core_device),
0043     X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE_L,     &pmc_core_device),
0044     {}
0045 };
0046 MODULE_DEVICE_TABLE(x86cpu, intel_pmc_core_platform_ids);
0047 
0048 static int __init pmc_core_platform_init(void)
0049 {
0050     int retval;
0051 
0052     /* Skip creating the platform device if ACPI already has a device */
0053     if (acpi_dev_present("INT33A1", NULL, -1))
0054         return -ENODEV;
0055 
0056     if (!x86_match_cpu(intel_pmc_core_platform_ids))
0057         return -ENODEV;
0058 
0059     pmc_core_device = kzalloc(sizeof(*pmc_core_device), GFP_KERNEL);
0060     if (!pmc_core_device)
0061         return -ENOMEM;
0062 
0063     pmc_core_device->name = "intel_pmc_core";
0064     pmc_core_device->dev.release = intel_pmc_core_release;
0065 
0066     retval = platform_device_register(pmc_core_device);
0067     if (retval)
0068         platform_device_put(pmc_core_device);
0069 
0070     return retval;
0071 }
0072 
0073 static void __exit pmc_core_platform_exit(void)
0074 {
0075     platform_device_unregister(pmc_core_device);
0076 }
0077 
0078 module_init(pmc_core_platform_init);
0079 module_exit(pmc_core_platform_exit);
0080 MODULE_LICENSE("GPL v2");