drivers/hwmon/xgene-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/xgene-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/xgene-hwmon.c- Extension
.c- Size
- 18614 bytes
- Lines
- 755
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
linux/acpi.hlinux/dma-mapping.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/io.hlinux/interrupt.hlinux/kfifo.hlinux/mailbox_controller.hlinux/mailbox_client.hlinux/module.hlinux/of.hlinux/platform_device.hacpi/pcc.h
Detected Declarations
struct slimpro_resp_msgstruct xgene_hwmon_devenum xgene_hwmon_versionfunction xgene_word_tst_and_clrfunction xgene_hwmon_pcc_rdfunction usecs_to_jiffiesfunction xgene_hwmon_rdfunction xgene_hwmon_reg_map_rdfunction xgene_hwmon_get_notification_msgfunction xgene_hwmon_get_cpu_pwrfunction xgene_hwmon_get_io_pwrfunction xgene_hwmon_get_tempfunction temp1_input_showfunction temp1_label_showfunction temp1_critical_alarm_showfunction power1_label_showfunction power2_label_showfunction power1_input_showfunction power2_input_showfunction xgene_hwmon_tpc_alarmfunction xgene_hwmon_process_pwrmsgfunction xgene_hwmon_evt_workfunction xgene_hwmon_rx_readyfunction xgene_hwmon_rx_cbfunction MSG_SUBTYPEfunction xgene_hwmon_pcc_rx_cbfunction MSG_SUBTYPEfunction xgene_hwmon_tx_donefunction xgene_hwmon_probefunction xgene_hwmon_remove
Annotated Snippet
struct slimpro_resp_msg {
u32 msg;
u32 param1;
u32 param2;
} __packed;
struct xgene_hwmon_dev {
struct device *dev;
struct mbox_chan *mbox_chan;
struct pcc_mbox_chan *pcc_chan;
struct mbox_client mbox_client;
int mbox_idx;
spinlock_t kfifo_lock;
struct mutex rd_mutex;
struct completion rd_complete;
int resp_pending;
struct slimpro_resp_msg sync_msg;
struct work_struct workq;
struct kfifo_rec_ptr_1 async_msg_fifo;
struct device *hwmon_dev;
bool temp_critical_alarm;
unsigned int usecs_lat;
};
/*
* This function tests and clears a bitmask then returns its old value
*/
static u16 xgene_word_tst_and_clr(u16 *addr, u16 mask)
{
u16 ret, val;
val = le16_to_cpu(READ_ONCE(*addr));
ret = val & mask;
val &= ~mask;
WRITE_ONCE(*addr, cpu_to_le16(val));
return ret;
}
static int xgene_hwmon_pcc_rd(struct xgene_hwmon_dev *ctx, u32 *msg)
{
struct acpi_pcct_shared_memory __iomem *generic_comm_base =
ctx->pcc_chan->shmem;
u32 *ptr = (void *)(generic_comm_base + 1);
int rc, i;
u16 val;
mutex_lock(&ctx->rd_mutex);
init_completion(&ctx->rd_complete);
ctx->resp_pending = true;
/* Write signature for subspace */
WRITE_ONCE(generic_comm_base->signature,
cpu_to_le32(PCC_SIGNATURE | ctx->mbox_idx));
/* Write to the shared command region */
WRITE_ONCE(generic_comm_base->command,
cpu_to_le16(MSG_TYPE(msg[0]) | PCC_CMD_GENERATE_DB_INTR));
/* Flip CMD COMPLETE bit */
val = le16_to_cpu(READ_ONCE(generic_comm_base->status));
val &= ~PCC_STATUS_CMD_COMPLETE;
WRITE_ONCE(generic_comm_base->status, cpu_to_le16(val));
/* Copy the message to the PCC comm space */
for (i = 0; i < sizeof(struct slimpro_resp_msg) / 4; i++)
WRITE_ONCE(ptr[i], cpu_to_le32(msg[i]));
/* Ring the doorbell */
rc = mbox_send_message(ctx->mbox_chan, msg);
if (rc < 0) {
dev_err(ctx->dev, "Mailbox send error %d\n", rc);
goto err;
}
if (!wait_for_completion_timeout(&ctx->rd_complete,
usecs_to_jiffies(ctx->usecs_lat))) {
dev_err(ctx->dev, "Mailbox operation timed out\n");
rc = -ETIMEDOUT;
goto err;
}
/* Check for error message */
if (MSG_TYPE(ctx->sync_msg.msg) == MSG_TYPE_ERR) {
rc = -EINVAL;
goto err;
}
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/dma-mapping.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/io.h`, `linux/interrupt.h`, `linux/kfifo.h`, `linux/mailbox_controller.h`.
- Detected declarations: `struct slimpro_resp_msg`, `struct xgene_hwmon_dev`, `enum xgene_hwmon_version`, `function xgene_word_tst_and_clr`, `function xgene_hwmon_pcc_rd`, `function usecs_to_jiffies`, `function xgene_hwmon_rd`, `function xgene_hwmon_reg_map_rd`, `function xgene_hwmon_get_notification_msg`, `function xgene_hwmon_get_cpu_pwr`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.