palinfo.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /*
  2. * palinfo.c
  3. *
  4. * Prints processor specific information reported by PAL.
  5. * This code is based on specification of PAL as of the
  6. * Intel IA-64 Architecture Software Developer's Manual v1.0.
  7. *
  8. *
  9. * Copyright (C) 2000-2001, 2003 Hewlett-Packard Co
  10. * Stephane Eranian <eranian@hpl.hp.com>
  11. * Copyright (C) 2004 Intel Corporation
  12. * Ashok Raj <ashok.raj@intel.com>
  13. *
  14. * 05/26/2000 S.Eranian initial release
  15. * 08/21/2000 S.Eranian updated to July 2000 PAL specs
  16. * 02/05/2001 S.Eranian fixed module support
  17. * 10/23/2001 S.Eranian updated pal_perf_mon_info bug fixes
  18. * 03/24/2004 Ashok Raj updated to work with CPU Hotplug
  19. */
  20. #include <linux/config.h>
  21. #include <linux/types.h>
  22. #include <linux/errno.h>
  23. #include <linux/init.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/mm.h>
  26. #include <linux/module.h>
  27. #include <linux/efi.h>
  28. #include <linux/notifier.h>
  29. #include <linux/cpu.h>
  30. #include <linux/cpumask.h>
  31. #include <asm/pal.h>
  32. #include <asm/sal.h>
  33. #include <asm/page.h>
  34. #include <asm/processor.h>
  35. #include <linux/smp.h>
  36. MODULE_AUTHOR("Stephane Eranian <eranian@hpl.hp.com>");
  37. MODULE_DESCRIPTION("/proc interface to IA-64 PAL");
  38. MODULE_LICENSE("GPL");
  39. #define PALINFO_VERSION "0.5"
  40. typedef int (*palinfo_func_t)(char*);
  41. typedef struct {
  42. const char *name; /* name of the proc entry */
  43. palinfo_func_t proc_read; /* function to call for reading */
  44. struct proc_dir_entry *entry; /* registered entry (removal) */
  45. } palinfo_entry_t;
  46. /*
  47. * A bunch of string array to get pretty printing
  48. */
  49. static char *cache_types[] = {
  50. "", /* not used */
  51. "Instruction",
  52. "Data",
  53. "Data/Instruction" /* unified */
  54. };
  55. static const char *cache_mattrib[]={
  56. "WriteThrough",
  57. "WriteBack",
  58. "", /* reserved */
  59. "" /* reserved */
  60. };
  61. static const char *cache_st_hints[]={
  62. "Temporal, level 1",
  63. "Reserved",
  64. "Reserved",
  65. "Non-temporal, all levels",
  66. "Reserved",
  67. "Reserved",
  68. "Reserved",
  69. "Reserved"
  70. };
  71. static const char *cache_ld_hints[]={
  72. "Temporal, level 1",
  73. "Non-temporal, level 1",
  74. "Reserved",
  75. "Non-temporal, all levels",
  76. "Reserved",
  77. "Reserved",
  78. "Reserved",
  79. "Reserved"
  80. };
  81. static const char *rse_hints[]={
  82. "enforced lazy",
  83. "eager stores",
  84. "eager loads",
  85. "eager loads and stores"
  86. };
  87. #define RSE_HINTS_COUNT ARRAY_SIZE(rse_hints)
  88. static const char *mem_attrib[]={
  89. "WB", /* 000 */
  90. "SW", /* 001 */
  91. "010", /* 010 */
  92. "011", /* 011 */
  93. "UC", /* 100 */
  94. "UCE", /* 101 */
  95. "WC", /* 110 */
  96. "NaTPage" /* 111 */
  97. };
  98. /*
  99. * Take a 64bit vector and produces a string such that
  100. * if bit n is set then 2^n in clear text is generated. The adjustment
  101. * to the right unit is also done.
  102. *
  103. * Input:
  104. * - a pointer to a buffer to hold the string
  105. * - a 64-bit vector
  106. * Ouput:
  107. * - a pointer to the end of the buffer
  108. *
  109. */
  110. static char *
  111. bitvector_process(char *p, u64 vector)
  112. {
  113. int i,j;
  114. const char *units[]={ "", "K", "M", "G", "T" };
  115. for (i=0, j=0; i < 64; i++ , j=i/10) {
  116. if (vector & 0x1) {
  117. p += sprintf(p, "%d%s ", 1 << (i-j*10), units[j]);
  118. }
  119. vector >>= 1;
  120. }
  121. return p;
  122. }
  123. /*
  124. * Take a 64bit vector and produces a string such that
  125. * if bit n is set then register n is present. The function
  126. * takes into account consecutive registers and prints out ranges.
  127. *
  128. * Input:
  129. * - a pointer to a buffer to hold the string
  130. * - a 64-bit vector
  131. * Ouput:
  132. * - a pointer to the end of the buffer
  133. *
  134. */
  135. static char *
  136. bitregister_process(char *p, u64 *reg_info, int max)
  137. {
  138. int i, begin, skip = 0;
  139. u64 value = reg_info[0];
  140. value >>= i = begin = ffs(value) - 1;
  141. for(; i < max; i++ ) {
  142. if (i != 0 && (i%64) == 0) value = *++reg_info;
  143. if ((value & 0x1) == 0 && skip == 0) {
  144. if (begin <= i - 2)
  145. p += sprintf(p, "%d-%d ", begin, i-1);
  146. else
  147. p += sprintf(p, "%d ", i-1);
  148. skip = 1;
  149. begin = -1;
  150. } else if ((value & 0x1) && skip == 1) {
  151. skip = 0;
  152. begin = i;
  153. }
  154. value >>=1;
  155. }
  156. if (begin > -1) {
  157. if (begin < 127)
  158. p += sprintf(p, "%d-127", begin);
  159. else
  160. p += sprintf(p, "127");
  161. }
  162. return p;
  163. }
  164. static int
  165. power_info(char *page)
  166. {
  167. s64 status;
  168. char *p = page;
  169. u64 halt_info_buffer[8];
  170. pal_power_mgmt_info_u_t *halt_info =(pal_power_mgmt_info_u_t *)halt_info_buffer;
  171. int i;
  172. status = ia64_pal_halt_info(halt_info);
  173. if (status != 0) return 0;
  174. for (i=0; i < 8 ; i++ ) {
  175. if (halt_info[i].pal_power_mgmt_info_s.im == 1) {
  176. p += sprintf(p, "Power level %d:\n"
  177. "\tentry_latency : %d cycles\n"
  178. "\texit_latency : %d cycles\n"
  179. "\tpower consumption : %d mW\n"
  180. "\tCache+TLB coherency : %s\n", i,
  181. halt_info[i].pal_power_mgmt_info_s.entry_latency,
  182. halt_info[i].pal_power_mgmt_info_s.exit_latency,
  183. halt_info[i].pal_power_mgmt_info_s.power_consumption,
  184. halt_info[i].pal_power_mgmt_info_s.co ? "Yes" : "No");
  185. } else {
  186. p += sprintf(p,"Power level %d: not implemented\n",i);
  187. }
  188. }
  189. return p - page;
  190. }
  191. static int
  192. cache_info(char *page)
  193. {
  194. char *p = page;
  195. u64 i, levels, unique_caches;
  196. pal_cache_config_info_t cci;
  197. int j, k;
  198. s64 status;
  199. if ((status = ia64_pal_cache_summary(&levels, &unique_caches)) != 0) {
  200. printk(KERN_ERR "ia64_pal_cache_summary=%ld\n", status);
  201. return 0;
  202. }
  203. p += sprintf(p, "Cache levels : %ld\nUnique caches : %ld\n\n", levels, unique_caches);
  204. for (i=0; i < levels; i++) {
  205. for (j=2; j >0 ; j--) {
  206. /* even without unification some level may not be present */
  207. if ((status=ia64_pal_cache_config_info(i,j, &cci)) != 0) {
  208. continue;
  209. }
  210. p += sprintf(p,
  211. "%s Cache level %lu:\n"
  212. "\tSize : %lu bytes\n"
  213. "\tAttributes : ",
  214. cache_types[j+cci.pcci_unified], i+1,
  215. cci.pcci_cache_size);
  216. if (cci.pcci_unified) p += sprintf(p, "Unified ");
  217. p += sprintf(p, "%s\n", cache_mattrib[cci.pcci_cache_attr]);
  218. p += sprintf(p,
  219. "\tAssociativity : %d\n"
  220. "\tLine size : %d bytes\n"
  221. "\tStride : %d bytes\n",
  222. cci.pcci_assoc, 1<<cci.pcci_line_size, 1<<cci.pcci_stride);
  223. if (j == 1)
  224. p += sprintf(p, "\tStore latency : N/A\n");
  225. else
  226. p += sprintf(p, "\tStore latency : %d cycle(s)\n",
  227. cci.pcci_st_latency);
  228. p += sprintf(p,
  229. "\tLoad latency : %d cycle(s)\n"
  230. "\tStore hints : ", cci.pcci_ld_latency);
  231. for(k=0; k < 8; k++ ) {
  232. if ( cci.pcci_st_hints & 0x1)
  233. p += sprintf(p, "[%s]", cache_st_hints[k]);
  234. cci.pcci_st_hints >>=1;
  235. }
  236. p += sprintf(p, "\n\tLoad hints : ");
  237. for(k=0; k < 8; k++ ) {
  238. if (cci.pcci_ld_hints & 0x1)
  239. p += sprintf(p, "[%s]", cache_ld_hints[k]);
  240. cci.pcci_ld_hints >>=1;
  241. }
  242. p += sprintf(p,
  243. "\n\tAlias boundary : %d byte(s)\n"
  244. "\tTag LSB : %d\n"
  245. "\tTag MSB : %d\n",
  246. 1<<cci.pcci_alias_boundary, cci.pcci_tag_lsb,
  247. cci.pcci_tag_msb);
  248. /* when unified, data(j=2) is enough */
  249. if (cci.pcci_unified) break;
  250. }
  251. }
  252. return p - page;
  253. }
  254. static int
  255. vm_info(char *page)
  256. {
  257. char *p = page;
  258. u64 tr_pages =0, vw_pages=0, tc_pages;
  259. u64 attrib;
  260. pal_vm_info_1_u_t vm_info_1;
  261. pal_vm_info_2_u_t vm_info_2;
  262. pal_tc_info_u_t tc_info;
  263. ia64_ptce_info_t ptce;
  264. const char *sep;
  265. int i, j;
  266. s64 status;
  267. if ((status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2)) !=0) {
  268. printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status);
  269. return 0;
  270. }
  271. p += sprintf(p,
  272. "Physical Address Space : %d bits\n"
  273. "Virtual Address Space : %d bits\n"
  274. "Protection Key Registers(PKR) : %d\n"
  275. "Implemented bits in PKR.key : %d\n"
  276. "Hash Tag ID : 0x%x\n"
  277. "Size of RR.rid : %d\n",
  278. vm_info_1.pal_vm_info_1_s.phys_add_size,
  279. vm_info_2.pal_vm_info_2_s.impl_va_msb+1, vm_info_1.pal_vm_info_1_s.max_pkr+1,
  280. vm_info_1.pal_vm_info_1_s.key_size, vm_info_1.pal_vm_info_1_s.hash_tag_id,
  281. vm_info_2.pal_vm_info_2_s.rid_size);
  282. if (ia64_pal_mem_attrib(&attrib) != 0)
  283. return 0;
  284. p += sprintf(p, "Supported memory attributes : ");
  285. sep = "";
  286. for (i = 0; i < 8; i++) {
  287. if (attrib & (1 << i)) {
  288. p += sprintf(p, "%s%s", sep, mem_attrib[i]);
  289. sep = ", ";
  290. }
  291. }
  292. p += sprintf(p, "\n");
  293. if ((status = ia64_pal_vm_page_size(&tr_pages, &vw_pages)) !=0) {
  294. printk(KERN_ERR "ia64_pal_vm_page_size=%ld\n", status);
  295. return 0;
  296. }
  297. p += sprintf(p,
  298. "\nTLB walker : %simplemented\n"
  299. "Number of DTR : %d\n"
  300. "Number of ITR : %d\n"
  301. "TLB insertable page sizes : ",
  302. vm_info_1.pal_vm_info_1_s.vw ? "" : "not ",
  303. vm_info_1.pal_vm_info_1_s.max_dtr_entry+1,
  304. vm_info_1.pal_vm_info_1_s.max_itr_entry+1);
  305. p = bitvector_process(p, tr_pages);
  306. p += sprintf(p, "\nTLB purgeable page sizes : ");
  307. p = bitvector_process(p, vw_pages);
  308. if ((status=ia64_get_ptce(&ptce)) != 0) {
  309. printk(KERN_ERR "ia64_get_ptce=%ld\n", status);
  310. return 0;
  311. }
  312. p += sprintf(p,
  313. "\nPurge base address : 0x%016lx\n"
  314. "Purge outer loop count : %d\n"
  315. "Purge inner loop count : %d\n"
  316. "Purge outer loop stride : %d\n"
  317. "Purge inner loop stride : %d\n",
  318. ptce.base, ptce.count[0], ptce.count[1], ptce.stride[0], ptce.stride[1]);
  319. p += sprintf(p,
  320. "TC Levels : %d\n"
  321. "Unique TC(s) : %d\n",
  322. vm_info_1.pal_vm_info_1_s.num_tc_levels,
  323. vm_info_1.pal_vm_info_1_s.max_unique_tcs);
  324. for(i=0; i < vm_info_1.pal_vm_info_1_s.num_tc_levels; i++) {
  325. for (j=2; j>0 ; j--) {
  326. tc_pages = 0; /* just in case */
  327. /* even without unification, some levels may not be present */
  328. if ((status=ia64_pal_vm_info(i,j, &tc_info, &tc_pages)) != 0) {
  329. continue;
  330. }
  331. p += sprintf(p,
  332. "\n%s Translation Cache Level %d:\n"
  333. "\tHash sets : %d\n"
  334. "\tAssociativity : %d\n"
  335. "\tNumber of entries : %d\n"
  336. "\tFlags : ",
  337. cache_types[j+tc_info.tc_unified], i+1, tc_info.tc_num_sets,
  338. tc_info.tc_associativity, tc_info.tc_num_entries);
  339. if (tc_info.tc_pf) p += sprintf(p, "PreferredPageSizeOptimized ");
  340. if (tc_info.tc_unified) p += sprintf(p, "Unified ");
  341. if (tc_info.tc_reduce_tr) p += sprintf(p, "TCReduction");
  342. p += sprintf(p, "\n\tSupported page sizes: ");
  343. p = bitvector_process(p, tc_pages);
  344. /* when unified date (j=2) is enough */
  345. if (tc_info.tc_unified) break;
  346. }
  347. }
  348. p += sprintf(p, "\n");
  349. return p - page;
  350. }
  351. static int
  352. register_info(char *page)
  353. {
  354. char *p = page;
  355. u64 reg_info[2];
  356. u64 info;
  357. u64 phys_stacked;
  358. pal_hints_u_t hints;
  359. u64 iregs, dregs;
  360. char *info_type[]={
  361. "Implemented AR(s)",
  362. "AR(s) with read side-effects",
  363. "Implemented CR(s)",
  364. "CR(s) with read side-effects",
  365. };
  366. for(info=0; info < 4; info++) {
  367. if (ia64_pal_register_info(info, &reg_info[0], &reg_info[1]) != 0) return 0;
  368. p += sprintf(p, "%-32s : ", info_type[info]);
  369. p = bitregister_process(p, reg_info, 128);
  370. p += sprintf(p, "\n");
  371. }
  372. if (ia64_pal_rse_info(&phys_stacked, &hints) != 0) return 0;
  373. p += sprintf(p,
  374. "RSE stacked physical registers : %ld\n"
  375. "RSE load/store hints : %ld (%s)\n",
  376. phys_stacked, hints.ph_data,
  377. hints.ph_data < RSE_HINTS_COUNT ? rse_hints[hints.ph_data]: "(??)");
  378. if (ia64_pal_debug_info(&iregs, &dregs))
  379. return 0;
  380. p += sprintf(p,
  381. "Instruction debug register pairs : %ld\n"
  382. "Data debug register pairs : %ld\n", iregs, dregs);
  383. return p - page;
  384. }
  385. static const char *proc_features[]={
  386. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  387. NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,
  388. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  389. NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,
  390. NULL,NULL,NULL,NULL,NULL,
  391. "XIP,XPSR,XFS implemented",
  392. "XR1-XR3 implemented",
  393. "Disable dynamic predicate prediction",
  394. "Disable processor physical number",
  395. "Disable dynamic data cache prefetch",
  396. "Disable dynamic inst cache prefetch",
  397. "Disable dynamic branch prediction",
  398. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  399. "Disable BINIT on processor time-out",
  400. "Disable dynamic power management (DPM)",
  401. "Disable coherency",
  402. "Disable cache",
  403. "Enable CMCI promotion",
  404. "Enable MCA to BINIT promotion",
  405. "Enable MCA promotion",
  406. "Enable BERR promotion"
  407. };
  408. static int
  409. processor_info(char *page)
  410. {
  411. char *p = page;
  412. const char **v = proc_features;
  413. u64 avail=1, status=1, control=1;
  414. int i;
  415. s64 ret;
  416. if ((ret=ia64_pal_proc_get_features(&avail, &status, &control)) != 0) return 0;
  417. for(i=0; i < 64; i++, v++,avail >>=1, status >>=1, control >>=1) {
  418. if ( ! *v ) continue;
  419. p += sprintf(p, "%-40s : %s%s %s\n", *v,
  420. avail & 0x1 ? "" : "NotImpl",
  421. avail & 0x1 ? (status & 0x1 ? "On" : "Off"): "",
  422. avail & 0x1 ? (control & 0x1 ? "Ctrl" : "NoCtrl"): "");
  423. }
  424. return p - page;
  425. }
  426. static const char *bus_features[]={
  427. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  428. NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,
  429. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  430. NULL,NULL,
  431. "Request Bus Parking",
  432. "Bus Lock Mask",
  433. "Enable Half Transfer",
  434. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  435. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  436. NULL, NULL, NULL, NULL,
  437. "Enable Cache Line Repl. Shared",
  438. "Enable Cache Line Repl. Exclusive",
  439. "Disable Transaction Queuing",
  440. "Disable Response Error Checking",
  441. "Disable Bus Error Checking",
  442. "Disable Bus Requester Internal Error Signalling",
  443. "Disable Bus Requester Error Signalling",
  444. "Disable Bus Initialization Event Checking",
  445. "Disable Bus Initialization Event Signalling",
  446. "Disable Bus Address Error Checking",
  447. "Disable Bus Address Error Signalling",
  448. "Disable Bus Data Error Checking"
  449. };
  450. static int
  451. bus_info(char *page)
  452. {
  453. char *p = page;
  454. const char **v = bus_features;
  455. pal_bus_features_u_t av, st, ct;
  456. u64 avail, status, control;
  457. int i;
  458. s64 ret;
  459. if ((ret=ia64_pal_bus_get_features(&av, &st, &ct)) != 0) return 0;
  460. avail = av.pal_bus_features_val;
  461. status = st.pal_bus_features_val;
  462. control = ct.pal_bus_features_val;
  463. for(i=0; i < 64; i++, v++, avail >>=1, status >>=1, control >>=1) {
  464. if ( ! *v ) continue;
  465. p += sprintf(p, "%-48s : %s%s %s\n", *v,
  466. avail & 0x1 ? "" : "NotImpl",
  467. avail & 0x1 ? (status & 0x1 ? "On" : "Off"): "",
  468. avail & 0x1 ? (control & 0x1 ? "Ctrl" : "NoCtrl"): "");
  469. }
  470. return p - page;
  471. }
  472. static int
  473. version_info(char *page)
  474. {
  475. pal_version_u_t min_ver, cur_ver;
  476. char *p = page;
  477. /* The PAL_VERSION call is advertised as being able to support
  478. * both physical and virtual mode calls. This seems to be a documentation
  479. * bug rather than firmware bug. In fact, it does only support physical mode.
  480. * So now the code reflects this fact and the pal_version() has been updated
  481. * accordingly.
  482. */
  483. if (ia64_pal_version(&min_ver, &cur_ver) != 0) return 0;
  484. p += sprintf(p,
  485. "PAL_vendor : 0x%02x (min=0x%02x)\n"
  486. "PAL_A : %x.%x.%x (min=%x.%x.%x)\n"
  487. "PAL_B : %x.%x.%x (min=%x.%x.%x)\n",
  488. cur_ver.pal_version_s.pv_pal_vendor, min_ver.pal_version_s.pv_pal_vendor,
  489. cur_ver.pal_version_s.pv_pal_a_model>>4,
  490. cur_ver.pal_version_s.pv_pal_a_model&0xf, cur_ver.pal_version_s.pv_pal_a_rev,
  491. min_ver.pal_version_s.pv_pal_a_model>>4,
  492. min_ver.pal_version_s.pv_pal_a_model&0xf, min_ver.pal_version_s.pv_pal_a_rev,
  493. cur_ver.pal_version_s.pv_pal_b_model>>4,
  494. cur_ver.pal_version_s.pv_pal_b_model&0xf, cur_ver.pal_version_s.pv_pal_b_rev,
  495. min_ver.pal_version_s.pv_pal_b_model>>4,
  496. min_ver.pal_version_s.pv_pal_b_model&0xf, min_ver.pal_version_s.pv_pal_b_rev);
  497. return p - page;
  498. }
  499. static int
  500. perfmon_info(char *page)
  501. {
  502. char *p = page;
  503. u64 pm_buffer[16];
  504. pal_perf_mon_info_u_t pm_info;
  505. if (ia64_pal_perf_mon_info(pm_buffer, &pm_info) != 0) return 0;
  506. p += sprintf(p,
  507. "PMC/PMD pairs : %d\n"
  508. "Counter width : %d bits\n"
  509. "Cycle event number : %d\n"
  510. "Retired event number : %d\n"
  511. "Implemented PMC : ",
  512. pm_info.pal_perf_mon_info_s.generic, pm_info.pal_perf_mon_info_s.width,
  513. pm_info.pal_perf_mon_info_s.cycles, pm_info.pal_perf_mon_info_s.retired);
  514. p = bitregister_process(p, pm_buffer, 256);
  515. p += sprintf(p, "\nImplemented PMD : ");
  516. p = bitregister_process(p, pm_buffer+4, 256);
  517. p += sprintf(p, "\nCycles count capable : ");
  518. p = bitregister_process(p, pm_buffer+8, 256);
  519. p += sprintf(p, "\nRetired bundles count capable : ");
  520. #ifdef CONFIG_ITANIUM
  521. /*
  522. * PAL_PERF_MON_INFO reports that only PMC4 can be used to count CPU_CYCLES
  523. * which is wrong, both PMC4 and PMD5 support it.
  524. */
  525. if (pm_buffer[12] == 0x10) pm_buffer[12]=0x30;
  526. #endif
  527. p = bitregister_process(p, pm_buffer+12, 256);
  528. p += sprintf(p, "\n");
  529. return p - page;
  530. }
  531. static int
  532. frequency_info(char *page)
  533. {
  534. char *p = page;
  535. struct pal_freq_ratio proc, itc, bus;
  536. u64 base;
  537. if (ia64_pal_freq_base(&base) == -1)
  538. p += sprintf(p, "Output clock : not implemented\n");
  539. else
  540. p += sprintf(p, "Output clock : %ld ticks/s\n", base);
  541. if (ia64_pal_freq_ratios(&proc, &bus, &itc) != 0) return 0;
  542. p += sprintf(p,
  543. "Processor/Clock ratio : %ld/%ld\n"
  544. "Bus/Clock ratio : %ld/%ld\n"
  545. "ITC/Clock ratio : %ld/%ld\n",
  546. proc.num, proc.den, bus.num, bus.den, itc.num, itc.den);
  547. return p - page;
  548. }
  549. static int
  550. tr_info(char *page)
  551. {
  552. char *p = page;
  553. s64 status;
  554. pal_tr_valid_u_t tr_valid;
  555. u64 tr_buffer[4];
  556. pal_vm_info_1_u_t vm_info_1;
  557. pal_vm_info_2_u_t vm_info_2;
  558. u64 i, j;
  559. u64 max[3], pgm;
  560. struct ifa_reg {
  561. u64 valid:1;
  562. u64 ig:11;
  563. u64 vpn:52;
  564. } *ifa_reg;
  565. struct itir_reg {
  566. u64 rv1:2;
  567. u64 ps:6;
  568. u64 key:24;
  569. u64 rv2:32;
  570. } *itir_reg;
  571. struct gr_reg {
  572. u64 p:1;
  573. u64 rv1:1;
  574. u64 ma:3;
  575. u64 a:1;
  576. u64 d:1;
  577. u64 pl:2;
  578. u64 ar:3;
  579. u64 ppn:38;
  580. u64 rv2:2;
  581. u64 ed:1;
  582. u64 ig:11;
  583. } *gr_reg;
  584. struct rid_reg {
  585. u64 ig1:1;
  586. u64 rv1:1;
  587. u64 ig2:6;
  588. u64 rid:24;
  589. u64 rv2:32;
  590. } *rid_reg;
  591. if ((status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2)) !=0) {
  592. printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status);
  593. return 0;
  594. }
  595. max[0] = vm_info_1.pal_vm_info_1_s.max_itr_entry+1;
  596. max[1] = vm_info_1.pal_vm_info_1_s.max_dtr_entry+1;
  597. for (i=0; i < 2; i++ ) {
  598. for (j=0; j < max[i]; j++) {
  599. status = ia64_pal_tr_read(j, i, tr_buffer, &tr_valid);
  600. if (status != 0) {
  601. printk(KERN_ERR "palinfo: pal call failed on tr[%lu:%lu]=%ld\n",
  602. i, j, status);
  603. continue;
  604. }
  605. ifa_reg = (struct ifa_reg *)&tr_buffer[2];
  606. if (ifa_reg->valid == 0) continue;
  607. gr_reg = (struct gr_reg *)tr_buffer;
  608. itir_reg = (struct itir_reg *)&tr_buffer[1];
  609. rid_reg = (struct rid_reg *)&tr_buffer[3];
  610. pgm = -1 << (itir_reg->ps - 12);
  611. p += sprintf(p,
  612. "%cTR%lu: av=%d pv=%d dv=%d mv=%d\n"
  613. "\tppn : 0x%lx\n"
  614. "\tvpn : 0x%lx\n"
  615. "\tps : ",
  616. "ID"[i], j,
  617. tr_valid.pal_tr_valid_s.access_rights_valid,
  618. tr_valid.pal_tr_valid_s.priv_level_valid,
  619. tr_valid.pal_tr_valid_s.dirty_bit_valid,
  620. tr_valid.pal_tr_valid_s.mem_attr_valid,
  621. (gr_reg->ppn & pgm)<< 12, (ifa_reg->vpn & pgm)<< 12);
  622. p = bitvector_process(p, 1<< itir_reg->ps);
  623. p += sprintf(p,
  624. "\n\tpl : %d\n"
  625. "\tar : %d\n"
  626. "\trid : %x\n"
  627. "\tp : %d\n"
  628. "\tma : %d\n"
  629. "\td : %d\n",
  630. gr_reg->pl, gr_reg->ar, rid_reg->rid, gr_reg->p, gr_reg->ma,
  631. gr_reg->d);
  632. }
  633. }
  634. return p - page;
  635. }
  636. /*
  637. * List {name,function} pairs for every entry in /proc/palinfo/cpu*
  638. */
  639. static palinfo_entry_t palinfo_entries[]={
  640. { "version_info", version_info, },
  641. { "vm_info", vm_info, },
  642. { "cache_info", cache_info, },
  643. { "power_info", power_info, },
  644. { "register_info", register_info, },
  645. { "processor_info", processor_info, },
  646. { "perfmon_info", perfmon_info, },
  647. { "frequency_info", frequency_info, },
  648. { "bus_info", bus_info },
  649. { "tr_info", tr_info, }
  650. };
  651. #define NR_PALINFO_ENTRIES (int) ARRAY_SIZE(palinfo_entries)
  652. /*
  653. * this array is used to keep track of the proc entries we create. This is
  654. * required in the module mode when we need to remove all entries. The procfs code
  655. * does not do recursion of deletion
  656. *
  657. * Notes:
  658. * - +1 accounts for the cpuN directory entry in /proc/pal
  659. */
  660. #define NR_PALINFO_PROC_ENTRIES (NR_CPUS*(NR_PALINFO_ENTRIES+1))
  661. static struct proc_dir_entry *palinfo_proc_entries[NR_PALINFO_PROC_ENTRIES];
  662. static struct proc_dir_entry *palinfo_dir;
  663. /*
  664. * This data structure is used to pass which cpu,function is being requested
  665. * It must fit in a 64bit quantity to be passed to the proc callback routine
  666. *
  667. * In SMP mode, when we get a request for another CPU, we must call that
  668. * other CPU using IPI and wait for the result before returning.
  669. */
  670. typedef union {
  671. u64 value;
  672. struct {
  673. unsigned req_cpu: 32; /* for which CPU this info is */
  674. unsigned func_id: 32; /* which function is requested */
  675. } pal_func_cpu;
  676. } pal_func_cpu_u_t;
  677. #define req_cpu pal_func_cpu.req_cpu
  678. #define func_id pal_func_cpu.func_id
  679. #ifdef CONFIG_SMP
  680. /*
  681. * used to hold information about final function to call
  682. */
  683. typedef struct {
  684. palinfo_func_t func; /* pointer to function to call */
  685. char *page; /* buffer to store results */
  686. int ret; /* return value from call */
  687. } palinfo_smp_data_t;
  688. /*
  689. * this function does the actual final call and he called
  690. * from the smp code, i.e., this is the palinfo callback routine
  691. */
  692. static void
  693. palinfo_smp_call(void *info)
  694. {
  695. palinfo_smp_data_t *data = (palinfo_smp_data_t *)info;
  696. if (data == NULL) {
  697. printk(KERN_ERR "palinfo: data pointer is NULL\n");
  698. data->ret = 0; /* no output */
  699. return;
  700. }
  701. /* does this actual call */
  702. data->ret = (*data->func)(data->page);
  703. }
  704. /*
  705. * function called to trigger the IPI, we need to access a remote CPU
  706. * Return:
  707. * 0 : error or nothing to output
  708. * otherwise how many bytes in the "page" buffer were written
  709. */
  710. static
  711. int palinfo_handle_smp(pal_func_cpu_u_t *f, char *page)
  712. {
  713. palinfo_smp_data_t ptr;
  714. int ret;
  715. ptr.func = palinfo_entries[f->func_id].proc_read;
  716. ptr.page = page;
  717. ptr.ret = 0; /* just in case */
  718. /* will send IPI to other CPU and wait for completion of remote call */
  719. if ((ret=smp_call_function_single(f->req_cpu, palinfo_smp_call, &ptr, 0, 1))) {
  720. printk(KERN_ERR "palinfo: remote CPU call from %d to %d on function %d: "
  721. "error %d\n", smp_processor_id(), f->req_cpu, f->func_id, ret);
  722. return 0;
  723. }
  724. return ptr.ret;
  725. }
  726. #else /* ! CONFIG_SMP */
  727. static
  728. int palinfo_handle_smp(pal_func_cpu_u_t *f, char *page)
  729. {
  730. printk(KERN_ERR "palinfo: should not be called with non SMP kernel\n");
  731. return 0;
  732. }
  733. #endif /* CONFIG_SMP */
  734. /*
  735. * Entry point routine: all calls go through this function
  736. */
  737. static int
  738. palinfo_read_entry(char *page, char **start, off_t off, int count, int *eof, void *data)
  739. {
  740. int len=0;
  741. pal_func_cpu_u_t *f = (pal_func_cpu_u_t *)&data;
  742. /*
  743. * in SMP mode, we may need to call another CPU to get correct
  744. * information. PAL, by definition, is processor specific
  745. */
  746. if (f->req_cpu == get_cpu())
  747. len = (*palinfo_entries[f->func_id].proc_read)(page);
  748. else
  749. len = palinfo_handle_smp(f, page);
  750. put_cpu();
  751. if (len <= off+count) *eof = 1;
  752. *start = page + off;
  753. len -= off;
  754. if (len>count) len = count;
  755. if (len<0) len = 0;
  756. return len;
  757. }
  758. static void
  759. create_palinfo_proc_entries(unsigned int cpu)
  760. {
  761. # define CPUSTR "cpu%d"
  762. pal_func_cpu_u_t f;
  763. struct proc_dir_entry **pdir;
  764. struct proc_dir_entry *cpu_dir;
  765. int j;
  766. char cpustr[sizeof(CPUSTR)];
  767. /*
  768. * we keep track of created entries in a depth-first order for
  769. * cleanup purposes. Each entry is stored into palinfo_proc_entries
  770. */
  771. sprintf(cpustr,CPUSTR, cpu);
  772. cpu_dir = proc_mkdir(cpustr, palinfo_dir);
  773. f.req_cpu = cpu;
  774. /*
  775. * Compute the location to store per cpu entries
  776. * We dont store the top level entry in this list, but
  777. * remove it finally after removing all cpu entries.
  778. */
  779. pdir = &palinfo_proc_entries[cpu*(NR_PALINFO_ENTRIES+1)];
  780. *pdir++ = cpu_dir;
  781. for (j=0; j < NR_PALINFO_ENTRIES; j++) {
  782. f.func_id = j;
  783. *pdir = create_proc_read_entry(
  784. palinfo_entries[j].name, 0, cpu_dir,
  785. palinfo_read_entry, (void *)f.value);
  786. if (*pdir)
  787. (*pdir)->owner = THIS_MODULE;
  788. pdir++;
  789. }
  790. }
  791. static void
  792. remove_palinfo_proc_entries(unsigned int hcpu)
  793. {
  794. int j;
  795. struct proc_dir_entry *cpu_dir, **pdir;
  796. pdir = &palinfo_proc_entries[hcpu*(NR_PALINFO_ENTRIES+1)];
  797. cpu_dir = *pdir;
  798. *pdir++=NULL;
  799. for (j=0; j < (NR_PALINFO_ENTRIES); j++) {
  800. if ((*pdir)) {
  801. remove_proc_entry ((*pdir)->name, cpu_dir);
  802. *pdir ++= NULL;
  803. }
  804. }
  805. if (cpu_dir) {
  806. remove_proc_entry(cpu_dir->name, palinfo_dir);
  807. }
  808. }
  809. static int __devinit palinfo_cpu_callback(struct notifier_block *nfb,
  810. unsigned long action,
  811. void *hcpu)
  812. {
  813. unsigned int hotcpu = (unsigned long)hcpu;
  814. switch (action) {
  815. case CPU_ONLINE:
  816. create_palinfo_proc_entries(hotcpu);
  817. break;
  818. #ifdef CONFIG_HOTPLUG_CPU
  819. case CPU_DEAD:
  820. remove_palinfo_proc_entries(hotcpu);
  821. break;
  822. #endif
  823. }
  824. return NOTIFY_OK;
  825. }
  826. static struct notifier_block palinfo_cpu_notifier =
  827. {
  828. .notifier_call = palinfo_cpu_callback,
  829. .priority = 0,
  830. };
  831. static int __init
  832. palinfo_init(void)
  833. {
  834. int i = 0;
  835. printk(KERN_INFO "PAL Information Facility v%s\n", PALINFO_VERSION);
  836. palinfo_dir = proc_mkdir("pal", NULL);
  837. /* Create palinfo dirs in /proc for all online cpus */
  838. for_each_online_cpu(i) {
  839. create_palinfo_proc_entries(i);
  840. }
  841. /* Register for future delivery via notify registration */
  842. register_cpu_notifier(&palinfo_cpu_notifier);
  843. return 0;
  844. }
  845. static void __exit
  846. palinfo_exit(void)
  847. {
  848. int i = 0;
  849. /* remove all nodes: depth first pass. Could optimize this */
  850. for_each_online_cpu(i) {
  851. remove_palinfo_proc_entries(i);
  852. }
  853. /*
  854. * Remove the top level entry finally
  855. */
  856. remove_proc_entry(palinfo_dir->name, NULL);
  857. /*
  858. * Unregister from cpu notifier callbacks
  859. */
  860. unregister_cpu_notifier(&palinfo_cpu_notifier);
  861. }
  862. module_init(palinfo_init);
  863. module_exit(palinfo_exit);