linux/arch/sparc64/kernel/isa.c
<<
>>
Prefs
   1#include <linux/kernel.h>
   2#include <linux/init.h>
   3#include <linux/pci.h>
   4#include <linux/slab.h>
   5#include <asm/oplib.h>
   6#include <asm/prom.h>
   7#include <asm/of_device.h>
   8#include <asm/isa.h>
   9
  10struct sparc_isa_bridge *isa_chain;
  11
  12static void __init fatal_err(const char *reason)
  13{
  14        prom_printf("ISA: fatal error, %s.\n", reason);
  15}
  16
  17static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
  18{
  19        if (child)
  20                printk(" (%s)", isa_dev->prom_node->name);
  21        else
  22                printk(" [%s", isa_dev->prom_node->name);
  23}
  24
  25static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev)
  26{
  27        struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
  28
  29        memcpy(&isa_dev->resource, &op->resource[0], sizeof(struct resource));
  30}
  31
  32static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev)
  33{
  34        struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
  35
  36        if (!op || !op->num_irqs) {
  37                isa_dev->irq = PCI_IRQ_NONE;
  38        } else {
  39                isa_dev->irq = op->irqs[0];
  40        }
  41}
  42
  43static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
  44{
  45        struct device_node *dp = parent_isa_dev->prom_node->child;
  46
  47        if (!dp)
  48                return;
  49
  50        printk(" ->");
  51        while (dp) {
  52                struct sparc_isa_device *isa_dev;
  53
  54                isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
  55                if (!isa_dev) {
  56                        fatal_err("cannot allocate child isa_dev");
  57                        prom_halt();
  58                }
  59
  60                /* Link it in to parent. */
  61                isa_dev->next = parent_isa_dev->child;
  62                parent_isa_dev->child = isa_dev;
  63
  64                isa_dev->bus = parent_isa_dev->bus;
  65                isa_dev->prom_node = dp;
  66
  67                isa_dev_get_resource(isa_dev);
  68                isa_dev_get_irq(isa_dev);
  69
  70                report_dev(isa_dev, 1);
  71
  72                dp = dp->sibling;
  73        }
  74}
  75
  76static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
  77{
  78        struct device_node *dp = isa_br->prom_node->child;
  79
  80        while (dp) {
  81                struct sparc_isa_device *isa_dev;
  82                struct dev_archdata *sd;
  83
  84                isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
  85                if (!isa_dev) {
  86                        printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
  87                        return;
  88                }
  89
  90                sd = &isa_dev->ofdev.dev.archdata;
  91                sd->prom_node = dp;
  92                sd->op = &isa_dev->ofdev;
  93                sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu;
  94                sd->stc = isa_br->ofdev.dev.parent->archdata.stc;
  95
  96                isa_dev->ofdev.node = dp;
  97                isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
  98                isa_dev->ofdev.dev.bus = &isa_bus_type;
  99                sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
 100
 101                /* Register with core */
 102                if (of_device_register(&isa_dev->ofdev) != 0) {
 103                        printk(KERN_DEBUG "isa: device registration error for %s!\n",
 104                               dp->path_component_name);
 105                        kfree(isa_dev);
 106                        goto next_sibling;
 107                }
 108
 109                /* Link it in. */
 110                isa_dev->next = NULL;
 111                if (isa_br->devices == NULL) {
 112                        isa_br->devices = isa_dev;
 113                } else {
 114                        struct sparc_isa_device *tmp = isa_br->devices;
 115
 116                        while (tmp->next)
 117                                tmp = tmp->next;
 118
 119                        tmp->next = isa_dev;
 120                }
 121
 122                isa_dev->bus = isa_br;
 123                isa_dev->prom_node = dp;
 124
 125                isa_dev_get_resource(isa_dev);
 126                isa_dev_get_irq(isa_dev);
 127
 128                report_dev(isa_dev, 0);
 129
 130                isa_fill_children(isa_dev);
 131
 132                printk("]");
 133
 134        next_sibling:
 135                dp = dp->sibling;
 136        }
 137}
 138
 139void __init isa_init(void)
 140{
 141        struct pci_dev *pdev;
 142        unsigned short vendor, device;
 143        int index = 0;
 144
 145        vendor = PCI_VENDOR_ID_AL;
 146        device = PCI_DEVICE_ID_AL_M1533;
 147
 148        pdev = NULL;
 149        while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
 150                struct sparc_isa_bridge *isa_br;
 151                struct device_node *dp;
 152
 153                dp = pci_device_to_OF_node(pdev);
 154
 155                isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
 156                if (!isa_br) {
 157                        printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
 158                        pci_dev_put(pdev);
 159                        return;
 160                }
 161
 162                isa_br->ofdev.node = dp;
 163                isa_br->ofdev.dev.parent = &pdev->dev;
 164                isa_br->ofdev.dev.bus = &isa_bus_type;
 165                sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
 166
 167                /* Register with core */
 168                if (of_device_register(&isa_br->ofdev) != 0) {
 169                        printk(KERN_DEBUG "isa: device registration error for %s!\n",
 170                               dp->path_component_name);
 171                        kfree(isa_br);
 172                        pci_dev_put(pdev);
 173                        return;
 174                }
 175
 176                /* Link it in. */
 177                isa_br->next = isa_chain;
 178                isa_chain = isa_br;
 179
 180                isa_br->self = pdev;
 181                isa_br->index = index++;
 182                isa_br->prom_node = dp;
 183
 184                printk("isa%d:", isa_br->index);
 185
 186                isa_fill_devices(isa_br);
 187
 188                printk("\n");
 189        }
 190}
 191