MCPcopy Create free account
hub / github.com/coreboot/coreboot / open_and_seek

Function open_and_seek

util/amdtool/cpu.c:100–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100static int open_and_seek(int cpu, unsigned long msr, int mode, int *fd)
101{
102 char dev[32];
103 char temp_string[50];
104
105 snprintf(dev, sizeof(dev), "/dev/cpu/%d/msr", cpu);
106 *fd = open(dev, mode);
107
108 if (*fd < 0) {
109 snprintf(temp_string, sizeof(temp_string), "open(\"%s\")", dev);
110 perror(temp_string);
111 return -1;
112 }
113
114 if (lseek(*fd, msr, SEEK_SET) == (off_t)-1) {
115 snprintf(temp_string, sizeof(temp_string), "lseek(%lu)", msr);
116 perror(temp_string);
117 close(*fd);
118 return -1;
119 }
120
121 return 0;
122}
123
124static msr_t rdmsr_from_cpu(int cpu, unsigned long addr)
125{

Callers 1

rdmsr_from_cpuFunction · 0.70

Calls 2

perrorFunction · 0.85
snprintfFunction · 0.50

Tested by

no test coverage detected