summaryrefslogtreecommitdiff
path: root/payloads/libpayload/drivers/pci_map_bus_ops.c
blob: 2b4f9d159a951b208724000d93745c06ffb26ab6 (plain)
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
37
38
39
40
41
42
43
44
45
46
/* SPDX-License-Identifier: GPL-2.0-only */

#include <libpayload.h>
#include <pci.h>

u8 pci_read_config8(pcidev_t dev, u16 reg)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	return read8((void *)(cfg_base | reg));
}

u16 pci_read_config16(pcidev_t dev, u16 reg)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	return read16((void *)(cfg_base | (reg & ~1)));
}

u32 pci_read_config32(pcidev_t dev, u16 reg)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	return read32((void *)(cfg_base | (reg & ~3)));
}

void pci_write_config8(pcidev_t dev, u16 reg, u8 val)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	write8((void *)(cfg_base | reg), val);
}

void pci_write_config16(pcidev_t dev, u16 reg, u16 val)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	write16((void *)(cfg_base | (reg & ~1)), val);
}

void pci_write_config32(pcidev_t dev, u16 reg, u32 val)
{
	uintptr_t cfg_base = pci_map_bus(dev);

	write32((void *)(cfg_base | (reg & ~3)), val);
}