macio_asic.c 19 KB

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