root/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. tcc_offset_degree_celsius_show
  2. tcc_offset_update
  3. tcc_offset_degree_celsius_store
  4. get_tjmax
  5. read_temp_msr
  6. proc_thermal_get_zone_temp
  7. proc_thermal_read_ppcc
  8. proc_thermal_notify
  9. proc_thermal_add
  10. proc_thermal_remove
  11. int3401_add
  12. int3401_remove
  13. proc_thermal_pci_msi_irq
  14. rapl_mmio_cpu_online
  15. rapl_mmio_cpu_down_prep
  16. rapl_mmio_read_raw
  17. rapl_mmio_write_raw
  18. proc_thermal_rapl_add
  19. proc_thermal_rapl_remove
  20. proc_thermal_rapl_add
  21. proc_thermal_rapl_remove
  22. proc_thermal_pci_probe
  23. proc_thermal_pci_remove
  24. proc_thermal_resume
  25. proc_thermal_init
  26. proc_thermal_exit

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * processor_thermal_device.c
   4  * Copyright (c) 2014, Intel Corporation.
   5  */
   6 #include <linux/kernel.h>
   7 #include <linux/module.h>
   8 #include <linux/init.h>
   9 #include <linux/pci.h>
  10 #include <linux/interrupt.h>
  11 #include <linux/platform_device.h>
  12 #include <linux/acpi.h>
  13 #include <linux/thermal.h>
  14 #include <linux/cpuhotplug.h>
  15 #include <linux/intel_rapl.h>
  16 #include "int340x_thermal_zone.h"
  17 #include "../intel_soc_dts_iosf.h"
  18 
  19 /* Broadwell-U/HSB thermal reporting device */
  20 #define PCI_DEVICE_ID_PROC_BDW_THERMAL  0x1603
  21 #define PCI_DEVICE_ID_PROC_HSB_THERMAL  0x0A03
  22 
  23 /* Skylake thermal reporting device */
  24 #define PCI_DEVICE_ID_PROC_SKL_THERMAL  0x1903
  25 
  26 /* CannonLake thermal reporting device */
  27 #define PCI_DEVICE_ID_PROC_CNL_THERMAL  0x5a03
  28 #define PCI_DEVICE_ID_PROC_CFL_THERMAL  0x3E83
  29 
  30 /* Braswell thermal reporting device */
  31 #define PCI_DEVICE_ID_PROC_BSW_THERMAL  0x22DC
  32 
  33 /* Broxton thermal reporting device */
  34 #define PCI_DEVICE_ID_PROC_BXT0_THERMAL  0x0A8C
  35 #define PCI_DEVICE_ID_PROC_BXT1_THERMAL  0x1A8C
  36 #define PCI_DEVICE_ID_PROC_BXTX_THERMAL  0x4A8C
  37 #define PCI_DEVICE_ID_PROC_BXTP_THERMAL  0x5A8C
  38 
  39 /* GeminiLake thermal reporting device */
  40 #define PCI_DEVICE_ID_PROC_GLK_THERMAL  0x318C
  41 
  42 /* IceLake thermal reporting device */
  43 #define PCI_DEVICE_ID_PROC_ICL_THERMAL  0x8a03
  44 
  45 #define DRV_NAME "proc_thermal"
  46 
  47 struct power_config {
  48         u32     index;
  49         u32     min_uw;
  50         u32     max_uw;
  51         u32     tmin_us;
  52         u32     tmax_us;
  53         u32     step_uw;
  54 };
  55 
  56 struct proc_thermal_device {
  57         struct device *dev;
  58         struct acpi_device *adev;
  59         struct power_config power_limits[2];
  60         struct int34x_thermal_zone *int340x_zone;
  61         struct intel_soc_dts_sensors *soc_dts;
  62         void __iomem *mmio_base;
  63 };
  64 
  65 enum proc_thermal_emum_mode_type {
  66         PROC_THERMAL_NONE,
  67         PROC_THERMAL_PCI,
  68         PROC_THERMAL_PLATFORM_DEV
  69 };
  70 
  71 struct rapl_mmio_regs {
  72         u64 reg_unit;
  73         u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
  74         int limits[RAPL_DOMAIN_MAX];
  75 };
  76 
  77 /*
  78  * We can have only one type of enumeration, PCI or Platform,
  79  * not both. So we don't need instance specific data.
  80  */
  81 static enum proc_thermal_emum_mode_type proc_thermal_emum_mode =
  82                                                         PROC_THERMAL_NONE;
  83 
  84 #define POWER_LIMIT_SHOW(index, suffix) \
  85 static ssize_t power_limit_##index##_##suffix##_show(struct device *dev, \
  86                                         struct device_attribute *attr, \
  87                                         char *buf) \
  88 { \
  89         struct proc_thermal_device *proc_dev = dev_get_drvdata(dev); \
  90         \
  91         if (proc_thermal_emum_mode == PROC_THERMAL_NONE) { \
  92                 dev_warn(dev, "Attempted to get power limit before device was initialized!\n"); \
  93                 return 0; \
  94         } \
  95         \
  96         return sprintf(buf, "%lu\n",\
  97         (unsigned long)proc_dev->power_limits[index].suffix * 1000); \
  98 }
  99 
 100 POWER_LIMIT_SHOW(0, min_uw)
 101 POWER_LIMIT_SHOW(0, max_uw)
 102 POWER_LIMIT_SHOW(0, step_uw)
 103 POWER_LIMIT_SHOW(0, tmin_us)
 104 POWER_LIMIT_SHOW(0, tmax_us)
 105 
 106 POWER_LIMIT_SHOW(1, min_uw)
 107 POWER_LIMIT_SHOW(1, max_uw)
 108 POWER_LIMIT_SHOW(1, step_uw)
 109 POWER_LIMIT_SHOW(1, tmin_us)
 110 POWER_LIMIT_SHOW(1, tmax_us)
 111 
 112 static DEVICE_ATTR_RO(power_limit_0_min_uw);
 113 static DEVICE_ATTR_RO(power_limit_0_max_uw);
 114 static DEVICE_ATTR_RO(power_limit_0_step_uw);
 115 static DEVICE_ATTR_RO(power_limit_0_tmin_us);
 116 static DEVICE_ATTR_RO(power_limit_0_tmax_us);
 117 
 118 static DEVICE_ATTR_RO(power_limit_1_min_uw);
 119 static DEVICE_ATTR_RO(power_limit_1_max_uw);
 120 static DEVICE_ATTR_RO(power_limit_1_step_uw);
 121 static DEVICE_ATTR_RO(power_limit_1_tmin_us);
 122 static DEVICE_ATTR_RO(power_limit_1_tmax_us);
 123 
 124 static struct attribute *power_limit_attrs[] = {
 125         &dev_attr_power_limit_0_min_uw.attr,
 126         &dev_attr_power_limit_1_min_uw.attr,
 127         &dev_attr_power_limit_0_max_uw.attr,
 128         &dev_attr_power_limit_1_max_uw.attr,
 129         &dev_attr_power_limit_0_step_uw.attr,
 130         &dev_attr_power_limit_1_step_uw.attr,
 131         &dev_attr_power_limit_0_tmin_us.attr,
 132         &dev_attr_power_limit_1_tmin_us.attr,
 133         &dev_attr_power_limit_0_tmax_us.attr,
 134         &dev_attr_power_limit_1_tmax_us.attr,
 135         NULL
 136 };
 137 
 138 static const struct attribute_group power_limit_attribute_group = {
 139         .attrs = power_limit_attrs,
 140         .name = "power_limits"
 141 };
 142 
 143 static ssize_t tcc_offset_degree_celsius_show(struct device *dev,
 144                                struct device_attribute *attr, char *buf)
 145 {
 146         u64 val;
 147         int err;
 148 
 149         err = rdmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, &val);
 150         if (err)
 151                 return err;
 152 
 153         val = (val >> 24) & 0xff;
 154         return sprintf(buf, "%d\n", (int)val);
 155 }
 156 
 157 static int tcc_offset_update(int tcc)
 158 {
 159         u64 val;
 160         int err;
 161 
 162         if (!tcc)
 163                 return -EINVAL;
 164 
 165         err = rdmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, &val);
 166         if (err)
 167                 return err;
 168 
 169         val &= ~GENMASK_ULL(31, 24);
 170         val |= (tcc & 0xff) << 24;
 171 
 172         err = wrmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, val);
 173         if (err)
 174                 return err;
 175 
 176         return 0;
 177 }
 178 
 179 static int tcc_offset_save;
 180 
 181 static ssize_t tcc_offset_degree_celsius_store(struct device *dev,
 182                                 struct device_attribute *attr, const char *buf,
 183                                 size_t count)
 184 {
 185         u64 val;
 186         int tcc, err;
 187 
 188         err = rdmsrl_safe(MSR_PLATFORM_INFO, &val);
 189         if (err)
 190                 return err;
 191 
 192         if (!(val & BIT(30)))
 193                 return -EACCES;
 194 
 195         if (kstrtoint(buf, 0, &tcc))
 196                 return -EINVAL;
 197 
 198         err = tcc_offset_update(tcc);
 199         if (err)
 200                 return err;
 201 
 202         tcc_offset_save = tcc;
 203 
 204         return count;
 205 }
 206 
 207 static DEVICE_ATTR_RW(tcc_offset_degree_celsius);
 208 
 209 static int stored_tjmax; /* since it is fixed, we can have local storage */
 210 
 211 static int get_tjmax(void)
 212 {
 213         u32 eax, edx;
 214         u32 val;
 215         int err;
 216 
 217         err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
 218         if (err)
 219                 return err;
 220 
 221         val = (eax >> 16) & 0xff;
 222         if (val)
 223                 return val;
 224 
 225         return -EINVAL;
 226 }
 227 
 228 static int read_temp_msr(int *temp)
 229 {
 230         int cpu;
 231         u32 eax, edx;
 232         int err;
 233         unsigned long curr_temp_off = 0;
 234 
 235         *temp = 0;
 236 
 237         for_each_online_cpu(cpu) {
 238                 err = rdmsr_safe_on_cpu(cpu, MSR_IA32_THERM_STATUS, &eax,
 239                                         &edx);
 240                 if (err)
 241                         goto err_ret;
 242                 else {
 243                         if (eax & 0x80000000) {
 244                                 curr_temp_off = (eax >> 16) & 0x7f;
 245                                 if (!*temp || curr_temp_off < *temp)
 246                                         *temp = curr_temp_off;
 247                         } else {
 248                                 err = -EINVAL;
 249                                 goto err_ret;
 250                         }
 251                 }
 252         }
 253 
 254         return 0;
 255 err_ret:
 256         return err;
 257 }
 258 
 259 static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
 260                                          int *temp)
 261 {
 262         int ret;
 263 
 264         ret = read_temp_msr(temp);
 265         if (!ret)
 266                 *temp = (stored_tjmax - *temp) * 1000;
 267 
 268         return ret;
 269 }
 270 
 271 static struct thermal_zone_device_ops proc_thermal_local_ops = {
 272         .get_temp       = proc_thermal_get_zone_temp,
 273 };
 274 
 275 static int proc_thermal_read_ppcc(struct proc_thermal_device *proc_priv)
 276 {
 277         int i;
 278         acpi_status status;
 279         struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
 280         union acpi_object *elements, *ppcc;
 281         union acpi_object *p;
 282         int ret = 0;
 283 
 284         status = acpi_evaluate_object(proc_priv->adev->handle, "PPCC",
 285                                       NULL, &buf);
 286         if (ACPI_FAILURE(status))
 287                 return -ENODEV;
 288 
 289         p = buf.pointer;
 290         if (!p || (p->type != ACPI_TYPE_PACKAGE)) {
 291                 dev_err(proc_priv->dev, "Invalid PPCC data\n");
 292                 ret = -EFAULT;
 293                 goto free_buffer;
 294         }
 295 
 296         if (!p->package.count) {
 297                 dev_err(proc_priv->dev, "Invalid PPCC package size\n");
 298                 ret = -EFAULT;
 299                 goto free_buffer;
 300         }
 301 
 302         for (i = 0; i < min((int)p->package.count - 1, 2); ++i) {
 303                 elements = &(p->package.elements[i+1]);
 304                 if (elements->type != ACPI_TYPE_PACKAGE ||
 305                     elements->package.count != 6) {
 306                         ret = -EFAULT;
 307                         goto free_buffer;
 308                 }
 309                 ppcc = elements->package.elements;
 310                 proc_priv->power_limits[i].index = ppcc[0].integer.value;
 311                 proc_priv->power_limits[i].min_uw = ppcc[1].integer.value;
 312                 proc_priv->power_limits[i].max_uw = ppcc[2].integer.value;
 313                 proc_priv->power_limits[i].tmin_us = ppcc[3].integer.value;
 314                 proc_priv->power_limits[i].tmax_us = ppcc[4].integer.value;
 315                 proc_priv->power_limits[i].step_uw = ppcc[5].integer.value;
 316         }
 317 
 318 free_buffer:
 319         kfree(buf.pointer);
 320 
 321         return ret;
 322 }
 323 
 324 #define PROC_POWER_CAPABILITY_CHANGED   0x83
 325 static void proc_thermal_notify(acpi_handle handle, u32 event, void *data)
 326 {
 327         struct proc_thermal_device *proc_priv = data;
 328 
 329         if (!proc_priv)
 330                 return;
 331 
 332         switch (event) {
 333         case PROC_POWER_CAPABILITY_CHANGED:
 334                 proc_thermal_read_ppcc(proc_priv);
 335                 int340x_thermal_zone_device_update(proc_priv->int340x_zone,
 336                                 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED);
 337                 break;
 338         default:
 339                 dev_dbg(proc_priv->dev, "Unsupported event [0x%x]\n", event);
 340                 break;
 341         }
 342 }
 343 
 344 
 345 static int proc_thermal_add(struct device *dev,
 346                             struct proc_thermal_device **priv)
 347 {
 348         struct proc_thermal_device *proc_priv;
 349         struct acpi_device *adev;
 350         acpi_status status;
 351         unsigned long long tmp;
 352         struct thermal_zone_device_ops *ops = NULL;
 353         int ret;
 354 
 355         adev = ACPI_COMPANION(dev);
 356         if (!adev)
 357                 return -ENODEV;
 358 
 359         proc_priv = devm_kzalloc(dev, sizeof(*proc_priv), GFP_KERNEL);
 360         if (!proc_priv)
 361                 return -ENOMEM;
 362 
 363         proc_priv->dev = dev;
 364         proc_priv->adev = adev;
 365         *priv = proc_priv;
 366 
 367         ret = proc_thermal_read_ppcc(proc_priv);
 368         if (ret)
 369                 return ret;
 370 
 371         status = acpi_evaluate_integer(adev->handle, "_TMP", NULL, &tmp);
 372         if (ACPI_FAILURE(status)) {
 373                 /* there is no _TMP method, add local method */
 374                 stored_tjmax = get_tjmax();
 375                 if (stored_tjmax > 0)
 376                         ops = &proc_thermal_local_ops;
 377         }
 378 
 379         proc_priv->int340x_zone = int340x_thermal_zone_add(adev, ops);
 380         if (IS_ERR(proc_priv->int340x_zone)) {
 381                 return PTR_ERR(proc_priv->int340x_zone);
 382         } else
 383                 ret = 0;
 384 
 385         ret = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
 386                                           proc_thermal_notify,
 387                                           (void *)proc_priv);
 388         if (ret)
 389                 goto remove_zone;
 390 
 391         return 0;
 392 
 393 remove_zone:
 394         int340x_thermal_zone_remove(proc_priv->int340x_zone);
 395 
 396         return ret;
 397 }
 398 
 399 static void proc_thermal_remove(struct proc_thermal_device *proc_priv)
 400 {
 401         acpi_remove_notify_handler(proc_priv->adev->handle,
 402                                    ACPI_DEVICE_NOTIFY, proc_thermal_notify);
 403         int340x_thermal_zone_remove(proc_priv->int340x_zone);
 404         sysfs_remove_file(&proc_priv->dev->kobj, &dev_attr_tcc_offset_degree_celsius.attr);
 405         sysfs_remove_group(&proc_priv->dev->kobj,
 406                            &power_limit_attribute_group);
 407 }
 408 
 409 static int int3401_add(struct platform_device *pdev)
 410 {
 411         struct proc_thermal_device *proc_priv;
 412         int ret;
 413 
 414         if (proc_thermal_emum_mode == PROC_THERMAL_PCI) {
 415                 dev_err(&pdev->dev, "error: enumerated as PCI dev\n");
 416                 return -ENODEV;
 417         }
 418 
 419         ret = proc_thermal_add(&pdev->dev, &proc_priv);
 420         if (ret)
 421                 return ret;
 422 
 423         platform_set_drvdata(pdev, proc_priv);
 424         proc_thermal_emum_mode = PROC_THERMAL_PLATFORM_DEV;
 425 
 426         dev_info(&pdev->dev, "Creating sysfs group for PROC_THERMAL_PLATFORM_DEV\n");
 427 
 428         ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_tcc_offset_degree_celsius.attr);
 429         if (ret)
 430                 return ret;
 431 
 432         ret = sysfs_create_group(&pdev->dev.kobj, &power_limit_attribute_group);
 433         if (ret)
 434                 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_tcc_offset_degree_celsius.attr);
 435 
 436         return ret;
 437 }
 438 
 439 static int int3401_remove(struct platform_device *pdev)
 440 {
 441         proc_thermal_remove(platform_get_drvdata(pdev));
 442 
 443         return 0;
 444 }
 445 
 446 static irqreturn_t proc_thermal_pci_msi_irq(int irq, void *devid)
 447 {
 448         struct proc_thermal_device *proc_priv;
 449         struct pci_dev *pdev = devid;
 450 
 451         proc_priv = pci_get_drvdata(pdev);
 452 
 453         intel_soc_dts_iosf_interrupt_handler(proc_priv->soc_dts);
 454 
 455         return IRQ_HANDLED;
 456 }
 457 
 458 #ifdef CONFIG_PROC_THERMAL_MMIO_RAPL
 459 
 460 #define MCHBAR 0
 461 
 462 /* RAPL Support via MMIO interface */
 463 static struct rapl_if_priv rapl_mmio_priv;
 464 
 465 static int rapl_mmio_cpu_online(unsigned int cpu)
 466 {
 467         struct rapl_package *rp;
 468 
 469         /* mmio rapl supports package 0 only for now */
 470         if (topology_physical_package_id(cpu))
 471                 return 0;
 472 
 473         rp = rapl_find_package_domain(cpu, &rapl_mmio_priv);
 474         if (!rp) {
 475                 rp = rapl_add_package(cpu, &rapl_mmio_priv);
 476                 if (IS_ERR(rp))
 477                         return PTR_ERR(rp);
 478         }
 479         cpumask_set_cpu(cpu, &rp->cpumask);
 480         return 0;
 481 }
 482 
 483 static int rapl_mmio_cpu_down_prep(unsigned int cpu)
 484 {
 485         struct rapl_package *rp;
 486         int lead_cpu;
 487 
 488         rp = rapl_find_package_domain(cpu, &rapl_mmio_priv);
 489         if (!rp)
 490                 return 0;
 491 
 492         cpumask_clear_cpu(cpu, &rp->cpumask);
 493         lead_cpu = cpumask_first(&rp->cpumask);
 494         if (lead_cpu >= nr_cpu_ids)
 495                 rapl_remove_package(rp);
 496         else if (rp->lead_cpu == cpu)
 497                 rp->lead_cpu = lead_cpu;
 498         return 0;
 499 }
 500 
 501 static int rapl_mmio_read_raw(int cpu, struct reg_action *ra)
 502 {
 503         if (!ra->reg)
 504                 return -EINVAL;
 505 
 506         ra->value = readq((void __iomem *)ra->reg);
 507         ra->value &= ra->mask;
 508         return 0;
 509 }
 510 
 511 static int rapl_mmio_write_raw(int cpu, struct reg_action *ra)
 512 {
 513         u64 val;
 514 
 515         if (!ra->reg)
 516                 return -EINVAL;
 517 
 518         val = readq((void __iomem *)ra->reg);
 519         val &= ~ra->mask;
 520         val |= ra->value;
 521         writeq(val, (void __iomem *)ra->reg);
 522         return 0;
 523 }
 524 
 525 static int proc_thermal_rapl_add(struct pci_dev *pdev,
 526                                  struct proc_thermal_device *proc_priv,
 527                                  struct rapl_mmio_regs *rapl_regs)
 528 {
 529         enum rapl_domain_reg_id reg;
 530         enum rapl_domain_type domain;
 531         int ret;
 532 
 533         if (!rapl_regs)
 534                 return 0;
 535 
 536         ret = pcim_iomap_regions(pdev, 1 << MCHBAR, DRV_NAME);
 537         if (ret) {
 538                 dev_err(&pdev->dev, "cannot reserve PCI memory region\n");
 539                 return -ENOMEM;
 540         }
 541 
 542         proc_priv->mmio_base = pcim_iomap_table(pdev)[MCHBAR];
 543 
 544         for (domain = RAPL_DOMAIN_PACKAGE; domain < RAPL_DOMAIN_MAX; domain++) {
 545                 for (reg = RAPL_DOMAIN_REG_LIMIT; reg < RAPL_DOMAIN_REG_MAX; reg++)
 546                         if (rapl_regs->regs[domain][reg])
 547                                 rapl_mmio_priv.regs[domain][reg] =
 548                                                 (u64)proc_priv->mmio_base +
 549                                                 rapl_regs->regs[domain][reg];
 550                 rapl_mmio_priv.limits[domain] = rapl_regs->limits[domain];
 551         }
 552         rapl_mmio_priv.reg_unit = (u64)proc_priv->mmio_base + rapl_regs->reg_unit;
 553 
 554         rapl_mmio_priv.read_raw = rapl_mmio_read_raw;
 555         rapl_mmio_priv.write_raw = rapl_mmio_write_raw;
 556 
 557         rapl_mmio_priv.control_type = powercap_register_control_type(NULL, "intel-rapl-mmio", NULL);
 558         if (IS_ERR(rapl_mmio_priv.control_type)) {
 559                 pr_debug("failed to register powercap control_type.\n");
 560                 return PTR_ERR(rapl_mmio_priv.control_type);
 561         }
 562 
 563         ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powercap/rapl:online",
 564                                 rapl_mmio_cpu_online, rapl_mmio_cpu_down_prep);
 565         if (ret < 0) {
 566                 powercap_unregister_control_type(rapl_mmio_priv.control_type);
 567                 rapl_mmio_priv.control_type = NULL;
 568                 return ret;
 569         }
 570         rapl_mmio_priv.pcap_rapl_online = ret;
 571 
 572         return 0;
 573 }
 574 
 575 static void proc_thermal_rapl_remove(void)
 576 {
 577         if (IS_ERR_OR_NULL(rapl_mmio_priv.control_type))
 578                 return;
 579 
 580         cpuhp_remove_state(rapl_mmio_priv.pcap_rapl_online);
 581         powercap_unregister_control_type(rapl_mmio_priv.control_type);
 582 }
 583 
 584 static const struct rapl_mmio_regs rapl_mmio_hsw = {
 585         .reg_unit = 0x5938,
 586         .regs[RAPL_DOMAIN_PACKAGE] = { 0x59a0, 0x593c, 0x58f0, 0, 0x5930},
 587         .regs[RAPL_DOMAIN_DRAM] = { 0x58e0, 0x58e8, 0x58ec, 0, 0},
 588         .limits[RAPL_DOMAIN_PACKAGE] = 2,
 589         .limits[RAPL_DOMAIN_DRAM] = 2,
 590 };
 591 
 592 #else
 593 
 594 static int proc_thermal_rapl_add(struct pci_dev *pdev,
 595                                  struct proc_thermal_device *proc_priv,
 596                                  struct rapl_mmio_regs *rapl_regs)
 597 {
 598         return 0;
 599 }
 600 static void proc_thermal_rapl_remove(void) {}
 601 static const struct rapl_mmio_regs rapl_mmio_hsw;
 602 
 603 #endif /* CONFIG_MMIO_RAPL */
 604 
 605 static int  proc_thermal_pci_probe(struct pci_dev *pdev,
 606                                    const struct pci_device_id *id)
 607 {
 608         struct proc_thermal_device *proc_priv;
 609         int ret;
 610 
 611         if (proc_thermal_emum_mode == PROC_THERMAL_PLATFORM_DEV) {
 612                 dev_err(&pdev->dev, "error: enumerated as platform dev\n");
 613                 return -ENODEV;
 614         }
 615 
 616         ret = pcim_enable_device(pdev);
 617         if (ret < 0) {
 618                 dev_err(&pdev->dev, "error: could not enable device\n");
 619                 return ret;
 620         }
 621 
 622         ret = proc_thermal_add(&pdev->dev, &proc_priv);
 623         if (ret)
 624                 return ret;
 625 
 626         ret = proc_thermal_rapl_add(pdev, proc_priv,
 627                                 (struct rapl_mmio_regs *)id->driver_data);
 628         if (ret) {
 629                 dev_err(&pdev->dev, "failed to add RAPL MMIO interface\n");
 630                 proc_thermal_remove(proc_priv);
 631                 return ret;
 632         }
 633 
 634         pci_set_drvdata(pdev, proc_priv);
 635         proc_thermal_emum_mode = PROC_THERMAL_PCI;
 636 
 637         if (pdev->device == PCI_DEVICE_ID_PROC_BSW_THERMAL) {
 638                 /*
 639                  * Enumerate additional DTS sensors available via IOSF.
 640                  * But we are not treating as a failure condition, if
 641                  * there are no aux DTSs enabled or fails. This driver
 642                  * already exposes sensors, which can be accessed via
 643                  * ACPI/MSR. So we don't want to fail for auxiliary DTSs.
 644                  */
 645                 proc_priv->soc_dts = intel_soc_dts_iosf_init(
 646                                         INTEL_SOC_DTS_INTERRUPT_MSI, 2, 0);
 647 
 648                 if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) {
 649                         ret = pci_enable_msi(pdev);
 650                         if (!ret) {
 651                                 ret = request_threaded_irq(pdev->irq, NULL,
 652                                                 proc_thermal_pci_msi_irq,
 653                                                 IRQF_ONESHOT, "proc_thermal",
 654                                                 pdev);
 655                                 if (ret) {
 656                                         intel_soc_dts_iosf_exit(
 657                                                         proc_priv->soc_dts);
 658                                         pci_disable_msi(pdev);
 659                                         proc_priv->soc_dts = NULL;
 660                                 }
 661                         }
 662                 } else
 663                         dev_err(&pdev->dev, "No auxiliary DTSs enabled\n");
 664         }
 665 
 666         dev_info(&pdev->dev, "Creating sysfs group for PROC_THERMAL_PCI\n");
 667 
 668         ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_tcc_offset_degree_celsius.attr);
 669         if (ret)
 670                 return ret;
 671 
 672         ret = sysfs_create_group(&pdev->dev.kobj, &power_limit_attribute_group);
 673         if (ret)
 674                 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_tcc_offset_degree_celsius.attr);
 675 
 676         return ret;
 677 }
 678 
 679 static void  proc_thermal_pci_remove(struct pci_dev *pdev)
 680 {
 681         struct proc_thermal_device *proc_priv = pci_get_drvdata(pdev);
 682 
 683         if (proc_priv->soc_dts) {
 684                 intel_soc_dts_iosf_exit(proc_priv->soc_dts);
 685                 if (pdev->irq) {
 686                         free_irq(pdev->irq, pdev);
 687                         pci_disable_msi(pdev);
 688                 }
 689         }
 690         proc_thermal_rapl_remove();
 691         proc_thermal_remove(proc_priv);
 692 }
 693 
 694 #ifdef CONFIG_PM_SLEEP
 695 static int proc_thermal_resume(struct device *dev)
 696 {
 697         struct proc_thermal_device *proc_dev;
 698 
 699         proc_dev = dev_get_drvdata(dev);
 700         proc_thermal_read_ppcc(proc_dev);
 701 
 702         tcc_offset_update(tcc_offset_save);
 703 
 704         return 0;
 705 }
 706 #else
 707 #define proc_thermal_resume NULL
 708 #endif
 709 
 710 static SIMPLE_DEV_PM_OPS(proc_thermal_pm, NULL, proc_thermal_resume);
 711 
 712 static const struct pci_device_id proc_thermal_pci_ids[] = {
 713         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BDW_THERMAL)},
 714         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_HSB_THERMAL)},
 715         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_SKL_THERMAL),
 716                 .driver_data = (kernel_ulong_t)&rapl_mmio_hsw, },
 717         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BSW_THERMAL)},
 718         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXT0_THERMAL)},
 719         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXT1_THERMAL)},
 720         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXTX_THERMAL)},
 721         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXTP_THERMAL)},
 722         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_CNL_THERMAL)},
 723         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_CFL_THERMAL)},
 724         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_GLK_THERMAL)},
 725         { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_ICL_THERMAL),
 726                 .driver_data = (kernel_ulong_t)&rapl_mmio_hsw, },
 727         { 0, },
 728 };
 729 
 730 MODULE_DEVICE_TABLE(pci, proc_thermal_pci_ids);
 731 
 732 static struct pci_driver proc_thermal_pci_driver = {
 733         .name           = DRV_NAME,
 734         .probe          = proc_thermal_pci_probe,
 735         .remove         = proc_thermal_pci_remove,
 736         .id_table       = proc_thermal_pci_ids,
 737         .driver.pm      = &proc_thermal_pm,
 738 };
 739 
 740 static const struct acpi_device_id int3401_device_ids[] = {
 741         {"INT3401", 0},
 742         {"", 0},
 743 };
 744 MODULE_DEVICE_TABLE(acpi, int3401_device_ids);
 745 
 746 static struct platform_driver int3401_driver = {
 747         .probe = int3401_add,
 748         .remove = int3401_remove,
 749         .driver = {
 750                 .name = "int3401 thermal",
 751                 .acpi_match_table = int3401_device_ids,
 752                 .pm = &proc_thermal_pm,
 753         },
 754 };
 755 
 756 static int __init proc_thermal_init(void)
 757 {
 758         int ret;
 759 
 760         ret = platform_driver_register(&int3401_driver);
 761         if (ret)
 762                 return ret;
 763 
 764         ret = pci_register_driver(&proc_thermal_pci_driver);
 765 
 766         return ret;
 767 }
 768 
 769 static void __exit proc_thermal_exit(void)
 770 {
 771         platform_driver_unregister(&int3401_driver);
 772         pci_unregister_driver(&proc_thermal_pci_driver);
 773 }
 774 
 775 module_init(proc_thermal_init);
 776 module_exit(proc_thermal_exit);
 777 
 778 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
 779 MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver");
 780 MODULE_LICENSE("GPL v2");

/* [<][>][^][v][top][bottom][index][help] */