-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_auto_reboot.c
58 lines (52 loc) · 1.22 KB
/
set_auto_reboot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/pciio.h>
#include <fcntl.h>
int main() {
int ret;
int f = open("/dev/pci", O_RDONLY|O_WRONLY);
if (f < 0) {
perror("Unable to open PCI dev for reading and writing");
exit(2);
}
struct pci_io d;
d.pi_sel.pc_domain = 0;
d.pi_sel.pc_bus = 0;
d.pi_sel.pc_dev = 3;
d.pi_sel.pc_func = 0;
d.pi_reg = 0x00; // read the device and vendor IDs
d.pi_width = 4;
ret = ioctl(f, PCIOCREAD, &d);
if (ret != 0) {
perror("Unable to perform PCIOCREAD for device and vendor ID");
exit(3);
} else {
if (d.pi_data != 0x0d8010de){
printf ("device not found, expecting 0xd8010de found 0x%x\n", d.pi_data);
exit (5);
}
}
d.pi_reg = 0x7b;
d.pi_width = 1;
ret = ioctl(f, PCIOCREAD, &d);
if (ret != 0) {
perror("Unable to perform PCIOCREAD");
exit(3);
} else {
const unsigned mask = 1<<6;
if (d.pi_data & mask) {
printf("Auto reboot bit NOT SET. Setting auto reboot bit.\n");
d.pi_data = d.pi_data & ~mask;
ret = ioctl(f, PCIOCWRITE, &d);
if (ret != 0) {
perror("Unable to perform PCIOCWRITE");
exit(4);
}
} else {
printf("Auto reboot bit SET. Nothing to do.\n");
}
}
}