macio_asic.c 19 KB

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