repository.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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_debug("%s:%d: %s%016lx : %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_debug("%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_debug("%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_debug("%s:%d: v1: %016lx\n", func, line, v1);
  65. pr_debug("%s:%d: v2: %016lx\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_get_repository_node_value(lpar_id, n1, n2, n3, n4, &v1,
  116. &v2);
  117. if (result) {
  118. pr_debug("%s:%d: lv1_get_repository_node_value 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_debug("%s:%d: warning: discarding non-zero v1: %016lx\n",
  130. __func__, __LINE__, v1);
  131. if (v2 && !_v2)
  132. pr_debug("%s:%d: warning: discarding non-zero v2: %016lx\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, 0);
  144. }
  145. int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id)
  146. {
  147. int result;
  148. u64 v1;
  149. u64 v2; /* unused */
  150. result = read_node(PS3_LPAR_ID_PME,
  151. make_first_field("bus", bus_index),
  152. make_field("id", 0),
  153. 0, 0,
  154. &v1, &v2);
  155. *bus_id = v1;
  156. return result;
  157. }
  158. int ps3_repository_read_bus_type(unsigned int bus_index,
  159. enum ps3_bus_type *bus_type)
  160. {
  161. int result;
  162. u64 v1;
  163. result = read_node(PS3_LPAR_ID_PME,
  164. make_first_field("bus", bus_index),
  165. make_field("type", 0),
  166. 0, 0,
  167. &v1, 0);
  168. *bus_type = v1;
  169. return result;
  170. }
  171. int ps3_repository_read_bus_num_dev(unsigned int bus_index,
  172. unsigned int *num_dev)
  173. {
  174. int result;
  175. u64 v1;
  176. result = read_node(PS3_LPAR_ID_PME,
  177. make_first_field("bus", bus_index),
  178. make_field("num_dev", 0),
  179. 0, 0,
  180. &v1, 0);
  181. *num_dev = v1;
  182. return result;
  183. }
  184. int ps3_repository_read_dev_str(unsigned int bus_index,
  185. unsigned int dev_index, const char *dev_str, u64 *value)
  186. {
  187. return read_node(PS3_LPAR_ID_PME,
  188. make_first_field("bus", bus_index),
  189. make_field("dev", dev_index),
  190. make_field(dev_str, 0),
  191. 0,
  192. value, 0);
  193. }
  194. int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
  195. unsigned int *dev_id)
  196. {
  197. int result;
  198. u64 v1;
  199. result = read_node(PS3_LPAR_ID_PME,
  200. make_first_field("bus", bus_index),
  201. make_field("dev", dev_index),
  202. make_field("id", 0),
  203. 0,
  204. &v1, 0);
  205. *dev_id = v1;
  206. return result;
  207. }
  208. int ps3_repository_read_dev_type(unsigned int bus_index,
  209. unsigned int dev_index, enum ps3_dev_type *dev_type)
  210. {
  211. int result;
  212. u64 v1;
  213. result = read_node(PS3_LPAR_ID_PME,
  214. make_first_field("bus", bus_index),
  215. make_field("dev", dev_index),
  216. make_field("type", 0),
  217. 0,
  218. &v1, 0);
  219. *dev_type = v1;
  220. return result;
  221. }
  222. int ps3_repository_read_dev_intr(unsigned int bus_index,
  223. unsigned int dev_index, unsigned int intr_index,
  224. enum ps3_interrupt_type *intr_type, unsigned int* interrupt_id)
  225. {
  226. int result;
  227. u64 v1;
  228. u64 v2;
  229. result = read_node(PS3_LPAR_ID_PME,
  230. make_first_field("bus", bus_index),
  231. make_field("dev", dev_index),
  232. make_field("intr", intr_index),
  233. 0,
  234. &v1, &v2);
  235. *intr_type = v1;
  236. *interrupt_id = v2;
  237. return result;
  238. }
  239. int ps3_repository_read_dev_reg_type(unsigned int bus_index,
  240. unsigned int dev_index, unsigned int reg_index,
  241. enum ps3_reg_type *reg_type)
  242. {
  243. int result;
  244. u64 v1;
  245. result = read_node(PS3_LPAR_ID_PME,
  246. make_first_field("bus", bus_index),
  247. make_field("dev", dev_index),
  248. make_field("reg", reg_index),
  249. make_field("type", 0),
  250. &v1, 0);
  251. *reg_type = v1;
  252. return result;
  253. }
  254. int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
  255. unsigned int dev_index, unsigned int reg_index, u64 *bus_addr, u64 *len)
  256. {
  257. return read_node(PS3_LPAR_ID_PME,
  258. make_first_field("bus", bus_index),
  259. make_field("dev", dev_index),
  260. make_field("reg", reg_index),
  261. make_field("data", 0),
  262. bus_addr, len);
  263. }
  264. int ps3_repository_read_dev_reg(unsigned int bus_index,
  265. unsigned int dev_index, unsigned int reg_index,
  266. enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len)
  267. {
  268. int result = ps3_repository_read_dev_reg_type(bus_index, dev_index,
  269. reg_index, reg_type);
  270. return result ? result
  271. : ps3_repository_read_dev_reg_addr(bus_index, dev_index,
  272. reg_index, bus_addr, len);
  273. }
  274. int ps3_repository_find_device(struct ps3_repository_device *repo)
  275. {
  276. int result;
  277. struct ps3_repository_device tmp = *repo;
  278. unsigned int num_dev;
  279. BUG_ON(repo->bus_index > 10);
  280. BUG_ON(repo->dev_index > 10);
  281. result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
  282. if (result) {
  283. pr_debug("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
  284. return result;
  285. }
  286. pr_debug("%s:%d: bus_type %u, bus_index %u, bus_id %u, num_dev %u\n",
  287. __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
  288. num_dev);
  289. if (tmp.dev_index >= num_dev) {
  290. pr_debug("%s:%d: no device found\n", __func__, __LINE__);
  291. return -ENODEV;
  292. }
  293. result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
  294. &tmp.dev_type);
  295. if (result) {
  296. pr_debug("%s:%d read_dev_type failed\n", __func__, __LINE__);
  297. return result;
  298. }
  299. if (tmp.bus_type == PS3_BUS_TYPE_STORAGE) {
  300. /*
  301. * A storage device may show up in the repository before the
  302. * hypervisor has finished probing its type and regions
  303. */
  304. unsigned int num_regions;
  305. if (tmp.dev_type == PS3_DEV_TYPE_STOR_DUMMY) {
  306. pr_debug("%s:%u storage device not ready\n", __func__,
  307. __LINE__);
  308. return -ENODEV;
  309. }
  310. result = ps3_repository_read_stor_dev_num_regions(tmp.bus_index,
  311. tmp.dev_index,
  312. &num_regions);
  313. if (result) {
  314. pr_debug("%s:%d read_stor_dev_num_regions failed\n",
  315. __func__, __LINE__);
  316. return result;
  317. }
  318. if (!num_regions) {
  319. pr_debug("%s:%u storage device has no regions yet\n",
  320. __func__, __LINE__);
  321. return -ENODEV;
  322. }
  323. }
  324. result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
  325. &tmp.dev_id);
  326. if (result) {
  327. pr_debug("%s:%d ps3_repository_read_dev_id failed\n", __func__,
  328. __LINE__);
  329. return result;
  330. }
  331. pr_debug("%s:%d: found: dev_type %u, dev_index %u, dev_id %u\n",
  332. __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
  333. *repo = tmp;
  334. return 0;
  335. }
  336. int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
  337. int (*callback)(const struct ps3_repository_device *repo))
  338. {
  339. int result = 0;
  340. struct ps3_repository_device repo;
  341. pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
  342. for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
  343. result = ps3_repository_read_bus_type(repo.bus_index,
  344. &repo.bus_type);
  345. if (result) {
  346. pr_debug("%s:%d read_bus_type(%u) failed\n",
  347. __func__, __LINE__, repo.bus_index);
  348. break;
  349. }
  350. if (repo.bus_type != bus_type) {
  351. pr_debug("%s:%d: skip, bus_type %u\n", __func__,
  352. __LINE__, repo.bus_type);
  353. continue;
  354. }
  355. result = ps3_repository_read_bus_id(repo.bus_index,
  356. &repo.bus_id);
  357. if (result) {
  358. pr_debug("%s:%d read_bus_id(%u) failed\n",
  359. __func__, __LINE__, repo.bus_index);
  360. continue;
  361. }
  362. for (repo.dev_index = 0; ; repo.dev_index++) {
  363. result = ps3_repository_find_device(&repo);
  364. if (result == -ENODEV) {
  365. result = 0;
  366. break;
  367. } else if (result)
  368. break;
  369. result = callback(&repo);
  370. if (result) {
  371. pr_debug("%s:%d: abort at callback\n", __func__,
  372. __LINE__);
  373. break;
  374. }
  375. }
  376. break;
  377. }
  378. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  379. return result;
  380. }
  381. int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
  382. unsigned int *bus_index)
  383. {
  384. unsigned int i;
  385. enum ps3_bus_type type;
  386. int error;
  387. for (i = from; i < 10; i++) {
  388. error = ps3_repository_read_bus_type(i, &type);
  389. if (error) {
  390. pr_debug("%s:%d read_bus_type failed\n",
  391. __func__, __LINE__);
  392. *bus_index = UINT_MAX;
  393. return error;
  394. }
  395. if (type == bus_type) {
  396. *bus_index = i;
  397. return 0;
  398. }
  399. }
  400. *bus_index = UINT_MAX;
  401. return -ENODEV;
  402. }
  403. int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
  404. enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
  405. {
  406. int result = 0;
  407. unsigned int res_index;
  408. pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
  409. *interrupt_id = UINT_MAX;
  410. for (res_index = 0; res_index < 10; res_index++) {
  411. enum ps3_interrupt_type t;
  412. unsigned int id;
  413. result = ps3_repository_read_dev_intr(repo->bus_index,
  414. repo->dev_index, res_index, &t, &id);
  415. if (result) {
  416. pr_debug("%s:%d read_dev_intr failed\n",
  417. __func__, __LINE__);
  418. return result;
  419. }
  420. if (t == intr_type) {
  421. *interrupt_id = id;
  422. break;
  423. }
  424. }
  425. if (res_index == 10)
  426. return -ENODEV;
  427. pr_debug("%s:%d: found intr_type %u at res_index %u\n",
  428. __func__, __LINE__, intr_type, res_index);
  429. return result;
  430. }
  431. int ps3_repository_find_reg(const struct ps3_repository_device *repo,
  432. enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
  433. {
  434. int result = 0;
  435. unsigned int res_index;
  436. pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
  437. *bus_addr = *len = 0;
  438. for (res_index = 0; res_index < 10; res_index++) {
  439. enum ps3_reg_type t;
  440. u64 a;
  441. u64 l;
  442. result = ps3_repository_read_dev_reg(repo->bus_index,
  443. repo->dev_index, res_index, &t, &a, &l);
  444. if (result) {
  445. pr_debug("%s:%d read_dev_reg failed\n",
  446. __func__, __LINE__);
  447. return result;
  448. }
  449. if (t == reg_type) {
  450. *bus_addr = a;
  451. *len = l;
  452. break;
  453. }
  454. }
  455. if (res_index == 10)
  456. return -ENODEV;
  457. pr_debug("%s:%d: found reg_type %u at res_index %u\n",
  458. __func__, __LINE__, reg_type, res_index);
  459. return result;
  460. }
  461. int ps3_repository_read_stor_dev_port(unsigned int bus_index,
  462. unsigned int dev_index, u64 *port)
  463. {
  464. return read_node(PS3_LPAR_ID_PME,
  465. make_first_field("bus", bus_index),
  466. make_field("dev", dev_index),
  467. make_field("port", 0),
  468. 0, port, 0);
  469. }
  470. int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
  471. unsigned int dev_index, u64 *blk_size)
  472. {
  473. return read_node(PS3_LPAR_ID_PME,
  474. make_first_field("bus", bus_index),
  475. make_field("dev", dev_index),
  476. make_field("blk_size", 0),
  477. 0, blk_size, 0);
  478. }
  479. int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
  480. unsigned int dev_index, u64 *num_blocks)
  481. {
  482. return read_node(PS3_LPAR_ID_PME,
  483. make_first_field("bus", bus_index),
  484. make_field("dev", dev_index),
  485. make_field("n_blocks", 0),
  486. 0, num_blocks, 0);
  487. }
  488. int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
  489. unsigned int dev_index, unsigned int *num_regions)
  490. {
  491. int result;
  492. u64 v1;
  493. result = read_node(PS3_LPAR_ID_PME,
  494. make_first_field("bus", bus_index),
  495. make_field("dev", dev_index),
  496. make_field("n_regs", 0),
  497. 0, &v1, 0);
  498. *num_regions = v1;
  499. return result;
  500. }
  501. int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
  502. unsigned int dev_index, unsigned int region_index,
  503. unsigned int *region_id)
  504. {
  505. int result;
  506. u64 v1;
  507. result = read_node(PS3_LPAR_ID_PME,
  508. make_first_field("bus", bus_index),
  509. make_field("dev", dev_index),
  510. make_field("region", region_index),
  511. make_field("id", 0),
  512. &v1, 0);
  513. *region_id = v1;
  514. return result;
  515. }
  516. int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
  517. unsigned int dev_index, unsigned int region_index, u64 *region_size)
  518. {
  519. return read_node(PS3_LPAR_ID_PME,
  520. make_first_field("bus", bus_index),
  521. make_field("dev", dev_index),
  522. make_field("region", region_index),
  523. make_field("size", 0),
  524. region_size, 0);
  525. }
  526. int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
  527. unsigned int dev_index, unsigned int region_index, u64 *region_start)
  528. {
  529. return read_node(PS3_LPAR_ID_PME,
  530. make_first_field("bus", bus_index),
  531. make_field("dev", dev_index),
  532. make_field("region", region_index),
  533. make_field("start", 0),
  534. region_start, 0);
  535. }
  536. int ps3_repository_read_stor_dev_info(unsigned int bus_index,
  537. unsigned int dev_index, u64 *port, u64 *blk_size,
  538. u64 *num_blocks, unsigned int *num_regions)
  539. {
  540. int result;
  541. result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
  542. if (result)
  543. return result;
  544. result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
  545. blk_size);
  546. if (result)
  547. return result;
  548. result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
  549. num_blocks);
  550. if (result)
  551. return result;
  552. result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
  553. num_regions);
  554. return result;
  555. }
  556. int ps3_repository_read_stor_dev_region(unsigned int bus_index,
  557. unsigned int dev_index, unsigned int region_index,
  558. unsigned int *region_id, u64 *region_start, u64 *region_size)
  559. {
  560. int result;
  561. result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
  562. region_index, region_id);
  563. if (result)
  564. return result;
  565. result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
  566. region_index, region_start);
  567. if (result)
  568. return result;
  569. result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
  570. region_index, region_size);
  571. return result;
  572. }
  573. int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
  574. {
  575. return read_node(PS3_LPAR_ID_CURRENT,
  576. make_first_field("bi", 0),
  577. make_field("pu", 0),
  578. ppe_id,
  579. make_field("rm_size", 0),
  580. rm_size, 0);
  581. }
  582. int ps3_repository_read_region_total(u64 *region_total)
  583. {
  584. return read_node(PS3_LPAR_ID_CURRENT,
  585. make_first_field("bi", 0),
  586. make_field("rgntotal", 0),
  587. 0, 0,
  588. region_total, 0);
  589. }
  590. /**
  591. * ps3_repository_read_mm_info - Read mm info for single pu system.
  592. * @rm_base: Real mode memory base address.
  593. * @rm_size: Real mode memory size.
  594. * @region_total: Maximum memory region size.
  595. */
  596. int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
  597. {
  598. int result;
  599. u64 ppe_id;
  600. lv1_get_logical_ppe_id(&ppe_id);
  601. *rm_base = 0;
  602. result = ps3_repository_read_rm_size(ppe_id, rm_size);
  603. return result ? result
  604. : ps3_repository_read_region_total(region_total);
  605. }
  606. /**
  607. * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
  608. * @num_spu: Number of physical spus.
  609. */
  610. int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
  611. {
  612. int result;
  613. u64 v1;
  614. result = read_node(PS3_LPAR_ID_CURRENT,
  615. make_first_field("bi", 0),
  616. make_field("spun", 0),
  617. 0, 0,
  618. &v1, 0);
  619. *num_spu_reserved = v1;
  620. return result;
  621. }
  622. /**
  623. * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
  624. * @num_resource_id: Number of spu resource ids.
  625. */
  626. int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
  627. {
  628. int result;
  629. u64 v1;
  630. result = read_node(PS3_LPAR_ID_CURRENT,
  631. make_first_field("bi", 0),
  632. make_field("spursvn", 0),
  633. 0, 0,
  634. &v1, 0);
  635. *num_resource_id = v1;
  636. return result;
  637. }
  638. /**
  639. * ps3_repository_read_spu_resource_id - spu resource reservation id value.
  640. * @res_index: Resource reservation index.
  641. * @resource_type: Resource reservation type.
  642. * @resource_id: Resource reservation id.
  643. */
  644. int ps3_repository_read_spu_resource_id(unsigned int res_index,
  645. enum ps3_spu_resource_type* resource_type, unsigned int *resource_id)
  646. {
  647. int result;
  648. u64 v1;
  649. u64 v2;
  650. result = read_node(PS3_LPAR_ID_CURRENT,
  651. make_first_field("bi", 0),
  652. make_field("spursv", 0),
  653. res_index,
  654. 0,
  655. &v1, &v2);
  656. *resource_type = v1;
  657. *resource_id = v2;
  658. return result;
  659. }
  660. int ps3_repository_read_boot_dat_address(u64 *address)
  661. {
  662. return read_node(PS3_LPAR_ID_CURRENT,
  663. make_first_field("bi", 0),
  664. make_field("boot_dat", 0),
  665. make_field("address", 0),
  666. 0,
  667. address, 0);
  668. }
  669. int ps3_repository_read_boot_dat_size(unsigned int *size)
  670. {
  671. int result;
  672. u64 v1;
  673. result = read_node(PS3_LPAR_ID_CURRENT,
  674. make_first_field("bi", 0),
  675. make_field("boot_dat", 0),
  676. make_field("size", 0),
  677. 0,
  678. &v1, 0);
  679. *size = v1;
  680. return result;
  681. }
  682. int ps3_repository_read_vuart_av_port(unsigned int *port)
  683. {
  684. int result;
  685. u64 v1;
  686. result = read_node(PS3_LPAR_ID_CURRENT,
  687. make_first_field("bi", 0),
  688. make_field("vir_uart", 0),
  689. make_field("port", 0),
  690. make_field("avset", 0),
  691. &v1, 0);
  692. *port = v1;
  693. return result;
  694. }
  695. int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
  696. {
  697. int result;
  698. u64 v1;
  699. result = read_node(PS3_LPAR_ID_CURRENT,
  700. make_first_field("bi", 0),
  701. make_field("vir_uart", 0),
  702. make_field("port", 0),
  703. make_field("sysmgr", 0),
  704. &v1, 0);
  705. *port = v1;
  706. return result;
  707. }
  708. /**
  709. * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
  710. * address: lpar address of cell_ext_os_area
  711. * @size: size of cell_ext_os_area
  712. */
  713. int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
  714. {
  715. int result;
  716. *size = 0;
  717. result = ps3_repository_read_boot_dat_address(lpar_addr);
  718. return result ? result
  719. : ps3_repository_read_boot_dat_size(size);
  720. }
  721. int ps3_repository_read_num_be(unsigned int *num_be)
  722. {
  723. int result;
  724. u64 v1;
  725. result = read_node(PS3_LPAR_ID_PME,
  726. make_first_field("ben", 0),
  727. 0,
  728. 0,
  729. 0,
  730. &v1, 0);
  731. *num_be = v1;
  732. return result;
  733. }
  734. int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
  735. {
  736. return read_node(PS3_LPAR_ID_PME,
  737. make_first_field("be", be_index),
  738. 0,
  739. 0,
  740. 0,
  741. node_id, 0);
  742. }
  743. int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
  744. {
  745. return read_node(PS3_LPAR_ID_PME,
  746. make_first_field("be", 0),
  747. node_id,
  748. make_field("clock", 0),
  749. 0,
  750. tb_freq, 0);
  751. }
  752. int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
  753. {
  754. int result;
  755. u64 node_id;
  756. *tb_freq = 0;
  757. result = ps3_repository_read_be_node_id(0, &node_id);
  758. return result ? result
  759. : ps3_repository_read_tb_freq(node_id, tb_freq);
  760. }
  761. #if defined(DEBUG)
  762. int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
  763. {
  764. int result = 0;
  765. unsigned int res_index;
  766. pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  767. repo->bus_index, repo->dev_index);
  768. for (res_index = 0; res_index < 10; res_index++) {
  769. enum ps3_interrupt_type intr_type;
  770. unsigned int interrupt_id;
  771. result = ps3_repository_read_dev_intr(repo->bus_index,
  772. repo->dev_index, res_index, &intr_type, &interrupt_id);
  773. if (result) {
  774. if (result != LV1_NO_ENTRY)
  775. pr_debug("%s:%d ps3_repository_read_dev_intr"
  776. " (%u:%u) failed\n", __func__, __LINE__,
  777. repo->bus_index, repo->dev_index);
  778. break;
  779. }
  780. pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
  781. __func__, __LINE__, repo->bus_index, repo->dev_index,
  782. intr_type, interrupt_id);
  783. }
  784. for (res_index = 0; res_index < 10; res_index++) {
  785. enum ps3_reg_type reg_type;
  786. u64 bus_addr;
  787. u64 len;
  788. result = ps3_repository_read_dev_reg(repo->bus_index,
  789. repo->dev_index, res_index, &reg_type, &bus_addr, &len);
  790. if (result) {
  791. if (result != LV1_NO_ENTRY)
  792. pr_debug("%s:%d ps3_repository_read_dev_reg"
  793. " (%u:%u) failed\n", __func__, __LINE__,
  794. repo->bus_index, repo->dev_index);
  795. break;
  796. }
  797. pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
  798. __func__, __LINE__, repo->bus_index, repo->dev_index,
  799. reg_type, bus_addr, len);
  800. }
  801. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  802. return result;
  803. }
  804. static int dump_stor_dev_info(struct ps3_repository_device *repo)
  805. {
  806. int result = 0;
  807. unsigned int num_regions, region_index;
  808. u64 port, blk_size, num_blocks;
  809. pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  810. repo->bus_index, repo->dev_index);
  811. result = ps3_repository_read_stor_dev_info(repo->bus_index,
  812. repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
  813. if (result) {
  814. pr_debug("%s:%d ps3_repository_read_stor_dev_info"
  815. " (%u:%u) failed\n", __func__, __LINE__,
  816. repo->bus_index, repo->dev_index);
  817. goto out;
  818. }
  819. pr_debug("%s:%d (%u:%u): port %lu, blk_size %lu, num_blocks "
  820. "%lu, num_regions %u\n",
  821. __func__, __LINE__, repo->bus_index, repo->dev_index, port,
  822. blk_size, num_blocks, num_regions);
  823. for (region_index = 0; region_index < num_regions; region_index++) {
  824. unsigned int region_id;
  825. u64 region_start, region_size;
  826. result = ps3_repository_read_stor_dev_region(repo->bus_index,
  827. repo->dev_index, region_index, &region_id,
  828. &region_start, &region_size);
  829. if (result) {
  830. pr_debug("%s:%d ps3_repository_read_stor_dev_region"
  831. " (%u:%u) failed\n", __func__, __LINE__,
  832. repo->bus_index, repo->dev_index);
  833. break;
  834. }
  835. pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
  836. __func__, __LINE__, repo->bus_index, repo->dev_index,
  837. region_id, region_start, region_size);
  838. }
  839. out:
  840. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  841. return result;
  842. }
  843. static int dump_device_info(struct ps3_repository_device *repo,
  844. unsigned int num_dev)
  845. {
  846. int result = 0;
  847. pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
  848. for (repo->dev_index = 0; repo->dev_index < num_dev;
  849. repo->dev_index++) {
  850. result = ps3_repository_read_dev_type(repo->bus_index,
  851. repo->dev_index, &repo->dev_type);
  852. if (result) {
  853. pr_debug("%s:%d ps3_repository_read_dev_type"
  854. " (%u:%u) failed\n", __func__, __LINE__,
  855. repo->bus_index, repo->dev_index);
  856. break;
  857. }
  858. result = ps3_repository_read_dev_id(repo->bus_index,
  859. repo->dev_index, &repo->dev_id);
  860. if (result) {
  861. pr_debug("%s:%d ps3_repository_read_dev_id"
  862. " (%u:%u) failed\n", __func__, __LINE__,
  863. repo->bus_index, repo->dev_index);
  864. continue;
  865. }
  866. pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %u\n", __func__,
  867. __LINE__, repo->bus_index, repo->dev_index,
  868. repo->dev_type, repo->dev_id);
  869. ps3_repository_dump_resource_info(repo);
  870. if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
  871. dump_stor_dev_info(repo);
  872. }
  873. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  874. return result;
  875. }
  876. int ps3_repository_dump_bus_info(void)
  877. {
  878. int result = 0;
  879. struct ps3_repository_device repo;
  880. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  881. memset(&repo, 0, sizeof(repo));
  882. for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
  883. unsigned int num_dev;
  884. result = ps3_repository_read_bus_type(repo.bus_index,
  885. &repo.bus_type);
  886. if (result) {
  887. pr_debug("%s:%d read_bus_type(%u) failed\n",
  888. __func__, __LINE__, repo.bus_index);
  889. break;
  890. }
  891. result = ps3_repository_read_bus_id(repo.bus_index,
  892. &repo.bus_id);
  893. if (result) {
  894. pr_debug("%s:%d read_bus_id(%u) failed\n",
  895. __func__, __LINE__, repo.bus_index);
  896. continue;
  897. }
  898. if (repo.bus_index != repo.bus_id)
  899. pr_debug("%s:%d bus_index != bus_id\n",
  900. __func__, __LINE__);
  901. result = ps3_repository_read_bus_num_dev(repo.bus_index,
  902. &num_dev);
  903. if (result) {
  904. pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
  905. __func__, __LINE__, repo.bus_index);
  906. continue;
  907. }
  908. pr_debug("%s:%d bus_%u: bus_type %u, bus_id %u, num_dev %u\n",
  909. __func__, __LINE__, repo.bus_index, repo.bus_type,
  910. repo.bus_id, num_dev);
  911. dump_device_info(&repo, num_dev);
  912. }
  913. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  914. return result;
  915. }
  916. #endif /* defined(DEBUG) */