drivers/thermal/pcie_cooling.c
Source file repositories/reference/linux-study-clean/drivers/thermal/pcie_cooling.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/pcie_cooling.c- Extension
.c- Size
- 2376 bytes
- Lines
- 81
- Domain
- Driver Families
- Bucket
- drivers/thermal
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/build_bug.hlinux/cleanup.hlinux/err.hlinux/module.hlinux/pci.hlinux/pci-bwctrl.hlinux/slab.hlinux/sprintf.hlinux/thermal.h
Detected Declarations
function Copyrightfunction pcie_cooling_get_cur_levelfunction pcie_cooling_set_cur_levelfunction pcie_cooling_device_unregister
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* PCIe cooling device
*
* Copyright (C) 2023-2024 Intel Corporation
*/
#include <linux/build_bug.h>
#include <linux/cleanup.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/pci-bwctrl.h>
#include <linux/slab.h>
#include <linux/sprintf.h>
#include <linux/thermal.h>
#define COOLING_DEV_TYPE_PREFIX "PCIe_Port_Link_Speed_"
static int pcie_cooling_get_max_level(struct thermal_cooling_device *cdev, unsigned long *state)
{
struct pci_dev *port = cdev->devdata;
/* cooling state 0 is same as the maximum PCIe speed */
*state = port->subordinate->max_bus_speed - PCIE_SPEED_2_5GT;
return 0;
}
static int pcie_cooling_get_cur_level(struct thermal_cooling_device *cdev, unsigned long *state)
{
struct pci_dev *port = cdev->devdata;
/* cooling state 0 is same as the maximum PCIe speed */
*state = cdev->max_state - (port->subordinate->cur_bus_speed - PCIE_SPEED_2_5GT);
return 0;
}
static int pcie_cooling_set_cur_level(struct thermal_cooling_device *cdev, unsigned long state)
{
struct pci_dev *port = cdev->devdata;
enum pci_bus_speed speed;
/* cooling state 0 is same as the maximum PCIe speed */
speed = (cdev->max_state - state) + PCIE_SPEED_2_5GT;
return pcie_set_target_speed(port, speed, true);
}
static struct thermal_cooling_device_ops pcie_cooling_ops = {
.get_max_state = pcie_cooling_get_max_level,
.get_cur_state = pcie_cooling_get_cur_level,
.set_cur_state = pcie_cooling_set_cur_level,
};
struct thermal_cooling_device *pcie_cooling_device_register(struct pci_dev *port)
{
char *name __free(kfree) =
kasprintf(GFP_KERNEL, COOLING_DEV_TYPE_PREFIX "%s", pci_name(port));
if (!name)
return ERR_PTR(-ENOMEM);
return thermal_cooling_device_register(name, port, &pcie_cooling_ops);
}
void pcie_cooling_device_unregister(struct thermal_cooling_device *cdev)
{
thermal_cooling_device_unregister(cdev);
}
/* For bus_speed <-> state arithmetic */
static_assert(PCIE_SPEED_2_5GT + 1 == PCIE_SPEED_5_0GT);
static_assert(PCIE_SPEED_5_0GT + 1 == PCIE_SPEED_8_0GT);
static_assert(PCIE_SPEED_8_0GT + 1 == PCIE_SPEED_16_0GT);
static_assert(PCIE_SPEED_16_0GT + 1 == PCIE_SPEED_32_0GT);
static_assert(PCIE_SPEED_32_0GT + 1 == PCIE_SPEED_64_0GT);
MODULE_AUTHOR("Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>");
MODULE_DESCRIPTION("PCIe cooling driver");
Annotation
- Immediate include surface: `linux/build_bug.h`, `linux/cleanup.h`, `linux/err.h`, `linux/module.h`, `linux/pci.h`, `linux/pci-bwctrl.h`, `linux/slab.h`, `linux/sprintf.h`.
- Detected declarations: `function Copyright`, `function pcie_cooling_get_cur_level`, `function pcie_cooling_set_cur_level`, `function pcie_cooling_device_unregister`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.