macio_asic.c 20 KB

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