Skip to content

Commit 48df598

Browse files
fix the e1000 supported list and massively improve speed of pci bus scanning
1 parent d967c1a commit 48df598

File tree

4 files changed

+132
-63
lines changed

4 files changed

+132
-63
lines changed

modules/e1000/e1000.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,43 @@ void init_e1000() {
406406

407407
// Try supported devices only
408408
const uint16_t supported[] = {
409+
E1000_82542,
410+
E1000_82543GC_F,
411+
E1000_82543GC_C,
412+
E1000_82544EI_C,
413+
E1000_82544EI_F,
414+
E1000_82544GC_C,
415+
E1000_82544GC_L,
409416
E1000_82540EM,
417+
E1000_82545EM_C,
418+
E1000_82546EB_C,
419+
E1000_82545EM_F,
420+
E1000_82546EB_F,
421+
E1000_82541EI,
422+
E1000_82541ER_L,
423+
E1000_82540EM_L,
424+
E1000_82540EP_L,
425+
E1000_82540EP,
426+
E1000_82541EI_M,
427+
E1000_82547EI,
428+
E1000_82547EI_M,
429+
E1000_82546EB_QC,
430+
E1000_82540EP_L2,
431+
E1000_82545GM_C,
432+
E1000_82545GM_F,
433+
E1000_82545GM_S,
434+
E1000_82547GI,
435+
E1000_82541GI,
436+
E1000_82541GI_M,
437+
E1000_82541ER,
438+
E1000_82546GB_C,
439+
E1000_82546GB_F,
440+
E1000_82546GB_S,
410441
E1000_82541PI,
411-
E1000_82577LM,
412-
E1000_I217,
413-
E1000_82567LM,
414-
E1000_82567LM_2,
415-
E1000_82567LM_3,
416-
E1000_82574L,
417-
E1000_82579LM,
418-
E1000_82583V,
419-
E1000_I218LM,
420-
E1000_I219LM,
442+
E1000_82546GB_P,
443+
E1000_82546GB_QC,
444+
E1000_82546GB_QC_3,
445+
E1000_CE4100_GBE,
421446
};
422447
for (size_t i = 0; i < sizeof(supported) / sizeof(supported[0]); i++) {
423448
pci_device = pci_get_device(INTEL_VEND, supported[i], -1);

modules/e1000/e1000.h

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,44 @@
88
#include <kernel.h>
99

1010
#define INTEL_VEND (uint32_t)0x8086 /* Vendor ID for Intel */
11-
#define E1000_82540EM (uint32_t)0x100E /* Device ID for the e1000 Qemu, Bochs, and VirtualBox emulated NICs */
12-
#define E1000_I217 (uint32_t)0x153A /* Device ID for Intel I217 */
13-
#define E1000_82577LM (uint32_t)0x10EA /* Device ID for Intel 82577LM */
14-
#define E1000_82541PI (uint32_t)0x107C /* Device ID for Intel 82541PI */
15-
#define E1000_82567LM (uint32_t)0x10F5 /* Device ID for Intel 82567LM */
16-
#define E1000_82567LM_2 (uint32_t)0x10CC /* Device ID for Intel 82567LM v2 */
17-
#define E1000_82567LM_3 (uint32_t)0x10DE /* Device ID for Intel 82567LM v3 */
18-
#define E1000_82574L (uint32_t)0x10D3 /* Intel 82574L PCIe Gigabit Controller */
19-
#define E1000_82579LM (uint32_t)0x1502 /* Intel 82579LM PCH-LAN Controller */
20-
#define E1000_82583V (uint32_t)0x150C /* Intel 82583V PCIe Gigabit Controller */
21-
#define E1000_I218LM (uint32_t)0x15A2 /* Intel I218-LM PCH-LAN Controller */
22-
#define E1000_I219LM (uint32_t)0x15E3 /* Intel I219-LM PCH-LAN Controller */
11+
#define E1000_82542 (uint32_t)0x1000
12+
#define E1000_82543GC_F (uint32_t)0x1001
13+
#define E1000_82543GC_C (uint32_t)0x1004
14+
#define E1000_82544EI_C (uint32_t)0x1008
15+
#define E1000_82544EI_F (uint32_t)0x1009
16+
#define E1000_82544GC_C (uint32_t)0x100C
17+
#define E1000_82544GC_L (uint32_t)0x100D
18+
#define E1000_82540EM (uint32_t)0x100E /* Device ID for the e1000 Qemu, Bochs, and VirtualBox emulated NICs */
19+
#define E1000_82545EM_C (uint32_t)0x100F
20+
#define E1000_82546EB_C (uint32_t)0x1010
21+
#define E1000_82545EM_F (uint32_t)0x1011
22+
#define E1000_82546EB_F (uint32_t)0x1012
23+
#define E1000_82541EI (uint32_t)0x1013
24+
#define E1000_82541ER_L (uint32_t)0x1014
25+
#define E1000_82540EM_L (uint32_t)0x1015
26+
#define E1000_82540EP_L (uint32_t)0x1016
27+
#define E1000_82540EP (uint32_t)0x1017
28+
#define E1000_82541EI_M (uint32_t)0x1018
29+
#define E1000_82547EI (uint32_t)0x1019
30+
#define E1000_82547EI_M (uint32_t)0x101A
31+
#define E1000_82546EB_QC (uint32_t)0x101D
32+
#define E1000_82540EP_L2 (uint32_t)0x101E
33+
#define E1000_82545GM_C (uint32_t)0x1026
34+
#define E1000_82545GM_F (uint32_t)0x1027
35+
#define E1000_82545GM_S (uint32_t)0x1028
36+
#define E1000_82547GI (uint32_t)0x1075
37+
#define E1000_82541GI (uint32_t)0x1076
38+
#define E1000_82541GI_M (uint32_t)0x1077
39+
#define E1000_82541ER (uint32_t)0x1078
40+
#define E1000_82546GB_C (uint32_t)0x1079
41+
#define E1000_82546GB_F (uint32_t)0x107A
42+
#define E1000_82546GB_S (uint32_t)0x107B
43+
#define E1000_82541PI (uint32_t)0x107C /* Device ID for Intel 82541PI */
44+
#define E1000_82546GB_P (uint32_t)0x108A
45+
#define E1000_82546GB_QC (uint32_t)0x1099
46+
#define E1000_82546GB_QC_3 (uint32_t)0x10B5
47+
#define E1000_CE4100_GBE (uint32_t)0x2E6E
48+
2349

2450

2551
#define REG_CTRL 0x0000

os/system/config/loadorder.conf

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,43 @@
2121

2222
[net]
2323
1AF4 1041 * virtio_net
24+
8086 1000 * e1000
25+
8086 1001 * e1000
26+
8086 1004 * e1000
27+
8086 1008 * e1000
28+
8086 1009 * e1000
29+
8086 100C * e1000
30+
8086 100D * e1000
2431
8086 100E * e1000
32+
8086 100F * e1000
33+
8086 1010 * e1000
34+
8086 1011 * e1000
35+
8086 1012 * e1000
36+
8086 1013 * e1000
37+
8086 1014 * e1000
38+
8086 1015 * e1000
39+
8086 1016 * e1000
40+
8086 1017 * e1000
41+
8086 1018 * e1000
42+
8086 1019 * e1000
43+
8086 101A * e1000
44+
8086 101D * e1000
45+
8086 101E * e1000
46+
8086 1026 * e1000
47+
8086 1027 * e1000
48+
8086 1028 * e1000
49+
8086 1075 * e1000
50+
8086 1076 * e1000
51+
8086 1077 * e1000
52+
8086 1078 * e1000
53+
8086 1079 * e1000
54+
8086 107A * e1000
55+
8086 107B * e1000
2556
8086 107C * e1000
26-
8086 153A * e1000
27-
8086 10EA * e1000
28-
8086 10F5 * e1000
29-
8086 10CC * e1000
30-
8086 10DE * e1000
31-
8086 10D3 * e1000
32-
8086 1502 * e1000
33-
8086 150C * e1000
34-
8086 15A2 * e1000
35-
8086 15E3 * e1000
57+
8086 108A * e1000
58+
8086 1099 * e1000
59+
8086 10B5 * e1000
60+
8086 2E6E * e1000
3661
10EC 8139 * rtl8139
3762

3863
[sound]

src/pci.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -473,70 +473,63 @@ pci_dev_t pci_scan_device(uint16_t vendor_id, uint16_t device_id, uint32_t bus,
473473
return dev_zero;
474474
}
475475

476-
/*
477-
* Scan bus
478-
*/
479476
static bool visited_buses[256] = { false };
477+
static bool pci_scanned_once = false;
480478

481479
pci_dev_t pci_scan_bus(uint16_t vendor_id, uint16_t device_id, uint32_t bus, int device_type) {
482480
if (visited_buses[bus]) {
483481
return dev_zero;
484482
}
485483
visited_buses[bus] = true;
486484

487-
pci_dev_t found = dev_zero;
488-
489485
for (int device = 0; device < DEVICE_PER_BUS; device++) {
490486
pci_dev_t dev = pci_scan_device(vendor_id, device_id, bus, device, device_type);
491487

492-
// Track if this is the specific device being searched for
493-
if (!pci_not_found(dev) &&
494-
(vendor_id != 0 || device_id != 0 || device_type != -1)) {
488+
if (!pci_not_found(dev) && (vendor_id != 0 || device_id != 0 || device_type != -1)) {
495489
uint32_t vend = pci_read(dev, PCI_VENDOR_ID);
496490
uint32_t devid = pci_read(dev, PCI_DEVICE_ID);
497-
uint32_t type = get_device_type(dev);
491+
uint32_t type = get_device_type(dev);
498492

499493
if ((vendor_id == 0 || vend == vendor_id) &&
500-
(device_id == 0 || devid == device_id) &&
501-
(device_type == -1 || type == (uint32_t)device_type)) {
502-
found = dev;
494+
(device_id == 0 || devid == device_id) &&
495+
(device_type == -1 || type == (uint32_t)device_type)) {
496+
return dev; /* early hit */
503497
}
504498
}
505499
}
506-
507-
return found;
500+
return dev_zero;
508501
}
509502

503+
pci_dev_t pci_get_device(uint16_t vendor_id, uint16_t device_id, int device_type) {
504+
if (!pci_scanned_once) {
505+
memset(visited_buses, 0, sizeof(visited_buses));
506+
device_total = 0;
510507

511-
/*
512-
* Device driver use this function to get its device object(given unique vendor id and device id)
513-
*/
514-
pci_dev_t pci_get_device(uint16_t vendor_id, uint16_t device_id, int device_type)
515-
{
516-
memset(visited_buses, 0, sizeof(visited_buses));
517-
device_total = 0;
518-
519-
for (int bus = 0; bus < 256; ++bus) {
520-
pci_scan_bus(vendor_id, device_id, bus, -1);
508+
for (int bus = 0; bus < 256; ++bus) {
509+
pci_dev_t cand = pci_scan_bus(vendor_id, device_id, bus, device_type);
510+
if (!pci_not_found(cand)) {
511+
pci_scanned_once = true;
512+
return cand;
513+
}
514+
}
515+
pci_scanned_once = true;
521516
}
522517

523-
// Now loop through and find matching device
524518
for (size_t i = 0; i < device_total; ++i) {
525519
uint32_t vendid = pci_read(device_list[i], PCI_VENDOR_ID);
526-
uint32_t devid = pci_read(device_list[i], PCI_DEVICE_ID);
527-
uint32_t type = get_device_type(device_list[i]);
520+
uint32_t devid = pci_read(device_list[i], PCI_DEVICE_ID);
521+
uint32_t type = get_device_type(device_list[i]);
528522

529523
if ((vendor_id == 0 || vendor_id == vendid) &&
530-
(device_id == 0 || device_id == devid) &&
531-
(device_type == -1 || device_type == (int)type)) {
524+
(device_id == 0 || device_id == devid) &&
525+
(device_type == -1 || device_type == (int)type)) {
532526
return device_list[i];
533527
}
534528
}
535529
return dev_zero;
536530
}
537531

538-
pci_dev_t pci_get_best(uint16_t vendor_id, uint16_t device_id, int device_type, pci_score_fn score, void *ctx)
539-
{
532+
pci_dev_t pci_get_best(uint16_t vendor_id, uint16_t device_id, int device_type, pci_score_fn score, void *ctx) {
540533
memset(visited_buses, 0, sizeof(visited_buses));
541534
device_total = 0;
542535

0 commit comments

Comments
 (0)