macio_asic.c 20 KB

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