1 /* SPDX-License-Identifier: GPL-2.0-only */
12 static int msr_fd
[MAX_CORES
] = {-1, -1, -1, -1, -1, -1, -1, -1};
14 int freebsd_probe(const struct sysdef
*system
)
19 return stat("/dev/cpuctl0", &st
) == 0;
25 int freebsd_open(uint8_t cpu
, enum SysModes mode
)
36 else if (SYS_WRONLY
== mode
)
41 snprintf(devname
, sizeof(devname
), "/dev/cpuctl%u", cpu
);
42 msr_fd
[cpu
] = open(devname
, flags
);
43 if (msr_fd
[cpu
] < 0) {
53 int freebsd_close(uint8_t cpu
)
58 if (msr_fd
[cpu
] != -1)
64 int freebsd_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
)
67 cpuctl_msr_args_t args
;
76 if (ioctl(msr_fd
[cpu
], CPUCTL_RDMSR
, &args
) < 0) {
77 perror("ioctl(CPUCTL_RDMSR)");
81 val
->hi
= args
.data
>> 32;
82 val
->lo
= args
.data
& 0xffffffff;