2 * Linux user-mode based PCI implementation
3 * NetWatch system management mode administration console
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
11 #include <sys/types.h>
17 #include "../include/pci.h"
19 static int _open(int bus, int slot, int fn)
23 sprintf(fname, "/proc/bus/pci/%02x/%02x.%01x", bus, slot, fn);
24 return open(fname, O_RDWR);
27 void pci_write32(int bus, int slot, int fn, int addr, uint32_t data)
31 fd = _open(bus, slot, fn);
34 lseek(fd, addr, SEEK_SET);
39 void pci_write16(int bus, int slot, int fn, int addr, uint16_t data)
43 fd = _open(bus, slot, fn);
46 lseek(fd, addr, SEEK_SET);
51 void pci_write8(int bus, int slot, int fn, int addr, uint8_t data)
55 fd = _open(bus, slot, fn);
58 lseek(fd, addr, SEEK_SET);
63 uint32_t pci_read32(int bus, int slot, int fn, int addr)
68 fd = _open(bus, slot, fn);
71 lseek(fd, addr, SEEK_SET);
78 uint16_t pci_read16(int bus, int slot, int fn, int addr)
83 fd = _open(bus, slot, fn);
89 lseek(fd, addr, SEEK_SET);
97 uint8_t pci_read8(int bus, int slot, int fn, int addr)
102 fd = _open(bus, slot, fn);
108 lseek(fd, addr, SEEK_SET);