atf_logger.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #define DEBUG
  2. #include <linux/module.h>
  3. #include <linux/file.h>
  4. #include <linux/fs.h>
  5. #include <linux/cdev.h>
  6. #include <linux/miscdevice.h>
  7. #include <linux/kernel.h> /* min() */
  8. #include <linux/uaccess.h> /* copy_to_user() */
  9. #include <linux/sched.h> /* TASK_INTERRUPTIBLE/signal_pending/schedule */
  10. #include <linux/poll.h>
  11. #include <linux/io.h> /* ioremap() */
  12. #include <linux/of_fdt.h>
  13. #include <linux/seq_file.h>
  14. #include <asm/setup.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/atomic.h>
  18. /*#define ATF_LOGGER_DEBUG*/
  19. #define ATF_LOG_CTRL_BUF_SIZE 256
  20. #define ATF_CRASH_MAGIC_NO 0xdead1abf
  21. /*#define atf_log_lock() atomic_inc(&(atf_buf_vir_ctl->info.atf_buf_lock))*/
  22. /*#define atf_log_unlock() atomic_dec(&(atf_buf_vir_ctl->info.atf_buf_lock))*/
  23. #define atf_log_lock() ((void)0)
  24. #define atf_log_unlock() ((void)0)
  25. static unsigned char *atf_crash_log_buf;
  26. static wait_queue_head_t atf_log_wq;
  27. #ifdef __aarch64__
  28. static void *_memcpy(void *dest, const void *src, size_t count)
  29. {
  30. char *tmp = dest;
  31. const char *s = src;
  32. while (count--)
  33. *tmp++ = *s++;
  34. return dest;
  35. }
  36. #define memcpy _memcpy
  37. #endif
  38. union atf_log_ctl_t {
  39. struct {
  40. unsigned int atf_buf_addr;
  41. unsigned int atf_buf_size;
  42. unsigned int atf_write_pos;
  43. unsigned int atf_read_pos;
  44. /* atf_spinlock_t atf_buf_lock; */
  45. unsigned int atf_buf_lock;
  46. unsigned int atf_buf_unread_size;
  47. unsigned int atf_irq_count;
  48. unsigned int atf_reader_alive;
  49. unsigned long long atf_write_seq;
  50. unsigned long long atf_read_seq;
  51. unsigned int atf_aee_dbg_buf_addr;
  52. unsigned int atf_aee_dbg_buf_size;
  53. unsigned int atf_crash_log_addr;
  54. unsigned int atf_crash_log_size;
  55. unsigned int atf_crash_flag;
  56. } info;
  57. unsigned char data[ATF_LOG_CTRL_BUF_SIZE];
  58. };
  59. struct ipanic_atf_log_rec {
  60. size_t total_size;
  61. size_t has_read;
  62. unsigned long start_idx;
  63. };
  64. union atf_log_ctl_t *atf_buf_vir_ctl;
  65. unsigned long atf_buf_phy_ctl;
  66. unsigned int atf_buf_len;
  67. unsigned char *atf_log_vir_addr;
  68. unsigned int atf_log_len;
  69. unsigned int write_index;
  70. unsigned int read_index;
  71. static unsigned int pos_to_index(unsigned int pos)
  72. {
  73. return pos - (atf_buf_phy_ctl + ATF_LOG_CTRL_BUF_SIZE);
  74. }
  75. static unsigned int index_to_pos(unsigned int index)
  76. {
  77. return (atf_buf_phy_ctl + ATF_LOG_CTRL_BUF_SIZE) + index;
  78. }
  79. #if 0
  80. static size_t atf_log_dump_nolock(unsigned char *buffer, unsigned int start, size_t size)
  81. {
  82. unsigned int len;
  83. unsigned int least;
  84. size_t skip = 0;
  85. unsigned char *p = atf_log_vir_addr + start;
  86. write_index = pos_to_index(atf_buf_vir_ctl->info.atf_write_pos);
  87. least = (write_index + atf_buf_len - start) % atf_buf_len;
  88. if (size > least)
  89. size = least;
  90. len = min(size, atf_log_len - start);
  91. if (size == len) {
  92. memcpy(buffer, atf_log_vir_addr + start, size);
  93. } else {
  94. size_t right = atf_log_len - start;
  95. while (skip < right) {
  96. if (*p != 0)
  97. break;
  98. p++;
  99. skip++;
  100. }
  101. /* pr_notice("skip:%d, right:%d, %p\n", skip, right, p); */
  102. memcpy(buffer, p, right - skip);
  103. memcpy(buffer, atf_log_vir_addr, size - right);
  104. return size - skip;
  105. }
  106. return size;
  107. }
  108. #endif
  109. static size_t atf_log_dump_nolock(unsigned char *buffer, struct ipanic_atf_log_rec *rec, size_t size)
  110. {
  111. unsigned int len;
  112. unsigned int least;
  113. write_index = pos_to_index(atf_buf_vir_ctl->info.atf_write_pos);
  114. /* find the first letter to read */
  115. while ((write_index + atf_log_len - rec->start_idx) % atf_log_len > 0) {
  116. if (*(atf_log_vir_addr + rec->start_idx) != 0)
  117. break;
  118. rec->start_idx++;
  119. if (rec->start_idx == atf_log_len)
  120. rec->start_idx = 0;
  121. }
  122. least = (write_index + atf_buf_len - rec->start_idx) % atf_buf_len;
  123. if (size > least)
  124. size = least;
  125. len = min(size, (size_t)(atf_log_len - rec->start_idx));
  126. if (size == len) {
  127. memcpy(buffer, atf_log_vir_addr + rec->start_idx, size);
  128. } else {
  129. size_t right = atf_log_len - rec->start_idx;
  130. memcpy(buffer, atf_log_vir_addr + rec->start_idx, right);
  131. memcpy(buffer, atf_log_vir_addr, size - right);
  132. }
  133. rec->start_idx += size;
  134. rec->start_idx %= atf_log_len;
  135. return size;
  136. }
  137. /* static size_t atf_log_dump(unsigned char *buffer, unsigned int start, size_t size) */
  138. static size_t atf_log_dump(unsigned char *buffer, struct ipanic_atf_log_rec *rec, size_t size)
  139. {
  140. size_t ret;
  141. atf_log_lock();
  142. /* ret = atf_log_dump_nolock(buffer, start, size); */
  143. ret = atf_log_dump_nolock(buffer, rec, size);
  144. atf_log_unlock();
  145. /* show_data(atf_log_vir_addr, 24*1024, "atf_buf"); */
  146. return ret;
  147. }
  148. size_t ipanic_atflog_buffer(void *data, unsigned char *buffer, size_t sz_buffer)
  149. {
  150. static bool last_read;
  151. size_t count;
  152. struct ipanic_atf_log_rec *rec = (struct ipanic_atf_log_rec *)data;
  153. if (atf_buf_len == 0)
  154. return 0;
  155. /* pr_notice("ipanic_atf_log: need %d, rec:%d, %d, %lu\n",
  156. sz_buffer, rec->total_size, rec->has_read, rec->start_idx); */
  157. if (rec->total_size == rec->has_read || last_read) {
  158. last_read = false;
  159. return 0;
  160. }
  161. if (rec->has_read == 0) {
  162. if (atf_buf_vir_ctl->info.atf_write_seq < atf_log_len
  163. && atf_buf_vir_ctl->info.atf_write_seq < sz_buffer)
  164. rec->start_idx = 0;
  165. else {
  166. /* atf_log_lock(); */
  167. write_index = pos_to_index(atf_buf_vir_ctl->info.atf_write_pos);
  168. /* atf_log_unlock(); */
  169. rec->start_idx = (write_index + atf_log_len - rec->total_size) % atf_log_len;
  170. }
  171. }
  172. /* count = atf_log_dump_nolock(buffer, (rec->start_idx + rec->has_read) % atf_log_len, sz_buffer); */
  173. /* count = atf_log_dump_nolock(buffer, rec, sz_buffer); */
  174. count = atf_log_dump(buffer, rec, sz_buffer);
  175. /* pr_notice("ipanic_atf_log: dump %d\n", count); */
  176. rec->has_read += count;
  177. if (count != sz_buffer)
  178. last_read = true;
  179. return count;
  180. }
  181. static ssize_t atf_log_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
  182. {
  183. wake_up_interruptible(&atf_log_wq);
  184. return 1;
  185. }
  186. static ssize_t do_read_log_to_usr(char __user *buf, size_t count)
  187. {
  188. size_t len;
  189. size_t least;
  190. write_index = pos_to_index(atf_buf_vir_ctl->info.atf_write_pos);
  191. read_index = pos_to_index(atf_buf_vir_ctl->info.atf_read_pos);
  192. least = (write_index + atf_buf_len - read_index) % atf_buf_len;
  193. if (count > least)
  194. count = least;
  195. len = min(count, (size_t)(atf_log_len - read_index));
  196. if (count == len) {
  197. if (copy_to_user(buf, atf_log_vir_addr + read_index, count))
  198. return -EFAULT;
  199. } else {
  200. size_t right = atf_log_len - read_index;
  201. if (copy_to_user(buf, atf_log_vir_addr + read_index, right))
  202. return -EFAULT;
  203. if (copy_to_user(buf, atf_log_vir_addr, count - right))
  204. return -EFAULT;
  205. }
  206. read_index = (read_index + count) % atf_log_len;
  207. return count;
  208. }
  209. static int atf_log_fix_reader(void)
  210. {
  211. if (atf_buf_vir_ctl->info.atf_write_seq < atf_log_len) {
  212. atf_buf_vir_ctl->info.atf_read_seq = 0;
  213. atf_buf_vir_ctl->info.atf_read_pos = index_to_pos(0);
  214. } else {
  215. atf_buf_vir_ctl->info.atf_read_seq = atf_buf_vir_ctl->info.atf_write_seq;
  216. atf_buf_vir_ctl->info.atf_read_pos = atf_buf_vir_ctl->info.atf_write_pos;
  217. }
  218. return 0;
  219. }
  220. static int atf_log_open(struct inode *inode, struct file *file)
  221. {
  222. int ret;
  223. ret = nonseekable_open(inode, file);
  224. if (unlikely(ret))
  225. return ret;
  226. file->private_data = NULL;
  227. atf_log_lock();
  228. if (!atf_buf_vir_ctl->info.atf_reader_alive)
  229. atf_log_fix_reader();
  230. atf_buf_vir_ctl->info.atf_reader_alive++;
  231. atf_log_unlock();
  232. return 0;
  233. }
  234. static int atf_log_release(struct inode *ignored, struct file *file)
  235. {
  236. atf_buf_vir_ctl->info.atf_reader_alive--;
  237. return 0;
  238. }
  239. static ssize_t atf_log_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
  240. {
  241. ssize_t ret;
  242. unsigned int write_pos;
  243. unsigned int read_pos;
  244. DEFINE_WAIT(wait);
  245. start:
  246. while (1) {
  247. atf_log_lock();
  248. write_pos = atf_buf_vir_ctl->info.atf_write_pos;
  249. read_pos = atf_buf_vir_ctl->info.atf_read_pos;
  250. /* pr_notice("atf_log_read: wait in wq\n"); */
  251. prepare_to_wait(&atf_log_wq, &wait, TASK_INTERRUPTIBLE);
  252. ret = (write_pos == read_pos);
  253. atf_log_unlock();
  254. if (!ret)
  255. break;
  256. if (file->f_flags & O_NONBLOCK) {
  257. ret = -EAGAIN;
  258. break;
  259. }
  260. if (signal_pending(current)) {
  261. ret = -EINTR;
  262. break;
  263. }
  264. schedule();
  265. }
  266. finish_wait(&atf_log_wq, &wait);
  267. /* pr_notice("atf_log_read: finish wait\n"); */
  268. if (ret)
  269. return ret;
  270. atf_log_lock();
  271. if (unlikely(write_pos == read_pos)) {
  272. atf_log_unlock();
  273. goto start;
  274. }
  275. ret = do_read_log_to_usr(buf, count);
  276. atf_buf_vir_ctl->info.atf_read_pos = index_to_pos(read_index);
  277. atf_buf_vir_ctl->info.atf_read_seq += ret;
  278. atf_log_unlock();
  279. /* pr_notice("atf_log_read: return %d, idx: %lu, readpos: %p, writepos: %p\n",
  280. ret, read_index, atf_buf_vir_ctl->info.atf_read_pos,
  281. atf_buf_vir_ctl->info.atf_write_pos); */
  282. return ret;
  283. }
  284. static unsigned int atf_log_poll(struct file *file, poll_table *wait)
  285. {
  286. unsigned int ret = POLLOUT | POLLWRNORM;
  287. if (!(file->f_mode & FMODE_READ))
  288. return ret;
  289. poll_wait(file, &atf_log_wq, wait);
  290. atf_log_lock();
  291. if (atf_buf_vir_ctl->info.atf_write_pos != atf_buf_vir_ctl->info.atf_read_pos)
  292. ret |= POLLIN | POLLRDNORM;
  293. atf_log_unlock();
  294. return ret;
  295. }
  296. long atf_log_ioctl(struct file *flip, unsigned int cmd, unsigned long arg)
  297. {
  298. return 0;
  299. }
  300. static const struct file_operations atf_log_fops = {
  301. .owner = THIS_MODULE,
  302. .unlocked_ioctl = atf_log_ioctl,
  303. .compat_ioctl = atf_log_ioctl,
  304. .poll = atf_log_poll,
  305. .read = atf_log_read,
  306. .open = atf_log_open,
  307. .release = atf_log_release,
  308. .write = atf_log_write,
  309. };
  310. static struct miscdevice atf_log_dev = {
  311. .minor = MISC_DYNAMIC_MINOR,
  312. .name = "atf_log",
  313. .fops = &atf_log_fops,
  314. .mode = 0644,
  315. };
  316. static int dt_scan_memory(unsigned long node, const char *uname, int depth, void *data)
  317. {
  318. char *type = (char *)of_get_flat_dt_prop(node, "device_type", NULL);
  319. __be32 *reg, *endp;
  320. int l;
  321. /* We are scanning "memory" nodes only */
  322. if (type == NULL) {
  323. /*
  324. * The longtrail doesn't have a device_type on the
  325. * /memory node, so look for the node called /memory@0.
  326. */
  327. if (depth != 1 || strcmp(uname, "memory@0") != 0)
  328. return 0;
  329. } else if (strcmp(type, "memory") != 0)
  330. return 0;
  331. reg = (__be32 *)of_get_flat_dt_prop(node, "reg", (int *)&l);
  332. if (reg == NULL)
  333. return 0;
  334. endp = reg + (l / sizeof(__be32));
  335. while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
  336. u64 base, size;
  337. base = dt_mem_next_cell(dt_root_addr_cells, (const __be32 **)&reg);
  338. size = dt_mem_next_cell(dt_root_size_cells, (const __be32 **)&reg);
  339. if (size == 0)
  340. continue;
  341. /* pr_notice( */
  342. /* "[PHY layout]DRAM size (dt) : 0x%llx - 0x%llx (0x%llx)\n", */
  343. /* (unsigned long long)base, */
  344. /* (unsigned long long)base + (unsigned long long)size - 1, */
  345. /* (unsigned long long)size); */
  346. }
  347. *(unsigned long *)data = node;
  348. return node;
  349. }
  350. unsigned long long atf_get_from_dt(unsigned long *phy_addr, unsigned int *len)
  351. {
  352. unsigned long node = 0;
  353. struct mem_desc *mem_desc = NULL;
  354. if (of_scan_flat_dt(dt_scan_memory, &node)) {
  355. mem_desc = (struct mem_desc *)of_get_flat_dt_prop(node, "tee_reserved_mem", NULL);
  356. if (mem_desc && mem_desc->size) {
  357. pr_notice("ATF reserved memory: 0x%08llx - 0x%08llx (0x%llx)\n",
  358. mem_desc->start, mem_desc->start+mem_desc->size - 1,
  359. mem_desc->size);
  360. }
  361. }
  362. if (mem_desc) {
  363. *phy_addr = mem_desc->start;
  364. *len = mem_desc->size;
  365. }
  366. return 0;
  367. }
  368. void show_atf_log_ctl(void)
  369. {
  370. pr_notice("atf_buf_addr(%p) = 0x%x\n", &(atf_buf_vir_ctl->info.atf_buf_addr),
  371. atf_buf_vir_ctl->info.atf_buf_addr);
  372. pr_notice("atf_buf_size(%p) = 0x%x\n", &(atf_buf_vir_ctl->info.atf_buf_size),
  373. atf_buf_vir_ctl->info.atf_buf_size);
  374. pr_notice("atf_write_pos(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_write_pos),
  375. atf_buf_vir_ctl->info.atf_write_pos);
  376. pr_notice("atf_read_pos(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_read_pos),
  377. atf_buf_vir_ctl->info.atf_read_pos);
  378. pr_notice("atf_buf_lock(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_buf_lock),
  379. atf_buf_vir_ctl->info.atf_buf_lock);
  380. pr_notice("atf_buf_unread_size(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_buf_unread_size),
  381. atf_buf_vir_ctl->info.atf_buf_unread_size);
  382. pr_notice("atf_irq_count(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_irq_count),
  383. atf_buf_vir_ctl->info.atf_irq_count);
  384. pr_notice("atf_reader_alive(%p) = %u\n", &(atf_buf_vir_ctl->info.atf_reader_alive),
  385. atf_buf_vir_ctl->info.atf_reader_alive);
  386. pr_notice("atf_write_seq(%p) = %llu\n", &(atf_buf_vir_ctl->info.atf_write_seq),
  387. atf_buf_vir_ctl->info.atf_write_seq);
  388. pr_notice("atf_read_seq(%p) = %llu\n", &(atf_buf_vir_ctl->info.atf_read_seq),
  389. atf_buf_vir_ctl->info.atf_read_seq);
  390. }
  391. #ifdef ATF_LOGGER_DEBUG
  392. static void show_data(unsigned long addr, int nbytes, const char *name)
  393. {
  394. int i, j;
  395. int nlines;
  396. u32 *p;
  397. /*
  398. * don't attempt to dump non-kernel addresses or
  399. * values that are probably just small negative numbers
  400. */
  401. if (addr < PAGE_OFFSET || addr > -256UL)
  402. return;
  403. pr_debug("\n%s: %#lx:\n", name, addr);
  404. /*
  405. * round address down to a 32 bit boundary
  406. * and always dump a multiple of 32 bytes
  407. */
  408. p = (u32 *)(addr & ~(sizeof(u32) - 1));
  409. nbytes += (addr & (sizeof(u32) - 1));
  410. nlines = (nbytes + 31) / 32;
  411. for (i = 0; i < nlines; i++) {
  412. /*
  413. * just display low 16 bits of address to keep
  414. * each line of the dump < 80 characters
  415. */
  416. pr_debug("%04lx ", (unsigned long)p & 0xffff);
  417. for (j = 0; j < 8; j++) {
  418. u32 data;
  419. if (probe_kernel_address(p, data))
  420. pr_debug(" ********");
  421. else
  422. pr_debug(" %08x", data);
  423. ++p;
  424. }
  425. pr_debug("\n");
  426. }
  427. }
  428. #endif
  429. static irqreturn_t ATF_log_irq_handler(int irq, void *dev_id)
  430. {
  431. if (!atf_buf_vir_ctl->info.atf_reader_alive)
  432. pr_err("No alive reader, but still receive irq\n");
  433. else
  434. pr_info("ATF_log_irq triggered!\n");
  435. wake_up_interruptible(&atf_log_wq);
  436. return IRQ_HANDLED;
  437. }
  438. static const struct file_operations proc_atf_log_file_operations = {
  439. .owner = THIS_MODULE,
  440. .open = atf_log_open,
  441. .read = atf_log_read,
  442. .unlocked_ioctl = atf_log_ioctl,
  443. .compat_ioctl = atf_log_ioctl,
  444. .release = atf_log_release,
  445. .poll = atf_log_poll,
  446. };
  447. static int atf_crash_show(struct seq_file *m, void *v)
  448. {
  449. seq_write(m, atf_crash_log_buf, atf_buf_vir_ctl->info.atf_crash_log_size);
  450. return 0;
  451. }
  452. static int atf_crash_file_open(struct inode *inode, struct file *file)
  453. {
  454. return single_open(file, atf_crash_show, inode->i_private);
  455. }
  456. static const struct file_operations proc_atf_crash_file_operations = {
  457. .owner = THIS_MODULE,
  458. .open = atf_crash_file_open,
  459. .read = seq_read,
  460. .llseek = seq_lseek,
  461. .release = single_release,
  462. };
  463. static struct proc_dir_entry *atf_log_proc_dir;
  464. static struct proc_dir_entry *atf_log_proc_file;
  465. static struct proc_dir_entry *atf_crash_proc_file;
  466. static int __init atf_log_init(void)
  467. {
  468. /* register module driver */
  469. int err;
  470. err = misc_register(&atf_log_dev);
  471. if (unlikely(err)) {
  472. pr_err("atf_log: failed to register device");
  473. return -1;
  474. }
  475. pr_notice("atf_log: inited");
  476. /* get atf reserved memory(atf_buf_phy_ctl) from device */
  477. atf_get_from_dt(&atf_buf_phy_ctl, &atf_buf_len); /* TODO */
  478. if (atf_buf_len == 0) {
  479. pr_err("No atf_log_buffer!\n");
  480. return -1;
  481. }
  482. /* map control header */
  483. atf_buf_vir_ctl = ioremap_wc(atf_buf_phy_ctl, ATF_LOG_CTRL_BUF_SIZE);
  484. atf_log_len = atf_buf_vir_ctl->info.atf_buf_size;
  485. /* map log buffer */
  486. atf_log_vir_addr = ioremap_wc(atf_buf_phy_ctl + ATF_LOG_CTRL_BUF_SIZE, atf_log_len);
  487. pr_notice("atf_buf_phy_ctl: 0x%lu\n", atf_buf_phy_ctl);
  488. pr_notice("atf_buf_len: %u\n", atf_buf_len);
  489. pr_notice("atf_buf_vir_ctl: %p\n", atf_buf_vir_ctl);
  490. pr_notice("atf_log_vir_addr: %p\n", atf_log_vir_addr);
  491. pr_notice("atf_log_len: %u\n", atf_log_len);
  492. /* show_atf_log_ctl(); */
  493. /* show_data(atf_buf_vir_ctl, 512, "atf_buf"); */
  494. atf_buf_vir_ctl->info.atf_reader_alive = 0;
  495. atf_buf_vir_ctl->info.atf_read_seq = 0;
  496. /* initial wait queue */
  497. init_waitqueue_head(&atf_log_wq);
  498. if (request_irq(281, (irq_handler_t)ATF_log_irq_handler, IRQF_TRIGGER_NONE, "ATF_irq", NULL) != 0) {
  499. pr_crit("Fail to request ATF_log_irq interrupt!\n");
  500. return -1;
  501. }
  502. /* create /proc/atf_log */
  503. atf_log_proc_dir = proc_mkdir("atf_log", NULL);
  504. if (atf_log_proc_dir == NULL) {
  505. pr_err("atf_log proc_mkdir failed\n");
  506. return -ENOMEM;
  507. }
  508. /* create /proc/atf_log/atf_log */
  509. atf_log_proc_file = proc_create("atf_log", 0444, atf_log_proc_dir, &proc_atf_log_file_operations);
  510. if (atf_log_proc_file == NULL) {
  511. pr_err("atf_log proc_create failed at atf_log\n");
  512. return -ENOMEM;
  513. }
  514. if (atf_buf_vir_ctl->info.atf_crash_flag == ATF_CRASH_MAGIC_NO) {
  515. atf_crash_proc_file = proc_create("atf_crash", 0444, atf_log_proc_dir, &proc_atf_crash_file_operations);
  516. if (atf_crash_proc_file == NULL) {
  517. pr_err("atf_log proc_create failed at atf_crash\n");
  518. return -ENOMEM;
  519. }
  520. atf_buf_vir_ctl->info.atf_crash_flag = 0;
  521. atf_crash_log_buf = ioremap_wc(atf_buf_vir_ctl->info.atf_crash_log_addr,
  522. atf_buf_vir_ctl->info.atf_crash_log_size);
  523. }
  524. return 0;
  525. }
  526. static void __exit atf_log_exit(void)
  527. {
  528. /* deregister module driver */
  529. int err;
  530. err = misc_deregister(&atf_log_dev);
  531. if (unlikely(err))
  532. pr_err("atf_log: failed to unregister device");
  533. pr_notice("atf_log: exited");
  534. }
  535. module_init(atf_log_init);
  536. module_exit(atf_log_exit);
  537. MODULE_DESCRIPTION("MEDIATEK Module ATF Logging Driver");
  538. MODULE_AUTHOR("Ji Zhang<ji.zhang@mediatek.com>");