-
Notifications
You must be signed in to change notification settings - Fork 0
/
pciconf.c
37 lines (31 loc) · 871 Bytes
/
pciconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Read PCI Config space v20141121
* Repurposed for kernel driver
* v20180106
* HanishKVC
*/
#include "pciconf.h"
struct resource *pResPCIConf;
int pciconf_init(void)
{
pResPCIConf = request_region(PCIIOCAM_CONFIGADDR, 0x8, HELPERMODULE_NAME);
if (pResPCIConf == NULL) {
printk(KERN_ALERT HELPERMODULE_NAME "pciconf iocam: Failed to get access");
return -1;
}
printk(KERN_INFO HELPERMODULE_NAME "pciconf iocam: got access");
return 0;
}
uint32_t pciconf_read32(uint32_t bus, uint32_t dev, uint32_t func, uint32_t offset)
{
uint32_t baseAddr, addr;
baseAddr = ((bus & 0xFF) << 16) | ((dev & 0x1F) << 11) | ((func & 0x06) << 8);
baseAddr |= ENABLE_PCI_CONFIGSPACE_MAPPING;
addr = baseAddr + offset;
outl_p(addr, PCIIOCAM_CONFIGADDR);
return inl_p(PCIIOCAM_CONFIGDATA);
}
void pciconf_release(void)
{
release_region(PCIIOCAM_CONFIGADDR, 0x8);
}