]> Joshua Wise's Git repositories - netwatch.git/blob - pci/pci-raw.c
Move elfload into tools/
[netwatch.git] / pci / pci-raw.c
1 /* pci-raw.c
2  * Raw PCI implementation
3  * NetWatch system management mode administration console
4  *
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.
8  *
9  */
10
11 #include <io.h>
12 #include <stdint.h>
13 #include <pci.h>
14
15 static void __pci_config(int bus, int slot, int fn, int addr)
16 {
17         outl(0xCF8, 0x80000000ULL | (bus << 16) | (slot << 11) | (fn << 8) | (addr & ~3));
18 }
19
20 void pci_write32(int bus, int slot, int fn, int addr, uint32_t data)
21 {
22         __pci_config(bus, slot, fn, addr);
23         outl(0xCFC, data);
24 }
25
26 void pci_write16(int bus, int slot, int fn, int addr, uint16_t data)
27 {
28         __pci_config(bus, slot, fn, addr);
29         outw(0xCFC, data);
30 }
31
32 void pci_write8(int bus, int slot, int fn, int addr, uint8_t data)
33 {
34         __pci_config(bus, slot, fn, addr);
35         outb(0xCFC, data);
36 }
37
38 uint32_t pci_read32(int bus, int slot, int fn, int addr)
39 {
40         __pci_config(bus, slot, fn, addr);
41         return inl(0xCFC);
42 }
43
44 uint16_t pci_read16(int bus, int slot, int fn, int addr)
45 {
46         __pci_config(bus, slot, fn, addr);
47         return inw(0xCFC + (addr & 2));
48 }
49
50 uint8_t pci_read8(int bus, int slot, int fn, int addr)
51 {
52         __pci_config(bus, slot, fn, addr);
53         return inb(0xCFC + (addr & 3));
54 }
This page took 0.018862 seconds and 4 git commands to generate.