repository.c 26 KB

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