Skip to content

Commit 74c2d24

Browse files
committed
pci: learn to code
1 parent 1f93de1 commit 74c2d24

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/kernel/pci.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@ void pci_enumerate() {
1212
uaddr lo, hi;
1313
struct vma *vma;
1414

15-
/* lol */
16-
uaddr base = 0;
17-
for (u64 i=0; i<32; ++i) {
18-
vma = vma_alloc(&kernel_virtual_allocator, 1);
19-
assert(vma);
15+
vma = vma_alloc(&kernel_virtual_allocator, 32);
16+
assert(vma);
2017

21-
vma_bounds(vma, &lo, &hi);
22-
mm_paging_map(lo, paddr_of_bits(pci_config + i * 0x1000), PGPERM_KRW);
18+
vma_bounds(vma, &lo, &hi);
2319

24-
if (base == 0) base = lo;
20+
for (u64 i=0; i<32; ++i) {
21+
mm_paging_map(lo + i * 0x1000, paddr_of_bits(pci_config + i * 0x1000), PGPERM_KRW);
2522
}
2623
for (u64 dev=0; dev<32; ++dev) {
2724
u64 bus = 0;
2825
u64 func = 0;
2926
u64 offset = 0;
3027
offset = (bus << 16) | (dev << 11) | (func << 8) | (offset);
31-
struct pci_device *device = (struct pci_device *)(base + offset);
28+
struct pci_device *device = (struct pci_device *)(lo + offset);
3229

3330
u16 did = device->did;
3431
u16 vid = device->vid;

0 commit comments

Comments
 (0)