mtk_ram_console.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. #include <linux/slab.h>
  2. #include <mt-plat/aee.h>
  3. #include <linux/atomic.h>
  4. #include <linux/console.h>
  5. #include <linux/delay.h>
  6. #include <linux/init.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/proc_fs.h>
  10. #include <linux/string.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/vmalloc.h>
  14. #include <linux/mm.h>
  15. #include <linux/fs.h>
  16. #include <linux/file.h>
  17. #include <linux/kthread.h>
  18. #include <linux/of.h>
  19. #include <linux/of_fdt.h>
  20. #include <linux/of_reserved_mem.h>
  21. #include <linux/pstore.h>
  22. #include <linux/io.h>
  23. #include <mach/wd_api.h>
  24. #include "ram_console.h"
  25. #include <mt-plat/mt_debug_latch.h>
  26. #define RAM_CONSOLE_HEADER_STR_LEN 1024
  27. static int mtk_cpu_num;
  28. static int ram_console_init_done;
  29. static unsigned int old_wdt_status;
  30. static int ram_console_clear;
  31. /*
  32. This group of API call by sub-driver module to report reboot reasons
  33. aee_rr_* stand for previous reboot reason
  34. */
  35. struct last_reboot_reason {
  36. uint32_t fiq_step;
  37. uint32_t exp_type; /* 0xaeedeadX: X=1 (HWT), X=2 (KE), X=3 (nested panic) */
  38. uint32_t reboot_mode;
  39. uint32_t last_irq_enter[NR_CPUS];
  40. uint64_t jiffies_last_irq_enter[NR_CPUS];
  41. uint32_t last_irq_exit[NR_CPUS];
  42. uint64_t jiffies_last_irq_exit[NR_CPUS];
  43. uint64_t jiffies_last_sched[NR_CPUS];
  44. char last_sched_comm[NR_CPUS][TASK_COMM_LEN];
  45. uint8_t hotplug_data1[NR_CPUS];
  46. uint8_t hotplug_data2;
  47. uint64_t hotplug_data3;
  48. uint32_t mcdi_wfi;
  49. uint32_t mcdi_r15;
  50. uint32_t deepidle_data;
  51. uint32_t sodi3_data;
  52. uint32_t sodi_data;
  53. uint32_t spm_suspend_data;
  54. uint64_t cpu_dormant[NR_CPUS];
  55. uint32_t clk_data[8];
  56. uint32_t suspend_debug_flag;
  57. uint32_t vcore_dvfs_opp;
  58. uint32_t vcore_dvfs_status;
  59. uint8_t cpu_dvfs_vproc_big;
  60. uint8_t cpu_dvfs_vproc_little;
  61. uint8_t cpu_dvfs_oppidx;
  62. uint8_t cpu_dvfs_status;
  63. uint8_t gpu_dvfs_vgpu;
  64. uint8_t gpu_dvfs_oppidx;
  65. uint8_t gpu_dvfs_status;
  66. uint64_t ptp_cpu_big_volt;
  67. uint64_t ptp_cpu_little_volt;
  68. uint64_t ptp_gpu_volt;
  69. uint64_t ptp_temp;
  70. uint8_t ptp_status;
  71. uint8_t thermal_temp1;
  72. uint8_t thermal_temp2;
  73. uint8_t thermal_temp3;
  74. uint8_t thermal_temp4;
  75. uint8_t thermal_temp5;
  76. uint8_t thermal_status;
  77. uint8_t isr_el1;
  78. void *kparams;
  79. };
  80. struct reboot_reason_pl {
  81. u32 wdt_status;
  82. u32 data[0];
  83. };
  84. struct reboot_reason_lk {
  85. u32 data[0];
  86. };
  87. struct ram_console_buffer {
  88. uint32_t sig;
  89. /* for size comptible */
  90. uint32_t off_pl;
  91. uint32_t off_lpl; /* last preloader: struct reboot_reason_pl */
  92. uint32_t sz_pl;
  93. uint32_t off_lk;
  94. uint32_t off_llk; /* last lk: struct reboot_reason_lk */
  95. uint32_t sz_lk;
  96. uint32_t padding[3];
  97. uint32_t sz_buffer;
  98. uint32_t off_linux; /* struct last_reboot_reason */
  99. uint32_t off_console;
  100. /* console buffer */
  101. uint32_t log_start;
  102. uint32_t log_size;
  103. uint32_t sz_console;
  104. };
  105. #define REBOOT_REASON_SIG (0x43474244) /* DBRR */
  106. static int FIQ_log_size = sizeof(struct ram_console_buffer);
  107. static struct ram_console_buffer *ram_console_buffer;
  108. static struct ram_console_buffer *ram_console_old;
  109. static struct ram_console_buffer *ram_console_buffer_pa;
  110. static DEFINE_SPINLOCK(ram_console_lock);
  111. static atomic_t rc_in_fiq = ATOMIC_INIT(0);
  112. #ifdef __aarch64__
  113. static void *_memcpy(void *dest, const void *src, size_t count)
  114. {
  115. char *tmp = dest;
  116. const char *s = src;
  117. while (count--)
  118. *tmp++ = *s++;
  119. return dest;
  120. }
  121. #define memcpy _memcpy
  122. #endif
  123. #define LAST_RR_SEC_VAL(header, sect, type, item) \
  124. (header->off_##sect ? ((type *)((void *)header + header->off_##sect))->item : 0)
  125. #define LAST_RRR_BUF_VAL(buf, rr_item) LAST_RR_SEC_VAL(buf, linux, struct last_reboot_reason, rr_item)
  126. #define LAST_RRPL_BUF_VAL(buf, rr_item) LAST_RR_SEC_VAL(buf, pl, struct reboot_reason_pl, rr_item)
  127. #define LAST_RRR_VAL(rr_item) LAST_RR_SEC_VAL(ram_console_old, linux, struct last_reboot_reason, rr_item)
  128. #define LAST_RRPL_VAL(rr_item) LAST_RR_SEC_VAL(ram_console_old, pl, struct reboot_reason_pl, rr_item)
  129. unsigned int ram_console_size(void)
  130. {
  131. return ram_console_buffer->sz_console;
  132. }
  133. #ifdef CONFIG_MTK_EMMC_SUPPORT
  134. #ifdef CONFIG_MTK_AEE_IPANIC
  135. #include <mt-plat/sd_misc.h>
  136. #define EMMC_ADDR 0X700000
  137. static char *ram_console2_log;
  138. void last_kmsg_store_to_emmc(void)
  139. {
  140. int buff_size;
  141. struct wd_api *wd_api = NULL;
  142. get_wd_api(&wd_api);
  143. /* if(num_online_cpus() > 1){ */
  144. if (wd_api->wd_get_check_bit() > 1) {
  145. pr_err("ram_console: online cpu %d!\n", wd_api->wd_get_check_bit());
  146. #ifdef CONFIG_MTPROF
  147. if (boot_finish == 0)
  148. return;
  149. #endif
  150. }
  151. /* save log to emmc */
  152. buff_size = ram_console_buffer->sz_buffer;
  153. card_dump_func_write((unsigned char *)ram_console_buffer, buff_size, EMMC_ADDR,
  154. DUMP_INTO_BOOT_CARD_IPANIC);
  155. pr_err("ram_console: save kernel log (0x%x) to emmc!\n", buff_size);
  156. }
  157. static int ram_console_lastk_show(struct ram_console_buffer *buffer, struct seq_file *m, void *v);
  158. static int ram_console2_show(struct seq_file *m, void *v)
  159. {
  160. struct ram_console_buffer *bufp = NULL;
  161. bufp = (struct ram_console_buffer *)ram_console2_log;
  162. seq_printf(m, "show last_kmsg2 sig %d, size %d", bufp->sig, bufp->log_size);
  163. ram_console_lastk_show(bufp, m, v);
  164. return 0;
  165. }
  166. static int ram_console2_file_open(struct inode *inode, struct file *file)
  167. {
  168. return single_open(file, ram_console2_show, inode->i_private);
  169. }
  170. static const struct file_operations ram_console2_file_ops = {
  171. .owner = THIS_MODULE,
  172. .open = ram_console2_file_open,
  173. .read = seq_read,
  174. .llseek = seq_lseek,
  175. .release = single_release,
  176. };
  177. static int emmc_read_last_kmsg(void *data)
  178. {
  179. int ret;
  180. struct file *filp;
  181. struct proc_dir_entry *entry;
  182. struct ram_console_buffer *bufp = NULL;
  183. int timeout = 0;
  184. ram_console2_log = kzalloc(ram_console_buffer->sz_buffer, GFP_KERNEL);
  185. if (ram_console2_log == NULL)
  186. return 1;
  187. do {
  188. filp = expdb_open();
  189. if (timeout++ > 60) {
  190. pr_err("ram_console: open expdb partition error [%ld]!\n", PTR_ERR(filp));
  191. return 1;
  192. }
  193. msleep(500);
  194. } while (IS_ERR(filp));
  195. ret = kernel_read(filp, EMMC_ADDR, ram_console2_log, ram_console_buffer->sz_buffer);
  196. fput(filp);
  197. if (IS_ERR(ERR_PTR(ret))) {
  198. kfree(ram_console2_log);
  199. ram_console2_log = NULL;
  200. pr_err("ram_console: read emmc data 2 error!\n");
  201. return 1;
  202. }
  203. bufp = (struct ram_console_buffer *)ram_console2_log;
  204. if (bufp->sig != REBOOT_REASON_SIG) {
  205. kfree(ram_console2_log);
  206. ram_console2_log = NULL;
  207. pr_err("ram_console: emmc read data sig is not match!\n");
  208. return 1;
  209. }
  210. entry = proc_create("last_kmsg2", 0444, NULL, &ram_console2_file_ops);
  211. if (!entry) {
  212. pr_err("ram_console: failed to create proc entry\n");
  213. kfree(ram_console2_log);
  214. ram_console2_log = NULL;
  215. return 1;
  216. }
  217. pr_err("ram_console: create last_kmsg2 ok.\n");
  218. return 0;
  219. }
  220. #else
  221. void last_kmsg_store_to_emmc(void)
  222. {
  223. }
  224. #endif
  225. #endif
  226. #ifdef CONFIG_PSTORE
  227. void sram_log_save(const char *msg, int count)
  228. {
  229. pstore_bconsole_write(NULL, msg, count);
  230. }
  231. void pstore_console_show(enum pstore_type_id type_id, struct seq_file *m, void *v)
  232. {
  233. struct pstore_info *psi = psinfo;
  234. char *buf = NULL;
  235. ssize_t size;
  236. u64 id;
  237. int count;
  238. enum pstore_type_id type;
  239. struct timespec time;
  240. bool compressed;
  241. if (!psi)
  242. return;
  243. mutex_lock(&psi->read_mutex);
  244. if (psi->open && psi->open(psi))
  245. goto out;
  246. while ((size = psi->read(&id, &type, &count, &time, &buf, &compressed, psi)) > 0) {
  247. /*pr_err("ram_console: id %lld, type %d, count %d, size %zx\n", id, type, count,
  248. size);*/
  249. if (type == type_id)
  250. seq_write(m, buf, size);
  251. kfree(buf);
  252. buf = NULL;
  253. }
  254. if (psi->close)
  255. psi->close(psi);
  256. out:
  257. mutex_unlock(&psi->read_mutex);
  258. }
  259. #else
  260. void sram_log_save(const char *msg, int count)
  261. {
  262. struct ram_console_buffer *buffer;
  263. char *rc_console;
  264. int rem;
  265. unsigned int ram_console_buffer_size = ram_console_size();
  266. if (ram_console_buffer == NULL) {
  267. pr_err("ram console buffer is NULL!\n");
  268. return;
  269. }
  270. buffer = ram_console_buffer;
  271. rc_console = (char *)ram_console_buffer + ram_console_buffer->off_console;
  272. /* count >= buffer_size, full the buffer */
  273. if (count >= ram_console_buffer_size) {
  274. memcpy(rc_console, msg + (count - ram_console_buffer_size),
  275. ram_console_buffer_size);
  276. buffer->log_start = 0;
  277. buffer->log_size = ram_console_buffer_size;
  278. } else if (count > (ram_console_buffer_size - buffer->log_start)) {
  279. /* count > last buffer, full them and fill the head buffer */
  280. rem = ram_console_buffer_size - buffer->log_start;
  281. memcpy(rc_console + buffer->log_start, msg, rem);
  282. memcpy(rc_console, msg + rem, count - rem);
  283. buffer->log_start = count - rem;
  284. buffer->log_size = ram_console_buffer_size;
  285. } else {
  286. /* count <= last buffer, fill in free buffer */
  287. memcpy(rc_console + buffer->log_start, msg, count); /* count <= last buffer, fill them */
  288. buffer->log_start += count;
  289. buffer->log_size += count;
  290. if (buffer->log_start >= ram_console_buffer_size)
  291. buffer->log_start = 0;
  292. if (buffer->log_size > ram_console_buffer_size)
  293. buffer->log_size = ram_console_buffer_size;
  294. }
  295. }
  296. #endif
  297. #ifdef __aarch64__
  298. #define FORMAT_LONG "%016lx "
  299. #else
  300. #define FORMAT_LONG "%08lx "
  301. #endif
  302. void aee_sram_fiq_save_bin(const char *msg, size_t len)
  303. {
  304. int i;
  305. char buf[20];
  306. for (i = 0; i < len;) {
  307. snprintf(buf, sizeof(long) * 2 + 2, FORMAT_LONG, *(long *)(msg + i));
  308. sram_log_save(buf, sizeof(long) * 2 + 1);
  309. i += sizeof(long);
  310. if (i % 32 == 0)
  311. sram_log_save("\n", 1);
  312. }
  313. }
  314. void aee_disable_ram_console_write(void)
  315. {
  316. atomic_set(&rc_in_fiq, 1);
  317. }
  318. void aee_sram_fiq_log(const char *msg)
  319. {
  320. unsigned int count = strlen(msg);
  321. int delay = 100;
  322. unsigned int ram_console_buffer_size = ram_console_size();
  323. if (FIQ_log_size + count > ram_console_buffer_size)
  324. return;
  325. atomic_set(&rc_in_fiq, 1);
  326. while ((delay > 0) && (spin_is_locked(&ram_console_lock))) {
  327. udelay(1);
  328. delay--;
  329. }
  330. sram_log_save(msg, count);
  331. FIQ_log_size += count;
  332. }
  333. void ram_console_write(struct console *console, const char *s, unsigned int count)
  334. {
  335. unsigned long flags;
  336. if (atomic_read(&rc_in_fiq))
  337. return;
  338. spin_lock_irqsave(&ram_console_lock, flags);
  339. sram_log_save(s, count);
  340. spin_unlock_irqrestore(&ram_console_lock, flags);
  341. }
  342. static struct console ram_console = {
  343. .name = "ram",
  344. .write = ram_console_write,
  345. .flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME,
  346. .index = -1,
  347. };
  348. void ram_console_enable_console(int enabled)
  349. {
  350. if (enabled)
  351. ram_console.flags |= CON_ENABLED;
  352. else
  353. ram_console.flags &= ~CON_ENABLED;
  354. }
  355. static int ram_console_check_header(struct ram_console_buffer *buffer)
  356. {
  357. /*int i;*/
  358. if (!buffer || (buffer->sz_buffer != ram_console_buffer->sz_buffer) || buffer->off_pl > buffer->sz_buffer
  359. || buffer->off_lk > buffer->sz_buffer || buffer->off_linux > buffer->sz_buffer
  360. || buffer->off_console > buffer->sz_buffer
  361. || buffer->off_pl + ALIGN(buffer->sz_pl, 64) != buffer->off_lpl
  362. || buffer->off_lk + ALIGN(buffer->sz_lk, 64) != buffer->off_llk) {
  363. pr_err("ram_console: ilegal header.");
  364. /*
  365. for (i = 0; i < 16; i++)
  366. pr_debug("0x%x ", ((int*)buffer)[i]);
  367. pr_debug("\n");
  368. */
  369. return -1;
  370. } else
  371. return 0;
  372. }
  373. static int ram_console_lastk_show(struct ram_console_buffer *buffer, struct seq_file *m, void *v)
  374. {
  375. unsigned int wdt_status;
  376. if (ram_console_check_header(buffer) && buffer->sz_buffer != 0) {
  377. pr_err("ram_console: buffer %p, size %x(%x)\n", buffer, buffer->sz_buffer,
  378. ram_console_buffer->sz_buffer);
  379. if (buffer)
  380. seq_write(m, buffer, ram_console_buffer->sz_buffer);
  381. else
  382. seq_puts(m, "NO VALID DATA.\n");
  383. return 0;
  384. }
  385. if (buffer->off_pl == 0 || buffer->off_pl + ALIGN(buffer->sz_pl, 64) != buffer->off_lpl) {
  386. /* workaround for compatiblity to old preloader & lk (OTA) */
  387. wdt_status = *((unsigned char *)buffer + 12);
  388. } else
  389. wdt_status = LAST_RRPL_BUF_VAL(buffer, wdt_status);
  390. seq_printf(m, "ram console header, hw_status: %u, fiq step %u.\n",
  391. wdt_status, LAST_RRR_BUF_VAL(buffer, fiq_step));
  392. seq_printf(m, "%s, old status is %u.\n", ram_console_clear ? "Clear" : "Not Clear", old_wdt_status);
  393. #ifdef CONFIG_PSTORE_CONSOLE
  394. /*pr_err("ram_console: pstore show start\n");*/
  395. pstore_console_show(PSTORE_TYPE_CONSOLE, m, v);
  396. /*pr_err("ram_console: pstore show end\n");*/
  397. #else
  398. if (buffer->off_console != 0
  399. && buffer->off_linux + ALIGN(sizeof(struct last_reboot_reason),
  400. 64) == buffer->off_console
  401. && buffer->sz_console == buffer->sz_buffer - buffer->off_console
  402. && buffer->log_size <= buffer->sz_console && buffer->log_start <= buffer->sz_console) {
  403. seq_write(m, (void *)buffer + buffer->off_console + buffer->log_start,
  404. buffer->log_size - buffer->log_start);
  405. seq_write(m, (void *)buffer + buffer->off_console, buffer->log_start);
  406. } else {
  407. seq_puts(m, "header may be corrupted, dump the raw buffer for reference only\n");
  408. seq_write(m, buffer, ram_console_buffer->sz_buffer);
  409. }
  410. #endif
  411. return 0;
  412. }
  413. static int __init ram_console_save_old(struct ram_console_buffer *buffer, size_t buffer_size)
  414. {
  415. ram_console_old = kmalloc(buffer_size, GFP_KERNEL);
  416. if (ram_console_old == NULL) {
  417. pr_err("ram_console: failed to allocate old buffer\n");
  418. return -1;
  419. }
  420. memcpy(ram_console_old, buffer, buffer_size);
  421. return 0;
  422. }
  423. static int __init ram_console_init(struct ram_console_buffer *buffer, size_t buffer_size)
  424. {
  425. ram_console_buffer = buffer;
  426. buffer->sz_buffer = buffer_size;
  427. old_wdt_status = LAST_RRPL_BUF_VAL(buffer, wdt_status);
  428. if (buffer->sig != REBOOT_REASON_SIG || ram_console_check_header(buffer)) {
  429. memset_io((void *)buffer, 0, buffer_size);
  430. buffer->sig = REBOOT_REASON_SIG;
  431. ram_console_clear = 1;
  432. }
  433. ram_console_save_old(buffer, buffer_size);
  434. if (buffer->sz_lk != 0 && buffer->off_lk + ALIGN(buffer->sz_lk, 64) == buffer->off_llk)
  435. buffer->off_linux = buffer->off_llk + ALIGN(buffer->sz_lk, 64);
  436. else
  437. buffer->off_linux = 512; /* OTA:leave enough space for pl/lk */
  438. buffer->sz_buffer = buffer_size;
  439. buffer->off_console = buffer->off_linux + ALIGN(sizeof(struct last_reboot_reason), 64);
  440. buffer->sz_console = buffer->sz_buffer - buffer->off_console;
  441. buffer->log_start = 0;
  442. buffer->log_size = 0;
  443. memset_io((void *)buffer + buffer->off_linux, 0, buffer_size - buffer->off_linux);
  444. #ifndef CONFIG_PSTORE
  445. register_console(&ram_console);
  446. #endif
  447. ram_console_init_done = 1;
  448. return 0;
  449. }
  450. #if defined(CONFIG_MTK_RAM_CONSOLE_USING_DRAM)
  451. static void *remap_lowmem(phys_addr_t start, phys_addr_t size)
  452. {
  453. struct page **pages;
  454. phys_addr_t page_start;
  455. unsigned int page_count;
  456. pgprot_t prot;
  457. unsigned int i;
  458. void *vaddr;
  459. page_start = start - offset_in_page(start);
  460. page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
  461. prot = pgprot_noncached(PAGE_KERNEL);
  462. pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
  463. if (!pages)
  464. return NULL;
  465. for (i = 0; i < page_count; i++) {
  466. phys_addr_t addr = page_start + i * PAGE_SIZE;
  467. pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
  468. }
  469. vaddr = vmap(pages, page_count, VM_MAP, prot);
  470. kfree(pages);
  471. if (!vaddr) {
  472. pr_err("%s: Failed to map %u pages\n", __func__, page_count);
  473. return NULL;
  474. }
  475. return vaddr + offset_in_page(start);
  476. }
  477. #endif
  478. struct mem_desc_t {
  479. unsigned long start;
  480. unsigned long size;
  481. };
  482. #if defined(CONFIG_MTK_RAM_CONSOLE_USING_SRAM)
  483. #ifdef CONFIG_OF
  484. static int __init dt_get_ram_console(unsigned long node, const char *uname, int depth, void *data)
  485. {
  486. struct mem_desc_t *sram;
  487. if (depth != 1 || (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
  488. return 0;
  489. sram = (struct mem_desc_t *) of_get_flat_dt_prop(node, "non_secure_sram", NULL);
  490. if (sram) {
  491. pr_notice("ram_console:[DT] 0x%lx@0x%lx\n", sram->size, sram->start);
  492. *(struct mem_desc_t *) data = *sram;
  493. }
  494. return 1;
  495. }
  496. #endif
  497. #endif
  498. static int __init ram_console_early_init(void)
  499. {
  500. struct ram_console_buffer *bufp = NULL;
  501. size_t buffer_size = 0;
  502. #if defined(CONFIG_MTK_RAM_CONSOLE_USING_SRAM)
  503. #ifdef CONFIG_OF
  504. struct mem_desc_t sram = { 0 };
  505. if (of_scan_flat_dt(dt_get_ram_console, &sram)) {
  506. if (sram.start == 0) {
  507. sram.start = CONFIG_MTK_RAM_CONSOLE_ADDR;
  508. sram.size = CONFIG_MTK_RAM_CONSOLE_SIZE;
  509. }
  510. bufp = ioremap(sram.start, sram.size);
  511. ram_console_buffer_pa = (struct ram_console_buffer *)sram.start;
  512. if (bufp)
  513. buffer_size = sram.size;
  514. else {
  515. pr_err("ram_console: ioremap failed, [0x%lx, 0x%lx]\n", sram.start,
  516. sram.size);
  517. return 0;
  518. }
  519. } else {
  520. return 0;
  521. }
  522. #else
  523. bufp = ioremap(CONFIG_MTK_RAM_CONSOLE_ADDR, CONFIG_MTK_RAM_CONSOLE_SIZE);
  524. if (bufp)
  525. buffer_size = CONFIG_MTK_RAM_CONSOLE_SIZE;
  526. ram_console_buffer_pa = CONFIG_MTK_RAM_CONSOLE_ADDR;
  527. else {
  528. pr_err("ram_console: ioremap failed, [0x%x, 0x%x]\n", sram.start, sram.size);
  529. return 0;
  530. }
  531. #endif
  532. #elif defined(CONFIG_MTK_RAM_CONSOLE_USING_DRAM)
  533. bufp = remap_lowmem(CONFIG_MTK_RAM_CONSOLE_DRAM_ADDR, CONFIG_MTK_RAM_CONSOLE_DRAM_SIZE);
  534. ram_console_buffer_pa = (struct ram_console_buffer *)CONFIG_MTK_RAM_CONSOLE_DRAM_ADDR;
  535. if (bufp == NULL) {
  536. pr_err("ram_console: ioremap failed\n");
  537. return 0;
  538. }
  539. buffer_size = CONFIG_MTK_RAM_CONSOLE_DRAM_SIZE;
  540. #else
  541. return 0;
  542. #endif
  543. pr_err("ram_console: buffer start: 0x%p, size: 0x%zx\n", bufp, buffer_size);
  544. mtk_cpu_num = num_present_cpus();
  545. return ram_console_init(bufp, buffer_size);
  546. }
  547. static int ram_console_show(struct seq_file *m, void *v)
  548. {
  549. ram_console_lastk_show(ram_console_old, m, v);
  550. return 0;
  551. }
  552. static int ram_console_file_open(struct inode *inode, struct file *file)
  553. {
  554. return single_open(file, ram_console_show, inode->i_private);
  555. }
  556. static const struct file_operations ram_console_file_ops = {
  557. .owner = THIS_MODULE,
  558. .open = ram_console_file_open,
  559. .read = seq_read,
  560. .llseek = seq_lseek,
  561. .release = single_release,
  562. };
  563. static int __init ram_console_late_init(void)
  564. {
  565. struct proc_dir_entry *entry;
  566. #ifdef CONFIG_MTK_EMMC_SUPPORT
  567. #ifdef CONFIG_MTK_AEE_IPANIC
  568. int err;
  569. static struct task_struct *thread;
  570. thread = kthread_run(emmc_read_last_kmsg, 0, "read_poweroff_log");
  571. if (IS_ERR(thread)) {
  572. err = PTR_ERR(thread);
  573. pr_err("ram_console: failed to create kernel thread: %d\n", err);
  574. }
  575. #endif
  576. #endif
  577. entry = proc_create("last_kmsg", 0444, NULL, &ram_console_file_ops);
  578. if (!entry) {
  579. pr_err("ram_console: failed to create proc entry\n");
  580. kfree(ram_console_old);
  581. ram_console_old = NULL;
  582. return 0;
  583. }
  584. return 0;
  585. }
  586. console_initcall(ram_console_early_init);
  587. late_initcall(ram_console_late_init);
  588. int ram_console_pstore_reserve_memory(struct reserved_mem *rmem)
  589. {
  590. pr_alert("[memblock]%s: 0x%llx - 0x%llx (0x%llx)\n", "pstore-reserve-memory",
  591. (unsigned long long)rmem->base,
  592. (unsigned long long)rmem->base + (unsigned long long)rmem->size,
  593. (unsigned long long)rmem->size);
  594. return 0;
  595. }
  596. int ram_console_binary_reserve_memory(struct reserved_mem *rmem)
  597. {
  598. pr_alert("[memblock]%s: 0x%llx - 0x%llx (0x%llx)\n", "ram_console-reserve-memory",
  599. (unsigned long long)rmem->base,
  600. (unsigned long long)rmem->base + (unsigned long long)rmem->size,
  601. (unsigned long long)rmem->size);
  602. return 0;
  603. }
  604. RESERVEDMEM_OF_DECLARE(reserve_memory_pstore, "pstore-reserve-memory",
  605. ram_console_pstore_reserve_memory);
  606. RESERVEDMEM_OF_DECLARE(reserve_memory_ram_console, "mediatek,ram_console",
  607. ram_console_binary_reserve_memory);
  608. /* aee sram flags save */
  609. #define RR_BASE(stage) ((void *)ram_console_buffer + ram_console_buffer->off_##stage)
  610. #define RR_LINUX ((struct last_reboot_reason *)RR_BASE(linux))
  611. #define RR_BASE_PA(stage) ((void *)ram_console_buffer_pa + ram_console_buffer->off_##stage)
  612. #define RR_LINUX_PA ((struct last_reboot_reason *)RR_BASE_PA(linux))
  613. /*NOTICE: You should check if ram_console is null before call these macros*/
  614. #define LAST_RR_SET(rr_item, value) (RR_LINUX->rr_item = value)
  615. #define LAST_RR_SET_WITH_ID(rr_item, id, value) (RR_LINUX->rr_item[id] = value)
  616. #define LAST_RR_VAL(rr_item) \
  617. (ram_console_buffer ? RR_LINUX->rr_item : 0)
  618. #define LAST_RR_MEMCPY(rr_item, str, len) \
  619. (strlcpy(RR_LINUX->rr_item, str, len))
  620. #define LAST_RR_MEMCPY_WITH_ID(rr_item, id, str, len) \
  621. (strlcpy(RR_LINUX->rr_item[id], str, len))
  622. void aee_rr_rec_reboot_mode(u8 mode)
  623. {
  624. if (!ram_console_init_done || !ram_console_buffer)
  625. return;
  626. LAST_RR_SET(reboot_mode, mode);
  627. }
  628. void aee_rr_rec_kdump_params(void *params)
  629. {
  630. if (!ram_console_init_done || !ram_console_buffer)
  631. return;
  632. LAST_RR_SET(kparams, params);
  633. }
  634. void aee_rr_rec_fiq_step(u8 step)
  635. {
  636. if (!ram_console_init_done || !ram_console_buffer)
  637. return;
  638. LAST_RR_SET(fiq_step, step);
  639. }
  640. int aee_rr_curr_fiq_step(void)
  641. {
  642. return LAST_RR_VAL(fiq_step);
  643. }
  644. void aee_rr_rec_exp_type(unsigned int type)
  645. {
  646. if (!ram_console_init_done || !ram_console_buffer)
  647. return;
  648. if (LAST_RR_VAL(exp_type) == 0 && type < 16)
  649. LAST_RR_SET(exp_type, 0xaeedead0 | type);
  650. }
  651. unsigned int aee_rr_curr_exp_type(void)
  652. {
  653. unsigned int exp_type = LAST_RR_VAL(exp_type);
  654. return (exp_type ^ 0xaeedead0) < 16 ? exp_type ^ 0xaeedead0 : exp_type;
  655. }
  656. /* composite api */
  657. void aee_rr_rec_last_irq_enter(int cpu, int irq, u64 jiffies)
  658. {
  659. if (!ram_console_init_done || !ram_console_buffer)
  660. return;
  661. if (cpu >= 0 && cpu < num_possible_cpus()) {
  662. LAST_RR_SET_WITH_ID(last_irq_enter, cpu, irq);
  663. LAST_RR_SET_WITH_ID(jiffies_last_irq_enter, cpu, jiffies);
  664. }
  665. mb(); /*TODO:need add comments */
  666. }
  667. void aee_rr_rec_last_irq_exit(int cpu, int irq, u64 jiffies)
  668. {
  669. if (!ram_console_init_done || !ram_console_buffer)
  670. return;
  671. if (cpu >= 0 && cpu < num_possible_cpus()) {
  672. LAST_RR_SET_WITH_ID(last_irq_exit, cpu, irq);
  673. LAST_RR_SET_WITH_ID(jiffies_last_irq_exit, cpu, jiffies);
  674. }
  675. mb(); /*TODO:need add comments */
  676. }
  677. void aee_rr_rec_last_sched_jiffies(int cpu, u64 jiffies, const char *comm)
  678. {
  679. if (!ram_console_init_done || !ram_console_buffer)
  680. return;
  681. if (cpu >= 0 && cpu < num_possible_cpus()) {
  682. LAST_RR_SET_WITH_ID(jiffies_last_sched, cpu, jiffies);
  683. LAST_RR_MEMCPY_WITH_ID(last_sched_comm, cpu, comm, TASK_COMM_LEN);
  684. }
  685. mb(); /*TODO:need add comments */
  686. }
  687. void aee_rr_rec_hoplug(int cpu, u8 data1, u8 data2)
  688. {
  689. if (!ram_console_init_done || !ram_console_buffer)
  690. return;
  691. if (cpu >= 0 && cpu < num_possible_cpus()) {
  692. LAST_RR_SET_WITH_ID(hotplug_data1, cpu, data1);
  693. if (cpu == 0)
  694. LAST_RR_SET(hotplug_data2, data2);
  695. }
  696. }
  697. void aee_rr_rec_hotplug(int cpu, u8 data1, u8 data2, unsigned long data3)
  698. {
  699. if (!ram_console_init_done || !ram_console_buffer)
  700. return;
  701. if (cpu >= 0 && cpu < num_possible_cpus()) {
  702. LAST_RR_SET_WITH_ID(hotplug_data1, cpu, data1);
  703. if (cpu == 0) {
  704. LAST_RR_SET(hotplug_data2, data2);
  705. LAST_RR_SET(hotplug_data3, (uint64_t) data3);
  706. }
  707. }
  708. }
  709. void aee_rr_rec_clk(int id, u32 val)
  710. {
  711. if (!ram_console_init_done || !ram_console_buffer)
  712. return;
  713. LAST_RR_SET_WITH_ID(clk_data, id, val);
  714. }
  715. void aee_rr_rec_deepidle_val(u32 val)
  716. {
  717. if (!ram_console_init_done || !ram_console_buffer)
  718. return;
  719. LAST_RR_SET(deepidle_data, val);
  720. }
  721. u32 aee_rr_curr_deepidle_val(void)
  722. {
  723. return LAST_RR_VAL(deepidle_data);
  724. }
  725. void aee_rr_rec_mcdi_wfi_val(u32 val)
  726. {
  727. if (!ram_console_init_done || !ram_console_buffer)
  728. return;
  729. LAST_RR_SET(mcdi_wfi, val);
  730. }
  731. u32 aee_rr_curr_mcdi_wfi_val(void)
  732. {
  733. return LAST_RR_VAL(mcdi_wfi);
  734. }
  735. void aee_rr_rec_mcdi_r15_val(u32 val)
  736. {
  737. if (!ram_console_init_done || !ram_console_buffer)
  738. return;
  739. LAST_RR_SET(mcdi_r15, val);
  740. }
  741. void aee_rr_rec_sodi_val(u32 val)
  742. {
  743. if (!ram_console_init_done || !ram_console_buffer)
  744. return;
  745. LAST_RR_SET(sodi_data, val);
  746. }
  747. void aee_rr_rec_sodi3_val(u32 val)
  748. {
  749. if (!ram_console_init_done)
  750. return;
  751. LAST_RR_SET(sodi3_data, val);
  752. }
  753. u32 aee_rr_curr_sodi3_val(void)
  754. {
  755. if (!ram_console_init_done)
  756. return 0;
  757. return LAST_RR_VAL(sodi3_data);
  758. }
  759. u32 aee_rr_curr_sodi_val(void)
  760. {
  761. return LAST_RR_VAL(sodi_data);
  762. }
  763. void aee_rr_rec_spm_suspend_val(u32 val)
  764. {
  765. if (!ram_console_init_done || !ram_console_buffer)
  766. return;
  767. LAST_RR_SET(spm_suspend_data, val);
  768. }
  769. u32 aee_rr_curr_spm_suspend_val(void)
  770. {
  771. return LAST_RR_VAL(spm_suspend_data);
  772. }
  773. /* special case without MMU, return addr directly, strongly suggest not to use */
  774. unsigned int *aee_rr_rec_mcdi_wfi(void)
  775. {
  776. #if 0
  777. if (ram_console_buffer)
  778. return &RR_LINUX->mcdi_wfi;
  779. else
  780. return NULL;
  781. #endif
  782. return NULL;
  783. }
  784. unsigned long *aee_rr_rec_cpu_dormant(void)
  785. {
  786. if (ram_console_buffer)
  787. return (unsigned long *)&RR_LINUX->cpu_dormant;
  788. else
  789. return NULL;
  790. }
  791. unsigned long *aee_rr_rec_cpu_dormant_pa(void)
  792. {
  793. if (ram_console_buffer_pa)
  794. return (unsigned long *)&RR_LINUX_PA->cpu_dormant;
  795. else
  796. return NULL;
  797. }
  798. void aee_rr_rec_vcore_dvfs_opp(u32 val)
  799. {
  800. if (!ram_console_init_done)
  801. return;
  802. LAST_RR_SET(vcore_dvfs_opp, val);
  803. }
  804. u32 aee_rr_curr_vcore_dvfs_opp(void)
  805. {
  806. return LAST_RR_VAL(vcore_dvfs_opp);
  807. }
  808. void aee_rr_rec_vcore_dvfs_status(u32 val)
  809. {
  810. if (!ram_console_init_done)
  811. return;
  812. LAST_RR_SET(vcore_dvfs_status, val);
  813. }
  814. u32 aee_rr_curr_vcore_dvfs_status(void)
  815. {
  816. return LAST_RR_VAL(vcore_dvfs_status);
  817. }
  818. void aee_rr_rec_cpu_dvfs_vproc_big(u8 val)
  819. {
  820. if (!ram_console_init_done || !ram_console_buffer)
  821. return;
  822. LAST_RR_SET(cpu_dvfs_vproc_big, val);
  823. }
  824. void aee_rr_rec_cpu_dvfs_vproc_little(u8 val)
  825. {
  826. if (!ram_console_init_done || !ram_console_buffer)
  827. return;
  828. LAST_RR_SET(cpu_dvfs_vproc_little, val);
  829. }
  830. void aee_rr_rec_cpu_dvfs_oppidx(u8 val)
  831. {
  832. if (!ram_console_init_done || !ram_console_buffer)
  833. return;
  834. LAST_RR_SET(cpu_dvfs_oppidx, val);
  835. }
  836. u8 aee_rr_curr_cpu_dvfs_oppidx(void)
  837. {
  838. return LAST_RR_VAL(cpu_dvfs_oppidx);
  839. }
  840. void aee_rr_rec_cpu_dvfs_status(u8 val)
  841. {
  842. if (!ram_console_init_done || !ram_console_buffer)
  843. return;
  844. LAST_RR_SET(cpu_dvfs_status, val);
  845. }
  846. u8 aee_rr_curr_cpu_dvfs_status(void)
  847. {
  848. return LAST_RR_VAL(cpu_dvfs_status);
  849. }
  850. void aee_rr_rec_gpu_dvfs_vgpu(u8 val)
  851. {
  852. if (!ram_console_init_done || !ram_console_buffer)
  853. return;
  854. LAST_RR_SET(gpu_dvfs_vgpu, val);
  855. }
  856. void aee_rr_rec_gpu_dvfs_oppidx(u8 val)
  857. {
  858. if (!ram_console_init_done || !ram_console_buffer)
  859. return;
  860. LAST_RR_SET(gpu_dvfs_oppidx, val);
  861. }
  862. void aee_rr_rec_gpu_dvfs_status(u8 val)
  863. {
  864. if (!ram_console_init_done || !ram_console_buffer)
  865. return;
  866. LAST_RR_SET(gpu_dvfs_status, val);
  867. }
  868. u8 aee_rr_curr_gpu_dvfs_status(void)
  869. {
  870. return LAST_RR_VAL(gpu_dvfs_status);
  871. }
  872. void aee_rr_rec_ptp_cpu_big_volt(u64 val)
  873. {
  874. if (!ram_console_init_done || !ram_console_buffer)
  875. return;
  876. LAST_RR_SET(ptp_cpu_big_volt, val);
  877. }
  878. void aee_rr_rec_ptp_cpu_little_volt(u64 val)
  879. {
  880. if (!ram_console_init_done || !ram_console_buffer)
  881. return;
  882. LAST_RR_SET(ptp_cpu_little_volt, val);
  883. }
  884. void aee_rr_rec_ptp_gpu_volt(u64 val)
  885. {
  886. if (!ram_console_init_done || !ram_console_buffer)
  887. return;
  888. LAST_RR_SET(ptp_gpu_volt, val);
  889. }
  890. void aee_rr_rec_ptp_temp(u64 val)
  891. {
  892. if (!ram_console_init_done || !ram_console_buffer)
  893. return;
  894. LAST_RR_SET(ptp_temp, val);
  895. }
  896. void aee_rr_rec_ptp_status(u8 val)
  897. {
  898. if (!ram_console_init_done || !ram_console_buffer)
  899. return;
  900. LAST_RR_SET(ptp_status, val);
  901. }
  902. void aee_rr_rec_thermal_temp1(u8 val)
  903. {
  904. if (!ram_console_init_done || !ram_console_buffer)
  905. return;
  906. LAST_RR_SET(thermal_temp1, val);
  907. }
  908. void aee_rr_rec_thermal_temp2(u8 val)
  909. {
  910. if (!ram_console_init_done || !ram_console_buffer)
  911. return;
  912. LAST_RR_SET(thermal_temp2, val);
  913. }
  914. void aee_rr_rec_thermal_temp3(u8 val)
  915. {
  916. if (!ram_console_init_done || !ram_console_buffer)
  917. return;
  918. LAST_RR_SET(thermal_temp3, val);
  919. }
  920. void aee_rr_rec_thermal_temp4(u8 val)
  921. {
  922. if (!ram_console_init_done || !ram_console_buffer)
  923. return;
  924. LAST_RR_SET(thermal_temp4, val);
  925. }
  926. void aee_rr_rec_thermal_temp5(u8 val)
  927. {
  928. if (!ram_console_init_done || !ram_console_buffer)
  929. return;
  930. LAST_RR_SET(thermal_temp5, val);
  931. }
  932. void aee_rr_rec_thermal_status(u8 val)
  933. {
  934. if (!ram_console_init_done || !ram_console_buffer)
  935. return;
  936. LAST_RR_SET(thermal_status, val);
  937. }
  938. void aee_rr_rec_isr_el1(u8 val)
  939. {
  940. if (!ram_console_init_done || !ram_console_buffer)
  941. return;
  942. LAST_RR_SET(isr_el1, val);
  943. }
  944. u64 aee_rr_curr_ptp_cpu_big_volt(void)
  945. {
  946. return LAST_RR_VAL(ptp_cpu_big_volt);
  947. }
  948. u64 aee_rr_curr_ptp_cpu_little_volt(void)
  949. {
  950. return LAST_RR_VAL(ptp_cpu_little_volt);
  951. }
  952. u64 aee_rr_curr_ptp_gpu_volt(void)
  953. {
  954. return LAST_RR_VAL(ptp_gpu_volt);
  955. }
  956. u64 aee_rr_curr_ptp_temp(void)
  957. {
  958. return LAST_RR_VAL(ptp_temp);
  959. }
  960. u8 aee_rr_curr_ptp_status(void)
  961. {
  962. return LAST_RR_VAL(ptp_status);
  963. }
  964. u8 aee_rr_curr_thermal_temp1(void)
  965. {
  966. return LAST_RR_VAL(thermal_temp1);
  967. }
  968. u8 aee_rr_curr_thermal_temp2(void)
  969. {
  970. return LAST_RR_VAL(thermal_temp2);
  971. }
  972. u8 aee_rr_curr_thermal_temp3(void)
  973. {
  974. return LAST_RR_VAL(thermal_temp3);
  975. }
  976. u8 aee_rr_curr_thermal_temp4(void)
  977. {
  978. return LAST_RR_VAL(thermal_temp4);
  979. }
  980. u8 aee_rr_curr_thermal_temp5(void)
  981. {
  982. return LAST_RR_VAL(thermal_temp5);
  983. }
  984. u8 aee_rr_curr_thermal_status(void)
  985. {
  986. return LAST_RR_VAL(thermal_status);
  987. }
  988. u8 aee_rr_curr_isr_el1(void)
  989. {
  990. return LAST_RR_VAL(isr_el1);
  991. }
  992. void aee_rr_rec_suspend_debug_flag(u32 val)
  993. {
  994. if (!ram_console_init_done || !ram_console_buffer)
  995. return;
  996. LAST_RR_SET(suspend_debug_flag, val);
  997. }
  998. /* aee sram flags print */
  999. int aee_rr_last_fiq_step(void)
  1000. {
  1001. return LAST_RRR_VAL(fiq_step);
  1002. }
  1003. typedef void (*last_rr_show_t) (struct seq_file *m);
  1004. typedef void (*last_rr_show_cpu_t) (struct seq_file *m, int cpu);
  1005. void aee_rr_show_wdt_status(struct seq_file *m)
  1006. {
  1007. unsigned int wdt_status;
  1008. struct ram_console_buffer *buffer = ram_console_old;
  1009. if (buffer->off_pl == 0 || buffer->off_pl + ALIGN(buffer->sz_pl, 64) != buffer->off_lpl) {
  1010. /* workaround for compatiblity to old preloader & lk (OTA) */
  1011. wdt_status = *((unsigned char *)buffer + 12);
  1012. } else
  1013. wdt_status = LAST_RRPL_VAL(wdt_status);
  1014. seq_printf(m, "WDT status: %d", wdt_status);
  1015. }
  1016. void aee_rr_show_fiq_step(struct seq_file *m)
  1017. {
  1018. seq_printf(m, " fiq step: %u ", LAST_RRR_VAL(fiq_step));
  1019. }
  1020. void aee_rr_show_exp_type(struct seq_file *m)
  1021. {
  1022. unsigned int exp_type = LAST_RRR_VAL(exp_type);
  1023. seq_printf(m, " exception type: %u\n",
  1024. (exp_type ^ 0xaeedead0) < 16 ? exp_type ^ 0xaeedead0 : exp_type);
  1025. }
  1026. void aee_rr_show_last_irq_enter(struct seq_file *m, int cpu)
  1027. {
  1028. seq_printf(m, " irq: enter(%d, ", LAST_RRR_VAL(last_irq_enter[cpu]));
  1029. }
  1030. void aee_rr_show_jiffies_last_irq_enter(struct seq_file *m, int cpu)
  1031. {
  1032. seq_printf(m, "%llu) ", LAST_RRR_VAL(jiffies_last_irq_enter[cpu]));
  1033. }
  1034. void aee_rr_show_last_irq_exit(struct seq_file *m, int cpu)
  1035. {
  1036. seq_printf(m, "quit(%d, ", LAST_RRR_VAL(last_irq_exit[cpu]));
  1037. }
  1038. void aee_rr_show_jiffies_last_irq_exit(struct seq_file *m, int cpu)
  1039. {
  1040. seq_printf(m, "%llu)\n", LAST_RRR_VAL(jiffies_last_irq_exit[cpu]));
  1041. }
  1042. void aee_rr_show_hotplug_data1(struct seq_file *m, int cpu)
  1043. {
  1044. seq_printf(m, " hotplug: %d, ", LAST_RRR_VAL(hotplug_data1[cpu]));
  1045. }
  1046. void aee_rr_show_hotplug_data2(struct seq_file *m, int cpu)
  1047. {
  1048. if (cpu == 0)
  1049. seq_printf(m, "%d, ", LAST_RRR_VAL(hotplug_data2));
  1050. }
  1051. void aee_rr_show_hotplug_data3(struct seq_file *m, int cpu)
  1052. {
  1053. if (cpu == 0)
  1054. seq_printf(m, "0x%llx", LAST_RRR_VAL(hotplug_data3));
  1055. seq_puts(m, "\n");
  1056. }
  1057. void aee_rr_show_mcdi(struct seq_file *m)
  1058. {
  1059. seq_printf(m, "mcdi_wfi: 0x%x\n", LAST_RRR_VAL(mcdi_wfi));
  1060. }
  1061. void aee_rr_show_mcdi_r15(struct seq_file *m)
  1062. {
  1063. seq_printf(m, "mcdi_r15: 0x%x\n", LAST_RRR_VAL(mcdi_r15));
  1064. }
  1065. void aee_rr_show_deepidle(struct seq_file *m)
  1066. {
  1067. seq_printf(m, "deepidle: 0x%x\n", LAST_RRR_VAL(deepidle_data));
  1068. }
  1069. void aee_rr_show_sodi3(struct seq_file *m)
  1070. {
  1071. seq_printf(m, "sodi3: 0x%x\n", LAST_RRR_VAL(sodi3_data));
  1072. }
  1073. void aee_rr_show_sodi(struct seq_file *m)
  1074. {
  1075. seq_printf(m, "sodi: 0x%x\n", LAST_RRR_VAL(sodi_data));
  1076. }
  1077. void aee_rr_show_spm_suspend(struct seq_file *m)
  1078. {
  1079. seq_printf(m, "spm_suspend: 0x%x\n", LAST_RRR_VAL(spm_suspend_data));
  1080. }
  1081. void aee_rr_show_cpu_dormant(struct seq_file *m, int cpu)
  1082. {
  1083. seq_printf(m, " cpu_dormant: 0x%llx\n", LAST_RRR_VAL(cpu_dormant[cpu]));
  1084. }
  1085. void aee_rr_show_clk(struct seq_file *m)
  1086. {
  1087. int i = 0;
  1088. for (i = 0; i < 8; i++)
  1089. seq_printf(m, "clk_data: 0x%x\n", LAST_RRR_VAL(clk_data[i]));
  1090. }
  1091. void aee_rr_show_vcore_dvfs_opp(struct seq_file *m)
  1092. {
  1093. seq_printf(m, "vcore_dvfs_opp: 0x%x\n", LAST_RRR_VAL(vcore_dvfs_opp));
  1094. }
  1095. void aee_rr_show_vcore_dvfs_status(struct seq_file *m)
  1096. {
  1097. seq_printf(m, "vcore_dvfs_status: 0x%x\n", LAST_RRR_VAL(vcore_dvfs_status));
  1098. }
  1099. void aee_rr_show_cpu_dvfs_vproc_big(struct seq_file *m)
  1100. {
  1101. seq_printf(m, "cpu_dvfs_vproc_big: 0x%x\n", LAST_RRR_VAL(cpu_dvfs_vproc_big));
  1102. }
  1103. void aee_rr_show_cpu_dvfs_vproc_little(struct seq_file *m)
  1104. {
  1105. seq_printf(m, "cpu_dvfs_vproc_little: 0x%x\n", LAST_RRR_VAL(cpu_dvfs_vproc_little));
  1106. }
  1107. void aee_rr_show_cpu_dvfs_oppidx(struct seq_file *m)
  1108. {
  1109. seq_printf(m, "cpu_dvfs_oppidx: little = 0x%x\n", LAST_RRR_VAL(cpu_dvfs_oppidx) & 0xF);
  1110. seq_printf(m, "cpu_dvfs_oppidx: big = 0x%x\n", (LAST_RRR_VAL(cpu_dvfs_oppidx) >> 4) & 0xF);
  1111. }
  1112. void aee_rr_show_cpu_dvfs_status(struct seq_file *m)
  1113. {
  1114. seq_printf(m, "cpu_dvfs_status: 0x%x\n", LAST_RRR_VAL(cpu_dvfs_status));
  1115. }
  1116. void aee_rr_show_gpu_dvfs_vgpu(struct seq_file *m)
  1117. {
  1118. seq_printf(m, "gpu_dvfs_vgpu: 0x%x\n", LAST_RRR_VAL(gpu_dvfs_vgpu));
  1119. }
  1120. void aee_rr_show_gpu_dvfs_oppidx(struct seq_file *m)
  1121. {
  1122. seq_printf(m, "gpu_dvfs_oppidx: 0x%x\n", LAST_RRR_VAL(gpu_dvfs_oppidx));
  1123. }
  1124. void aee_rr_show_gpu_dvfs_status(struct seq_file *m)
  1125. {
  1126. seq_printf(m, "gpu_dvfs_status: 0x%x\n", LAST_RRR_VAL(gpu_dvfs_status));
  1127. }
  1128. void aee_rr_show_ptp_cpu_big_volt(struct seq_file *m)
  1129. {
  1130. int i;
  1131. for (i = 0; i < 8; i++)
  1132. seq_printf(m, "ptp_cpu_big_volt[%d] = %llx\n", i,
  1133. (LAST_RRR_VAL(ptp_cpu_big_volt) >> (i * 8)) & 0xFF);
  1134. }
  1135. void aee_rr_show_ptp_cpu_little_volt(struct seq_file *m)
  1136. {
  1137. int i;
  1138. for (i = 0; i < 8; i++)
  1139. seq_printf(m, "ptp_cpu_little_volt[%d] = %llx\n", i,
  1140. (LAST_RRR_VAL(ptp_cpu_little_volt) >> (i * 8)) & 0xFF);
  1141. }
  1142. void aee_rr_show_ptp_gpu_volt(struct seq_file *m)
  1143. {
  1144. int i;
  1145. for (i = 0; i < 8; i++)
  1146. seq_printf(m, "ptp_gpu_volt[%d] = %llx\n", i,
  1147. (LAST_RRR_VAL(ptp_gpu_volt) >> (i * 8)) & 0xFF);
  1148. }
  1149. void aee_rr_show_ptp_temp(struct seq_file *m)
  1150. {
  1151. seq_printf(m, "ptp_temp: little = %llx\n", LAST_RRR_VAL(ptp_temp) & 0xFF);
  1152. seq_printf(m, "ptp_temp: big = %llx\n", (LAST_RRR_VAL(ptp_temp) >> 8) & 0xFF);
  1153. seq_printf(m, "ptp_temp: GPU = %llx\n", (LAST_RRR_VAL(ptp_temp) >> 16) & 0xFF);
  1154. }
  1155. void aee_rr_show_thermal_temp(struct seq_file *m)
  1156. {
  1157. seq_printf(m, "thermal_temp1 = %d\n", LAST_RRR_VAL(thermal_temp1));
  1158. seq_printf(m, "thermal_temp2 = %d\n", LAST_RRR_VAL(thermal_temp2));
  1159. seq_printf(m, "thermal_temp3 = %d\n", LAST_RRR_VAL(thermal_temp3));
  1160. seq_printf(m, "thermal_temp4 = %d\n", LAST_RRR_VAL(thermal_temp4));
  1161. seq_printf(m, "thermal_temp5 = %d\n", LAST_RRR_VAL(thermal_temp5));
  1162. }
  1163. void aee_rr_show_ptp_status(struct seq_file *m)
  1164. {
  1165. seq_printf(m, "ptp_status: 0x%x\n", LAST_RRR_VAL(ptp_status));
  1166. }
  1167. void aee_rr_show_thermal_status(struct seq_file *m)
  1168. {
  1169. seq_printf(m, "thermal_status: %d\n", LAST_RRR_VAL(thermal_status));
  1170. }
  1171. void aee_rr_show_isr_el1(struct seq_file *m)
  1172. {
  1173. seq_printf(m, "isr_el1: %d\n", LAST_RRR_VAL(isr_el1));
  1174. }
  1175. __weak uint32_t get_suspend_debug_flag(void)
  1176. {
  1177. return LAST_RR_VAL(suspend_debug_flag);
  1178. }
  1179. void aee_rr_show_suspend_debug_flag(struct seq_file *m)
  1180. {
  1181. uint32_t flag = get_suspend_debug_flag();
  1182. seq_printf(m, "SPM Suspend debug = 0x%x\n", flag);
  1183. }
  1184. int __weak mt_reg_dump(char *buf)
  1185. {
  1186. return 1;
  1187. }
  1188. void aee_rr_show_last_pc(struct seq_file *m)
  1189. {
  1190. char *reg_buf = kmalloc(4096, GFP_KERNEL);
  1191. if (reg_buf) {
  1192. if (mt_reg_dump(reg_buf) == 0)
  1193. seq_printf(m, "%s\n", reg_buf);
  1194. kfree(reg_buf);
  1195. }
  1196. }
  1197. int __weak mt_lastbus_dump(char *buf)
  1198. {
  1199. return 1;
  1200. }
  1201. void aee_rr_show_last_bus(struct seq_file *m)
  1202. {
  1203. char *reg_buf = kmalloc(4096, GFP_KERNEL);
  1204. if (reg_buf) {
  1205. if (mt_lastbus_dump) {
  1206. mt_lastbus_dump(reg_buf);
  1207. seq_printf(m, "%s\n", reg_buf);
  1208. }
  1209. kfree(reg_buf);
  1210. }
  1211. }
  1212. last_rr_show_t aee_rr_show[] = {
  1213. aee_rr_show_wdt_status,
  1214. aee_rr_show_fiq_step,
  1215. aee_rr_show_exp_type,
  1216. aee_rr_show_last_pc,
  1217. aee_rr_show_last_bus,
  1218. aee_rr_show_mcdi,
  1219. aee_rr_show_mcdi_r15,
  1220. aee_rr_show_suspend_debug_flag,
  1221. aee_rr_show_deepidle,
  1222. aee_rr_show_sodi3,
  1223. aee_rr_show_sodi,
  1224. aee_rr_show_spm_suspend,
  1225. aee_rr_show_vcore_dvfs_opp,
  1226. aee_rr_show_vcore_dvfs_status,
  1227. aee_rr_show_clk,
  1228. aee_rr_show_cpu_dvfs_vproc_big,
  1229. aee_rr_show_cpu_dvfs_vproc_little,
  1230. aee_rr_show_cpu_dvfs_oppidx,
  1231. aee_rr_show_cpu_dvfs_status,
  1232. aee_rr_show_gpu_dvfs_vgpu,
  1233. aee_rr_show_gpu_dvfs_oppidx,
  1234. aee_rr_show_gpu_dvfs_status,
  1235. aee_rr_show_ptp_cpu_big_volt,
  1236. aee_rr_show_ptp_cpu_little_volt,
  1237. aee_rr_show_ptp_gpu_volt,
  1238. aee_rr_show_ptp_temp,
  1239. aee_rr_show_ptp_status,
  1240. aee_rr_show_thermal_temp,
  1241. aee_rr_show_thermal_status,
  1242. aee_rr_show_isr_el1
  1243. };
  1244. last_rr_show_cpu_t aee_rr_show_cpu[] = {
  1245. aee_rr_show_last_irq_enter,
  1246. aee_rr_show_jiffies_last_irq_enter,
  1247. aee_rr_show_last_irq_exit,
  1248. aee_rr_show_jiffies_last_irq_exit,
  1249. aee_rr_show_hotplug_data1,
  1250. aee_rr_show_hotplug_data2,
  1251. aee_rr_show_hotplug_data3,
  1252. aee_rr_show_cpu_dormant,
  1253. };
  1254. last_rr_show_t aee_rr_last_xxx[] = {
  1255. aee_rr_show_last_pc,
  1256. aee_rr_show_last_bus,
  1257. aee_rr_show_suspend_debug_flag
  1258. };
  1259. #define array_size(x) (sizeof(x) / sizeof((x)[0]))
  1260. int aee_rr_reboot_reason_show(struct seq_file *m, void *v)
  1261. {
  1262. int i, cpu;
  1263. if (ram_console_check_header(ram_console_old)) {
  1264. seq_puts(m, "NO VALID DATA.\n");
  1265. seq_printf(m, "%s, old status is %u.\n", ram_console_clear ? "Clear" : "Not Clear", old_wdt_status);
  1266. seq_puts(m, "Only try to dump last_XXX.\n");
  1267. for (i = 0; i < array_size(aee_rr_last_xxx); i++)
  1268. aee_rr_last_xxx[i] (m);
  1269. return 0;
  1270. }
  1271. for (i = 0; i < array_size(aee_rr_show); i++)
  1272. aee_rr_show[i] (m);
  1273. for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
  1274. seq_printf(m, "CPU %d\n", cpu);
  1275. for (i = 0; i < array_size(aee_rr_show_cpu); i++)
  1276. aee_rr_show_cpu[i] (m, cpu);
  1277. }
  1278. return 0;
  1279. }