20 #include <linux/string.h>
21 #include <linux/kernel.h>
22 #include <linux/pci.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <asm/machdep.h>
32 #include <asm/pci-bridge.h>
36 #define MAX_NODE_NAME_SIZE (20 - 12)
38 static struct macio_chip *macio_on_hold;
58 return to_macio_device(tmp);
70 static int macio_device_probe(
struct device *
dev)
73 struct macio_driver *drv;
74 struct macio_dev *macio_dev;
77 drv = to_macio_driver(dev->
driver);
78 macio_dev = to_macio_device(dev);
87 error = drv->probe(macio_dev, match);
94 static int macio_device_remove(
struct device *dev)
96 struct macio_dev * macio_dev = to_macio_device(dev);
97 struct macio_driver * drv = to_macio_driver(dev->
driver);
99 if (dev->
driver && drv->remove)
100 drv->remove(macio_dev);
106 static void macio_device_shutdown(
struct device *dev)
108 struct macio_dev * macio_dev = to_macio_device(dev);
109 struct macio_driver * drv = to_macio_driver(dev->
driver);
111 if (dev->
driver && drv->shutdown)
112 drv->shutdown(macio_dev);
117 struct macio_dev * macio_dev = to_macio_device(dev);
118 struct macio_driver * drv = to_macio_driver(dev->
driver);
120 if (dev->
driver && drv->suspend)
121 return drv->suspend(macio_dev, state);
125 static int macio_device_resume(
struct device * dev)
127 struct macio_dev * macio_dev = to_macio_device(dev);
128 struct macio_driver * drv = to_macio_driver(dev->
driver);
130 if (dev->
driver && drv->resume)
131 return drv->resume(macio_dev);
139 .match = macio_bus_match,
141 .probe = macio_device_probe,
142 .remove = macio_device_remove,
143 .shutdown = macio_device_shutdown,
144 .suspend = macio_device_suspend,
145 .resume = macio_device_resume,
149 static int __init macio_bus_driver_init(
void)
167 static void macio_release_dev(
struct device *dev)
169 struct macio_dev *mdev;
171 mdev = to_macio_device(dev);
201 if ((res->
start & 0x0001f000) == 0x00008000)
213 if (index >= 3 && !(
strcmp(np->
name,
"ch-a") &&
218 if (index > 0 && !
strcmp(np->
name,
"media-bay"))
224 if (index == 0 && (res->
end - res->
start) > 0xfff)
226 if (index == 1 && (res->
end - res->
start) > 0xff)
232 static void macio_create_fixup_irq(
struct macio_dev *dev,
int index,
239 dev->interrupt[
index].start = irq;
241 dev->interrupt[
index].name = dev_name(&dev->ofdev.dev);
243 if (dev->n_interrupts <= index)
244 dev->n_interrupts = index + 1;
247 static void macio_add_missing_resources(
struct macio_dev *dev)
250 unsigned int irq_base;
253 if (dev->bus->chip->type != macio_gatwick)
263 macio_create_fixup_irq(dev, 0, 15 + irq_base);
264 macio_create_fixup_irq(dev, 1, 4 + irq_base);
265 macio_create_fixup_irq(dev, 2, 5 + irq_base);
271 macio_create_fixup_irq(dev, 0, 29 + irq_base);
277 macio_create_fixup_irq(dev, 0, 19 + irq_base);
278 macio_create_fixup_irq(dev, 1, 1 + irq_base);
282 macio_create_fixup_irq(dev, 0, 14 + irq_base);
283 macio_create_fixup_irq(dev, 0, 3 + irq_base);
288 static void macio_setup_interrupts(
struct macio_dev *dev)
297 if (
j >= MACIO_DEV_COUNT_IRQS)
299 res = &dev->interrupt[
j];
305 res->
name = dev_name(&dev->ofdev.dev);
306 if (macio_resource_quirks(np, res, i - 1)) {
312 dev->n_interrupts =
j;
315 static void macio_setup_resources(
struct macio_dev *dev,
324 if (index >= MACIO_DEV_COUNT_RESOURCES)
326 res = &dev->resource[
index];
328 res->
name = dev_name(&dev->ofdev.dev);
330 if (macio_resource_quirks(np, res, index)) {
340 "%d for MacIO device %s\n",
341 index, dev_name(&dev->ofdev.dev));
344 dev->n_resources =
index;
356 static struct macio_dev * macio_add_one_device(
struct macio_chip *
chip,
359 struct macio_dev *in_bay,
362 struct macio_dev *
dev;
372 dev->bus = &chip->lbus;
373 dev->media_bay = in_bay;
374 dev->ofdev.dev.of_node = np;
375 dev->ofdev.archdata.dma_mask = 0xffffffff
UL;
376 dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask;
377 dev->ofdev.dev.parent = parent;
379 dev->ofdev.dev.release = macio_release_dev;
380 dev->ofdev.dev.dma_parms = &dev->dma_parms;
383 dma_set_max_seg_size(&dev->ofdev.dev, 65536);
384 dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
393 dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
397 printk(
"preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
398 dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj);
402 if (np == chip->of_node) {
419 macio_setup_interrupts(dev);
420 macio_setup_resources(dev, parent_res);
421 macio_add_missing_resources(dev);
426 dev_name(&dev->ofdev.dev));
434 static int macio_skip_device(
struct device_node *np)
454 static void macio_pci_add_devices(
struct macio_chip *chip)
457 struct macio_dev *
rdev, *mdev, *mbdev =
NULL, *sdev =
NULL;
463 if (chip->lbus.pdev) {
464 parent = &chip->lbus.pdev->dev;
465 root_res = &chip->lbus.pdev->resource[0];
468 pnode = of_node_get(chip->of_node);
473 rdev = macio_add_one_device(chip, parent, pnode,
NULL, root_res);
476 root_res = &rdev->resource[0];
480 if (macio_skip_device(np))
483 mdev = macio_add_one_device(chip, &rdev->ofdev.dev, np,
NULL,
495 pnode = mbdev->ofdev.dev.of_node;
497 if (macio_skip_device(np))
500 if (macio_add_one_device(chip, &mbdev->ofdev.dev, np,
501 mbdev, root_res) ==
NULL)
508 pnode = sdev->ofdev.dev.of_node;
510 if (macio_skip_device(np))
513 if (macio_add_one_device(chip, &sdev->ofdev.dev, np,
548 static void maciom_release(
struct device *gendev,
void *res)
550 struct macio_dev *dev = to_macio_device(gendev);
554 max =
min(dev->n_resources, 32);
555 for (i = 0; i <
max; i++) {
574 static struct macio_devres * find_macio_dr(
struct macio_dev *dev)
598 if (macio_resource_len(dev, resource_no) == 0)
602 macio_resource_len(dev, resource_no),
606 if (dr && resource_no < 32)
615 macio_resource_len(dev, resource_no),
616 macio_resource_start(dev, resource_no),
617 dev_name(&dev->ofdev.dev));
630 if (macio_resource_len(dev, resource_no) == 0)
633 macio_resource_len(dev, resource_no));
634 if (dr && resource_no < 32)
635 dr->
res_mask &= ~(1 << resource_no);
654 for (i = 0; i < dev->n_resources; i++)
675 for (i = 0; i < dev->n_resources; i++)
685 struct macio_chip*
chip;
693 np = pci_device_to_OF_node(pdev);
711 if (chip->lbus.pdev ==
NULL) {
712 chip->lbus.pdev = pdev;
713 chip->lbus.chip =
chip;
714 pci_set_drvdata(pdev, &chip->lbus);
727 if (chip->type == macio_gatwick || chip->type == macio_ohareII)
729 macio_on_hold =
chip;
733 macio_pci_add_devices(chip);
735 macio_pci_add_devices(macio_on_hold);
736 macio_on_hold =
NULL;
744 panic(
"removing of macio-asic not supported !\n");
763 .
name = (
char *)
"macio",
766 .
probe = macio_pci_probe,
767 .
remove = macio_pci_remove,
772 static int __init macio_module_init (
void)
777 rc = pci_register_driver(&macio_pci_driver);