CS350 COS
COS
Loading...
Searching...
No Matches
pci.c
Go to the documentation of this file.
1
2#include <stdint.h>
3
4#include <sys/kassert.h>
5#include <sys/pci.h>
6
7#include <machine/amd64.h>
8#include <machine/amd64op.h>
9
10#define PCI_PORT_ADDR 0xCF8
11#define PCI_PORT_DATABASE 0xCFC
12
13static inline uint32_t
15{
16 ASSERT(bus < 256 && slot < 64 && func < 8 && reg < 256);
17 return (1 << 31) | (bus << 16) | (slot << 11) | (func << 8) | (reg & 0x00fc);
18}
19
22{
23 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
24 uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
25
27 return inb(port);
28}
29
32{
33 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
34 uint16_t port = PCI_PORT_DATABASE + (reg & 0x2);
35
36 ASSERT((reg & 0x1) == 0);
37
39 return inw(port);
40}
41
44{
45 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
47
48 ASSERT((reg & 0x3) == 0);
49
51 return inl(port);
52}
53
54void
56 uint8_t data)
57{
58 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
59 uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
60
62 outb(port, data);
63}
64
65void
67 uint16_t data)
68{
69 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
70 uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
71
73 outw(port, data);
74}
75
76void
78 uint32_t data)
79{
80 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
81 uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
82
84 outl(port, data);
85}
86
uint32_t PCICfgRead32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:43
uint8_t PCICfgRead8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:21
void PCICfgWrite8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint8_t data)
Definition: pci.c:55
#define PCI_PORT_ADDR
Definition: pci.c:10
#define PCI_PORT_DATABASE
Definition: pci.c:11
static uint32_t PCIGetAddr(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:14
void PCICfgWrite32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint32_t data)
Definition: pci.c:77
void PCICfgWrite16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint16_t data)
Definition: pci.c:66
uint16_t PCICfgRead16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:31
static INLINE uint8_t inb(uint16_t port)
Definition: amd64op.h:452
static INLINE void outw(uint16_t port, uint16_t data)
Definition: amd64op.h:438
static INLINE void outb(uint16_t port, uint8_t data)
Definition: amd64op.h:431
static INLINE uint16_t inw(uint16_t port)
Definition: amd64op.h:463
static INLINE void outl(uint16_t port, uint32_t data)
Definition: amd64op.h:445
static INLINE uint32_t inl(uint16_t port)
Definition: amd64op.h:474
#define ASSERT(_x)
Definition: kassert.h:8
uint64_t addr
Definition: multiboot.h:1
unsigned short uint16_t
Definition: types.h:11
unsigned int uint32_t
Definition: types.h:12
unsigned char uint8_t
Definition: types.h:10