Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 6 | #include <asm/prom.h> |
| 7 | #include <asm/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/isa.h> |
| 9 | |
| 10 | struct sparc_isa_bridge *isa_chain; |
| 11 | |
| 12 | static void __init fatal_err(const char *reason) |
| 13 | { |
| 14 | prom_printf("ISA: fatal error, %s.\n", reason); |
| 15 | } |
| 16 | |
| 17 | static void __init report_dev(struct sparc_isa_device *isa_dev, int child) |
| 18 | { |
| 19 | if (child) |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 20 | printk(" (%s)", isa_dev->prom_node->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | else |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 22 | printk(" [%s", isa_dev->prom_node->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | } |
| 24 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 25 | static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 27 | struct linux_prom_registers *pregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | unsigned long base, len; |
| 29 | int prop_len; |
| 30 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 31 | pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len); |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 32 | if (!pregs) |
| 33 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* Only the first one is interesting. */ |
| 36 | len = pregs[0].reg_size; |
| 37 | base = (((unsigned long)pregs[0].which_io << 32) | |
| 38 | (unsigned long)pregs[0].phys_addr); |
| 39 | base += isa_dev->bus->parent->io_space.start; |
| 40 | |
| 41 | isa_dev->resource.start = base; |
| 42 | isa_dev->resource.end = (base + len - 1UL); |
| 43 | isa_dev->resource.flags = IORESOURCE_IO; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 44 | isa_dev->resource.name = isa_dev->prom_node->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | request_resource(&isa_dev->bus->parent->io_space, |
| 47 | &isa_dev->resource); |
| 48 | } |
| 49 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 50 | static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 52 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 54 | if (!op || !op->num_irqs) { |
| 55 | isa_dev->irq = PCI_IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } else { |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 57 | isa_dev->irq = op->irqs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev) |
| 62 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 63 | struct device_node *dp = parent_isa_dev->prom_node->child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 65 | if (!dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return; |
| 67 | |
| 68 | printk(" ->"); |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 69 | while (dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | struct sparc_isa_device *isa_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 72 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | if (!isa_dev) { |
| 74 | fatal_err("cannot allocate child isa_dev"); |
| 75 | prom_halt(); |
| 76 | } |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* Link it in to parent. */ |
| 79 | isa_dev->next = parent_isa_dev->child; |
| 80 | parent_isa_dev->child = isa_dev; |
| 81 | |
| 82 | isa_dev->bus = parent_isa_dev->bus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 83 | isa_dev->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 85 | isa_dev_get_resource(isa_dev); |
| 86 | isa_dev_get_irq(isa_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | report_dev(isa_dev, 1); |
| 89 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 90 | dp = dp->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br) |
| 95 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 96 | struct device_node *dp = isa_br->prom_node->child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 98 | while (dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | struct sparc_isa_device *isa_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 101 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (!isa_dev) { |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 103 | printk(KERN_DEBUG "ISA: cannot allocate isa_dev"); |
| 104 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 107 | isa_dev->ofdev.node = dp; |
| 108 | isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; |
| 109 | isa_dev->ofdev.dev.bus = &isa_bus_type; |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 110 | sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 111 | |
| 112 | /* Register with core */ |
| 113 | if (of_device_register(&isa_dev->ofdev) != 0) { |
| 114 | printk(KERN_DEBUG "isa: device registration error for %s!\n", |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 115 | dp->path_component_name); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 116 | kfree(isa_dev); |
| 117 | goto next_sibling; |
| 118 | } |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* Link it in. */ |
| 121 | isa_dev->next = NULL; |
| 122 | if (isa_br->devices == NULL) { |
| 123 | isa_br->devices = isa_dev; |
| 124 | } else { |
| 125 | struct sparc_isa_device *tmp = isa_br->devices; |
| 126 | |
| 127 | while (tmp->next) |
| 128 | tmp = tmp->next; |
| 129 | |
| 130 | tmp->next = isa_dev; |
| 131 | } |
| 132 | |
| 133 | isa_dev->bus = isa_br; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 134 | isa_dev->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 136 | isa_dev_get_resource(isa_dev); |
| 137 | isa_dev_get_irq(isa_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | report_dev(isa_dev, 0); |
| 140 | |
| 141 | isa_fill_children(isa_dev); |
| 142 | |
| 143 | printk("]"); |
| 144 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 145 | next_sibling: |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 146 | dp = dp->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | void __init isa_init(void) |
| 151 | { |
| 152 | struct pci_dev *pdev; |
| 153 | unsigned short vendor, device; |
| 154 | int index = 0; |
| 155 | |
| 156 | vendor = PCI_VENDOR_ID_AL; |
| 157 | device = PCI_DEVICE_ID_AL_M1533; |
| 158 | |
| 159 | pdev = NULL; |
| 160 | while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) { |
| 161 | struct pcidev_cookie *pdev_cookie; |
| 162 | struct pci_pbm_info *pbm; |
| 163 | struct sparc_isa_bridge *isa_br; |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 164 | struct device_node *dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | pdev_cookie = pdev->sysdata; |
| 167 | if (!pdev_cookie) { |
| 168 | printk("ISA: Warning, ISA bridge ignored due to " |
| 169 | "lack of OBP data.\n"); |
| 170 | continue; |
| 171 | } |
| 172 | pbm = pdev_cookie->pbm; |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 173 | dp = pdev_cookie->prom_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 175 | isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if (!isa_br) { |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 177 | printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge"); |
| 178 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 181 | isa_br->ofdev.node = dp; |
| 182 | isa_br->ofdev.dev.parent = &pdev->dev; |
| 183 | isa_br->ofdev.dev.bus = &isa_bus_type; |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 184 | sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 185 | |
| 186 | /* Register with core */ |
| 187 | if (of_device_register(&isa_br->ofdev) != 0) { |
| 188 | printk(KERN_DEBUG "isa: device registration error for %s!\n", |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 189 | dp->path_component_name); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 190 | kfree(isa_br); |
| 191 | return; |
| 192 | } |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* Link it in. */ |
| 195 | isa_br->next = isa_chain; |
| 196 | isa_chain = isa_br; |
| 197 | |
| 198 | isa_br->parent = pbm; |
| 199 | isa_br->self = pdev; |
| 200 | isa_br->index = index++; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 201 | isa_br->prom_node = pdev_cookie->prom_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | printk("isa%d:", isa_br->index); |
| 204 | |
| 205 | isa_fill_devices(isa_br); |
| 206 | |
| 207 | printk("\n"); |
| 208 | } |
| 209 | } |