Commit fbbc8548 authored by Guilherme G. Piccoli's avatar Guilherme G. Piccoli Committed by Khalid Elmously

UBUNTU: SAUCE: x86/PCI: Export find_cap() to be used in early PCI code

BugLink: https://bugs.launchpad.net/bugs/1797990

This patch exports (and renames) the function find_cap() to be used
in the early PCI quirk code, by the next patch.

This is being moved out from AGP code to generic early-PCI code
since it's not AGP-specific and can be used for any PCI device.
No functional changes intended.
Signed-off-by: default avatarGuilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: default avatarMauricio Faria de Oliveira <mfo@canonical.com>
Acked-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Acked-by: default avatarThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 8b82ddf1
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
extern u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset); extern u32 read_pci_config(u8 bus, u8 slot, u8 func, u8 offset);
extern u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset); extern u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset);
extern u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset); extern u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset);
extern u32 pci_early_find_cap(int bus, int slot, int func, int cap);
extern void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, u32 val); extern void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, u32 val);
extern void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val); extern void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val);
extern void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val); extern void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val);
......
...@@ -91,32 +91,6 @@ static u32 __init allocate_aperture(void) ...@@ -91,32 +91,6 @@ static u32 __init allocate_aperture(void)
} }
/* Find a PCI capability */
static u32 __init find_cap(int bus, int slot, int func, int cap)
{
int bytes;
u8 pos;
if (!(read_pci_config_16(bus, slot, func, PCI_STATUS) &
PCI_STATUS_CAP_LIST))
return 0;
pos = read_pci_config_byte(bus, slot, func, PCI_CAPABILITY_LIST);
for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
u8 id;
pos &= ~3;
id = read_pci_config_byte(bus, slot, func, pos+PCI_CAP_LIST_ID);
if (id == 0xff)
break;
if (id == cap)
return pos;
pos = read_pci_config_byte(bus, slot, func,
pos+PCI_CAP_LIST_NEXT);
}
return 0;
}
/* Read a standard AGPv3 bridge header */ /* Read a standard AGPv3 bridge header */
static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order) static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order)
{ {
...@@ -205,8 +179,8 @@ static u32 __init search_agp_bridge(u32 *order, int *valid_agp) ...@@ -205,8 +179,8 @@ static u32 __init search_agp_bridge(u32 *order, int *valid_agp)
case PCI_CLASS_BRIDGE_HOST: case PCI_CLASS_BRIDGE_HOST:
case PCI_CLASS_BRIDGE_OTHER: /* needed? */ case PCI_CLASS_BRIDGE_OTHER: /* needed? */
/* AGP bridge? */ /* AGP bridge? */
cap = find_cap(bus, slot, func, cap = pci_early_find_cap(bus, slot,
PCI_CAP_ID_AGP); func, PCI_CAP_ID_AGP);
if (!cap) if (!cap)
break; break;
*valid_agp = 1; *valid_agp = 1;
......
...@@ -50,6 +50,31 @@ void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val) ...@@ -50,6 +50,31 @@ void write_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset, u16 val)
outw(val, 0xcfc + (offset&2)); outw(val, 0xcfc + (offset&2));
} }
u32 pci_early_find_cap(int bus, int slot, int func, int cap)
{
int bytes;
u8 pos;
if (!(read_pci_config_16(bus, slot, func, PCI_STATUS) &
PCI_STATUS_CAP_LIST))
return 0;
pos = read_pci_config_byte(bus, slot, func, PCI_CAPABILITY_LIST);
for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
u8 id;
pos &= ~3;
id = read_pci_config_byte(bus, slot, func, pos+PCI_CAP_LIST_ID);
if (id == 0xff)
break;
if (id == cap)
return pos;
pos = read_pci_config_byte(bus, slot, func,
pos+PCI_CAP_LIST_NEXT);
}
return 0;
}
int early_pci_allowed(void) int early_pci_allowed(void)
{ {
return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) == return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment