Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Bus & driver management routines for devices within
0004  * a MacIO ASIC. Interface to new driver model mostly
0005  * stolen from the PCI version.
0006  * 
0007  *  Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org)
0008  *
0009  * TODO:
0010  * 
0011  *  - Don't probe below media bay by default, but instead provide
0012  *    some hooks for media bay to dynamically add/remove it's own
0013  *    sub-devices.
0014  */
0015  
0016 #include <linux/string.h>
0017 #include <linux/kernel.h>
0018 #include <linux/pci.h>
0019 #include <linux/pci_ids.h>
0020 #include <linux/init.h>
0021 #include <linux/module.h>
0022 #include <linux/slab.h>
0023 #include <linux/of.h>
0024 #include <linux/of_address.h>
0025 #include <linux/of_device.h>
0026 #include <linux/of_irq.h>
0027 
0028 #include <asm/machdep.h>
0029 #include <asm/macio.h>
0030 #include <asm/pmac_feature.h>
0031 
0032 #undef DEBUG
0033 
0034 #define MAX_NODE_NAME_SIZE (20 - 12)
0035 
0036 static struct macio_chip      *macio_on_hold;
0037 
0038 static int macio_bus_match(struct device *dev, struct device_driver *drv) 
0039 {
0040     const struct of_device_id * matches = drv->of_match_table;
0041 
0042     if (!matches) 
0043         return 0;
0044 
0045     return of_match_device(matches, dev) != NULL;
0046 }
0047 
0048 struct macio_dev *macio_dev_get(struct macio_dev *dev)
0049 {
0050     struct device *tmp;
0051 
0052     if (!dev)
0053         return NULL;
0054     tmp = get_device(&dev->ofdev.dev);
0055     if (tmp)
0056         return to_macio_device(tmp);
0057     else
0058         return NULL;
0059 }
0060 
0061 void macio_dev_put(struct macio_dev *dev)
0062 {
0063     if (dev)
0064         put_device(&dev->ofdev.dev);
0065 }
0066 
0067 
0068 static int macio_device_probe(struct device *dev)
0069 {
0070     int error = -ENODEV;
0071     struct macio_driver *drv;
0072     struct macio_dev *macio_dev;
0073     const struct of_device_id *match;
0074 
0075     drv = to_macio_driver(dev->driver);
0076     macio_dev = to_macio_device(dev);
0077 
0078     if (!drv->probe)
0079         return error;
0080 
0081     macio_dev_get(macio_dev);
0082 
0083     match = of_match_device(drv->driver.of_match_table, dev);
0084     if (match)
0085         error = drv->probe(macio_dev, match);
0086     if (error)
0087         macio_dev_put(macio_dev);
0088 
0089     return error;
0090 }
0091 
0092 static void macio_device_remove(struct device *dev)
0093 {
0094     struct macio_dev * macio_dev = to_macio_device(dev);
0095     struct macio_driver * drv = to_macio_driver(dev->driver);
0096 
0097     if (dev->driver && drv->remove)
0098         drv->remove(macio_dev);
0099     macio_dev_put(macio_dev);
0100 }
0101 
0102 static void macio_device_shutdown(struct device *dev)
0103 {
0104     struct macio_dev * macio_dev = to_macio_device(dev);
0105     struct macio_driver * drv = to_macio_driver(dev->driver);
0106 
0107     if (dev->driver && drv->shutdown)
0108         drv->shutdown(macio_dev);
0109 }
0110 
0111 static int macio_device_suspend(struct device *dev, pm_message_t state)
0112 {
0113     struct macio_dev * macio_dev = to_macio_device(dev);
0114     struct macio_driver * drv = to_macio_driver(dev->driver);
0115 
0116     if (dev->driver && drv->suspend)
0117         return drv->suspend(macio_dev, state);
0118     return 0;
0119 }
0120 
0121 static int macio_device_resume(struct device * dev)
0122 {
0123     struct macio_dev * macio_dev = to_macio_device(dev);
0124     struct macio_driver * drv = to_macio_driver(dev->driver);
0125 
0126     if (dev->driver && drv->resume)
0127         return drv->resume(macio_dev);
0128     return 0;
0129 }
0130 
0131 extern const struct attribute_group *macio_dev_groups[];
0132 
0133 struct bus_type macio_bus_type = {
0134        .name    = "macio",
0135        .match   = macio_bus_match,
0136        .uevent = of_device_uevent_modalias,
0137        .probe   = macio_device_probe,
0138        .remove  = macio_device_remove,
0139        .shutdown = macio_device_shutdown,
0140        .suspend = macio_device_suspend,
0141        .resume  = macio_device_resume,
0142        .dev_groups = macio_dev_groups,
0143 };
0144 
0145 static int __init macio_bus_driver_init(void)
0146 {
0147     return bus_register(&macio_bus_type);
0148 }
0149 
0150 postcore_initcall(macio_bus_driver_init);
0151 
0152 
0153 /**
0154  * macio_release_dev - free a macio device structure when all users of it are
0155  * finished.
0156  * @dev: device that's been disconnected
0157  *
0158  * Will be called only by the device core when all users of this macio device
0159  * are done. This currently means never as we don't hot remove any macio
0160  * device yet, though that will happen with mediabay based devices in a later
0161  * implementation.
0162  */
0163 static void macio_release_dev(struct device *dev)
0164 {
0165     struct macio_dev *mdev;
0166 
0167         mdev = to_macio_device(dev);
0168     kfree(mdev);
0169 }
0170 
0171 /**
0172  * macio_resource_quirks - tweak or skip some resources for a device
0173  * @np: pointer to the device node
0174  * @res: resulting resource
0175  * @index: index of resource in node
0176  *
0177  * If this routine returns non-null, then the resource is completely
0178  * skipped.
0179  */
0180 static int macio_resource_quirks(struct device_node *np, struct resource *res,
0181                  int index)
0182 {
0183     /* Only quirks for memory resources for now */
0184     if ((res->flags & IORESOURCE_MEM) == 0)
0185         return 0;
0186 
0187     /* Grand Central has too large resource 0 on some machines */
0188     if (index == 0 && of_node_name_eq(np, "gc"))
0189         res->end = res->start + 0x1ffff;
0190 
0191     /* Airport has bogus resource 2 */
0192     if (index >= 2 && of_node_name_eq(np, "radio"))
0193         return 1;
0194 
0195 #ifndef CONFIG_PPC64
0196     /* DBDMAs may have bogus sizes */
0197     if ((res->start & 0x0001f000) == 0x00008000)
0198         res->end = res->start + 0xff;
0199 #endif /* CONFIG_PPC64 */
0200 
0201     /* ESCC parent eats child resources. We could have added a
0202      * level of hierarchy, but I don't really feel the need
0203      * for it
0204      */
0205     if (of_node_name_eq(np, "escc"))
0206         return 1;
0207 
0208     /* ESCC has bogus resources >= 3 */
0209     if (index >= 3 && (of_node_name_eq(np, "ch-a") ||
0210                of_node_name_eq(np, "ch-b")))
0211         return 1;
0212 
0213     /* Media bay has too many resources, keep only first one */
0214     if (index > 0 && of_node_name_eq(np, "media-bay"))
0215         return 1;
0216 
0217     /* Some older IDE resources have bogus sizes */
0218     if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
0219         of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
0220         if (index == 0 && (res->end - res->start) > 0xfff)
0221             res->end = res->start + 0xfff;
0222         if (index == 1 && (res->end - res->start) > 0xff)
0223             res->end = res->start + 0xff;
0224     }
0225     return 0;
0226 }
0227 
0228 static void macio_create_fixup_irq(struct macio_dev *dev, int index,
0229                    unsigned int line)
0230 {
0231     unsigned int irq;
0232 
0233     irq = irq_create_mapping(NULL, line);
0234     if (!irq) {
0235         dev->interrupt[index].start = irq;
0236         dev->interrupt[index].flags = IORESOURCE_IRQ;
0237         dev->interrupt[index].name = dev_name(&dev->ofdev.dev);
0238     }
0239     if (dev->n_interrupts <= index)
0240         dev->n_interrupts = index + 1;
0241 }
0242 
0243 static void macio_add_missing_resources(struct macio_dev *dev)
0244 {
0245     struct device_node *np = dev->ofdev.dev.of_node;
0246     unsigned int irq_base;
0247 
0248     /* Gatwick has some missing interrupts on child nodes */
0249     if (dev->bus->chip->type != macio_gatwick)
0250         return;
0251 
0252     /* irq_base is always 64 on gatwick. I have no cleaner way to get
0253      * that value from here at this point
0254      */
0255     irq_base = 64;
0256 
0257     /* Fix SCC */
0258     if (of_node_name_eq(np, "ch-a")) {
0259         macio_create_fixup_irq(dev, 0, 15 + irq_base);
0260         macio_create_fixup_irq(dev, 1,  4 + irq_base);
0261         macio_create_fixup_irq(dev, 2,  5 + irq_base);
0262         printk(KERN_INFO "macio: fixed SCC irqs on gatwick\n");
0263     }
0264 
0265     /* Fix media-bay */
0266     if (of_node_name_eq(np, "media-bay")) {
0267         macio_create_fixup_irq(dev, 0, 29 + irq_base);
0268         printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n");
0269     }
0270 
0271     /* Fix left media bay childs */
0272     if (dev->media_bay != NULL && of_node_name_eq(np, "floppy")) {
0273         macio_create_fixup_irq(dev, 0, 19 + irq_base);
0274         macio_create_fixup_irq(dev, 1,  1 + irq_base);
0275         printk(KERN_INFO "macio: fixed left floppy irqs\n");
0276     }
0277     if (dev->media_bay != NULL && of_node_name_eq(np, "ata4")) {
0278         macio_create_fixup_irq(dev, 0, 14 + irq_base);
0279         macio_create_fixup_irq(dev, 0,  3 + irq_base);
0280         printk(KERN_INFO "macio: fixed left ide irqs\n");
0281     }
0282 }
0283 
0284 static void macio_setup_interrupts(struct macio_dev *dev)
0285 {
0286     struct device_node *np = dev->ofdev.dev.of_node;
0287     unsigned int irq;
0288     int i = 0, j = 0;
0289 
0290     for (;;) {
0291         struct resource *res;
0292 
0293         if (j >= MACIO_DEV_COUNT_IRQS)
0294             break;
0295         res = &dev->interrupt[j];
0296         irq = irq_of_parse_and_map(np, i++);
0297         if (!irq)
0298             break;
0299         res->start = irq;
0300         res->flags = IORESOURCE_IRQ;
0301         res->name = dev_name(&dev->ofdev.dev);
0302         if (macio_resource_quirks(np, res, i - 1)) {
0303             memset(res, 0, sizeof(struct resource));
0304             continue;
0305         } else
0306             j++;
0307     }
0308     dev->n_interrupts = j;
0309 }
0310 
0311 static void macio_setup_resources(struct macio_dev *dev,
0312                   struct resource *parent_res)
0313 {
0314     struct device_node *np = dev->ofdev.dev.of_node;
0315     struct resource r;
0316     int index;
0317 
0318     for (index = 0; of_address_to_resource(np, index, &r) == 0; index++) {
0319         struct resource *res;
0320         if (index >= MACIO_DEV_COUNT_RESOURCES)
0321             break;
0322         res = &dev->resource[index];
0323         *res = r;
0324         res->name = dev_name(&dev->ofdev.dev);
0325 
0326         if (macio_resource_quirks(np, res, index)) {
0327             memset(res, 0, sizeof(struct resource));
0328             continue;
0329         }
0330         /* Currently, we consider failure as harmless, this may
0331          * change in the future, once I've found all the device
0332          * tree bugs in older machines & worked around them
0333          */
0334         if (insert_resource(parent_res, res)) {
0335             printk(KERN_WARNING "Can't request resource "
0336                    "%d for MacIO device %s\n",
0337                    index, dev_name(&dev->ofdev.dev));
0338         }
0339     }
0340     dev->n_resources = index;
0341 }
0342 
0343 /**
0344  * macio_add_one_device - Add one device from OF node to the device tree
0345  * @chip: pointer to the macio_chip holding the device
0346  * @np: pointer to the device node in the OF tree
0347  * @in_bay: set to 1 if device is part of a media-bay
0348  *
0349  * When media-bay is changed to hotswap drivers, this function will
0350  * be exposed to the bay driver some way...
0351  */
0352 static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
0353                            struct device *parent,
0354                            struct device_node *np,
0355                            struct macio_dev *in_bay,
0356                            struct resource *parent_res)
0357 {
0358     char name[MAX_NODE_NAME_SIZE + 1];
0359     struct macio_dev *dev;
0360     const u32 *reg;
0361 
0362     if (np == NULL)
0363         return NULL;
0364 
0365     dev = kzalloc(sizeof(*dev), GFP_KERNEL);
0366     if (!dev)
0367         return NULL;
0368 
0369     dev->bus = &chip->lbus;
0370     dev->media_bay = in_bay;
0371     dev->ofdev.dev.of_node = np;
0372     dev->ofdev.archdata.dma_mask = 0xffffffffUL;
0373     dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask;
0374     dev->ofdev.dev.coherent_dma_mask = dev->ofdev.archdata.dma_mask;
0375     dev->ofdev.dev.parent = parent;
0376     dev->ofdev.dev.bus = &macio_bus_type;
0377     dev->ofdev.dev.release = macio_release_dev;
0378     dev->ofdev.dev.dma_parms = &dev->dma_parms;
0379 
0380     /* Standard DMA paremeters */
0381     dma_set_max_seg_size(&dev->ofdev.dev, 65536);
0382     dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
0383 
0384 #if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS)
0385     /* Set the DMA ops to the ones from the PCI device, this could be
0386      * fishy if we didn't know that on PowerMac it's always direct ops
0387      * or iommu ops that will work fine
0388      *
0389      * To get all the fields, copy all archdata
0390      */
0391     dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
0392     dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops;
0393 #endif /* CONFIG_PCI && CONFIG_DMA_OPS */
0394 
0395 #ifdef DEBUG
0396     printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
0397            dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj);
0398 #endif
0399 
0400     /* MacIO itself has a different reg, we use it's PCI base */
0401     snprintf(name, sizeof(name), "%pOFn", np);
0402     if (np == chip->of_node) {
0403         dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
0404                  chip->lbus.index,
0405 #ifdef CONFIG_PCI
0406             (unsigned int)pci_resource_start(chip->lbus.pdev, 0),
0407 #else
0408             0, /* NuBus may want to do something better here */
0409 #endif
0410             MAX_NODE_NAME_SIZE, name);
0411     } else {
0412         reg = of_get_property(np, "reg", NULL);
0413         dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
0414                  chip->lbus.index,
0415                  reg ? *reg : 0, MAX_NODE_NAME_SIZE, name);
0416     }
0417 
0418     /* Setup interrupts & resources */
0419     macio_setup_interrupts(dev);
0420     macio_setup_resources(dev, parent_res);
0421     macio_add_missing_resources(dev);
0422 
0423     /* Register with core */
0424     if (of_device_register(&dev->ofdev) != 0) {
0425         printk(KERN_DEBUG"macio: device registration error for %s!\n",
0426                dev_name(&dev->ofdev.dev));
0427         kfree(dev);
0428         return NULL;
0429     }
0430 
0431     return dev;
0432 }
0433 
0434 static int macio_skip_device(struct device_node *np)
0435 {
0436     return of_node_name_prefix(np, "battery") ||
0437            of_node_name_prefix(np, "escc-legacy");
0438 }
0439 
0440 /**
0441  * macio_pci_add_devices - Adds sub-devices of mac-io to the device tree
0442  * @chip: pointer to the macio_chip holding the devices
0443  * 
0444  * This function will do the job of extracting devices from the
0445  * Open Firmware device tree, build macio_dev structures and add
0446  * them to the Linux device tree.
0447  * 
0448  * For now, childs of media-bay are added now as well. This will
0449  * change rsn though.
0450  */
0451 static void macio_pci_add_devices(struct macio_chip *chip)
0452 {
0453     struct device_node *np, *pnode;
0454     struct macio_dev *rdev, *mdev, *mbdev = NULL, *sdev = NULL;
0455     struct device *parent = NULL;
0456     struct resource *root_res = &iomem_resource;
0457     
0458     /* Add a node for the macio bus itself */
0459 #ifdef CONFIG_PCI
0460     if (chip->lbus.pdev) {
0461         parent = &chip->lbus.pdev->dev;
0462         root_res = &chip->lbus.pdev->resource[0];
0463     }
0464 #endif
0465     pnode = of_node_get(chip->of_node);
0466     if (pnode == NULL)
0467         return;
0468 
0469     /* Add macio itself to hierarchy */
0470     rdev = macio_add_one_device(chip, parent, pnode, NULL, root_res);
0471     if (rdev == NULL)
0472         return;
0473     root_res = &rdev->resource[0];
0474 
0475     /* First scan 1st level */
0476     for_each_child_of_node(pnode, np) {
0477         if (macio_skip_device(np))
0478             continue;
0479         of_node_get(np);
0480         mdev = macio_add_one_device(chip, &rdev->ofdev.dev, np, NULL,
0481                         root_res);
0482         if (mdev == NULL)
0483             of_node_put(np);
0484         else if (of_node_name_prefix(np, "media-bay"))
0485             mbdev = mdev;
0486         else if (of_node_name_prefix(np, "escc"))
0487             sdev = mdev;
0488     }
0489 
0490     /* Add media bay devices if any */
0491     if (mbdev) {
0492         pnode = mbdev->ofdev.dev.of_node;
0493         for_each_child_of_node(pnode, np) {
0494             if (macio_skip_device(np))
0495                 continue;
0496             of_node_get(np);
0497             if (macio_add_one_device(chip, &mbdev->ofdev.dev, np,
0498                          mbdev,  root_res) == NULL)
0499                 of_node_put(np);
0500         }
0501     }
0502 
0503     /* Add serial ports if any */
0504     if (sdev) {
0505         pnode = sdev->ofdev.dev.of_node;
0506         for_each_child_of_node(pnode, np) {
0507             if (macio_skip_device(np))
0508                 continue;
0509             of_node_get(np);
0510             if (macio_add_one_device(chip, &sdev->ofdev.dev, np,
0511                          NULL, root_res) == NULL)
0512                 of_node_put(np);
0513         }
0514     }
0515 }
0516 
0517 
0518 /**
0519  * macio_register_driver - Registers a new MacIO device driver
0520  * @drv: pointer to the driver definition structure
0521  */
0522 int macio_register_driver(struct macio_driver *drv)
0523 {
0524     /* initialize common driver fields */
0525     drv->driver.bus = &macio_bus_type;
0526 
0527     /* register with core */
0528     return driver_register(&drv->driver);
0529 }
0530 
0531 /**
0532  * macio_unregister_driver - Unregisters a new MacIO device driver
0533  * @drv: pointer to the driver definition structure
0534  */
0535 void macio_unregister_driver(struct macio_driver *drv)
0536 {
0537     driver_unregister(&drv->driver);
0538 }
0539 
0540 /* Managed MacIO resources */
0541 struct macio_devres {
0542     u32 res_mask;
0543 };
0544 
0545 static void maciom_release(struct device *gendev, void *res)
0546 {
0547     struct macio_dev *dev = to_macio_device(gendev);
0548     struct macio_devres *dr = res;
0549     int i, max;
0550 
0551     max = min(dev->n_resources, 32);
0552     for (i = 0; i < max; i++) {
0553         if (dr->res_mask & (1 << i))
0554             macio_release_resource(dev, i);
0555     }
0556 }
0557 
0558 int macio_enable_devres(struct macio_dev *dev)
0559 {
0560     struct macio_devres *dr;
0561 
0562     dr = devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
0563     if (!dr) {
0564         dr = devres_alloc(maciom_release, sizeof(*dr), GFP_KERNEL);
0565         if (!dr)
0566             return -ENOMEM;
0567     }
0568     return devres_get(&dev->ofdev.dev, dr, NULL, NULL) != NULL;
0569 }
0570 
0571 static struct macio_devres * find_macio_dr(struct macio_dev *dev)
0572 {
0573     return devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
0574 }
0575 
0576 /**
0577  *  macio_request_resource - Request an MMIO resource
0578  *  @dev: pointer to the device holding the resource
0579  *  @resource_no: resource number to request
0580  *  @name: resource name
0581  *
0582  *  Mark  memory region number @resource_no associated with MacIO
0583  *  device @dev as being reserved by owner @name.  Do not access
0584  *  any address inside the memory regions unless this call returns
0585  *  successfully.
0586  *
0587  *  Returns 0 on success, or %EBUSY on error.  A warning
0588  *  message is also printed on failure.
0589  */
0590 int macio_request_resource(struct macio_dev *dev, int resource_no,
0591                const char *name)
0592 {
0593     struct macio_devres *dr = find_macio_dr(dev);
0594 
0595     if (macio_resource_len(dev, resource_no) == 0)
0596         return 0;
0597         
0598     if (!request_mem_region(macio_resource_start(dev, resource_no),
0599                 macio_resource_len(dev, resource_no),
0600                 name))
0601         goto err_out;
0602 
0603     if (dr && resource_no < 32)
0604         dr->res_mask |= 1 << resource_no;
0605     
0606     return 0;
0607 
0608 err_out:
0609     printk (KERN_WARNING "MacIO: Unable to reserve resource #%d:%lx@%lx"
0610         " for device %s\n",
0611         resource_no,
0612         macio_resource_len(dev, resource_no),
0613         macio_resource_start(dev, resource_no),
0614         dev_name(&dev->ofdev.dev));
0615     return -EBUSY;
0616 }
0617 
0618 /**
0619  * macio_release_resource - Release an MMIO resource
0620  * @dev: pointer to the device holding the resource
0621  * @resource_no: resource number to release
0622  */
0623 void macio_release_resource(struct macio_dev *dev, int resource_no)
0624 {
0625     struct macio_devres *dr = find_macio_dr(dev);
0626 
0627     if (macio_resource_len(dev, resource_no) == 0)
0628         return;
0629     release_mem_region(macio_resource_start(dev, resource_no),
0630                macio_resource_len(dev, resource_no));
0631     if (dr && resource_no < 32)
0632         dr->res_mask &= ~(1 << resource_no);
0633 }
0634 
0635 /**
0636  *  macio_request_resources - Reserve all memory resources
0637  *  @dev: MacIO device whose resources are to be reserved
0638  *  @name: Name to be associated with resource.
0639  *
0640  *  Mark all memory regions associated with MacIO device @dev as
0641  *  being reserved by owner @name.  Do not access any address inside
0642  *  the memory regions unless this call returns successfully.
0643  *
0644  *  Returns 0 on success, or %EBUSY on error.  A warning
0645  *  message is also printed on failure.
0646  */
0647 int macio_request_resources(struct macio_dev *dev, const char *name)
0648 {
0649     int i;
0650     
0651     for (i = 0; i < dev->n_resources; i++)
0652         if (macio_request_resource(dev, i, name))
0653             goto err_out;
0654     return 0;
0655 
0656 err_out:
0657     while(--i >= 0)
0658         macio_release_resource(dev, i);
0659         
0660     return -EBUSY;
0661 }
0662 
0663 /**
0664  *  macio_release_resources - Release reserved memory resources
0665  *  @dev: MacIO device whose resources were previously reserved
0666  */
0667 
0668 void macio_release_resources(struct macio_dev *dev)
0669 {
0670     int i;
0671     
0672     for (i = 0; i < dev->n_resources; i++)
0673         macio_release_resource(dev, i);
0674 }
0675 
0676 
0677 #ifdef CONFIG_PCI
0678 
0679 static int macio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
0680 {
0681     struct device_node* np;
0682     struct macio_chip* chip;
0683     
0684     if (ent->vendor != PCI_VENDOR_ID_APPLE)
0685         return -ENODEV;
0686 
0687     /* Note regarding refcounting: We assume pci_device_to_OF_node() is
0688      * ported to new OF APIs and returns a node with refcount incremented.
0689      */
0690     np = pci_device_to_OF_node(pdev);
0691     if (np == NULL)
0692         return -ENODEV;
0693 
0694     /* The above assumption is wrong !!!
0695      * fix that here for now until I fix the arch code
0696      */
0697     of_node_get(np);
0698 
0699     /* We also assume that pmac_feature will have done a get() on nodes
0700      * stored in the macio chips array
0701      */
0702     chip = macio_find(np, macio_unknown);
0703         of_node_put(np);
0704     if (chip == NULL)
0705         return -ENODEV;
0706 
0707     /* XXX Need locking ??? */
0708     if (chip->lbus.pdev == NULL) {
0709         chip->lbus.pdev = pdev;
0710         chip->lbus.chip = chip;
0711         pci_set_drvdata(pdev, &chip->lbus);
0712         pci_set_master(pdev);
0713     }
0714 
0715     printk(KERN_INFO "MacIO PCI driver attached to %s chipset\n",
0716         chip->name);
0717 
0718     /*
0719      * HACK ALERT: The WallStreet PowerBook and some OHare based machines
0720      * have 2 macio ASICs. I must probe the "main" one first or IDE
0721      * ordering will be incorrect. So I put on "hold" the second one since
0722      * it seem to appear first on PCI
0723      */
0724     if (chip->type == macio_gatwick || chip->type == macio_ohareII)
0725         if (macio_chips[0].lbus.pdev == NULL) {
0726             macio_on_hold = chip;
0727             return 0;
0728         }
0729 
0730     macio_pci_add_devices(chip);
0731     if (macio_on_hold && macio_chips[0].lbus.pdev != NULL) {
0732         macio_pci_add_devices(macio_on_hold);
0733         macio_on_hold = NULL;
0734     }
0735 
0736     return 0;
0737 }
0738 
0739 static void macio_pci_remove(struct pci_dev* pdev)
0740 {
0741     panic("removing of macio-asic not supported !\n");
0742 }
0743 
0744 /*
0745  * MacIO is matched against any Apple ID, it's probe() function
0746  * will then decide wether it applies or not
0747  */
0748 static const struct pci_device_id pci_ids[] = { {
0749     .vendor     = PCI_VENDOR_ID_APPLE,
0750     .device     = PCI_ANY_ID,
0751     .subvendor  = PCI_ANY_ID,
0752     .subdevice  = PCI_ANY_ID,
0753 
0754     }, { /* end: all zeroes */ }
0755 };
0756 MODULE_DEVICE_TABLE (pci, pci_ids);
0757 
0758 /* pci driver glue; this is a "new style" PCI driver module */
0759 static struct pci_driver macio_pci_driver = {
0760     .name       = "macio",
0761     .id_table   = pci_ids,
0762 
0763     .probe      = macio_pci_probe,
0764     .remove     = macio_pci_remove,
0765 };
0766 
0767 #endif /* CONFIG_PCI */
0768 
0769 static int __init macio_module_init (void) 
0770 {
0771 #ifdef CONFIG_PCI
0772     int rc;
0773 
0774     rc = pci_register_driver(&macio_pci_driver);
0775     if (rc)
0776         return rc;
0777 #endif /* CONFIG_PCI */
0778     return 0;
0779 }
0780 
0781 module_init(macio_module_init);
0782 
0783 EXPORT_SYMBOL(macio_register_driver);
0784 EXPORT_SYMBOL(macio_unregister_driver);
0785 EXPORT_SYMBOL(macio_dev_get);
0786 EXPORT_SYMBOL(macio_dev_put);
0787 EXPORT_SYMBOL(macio_request_resource);
0788 EXPORT_SYMBOL(macio_release_resource);
0789 EXPORT_SYMBOL(macio_request_resources);
0790 EXPORT_SYMBOL(macio_release_resources);
0791 EXPORT_SYMBOL(macio_enable_devres);
0792