xref: /illumos-gate/usr/src/lib/fm/topo/modules/common/zen/topo_zen_sensor.c (revision 71536d92c2013e2e7bf726baf846077b18ddf93d)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2024 Oxide Computer Company
14  */
15 
16 /*
17  * Create and manage the various CPU Tctl and Tdie sensors.
18  */
19 
20 #include <sys/fm/protocol.h>
21 #include <fm/topo_mod.h>
22 #include <topo_sensor.h>
23 
24 #include "topo_zen_impl.h"
25 
26 static const char *sensor_base = "/dev/sensors/temperature/cpu";
27 
28 int
topo_zen_create_tdie(topo_mod_t * mod,tnode_t * tn,const amdzen_topo_ccd_t * ccd)29 topo_zen_create_tdie(topo_mod_t *mod, tnode_t *tn, const amdzen_topo_ccd_t *ccd)
30 {
31 	char buf[PATH_MAX];
32 
33 	if (snprintf(buf, sizeof (buf), "%s/procnode.%u.die.%u", sensor_base,
34 	    ccd->atccd_dfno, ccd->atccd_phys_no) >= sizeof (buf)) {
35 		return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
36 	}
37 
38 	return (topo_sensor_create_scalar_sensor(mod, tn, buf, "Tdie"));
39 }
40 
41 int
topo_zen_create_tctl(topo_mod_t * mod,tnode_t * tn,const amdzen_topo_df_t * df)42 topo_zen_create_tctl(topo_mod_t *mod, tnode_t *tn, const amdzen_topo_df_t *df)
43 {
44 	char buf[PATH_MAX];
45 
46 	if (snprintf(buf, sizeof (buf), "%s/procnode.%u", sensor_base,
47 	    df->atd_dfno) >= sizeof (buf)) {
48 		return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
49 	}
50 
51 	return (topo_sensor_create_scalar_sensor(mod, tn, buf, "Tctl"));
52 }
53