repository.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
  300. &tmp.dev_id);
  301. if (result) {
  302. pr_debug("%s:%d ps3_repository_read_dev_id failed\n", __func__,
  303. __LINE__);
  304. return result;
  305. }
  306. pr_debug("%s:%d: found: dev_type %u, dev_index %u, dev_id %u\n",
  307. __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
  308. *repo = tmp;
  309. return 0;
  310. }
  311. int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
  312. int (*callback)(const struct ps3_repository_device *repo))
  313. {
  314. int result = 0;
  315. struct ps3_repository_device repo;
  316. pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
  317. for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
  318. result = ps3_repository_read_bus_type(repo.bus_index,
  319. &repo.bus_type);
  320. if (result) {
  321. pr_debug("%s:%d read_bus_type(%u) failed\n",
  322. __func__, __LINE__, repo.bus_index);
  323. break;
  324. }
  325. if (repo.bus_type != bus_type) {
  326. pr_debug("%s:%d: skip, bus_type %u\n", __func__,
  327. __LINE__, repo.bus_type);
  328. continue;
  329. }
  330. result = ps3_repository_read_bus_id(repo.bus_index,
  331. &repo.bus_id);
  332. if (result) {
  333. pr_debug("%s:%d read_bus_id(%u) failed\n",
  334. __func__, __LINE__, repo.bus_index);
  335. continue;
  336. }
  337. for (repo.dev_index = 0; ; repo.dev_index++) {
  338. result = ps3_repository_find_device(&repo);
  339. if (result == -ENODEV) {
  340. result = 0;
  341. break;
  342. } else if (result)
  343. break;
  344. result = callback(&repo);
  345. if (result) {
  346. pr_debug("%s:%d: abort at callback\n", __func__,
  347. __LINE__);
  348. break;
  349. }
  350. }
  351. break;
  352. }
  353. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  354. return result;
  355. }
  356. int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
  357. unsigned int *bus_index)
  358. {
  359. unsigned int i;
  360. enum ps3_bus_type type;
  361. int error;
  362. for (i = from; i < 10; i++) {
  363. error = ps3_repository_read_bus_type(i, &type);
  364. if (error) {
  365. pr_debug("%s:%d read_bus_type failed\n",
  366. __func__, __LINE__);
  367. *bus_index = UINT_MAX;
  368. return error;
  369. }
  370. if (type == bus_type) {
  371. *bus_index = i;
  372. return 0;
  373. }
  374. }
  375. *bus_index = UINT_MAX;
  376. return -ENODEV;
  377. }
  378. int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
  379. enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
  380. {
  381. int result = 0;
  382. unsigned int res_index;
  383. pr_debug("%s:%d: find intr_type %u\n", __func__, __LINE__, intr_type);
  384. *interrupt_id = UINT_MAX;
  385. for (res_index = 0; res_index < 10; res_index++) {
  386. enum ps3_interrupt_type t;
  387. unsigned int id;
  388. result = ps3_repository_read_dev_intr(repo->bus_index,
  389. repo->dev_index, res_index, &t, &id);
  390. if (result) {
  391. pr_debug("%s:%d read_dev_intr failed\n",
  392. __func__, __LINE__);
  393. return result;
  394. }
  395. if (t == intr_type) {
  396. *interrupt_id = id;
  397. break;
  398. }
  399. }
  400. if (res_index == 10)
  401. return -ENODEV;
  402. pr_debug("%s:%d: found intr_type %u at res_index %u\n",
  403. __func__, __LINE__, intr_type, res_index);
  404. return result;
  405. }
  406. int ps3_repository_find_reg(const struct ps3_repository_device *repo,
  407. enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
  408. {
  409. int result = 0;
  410. unsigned int res_index;
  411. pr_debug("%s:%d: find reg_type %u\n", __func__, __LINE__, reg_type);
  412. *bus_addr = *len = 0;
  413. for (res_index = 0; res_index < 10; res_index++) {
  414. enum ps3_reg_type t;
  415. u64 a;
  416. u64 l;
  417. result = ps3_repository_read_dev_reg(repo->bus_index,
  418. repo->dev_index, res_index, &t, &a, &l);
  419. if (result) {
  420. pr_debug("%s:%d read_dev_reg failed\n",
  421. __func__, __LINE__);
  422. return result;
  423. }
  424. if (t == reg_type) {
  425. *bus_addr = a;
  426. *len = l;
  427. break;
  428. }
  429. }
  430. if (res_index == 10)
  431. return -ENODEV;
  432. pr_debug("%s:%d: found reg_type %u at res_index %u\n",
  433. __func__, __LINE__, reg_type, res_index);
  434. return result;
  435. }
  436. int ps3_repository_read_stor_dev_port(unsigned int bus_index,
  437. unsigned int dev_index, u64 *port)
  438. {
  439. return read_node(PS3_LPAR_ID_PME,
  440. make_first_field("bus", bus_index),
  441. make_field("dev", dev_index),
  442. make_field("port", 0),
  443. 0, port, 0);
  444. }
  445. int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
  446. unsigned int dev_index, u64 *blk_size)
  447. {
  448. return read_node(PS3_LPAR_ID_PME,
  449. make_first_field("bus", bus_index),
  450. make_field("dev", dev_index),
  451. make_field("blk_size", 0),
  452. 0, blk_size, 0);
  453. }
  454. int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
  455. unsigned int dev_index, u64 *num_blocks)
  456. {
  457. return read_node(PS3_LPAR_ID_PME,
  458. make_first_field("bus", bus_index),
  459. make_field("dev", dev_index),
  460. make_field("n_blocks", 0),
  461. 0, num_blocks, 0);
  462. }
  463. int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
  464. unsigned int dev_index, unsigned int *num_regions)
  465. {
  466. int result;
  467. u64 v1;
  468. result = read_node(PS3_LPAR_ID_PME,
  469. make_first_field("bus", bus_index),
  470. make_field("dev", dev_index),
  471. make_field("n_regs", 0),
  472. 0, &v1, 0);
  473. *num_regions = v1;
  474. return result;
  475. }
  476. int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
  477. unsigned int dev_index, unsigned int region_index,
  478. unsigned int *region_id)
  479. {
  480. int result;
  481. u64 v1;
  482. result = read_node(PS3_LPAR_ID_PME,
  483. make_first_field("bus", bus_index),
  484. make_field("dev", dev_index),
  485. make_field("region", region_index),
  486. make_field("id", 0),
  487. &v1, 0);
  488. *region_id = v1;
  489. return result;
  490. }
  491. int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
  492. unsigned int dev_index, unsigned int region_index, u64 *region_size)
  493. {
  494. return read_node(PS3_LPAR_ID_PME,
  495. make_first_field("bus", bus_index),
  496. make_field("dev", dev_index),
  497. make_field("region", region_index),
  498. make_field("size", 0),
  499. region_size, 0);
  500. }
  501. int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
  502. unsigned int dev_index, unsigned int region_index, u64 *region_start)
  503. {
  504. return read_node(PS3_LPAR_ID_PME,
  505. make_first_field("bus", bus_index),
  506. make_field("dev", dev_index),
  507. make_field("region", region_index),
  508. make_field("start", 0),
  509. region_start, 0);
  510. }
  511. int ps3_repository_read_stor_dev_info(unsigned int bus_index,
  512. unsigned int dev_index, u64 *port, u64 *blk_size,
  513. u64 *num_blocks, unsigned int *num_regions)
  514. {
  515. int result;
  516. result = ps3_repository_read_stor_dev_port(bus_index, dev_index, port);
  517. if (result)
  518. return result;
  519. result = ps3_repository_read_stor_dev_blk_size(bus_index, dev_index,
  520. blk_size);
  521. if (result)
  522. return result;
  523. result = ps3_repository_read_stor_dev_num_blocks(bus_index, dev_index,
  524. num_blocks);
  525. if (result)
  526. return result;
  527. result = ps3_repository_read_stor_dev_num_regions(bus_index, dev_index,
  528. num_regions);
  529. return result;
  530. }
  531. int ps3_repository_read_stor_dev_region(unsigned int bus_index,
  532. unsigned int dev_index, unsigned int region_index,
  533. unsigned int *region_id, u64 *region_start, u64 *region_size)
  534. {
  535. int result;
  536. result = ps3_repository_read_stor_dev_region_id(bus_index, dev_index,
  537. region_index, region_id);
  538. if (result)
  539. return result;
  540. result = ps3_repository_read_stor_dev_region_start(bus_index, dev_index,
  541. region_index, region_start);
  542. if (result)
  543. return result;
  544. result = ps3_repository_read_stor_dev_region_size(bus_index, dev_index,
  545. region_index, region_size);
  546. return result;
  547. }
  548. int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
  549. {
  550. return read_node(PS3_LPAR_ID_CURRENT,
  551. make_first_field("bi", 0),
  552. make_field("pu", 0),
  553. ppe_id,
  554. make_field("rm_size", 0),
  555. rm_size, 0);
  556. }
  557. int ps3_repository_read_region_total(u64 *region_total)
  558. {
  559. return read_node(PS3_LPAR_ID_CURRENT,
  560. make_first_field("bi", 0),
  561. make_field("rgntotal", 0),
  562. 0, 0,
  563. region_total, 0);
  564. }
  565. /**
  566. * ps3_repository_read_mm_info - Read mm info for single pu system.
  567. * @rm_base: Real mode memory base address.
  568. * @rm_size: Real mode memory size.
  569. * @region_total: Maximum memory region size.
  570. */
  571. int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size, u64 *region_total)
  572. {
  573. int result;
  574. u64 ppe_id;
  575. lv1_get_logical_ppe_id(&ppe_id);
  576. *rm_base = 0;
  577. result = ps3_repository_read_rm_size(ppe_id, rm_size);
  578. return result ? result
  579. : ps3_repository_read_region_total(region_total);
  580. }
  581. /**
  582. * ps3_repository_read_num_spu_reserved - Number of physical spus reserved.
  583. * @num_spu: Number of physical spus.
  584. */
  585. int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
  586. {
  587. int result;
  588. u64 v1;
  589. result = read_node(PS3_LPAR_ID_CURRENT,
  590. make_first_field("bi", 0),
  591. make_field("spun", 0),
  592. 0, 0,
  593. &v1, 0);
  594. *num_spu_reserved = v1;
  595. return result;
  596. }
  597. /**
  598. * ps3_repository_read_num_spu_resource_id - Number of spu resource reservations.
  599. * @num_resource_id: Number of spu resource ids.
  600. */
  601. int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
  602. {
  603. int result;
  604. u64 v1;
  605. result = read_node(PS3_LPAR_ID_CURRENT,
  606. make_first_field("bi", 0),
  607. make_field("spursvn", 0),
  608. 0, 0,
  609. &v1, 0);
  610. *num_resource_id = v1;
  611. return result;
  612. }
  613. /**
  614. * ps3_repository_read_spu_resource_id - spu resource reservation id value.
  615. * @res_index: Resource reservation index.
  616. * @resource_type: Resource reservation type.
  617. * @resource_id: Resource reservation id.
  618. */
  619. int ps3_repository_read_spu_resource_id(unsigned int res_index,
  620. enum ps3_spu_resource_type* resource_type, unsigned int *resource_id)
  621. {
  622. int result;
  623. u64 v1;
  624. u64 v2;
  625. result = read_node(PS3_LPAR_ID_CURRENT,
  626. make_first_field("bi", 0),
  627. make_field("spursv", 0),
  628. res_index,
  629. 0,
  630. &v1, &v2);
  631. *resource_type = v1;
  632. *resource_id = v2;
  633. return result;
  634. }
  635. int ps3_repository_read_boot_dat_address(u64 *address)
  636. {
  637. return read_node(PS3_LPAR_ID_CURRENT,
  638. make_first_field("bi", 0),
  639. make_field("boot_dat", 0),
  640. make_field("address", 0),
  641. 0,
  642. address, 0);
  643. }
  644. int ps3_repository_read_boot_dat_size(unsigned int *size)
  645. {
  646. int result;
  647. u64 v1;
  648. result = read_node(PS3_LPAR_ID_CURRENT,
  649. make_first_field("bi", 0),
  650. make_field("boot_dat", 0),
  651. make_field("size", 0),
  652. 0,
  653. &v1, 0);
  654. *size = v1;
  655. return result;
  656. }
  657. int ps3_repository_read_vuart_av_port(unsigned int *port)
  658. {
  659. int result;
  660. u64 v1;
  661. result = read_node(PS3_LPAR_ID_CURRENT,
  662. make_first_field("bi", 0),
  663. make_field("vir_uart", 0),
  664. make_field("port", 0),
  665. make_field("avset", 0),
  666. &v1, 0);
  667. *port = v1;
  668. return result;
  669. }
  670. int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
  671. {
  672. int result;
  673. u64 v1;
  674. result = read_node(PS3_LPAR_ID_CURRENT,
  675. make_first_field("bi", 0),
  676. make_field("vir_uart", 0),
  677. make_field("port", 0),
  678. make_field("sysmgr", 0),
  679. &v1, 0);
  680. *port = v1;
  681. return result;
  682. }
  683. /**
  684. * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
  685. * address: lpar address of cell_ext_os_area
  686. * @size: size of cell_ext_os_area
  687. */
  688. int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
  689. {
  690. int result;
  691. *size = 0;
  692. result = ps3_repository_read_boot_dat_address(lpar_addr);
  693. return result ? result
  694. : ps3_repository_read_boot_dat_size(size);
  695. }
  696. int ps3_repository_read_num_be(unsigned int *num_be)
  697. {
  698. int result;
  699. u64 v1;
  700. result = read_node(PS3_LPAR_ID_PME,
  701. make_first_field("ben", 0),
  702. 0,
  703. 0,
  704. 0,
  705. &v1, 0);
  706. *num_be = v1;
  707. return result;
  708. }
  709. int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
  710. {
  711. return read_node(PS3_LPAR_ID_PME,
  712. make_first_field("be", be_index),
  713. 0,
  714. 0,
  715. 0,
  716. node_id, 0);
  717. }
  718. int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
  719. {
  720. return read_node(PS3_LPAR_ID_PME,
  721. make_first_field("be", 0),
  722. node_id,
  723. make_field("clock", 0),
  724. 0,
  725. tb_freq, 0);
  726. }
  727. int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
  728. {
  729. int result;
  730. u64 node_id;
  731. *tb_freq = 0;
  732. result = ps3_repository_read_be_node_id(0, &node_id);
  733. return result ? result
  734. : ps3_repository_read_tb_freq(node_id, tb_freq);
  735. }
  736. #if defined(DEBUG)
  737. int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
  738. {
  739. int result = 0;
  740. unsigned int res_index;
  741. pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  742. repo->bus_index, repo->dev_index);
  743. for (res_index = 0; res_index < 10; res_index++) {
  744. enum ps3_interrupt_type intr_type;
  745. unsigned int interrupt_id;
  746. result = ps3_repository_read_dev_intr(repo->bus_index,
  747. repo->dev_index, res_index, &intr_type, &interrupt_id);
  748. if (result) {
  749. if (result != LV1_NO_ENTRY)
  750. pr_debug("%s:%d ps3_repository_read_dev_intr"
  751. " (%u:%u) failed\n", __func__, __LINE__,
  752. repo->bus_index, repo->dev_index);
  753. break;
  754. }
  755. pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
  756. __func__, __LINE__, repo->bus_index, repo->dev_index,
  757. intr_type, interrupt_id);
  758. }
  759. for (res_index = 0; res_index < 10; res_index++) {
  760. enum ps3_reg_type reg_type;
  761. u64 bus_addr;
  762. u64 len;
  763. result = ps3_repository_read_dev_reg(repo->bus_index,
  764. repo->dev_index, res_index, &reg_type, &bus_addr, &len);
  765. if (result) {
  766. if (result != LV1_NO_ENTRY)
  767. pr_debug("%s:%d ps3_repository_read_dev_reg"
  768. " (%u:%u) failed\n", __func__, __LINE__,
  769. repo->bus_index, repo->dev_index);
  770. break;
  771. }
  772. pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
  773. __func__, __LINE__, repo->bus_index, repo->dev_index,
  774. reg_type, bus_addr, len);
  775. }
  776. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  777. return result;
  778. }
  779. static int dump_stor_dev_info(struct ps3_repository_device *repo)
  780. {
  781. int result = 0;
  782. unsigned int num_regions, region_index;
  783. u64 port, blk_size, num_blocks;
  784. pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
  785. repo->bus_index, repo->dev_index);
  786. result = ps3_repository_read_stor_dev_info(repo->bus_index,
  787. repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
  788. if (result) {
  789. pr_debug("%s:%d ps3_repository_read_stor_dev_info"
  790. " (%u:%u) failed\n", __func__, __LINE__,
  791. repo->bus_index, repo->dev_index);
  792. goto out;
  793. }
  794. pr_debug("%s:%d (%u:%u): port %lu, blk_size %lu, num_blocks "
  795. "%lu, num_regions %u\n",
  796. __func__, __LINE__, repo->bus_index, repo->dev_index, port,
  797. blk_size, num_blocks, num_regions);
  798. for (region_index = 0; region_index < num_regions; region_index++) {
  799. unsigned int region_id;
  800. u64 region_start, region_size;
  801. result = ps3_repository_read_stor_dev_region(repo->bus_index,
  802. repo->dev_index, region_index, &region_id,
  803. &region_start, &region_size);
  804. if (result) {
  805. pr_debug("%s:%d ps3_repository_read_stor_dev_region"
  806. " (%u:%u) failed\n", __func__, __LINE__,
  807. repo->bus_index, repo->dev_index);
  808. break;
  809. }
  810. pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
  811. __func__, __LINE__, repo->bus_index, repo->dev_index,
  812. region_id, region_start, region_size);
  813. }
  814. out:
  815. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  816. return result;
  817. }
  818. static int dump_device_info(struct ps3_repository_device *repo,
  819. unsigned int num_dev)
  820. {
  821. int result = 0;
  822. pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
  823. for (repo->dev_index = 0; repo->dev_index < num_dev;
  824. repo->dev_index++) {
  825. result = ps3_repository_read_dev_type(repo->bus_index,
  826. repo->dev_index, &repo->dev_type);
  827. if (result) {
  828. pr_debug("%s:%d ps3_repository_read_dev_type"
  829. " (%u:%u) failed\n", __func__, __LINE__,
  830. repo->bus_index, repo->dev_index);
  831. break;
  832. }
  833. result = ps3_repository_read_dev_id(repo->bus_index,
  834. repo->dev_index, &repo->dev_id);
  835. if (result) {
  836. pr_debug("%s:%d ps3_repository_read_dev_id"
  837. " (%u:%u) failed\n", __func__, __LINE__,
  838. repo->bus_index, repo->dev_index);
  839. continue;
  840. }
  841. pr_debug("%s:%d (%u:%u): dev_type %u, dev_id %u\n", __func__,
  842. __LINE__, repo->bus_index, repo->dev_index,
  843. repo->dev_type, repo->dev_id);
  844. ps3_repository_dump_resource_info(repo);
  845. if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
  846. dump_stor_dev_info(repo);
  847. }
  848. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  849. return result;
  850. }
  851. int ps3_repository_dump_bus_info(void)
  852. {
  853. int result = 0;
  854. struct ps3_repository_device repo;
  855. pr_debug(" -> %s:%d\n", __func__, __LINE__);
  856. memset(&repo, 0, sizeof(repo));
  857. for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
  858. unsigned int num_dev;
  859. result = ps3_repository_read_bus_type(repo.bus_index,
  860. &repo.bus_type);
  861. if (result) {
  862. pr_debug("%s:%d read_bus_type(%u) failed\n",
  863. __func__, __LINE__, repo.bus_index);
  864. break;
  865. }
  866. result = ps3_repository_read_bus_id(repo.bus_index,
  867. &repo.bus_id);
  868. if (result) {
  869. pr_debug("%s:%d read_bus_id(%u) failed\n",
  870. __func__, __LINE__, repo.bus_index);
  871. continue;
  872. }
  873. if (repo.bus_index != repo.bus_id)
  874. pr_debug("%s:%d bus_index != bus_id\n",
  875. __func__, __LINE__);
  876. result = ps3_repository_read_bus_num_dev(repo.bus_index,
  877. &num_dev);
  878. if (result) {
  879. pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
  880. __func__, __LINE__, repo.bus_index);
  881. continue;
  882. }
  883. pr_debug("%s:%d bus_%u: bus_type %u, bus_id %u, num_dev %u\n",
  884. __func__, __LINE__, repo.bus_index, repo.bus_type,
  885. repo.bus_id, num_dev);
  886. dump_device_info(&repo, num_dev);
  887. }
  888. pr_debug(" <- %s:%d\n", __func__, __LINE__);
  889. return result;
  890. }
  891. #endif /* defined(DEBUG) */