pnv_php.c 17 KB

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