1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2fb9aa6f1SThomas Gleixner #include <linux/kernel.h>
3fb9aa6f1SThomas Gleixner #include <linux/pci.h>
4fb9aa6f1SThomas Gleixner #include <asm/pci-direct.h>
5fb9aa6f1SThomas Gleixner #include <asm/io.h>
682487711SJaswinder Singh Rajput #include <asm/pci_x86.h>
7fb9aa6f1SThomas Gleixner
8fb9aa6f1SThomas Gleixner /* Direct PCI access. This is used for PCI accesses in early boot before
9fb9aa6f1SThomas Gleixner the PCI subsystem works. */
10fb9aa6f1SThomas Gleixner
read_pci_config(u8 bus,u8 slot,u8 func,u8 offset)11fb9aa6f1SThomas Gleixner u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset)
12fb9aa6f1SThomas Gleixner {
13fb9aa6f1SThomas Gleixner u32 v;
14fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
15fb9aa6f1SThomas Gleixner v = inl(0xcfc);
16fb9aa6f1SThomas Gleixner return v;
17fb9aa6f1SThomas Gleixner }
18fb9aa6f1SThomas Gleixner
read_pci_config_byte(u8 bus,u8 slot,u8 func,u8 offset)19fb9aa6f1SThomas Gleixner u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset)
20fb9aa6f1SThomas Gleixner {
21fb9aa6f1SThomas Gleixner u8 v;
22fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
23fb9aa6f1SThomas Gleixner v = inb(0xcfc + (offset&3));
24fb9aa6f1SThomas Gleixner return v;
25fb9aa6f1SThomas Gleixner }
26fb9aa6f1SThomas Gleixner
read_pci_config_16(u8 bus,u8 slot,u8 func,u8 offset)27fb9aa6f1SThomas Gleixner u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset)
28fb9aa6f1SThomas Gleixner {
29fb9aa6f1SThomas Gleixner u16 v;
30fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
31fb9aa6f1SThomas Gleixner v = inw(0xcfc + (offset&2));
32fb9aa6f1SThomas Gleixner return v;
33fb9aa6f1SThomas Gleixner }
34fb9aa6f1SThomas Gleixner
write_pci_config(u8 bus,u8 slot,u8 func,u8 offset,u32 val)35fb9aa6f1SThomas Gleixner void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset,
36fb9aa6f1SThomas Gleixner u32 val)
37fb9aa6f1SThomas Gleixner {
38fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
39fb9aa6f1SThomas Gleixner outl(val, 0xcfc);
40fb9aa6f1SThomas Gleixner }
41fb9aa6f1SThomas Gleixner
write_pci_config_byte(u8 bus,u8 slot,u8 func,u8 offset,u8 val)42fb9aa6f1SThomas Gleixner void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val)
43fb9aa6f1SThomas Gleixner {
44fb9aa6f1SThomas Gleixner outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
45e7891c73SYinghai Lu outb(val, 0xcfc + (offset&3));
46e7891c73SYinghai Lu }
47e7891c73SYinghai Lu
write_pci_config_16(u8 bus,u8 slot,u8 func,u8 offset,u16 val)48e7891c73SYinghai Lu void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val)
49e7891c73SYinghai Lu {
50e7891c73SYinghai Lu outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
51e7891c73SYinghai Lu outw(val, 0xcfc + (offset&2));
52fb9aa6f1SThomas Gleixner }
53fb9aa6f1SThomas Gleixner
early_pci_allowed(void)54fb9aa6f1SThomas Gleixner int early_pci_allowed(void)
55fb9aa6f1SThomas Gleixner {
56fb9aa6f1SThomas Gleixner return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
57fb9aa6f1SThomas Gleixner PCI_PROBE_CONF1;
58fb9aa6f1SThomas Gleixner }
59e3f2baebSYinghai Lu
60