^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Bus & driver management routines for devices within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * a MacIO ASIC. Interface to new driver model mostly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * stolen from the PCI version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * - Don't probe below media bay by default, but instead provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * some hooks for media bay to dynamically add/remove it's own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * sub-devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pci_ids.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/machdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/macio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/pmac_feature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define MAX_NODE_NAME_SIZE (20 - 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static struct macio_chip *macio_on_hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int macio_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) const struct of_device_id * matches = drv->of_match_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!matches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return of_match_device(matches, dev) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct macio_dev *macio_dev_get(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct device *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) tmp = get_device(&dev->ofdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return to_macio_device(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void macio_dev_put(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) put_device(&dev->ofdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int macio_device_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct macio_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct macio_dev *macio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) drv = to_macio_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) macio_dev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!drv->probe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) macio_dev_get(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) match = of_match_device(drv->driver.of_match_table, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) error = drv->probe(macio_dev, match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) macio_dev_put(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static int macio_device_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct macio_dev * macio_dev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct macio_driver * drv = to_macio_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (dev->driver && drv->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) drv->remove(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) macio_dev_put(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void macio_device_shutdown(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct macio_dev * macio_dev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct macio_driver * drv = to_macio_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (dev->driver && drv->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) drv->shutdown(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int macio_device_suspend(struct device *dev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct macio_dev * macio_dev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct macio_driver * drv = to_macio_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (dev->driver && drv->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return drv->suspend(macio_dev, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int macio_device_resume(struct device * dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct macio_dev * macio_dev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct macio_driver * drv = to_macio_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (dev->driver && drv->resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return drv->resume(macio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) extern const struct attribute_group *macio_dev_groups[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct bus_type macio_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .name = "macio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .match = macio_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .uevent = of_device_uevent_modalias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .probe = macio_device_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .remove = macio_device_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .shutdown = macio_device_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .suspend = macio_device_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .resume = macio_device_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .dev_groups = macio_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int __init macio_bus_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return bus_register(&macio_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) postcore_initcall(macio_bus_driver_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * macio_release_dev - free a macio device structure when all users of it are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @dev: device that's been disconnected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Will be called only by the device core when all users of this macio device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * are done. This currently means never as we don't hot remove any macio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * device yet, though that will happen with mediabay based devices in a later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void macio_release_dev(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct macio_dev *mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) mdev = to_macio_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) kfree(mdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * macio_resource_quirks - tweak or skip some resources for a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @np: pointer to the device node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * @res: resulting resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * @index: index of resource in node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * If this routine returns non-null, then the resource is completely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * skipped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int macio_resource_quirks(struct device_node *np, struct resource *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Only quirks for memory resources for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if ((res->flags & IORESOURCE_MEM) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Grand Central has too large resource 0 on some machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (index == 0 && of_node_name_eq(np, "gc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) res->end = res->start + 0x1ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Airport has bogus resource 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (index >= 2 && of_node_name_eq(np, "radio"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #ifndef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* DBDMAs may have bogus sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if ((res->start & 0x0001f000) == 0x00008000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) res->end = res->start + 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif /* CONFIG_PPC64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* ESCC parent eats child resources. We could have added a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * level of hierarchy, but I don't really feel the need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (of_node_name_eq(np, "escc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* ESCC has bogus resources >= 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (index >= 3 && (of_node_name_eq(np, "ch-a") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) of_node_name_eq(np, "ch-b")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Media bay has too many resources, keep only first one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (index > 0 && of_node_name_eq(np, "media-bay"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Some older IDE resources have bogus sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (index == 0 && (res->end - res->start) > 0xfff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) res->end = res->start + 0xfff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (index == 1 && (res->end - res->start) > 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) res->end = res->start + 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static void macio_create_fixup_irq(struct macio_dev *dev, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unsigned int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) irq = irq_create_mapping(NULL, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) dev->interrupt[index].start = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) dev->interrupt[index].flags = IORESOURCE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dev->interrupt[index].name = dev_name(&dev->ofdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (dev->n_interrupts <= index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dev->n_interrupts = index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void macio_add_missing_resources(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct device_node *np = dev->ofdev.dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unsigned int irq_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* Gatwick has some missing interrupts on child nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (dev->bus->chip->type != macio_gatwick)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* irq_base is always 64 on gatwick. I have no cleaner way to get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * that value from here at this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) irq_base = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* Fix SCC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (of_node_name_eq(np, "ch-a")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) macio_create_fixup_irq(dev, 0, 15 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) macio_create_fixup_irq(dev, 1, 4 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) macio_create_fixup_irq(dev, 2, 5 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) printk(KERN_INFO "macio: fixed SCC irqs on gatwick\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Fix media-bay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (of_node_name_eq(np, "media-bay")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) macio_create_fixup_irq(dev, 0, 29 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Fix left media bay childs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (dev->media_bay != NULL && of_node_name_eq(np, "floppy")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) macio_create_fixup_irq(dev, 0, 19 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) macio_create_fixup_irq(dev, 1, 1 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) printk(KERN_INFO "macio: fixed left floppy irqs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (dev->media_bay != NULL && of_node_name_eq(np, "ata4")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) macio_create_fixup_irq(dev, 0, 14 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) macio_create_fixup_irq(dev, 0, 3 + irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) printk(KERN_INFO "macio: fixed left ide irqs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void macio_setup_interrupts(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct device_node *np = dev->ofdev.dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int i = 0, j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (j >= MACIO_DEV_COUNT_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) res = &dev->interrupt[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) irq = irq_of_parse_and_map(np, i++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (!irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) res->start = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) res->flags = IORESOURCE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) res->name = dev_name(&dev->ofdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (macio_resource_quirks(np, res, i - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) memset(res, 0, sizeof(struct resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) dev->n_interrupts = j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static void macio_setup_resources(struct macio_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct resource *parent_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct device_node *np = dev->ofdev.dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct resource r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) for (index = 0; of_address_to_resource(np, index, &r) == 0; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (index >= MACIO_DEV_COUNT_RESOURCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) res = &dev->resource[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *res = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) res->name = dev_name(&dev->ofdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (macio_resource_quirks(np, res, index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) memset(res, 0, sizeof(struct resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Currently, we consider failure as harmless, this may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * change in the future, once I've found all the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * tree bugs in older machines & worked around them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (insert_resource(parent_res, res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) printk(KERN_WARNING "Can't request resource "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) "%d for MacIO device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) index, dev_name(&dev->ofdev.dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) dev->n_resources = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * macio_add_one_device - Add one device from OF node to the device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * @chip: pointer to the macio_chip holding the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * @np: pointer to the device node in the OF tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * @in_bay: set to 1 if device is part of a media-bay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * When media-bay is changed to hotswap drivers, this function will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * be exposed to the bay driver some way...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct macio_dev *in_bay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct resource *parent_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) char name[MAX_NODE_NAME_SIZE + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct macio_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) const u32 *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (np == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) dev = kzalloc(sizeof(*dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dev->bus = &chip->lbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) dev->media_bay = in_bay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) dev->ofdev.dev.of_node = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) dev->ofdev.archdata.dma_mask = 0xffffffffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) dev->ofdev.dev.coherent_dma_mask = dev->ofdev.archdata.dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dev->ofdev.dev.parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) dev->ofdev.dev.bus = &macio_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) dev->ofdev.dev.release = macio_release_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dev->ofdev.dev.dma_parms = &dev->dma_parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* Standard DMA paremeters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) dma_set_max_seg_size(&dev->ofdev.dev, 65536);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* Set the DMA ops to the ones from the PCI device, this could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * fishy if we didn't know that on PowerMac it's always direct ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * or iommu ops that will work fine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * To get all the fields, copy all archdata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #endif /* CONFIG_PCI && CONFIG_DMA_OPS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /* MacIO itself has a different reg, we use it's PCI base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) snprintf(name, sizeof(name), "%pOFn", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (np == chip->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) chip->lbus.index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) (unsigned int)pci_resource_start(chip->lbus.pdev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 0, /* NuBus may want to do something better here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) MAX_NODE_NAME_SIZE, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) reg = of_get_property(np, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) chip->lbus.index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) reg ? *reg : 0, MAX_NODE_NAME_SIZE, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* Setup interrupts & resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) macio_setup_interrupts(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) macio_setup_resources(dev, parent_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) macio_add_missing_resources(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Register with core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (of_device_register(&dev->ofdev) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) printk(KERN_DEBUG"macio: device registration error for %s!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) dev_name(&dev->ofdev.dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int macio_skip_device(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return of_node_name_prefix(np, "battery") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) of_node_name_prefix(np, "escc-legacy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * macio_pci_add_devices - Adds sub-devices of mac-io to the device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * @chip: pointer to the macio_chip holding the devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * This function will do the job of extracting devices from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * Open Firmware device tree, build macio_dev structures and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * them to the Linux device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * For now, childs of media-bay are added now as well. This will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * change rsn though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static void macio_pci_add_devices(struct macio_chip *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct device_node *np, *pnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct macio_dev *rdev, *mdev, *mbdev = NULL, *sdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct device *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct resource *root_res = &iomem_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* Add a node for the macio bus itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (chip->lbus.pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) parent = &chip->lbus.pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) root_res = &chip->lbus.pdev->resource[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) pnode = of_node_get(chip->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (pnode == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /* Add macio itself to hierarchy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) rdev = macio_add_one_device(chip, parent, pnode, NULL, root_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (rdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) root_res = &rdev->resource[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* First scan 1st level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (macio_skip_device(np))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) mdev = macio_add_one_device(chip, &rdev->ofdev.dev, np, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) root_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (mdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) else if (of_node_name_prefix(np, "media-bay"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) mbdev = mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) else if (of_node_name_prefix(np, "escc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) sdev = mdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* Add media bay devices if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (mbdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) pnode = mbdev->ofdev.dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (macio_skip_device(np))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (macio_add_one_device(chip, &mbdev->ofdev.dev, np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) mbdev, root_res) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /* Add serial ports if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (sdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) pnode = sdev->ofdev.dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (macio_skip_device(np))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (macio_add_one_device(chip, &sdev->ofdev.dev, np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) NULL, root_res) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * macio_register_driver - Registers a new MacIO device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * @drv: pointer to the driver definition structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) int macio_register_driver(struct macio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /* initialize common driver fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) drv->driver.bus = &macio_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* register with core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return driver_register(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * macio_unregister_driver - Unregisters a new MacIO device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * @drv: pointer to the driver definition structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) void macio_unregister_driver(struct macio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) driver_unregister(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* Managed MacIO resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct macio_devres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) u32 res_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void maciom_release(struct device *gendev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct macio_dev *dev = to_macio_device(gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct macio_devres *dr = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) int i, max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) max = min(dev->n_resources, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (dr->res_mask & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) macio_release_resource(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int macio_enable_devres(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct macio_devres *dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) dr = devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!dr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) dr = devres_alloc(maciom_release, sizeof(*dr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (!dr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return devres_get(&dev->ofdev.dev, dr, NULL, NULL) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static struct macio_devres * find_macio_dr(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * macio_request_resource - Request an MMIO resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * @dev: pointer to the device holding the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * @resource_no: resource number to request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * @name: resource name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * Mark memory region number @resource_no associated with MacIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * device @dev as being reserved by owner @name. Do not access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * any address inside the memory regions unless this call returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * Returns 0 on success, or %EBUSY on error. A warning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * message is also printed on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) int macio_request_resource(struct macio_dev *dev, int resource_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct macio_devres *dr = find_macio_dr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (macio_resource_len(dev, resource_no) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!request_mem_region(macio_resource_start(dev, resource_no),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) macio_resource_len(dev, resource_no),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (dr && resource_no < 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) dr->res_mask |= 1 << resource_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) printk (KERN_WARNING "MacIO: Unable to reserve resource #%d:%lx@%lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) " for device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) resource_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) macio_resource_len(dev, resource_no),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) macio_resource_start(dev, resource_no),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) dev_name(&dev->ofdev.dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * macio_release_resource - Release an MMIO resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * @dev: pointer to the device holding the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * @resource_no: resource number to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) void macio_release_resource(struct macio_dev *dev, int resource_no)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct macio_devres *dr = find_macio_dr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (macio_resource_len(dev, resource_no) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) release_mem_region(macio_resource_start(dev, resource_no),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) macio_resource_len(dev, resource_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (dr && resource_no < 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) dr->res_mask &= ~(1 << resource_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * macio_request_resources - Reserve all memory resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * @dev: MacIO device whose resources are to be reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * @name: Name to be associated with resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * Mark all memory regions associated with MacIO device @dev as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * being reserved by owner @name. Do not access any address inside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * the memory regions unless this call returns successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * Returns 0 on success, or %EBUSY on error. A warning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * message is also printed on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) int macio_request_resources(struct macio_dev *dev, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) for (i = 0; i < dev->n_resources; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (macio_request_resource(dev, i, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) while(--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) macio_release_resource(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * macio_release_resources - Release reserved memory resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * @dev: MacIO device whose resources were previously reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) void macio_release_resources(struct macio_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) for (i = 0; i < dev->n_resources; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) macio_release_resource(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static int macio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct device_node* np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct macio_chip* chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (ent->vendor != PCI_VENDOR_ID_APPLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /* Note regarding refcounting: We assume pci_device_to_OF_node() is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) * ported to new OF APIs and returns a node with refcount incremented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) np = pci_device_to_OF_node(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (np == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /* The above assumption is wrong !!!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * fix that here for now until I fix the arch code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /* We also assume that pmac_feature will have done a get() on nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * stored in the macio chips array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) chip = macio_find(np, macio_unknown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (chip == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /* XXX Need locking ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (chip->lbus.pdev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) chip->lbus.pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) chip->lbus.chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) pci_set_drvdata(pdev, &chip->lbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) pci_set_master(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) printk(KERN_INFO "MacIO PCI driver attached to %s chipset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) chip->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * HACK ALERT: The WallStreet PowerBook and some OHare based machines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) * have 2 macio ASICs. I must probe the "main" one first or IDE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * ordering will be incorrect. So I put on "hold" the second one since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * it seem to appear first on PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (chip->type == macio_gatwick || chip->type == macio_ohareII)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (macio_chips[0].lbus.pdev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) macio_on_hold = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) macio_pci_add_devices(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (macio_on_hold && macio_chips[0].lbus.pdev != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) macio_pci_add_devices(macio_on_hold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) macio_on_hold = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static void macio_pci_remove(struct pci_dev* pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) panic("removing of macio-asic not supported !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * MacIO is matched against any Apple ID, it's probe() function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * will then decide wether it applies or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) static const struct pci_device_id pci_ids[] = { {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) .vendor = PCI_VENDOR_ID_APPLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) .device = PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) .subvendor = PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) .subdevice = PCI_ANY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }, { /* end: all zeroes */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) MODULE_DEVICE_TABLE (pci, pci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /* pci driver glue; this is a "new style" PCI driver module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) static struct pci_driver macio_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .name = (char *) "macio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .id_table = pci_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) .probe = macio_pci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) .remove = macio_pci_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) #endif /* CONFIG_PCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) static int __init macio_module_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) rc = pci_register_driver(&macio_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) #endif /* CONFIG_PCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) module_init(macio_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) EXPORT_SYMBOL(macio_register_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) EXPORT_SYMBOL(macio_unregister_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) EXPORT_SYMBOL(macio_dev_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) EXPORT_SYMBOL(macio_dev_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) EXPORT_SYMBOL(macio_request_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) EXPORT_SYMBOL(macio_release_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) EXPORT_SYMBOL(macio_request_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) EXPORT_SYMBOL(macio_release_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) EXPORT_SYMBOL(macio_enable_devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)