repository.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. /*
  2. * PS3 repository routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <asm/lv1call.h>
  21. #include "platform.h"
  22. enum ps3_vendor_id {
  23. PS3_VENDOR_ID_NONE = 0,
  24. PS3_VENDOR_ID_SONY = 0x8000000000000000UL,
  25. };
  26. enum ps3_lpar_id {
  27. PS3_LPAR_ID_CURRENT = 0,
  28. PS3_LPAR_ID_PME = 1,
  29. };
  30. #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
  31. static void _dump_field(const char *hdr, u64 n, const char *func, int line)
  32. {
  33. #if defined(DEBUG)
  34. char s[16];
  35. const char *const in = (const char *)&n;
  36. unsigned int i;
  37. for (i = 0; i < 8; i++)
  38. s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
  39. s[i] = 0;
  40. pr_devel("%s:%d: %s%016llx : %s\n", func, line, hdr, n, s);
  41. #endif
  42. }
  43. #define dump_node_name(_a, _b, _c, _d, _e) \
  44. _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
  45. static void _dump_node_name(unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
  46. u64 n4, const char *func, int line)
  47. {
  48. pr_devel("%s:%d: lpar: %u\n", func, line, lpar_id);
  49. _dump_field("n1: ", n1, func, line);
  50. _dump_field("n2: ", n2, func, line);
  51. _dump_field("n3: ", n3, func, line);
  52. _dump_field("n4: ", n4, func, line);
  53. }
  54. #define dump_node(_a, _b, _c, _d, _e, _f, _g) \
  55. _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
  56. static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
  57. u64 v1, u64 v2, const char *func, int line)
  58. {
  59. pr_devel("%s:%d: lpar: %u\n", func, line, lpar_id);
  60. _dump_field("n1: ", n1, func, line);
  61. _dump_field("n2: ", n2, func, line);
  62. _dump_field("n3: ", n3, func, line);
  63. _dump_field("n4: ", n4, func, line);
  64. pr_devel("%s:%d: v1: %016llx\n", func, line, v1);
  65. pr_devel("%s:%d: v2: %016llx\n", func, line, v2);
  66. }
  67. /**
  68. * make_first_field - Make the first field of a repository node name.
  69. * @text: Text portion of the field.
  70. * @index: Numeric index portion of the field. Use zero for 'don't care'.
  71. *
  72. * This routine sets the vendor id to zero (non-vendor specific).
  73. * Returns field value.
  74. */
  75. static u64 make_first_field(const char *text, u64 index)
  76. {
  77. u64 n;
  78. strncpy((char *)&n, text, 8);
  79. return PS3_VENDOR_ID_NONE + (n >> 32) + index;
  80. }
  81. /**
  82. * make_field - Make subsequent fields of a repository node name.
  83. * @text: Text portion of the field. Use "" for 'don't care'.
  84. * @index: Numeric index portion of the field. Use zero for 'don't care'.
  85. *
  86. * Returns field value.
  87. */
  88. static u64 make_field(const char *text, u64 index)
  89. {
  90. u64 n;
  91. strncpy((char *)&n, text, 8);
  92. return n + index;
  93. }
  94. /**
  95. * read_node - Read a repository node from raw fields.
  96. * @n1: First field of node name.
  97. * @n2: Second field of node name. Use zero for 'don't care'.
  98. * @n3: Third field of node name. Use zero for 'don't care'.
  99. * @n4: Fourth field of node name. Use zero for 'don't care'.
  100. * @v1: First repository value (high word).
  101. * @v2: Second repository value (low word). Optional parameter, use zero
  102. * for 'don't care'.
  103. */
  104. static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
  105. u64 *_v1, u64 *_v2)
  106. {
  107. int result;
  108. u64 v1;
  109. u64 v2;
  110. if (lpar_id == PS3_LPAR_ID_CURRENT) {
  111. u64 id;
  112. lv1_get_logical_partition_id(&id);
  113. lpar_id = id;
  114. }
  115. result = lv1_read_repository_node(lpar_id, n1, n2, n3, n4, &v1,
  116. &v2);
  117. if (result) {
  118. pr_warn("%s:%d: lv1_read_repository_node failed: %s\n",
  119. __func__, __LINE__, ps3_result(result));
  120. dump_node_name(lpar_id, n1, n2, n3, n4);
  121. return -ENOENT;
  122. }
  123. dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
  124. if (_v1)
  125. *_v1 = v1;
  126. if (_v2)
  127. *_v2 = v2;
  128. if (v1 && !_v1)
  129. pr_devel("%s:%d: warning: discarding non-zero v1: %016llx\n",
  130. __func__, __LINE__, v1);
  131. if (v2 && !_v2)
  132. pr_devel("%s:%d: warning: discarding non-zero v2: %016llx\n",
  133. __func__, __LINE__, v2);
  134. return 0;
  135. }
  136. int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
  137. u64 *value)
  138. {
  139. return read_node(PS3_LPAR_ID_PME,
  140. make_first_field("bus", bus_index),
  141. make_field(bus_str, 0),
  142. 0, 0,
  143. value, NULL);
  144. }
  145. int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id)
  146. {
  147. int result;
  148. result = read_node(PS3_LPAR_ID_PME,
  149. make_first_field("bus", bus_index),
  150. make_field("id", 0),
  151. 0, 0,
  152. bus_id, NULL);
  153. return result;
  154. }
  155. int ps3_repository_read_bus_type(unsigned int bus_index,
  156. enum ps3_bus_type *bus_type)
  157. {
  158. int result;
  159. u64 v1 = 0;
  160. result = read_node(PS3_LPAR_ID_PME,
  161. make_first_field("bus", bus_index),
  162. make_field("type", 0),
  163. 0, 0,
  164. &v1, NULL);
  165. *bus_type = v1;
  166. return result;
  167. }
  168. int ps3_repository_read_bus_num_dev(unsigned int bus_index,
  169. unsigned int *num_dev)
  170. {
  171. int result;
  172. u64 v1 = 0;
  173. result = read_node(PS3_LPAR_ID_PME,
  174. make_first_field("bus", bus_index),
  175. make_field("num_dev", 0),
  176. 0, 0,
  177. &v1, NULL);
  178. *num_dev = v1;
  179. return result;
  180. }
  181. int ps3_repository_read_dev_str(unsigned int bus_index,
  182. unsigned int dev_index, const char *dev_str, u64 *value)
  183. {
  184. return read_node(PS3_LPAR_ID_PME,
  185. make_first_field("bus", bus_index),
  186. make_field("dev", dev_index),
  187. make_field(dev_str, 0),
  188. 0,
  189. value, NULL);
  190. }
  191. int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
  192. u64 *dev_id)
  193. {
  194. int result;
  195. result = read_node(PS3_LPAR_ID_PME,
  196. make_first_field("bus", bus_index),
  197. make_field("dev", dev_index),
  198. make_field("id", 0),
  199. 0,
  200. dev_id, NULL);
  201. return result;
  202. }
  203. int ps3_repository_read_dev_type(unsigned int bus_index,
  204. unsigned int dev_index, enum ps3_dev_type *dev_type)
  205. {
  206. int result;
  207. u64 v1 = 0;
  208. result = read_node(PS3_LPAR_ID_PME,
  209. make_first_field("bus", bus_index),
  210. make_field("dev", dev_index),
  211. make_field("type", 0),
  212. 0,
  213. &v1, NULL);
  214. *dev_type = v1;
  215. return result;
  216. }
  217. int ps3_repository_read_dev_intr(unsigned int bus_index,
  218. unsigned int dev_index, unsigned int intr_index,
  219. enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id)
  220. {
  221. int result;
  222. u64 v1 = 0;
  223. u64 v2 = 0;
  224. result = read_node(PS3_LPAR_ID_PME,
  225. make_first_field("bus", bus_index),
  226. make_field("dev", dev_index),
  227. make_field("intr", intr_index),
  228. 0,
  229. &v1, &v2);
  230. *intr_type = v1;
  231. *interrupt_id = v2;
  232. return result;
  233. }
  234. int ps3_repository_read_dev_reg_type(unsigned int bus_index,
  235. unsigned int dev_index, unsigned int reg_index,
  236. enum ps3_reg_type *reg_type)
  237. {
  238. int result;
  239. u64 v1 = 0;
  240. result = read_node(PS3_LPAR_ID_PME,
  241. make_first_field("bus", bus_index),
  242. make_field("dev", dev_index),
  243. make_field("reg", reg_index),
  244. make_field("type", 0),
  245. &v1, NULL);
  246. *reg_type = v1;
  247. return result;
  248. }
  249. int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
  250. unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
  251. {
  252. return read_node(PS3_LPAR_ID_PME,
  253. make_first_field("bus", bus_index),
  254. make_field("dev", dev_index),
  255. make_field("reg", reg_index),
  256. make_field("data", 0),
  257. bus_addr, len);
  258. }
  259. int ps3_repository_read_dev_reg(unsigned int bus_index,
  260. unsigned int dev_index, unsigned int reg_index,
  261. enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
  262. {
  263. int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
  264. reg_index, reg_type);
  265. return result ? result
  266. : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
  267. reg_index, bus_addr, len);
  268. }
  269. int ps3_repository_find_device(struct ps3_repository_device *repo)
  270. {
  271. int result;
  272. struct ps3_repository_device tmp = *repo;
  273. unsigned int num_dev;
  274. BUG_ON(repo->bus_index > 10);
  275. BUG_ON(repo->dev_index > 10);
  276. result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
  277. if (result) {
  278. pr_devel("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
  279. return result;
  280. }
  281. pr_devel("%s:%d: bus_type %u, bus_index %u, bus_id %llu, num_dev %u\n",
  282. __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
  283. num_dev);
  284. if (tmp.dev_index >= num_dev) {
  285. pr_devel("%s:%d: no device found\n", __func__, __LINE__);
  286. return -ENODEV;
  287. }
  288. result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
  289. &tmp.dev_type);
  290. if (result) {
  291. pr_devel("%s:%d read_dev_type failed\n", __func__, __LINE__);
  292. return result;
  293. }
  294. result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
  295. &tmp.dev_id);
  296. if (result) {
  297. pr_devel("%s:%d ps3_repository_read_dev_id failed\n", __func__,
  298. __LINE__);
  299. return result;
  300. }
  301. pr_devel("%s:%d: found: dev_type %u, dev_index %u, dev_id %llu\n",
  302. __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
  303. *repo = tmp;
  304. return 0;
  305. }
  306. int ps3_repository_find_device_by_id(struct ps3_repository_device *repo,
  307. u64 bus_id, u64 dev_id)
  308. {
  309. int result = -ENODEV;
  310. struct ps3_repository_device tmp;
  311. unsigned int num_dev;
  312. pr_devel(" -> %s:%u: find device by id %llu:%llu\n", __func__, __LINE__,
  313. bus_id, dev_id);
  314. for (tmp.bus_index = 0; tmp.bus_index < 10; tmp.bus_index++) {
  315. result = ps3_repository_read_bus_id(tmp.bus_index,
  316. &tmp.bus_id);
  317. if (result) {
  318. pr_devel("%s:%u read_bus_id(%u) failed\n", __func__,
  319. __LINE__, tmp.bus_index);
  320. return result;
  321. }
  322. if (tmp.bus_id == bus_id)
  323. goto found_bus;
  324. pr_devel("%s:%u: skip, bus_id %llu\n", __func__, __LINE__,
  325. tmp.bus_id);
  326. }
  327. pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__);
  328. return result;
  329. found_bus:
  330. result = ps3_repository_read_bus_type(tmp.bus_index, &tmp.bus_type);
  331. if (result) {
  332. pr_devel("%s:%u read_bus_type(%u) failed\n", __func__,
  333. __LINE__, tmp.bus_index);
  334. return result;
  335. }
  336. result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
  337. if (result) {
  338. pr_devel("%s:%u read_bus_num_dev failed\n", __func__,
  339. __LINE__);
  340. return result;
  341. }
  342. for (tmp.dev_index = 0; tmp.dev_index < num_dev; tmp.dev_index++) {
  343. result = ps3_repository_read_dev_id(tmp.bus_index,
  344. tmp.dev_index,
  345. &tmp.dev_id);
  346. if (result) {
  347. pr_devel("%s:%u read_dev_id(%u:%u) failed\n", __func__,
  348. __LINE__, tmp.bus_index, tmp.dev_index);
  349. return result;
  350. }
  351. if (tmp.dev_id == dev_id)
  352. goto found_dev;
  353. pr_devel("%s:%u: skip, dev_id %llu\n", __func__, __LINE__,
  354. tmp.dev_id);
  355. }
  356. pr_devel(" <- %s:%u: dev not found\n", __func__, __LINE__);
  357. return result;
  358. found_dev:
  359. result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
  360. &tmp.dev_type);
  361. if (result) {
  362. pr_devel("%s:%u read_dev_type failed\n", __func__, __LINE__);
  363. return result;
  364. }
  365. pr_devel(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%llu:%llu)\n",
  366. __func__, __LINE__, tmp.bus_type, tmp.dev_type, tmp.bus_index,
  367. tmp.dev_index, tmp.bus_id, tmp.dev_id);
  368. *repo = tmp;
  369. return 0;
  370. }
  371. int ps3_repository_find_devices(enum ps3_bus_type bus_type,
  372. int (*callback)(const struct ps3_repository_device *repo))
  373. {
  374. int result = 0;
  375. struct ps3_repository_device repo;
  376. pr_devel(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
  377. repo.bus_type = bus_type;
  378. result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
  379. if (result) {
  380. pr_devel(" <- %s:%u: bus not found\n", __func__, __LINE__);
  381. return result;
  382. }
  383. result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
  384. if (result) {
  385. pr_devel("%s:%d read_bus_id(%u) failed\n", __func__, __LINE__,
  386. repo.bus_index);
  387. return result;
  388. }
  389. for (repo.dev_index = 0; ; repo.dev_index++) {
  390. result = ps3_repository_find_device(&repo);
  391. if (result == -ENODEV) {
  392. result = 0;
  393. break;
  394. } else if (result)
  395. break;
  396. result = callback(&repo);
  397. if (result) {
  398. pr_devel("%s:%d: abort at callback\n", __func__,
  399. __LINE__);
  400. break;
  401. }
  402. }
  403. pr_devel(" <- %s:%d\n", __func__, __LINE__);
  404. return result;
  405. }
  406. int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
  407. unsigned int *bus_index)
  408. {
  409. unsigned int i;
  410. enum ps3_bus_type type;
  411. int error;
  412. for (i = from; i < 10; i++) {
  413. error = ps3_repository_read_bus_type(i, &type);
  414. if (error) {
  415. pr_devel("%s:%d read_bus_type failed\n",
  416. __func__, __LINE__);
  417. *bus_index = UINT_MAX;
  418. return error;
  419. }
  420. if (type == bus_type) {
  421. *bus_index = i;
  422. return 0;
  423. }
  424. }
  425. *bus_index = UINT_MAX;
  426. return -ENODEV;
  427. }
  428. int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
  429. enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
  430. {
  431. int result = 0;
  432. unsigned int res_index;
  433. pr_devel("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
  434. *interrupt_id = UINT_MAX;
  435. for (res_index = 0; res_index < 10; res_index++) {
  436. enum ps3_interrupt_type t;
  437. unsigned int id;
  438. result = ps3_repository_read_dev_intr(repo->bus_index,
  439. repo->dev_index, res_index, &t, &id);
  440. if (result) {
  441. pr_devel("%s:%d read_dev_intr failed\n",
  442. __func__, __LINE__);
  443. return result;
  444. }
  445. if (t == intr_type) {
  446. *interrupt_id = id;
  447. break;
  448. }
  449. }
  450. if (res_index == 10)
  451. return -ENODEV;
  452. pr_devel("%s:%d: found intr_type %u at res_index %u\n",
  453. __func__, __LINE__, intr_type, res_index);
  454. return result;
  455. }
  456. int ps3_repository_find_reg(const struct ps3_repository_device *repo,
  457. enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
  458. {
  459. int result = 0;
  460. unsigned int res_index;
  461. pr_devel("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
  462. *bus_addr = *len = 0;
  463. for (res_index = 0; res_index < 10; res_index++) {
  464. enum ps3_reg_type t;
  465. u64 a;
  466. u64 l;
  467. result = ps3_repository_read_dev_reg(repo->bus_index,
  468. repo->dev_index, res_index, &t, &a, &l);
  469. if (result) {
  470. pr_devel("%s:%d read_dev_reg failed\n",
  471. __func__, __LINE__);
  472. return result;
  473. }
  474. if (t == reg_type) {
  475. *bus_addr = a;
  476. *len = l;
  477. break;
  478. }
  479. }
  480. if (res_index == 10)
  481. return -ENODEV;
  482. pr_devel("%s:%d: found reg_type %u at res_index %u\n",
  483. __func__, __LINE__, reg_type, res_index);
  484. return result;
  485. }
  486. int ps3_repository_read_stor_dev_port(unsigned int bus_index,
  487. unsigned int dev_index, u64 *port)
  488. {
  489. return read_node(PS3_LPAR_ID_PME,
  490. make_first_field("bus", bus_index),
  491. make_field("dev", dev_index),
  492. make_field("port", 0),
  493. 0, port, NULL);
  494. }
  495. int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
  496. unsigned int dev_index, u64 *blk_size)
  497. {
  498. return read_node(PS3_LPAR_ID_PME,
  499. make_first_field("bus", bus_index),
  500. make_field("dev", dev_index),
  501. make_field("blk_size", 0),
  502. 0, blk_size, NULL);
  503. }
  504. int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
  505. unsigned int dev_index, u64 *num_blocks)
  506. {
  507. return read_node(PS3_LPAR_ID_PME,
  508. make_first_field("bus", bus_index),
  509. make_field("dev", dev_index),
  510. make_field("n_blocks", 0),
  511. 0, num_blocks, NULL);
  512. }
  513. int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
  514. unsigned int dev_index, unsigned int *num_regions)
  515. {
  516. int result;
  517. u64 v1 = 0;
  518. result = read_node(PS3_LPAR_ID_PME,
  519. make_first_field("bus", bus_index),
  520. make_field("dev", dev_index),
  521. make_field("n_regs", 0),
  522. 0, &v1, NULL);
  523. *num_regions = v1;
  524. return result;
  525. }
  526. int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
  527. unsigned int dev_index, unsigned int region_index,
  528. unsigned int *region_id)
  529. {
  530. int result;
  531. u64 v1 = 0;
  532. result = read_node(PS3_LPAR_ID_PME,
  533. make_first_field("bus", bus_index),
  534. make_field("dev", dev_index),
  535. make_field("region", region_index),
  536. make_field("id", 0),
  537. &v1, NULL);
  538. *region_id = v1;
  539. return result;
  540. }
  541. int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
  542. unsigned int dev_index, unsigned int region_index, u64 *region_size)
  543. {
  544. return read_node(PS3_LPAR_ID_PME,
  545. make_first_field("bus", bus_index),
  546. make_field("dev", dev_index),
  547. make_field("region", region_index),
  548. make_field("size", 0),
  549. region_size, NULL);
  550. }
  551. int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
  552. unsigned int dev_index, unsigned int region_index, u64 *region_start)
  553. {
  554. return read_node(PS3_LPAR_ID_PME,
  555. make_first_field("bus", bus_index),
  556. make_field("dev", dev_index),
  557. make_field("region", region_index),
  558. make_field("start", 0),
  559. region_start, NULL);
  560. }
  561. int ps3_repository_read_stor_dev_info(unsigned int bus_index,
  562. unsigned int dev_index, u64 *port, u64 *blk_size,
  563. u64 *num_blocks, unsigned int *num_regions)
  564. {
  565. int result;
  566. result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
  567. if (result)
  568. return result;
  569. result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
  570. blk_size);
  571. if (result)
  572. return result;
  573. result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
  574. num_blocks);
  575. if (result)
  576. return result;
  577. result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
  578. num_regions);
  579. return result;
  580. }
  581. int ps3_repository_read_stor_dev_region(unsigned int bus_index,
  582. unsigned int dev_index, unsigned int region_index,
  583. unsigned int *region_id, u64 *region_start, u64 *region_size)
  584. {
  585. int result;
  586. result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
  587. region_index, region_id);
  588. if (result)
  589. return result;
  590. result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
  591. region_index, region_start);
  592. if (result)
  593. return result;
  594. result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
  595. region_index, region_size);
  596. return result;
  597. }
  598. /**
  599. * ps3_repository_read_num_pu - Number of logical PU processors for this lpar.
  600. */
  601. int ps3_repository_read_num_pu(u64 *num_pu)
  602. {
  603. *num_pu = 0;
  604. return read_node(PS3_LPAR_ID_CURRENT,
  605. make_first_field("bi", 0),
  606. make_field("pun", 0),
  607. 0, 0,
  608. num_pu, NULL);
  609. }
  610. /**
  611. * ps3_repository_read_pu_id - Read the logical PU id.
  612. * @pu_index: Zero based index.
  613. * @pu_id: The logical PU id.
  614. */
  615. int ps3_repository_read_pu_id(unsigned int pu_index, u64 *pu_id)
  616. {
  617. return read_node(PS3_LPAR_ID_CURRENT,
  618. make_first_field("bi", 0),
  619. make_field("pu", pu_index),
  620. 0, 0,
  621. pu_id, NULL);
  622. }
  623. int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
  624. {
  625. return read_node(PS3_LPAR_ID_CURRENT,
  626. make_first_field("bi", 0),
  627. make_field("pu", 0),
  628. ppe_id,
  629. make_field("rm_size", 0),
  630. rm_size, NULL);
  631. }
  632. int ps3_repository_read_region_total(u64 *region_total)
  633. {
  634. return read_node(PS3_LPAR_ID_CURRENT,
  635. make_first_field("bi", 0),
  636. make_field("rgntotal", 0),
  637. 0, 0,
  638. region_total, NULL);
  639. }
  640. /**
  641. * ps3_repository_read_mm_info - Read mm info for single pu system.
  642. * @rm_base: Real mode memory base address.
  643. * @rm_size: Real mode memory size.
  644. * @region_total: Maximum memory region size.
  645. */
  646. int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
  647. {
  648. int result;
  649. u64 ppe_id;
  650. lv1_get_logical_ppe_id(&ppe_id);
  651. *rm_base = 0;
  652. result = ps3_repository_read_rm_size(ppe_id, rm_size);
  653. return result ? result
  654. : ps3_repository_read_region_total(region_total);
  655. }
  656. /**
  657. * ps3_repository_read_highmem_region_count - Read the number of highmem regions
  658. *
  659. * Bootloaders must arrange the repository nodes such that regions are indexed
  660. * with a region_index from 0 to region_count-1.
  661. */
  662. int ps3_repository_read_highmem_region_count(unsigned int *region_count)
  663. {
  664. int result;
  665. u64 v1 = 0;
  666. result = read_node(PS3_LPAR_ID_CURRENT,
  667. make_first_field("highmem", 0),
  668. make_field("region", 0),
  669. make_field("count", 0),
  670. 0,
  671. &v1, NULL);
  672. *region_count = v1;
  673. return result;
  674. }
  675. int ps3_repository_read_highmem_base(unsigned int region_index,
  676. u64 *highmem_base)
  677. {
  678. return read_node(PS3_LPAR_ID_CURRENT,
  679. make_first_field("highmem", 0),
  680. make_field("region", region_index),
  681. make_field("base", 0),
  682. 0,
  683. highmem_base, NULL);
  684. }
  685. int ps3_repository_read_highmem_size(unsigned int region_index,
  686. u64 *highmem_size)
  687. {
  688. return read_node(PS3_LPAR_ID_CURRENT,
  689. make_first_field("highmem", 0),
  690. make_field("region", region_index),
  691. make_field("size", 0),
  692. 0,
  693. highmem_size, NULL);
  694. }
  695. /**
  696. * ps3_repository_read_highmem_info - Read high memory region info
  697. * @region_index: Region index, {0,..,region_count-1}.
  698. * @highmem_base: High memory base address.
  699. * @highmem_size: High memory size.
  700. *
  701. * Bootloaders that preallocate highmem regions must place the
  702. * region info into the repository at these well known nodes.
  703. */
  704. int ps3_repository_read_highmem_info(unsigned int region_index,
  705. u64 *highmem_base, u64 *highmem_size)
  706. {
  707. int result;
  708. *highmem_base = 0;
  709. result = ps3_repository_read_highmem_base(region_index, highmem_base);
  710. return result ? result
  711. : ps3_repository_read_highmem_size(region_index, highmem_size);
  712. }
  713. /**
  714. * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
  715. * @num_spu: Number of physical spus.
  716. */
  717. int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
  718. {
  719. int result;
  720. u64 v1 = 0;
  721. result = read_node(PS3_LPAR_ID_CURRENT,
  722. make_first_field("bi", 0),
  723. make_field("spun", 0),
  724. 0, 0,
  725. &v1, NULL);
  726. *num_spu_reserved = v1;
  727. return result;
  728. }
  729. /**
  730. * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
  731. * @num_resource_id: Number of spu resource ids.
  732. */
  733. int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
  734. {
  735. int result;
  736. u64 v1 = 0;
  737. result = read_node(PS3_LPAR_ID_CURRENT,
  738. make_first_field("bi", 0),
  739. make_field("spursvn", 0),
  740. 0, 0,
  741. &v1, NULL);
  742. *num_resource_id = v1;
  743. return result;
  744. }
  745. /**
  746. * ps3_repository_read_spu_resource_id - spu resource reservation id value.
  747. * @res_index: Resource reservation index.
  748. * @resource_type: Resource reservation type.
  749. * @resource_id: Resource reservation id.
  750. */
  751. int ps3_repository_read_spu_resource_id(unsigned int res_index,
  752. enum ps3_spu_resource_type *resource_type, unsigned int *resource_id)
  753. {
  754. int result;
  755. u64 v1 = 0;
  756. u64 v2 = 0;
  757. result = read_node(PS3_LPAR_ID_CURRENT,
  758. make_first_field("bi", 0),
  759. make_field("spursv", 0),
  760. res_index,
  761. 0,
  762. &v1, &v2);
  763. *resource_type = v1;
  764. *resource_id = v2;
  765. return result;
  766. }
  767. static int ps3_repository_read_boot_dat_address(u64 *address)
  768. {
  769. return read_node(PS3_LPAR_ID_CURRENT,
  770. make_first_field("bi", 0),
  771. make_field("boot_dat", 0),
  772. make_field("address", 0),
  773. 0,
  774. address, NULL);
  775. }
  776. int ps3_repository_read_boot_dat_size(unsigned int *size)
  777. {
  778. int result;
  779. u64 v1 = 0;
  780. result = read_node(PS3_LPAR_ID_CURRENT,
  781. make_first_field("bi", 0),
  782. make_field("boot_dat", 0),
  783. make_field("size", 0),
  784. 0,
  785. &v1, NULL);
  786. *size = v1;
  787. return result;
  788. }
  789. int ps3_repository_read_vuart_av_port(unsigned int *port)
  790. {
  791. int result;
  792. u64 v1 = 0;
  793. result = read_node(PS3_LPAR_ID_CURRENT,
  794. make_first_field("bi", 0),
  795. make_field("vir_uart", 0),
  796. make_field("port", 0),
  797. make_field("avset", 0),
  798. &v1, NULL);
  799. *port = v1;
  800. return result;
  801. }
  802. int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
  803. {
  804. int result;
  805. u64 v1 = 0;
  806. result = read_node(PS3_LPAR_ID_CURRENT,
  807. make_first_field("bi", 0),
  808. make_field("vir_uart", 0),
  809. make_field("port", 0),
  810. make_field("sysmgr", 0),
  811. &v1, NULL);
  812. *port = v1;
  813. return result;
  814. }
  815. /**
  816. * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
  817. * address: lpar address of cell_ext_os_area
  818. * @size: size of cell_ext_os_area
  819. */
  820. int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
  821. {
  822. int result;
  823. *size = 0;
  824. result = ps3_repository_read_boot_dat_address(lpar_addr);
  825. return result ? result
  826. : ps3_repository_read_boot_dat_size(size);
  827. }
  828. /**
  829. * ps3_repository_read_num_be - Number of physical BE processors in the system.
  830. */
  831. int ps3_repository_read_num_be(unsigned int *num_be)
  832. {
  833. int result;
  834. u64 v1 = 0;
  835. result = read_node(PS3_LPAR_ID_PME,
  836. make_first_field("ben", 0),
  837. 0,
  838. 0,
  839. 0,
  840. &v1, NULL);
  841. *num_be = v1;
  842. return result;
  843. }
  844. /**
  845. * ps3_repository_read_be_node_id - Read the physical BE processor node id.
  846. * @be_index: Zero based index.
  847. * @node_id: The BE processor node id.
  848. */
  849. int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
  850. {
  851. return read_node(PS3_LPAR_ID_PME,
  852. make_first_field("be", be_index),
  853. 0,
  854. 0,
  855. 0,
  856. node_id, NULL);
  857. }
  858. /**
  859. * ps3_repository_read_be_id - Read the physical BE processor id.
  860. * @node_id: The BE processor node id.
  861. * @be_id: The BE processor id.
  862. */
  863. int ps3_repository_read_be_id(u64 node_id, u64 *be_id)
  864. {
  865. return read_node(PS3_LPAR_ID_PME,
  866. make_first_field("be", 0),
  867. node_id,
  868. 0,
  869. 0,
  870. be_id, NULL);
  871. }
  872. int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
  873. {
  874. return read_node(PS3_LPAR_ID_PME,
  875. make_first_field("be", 0),
  876. node_id,
  877. make_field("clock", 0),
  878. 0,
  879. tb_freq, NULL);
  880. }
  881. int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
  882. {
  883. int result;
  884. u64 node_id;
  885. *tb_freq = 0;
  886. result = ps3_repository_read_be_node_id(be_index, &node_id);
  887. return result ? result
  888. : ps3_repository_read_tb_freq(node_id, tb_freq);
  889. }
  890. int ps3_repository_read_lpm_privileges(unsigned int be_index, u64 *lpar,
  891. u64 *rights)
  892. {
  893. int result;
  894. u64 node_id;
  895. *lpar = 0;
  896. *rights = 0;
  897. result = ps3_repository_read_be_node_id(be_index, &node_id);
  898. return result ? result
  899. : read_node(PS3_LPAR_ID_PME,
  900. make_first_field("be", 0),
  901. node_id,
  902. make_field("lpm", 0),
  903. make_field("priv", 0),
  904. lpar, rights);
  905. }
  906. #if defined(CONFIG_PS3_REPOSITORY_WRITE)
  907. static int create_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2)
  908. {
  909. int result;
  910. dump_node(0, n1, n2, n3, n4, v1, v2);
  911. result = lv1_create_repository_node(n1, n2, n3, n4, v1, v2);
  912. if (result) {
  913. pr_devel("%s:%d: lv1_create_repository_node failed: %s\n",
  914. __func__, __LINE__, ps3_result(result));
  915. return -ENOENT;
  916. }
  917. return 0;
  918. }
  919. static int delete_node(u64 n1, u64 n2, u64 n3, u64 n4)
  920. {
  921. int result;
  922. dump_node(0, n1, n2, n3, n4, 0, 0);
  923. result = lv1_delete_repository_node(n1, n2, n3, n4);
  924. if (result) {
  925. pr_devel("%s:%d: lv1_delete_repository_node failed: %s\n",
  926. __func__, __LINE__, ps3_result(result));
  927. return -ENOENT;
  928. }
  929. return 0;
  930. }
  931. static int write_node(u64 n1, u64 n2, u64 n3, u64 n4, u64 v1, u64 v2)
  932. {
  933. int result;
  934. result = create_node(n1, n2, n3, n4, v1, v2);
  935. if (!result)
  936. return 0;
  937. result = lv1_write_repository_node(n1, n2, n3, n4, v1, v2);
  938. if (result) {
  939. pr_devel("%s:%d: lv1_write_repository_node failed: %s\n",
  940. __func__, __LINE__, ps3_result(result));
  941. return -ENOENT;
  942. }
  943. return 0;
  944. }
  945. int ps3_repository_write_highmem_region_count(unsigned int region_count)
  946. {
  947. int result;
  948. u64 v1 = (u64)region_count;
  949. result = write_node(
  950. make_first_field("highmem", 0),
  951. make_field("region", 0),
  952. make_field("count", 0),
  953. 0,
  954. v1, 0);
  955. return result;
  956. }
  957. int ps3_repository_write_highmem_base(unsigned int region_index,
  958. u64 highmem_base)
  959. {
  960. return write_node(
  961. make_first_field("highmem", 0),
  962. make_field("region", region_index),
  963. make_field("base", 0),
  964. 0,
  965. highmem_base, 0);
  966. }
  967. int ps3_repository_write_highmem_size(unsigned int region_index,
  968. u64 highmem_size)
  969. {
  970. return write_node(
  971. make_first_field("highmem", 0),
  972. make_field("region", region_index),
  973. make_field("size", 0),
  974. 0,
  975. highmem_size, 0);
  976. }
  977. int ps3_repository_write_highmem_info(unsigned int region_index,
  978. u64 highmem_base, u64 highmem_size)
  979. {
  980. int result;
  981. result = ps3_repository_write_highmem_base(region_index, highmem_base);
  982. return result ? result
  983. : ps3_repository_write_highmem_size(region_index, highmem_size);
  984. }
  985. static int ps3_repository_delete_highmem_base(unsigned int region_index)
  986. {
  987. return delete_node(
  988. make_first_field("highmem", 0),
  989. make_field("region", region_index),
  990. make_field("base", 0),
  991. 0);
  992. }
  993. static int ps3_repository_delete_highmem_size(unsigned int region_index)
  994. {
  995. return delete_node(
  996. make_first_field("highmem", 0),
  997. make_field("region", region_index),
  998. make_field("size", 0),
  999. 0);
  1000. }
  1001. int ps3_repository_delete_highmem_info(unsigned int region_index)
  1002. {
  1003. int result;
  1004. result = ps3_repository_delete_highmem_base(region_index);
  1005. result += ps3_repository_delete_highmem_size(region_index);
  1006. return result ? -1 : 0;
  1007. }
  1008. #endif /* defined(CONFIG_PS3_REPOSITORY_WRITE) */
  1009. #if defined(DEBUG)
  1010. int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
  1011. {
  1012. int result = 0;
  1013. unsigned int res_index;
  1014. pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  1015. repo->bus_index, repo->dev_index);
  1016. for (res_index = 0; res_index < 10; res_index++) {
  1017. enum ps3_interrupt_type intr_type;
  1018. unsigned int interrupt_id;
  1019. result = ps3_repository_read_dev_intr(repo->bus_index,
  1020. repo->dev_index, res_index, &intr_type, &interrupt_id);
  1021. if (result) {
  1022. if (result != LV1_NO_ENTRY)
  1023. pr_devel("%s:%d ps3_repository_read_dev_intr"
  1024. " (%u:%u) failed\n", __func__, __LINE__,
  1025. repo->bus_index, repo->dev_index);
  1026. break;
  1027. }
  1028. pr_devel("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
  1029. __func__, __LINE__, repo->bus_index, repo->dev_index,
  1030. intr_type, interrupt_id);
  1031. }
  1032. for (res_index = 0; res_index < 10; res_index++) {
  1033. enum ps3_reg_type reg_type;
  1034. u64 bus_addr;
  1035. u64 len;
  1036. result = ps3_repository_read_dev_reg(repo->bus_index,
  1037. repo->dev_index, res_index, &reg_type, &bus_addr, &len);
  1038. if (result) {
  1039. if (result != LV1_NO_ENTRY)
  1040. pr_devel("%s:%d ps3_repository_read_dev_reg"
  1041. " (%u:%u) failed\n", __func__, __LINE__,
  1042. repo->bus_index, repo->dev_index);
  1043. break;
  1044. }
  1045. pr_devel("%s:%d (%u:%u) reg_type %u, bus_addr %llxh, len %llxh\n",
  1046. __func__, __LINE__, repo->bus_index, repo->dev_index,
  1047. reg_type, bus_addr, len);
  1048. }
  1049. pr_devel(" <- %s:%d\n", __func__, __LINE__);
  1050. return result;
  1051. }
  1052. static int dump_stor_dev_info(struct ps3_repository_device *repo)
  1053. {
  1054. int result = 0;
  1055. unsigned int num_regions, region_index;
  1056. u64 port, blk_size, num_blocks;
  1057. pr_devel(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  1058. repo->bus_index, repo->dev_index);
  1059. result = ps3_repository_read_stor_dev_info(repo->bus_index,
  1060. repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
  1061. if (result) {
  1062. pr_devel("%s:%d ps3_repository_read_stor_dev_info"
  1063. " (%u:%u) failed\n", __func__, __LINE__,
  1064. repo->bus_index, repo->dev_index);
  1065. goto out;
  1066. }
  1067. pr_devel("%s:%d (%u:%u): port %llu, blk_size %llu, num_blocks "
  1068. "%llu, num_regions %u\n",
  1069. __func__, __LINE__, repo->bus_index, repo->dev_index,
  1070. port, blk_size, num_blocks, num_regions);
  1071. for (region_index = 0; region_index < num_regions; region_index++) {
  1072. unsigned int region_id;
  1073. u64 region_start, region_size;
  1074. result = ps3_repository_read_stor_dev_region(repo->bus_index,
  1075. repo->dev_index, region_index, &region_id,
  1076. &region_start, &region_size);
  1077. if (result) {
  1078. pr_devel("%s:%d ps3_repository_read_stor_dev_region"
  1079. " (%u:%u) failed\n", __func__, __LINE__,
  1080. repo->bus_index, repo->dev_index);
  1081. break;
  1082. }
  1083. pr_devel("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
  1084. __func__, __LINE__, repo->bus_index, repo->dev_index,
  1085. region_id, (unsigned long)region_start,
  1086. (unsigned long)region_size);
  1087. }
  1088. out:
  1089. pr_devel(" <- %s:%d\n", __func__, __LINE__);
  1090. return result;
  1091. }
  1092. static int dump_device_info(struct ps3_repository_device *repo,
  1093. unsigned int num_dev)
  1094. {
  1095. int result = 0;
  1096. pr_devel(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
  1097. for (repo->dev_index = 0; repo->dev_index < num_dev;
  1098. repo->dev_index++) {
  1099. result = ps3_repository_read_dev_type(repo->bus_index,
  1100. repo->dev_index, &repo->dev_type);
  1101. if (result) {
  1102. pr_devel("%s:%d ps3_repository_read_dev_type"
  1103. " (%u:%u) failed\n", __func__, __LINE__,
  1104. repo->bus_index, repo->dev_index);
  1105. break;
  1106. }
  1107. result = ps3_repository_read_dev_id(repo->bus_index,
  1108. repo->dev_index, &repo->dev_id);
  1109. if (result) {
  1110. pr_devel("%s:%d ps3_repository_read_dev_id"
  1111. " (%u:%u) failed\n", __func__, __LINE__,
  1112. repo->bus_index, repo->dev_index);
  1113. continue;
  1114. }
  1115. pr_devel("%s:%d (%u:%u): dev_type %u, dev_id %lu\n", __func__,
  1116. __LINE__, repo->bus_index, repo->dev_index,
  1117. repo->dev_type, (unsigned long)repo->dev_id);
  1118. ps3_repository_dump_resource_info(repo);
  1119. if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
  1120. dump_stor_dev_info(repo);
  1121. }
  1122. pr_devel(" <- %s:%d\n", __func__, __LINE__);
  1123. return result;
  1124. }
  1125. int ps3_repository_dump_bus_info(void)
  1126. {
  1127. int result = 0;
  1128. struct ps3_repository_device repo;
  1129. pr_devel(" -> %s:%d\n", __func__, __LINE__);
  1130. memset(&repo, 0, sizeof(repo));
  1131. for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
  1132. unsigned int num_dev;
  1133. result = ps3_repository_read_bus_type(repo.bus_index,
  1134. &repo.bus_type);
  1135. if (result) {
  1136. pr_devel("%s:%d read_bus_type(%u) failed\n",
  1137. __func__, __LINE__, repo.bus_index);
  1138. break;
  1139. }
  1140. result = ps3_repository_read_bus_id(repo.bus_index,
  1141. &repo.bus_id);
  1142. if (result) {
  1143. pr_devel("%s:%d read_bus_id(%u) failed\n",
  1144. __func__, __LINE__, repo.bus_index);
  1145. continue;
  1146. }
  1147. if (repo.bus_index != repo.bus_id)
  1148. pr_devel("%s:%d bus_index != bus_id\n",
  1149. __func__, __LINE__);
  1150. result = ps3_repository_read_bus_num_dev(repo.bus_index,
  1151. &num_dev);
  1152. if (result) {
  1153. pr_devel("%s:%d read_bus_num_dev(%u) failed\n",
  1154. __func__, __LINE__, repo.bus_index);
  1155. continue;
  1156. }
  1157. pr_devel("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n",
  1158. __func__, __LINE__, repo.bus_index, repo.bus_type,
  1159. (unsigned long)repo.bus_id, num_dev);
  1160. dump_device_info(&repo, num_dev);
  1161. }
  1162. pr_devel(" <- %s:%d\n", __func__, __LINE__);
  1163. return result;
  1164. }
  1165. #endif /* defined(DEBUG) */