repository.c 24 KB

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