Commit 01f94c4a authored by David S. Miller's avatar David S. Miller Committed by David S. Miller

[SPARC64]: Fix sabre pci controllers with new probing scheme.

The SIMBA APB bridge is strange, it is a PCI bridge but it lacks
some standard OF properties, in particular it lacks a 'ranges'
property.

What you have to do is read the IO and MEM range registers in
the APB bridge to determine the ranges handled by each bridge.
So fill in the bus resources by doing that.

Since we now handle this quirk in the generic PCI and OF device
probing layers, we can flat out eliminate all of that code from
the sabre pci controller driver.

In fact we can thus eliminate completely another quirk of the sabre
driver.  It tried to make the two APB bridges look like PBMs but that
makes zero sense now (and it's questionable whether it ever made sense).
So now just use pbm_A and probe the whole PCI hierarchy using that as
the root.

This simplification allows many future cleanups to occur.

Also, I've found yet another quirk that needs to be worked around
while testing this.  You can't use the 'class-code' OF firmware
property, especially for IDE controllers.  We have to read the value
out of PCI config space or else we'll see the value the device was
showing before it was programmed into native mode.

I'm starting to think it might be wise to just read all of the values
out of PCI config space instead of using the OF properties. :-/
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a378fd0e
...@@ -317,6 +317,11 @@ static unsigned int of_bus_default_get_flags(const u32 *addr) ...@@ -317,6 +317,11 @@ static unsigned int of_bus_default_get_flags(const u32 *addr)
static int of_bus_pci_match(struct device_node *np) static int of_bus_pci_match(struct device_node *np)
{ {
if (!strcmp(np->type, "pci") || !strcmp(np->type, "pciex")) { if (!strcmp(np->type, "pci") || !strcmp(np->type, "pciex")) {
char *model = of_get_property(np, "model", NULL);
if (model && !strcmp(model, "SUNW,simba"))
return 0;
/* Do not do PCI specific frobbing if the /* Do not do PCI specific frobbing if the
* PCI bridge lacks a ranges property. We * PCI bridge lacks a ranges property. We
* want to pass it through up to the next * want to pass it through up to the next
...@@ -332,6 +337,21 @@ static int of_bus_pci_match(struct device_node *np) ...@@ -332,6 +337,21 @@ static int of_bus_pci_match(struct device_node *np)
return 0; return 0;
} }
static int of_bus_simba_match(struct device_node *np)
{
char *model = of_get_property(np, "model", NULL);
if (model && !strcmp(model, "SUNW,simba"))
return 1;
return 0;
}
static int of_bus_simba_map(u32 *addr, const u32 *range,
int na, int ns, int pna)
{
return 0;
}
static void of_bus_pci_count_cells(struct device_node *np, static void of_bus_pci_count_cells(struct device_node *np,
int *addrc, int *sizec) int *addrc, int *sizec)
{ {
...@@ -436,6 +456,15 @@ static struct of_bus of_busses[] = { ...@@ -436,6 +456,15 @@ static struct of_bus of_busses[] = {
.map = of_bus_pci_map, .map = of_bus_pci_map,
.get_flags = of_bus_pci_get_flags, .get_flags = of_bus_pci_get_flags,
}, },
/* SIMBA */
{
.name = "simba",
.addr_prop_name = "assigned-addresses",
.match = of_bus_simba_match,
.count_cells = of_bus_pci_count_cells,
.map = of_bus_simba_map,
.get_flags = of_bus_pci_get_flags,
},
/* SBUS */ /* SBUS */
{ {
.name = "sbus", .name = "sbus",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <asm/ebus.h> #include <asm/ebus.h>
#include <asm/isa.h> #include <asm/isa.h>
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/apb.h>
#include "pci_impl.h" #include "pci_impl.h"
...@@ -372,6 +373,7 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, ...@@ -372,6 +373,7 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
struct dev_archdata *sd; struct dev_archdata *sd;
struct pci_dev *dev; struct pci_dev *dev;
const char *type; const char *type;
u32 class;
dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL); dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
if (!dev) if (!dev)
...@@ -409,7 +411,15 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, ...@@ -409,7 +411,15 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus), sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
dev->class = of_getintprop_default(node, "class-code", 0);
/* dev->class = of_getintprop_default(node, "class-code", 0); */
/* We can't actually use the firmware value, we have to read what
* is in the register right now. One reason is that in the case
* of IDE interfaces the firmware can sample the value before the
* the IDE interface is programmed into native mode.
*/
pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
dev->class = class >> 8;
printk(" class: 0x%x\n", dev->class); printk(" class: 0x%x\n", dev->class);
...@@ -440,6 +450,53 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, ...@@ -440,6 +450,53 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
return dev; return dev;
} }
static void __init apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
{
u32 idx, first, last;
first = 8;
last = 0;
for (idx = 0; idx < 8; idx++) {
if ((map & (1 << idx)) != 0) {
if (first > idx)
first = idx;
if (last < idx)
last = idx;
}
}
*first_p = first;
*last_p = last;
}
/* Cook up fake bus resources for SUNW,simba PCI bridges which lack
* a proper 'ranges' property.
*/
static void __init apb_fake_ranges(struct pci_dev *dev,
struct pci_bus *bus,
struct pci_pbm_info *pbm)
{
struct resource *res;
u32 first, last;
u8 map;
pci_read_config_byte(dev, APB_IO_ADDRESS_MAP, &map);
apb_calc_first_last(map, &first, &last);
res = bus->resource[0];
res->start = (first << 21);
res->end = (last << 21) + ((1 << 21) - 1);
res->flags = IORESOURCE_IO;
pbm->parent->resource_adjust(dev, res, &pbm->io_space);
pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map);
apb_calc_first_last(map, &first, &last);
res = bus->resource[1];
res->start = (first << 21);
res->end = (last << 21) + ((1 << 21) - 1);
res->flags = IORESOURCE_MEM;
pbm->parent->resource_adjust(dev, res, &pbm->mem_space);
}
static void __init pci_of_scan_bus(struct pci_pbm_info *pbm, static void __init pci_of_scan_bus(struct pci_pbm_info *pbm,
struct device_node *node, struct device_node *node,
struct pci_bus *bus); struct pci_bus *bus);
...@@ -452,7 +509,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, ...@@ -452,7 +509,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
{ {
struct pci_bus *bus; struct pci_bus *bus;
const u32 *busrange, *ranges; const u32 *busrange, *ranges;
int len, i; int len, i, simba;
struct resource *res; struct resource *res;
unsigned int flags; unsigned int flags;
u64 size; u64 size;
...@@ -467,10 +524,16 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, ...@@ -467,10 +524,16 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
return; return;
} }
ranges = of_get_property(node, "ranges", &len); ranges = of_get_property(node, "ranges", &len);
simba = 0;
if (ranges == NULL) { if (ranges == NULL) {
printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %s\n", char *model = of_get_property(node, "model", NULL);
node->full_name); if (model && !strcmp(model, "SUNW,simba")) {
return; simba = 1;
} else {
printk(KERN_DEBUG "Can't get ranges for PCI-PCI bridge %s\n",
node->full_name);
return;
}
} }
bus = pci_add_new_bus(dev->bus, dev, busrange[0]); bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
...@@ -484,7 +547,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, ...@@ -484,7 +547,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
bus->subordinate = busrange[1]; bus->subordinate = busrange[1];
bus->bridge_ctl = 0; bus->bridge_ctl = 0;
/* parse ranges property */ /* parse ranges property, or cook one up by hand for Simba */
/* PCI #address-cells == 3 and #size-cells == 2 always */ /* PCI #address-cells == 3 and #size-cells == 2 always */
res = &dev->resource[PCI_BRIDGE_RESOURCES]; res = &dev->resource[PCI_BRIDGE_RESOURCES];
for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) { for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
...@@ -492,6 +555,10 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, ...@@ -492,6 +555,10 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
bus->resource[i] = res; bus->resource[i] = res;
++res; ++res;
} }
if (simba) {
apb_fake_ranges(dev, bus, pbm);
goto simba_cont;
}
i = 1; i = 1;
for (; len >= 32; len -= 32, ranges += 8) { for (; len >= 32; len -= 32, ranges += 8) {
struct resource *root; struct resource *root;
...@@ -529,6 +596,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, ...@@ -529,6 +596,7 @@ void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
*/ */
pbm->parent->resource_adjust(dev, res, root); pbm->parent->resource_adjust(dev, res, root);
} }
simba_cont:
sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus), sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
bus->number); bus->number);
printk(" bus name: %s\n", bus->name); printk(" bus name: %s\n", bus->name);
......
This diff is collapsed.
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