coresight-etm-cp14.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <asm/hardware/cp14.h>
  15. static unsigned int etm_read_reg(uint32_t reg)
  16. {
  17. switch (reg) {
  18. case 0x0:
  19. return etm_read(ETMCR);
  20. case 0x1:
  21. return etm_read(ETMCCR);
  22. case 0x2:
  23. return etm_read(ETMTRIGGER);
  24. case 0x4:
  25. return etm_read(ETMSR);
  26. case 0x5:
  27. return etm_read(ETMSCR);
  28. case 0x6:
  29. return etm_read(ETMTSSCR);
  30. case 0x8:
  31. return etm_read(ETMTEEVR);
  32. case 0x9:
  33. return etm_read(ETMTECR1);
  34. case 0xB:
  35. return etm_read(ETMFFLR);
  36. case 0x10:
  37. return etm_read(ETMACVR0);
  38. case 0x11:
  39. return etm_read(ETMACVR1);
  40. case 0x12:
  41. return etm_read(ETMACVR2);
  42. case 0x13:
  43. return etm_read(ETMACVR3);
  44. case 0x14:
  45. return etm_read(ETMACVR4);
  46. case 0x15:
  47. return etm_read(ETMACVR5);
  48. case 0x16:
  49. return etm_read(ETMACVR6);
  50. case 0x17:
  51. return etm_read(ETMACVR7);
  52. case 0x18:
  53. return etm_read(ETMACVR8);
  54. case 0x19:
  55. return etm_read(ETMACVR9);
  56. case 0x1A:
  57. return etm_read(ETMACVR10);
  58. case 0x1B:
  59. return etm_read(ETMACVR11);
  60. case 0x1C:
  61. return etm_read(ETMACVR12);
  62. case 0x1D:
  63. return etm_read(ETMACVR13);
  64. case 0x1E:
  65. return etm_read(ETMACVR14);
  66. case 0x1F:
  67. return etm_read(ETMACVR15);
  68. case 0x20:
  69. return etm_read(ETMACTR0);
  70. case 0x21:
  71. return etm_read(ETMACTR1);
  72. case 0x22:
  73. return etm_read(ETMACTR2);
  74. case 0x23:
  75. return etm_read(ETMACTR3);
  76. case 0x24:
  77. return etm_read(ETMACTR4);
  78. case 0x25:
  79. return etm_read(ETMACTR5);
  80. case 0x26:
  81. return etm_read(ETMACTR6);
  82. case 0x27:
  83. return etm_read(ETMACTR7);
  84. case 0x28:
  85. return etm_read(ETMACTR8);
  86. case 0x29:
  87. return etm_read(ETMACTR9);
  88. case 0x2A:
  89. return etm_read(ETMACTR10);
  90. case 0x2B:
  91. return etm_read(ETMACTR11);
  92. case 0x2C:
  93. return etm_read(ETMACTR12);
  94. case 0x2D:
  95. return etm_read(ETMACTR13);
  96. case 0x2E:
  97. return etm_read(ETMACTR14);
  98. case 0x2F:
  99. return etm_read(ETMACTR15);
  100. case 0x50:
  101. return etm_read(ETMCNTRLDVR0);
  102. case 0x51:
  103. return etm_read(ETMCNTRLDVR1);
  104. case 0x52:
  105. return etm_read(ETMCNTRLDVR2);
  106. case 0x53:
  107. return etm_read(ETMCNTRLDVR3);
  108. case 0x54:
  109. return etm_read(ETMCNTENR0);
  110. case 0x55:
  111. return etm_read(ETMCNTENR1);
  112. case 0x56:
  113. return etm_read(ETMCNTENR2);
  114. case 0x57:
  115. return etm_read(ETMCNTENR3);
  116. case 0x58:
  117. return etm_read(ETMCNTRLDEVR0);
  118. case 0x59:
  119. return etm_read(ETMCNTRLDEVR1);
  120. case 0x5A:
  121. return etm_read(ETMCNTRLDEVR2);
  122. case 0x5B:
  123. return etm_read(ETMCNTRLDEVR3);
  124. case 0x5C:
  125. return etm_read(ETMCNTVR0);
  126. case 0x5D:
  127. return etm_read(ETMCNTVR1);
  128. case 0x5E:
  129. return etm_read(ETMCNTVR2);
  130. case 0x5F:
  131. return etm_read(ETMCNTVR3);
  132. case 0x60:
  133. return etm_read(ETMSQ12EVR);
  134. case 0x61:
  135. return etm_read(ETMSQ21EVR);
  136. case 0x62:
  137. return etm_read(ETMSQ23EVR);
  138. case 0x63:
  139. return etm_read(ETMSQ31EVR);
  140. case 0x64:
  141. return etm_read(ETMSQ32EVR);
  142. case 0x65:
  143. return etm_read(ETMSQ13EVR);
  144. case 0x67:
  145. return etm_read(ETMSQR);
  146. case 0x68:
  147. return etm_read(ETMEXTOUTEVR0);
  148. case 0x69:
  149. return etm_read(ETMEXTOUTEVR1);
  150. case 0x6A:
  151. return etm_read(ETMEXTOUTEVR2);
  152. case 0x6B:
  153. return etm_read(ETMEXTOUTEVR3);
  154. case 0x6C:
  155. return etm_read(ETMCIDCVR0);
  156. case 0x6D:
  157. return etm_read(ETMCIDCVR1);
  158. case 0x6E:
  159. return etm_read(ETMCIDCVR2);
  160. case 0x6F:
  161. return etm_read(ETMCIDCMR);
  162. case 0x70:
  163. return etm_read(ETMIMPSPEC0);
  164. case 0x71:
  165. return etm_read(ETMIMPSPEC1);
  166. case 0x72:
  167. return etm_read(ETMIMPSPEC2);
  168. case 0x73:
  169. return etm_read(ETMIMPSPEC3);
  170. case 0x74:
  171. return etm_read(ETMIMPSPEC4);
  172. case 0x75:
  173. return etm_read(ETMIMPSPEC5);
  174. case 0x76:
  175. return etm_read(ETMIMPSPEC6);
  176. case 0x77:
  177. return etm_read(ETMIMPSPEC7);
  178. case 0x78:
  179. return etm_read(ETMSYNCFR);
  180. case 0x79:
  181. return etm_read(ETMIDR);
  182. case 0x7A:
  183. return etm_read(ETMCCER);
  184. case 0x7B:
  185. return etm_read(ETMEXTINSELR);
  186. case 0x7C:
  187. return etm_read(ETMTESSEICR);
  188. case 0x7D:
  189. return etm_read(ETMEIBCR);
  190. case 0x7E:
  191. return etm_read(ETMTSEVR);
  192. case 0x7F:
  193. return etm_read(ETMAUXCR);
  194. case 0x80:
  195. return etm_read(ETMTRACEIDR);
  196. case 0x90:
  197. return etm_read(ETMVMIDCVR);
  198. case 0xC1:
  199. return etm_read(ETMOSLSR);
  200. case 0xC2:
  201. return etm_read(ETMOSSRR);
  202. case 0xC4:
  203. return etm_read(ETMPDCR);
  204. case 0xC5:
  205. return etm_read(ETMPDSR);
  206. default:
  207. WARN(1, "invalid CP14 access to ETM reg: %lx",
  208. (unsigned long)reg);
  209. return 0;
  210. }
  211. }
  212. static void etm_write_reg(uint32_t val, uint32_t reg)
  213. {
  214. switch (reg) {
  215. case 0x0:
  216. etm_write(val, ETMCR);
  217. return;
  218. case 0x2:
  219. etm_write(val, ETMTRIGGER);
  220. return;
  221. case 0x4:
  222. etm_write(val, ETMSR);
  223. return;
  224. case 0x6:
  225. etm_write(val, ETMTSSCR);
  226. return;
  227. case 0x8:
  228. etm_write(val, ETMTEEVR);
  229. return;
  230. case 0x9:
  231. etm_write(val, ETMTECR1);
  232. return;
  233. case 0xB:
  234. etm_write(val, ETMFFLR);
  235. return;
  236. case 0x10:
  237. etm_write(val, ETMACVR0);
  238. return;
  239. case 0x11:
  240. etm_write(val, ETMACVR1);
  241. return;
  242. case 0x12:
  243. etm_write(val, ETMACVR2);
  244. return;
  245. case 0x13:
  246. etm_write(val, ETMACVR3);
  247. return;
  248. case 0x14:
  249. etm_write(val, ETMACVR4);
  250. return;
  251. case 0x15:
  252. etm_write(val, ETMACVR5);
  253. return;
  254. case 0x16:
  255. etm_write(val, ETMACVR6);
  256. return;
  257. case 0x17:
  258. etm_write(val, ETMACVR7);
  259. return;
  260. case 0x18:
  261. etm_write(val, ETMACVR8);
  262. return;
  263. case 0x19:
  264. etm_write(val, ETMACVR9);
  265. return;
  266. case 0x1A:
  267. etm_write(val, ETMACVR10);
  268. return;
  269. case 0x1B:
  270. etm_write(val, ETMACVR11);
  271. return;
  272. case 0x1C:
  273. etm_write(val, ETMACVR12);
  274. return;
  275. case 0x1D:
  276. etm_write(val, ETMACVR13);
  277. return;
  278. case 0x1E:
  279. etm_write(val, ETMACVR14);
  280. return;
  281. case 0x1F:
  282. etm_write(val, ETMACVR15);
  283. return;
  284. case 0x20:
  285. etm_write(val, ETMACTR0);
  286. return;
  287. case 0x21:
  288. etm_write(val, ETMACTR1);
  289. return;
  290. case 0x22:
  291. etm_write(val, ETMACTR2);
  292. return;
  293. case 0x23:
  294. etm_write(val, ETMACTR3);
  295. return;
  296. case 0x24:
  297. etm_write(val, ETMACTR4);
  298. return;
  299. case 0x25:
  300. etm_write(val, ETMACTR5);
  301. return;
  302. case 0x26:
  303. etm_write(val, ETMACTR6);
  304. return;
  305. case 0x27:
  306. etm_write(val, ETMACTR7);
  307. return;
  308. case 0x28:
  309. etm_write(val, ETMACTR8);
  310. return;
  311. case 0x29:
  312. etm_write(val, ETMACTR9);
  313. return;
  314. case 0x2A:
  315. etm_write(val, ETMACTR10);
  316. return;
  317. case 0x2B:
  318. etm_write(val, ETMACTR11);
  319. return;
  320. case 0x2C:
  321. etm_write(val, ETMACTR12);
  322. return;
  323. case 0x2D:
  324. etm_write(val, ETMACTR13);
  325. return;
  326. case 0x2E:
  327. etm_write(val, ETMACTR14);
  328. return;
  329. case 0x2F:
  330. etm_write(val, ETMACTR15);
  331. return;
  332. case 0x50:
  333. etm_write(val, ETMCNTRLDVR0);
  334. return;
  335. case 0x51:
  336. etm_write(val, ETMCNTRLDVR1);
  337. return;
  338. case 0x52:
  339. etm_write(val, ETMCNTRLDVR2);
  340. return;
  341. case 0x53:
  342. etm_write(val, ETMCNTRLDVR3);
  343. return;
  344. case 0x54:
  345. etm_write(val, ETMCNTENR0);
  346. return;
  347. case 0x55:
  348. etm_write(val, ETMCNTENR1);
  349. return;
  350. case 0x56:
  351. etm_write(val, ETMCNTENR2);
  352. return;
  353. case 0x57:
  354. etm_write(val, ETMCNTENR3);
  355. return;
  356. case 0x58:
  357. etm_write(val, ETMCNTRLDEVR0);
  358. return;
  359. case 0x59:
  360. etm_write(val, ETMCNTRLDEVR1);
  361. return;
  362. case 0x5A:
  363. etm_write(val, ETMCNTRLDEVR2);
  364. return;
  365. case 0x5B:
  366. etm_write(val, ETMCNTRLDEVR3);
  367. return;
  368. case 0x5C:
  369. etm_write(val, ETMCNTVR0);
  370. return;
  371. case 0x5D:
  372. etm_write(val, ETMCNTVR1);
  373. return;
  374. case 0x5E:
  375. etm_write(val, ETMCNTVR2);
  376. return;
  377. case 0x5F:
  378. etm_write(val, ETMCNTVR3);
  379. return;
  380. case 0x60:
  381. etm_write(val, ETMSQ12EVR);
  382. return;
  383. case 0x61:
  384. etm_write(val, ETMSQ21EVR);
  385. return;
  386. case 0x62:
  387. etm_write(val, ETMSQ23EVR);
  388. return;
  389. case 0x63:
  390. etm_write(val, ETMSQ31EVR);
  391. return;
  392. case 0x64:
  393. etm_write(val, ETMSQ32EVR);
  394. return;
  395. case 0x65:
  396. etm_write(val, ETMSQ13EVR);
  397. return;
  398. case 0x67:
  399. etm_write(val, ETMSQR);
  400. return;
  401. case 0x68:
  402. etm_write(val, ETMEXTOUTEVR0);
  403. return;
  404. case 0x69:
  405. etm_write(val, ETMEXTOUTEVR1);
  406. return;
  407. case 0x6A:
  408. etm_write(val, ETMEXTOUTEVR2);
  409. return;
  410. case 0x6B:
  411. etm_write(val, ETMEXTOUTEVR3);
  412. return;
  413. case 0x6C:
  414. etm_write(val, ETMCIDCVR0);
  415. return;
  416. case 0x6D:
  417. etm_write(val, ETMCIDCVR1);
  418. return;
  419. case 0x6E:
  420. etm_write(val, ETMCIDCVR2);
  421. return;
  422. case 0x6F:
  423. etm_write(val, ETMCIDCMR);
  424. return;
  425. case 0x70:
  426. etm_write(val, ETMIMPSPEC0);
  427. return;
  428. case 0x71:
  429. etm_write(val, ETMIMPSPEC1);
  430. return;
  431. case 0x72:
  432. etm_write(val, ETMIMPSPEC2);
  433. return;
  434. case 0x73:
  435. etm_write(val, ETMIMPSPEC3);
  436. return;
  437. case 0x74:
  438. etm_write(val, ETMIMPSPEC4);
  439. return;
  440. case 0x75:
  441. etm_write(val, ETMIMPSPEC5);
  442. return;
  443. case 0x76:
  444. etm_write(val, ETMIMPSPEC6);
  445. return;
  446. case 0x77:
  447. etm_write(val, ETMIMPSPEC7);
  448. return;
  449. case 0x78:
  450. etm_write(val, ETMSYNCFR);
  451. return;
  452. case 0x7B:
  453. etm_write(val, ETMEXTINSELR);
  454. return;
  455. case 0x7C:
  456. etm_write(val, ETMTESSEICR);
  457. return;
  458. case 0x7D:
  459. etm_write(val, ETMEIBCR);
  460. return;
  461. case 0x7E:
  462. etm_write(val, ETMTSEVR);
  463. return;
  464. case 0x7F:
  465. etm_write(val, ETMAUXCR);
  466. return;
  467. case 0x80:
  468. etm_write(val, ETMTRACEIDR);
  469. return;
  470. case 0x90:
  471. etm_write(val, ETMVMIDCVR);
  472. return;
  473. case 0xC0:
  474. etm_write(val, ETMOSLAR);
  475. return;
  476. case 0xC2:
  477. etm_write(val, ETMOSSRR);
  478. return;
  479. case 0xC4:
  480. etm_write(val, ETMPDCR);
  481. return;
  482. case 0xC5:
  483. etm_write(val, ETMPDSR);
  484. return;
  485. default:
  486. WARN(1, "invalid CP14 access to ETM reg: %lx",
  487. (unsigned long)reg);
  488. return;
  489. }
  490. }
  491. static inline uint32_t offset_to_reg_num(uint32_t off)
  492. {
  493. return off >> 2;
  494. }
  495. unsigned int etm_readl_cp14(uint32_t off)
  496. {
  497. uint32_t reg = offset_to_reg_num(off);
  498. return etm_read_reg(reg);
  499. }
  500. void etm_writel_cp14(uint32_t val, uint32_t off)
  501. {
  502. uint32_t reg = offset_to_reg_num(off);
  503. etm_write_reg(val, reg);
  504. }