]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - pci/pci-linux.c
rfb chunks
[netwatch.git] / pci / pci-linux.c
... / ...
CommitLineData
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <fcntl.h>
4#include <stdio.h>
5#include <inttypes.h>
6
7#include "../include/pci.h"
8
9static int _open(int bus, int slot, int fn)
10{
11 char fname[512];
12
13 sprintf(fname, "/proc/bus/pci/%02x/%02x.%01x", bus, slot, fn);
14 return open(fname, O_RDWR);
15}
16
17void pci_write32(int bus, int slot, int fn, int addr, uint32_t data)
18{
19 int fd;
20
21 fd = _open(bus, slot, fn);
22 if (fd < 0)
23 return;
24 lseek(fd, addr, SEEK_SET);
25 write(fd, &data, 4);
26 close(fd);
27}
28
29void pci_write16(int bus, int slot, int fn, int addr, uint16_t data)
30{
31 int fd;
32
33 fd = _open(bus, slot, fn);
34 if (fd < 0)
35 return;
36 lseek(fd, addr, SEEK_SET);
37 write(fd, &data, 2);
38 close(fd);
39}
40
41void pci_write8(int bus, int slot, int fn, int addr, uint8_t data)
42{
43 int fd;
44
45 fd = _open(bus, slot, fn);
46 if (fd < 0)
47 return;
48 lseek(fd, addr, SEEK_SET);
49 write(fd, &data, 1);
50 close(fd);
51}
52
53uint32_t pci_read32(int bus, int slot, int fn, int addr)
54{
55 int fd;
56 uint32_t data;
57
58 fd = _open(bus, slot, fn);
59 if (fd < 0)
60 return;
61 lseek(fd, addr, SEEK_SET);
62 read(fd, &data, 4);
63 close(fd);
64
65 return data;
66}
67
68uint16_t pci_read16(int bus, int slot, int fn, int addr)
69{
70 int fd;
71 uint16_t data;
72
73 fd = _open(bus, slot, fn);
74 if (fd < 0)
75 {
76 perror("open");
77 return;
78 }
79 lseek(fd, addr, SEEK_SET);
80 read(fd, &data, 2);
81 close(fd);
82
83 return data;
84}
85
86
87uint8_t pci_read8(int bus, int slot, int fn, int addr)
88{
89 int fd;
90 uint8_t data;
91
92 fd = _open(bus, slot, fn);
93 if (fd < 0)
94 {
95 perror("open");
96 return;
97 }
98 lseek(fd, addr, SEEK_SET);
99 read(fd, &data, 1);
100 close(fd);
101
102 return data;
103}
This page took 0.02441 seconds and 4 git commands to generate.