repository.c 33 KB

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