eeh_pseries.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * The file intends to implement the platform dependent EEH operations on pseries.
  3. * Actually, the pseries platform is built based on RTAS heavily. That means the
  4. * pseries platform dependent EEH operations will be built on RTAS calls. The functions
  5. * are devired from arch/powerpc/platforms/pseries/eeh.c and necessary cleanup has
  6. * been done.
  7. *
  8. * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2011.
  9. * Copyright IBM Corporation 2001, 2005, 2006
  10. * Copyright Dave Engebretsen & Todd Inglett 2001
  11. * Copyright Linas Vepstas 2005, 2006
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <linux/atomic.h>
  28. #include <linux/delay.h>
  29. #include <linux/export.h>
  30. #include <linux/init.h>
  31. #include <linux/list.h>
  32. #include <linux/of.h>
  33. #include <linux/pci.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/rbtree.h>
  36. #include <linux/sched.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/spinlock.h>
  39. #include <asm/eeh.h>
  40. #include <asm/eeh_event.h>
  41. #include <asm/io.h>
  42. #include <asm/machdep.h>
  43. #include <asm/ppc-pci.h>
  44. #include <asm/rtas.h>
  45. /* RTAS tokens */
  46. static int ibm_set_eeh_option;
  47. static int ibm_set_slot_reset;
  48. static int ibm_read_slot_reset_state;
  49. static int ibm_read_slot_reset_state2;
  50. static int ibm_slot_error_detail;
  51. static int ibm_get_config_addr_info;
  52. static int ibm_get_config_addr_info2;
  53. static int ibm_configure_bridge;
  54. static int ibm_configure_pe;
  55. /*
  56. * Buffer for reporting slot-error-detail rtas calls. Its here
  57. * in BSS, and not dynamically alloced, so that it ends up in
  58. * RMO where RTAS can access it.
  59. */
  60. static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
  61. static DEFINE_SPINLOCK(slot_errbuf_lock);
  62. static int eeh_error_buf_size;
  63. /**
  64. * pseries_eeh_init - EEH platform dependent initialization
  65. *
  66. * EEH platform dependent initialization on pseries.
  67. */
  68. static int pseries_eeh_init(void)
  69. {
  70. /* figure out EEH RTAS function call tokens */
  71. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  72. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  73. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  74. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  75. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  76. ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
  77. ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
  78. ibm_configure_pe = rtas_token("ibm,configure-pe");
  79. ibm_configure_bridge = rtas_token("ibm,configure-bridge");
  80. /*
  81. * Necessary sanity check. We needn't check "get-config-addr-info"
  82. * and its variant since the old firmware probably support address
  83. * of domain/bus/slot/function for EEH RTAS operations.
  84. */
  85. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE) {
  86. pr_warning("%s: RTAS service <ibm,set-eeh-option> invalid\n",
  87. __func__);
  88. return -EINVAL;
  89. } else if (ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE) {
  90. pr_warning("%s: RTAS service <ibm,set-slot-reset> invalid\n",
  91. __func__);
  92. return -EINVAL;
  93. } else if (ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE &&
  94. ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) {
  95. pr_warning("%s: RTAS service <ibm,read-slot-reset-state2> and "
  96. "<ibm,read-slot-reset-state> invalid\n",
  97. __func__);
  98. return -EINVAL;
  99. } else if (ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE) {
  100. pr_warning("%s: RTAS service <ibm,slot-error-detail> invalid\n",
  101. __func__);
  102. return -EINVAL;
  103. } else if (ibm_configure_pe == RTAS_UNKNOWN_SERVICE &&
  104. ibm_configure_bridge == RTAS_UNKNOWN_SERVICE) {
  105. pr_warning("%s: RTAS service <ibm,configure-pe> and "
  106. "<ibm,configure-bridge> invalid\n",
  107. __func__);
  108. return -EINVAL;
  109. }
  110. /* Initialize error log lock and size */
  111. spin_lock_init(&slot_errbuf_lock);
  112. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  113. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  114. pr_warning("%s: unknown EEH error log size\n",
  115. __func__);
  116. eeh_error_buf_size = 1024;
  117. } else if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  118. pr_warning("%s: EEH error log size %d exceeds the maximal %d\n",
  119. __func__, eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  120. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  121. }
  122. /* Set EEH probe mode */
  123. eeh_probe_mode_set(EEH_PROBE_MODE_DEVTREE);
  124. return 0;
  125. }
  126. /**
  127. * pseries_eeh_of_probe - EEH probe on the given device
  128. * @dn: OF node
  129. * @flag: Unused
  130. *
  131. * When EEH module is installed during system boot, all PCI devices
  132. * are checked one by one to see if it supports EEH. The function
  133. * is introduced for the purpose.
  134. */
  135. static void *pseries_eeh_of_probe(struct device_node *dn, void *flag)
  136. {
  137. struct eeh_dev *edev;
  138. struct eeh_pe pe;
  139. const u32 *class_code, *vendor_id, *device_id;
  140. const u32 *regs;
  141. int enable = 0;
  142. int ret;
  143. /* Retrieve OF node and eeh device */
  144. edev = of_node_to_eeh_dev(dn);
  145. if (!of_device_is_available(dn))
  146. return NULL;
  147. /* Retrieve class/vendor/device IDs */
  148. class_code = of_get_property(dn, "class-code", NULL);
  149. vendor_id = of_get_property(dn, "vendor-id", NULL);
  150. device_id = of_get_property(dn, "device-id", NULL);
  151. /* Skip for bad OF node or PCI-ISA bridge */
  152. if (!class_code || !vendor_id || !device_id)
  153. return NULL;
  154. if (dn->type && !strcmp(dn->type, "isa"))
  155. return NULL;
  156. /* Update class code and mode of eeh device */
  157. edev->class_code = *class_code;
  158. edev->mode = 0;
  159. /* Retrieve the device address */
  160. regs = of_get_property(dn, "reg", NULL);
  161. if (!regs) {
  162. pr_warning("%s: OF node property %s::reg not found\n",
  163. __func__, dn->full_name);
  164. return NULL;
  165. }
  166. /* Initialize the fake PE */
  167. memset(&pe, 0, sizeof(struct eeh_pe));
  168. pe.phb = edev->phb;
  169. pe.config_addr = regs[0];
  170. /* Enable EEH on the device */
  171. ret = eeh_ops->set_option(&pe, EEH_OPT_ENABLE);
  172. if (!ret) {
  173. edev->config_addr = regs[0];
  174. /* Retrieve PE address */
  175. edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
  176. pe.addr = edev->pe_config_addr;
  177. /* Some older systems (Power4) allow the ibm,set-eeh-option
  178. * call to succeed even on nodes where EEH is not supported.
  179. * Verify support explicitly.
  180. */
  181. ret = eeh_ops->get_state(&pe, NULL);
  182. if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
  183. enable = 1;
  184. if (enable) {
  185. eeh_subsystem_enabled = 1;
  186. eeh_add_to_parent_pe(edev);
  187. pr_debug("%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n",
  188. __func__, dn->full_name, pe.phb->global_number,
  189. pe.addr, pe.config_addr);
  190. } else if (dn->parent && of_node_to_eeh_dev(dn->parent) &&
  191. (of_node_to_eeh_dev(dn->parent))->pe) {
  192. /* This device doesn't support EEH, but it may have an
  193. * EEH parent, in which case we mark it as supported.
  194. */
  195. edev->config_addr = of_node_to_eeh_dev(dn->parent)->config_addr;
  196. edev->pe_config_addr = of_node_to_eeh_dev(dn->parent)->pe_config_addr;
  197. eeh_add_to_parent_pe(edev);
  198. }
  199. }
  200. /* Save memory bars */
  201. eeh_save_bars(edev);
  202. return NULL;
  203. }
  204. /**
  205. * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
  206. * @pe: EEH PE
  207. * @option: operation to be issued
  208. *
  209. * The function is used to control the EEH functionality globally.
  210. * Currently, following options are support according to PAPR:
  211. * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
  212. */
  213. static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  214. {
  215. int ret = 0;
  216. int config_addr;
  217. /*
  218. * When we're enabling or disabling EEH functioality on
  219. * the particular PE, the PE config address is possibly
  220. * unavailable. Therefore, we have to figure it out from
  221. * the FDT node.
  222. */
  223. switch (option) {
  224. case EEH_OPT_DISABLE:
  225. case EEH_OPT_ENABLE:
  226. case EEH_OPT_THAW_MMIO:
  227. case EEH_OPT_THAW_DMA:
  228. config_addr = pe->config_addr;
  229. if (pe->addr)
  230. config_addr = pe->addr;
  231. break;
  232. default:
  233. pr_err("%s: Invalid option %d\n",
  234. __func__, option);
  235. return -EINVAL;
  236. }
  237. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  238. config_addr, BUID_HI(pe->phb->buid),
  239. BUID_LO(pe->phb->buid), option);
  240. return ret;
  241. }
  242. /**
  243. * pseries_eeh_get_pe_addr - Retrieve PE address
  244. * @pe: EEH PE
  245. *
  246. * Retrieve the assocated PE address. Actually, there're 2 RTAS
  247. * function calls dedicated for the purpose. We need implement
  248. * it through the new function and then the old one. Besides,
  249. * you should make sure the config address is figured out from
  250. * FDT node before calling the function.
  251. *
  252. * It's notable that zero'ed return value means invalid PE config
  253. * address.
  254. */
  255. static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
  256. {
  257. int ret = 0;
  258. int rets[3];
  259. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  260. /*
  261. * First of all, we need to make sure there has one PE
  262. * associated with the device. Otherwise, PE address is
  263. * meaningless.
  264. */
  265. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  266. pe->config_addr, BUID_HI(pe->phb->buid),
  267. BUID_LO(pe->phb->buid), 1);
  268. if (ret || (rets[0] == 0))
  269. return 0;
  270. /* Retrieve the associated PE config address */
  271. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  272. pe->config_addr, BUID_HI(pe->phb->buid),
  273. BUID_LO(pe->phb->buid), 0);
  274. if (ret) {
  275. pr_warning("%s: Failed to get address for PHB#%d-PE#%x\n",
  276. __func__, pe->phb->global_number, pe->config_addr);
  277. return 0;
  278. }
  279. return rets[0];
  280. }
  281. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  282. ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
  283. pe->config_addr, BUID_HI(pe->phb->buid),
  284. BUID_LO(pe->phb->buid), 0);
  285. if (ret) {
  286. pr_warning("%s: Failed to get address for PHB#%d-PE#%x\n",
  287. __func__, pe->phb->global_number, pe->config_addr);
  288. return 0;
  289. }
  290. return rets[0];
  291. }
  292. return ret;
  293. }
  294. /**
  295. * pseries_eeh_get_state - Retrieve PE state
  296. * @pe: EEH PE
  297. * @state: return value
  298. *
  299. * Retrieve the state of the specified PE. On RTAS compliant
  300. * pseries platform, there already has one dedicated RTAS function
  301. * for the purpose. It's notable that the associated PE config address
  302. * might be ready when calling the function. Therefore, endeavour to
  303. * use the PE config address if possible. Further more, there're 2
  304. * RTAS calls for the purpose, we need to try the new one and back
  305. * to the old one if the new one couldn't work properly.
  306. */
  307. static int pseries_eeh_get_state(struct eeh_pe *pe, int *state)
  308. {
  309. int config_addr;
  310. int ret;
  311. int rets[4];
  312. int result;
  313. /* Figure out PE config address if possible */
  314. config_addr = pe->config_addr;
  315. if (pe->addr)
  316. config_addr = pe->addr;
  317. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  318. ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
  319. config_addr, BUID_HI(pe->phb->buid),
  320. BUID_LO(pe->phb->buid));
  321. } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
  322. /* Fake PE unavailable info */
  323. rets[2] = 0;
  324. ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
  325. config_addr, BUID_HI(pe->phb->buid),
  326. BUID_LO(pe->phb->buid));
  327. } else {
  328. return EEH_STATE_NOT_SUPPORT;
  329. }
  330. if (ret)
  331. return ret;
  332. /* Parse the result out */
  333. result = 0;
  334. if (rets[1]) {
  335. switch(rets[0]) {
  336. case 0:
  337. result &= ~EEH_STATE_RESET_ACTIVE;
  338. result |= EEH_STATE_MMIO_ACTIVE;
  339. result |= EEH_STATE_DMA_ACTIVE;
  340. break;
  341. case 1:
  342. result |= EEH_STATE_RESET_ACTIVE;
  343. result |= EEH_STATE_MMIO_ACTIVE;
  344. result |= EEH_STATE_DMA_ACTIVE;
  345. break;
  346. case 2:
  347. result &= ~EEH_STATE_RESET_ACTIVE;
  348. result &= ~EEH_STATE_MMIO_ACTIVE;
  349. result &= ~EEH_STATE_DMA_ACTIVE;
  350. break;
  351. case 4:
  352. result &= ~EEH_STATE_RESET_ACTIVE;
  353. result &= ~EEH_STATE_MMIO_ACTIVE;
  354. result &= ~EEH_STATE_DMA_ACTIVE;
  355. result |= EEH_STATE_MMIO_ENABLED;
  356. break;
  357. case 5:
  358. if (rets[2]) {
  359. if (state) *state = rets[2];
  360. result = EEH_STATE_UNAVAILABLE;
  361. } else {
  362. result = EEH_STATE_NOT_SUPPORT;
  363. }
  364. default:
  365. result = EEH_STATE_NOT_SUPPORT;
  366. }
  367. } else {
  368. result = EEH_STATE_NOT_SUPPORT;
  369. }
  370. return result;
  371. }
  372. /**
  373. * pseries_eeh_reset - Reset the specified PE
  374. * @pe: EEH PE
  375. * @option: reset option
  376. *
  377. * Reset the specified PE
  378. */
  379. static int pseries_eeh_reset(struct eeh_pe *pe, int option)
  380. {
  381. int config_addr;
  382. int ret;
  383. /* Figure out PE address */
  384. config_addr = pe->config_addr;
  385. if (pe->addr)
  386. config_addr = pe->addr;
  387. /* Reset PE through RTAS call */
  388. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  389. config_addr, BUID_HI(pe->phb->buid),
  390. BUID_LO(pe->phb->buid), option);
  391. /* If fundamental-reset not supported, try hot-reset */
  392. if (option == EEH_RESET_FUNDAMENTAL &&
  393. ret == -8) {
  394. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  395. config_addr, BUID_HI(pe->phb->buid),
  396. BUID_LO(pe->phb->buid), EEH_RESET_HOT);
  397. }
  398. return ret;
  399. }
  400. /**
  401. * pseries_eeh_wait_state - Wait for PE state
  402. * @pe: EEH PE
  403. * @max_wait: maximal period in microsecond
  404. *
  405. * Wait for the state of associated PE. It might take some time
  406. * to retrieve the PE's state.
  407. */
  408. static int pseries_eeh_wait_state(struct eeh_pe *pe, int max_wait)
  409. {
  410. int ret;
  411. int mwait;
  412. /*
  413. * According to PAPR, the state of PE might be temporarily
  414. * unavailable. Under the circumstance, we have to wait
  415. * for indicated time determined by firmware. The maximal
  416. * wait time is 5 minutes, which is acquired from the original
  417. * EEH implementation. Also, the original implementation
  418. * also defined the minimal wait time as 1 second.
  419. */
  420. #define EEH_STATE_MIN_WAIT_TIME (1000)
  421. #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
  422. while (1) {
  423. ret = pseries_eeh_get_state(pe, &mwait);
  424. /*
  425. * If the PE's state is temporarily unavailable,
  426. * we have to wait for the specified time. Otherwise,
  427. * the PE's state will be returned immediately.
  428. */
  429. if (ret != EEH_STATE_UNAVAILABLE)
  430. return ret;
  431. if (max_wait <= 0) {
  432. pr_warning("%s: Timeout when getting PE's state (%d)\n",
  433. __func__, max_wait);
  434. return EEH_STATE_NOT_SUPPORT;
  435. }
  436. if (mwait <= 0) {
  437. pr_warning("%s: Firmware returned bad wait value %d\n",
  438. __func__, mwait);
  439. mwait = EEH_STATE_MIN_WAIT_TIME;
  440. } else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
  441. pr_warning("%s: Firmware returned too long wait value %d\n",
  442. __func__, mwait);
  443. mwait = EEH_STATE_MAX_WAIT_TIME;
  444. }
  445. max_wait -= mwait;
  446. msleep(mwait);
  447. }
  448. return EEH_STATE_NOT_SUPPORT;
  449. }
  450. /**
  451. * pseries_eeh_get_log - Retrieve error log
  452. * @pe: EEH PE
  453. * @severity: temporary or permanent error log
  454. * @drv_log: driver log to be combined with retrieved error log
  455. * @len: length of driver log
  456. *
  457. * Retrieve the temporary or permanent error from the PE.
  458. * Actually, the error will be retrieved through the dedicated
  459. * RTAS call.
  460. */
  461. static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len)
  462. {
  463. int config_addr;
  464. unsigned long flags;
  465. int ret;
  466. spin_lock_irqsave(&slot_errbuf_lock, flags);
  467. memset(slot_errbuf, 0, eeh_error_buf_size);
  468. /* Figure out the PE address */
  469. config_addr = pe->config_addr;
  470. if (pe->addr)
  471. config_addr = pe->addr;
  472. ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, config_addr,
  473. BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid),
  474. virt_to_phys(drv_log), len,
  475. virt_to_phys(slot_errbuf), eeh_error_buf_size,
  476. severity);
  477. if (!ret)
  478. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  479. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  480. return ret;
  481. }
  482. /**
  483. * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE
  484. * @pe: EEH PE
  485. *
  486. * The function will be called to reconfigure the bridges included
  487. * in the specified PE so that the mulfunctional PE would be recovered
  488. * again.
  489. */
  490. static int pseries_eeh_configure_bridge(struct eeh_pe *pe)
  491. {
  492. int config_addr;
  493. int ret;
  494. /* Figure out the PE address */
  495. config_addr = pe->config_addr;
  496. if (pe->addr)
  497. config_addr = pe->addr;
  498. /* Use new configure-pe function, if supported */
  499. if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) {
  500. ret = rtas_call(ibm_configure_pe, 3, 1, NULL,
  501. config_addr, BUID_HI(pe->phb->buid),
  502. BUID_LO(pe->phb->buid));
  503. } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) {
  504. ret = rtas_call(ibm_configure_bridge, 3, 1, NULL,
  505. config_addr, BUID_HI(pe->phb->buid),
  506. BUID_LO(pe->phb->buid));
  507. } else {
  508. return -EFAULT;
  509. }
  510. if (ret)
  511. pr_warning("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n",
  512. __func__, pe->phb->global_number, pe->addr, ret);
  513. return ret;
  514. }
  515. /**
  516. * pseries_eeh_read_config - Read PCI config space
  517. * @dn: device node
  518. * @where: PCI address
  519. * @size: size to read
  520. * @val: return value
  521. *
  522. * Read config space from the speicifed device
  523. */
  524. static int pseries_eeh_read_config(struct device_node *dn, int where, int size, u32 *val)
  525. {
  526. struct pci_dn *pdn;
  527. pdn = PCI_DN(dn);
  528. return rtas_read_config(pdn, where, size, val);
  529. }
  530. /**
  531. * pseries_eeh_write_config - Write PCI config space
  532. * @dn: device node
  533. * @where: PCI address
  534. * @size: size to write
  535. * @val: value to be written
  536. *
  537. * Write config space to the specified device
  538. */
  539. static int pseries_eeh_write_config(struct device_node *dn, int where, int size, u32 val)
  540. {
  541. struct pci_dn *pdn;
  542. pdn = PCI_DN(dn);
  543. return rtas_write_config(pdn, where, size, val);
  544. }
  545. static struct eeh_ops pseries_eeh_ops = {
  546. .name = "pseries",
  547. .init = pseries_eeh_init,
  548. .of_probe = pseries_eeh_of_probe,
  549. .dev_probe = NULL,
  550. .set_option = pseries_eeh_set_option,
  551. .get_pe_addr = pseries_eeh_get_pe_addr,
  552. .get_state = pseries_eeh_get_state,
  553. .reset = pseries_eeh_reset,
  554. .wait_state = pseries_eeh_wait_state,
  555. .get_log = pseries_eeh_get_log,
  556. .configure_bridge = pseries_eeh_configure_bridge,
  557. .read_config = pseries_eeh_read_config,
  558. .write_config = pseries_eeh_write_config
  559. };
  560. /**
  561. * eeh_pseries_init - Register platform dependent EEH operations
  562. *
  563. * EEH initialization on pseries platform. This function should be
  564. * called before any EEH related functions.
  565. */
  566. static int __init eeh_pseries_init(void)
  567. {
  568. int ret = -EINVAL;
  569. if (!machine_is(pseries))
  570. return ret;
  571. ret = eeh_ops_register(&pseries_eeh_ops);
  572. if (!ret)
  573. pr_info("EEH: pSeries platform initialized\n");
  574. else
  575. pr_info("EEH: pSeries platform initialization failure (%d)\n",
  576. ret);
  577. return ret;
  578. }
  579. early_initcall(eeh_pseries_init);