drivers/accel/habanalabs/common/sysfs.c
Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/accel/habanalabs/common/sysfs.c- Extension
.c- Size
- 13795 bytes
- Lines
- 568
- Domain
- Driver Families
- Bucket
- drivers/accel
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
habanalabs.hlinux/pci.hlinux/types.h
Detected Declarations
function clk_max_freq_mhz_showfunction clk_max_freq_mhz_storefunction clk_cur_freq_mhz_showfunction vrm_ver_showfunction uboot_ver_showfunction armcp_kernel_ver_showfunction armcp_ver_showfunction cpld_ver_showfunction cpucp_kernel_ver_showfunction cpucp_ver_showfunction fuse_ver_showfunction thermal_ver_showfunction fw_os_ver_showfunction preboot_btl_ver_showfunction soft_reset_storefunction hard_reset_storefunction device_type_showfunction pci_addr_showfunction status_showfunction soft_reset_cnt_showfunction hard_reset_cnt_showfunction max_power_showfunction max_power_storefunction eeprom_read_handlerfunction security_enabled_showfunction module_id_showfunction parent_device_showfunction hl_sysfs_add_dev_clk_attrfunction hl_sysfs_add_dev_vrm_attrfunction hl_sysfs_initfunction hl_sysfs_fini
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2016-2022 HabanaLabs, Ltd.
* All Rights Reserved.
*/
#include "habanalabs.h"
#include <linux/pci.h>
#include <linux/types.h>
static ssize_t clk_max_freq_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct hl_device *hdev = dev_get_drvdata(dev);
long value;
if (!hl_device_operational(hdev, NULL))
return -ENODEV;
value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false);
if (value < 0)
return value;
hdev->asic_prop.max_freq_value = value;
return sprintf(buf, "%lu\n", (value / 1000 / 1000));
}
static ssize_t clk_max_freq_mhz_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct hl_device *hdev = dev_get_drvdata(dev);
int rc;
u64 value;
if (!hl_device_operational(hdev, NULL)) {
count = -ENODEV;
goto fail;
}
rc = kstrtoull(buf, 0, &value);
if (rc) {
count = -EINVAL;
goto fail;
}
hdev->asic_prop.max_freq_value = value * 1000 * 1000;
hl_fw_set_frequency(hdev, hdev->asic_prop.clk_pll_index, hdev->asic_prop.max_freq_value);
fail:
return count;
}
static ssize_t clk_cur_freq_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct hl_device *hdev = dev_get_drvdata(dev);
long value;
if (!hl_device_operational(hdev, NULL))
return -ENODEV;
value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true);
if (value < 0)
return value;
return sprintf(buf, "%lu\n", (value / 1000 / 1000));
}
static DEVICE_ATTR_RW(clk_max_freq_mhz);
static DEVICE_ATTR_RO(clk_cur_freq_mhz);
static struct attribute *hl_dev_clk_attrs[] = {
&dev_attr_clk_max_freq_mhz.attr,
&dev_attr_clk_cur_freq_mhz.attr,
NULL,
};
static ssize_t vrm_ver_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct hl_device *hdev = dev_get_drvdata(dev);
struct cpucp_info *cpucp_info;
u32 infineon_second_stage_version;
u32 infineon_second_stage_first_instance;
u32 infineon_second_stage_second_instance;
u32 infineon_second_stage_third_instance;
u32 mask = 0xff;
cpucp_info = &hdev->asic_prop.cpucp_info;
Annotation
- Immediate include surface: `habanalabs.h`, `linux/pci.h`, `linux/types.h`.
- Detected declarations: `function clk_max_freq_mhz_show`, `function clk_max_freq_mhz_store`, `function clk_cur_freq_mhz_show`, `function vrm_ver_show`, `function uboot_ver_show`, `function armcp_kernel_ver_show`, `function armcp_ver_show`, `function cpld_ver_show`, `function cpucp_kernel_ver_show`, `function cpucp_ver_show`.
- Atlas domain: Driver Families / drivers/accel.
- 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.