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