Skip to content

Commit

Permalink
pci: disable bus mastering, I/O and mem access before reading BARs
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 committed Jun 19, 2023
1 parent 13caf34 commit f7854a7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <stddef.h>

void lil_get_bar(void* device, int bar, uintptr_t* obase, uintptr_t* len) {
/* disable Bus Mastering and Memory + I/O space access */
uint16_t command = lil_pci_readw(device, 4);
lil_pci_writew(device, 4, command & ~7); /* Bus Master | Memory Space | I/O Space */

size_t reg_index = 0x10 + bar * 4;
uint64_t bar_low = lil_pci_readd(device, reg_index), bar_size_low;
uint64_t bar_high = 0, bar_size_high = ~0;
Expand Down Expand Up @@ -35,4 +39,7 @@ void lil_get_bar(void* device, int bar, uintptr_t* obase, uintptr_t* len) {

*obase = base;
*len = size;

/* restore Bus Mastering and Memory + I/O space access */
lil_pci_writew(device, 4, command);
}

0 comments on commit f7854a7

Please sign in to comment.