blob: f5fc953e584832901a6f45cd130f29a321c6b280 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Andi Kleen8f607742006-09-26 10:52:41 +02002#include <linux/kernel.h>
Andi Kleen0637a702006-09-26 10:52:41 +02003#include <linux/pci.h>
Andi Kleen8f607742006-09-26 10:52:41 +02004#include <asm/pci-direct.h>
5#include <asm/io.h>
Jaswinder Singh Rajput82487712008-12-27 18:32:28 +05306#include <asm/pci_x86.h>
Andi Kleen8f607742006-09-26 10:52:41 +02007
8/* Direct PCI access. This is used for PCI accesses in early boot before
9 the PCI subsystem works. */
10
Andi Kleen8f607742006-09-26 10:52:41 +020011u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset)
12{
13 u32 v;
14 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
15 v = inl(0xcfc);
Andi Kleen8f607742006-09-26 10:52:41 +020016 return v;
17}
18
19u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset)
20{
21 u8 v;
22 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
23 v = inb(0xcfc + (offset&3));
Andi Kleen8f607742006-09-26 10:52:41 +020024 return v;
25}
26
27u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset)
28{
29 u16 v;
30 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
31 v = inw(0xcfc + (offset&2));
Andi Kleen8f607742006-09-26 10:52:41 +020032 return v;
33}
34
35void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset,
36 u32 val)
37{
Andi Kleen8f607742006-09-26 10:52:41 +020038 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
39 outl(val, 0xcfc);
40}
Andi Kleen0637a702006-09-26 10:52:41 +020041
Siddha, Suresh B274e1bb2006-12-07 02:14:10 +010042void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val)
43{
Siddha, Suresh B274e1bb2006-12-07 02:14:10 +010044 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
Yinghai Lue7891c72008-05-22 14:35:21 -070045 outb(val, 0xcfc + (offset&3));
46}
47
48void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val)
49{
Yinghai Lue7891c72008-05-22 14:35:21 -070050 outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
51 outw(val, 0xcfc + (offset&2));
Siddha, Suresh B274e1bb2006-12-07 02:14:10 +010052}
53
Andi Kleen0637a702006-09-26 10:52:41 +020054int early_pci_allowed(void)
55{
56 return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
57 PCI_PROBE_CONF1;
58}
Yinghai Lue3f2bae2008-05-22 14:35:11 -070059