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

Go to the source code of this file.

Functions

static void PCIScan ()
 
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)
 
void AHCI_Init (uint32_t bus, uint32_t device, uint32_t func)
 
void E1000_Init (uint32_t bus, uint32_t device, uint32_t func)
 
void PCI_Init ()
 
uint16_t PCIGetDeviceID (uint32_t bus, uint32_t device, uint32_t func)
 
uint16_t PCIGetVendorID (uint32_t bus, uint32_t device, uint32_t func)
 
uint8_t PCIGetBaseClass (uint32_t bus, uint32_t device, uint32_t func)
 
uint8_t PCIGetSubClass (uint32_t bus, uint32_t device, uint32_t func)
 
uint8_t PCIGetHeaderType (uint32_t bus, uint32_t device, uint32_t func)
 
uint8_t PCI_CfgRead8 (PCIDevice *dev, uint32_t reg)
 
uint16_t PCI_CfgRead16 (PCIDevice *dev, uint32_t reg)
 
uint32_t PCI_CfgRead32 (PCIDevice *dev, uint32_t reg)
 
void PCI_CfgWrite8 (PCIDevice *dev, uint32_t reg, uint8_t data)
 
void PCI_CfgWrite16 (PCIDevice *dev, uint32_t reg, uint16_t data)
 
void PCI_CfgWrite32 (PCIDevice *dev, uint32_t reg, uint32_t data)
 
uint16_t PCI_GetDeviceID (PCIDevice *dev)
 
uint16_t PCI_GetVendorID (PCIDevice *dev)
 
uint8_t PCI_GetBaseClass (PCIDevice *dev)
 
uint8_t PCI_GetSubClass (PCIDevice *dev)
 
uint8_t PCI_GetHeaderType (PCIDevice *dev)
 
static void PCICheckFunction (uint32_t bus, uint32_t device, uint32_t func)
 
static void PCIScanDevice (uint32_t bus, uint32_t device)
 
static void PCIScanBus (uint8_t bus)
 
void PCI_Configure (PCIDevice *dev)
 
static void DebugPCICheckFunction (uint32_t bus, uint32_t device, uint32_t func)
 
static void DebugPCIScanBus (uint8_t bus)
 
void Debug_PCIList (int argc, const char *argv[])
 
 REGISTER_DBGCMD (pcilist, "PCI Device List", Debug_PCIList)
 
void Debug_PCIDump (int argc, const char *argv[])
 
 REGISTER_DBGCMD (pcidump, "PCI Device Dump", Debug_PCIDump)
 

Function Documentation

◆ AHCI_Init()

void AHCI_Init ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 183 of file ahci.c.

184{
185 PCIDevice dev;
186
187 dev.bus = bus;
188 dev.slot = slot;
189 dev.func = func;
190 dev.vendor = PCI_GetVendorID(&dev);
191 dev.device = PCI_GetDeviceID(&dev);
192
193 uint32_t device = dev.vendor << 16 | dev.device;
194
195 uint8_t progif = PCI_CfgRead8(&dev, PCI_OFFSET_PROGIF);
196 if (progif != 0x01)
197 {
198 kprintf("Unsupported SATA Controller PROGIF=%02x\n", progif);
199 return;
200 }
201
202 // XXX: Temporary until we have a slab allocator
203#define PGSIZE 4096
204 ASSERT(sizeof(AHCI) <= PGSIZE);
205 ASSERT(sizeof(AHCICommandList) <= PGSIZE);
206 ASSERT(sizeof(AHCIRecvFIS) <= PGSIZE);
207 ASSERT(sizeof(ATAIdentifyDevice) == 512);
208
209 int deviceIdx = 0;
210 while (deviceList[deviceIdx].device != 0x0) {
211 if (deviceList[deviceIdx].device == device) {
212 kprintf("AHCI: Found %s\n", deviceList[deviceIdx].name);
213 // Configure and add disks
214 AHCI_Configure(dev);
215 }
216
217 deviceIdx++;
218 }
219}
void AHCI_Configure(PCIDevice dev)
Definition: ahci.c:419
static AHCIDevice deviceList[]
Definition: ahci.c:26
#define PGSIZE
Definition: ahci.c:169
uint16_t PCI_GetVendorID(PCIDevice *dev)
Definition: pci.c:107
uint16_t PCI_GetDeviceID(PCIDevice *dev)
Definition: pci.c:101
uint8_t PCI_CfgRead8(PCIDevice *dev, uint32_t reg)
Definition: pci.c:65
#define ASSERT(_x)
Definition: kassert.h:8
int kprintf(const char *fmt,...)
Definition: printf.c:210
#define PCI_OFFSET_PROGIF
Definition: pci.h:7
uint8_t slot
Definition: pci.h:61
uint16_t device
Definition: pci.h:58
uint8_t func
Definition: pci.h:62
uint16_t vendor
Definition: pci.h:57
uint8_t bus
Definition: pci.h:60
Definition: pci.h:56
unsigned int uint32_t
Definition: types.h:12
unsigned char uint8_t
Definition: types.h:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug_PCIDump()

