2 * This file is part of msrtool.
4 * Copyright (c) 2009 Andriy Gapon <avg@icyb.net.ua>
5 * Copyright (c) 2009 Peter Stuge <peter@stuge.se>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <sys/types.h>
30 static int msr_fd[MAX_CORES] = {-1, -1, -1, -1, -1, -1, -1, -1};
32 int freebsd_probe(const struct sysdef *system)
37 return stat("/dev/cpuctl0", &st) == 0;
43 int freebsd_open(uint8_t cpu, enum SysModes mode)
54 else if (SYS_WRONLY == mode)
59 snprintf(devname, sizeof(devname), "/dev/cpuctl%u", cpu);
60 msr_fd[cpu] = open(devname, flags);
61 if (msr_fd[cpu] < 0) {
71 int freebsd_close(uint8_t cpu)
76 if (msr_fd[cpu] != -1)
82 int freebsd_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val)
85 cpuctl_msr_args_t args;
94 if (ioctl(msr_fd[cpu], CPUCTL_RDMSR, &args) < 0) {
95 perror("ioctl(CPUCTL_RDMSR)");
99 val->hi = args.data >> 32;
100 val->lo = args.data & 0xffffffff;