]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/aux/icanhasmsi.c
kbdfs: allow to escape ctlr-alt-del with shift for vmx and vnc.
[plan9front.git] / sys / src / cmd / aux / icanhasmsi.c
1 #include <u.h>
2 #include <libc.h>
3
4 int
5 pcicfg16r(int fd, ushort *s, vlong offset)
6 {
7         char buf[2];
8         
9         if(pread(fd, buf, 2, offset) < 2) return -1;
10         *s = buf[0] | (buf[1] << 8);
11         return 0;
12 }
13
14 void
15 main()
16 {
17         int fd;
18         long n;
19         Dir *dir;
20         char *p, *s;
21         uchar cap, c;
22         ushort sh;
23         
24         fd = open("/dev/pci", OREAD);
25         if(fd < 0) sysfatal("open /dev/pci: %r");
26         n = dirreadall(fd, &dir);
27         if(n < 0) sysfatal("dirreadall /dev/pci: %r");
28         close(fd);
29         for(; n--; dir++) {
30                 p = dir->name + strlen(dir->name) - 3;
31                 if(strcmp(p, "raw") != 0)
32                         continue;
33                 s = smprint("/dev/pci/%s", dir->name);
34                 fd = open(s, OREAD);
35                 if(fd < 0) {
36                         fprint(2, "open %s: %r", s);
37                         free(s);
38                         continue;
39                 }
40                 if(pcicfg16r(fd, &sh, 0) < 0) goto err;
41                 if(sh == 0xFFFF) goto end;
42                 if(pcicfg16r(fd, &sh, 0x06) < 0) goto err;
43                 if((sh & (1<<4)) == 0) goto end;
44                 cap = 0x33;
45                 for(;;) {
46                         if(pread(fd, &cap, 1, cap+1) < 0) goto err;
47                         if(cap == 0) goto end;
48                         if(pread(fd, &c, 1, cap) < 0) goto err;
49                         if(c == 0x05) break;
50                 }
51                 s[strlen(s) - 3] = 0;
52                 print("%s\n", s+9);
53                 goto end;
54         err:
55                 fprint(2, "read %s: %r", s);
56         end:
57                 free(s);
58                 close(fd);
59         }
60 }