void Debug_PCIDump ( int  argc,
const char *  argv[] 
)

Definition at line 394 of file pci.c.

395{
396 uint32_t bus, device, func;
397 uint32_t bar;
398
399 if (argc != 4) {
400 kprintf("Requires 3 arguments!\n");
401 return;
402 }
403
404 bus = Debug_StrToInt(argv[1]);
405 device = Debug_StrToInt(argv[2]);
406 func = Debug_StrToInt(argv[3]);
407
408 kprintf("Vendor ID: %04x\n", PCIGetVendorID(bus, device, func));
409 kprintf("Device ID: %04x\n", PCIGetDeviceID(bus, device, func));
410 kprintf("Class: %d\n", PCIGetBaseClass(bus, device, func));
411 kprintf("Subclass: %d\n", PCIGetSubClass(bus, device, func));
412 kprintf("Header Type: %d\n", PCIGetHeaderType(bus, device, func));
413
414 for (bar = 0; bar < PCI_MAX_BARS; bar++)
415 {
416 uint32_t barReg = PCI_OFFSET_BARFIRST + 4 * bar;
417
418 kprintf("BAR%d: %016llx\n", bar, PCICfgRead32(bus, device, func, barReg));
419 }
420}
uint32_t PCICfgRead32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:43
uint16_t PCIGetVendorID(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:41
uint8_t PCIGetSubClass(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:53
uint16_t PCIGetDeviceID(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:35
uint8_t PCIGetHeaderType(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:59
uint8_t PCIGetBaseClass(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:47
uint64_t Debug_StrToInt(const char *s)
Definition: debug.c:124
#define PCI_OFFSET_BARFIRST
Definition: pci.h:15
#define PCI_MAX_BARS
Definition: pci.h:24
Here is the call graph for this function:

◆ Debug_PCIList()

void Debug_PCIList ( int  argc,
const char *  argv[] 
)

Definition at line 374 of file pci.c.

375{
376 uint8_t headerType = PCIGetHeaderType(0, 0, 0);
377
378 if ((headerType & 0x80) == 0) {
380 } else {
381 uint8_t busNo;
382
383 for (busNo = 0; busNo < 8; busNo++) {
384 if (PCIGetVendorID(0, 0, busNo) != 0xFFFF)
385 break;
386 DebugPCIScanBus(busNo);
387 }
388 }
389}
static void DebugPCIScanBus(uint8_t bus)
Definition: pci.c:348
Here is the call graph for this function:

◆ DebugPCICheckFunction()

static void DebugPCICheckFunction ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)
static

Definition at line 299 of file pci.c.

300{
301 uint8_t baseClass, subClass;
302 uint16_t vendorId, deviceId;
303
304 baseClass = PCIGetBaseClass(bus, device, func);
305 subClass = PCIGetSubClass(bus, device, func);
306 vendorId = PCIGetVendorID(bus, device, func);
307 deviceId = PCIGetDeviceID(bus, device, func);
308
309 if (baseClass == PCI_CLASS_BRIDGE) {
310 if (subClass == PCI_SCLASS_BRIDGE_HOST) {
311 kprintf("PCI: (%d,%d,%d) Host Bridge (%04x:%04x)\n",
312 bus, device, func, vendorId, deviceId);
313 } else if (subClass == PCI_SCLASS_BRIDGE_ISA) {
314 kprintf("PCI: (%d,%d,%d) ISA Bridge (%04x:%04x)\n",
315 bus, device, func, vendorId, deviceId);
316 } else if (subClass == PCI_SCLASS_BRIDGE_PCI) {
317 kprintf("PCI: (%d,%d,%d) PCI-PCI Bridge (%04x:%04x)\n",
318 bus, device, func, vendorId, deviceId);
319 // XXX: Scan sub-bus
320 } else if (subClass == PCI_SCLASS_BRIDGE_MISC) {
321 kprintf("PCI: (%d,%d,%d) Other Bridge (%04x:%04x)\n",
322 bus, device, func, vendorId, deviceId);
323 }
324 } else if (baseClass == PCI_CLASS_STORAGE) {
325 if (subClass == PCI_SCLASS_STORAGE_SATA) {
326 kprintf("PCI: (%d,%d,%d) SATA Controller (%04x:%04x)\n",
327 bus, device, func, vendorId, deviceId);
328 } else if (subClass == PCI_SCLASS_STORAGE_IDE) {
329 kprintf("PCI: (%d,%d,%d) IDE Controller (%04x:%04x)\n",
330 bus, device, func, vendorId, deviceId);
331 }
332 } else if ((baseClass == PCI_CLASS_NETWORK) && (subClass == 0x00)) {
333 kprintf("PCI: (%d,%d,%d) Ethernet (%04x:%04x)\n",
334 bus, device, func, vendorId, deviceId);
335 } else if ((baseClass == PCI_CLASS_GRAPHICS) && (subClass == 0x00)) {
336 kprintf("PCI: (%d,%d,%d) VGA (%04x:%04x)\n",
337 bus, device, func, vendorId, deviceId);
338 } else if ((baseClass == PCI_CLASS_BUS) && (subClass == PCI_SCLASS_BUS_SMBUS)) {
339 kprintf("PCI: (%d,%d,%d) SMBUS (%04x:%04x)\n",
340 bus, device, func, vendorId, deviceId);
341 } else {
342 kprintf("PCI: (%d,%d,%d) Unsupported (%04x:%04x %02x:%02x)\n",
343 bus, device, func, vendorId, deviceId, baseClass, subClass);
344 }
345}
#define PCI_SCLASS_BUS_SMBUS
Definition: pci.h:42
#define PCI_SCLASS_BRIDGE_PCI
Definition: pci.h:37
#define PCI_SCLASS_BRIDGE_ISA
Definition: pci.h:36
#define PCI_CLASS_NETWORK
Definition: pci.h:27
#define PCI_CLASS_BRIDGE
Definition: pci.h:29
#define PCI_CLASS_BUS
Definition: pci.h:30
#define PCI_SCLASS_BRIDGE_MISC
Definition: pci.h:38
#define PCI_SCLASS_STORAGE_SATA
Definition: pci.h:33
#define PCI_CLASS_STORAGE
Definition: pci.h:26
#define PCI_SCLASS_STORAGE_IDE
Definition: pci.h:32
#define PCI_CLASS_GRAPHICS
Definition: pci.h:28
#define PCI_SCLASS_BRIDGE_HOST
Definition: pci.h:35
unsigned short uint16_t
Definition: types.h:11
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DebugPCIScanBus()

static void DebugPCIScanBus ( uint8_t  bus)
static

Definition at line 348 of file pci.c.

349{
350 uint8_t device;
351 uint8_t headerType;
352 uint16_t vendorId;
353
354 for (device = 0; device < 32; device++) {
355 vendorId = PCIGetVendorID(bus, device, 0);
356 if (vendorId == 0xFFFF)
357 return;
358
359 DebugPCICheckFunction(bus, device, 0);
360
361 headerType = PCIGetHeaderType(bus, device, 0);
362 if ((headerType & 0x80) != 0) {
363 uint8_t func;
364 for (func = 0; func < 8; func++) {
365 if (PCIGetVendorID(bus, device, func) != 0xFFFF) {
366 DebugPCICheckFunction(bus, device, func);
367 }
368 }
369 }
370 }
371}
static void DebugPCICheckFunction(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:299
Here is the call graph for this function:
Here is the caller graph for this function:

◆ E1000_Init()

void E1000_Init ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 168 of file e1000.c.

169{
170 PCIDevice dev;
171
172 dev.bus = bus;
173 dev.slot = slot;
174 dev.func = func;
175 dev.vendor = PCI_GetVendorID(&dev);
176 dev.device = PCI_GetDeviceID(&dev);
177
178 uint32_t device = dev.vendor << 16 | dev.device;
179
180 int deviceIdx = 0;
181 while (deviceList[deviceIdx].device != 0x0) {
182 if (deviceList[deviceIdx].device == device) {
183 kprintf("E1000: Found %s\n", deviceList[deviceIdx].name);
184 // Configure and add disks
185 E1000_Configure(dev);
186 }
187
188 deviceIdx++;
189 }
190}
static E1000Device deviceList[]
Definition: e1000.c:24
void E1000_Configure(PCIDevice dev)
Definition: e1000.c:437
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgRead16()

uint16_t PCI_CfgRead16 ( PCIDevice dev,
uint32_t  reg 
)

Definition at line 71 of file pci.c.

72{
73 return PCICfgRead16(dev->bus, dev->slot, dev->func, reg);
74}
uint16_t PCICfgRead16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgRead32()

uint32_t PCI_CfgRead32 ( PCIDevice dev,
uint32_t  reg 
)

Definition at line 77 of file pci.c.

78{
79 return PCICfgRead32(dev->bus, dev->slot, dev->func, reg);
80}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgRead8()

uint8_t PCI_CfgRead8 ( PCIDevice dev,
uint32_t  reg 
)

Definition at line 65 of file pci.c.

66{
67 return PCICfgRead8(dev->bus, dev->slot, dev->func, reg);
68}
uint8_t PCICfgRead8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
Definition: pci.c:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgWrite16()

void PCI_CfgWrite16 ( PCIDevice dev,
uint32_t  reg,
uint16_t  data 
)

Definition at line 89 of file pci.c.

90{
91 return PCICfgWrite16(dev->bus, dev->slot, dev->func, reg, data);
92}
void PCICfgWrite16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint16_t data)
Definition: pci.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgWrite32()

void PCI_CfgWrite32 ( PCIDevice dev,
uint32_t  reg,
uint32_t  data 
)

Definition at line 95 of file pci.c.

96{
97 return PCICfgWrite32(dev->bus, dev->slot, dev->func, reg, data);
98}
void PCICfgWrite32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint32_t data)
Definition: pci.c:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_CfgWrite8()

void PCI_CfgWrite8 ( PCIDevice dev,
uint32_t  reg,
uint8_t  data 
)

Definition at line 83 of file pci.c.

84{
85 return PCICfgWrite8(dev->bus, dev->slot, dev->func, reg, data);
86}
void PCICfgWrite8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg, uint8_t data)
Definition: pci.c:55
Here is the call graph for this function:

◆ PCI_Configure()

void PCI_Configure ( PCIDevice dev)

Definition at line 249 of file pci.c.

250{
251 int bar;
252
254
257
258 for (bar = 0; bar < PCI_MAX_BARS; bar++)
259 {
260 dev->bars[bar].base = 0;
261 dev->bars[bar].size = 0;
262 dev->bars[bar].type = PCIBAR_TYPE_NULL;
263 }
264
265 for (bar = 0; bar < PCI_MAX_BARS; bar++)
266 {
267 uint32_t barReg = PCI_OFFSET_BARFIRST + 4 * bar;
269 uint32_t origValue = PCI_CfgRead32(dev, barReg);
270
271 PCI_CfgWrite32(dev, barReg, 0xFFFFFFFF);
272 size = PCI_CfgRead32(dev, barReg);
273 if (size == 0)
274 continue;
275
276 PCI_CfgWrite32(dev, barReg, origValue);
277
278 if (origValue & 0x1)
279 {
280 dev->bars[bar].type = PCIBAR_TYPE_IO;
281 base = origValue & 0xFFFFFFFC;
282 size = size & 0xFFFFFFFC;
283 size = ~size + 1;
284 } else {
285 dev->bars[bar].type = PCIBAR_TYPE_MEM;
286 base = origValue & 0xFFFFFFF0;
287 size = size & 0xFFFFFFF0;
288 size = ~size + 1;
289 // XXX: Support 64-bit
290 ASSERT((origValue & 0x06) == 0x00);
291 }
292
293 dev->bars[bar].base = base;
294 dev->bars[bar].size = size;
295 }
296}
void PCI_CfgWrite32(PCIDevice *dev, uint32_t reg, uint32_t data)
Definition: pci.c:95
void PCI_CfgWrite16(PCIDevice *dev, uint32_t reg, uint16_t data)
Definition: pci.c:89
uint32_t PCI_CfgRead32(PCIDevice *dev, uint32_t reg)
Definition: pci.c:77
uint32_t size
Definition: multiboot.h:0
#define PCI_COMMAND_MEMENABLE
Definition: pci.h:21
#define PCI_OFFSET_IRQLINE
Definition: pci.h:18
#define PCIBAR_TYPE_NULL
Definition: pci.h:44
uint8_t irq
Definition: pci.h:64
#define PCIBAR_TYPE_IO
Definition: pci.h:45
#define PCI_COMMAND_BUSMASTER
Definition: pci.h:22
PCIBAR bars[PCI_MAX_BARS]
Definition: pci.h:66
#define PCI_OFFSET_COMMAND
Definition: pci.h:4
uint32_t base
Definition: pci.h:50
#define PCIBAR_TYPE_MEM
Definition: pci.h:46
uint32_t size
Definition: pci.h:51
#define PCI_COMMAND_IOENABLE
Definition: pci.h:20
uint32_t type
Definition: pci.h:52
static uint16_t base
Definition: sercons.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_GetBaseClass()

uint8_t PCI_GetBaseClass ( PCIDevice dev)

Definition at line 113 of file pci.c.

114{
115 return PCI_CfgRead8(dev, PCI_OFFSET_CLASS);
116}
#define PCI_OFFSET_CLASS
Definition: pci.h:9
Here is the call graph for this function:

◆ PCI_GetDeviceID()

uint16_t PCI_GetDeviceID ( PCIDevice dev)

Definition at line 101 of file pci.c.

102{
104}
uint16_t PCI_CfgRead16(PCIDevice *dev, uint32_t reg)
Definition: pci.c:71
#define PCI_OFFSET_DEVICEID
Definition: pci.h:3
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_GetHeaderType()

uint8_t PCI_GetHeaderType ( PCIDevice dev)

Definition at line 125 of file pci.c.

126{
128}
#define PCI_OFFSET_HEADERTYPE
Definition: pci.h:12
Here is the call graph for this function:

◆ PCI_GetSubClass()

uint8_t PCI_GetSubClass ( PCIDevice dev)

Definition at line 119 of file pci.c.

120{
122}
#define PCI_OFFSET_SUBCLASS
Definition: pci.h:8
Here is the call graph for this function:

◆ PCI_GetVendorID()

uint16_t PCI_GetVendorID ( PCIDevice dev)

Definition at line 107 of file pci.c.

108{
110}
#define PCI_OFFSET_VENDORID
Definition: pci.h:2
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCI_Init()

void PCI_Init ( )

Definition at line 27 of file pci.c.

28{
29 kprintf("PCI: Initializing ...\n");
30 PCIScan();
31 kprintf("PCI: Initialization Done!\n");
32}
static void PCIScan()
Definition: pci.c:226
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
uint64_t addr
Definition: multiboot.h:1
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:

◆ PCICheckFunction()

static void PCICheckFunction ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)
static

Definition at line 136 of file pci.c.

137{
138 uint8_t baseClass, subClass;
139 uint16_t vendorId, deviceId;
140
141 baseClass = PCIGetBaseClass(bus, device, func);
142 subClass = PCIGetSubClass(bus, device, func);
143 vendorId = PCIGetVendorID(bus, device, func);
144 deviceId = PCIGetDeviceID(bus, device, func);
145
146 if (baseClass == PCI_CLASS_BRIDGE) {
147 if (subClass == PCI_SCLASS_BRIDGE_HOST) {
148 kprintf("PCI: (%d,%d,%d) Host Bridge (%04x:%04x)\n",
149 bus, device, func, vendorId, deviceId);
150 } else if (subClass == PCI_SCLASS_BRIDGE_ISA) {
151 kprintf("PCI: (%d,%d,%d) ISA Bridge (%04x:%04x)\n",
152 bus, device, func, vendorId, deviceId);
153 } else if (subClass == PCI_SCLASS_BRIDGE_PCI) {
154 kprintf("PCI: (%d,%d,%d) PCI-PCI Bridge (%04x:%04x)\n",
155 bus, device, func, vendorId, deviceId);
156 // Scan sub-bus
157 } else if (subClass == PCI_SCLASS_BRIDGE_MISC) {
158 kprintf("PCI: (%d,%d,%d) Other Bridge (%04x:%04x)\n",
159 bus, device, func, vendorId, deviceId);
160 }
161 } else if (baseClass == PCI_CLASS_STORAGE) {
162 if (subClass == PCI_SCLASS_STORAGE_SATA) {
163 kprintf("PCI: (%d,%d,%d) SATA Controller (%04x:%04x)\n",
164 bus, device, func, vendorId, deviceId);
165
166 AHCI_Init(bus, device, func);
167 } else if (subClass == PCI_SCLASS_STORAGE_IDE) {
168 kprintf("PCI: (%d,%d,%d) IDE Controller (%04x:%04x)\n",
169 bus, device, func, vendorId, deviceId);
170 }
171 } else if ((baseClass == PCI_CLASS_NETWORK) && (subClass == 0x00)) {
172 kprintf("PCI: (%d,%d,%d) Ethernet (%04x:%04x)\n",
173 bus, device, func, vendorId, deviceId);
174 E1000_Init(bus, device, func);
175 } else if ((baseClass == PCI_CLASS_GRAPHICS) && (subClass == 0x00)) {
176 kprintf("PCI: (%d,%d,%d) VGA (%04x:%04x)\n",
177 bus, device, func, vendorId, deviceId);
178 } else if ((baseClass == PCI_CLASS_BUS) && (subClass == PCI_SCLASS_BUS_SMBUS)) {
179 kprintf("PCI: (%d,%d,%d) SMBUS (%04x:%04x)\n",
180 bus, device, func, vendorId, deviceId);
181 } else {
182 kprintf("PCI: (%d,%d,%d) Unsupported (%04x:%04x %02x:%02x)\n",
183 bus, device, func, vendorId, deviceId, baseClass, subClass);
184 }
185}
void AHCI_Init(uint32_t bus, uint32_t device, uint32_t func)
Definition: ahci.c:183
void E1000_Init(uint32_t bus, uint32_t device, uint32_t func)
Definition: e1000.c:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetBaseClass()

uint8_t PCIGetBaseClass ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 47 of file pci.c.

48{
49 return PCICfgRead8(bus, device, func, PCI_OFFSET_CLASS);
50}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetDeviceID()

uint16_t PCIGetDeviceID ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 35 of file pci.c.

36{
37 return PCICfgRead16(bus, device, func, PCI_OFFSET_DEVICEID);
38}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetHeaderType()

uint8_t PCIGetHeaderType ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 59 of file pci.c.

60{
61 return PCICfgRead8(bus, device, func, PCI_OFFSET_HEADERTYPE);
62}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetSubClass()

uint8_t PCIGetSubClass ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 53 of file pci.c.

54{
55 return PCICfgRead8(bus, device, func, PCI_OFFSET_SUBCLASS);
56}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIGetVendorID()

uint16_t PCIGetVendorID ( uint32_t  bus,
uint32_t  device,
uint32_t  func 
)

Definition at line 41 of file pci.c.

42{
43 return PCICfgRead16(bus, device, func, PCI_OFFSET_VENDORID);
44}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIScan()

static void PCIScan ( )
static

Definition at line 226 of file pci.c.

227{
228 uint8_t headerType = PCIGetHeaderType(0, 0, 0);
229
230 if ((headerType & 0x80) == 0) {
231 PCIScanBus(0);
232 } else {
233 uint8_t busNo;
234
235 for (busNo = 0; busNo < 8; busNo++) {
236 if (PCIGetVendorID(0, 0, busNo) != 0xFFFF)
237 break;
238 PCIScanBus(busNo);
239 }
240 }
241}
static void PCIScanBus(uint8_t bus)
Definition: pci.c:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIScanBus()

static void PCIScanBus ( uint8_t  bus)
static

Definition at line 211 of file pci.c.

212{
213 uint8_t device;
214
215 for (device = 0; device < 32; device++) {
216 PCIScanDevice(bus, device);
217 }
218}
static void PCIScanDevice(uint32_t bus, uint32_t device)
Definition: pci.c:188
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCIScanDevice()

static void PCIScanDevice ( uint32_t  bus,
uint32_t  device 
)
static

Definition at line 188 of file pci.c.

189{
190 uint8_t headerType;
191 uint16_t vendorId;
192
193 vendorId = PCIGetVendorID(bus, device, 0);
194 if (vendorId == 0xFFFF)
195 return;
196
197 PCICheckFunction(bus, device, 0);
198
199 headerType = PCIGetHeaderType(bus, device, 0);
200 if ((headerType & 0x80) != 0) {
201 uint8_t func;
202 for (func = 0; func < 8; func++) {
203 if (PCIGetVendorID(bus, device, func) != 0xFFFF) {
204 PCICheckFunction(bus, device, func);
205 }
206 }
207 }
208}
static void PCICheckFunction(uint32_t bus, uint32_t device, uint32_t func)
Definition: pci.c:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ REGISTER_DBGCMD() [1/2]

REGISTER_DBGCMD ( pcidump  ,
"PCI Device Dump"  ,
Debug_PCIDump   
)

◆ REGISTER_DBGCMD() [2/2]

REGISTER_DBGCMD ( pcilist  ,
"PCI Device List"  ,
Debug_PCIList   
)