// SPDX-License-Identifier: GPL-2.0-or-later /* * Bus & driver management routines for devices within * a MacIO ASIC. Interface to new driver model mostly * stolen from the PCI version. * * Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org) * * TODO: * * - Don't probe below media bay by default, but instead provide * some hooks for media bay to dynamically add/remove it's own * sub-devices.
*/
/** * macio_release_dev - free a macio device structure when all users of it are * finished. * @dev: device that's been disconnected * * Will be called only by the device core when all users of this macio device * are done. This currently means never as we don't hot remove any macio * device yet, though that will happen with mediabay based devices in a later * implementation.
*/ staticvoid macio_release_dev(struct device *dev)
{ struct macio_dev *mdev;
mdev = to_macio_device(dev);
kfree(mdev);
}
/** * macio_resource_quirks - tweak or skip some resources for a device * @np: pointer to the device node * @res: resulting resource * @index: index of resource in node * * If this routine returns non-null, then the resource is completely * skipped.
*/ staticint macio_resource_quirks(struct device_node *np, struct resource *res, int index)
{ /* Only quirks for memory resources for now */ if ((res->flags & IORESOURCE_MEM) == 0) return 0;
/* Grand Central has too large resource 0 on some machines */ if (index == 0 && of_node_name_eq(np, "gc"))
res->end = res->start + 0x1ffff;
/* Airport has bogus resource 2 */ if (index >= 2 && of_node_name_eq(np, "radio")) return 1;
#ifndef CONFIG_PPC64 /* DBDMAs may have bogus sizes */ if ((res->start & 0x0001f000) == 0x00008000)
res->end = res->start + 0xff; #endif/* CONFIG_PPC64 */
/* ESCC parent eats child resources. We could have added a * level of hierarchy, but I don't really feel the need * for it
*/ if (of_node_name_eq(np, "escc")) return 1;
/* ESCC has bogus resources >= 3 */ if (index >= 3 && (of_node_name_eq(np, "ch-a") ||
of_node_name_eq(np, "ch-b"))) return 1;
/* Media bay has too many resources, keep only first one */ if (index > 0 && of_node_name_eq(np, "media-bay")) return 1;
/* Some older IDE resources have bogus sizes */ if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) { if (index == 0 && (res->end - res->start) > 0xfff)
res->end = res->start + 0xfff; if (index == 1 && (res->end - res->start) > 0xff)
res->end = res->start + 0xff;
} return 0;
}
for (index = 0; of_address_to_resource(np, index, &r) == 0; index++) { struct resource *res; if (index >= MACIO_DEV_COUNT_RESOURCES) break;
res = &dev->resource[index];
*res = r;
res->name = dev_name(&dev->ofdev.dev);
if (macio_resource_quirks(np, res, index)) {
memset(res, 0, sizeof(struct resource)); continue;
} /* Currently, we consider failure as harmless, this may * change in the future, once I've found all the device * tree bugs in older machines & worked around them
*/ if (insert_resource(parent_res, res)) {
printk(KERN_WARNING "Can't request resource " "%d for MacIO device %s\n",
index, dev_name(&dev->ofdev.dev));
}
}
dev->n_resources = index;
}
/** * macio_add_one_device - Add one device from OF node to the device tree * @chip: pointer to the macio_chip holding the device * @np: pointer to the device node in the OF tree * @in_bay: set to 1 if device is part of a media-bay * * When media-bay is changed to hotswap drivers, this function will * be exposed to the bay driver some way...
*/ staticstruct macio_dev * macio_add_one_device(struct macio_chip *chip, struct device *parent, struct device_node *np, struct macio_dev *in_bay, struct resource *parent_res)
{ char name[MAX_NODE_NAME_SIZE + 1]; struct macio_dev *dev; const u32 *reg;
if (np == NULL) return NULL;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return NULL;
/* Standard DMA paremeters */
dma_set_max_seg_size(&dev->ofdev.dev, 65536);
dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
#ifdefined(CONFIG_PCI) && defined(CONFIG_ARCH_HAS_DMA_OPS) /* Set the DMA ops to the ones from the PCI device, this could be * fishy if we didn't know that on PowerMac it's always direct ops * or iommu ops that will work fine * * To get all the fields, copy all archdata
*/
dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops; #endif/* CONFIG_PCI && CONFIG_ARCH_HAS_DMA_OPS */
/** * macio_pci_add_devices - Adds sub-devices of mac-io to the device tree * @chip: pointer to the macio_chip holding the devices * * This function will do the job of extracting devices from the * Open Firmware device tree, build macio_dev structures and add * them to the Linux device tree. * * For now, childs of media-bay are added now as well. This will * change rsn though.
*/ staticvoid macio_pci_add_devices(struct macio_chip *chip)
{ struct device_node *np, *pnode; struct macio_dev *rdev, *mdev, *mbdev = NULL, *sdev = NULL; struct device *parent = NULL; struct resource *root_res = &iomem_resource;
/* Add a node for the macio bus itself */ #ifdef CONFIG_PCI if (chip->lbus.pdev) {
parent = &chip->lbus.pdev->dev;
root_res = &chip->lbus.pdev->resource[0];
} #endif
pnode = of_node_get(chip->of_node); if (pnode == NULL) return;
/* Add media bay devices if any */ if (mbdev) {
pnode = mbdev->ofdev.dev.of_node;
for_each_child_of_node(pnode, np) { if (macio_skip_device(np)) continue;
of_node_get(np); if (macio_add_one_device(chip, &mbdev->ofdev.dev, np,
mbdev, root_res) == NULL)
of_node_put(np);
}
}
/* Add serial ports if any */ if (sdev) {
pnode = sdev->ofdev.dev.of_node;
for_each_child_of_node(pnode, np) { if (macio_skip_device(np)) continue;
of_node_get(np); if (macio_add_one_device(chip, &sdev->ofdev.dev, np,
NULL, root_res) == NULL)
of_node_put(np);
}
}
}
/** * macio_register_driver - Registers a new MacIO device driver * @drv: pointer to the driver definition structure
*/ int macio_register_driver(struct macio_driver *drv)
{ /* initialize common driver fields */
drv->driver.bus = &macio_bus_type;
/* register with core */ return driver_register(&drv->driver);
}
/** * macio_unregister_driver - Unregisters a new MacIO device driver * @drv: pointer to the driver definition structure
*/ void macio_unregister_driver(struct macio_driver *drv)
{
driver_unregister(&drv->driver);
}
/** * macio_request_resource - Request an MMIO resource * @dev: pointer to the device holding the resource * @resource_no: resource number to request * @name: resource name * * Mark memory region number @resource_no associated with MacIO * device @dev as being reserved by owner @name. Do not access * any address inside the memory regions unless this call returns * successfully. * * Returns 0 on success, or %EBUSY on error. A warning * message is also printed on failure.
*/ int macio_request_resource(struct macio_dev *dev, int resource_no, constchar *name)
{ struct macio_devres *dr = find_macio_dr(dev);
if (macio_resource_len(dev, resource_no) == 0) return 0;
if (!request_mem_region(macio_resource_start(dev, resource_no),
macio_resource_len(dev, resource_no),
name)) goto err_out;
/** * macio_request_resources - Reserve all memory resources * @dev: MacIO device whose resources are to be reserved * @name: Name to be associated with resource. * * Mark all memory regions associated with MacIO device @dev as * being reserved by owner @name. Do not access any address inside * the memory regions unless this call returns successfully. * * Returns 0 on success, or %EBUSY on error. A warning * message is also printed on failure.
*/ int macio_request_resources(struct macio_dev *dev, constchar *name)
{ int i;
for (i = 0; i < dev->n_resources; i++) if (macio_request_resource(dev, i, name)) goto err_out; return 0;
if (ent->vendor != PCI_VENDOR_ID_APPLE) return -ENODEV;
/* Note regarding refcounting: We assume pci_device_to_OF_node() is * ported to new OF APIs and returns a node with refcount incremented.
*/
np = pci_device_to_OF_node(pdev); if (np == NULL) return -ENODEV;
/* The above assumption is wrong !!! * fix that here for now until I fix the arch code
*/
of_node_get(np);
/* We also assume that pmac_feature will have done a get() on nodes * stored in the macio chips array
*/
chip = macio_find(np, macio_unknown);
of_node_put(np); if (chip == NULL) return -ENODEV;
printk(KERN_INFO "MacIO PCI driver attached to %s chipset\n",
chip->name);
/* * HACK ALERT: The WallStreet PowerBook and some OHare based machines * have 2 macio ASICs. I must probe the "main" one first or IDE * ordering will be incorrect. So I put on "hold" the second one since * it seem to appear first on PCI
*/ if (chip->type == macio_gatwick || chip->type == macio_ohareII) if (macio_chips[0].lbus.pdev == NULL) {
macio_on_hold = chip; return 0;
}
staticvoid macio_pci_remove(struct pci_dev* pdev)
{
panic("removing of macio-asic not supported !\n");
}
/* * MacIO is matched against any Apple ID, it's probe() function * will then decide wether it applies or not
*/ staticconststruct pci_device_id pci_ids[] = { {
.vendor = PCI_VENDOR_ID_APPLE,
.device = PCI_ANY_ID,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.