blob: 154b4fecb58254f6b10bffa5cc6652be801c0104 [file] [log] [blame]
Hanumant Singh4bcc4e52012-07-19 11:31:59 -07001/* Copyright (c) 2012, Code Aurora Forum. 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 <asm/cacheflush.h>
13#include <linux/slab.h>
14#include <linux/io.h>
15#include <linux/init.h>
16#include <linux/notifier.h>
17#include <linux/export.h>
18#include <mach/msm_iomap.h>
19#include <mach/msm_memory_dump.h>
20
21
22/*TODO: Needs to be set to correct value */
Hanumant Singhae358622012-08-22 21:14:16 -070023#define DUMP_TABLE_OFFSET 0x14
Hanumant Singh4bcc4e52012-07-19 11:31:59 -070024#define MSM_DUMP_TABLE_VERSION MK_TABLE(1, 0)
25
26static struct msm_memory_dump mem_dump_data;
27
28static int msm_memory_dump_panic(struct notifier_block *this,
29 unsigned long event, void *ptr)
30{
31 writel_relaxed(0, MSM_IMEM_BASE + DUMP_TABLE_OFFSET);
32 return 0;
33}
34
35static struct notifier_block msm_memory_dump_blk = {
36 .notifier_call = msm_memory_dump_panic,
37};
38
39int msm_dump_table_register(struct msm_client_dump *client_entry)
40{
41 struct msm_client_dump *entry;
42 struct msm_dump_table *table = mem_dump_data.dump_table_ptr;
43
44 if (!table || table->num_entries >= MAX_NUM_CLIENTS)
45 return -EINVAL;
46 entry = &table->client_entries[table->num_entries];
47 entry->id = client_entry->id;
48 entry->start_addr = client_entry->start_addr;
49 entry->end_addr = client_entry->end_addr;
50 table->num_entries++;
51 /* flush cache */
52 dmac_flush_range(table, table + sizeof(struct msm_dump_table));
53 return 0;
54}
55EXPORT_SYMBOL(msm_dump_table_register);
56
57static int __init init_memory_dump(void)
58{
59 struct msm_dump_table *table;
60
61 mem_dump_data.dump_table_ptr = kzalloc(sizeof(struct msm_dump_table),
62 GFP_KERNEL);
63 if (!mem_dump_data.dump_table_ptr) {
64 printk(KERN_ERR "unable to allocate memory for dump table\n");
65 return -ENOMEM;
66 }
67 table = mem_dump_data.dump_table_ptr;
68 table->version = MSM_DUMP_TABLE_VERSION;
69 mem_dump_data.dump_table_phys = virt_to_phys(table);
Hanumant Singhae358622012-08-22 21:14:16 -070070 writel_relaxed(mem_dump_data.dump_table_phys,
71 MSM_IMEM_BASE + DUMP_TABLE_OFFSET);
Hanumant Singh23f9acc2012-08-27 17:43:20 -070072 /* TODO: Write to Debug image IMEM.
73 * Once IMEM issues are resolved MSM_IMEM_BASE
74 * will have actual mapping.
75 */
76 writel_relaxed(mem_dump_data.dump_table_phys,
77 MSM_DBG_IMEM_BASE + DUMP_TABLE_OFFSET);
Hanumant Singh4bcc4e52012-07-19 11:31:59 -070078 atomic_notifier_chain_register(&panic_notifier_list,
79 &msm_memory_dump_blk);
80 printk(KERN_INFO "MSM Memory Dump table set up\n");
81 return 0;
82}
83
84early_initcall(init_memory_dump);
85