pnv_php.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * PCI Hotplug Driver for PowerPC PowerNV platform.
  3. *
  4. * Copyright Gavin Shan, IBM Corporation 2016.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/libfdt.h>
  12. #include <linux/module.h>
  13. #include <linux/pci.h>
  14. #include <linux/pci_hotplug.h>
  15. #include <asm/opal.h>
  16. #include <asm/pnv-pci.h>
  17. #include <asm/ppc-pci.h>
  18. #define DRIVER_VERSION "0.1"
  19. #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"
  20. #define DRIVER_DESC "PowerPC PowerNV PCI Hotplug Driver"
  21. static LIST_HEAD(pnv_php_slot_list);
  22. static DEFINE_SPINLOCK(pnv_php_lock);
  23. static void pnv_php_register(struct device_node *dn);
  24. static void pnv_php_unregister_one(struct device_node *dn);
  25. static void pnv_php_unregister(struct device_node *dn);
  26. static void pnv_php_free_slot(struct kref *kref)
  27. {
  28. struct pnv_php_slot *php_slot = container_of(kref,
  29. struct pnv_php_slot, kref);
  30. WARN_ON(!list_empty(&php_slot->children));
  31. kfree(php_slot->name);
  32. kfree(php_slot);
  33. }
  34. static inline void pnv_php_put_slot(struct pnv_php_slot *php_slot)
  35. {
  36. if (WARN_ON(!php_slot))
  37. return;
  38. kref_put(&php_slot->kref, pnv_php_free_slot);
  39. }
  40. static struct pnv_php_slot *pnv_php_match(struct device_node *dn,
  41. struct pnv_php_slot *php_slot)
  42. {
  43. struct pnv_php_slot *target, *tmp;
  44. if (php_slot->dn == dn) {
  45. kref_get(&php_slot->kref);
  46. return php_slot;
  47. }
  48. list_for_each_entry(tmp, &php_slot->children, link) {
  49. target = pnv_php_match(dn, tmp);
  50. if (target)
  51. return target;
  52. }
  53. return NULL;
  54. }
  55. struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn)
  56. {
  57. struct pnv_php_slot *php_slot, *tmp;
  58. unsigned long flags;
  59. spin_lock_irqsave(&pnv_php_lock, flags);
  60. list_for_each_entry(tmp, &pnv_php_slot_list, link) {
  61. php_slot = pnv_php_match(dn, tmp);
  62. if (php_slot) {
  63. spin_unlock_irqrestore(&pnv_php_lock, flags);
  64. return php_slot;
  65. }
  66. }
  67. spin_unlock_irqrestore(&pnv_php_lock, flags);
  68. return NULL;
  69. }
  70. EXPORT_SYMBOL_GPL(pnv_php_find_slot);
  71. /*
  72. * Remove pdn for all children of the indicated device node.
  73. * The function should remove pdn in a depth-first manner.
  74. */
  75. static void pnv_php_rmv_pdns(struct device_node *dn)
  76. {
  77. struct device_node *child;
  78. for_each_child_of_node(dn, child) {
  79. pnv_php_rmv_pdns(child);
  80. pci_remove_device_node_info(child);
  81. }
  82. }
  83. /*
  84. * Detach all child nodes of the indicated device nodes. The
  85. * function should handle device nodes in depth-first manner.
  86. *
  87. * We should not invoke of_node_release() as the memory for
  88. * individual device node is part of large memory block. The
  89. * large block is allocated from memblock (system bootup) or
  90. * kmalloc() when unflattening the device tree by OF changeset.
  91. * We can not free the large block allocated from memblock. For
  92. * later case, it should be released at once.
  93. */
  94. static void pnv_php_detach_device_nodes(struct device_node *parent)
  95. {
  96. struct device_node *dn;
  97. int refcount;
  98. for_each_child_of_node(parent, dn) {
  99. pnv_php_detach_device_nodes(dn);
  100. of_node_put(dn);
  101. refcount = atomic_read(&dn->kobj.kref.refcount);
  102. if (unlikely(refcount != 1))
  103. pr_warn("Invalid refcount %d on <%s>\n",
  104. refcount, of_node_full_name(dn));
  105. of_detach_node(dn);
  106. }
  107. }
  108. static void pnv_php_rmv_devtree(struct pnv_php_slot *php_slot)
  109. {
  110. pnv_php_rmv_pdns(php_slot->dn);
  111. /*
  112. * Decrease the refcount if the device nodes were created
  113. * through OF changeset before detaching them.
  114. */
  115. if (php_slot->fdt)
  116. of_changeset_destroy(&php_slot->ocs);
  117. pnv_php_detach_device_nodes(php_slot->dn);
  118. if (php_slot->fdt) {
  119. kfree(php_slot->dt);
  120. kfree(php_slot->fdt);
  121. php_slot->dt = NULL;
  122. php_slot->dn->child = NULL;
  123. php_slot->fdt = NULL;
  124. }
  125. }
  126. /*
  127. * As the nodes in OF changeset are applied in reverse order, we
  128. * need revert the nodes in advance so that we have correct node
  129. * order after the changeset is applied.
  130. */
  131. static void pnv_php_reverse_nodes(struct device_node *parent)
  132. {
  133. struct device_node *child, *next;
  134. /* In-depth first */
  135. for_each_child_of_node(parent, child)
  136. pnv_php_reverse_nodes(child);
  137. /* Reverse the nodes in the child list */
  138. child = parent->child;
  139. parent->child = NULL;
  140. while (child) {
  141. next = child->sibling;
  142. child->sibling = parent->child;
  143. parent->child = child;
  144. child = next;
  145. }
  146. }
  147. static int pnv_php_populate_changeset(struct of_changeset *ocs,
  148. struct device_node *dn)
  149. {
  150. struct device_node *child;
  151. int ret = 0;
  152. for_each_child_of_node(dn, child) {
  153. ret = of_changeset_attach_node(ocs, child);
  154. if (unlikely(ret))
  155. break;
  156. ret = pnv_php_populate_changeset(ocs, child);
  157. if (unlikely(ret))
  158. break;
  159. }
  160. return ret;
  161. }
  162. static void *pnv_php_add_one_pdn(struct device_node *dn, void *data)
  163. {
  164. struct pci_controller *hose = (struct pci_controller *)data;
  165. struct pci_dn *pdn;
  166. pdn = pci_add_device_node_info(hose, dn);
  167. if (unlikely(!pdn))
  168. return ERR_PTR(-ENOMEM);
  169. return NULL;
  170. }
  171. static void pnv_php_add_pdns(struct pnv_php_slot *slot)
  172. {
  173. struct pci_controller *hose = pci_bus_to_host(slot->bus);
  174. pci_traverse_device_nodes(slot->dn, pnv_php_add_one_pdn, hose);
  175. }
  176. static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
  177. {
  178. void *fdt, *fdt1, *dt;
  179. int ret;
  180. /* We don't know the FDT blob size. We try to get it through
  181. * maximal memory chunk and then copy it to another chunk that
  182. * fits the real size.
  183. */
  184. fdt1 = kzalloc(0x10000, GFP_KERNEL);
  185. if (unlikely(!fdt1)) {
  186. ret = -ENOMEM;
  187. dev_warn(&php_slot->pdev->dev, "Cannot alloc FDT blob\n");
  188. goto out;
  189. }
  190. ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000);
  191. if (unlikely(ret)) {
  192. dev_warn(&php_slot->pdev->dev, "Error %d getting FDT blob\n",
  193. ret);
  194. goto free_fdt1;
  195. }
  196. fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL);
  197. if (unlikely(!fdt)) {
  198. ret = -ENOMEM;
  199. dev_warn(&php_slot->pdev->dev, "Cannot %d bytes memory\n",
  200. fdt_totalsize(fdt1));
  201. goto free_fdt1;
  202. }
  203. /* Unflatten device tree blob */
  204. memcpy(fdt, fdt1, fdt_totalsize(fdt1));
  205. dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL);
  206. if (unlikely(!dt)) {
  207. ret = -EINVAL;
  208. dev_warn(&php_slot->pdev->dev, "Cannot unflatten FDT\n");
  209. goto free_fdt;
  210. }
  211. /* Initialize and apply the changeset */
  212. of_changeset_init(&php_slot->ocs);
  213. pnv_php_reverse_nodes(php_slot->dn);
  214. ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn);
  215. if (unlikely(ret)) {
  216. pnv_php_reverse_nodes(php_slot->dn);
  217. dev_warn(&php_slot->pdev->dev, "Error %d populating changeset\n",
  218. ret);
  219. goto free_dt;
  220. }
  221. php_slot->dn->child = NULL;
  222. ret = of_changeset_apply(&php_slot->ocs);
  223. if (unlikely(ret)) {
  224. dev_warn(&php_slot->pdev->dev, "Error %d applying changeset\n",
  225. ret);
  226. goto destroy_changeset;
  227. }
  228. /* Add device node firmware data */
  229. pnv_php_add_pdns(php_slot);
  230. php_slot->fdt = fdt;
  231. php_slot->dt = dt;
  232. kfree(fdt1);
  233. goto out;
  234. destroy_changeset:
  235. of_changeset_destroy(&php_slot->ocs);
  236. free_dt:
  237. kfree(dt);
  238. php_slot->dn->child = NULL;
  239. free_fdt:
  240. kfree(fdt);
  241. free_fdt1:
  242. kfree(fdt1);
  243. out:
  244. return ret;
  245. }
  246. int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
  247. uint8_t state)
  248. {
  249. struct pnv_php_slot *php_slot = slot->private;
  250. struct opal_msg msg;
  251. int ret;
  252. ret = pnv_pci_set_power_state(php_slot->id, state, &msg);
  253. if (likely(ret > 0)) {
  254. if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle ||
  255. be64_to_cpu(msg.params[2]) != state ||
  256. be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) {
  257. dev_warn(&php_slot->pdev->dev, "Wrong msg (%lld, %lld, %lld)\n",
  258. be64_to_cpu(msg.params[1]),
  259. be64_to_cpu(msg.params[2]),
  260. be64_to_cpu(msg.params[3]));
  261. return -ENOMSG;
  262. }
  263. } else if (unlikely(ret < 0)) {
  264. dev_warn(&php_slot->pdev->dev, "Error %d powering %s\n",
  265. ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off");
  266. return ret;
  267. }
  268. if (state == OPAL_PCI_SLOT_POWER_OFF || state == OPAL_PCI_SLOT_OFFLINE)
  269. pnv_php_rmv_devtree(php_slot);
  270. else
  271. ret = pnv_php_add_devtree(php_slot);
  272. return ret;
  273. }
  274. EXPORT_SYMBOL_GPL(pnv_php_set_slot_power_state);
  275. static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state)
  276. {
  277. struct pnv_php_slot *php_slot = slot->private;
  278. uint8_t power_state = OPAL_PCI_SLOT_POWER_ON;
  279. int ret;
  280. /*
  281. * Retrieve power status from firmware. If we fail
  282. * getting that, the power status fails back to
  283. * be on.
  284. */
  285. ret = pnv_pci_get_power_state(php_slot->id, &power_state);
  286. if (unlikely(ret)) {
  287. dev_warn(&php_slot->pdev->dev, "Error %d getting power status\n",
  288. ret);
  289. } else {
  290. *state = power_state;
  291. slot->info->power_status = power_state;
  292. }
  293. return 0;
  294. }
  295. static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)
  296. {
  297. struct pnv_php_slot *php_slot = slot->private;
  298. uint8_t presence = OPAL_PCI_SLOT_EMPTY;
  299. int ret;
  300. /*
  301. * Retrieve presence status from firmware. If we can't
  302. * get that, it will fail back to be empty.
  303. */
  304. ret = pnv_pci_get_presence_state(php_slot->id, &presence);
  305. if (likely(ret >= 0)) {
  306. *state = presence;
  307. slot->info->adapter_status = presence;
  308. ret = 0;
  309. } else {
  310. dev_warn(&php_slot->pdev->dev, "Error %d getting presence\n",
  311. ret);
  312. }
  313. return ret;
  314. }
  315. static int pnv_php_set_attention_state(struct hotplug_slot *slot, u8 state)
  316. {
  317. /* FIXME: Make it real once firmware supports it */
  318. slot->info->attention_status = state;
  319. return 0;
  320. }
  321. static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
  322. {
  323. struct hotplug_slot *slot = &php_slot->slot;
  324. uint8_t presence = OPAL_PCI_SLOT_EMPTY;
  325. uint8_t power_status = OPAL_PCI_SLOT_POWER_ON;
  326. int ret;
  327. /* Check if the slot has been configured */
  328. if (php_slot->state != PNV_PHP_STATE_REGISTERED)
  329. return 0;
  330. /* Retrieve slot presence status */
  331. ret = pnv_php_get_adapter_state(slot, &presence);
  332. if (unlikely(ret))
  333. return ret;
  334. /* Proceed if there have nothing behind the slot */
  335. if (presence == OPAL_PCI_SLOT_EMPTY)
  336. goto scan;
  337. /*
  338. * If the power supply to the slot is off, we can't detect
  339. * adapter presence state. That means we have to turn the
  340. * slot on before going to probe slot's presence state.
  341. *
  342. * On the first time, we don't change the power status to
  343. * boost system boot with assumption that the firmware
  344. * supplies consistent slot power status: empty slot always
  345. * has its power off and non-empty slot has its power on.
  346. */
  347. if (!php_slot->power_state_check) {
  348. php_slot->power_state_check = true;
  349. ret = pnv_php_get_power_state(slot, &power_status);
  350. if (unlikely(ret))
  351. return ret;
  352. if (power_status != OPAL_PCI_SLOT_POWER_ON)
  353. return 0;
  354. }
  355. /* Check the power status. Scan the slot if it is already on */
  356. ret = pnv_php_get_power_state(slot, &power_status);
  357. if (unlikely(ret))
  358. return ret;
  359. if (power_status == OPAL_PCI_SLOT_POWER_ON)
  360. goto scan;
  361. /* Power is off, turn it on and then scan the slot */
  362. ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_ON);
  363. if (unlikely(ret))
  364. return ret;
  365. scan:
  366. if (presence == OPAL_PCI_SLOT_PRESENT) {
  367. if (rescan) {
  368. pci_lock_rescan_remove();
  369. pci_hp_add_devices(php_slot->bus);
  370. pci_unlock_rescan_remove();
  371. }
  372. /* Rescan for child hotpluggable slots */
  373. php_slot->state = PNV_PHP_STATE_POPULATED;
  374. if (rescan)
  375. pnv_php_register(php_slot->dn);
  376. } else {
  377. php_slot->state = PNV_PHP_STATE_POPULATED;
  378. }
  379. return 0;
  380. }
  381. static int pnv_php_enable_slot(struct hotplug_slot *slot)
  382. {
  383. struct pnv_php_slot *php_slot = container_of(slot,
  384. struct pnv_php_slot, slot);
  385. return pnv_php_enable(php_slot, true);
  386. }
  387. static int pnv_php_disable_slot(struct hotplug_slot *slot)
  388. {
  389. struct pnv_php_slot *php_slot = slot->private;
  390. int ret;
  391. if (php_slot->state != PNV_PHP_STATE_POPULATED)
  392. return 0;
  393. /* Remove all devices behind the slot */
  394. pci_lock_rescan_remove();
  395. pci_hp_remove_devices(php_slot->bus);
  396. pci_unlock_rescan_remove();
  397. /* Detach the child hotpluggable slots */
  398. pnv_php_unregister(php_slot->dn);
  399. /* Notify firmware and remove device nodes */
  400. ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_OFF);
  401. php_slot->state = PNV_PHP_STATE_REGISTERED;
  402. return ret;
  403. }
  404. static struct hotplug_slot_ops php_slot_ops = {
  405. .get_power_status = pnv_php_get_power_state,
  406. .get_adapter_status = pnv_php_get_adapter_state,
  407. .set_attention_status = pnv_php_set_attention_state,
  408. .enable_slot = pnv_php_enable_slot,
  409. .disable_slot = pnv_php_disable_slot,
  410. };
  411. static void pnv_php_release(struct hotplug_slot *slot)
  412. {
  413. struct pnv_php_slot *php_slot = slot->private;
  414. unsigned long flags;
  415. /* Remove from global or child list */
  416. spin_lock_irqsave(&pnv_php_lock, flags);
  417. list_del(&php_slot->link);
  418. spin_unlock_irqrestore(&pnv_php_lock, flags);
  419. /* Detach from parent */
  420. pnv_php_put_slot(php_slot);
  421. pnv_php_put_slot(php_slot->parent);
  422. }
  423. static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
  424. {
  425. struct pnv_php_slot *php_slot;
  426. struct pci_bus *bus;
  427. const char *label;
  428. uint64_t id;
  429. label = of_get_property(dn, "ibm,slot-label", NULL);
  430. if (unlikely(!label))
  431. return NULL;
  432. if (pnv_pci_get_slot_id(dn, &id))
  433. return NULL;
  434. bus = pci_find_bus_by_node(dn);
  435. if (unlikely(!bus))
  436. return NULL;
  437. php_slot = kzalloc(sizeof(*php_slot), GFP_KERNEL);
  438. if (unlikely(!php_slot))
  439. return NULL;
  440. php_slot->name = kstrdup(label, GFP_KERNEL);
  441. if (unlikely(!php_slot->name)) {
  442. kfree(php_slot);
  443. return NULL;
  444. }
  445. if (likely(dn->child && PCI_DN(dn->child)))
  446. php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn);
  447. else
  448. php_slot->slot_no = -1; /* Placeholder slot */
  449. kref_init(&php_slot->kref);
  450. php_slot->state = PNV_PHP_STATE_INITIALIZED;
  451. php_slot->dn = dn;
  452. php_slot->pdev = bus->self;
  453. php_slot->bus = bus;
  454. php_slot->id = id;
  455. php_slot->power_state_check = false;
  456. php_slot->slot.ops = &php_slot_ops;
  457. php_slot->slot.info = &php_slot->slot_info;
  458. php_slot->slot.release = pnv_php_release;
  459. php_slot->slot.private = php_slot;
  460. INIT_LIST_HEAD(&php_slot->children);
  461. INIT_LIST_HEAD(&php_slot->link);
  462. return php_slot;
  463. }
  464. static int pnv_php_register_slot(struct pnv_php_slot *php_slot)
  465. {
  466. struct pnv_php_slot *parent;
  467. struct device_node *dn = php_slot->dn;
  468. unsigned long flags;
  469. int ret;
  470. /* Check if the slot is registered or not */
  471. parent = pnv_php_find_slot(php_slot->dn);
  472. if (unlikely(parent)) {
  473. pnv_php_put_slot(parent);
  474. return -EEXIST;
  475. }
  476. /* Register PCI slot */
  477. ret = pci_hp_register(&php_slot->slot, php_slot->bus,
  478. php_slot->slot_no, php_slot->name);
  479. if (unlikely(ret)) {
  480. dev_warn(&php_slot->pdev->dev, "Error %d registering slot\n",
  481. ret);
  482. return ret;
  483. }
  484. /* Attach to the parent's child list or global list */
  485. while ((dn = of_get_parent(dn))) {
  486. if (!PCI_DN(dn)) {
  487. of_node_put(dn);
  488. break;
  489. }
  490. parent = pnv_php_find_slot(dn);
  491. if (parent) {
  492. of_node_put(dn);
  493. break;
  494. }
  495. of_node_put(dn);
  496. }
  497. spin_lock_irqsave(&pnv_php_lock, flags);
  498. php_slot->parent = parent;
  499. if (parent)
  500. list_add_tail(&php_slot->link, &parent->children);
  501. else
  502. list_add_tail(&php_slot->link, &pnv_php_slot_list);
  503. spin_unlock_irqrestore(&pnv_php_lock, flags);
  504. php_slot->state = PNV_PHP_STATE_REGISTERED;
  505. return 0;
  506. }
  507. static int pnv_php_register_one(struct device_node *dn)
  508. {
  509. struct pnv_php_slot *php_slot;
  510. const __be32 *prop32;
  511. int ret;
  512. /* Check if it's hotpluggable slot */
  513. prop32 = of_get_property(dn, "ibm,slot-pluggable", NULL);
  514. if (!prop32 || !of_read_number(prop32, 1))
  515. return -ENXIO;
  516. prop32 = of_get_property(dn, "ibm,reset-by-firmware", NULL);
  517. if (!prop32 || !of_read_number(prop32, 1))
  518. return -ENXIO;
  519. php_slot = pnv_php_alloc_slot(dn);
  520. if (unlikely(!php_slot))
  521. return -ENODEV;
  522. ret = pnv_php_register_slot(php_slot);
  523. if (unlikely(ret))
  524. goto free_slot;
  525. ret = pnv_php_enable(php_slot, false);
  526. if (unlikely(ret))
  527. goto unregister_slot;
  528. return 0;
  529. unregister_slot:
  530. pnv_php_unregister_one(php_slot->dn);
  531. free_slot:
  532. pnv_php_put_slot(php_slot);
  533. return ret;
  534. }
  535. static void pnv_php_register(struct device_node *dn)
  536. {
  537. struct device_node *child;
  538. /*
  539. * The parent slots should be registered before their
  540. * child slots.
  541. */
  542. for_each_child_of_node(dn, child) {
  543. pnv_php_register_one(child);
  544. pnv_php_register(child);
  545. }
  546. }
  547. static void pnv_php_unregister_one(struct device_node *dn)
  548. {
  549. struct pnv_php_slot *php_slot;
  550. php_slot = pnv_php_find_slot(dn);
  551. if (!php_slot)
  552. return;
  553. php_slot->state = PNV_PHP_STATE_OFFLINE;
  554. pnv_php_put_slot(php_slot);
  555. pci_hp_deregister(&php_slot->slot);
  556. }
  557. static void pnv_php_unregister(struct device_node *dn)
  558. {
  559. struct device_node *child;
  560. /* The child slots should go before their parent slots */
  561. for_each_child_of_node(dn, child) {
  562. pnv_php_unregister(child);
  563. pnv_php_unregister_one(child);
  564. }
  565. }
  566. static int __init pnv_php_init(void)
  567. {
  568. struct device_node *dn;
  569. pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  570. for_each_compatible_node(dn, NULL, "ibm,ioda2-phb")
  571. pnv_php_register(dn);
  572. return 0;
  573. }
  574. static void __exit pnv_php_exit(void)
  575. {
  576. struct device_node *dn;
  577. for_each_compatible_node(dn, NULL, "ibm,ioda2-phb")
  578. pnv_php_unregister(dn);
  579. }
  580. module_init(pnv_php_init);
  581. module_exit(pnv_php_exit);
  582. MODULE_VERSION(DRIVER_VERSION);
  583. MODULE_LICENSE("GPL v2");
  584. MODULE_AUTHOR(DRIVER_AUTHOR);
  585. MODULE_DESCRIPTION(DRIVER_DESC);