CS350 COS
COS
Loading...
Searching...
No Matches
pci.c File Reference
#include <stdint.h>
#include <sys/kassert.h>
#include <sys/pci.h>
#include <machine/amd64.h>
#include <machine/amd64op.h>
Include dependency graph for pci.c:

Go to the source code of this file.

Macros

#define PCI_PORT_ADDR   0xCF8
 
#define PCI_PORT_DATABASE   0xCFC
 

Functions

static uint32_t PCIGetAddr (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
 
uint8_t PCICfgRead8 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
 
uint16_t PCICfgRead16 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
 
uint32_t PCICfgRead32 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
 
void PCICfgWrite8 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint8_t data)
 
void PCICfgWrite16 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint16_t data)
 
void PCICfgWrite32 (uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint32_t data)
 

Macro Definition Documentation

◆ PCI_PORT_ADDR

#define PCI_PORT_ADDR   0xCF8

Definition at line 10 of file pci.c.

◆ PCI_PORT_DATABASE

#define PCI_PORT_DATABASE   0xCFC

Definition at line 11 of file pci.c.

Function Documentation

◆ PCICfgRead16()

uint16_t PCICfgRead16 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg 
)

Definition at line 31 of file pci.c.

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}
#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
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
#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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCICfgRead32()

uint32_t PCICfgRead32 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg 
)

Definition at line 43 of file pci.c.

44{
45 uint32_t addr = PCIGetAddr(bus, slot, func, reg);
47
48 ASSERT((reg & 0x3) == 0);
49
51 return inl(port);
52}
static INLINE uint32_t inl(uint16_t port)
Definition: amd64op.h:474
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCICfgRead8()

uint8_t PCICfgRead8 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg 
)

Definition at line 21 of file pci.c.

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}
static INLINE uint8_t inb(uint16_t port)
Definition: amd64op.h:452
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCICfgWrite16()

void PCICfgWrite16 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg,
uint16_t  data 
)

Definition at line 66 of file pci.c.

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}
static INLINE void outw(uint16_t port, uint16_t data)
Definition: amd64op.h:438
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCICfgWrite32()

void PCICfgWrite32 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg,
uint32_t  data 
)

Definition at line 77 of file pci.c.

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}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCICfgWrite8()

void PCICfgWrite8 ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg,
uint8_t  data 
)

Definition at line 55 of file pci.c.

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}
static INLINE void outb(uint16_t port, uint8_t data)
Definition: amd64op.h:431
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetAddr()

static uint32_t PCIGetAddr ( uint32_t  bus,
uint32_t  slot,
uint32_t  func,
uint32_t  reg 
)
inlinestatic

Definition at line 14 of file pci.c.

15{
16 ASSERT(bus < 256 && slot < 64 && func < 8 && reg < 256);
17 return (1 << 31) | (bus << 16) | (slot << 11) | (func << 8) | (reg & 0x00fc);
18}
Here is the caller graph for this function: