summaryrefslogtreecommitdiff
path: root/arch/arm/mach-ux500/dbx500_dump.c
blob: 89470216590c5e19c95f7933a3f144a7262c23ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * Copyright (C) ST-Ericsson SA 2011
 *
 * License Terms: GNU General Public License v2
 * Author: Johan Bjornstedt <johan.bjornstedt@stericsson.com>
 *
 * Save DBx500 registers in case of kernel crash
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/kdebug.h>

#include <mach/hardware.h>
#include <mach/db8500-regs.h>
#include <mach/db5500-regs.h>

struct dbx500_dump_info {
	char *name;
	int *data;
	int *io_addr;
	int phy_addr;
	int size;
};

static struct dbx500_dump_info db8500_dump[] = {
	{
		.name     = "prcmu_tcdm",
		.phy_addr = U8500_PRCMU_TCDM_BASE,
		.size     = 0x1000,
	},
	{
		.name     = "prcmu_non_sec_1",
		.phy_addr = U8500_PRCMU_BASE,
		.size     = 0x340,
	},
	{
		.name     = "prcmu_pmb",
		.phy_addr = (U8500_PRCMU_BASE + 0x344),
		.size     = 0xC,
	},
	{
		.name     = "prcmu_thermal",
		.phy_addr = (U8500_PRCMU_BASE + 0x3C0),
		.size     = 0x40,
	},
	{
		.name     = "prcmu_non_sec_2",
		.phy_addr = (U8500_PRCMU_BASE + 0x404),
		.size     = 0x1FC,
	},
	{
		.name     = "prcmu_icn_pmu",
		.phy_addr = (U8500_PRCMU_BASE + 0xE00),
		.size     = 0x90,
	},
	{
		.name	  = "db8500_fuses",
		.phy_addr = (U8500_BACKUPRAM1_BASE + 0xF70),
		.size	  = 0xc,
	},
};

static struct dbx500_dump_info db9540_dump[] = {
	{
		.name     = "prcmu_tcdm",
		.phy_addr = U9540_PRCMU_TCDM_BASE,
		.size     = 0x1000,
	},
	{
		.name     = "prcmu_non_sec_1",
		.phy_addr = U8500_PRCMU_BASE,
		.size     = 0x340,
	},
	{
		.name     = "prcmu_pmb",
		.phy_addr = (U8500_PRCMU_BASE + 0x344),
		.size     = 0xC,
	},
	{
		.name     = "prcmu_thermal",
		.phy_addr = (U8500_PRCMU_BASE + 0x3C0),
		.size     = 0x40,
	},
	{
		.name     = "prcmu_non_sec_2",
		.phy_addr = (U8500_PRCMU_BASE + 0x404),
		.size     = 0x1FC,
	},
	{
		.name     = "prcmu_icn_pmu",
		.phy_addr = (U8500_PRCMU_BASE + 0xE00),
		.size     = 0x118,
	},
};

static struct dbx500_dump_info db5500_dump[] = {
	{
		.name     = "prcmu_tcdm",
		.phy_addr = U5500_PRCMU_TCDM_BASE,
		.size     = 0x5000,
	},
	{
		.name     = "prcmu_gpio",
		.phy_addr = U5500_GPIO2_BASE,
		.size     = 0x1000,
	},
	{
		.name     = "prcmu_msp1",
		.phy_addr = U5500_MSP1_BASE,
		.size     = 0x1000,
	},
	{
		.name     = "prcmu_sec",
		.phy_addr = (U5500_PRCMU_BASE + 0x1000),
		.size     = 0x1000,
	},
	{
		.name     = "prcmu_unsec",
		.phy_addr = U5500_PRCMU_BASE,
		.size     = 0x1000,
	},
};

static struct dbx500_dump_info *dbx500_dump;
static int dbx500_dump_size;
static bool dbx500_dump_done;

static DEFINE_SPINLOCK(dbx500_dump_lock);

static int crash_notifier(struct notifier_block *nb, unsigned long val,
		void *data)
{
	int i;
	unsigned long flags;

	/*
        * Since there are two ways into this function (die and panic) we have
        * to make sure we only dump the DB registers once
        */
	spin_lock_irqsave(&dbx500_dump_lock, flags);
	if (dbx500_dump_done)
		return NOTIFY_DONE;

	pr_info("dbx500_dump notified of crash\n");

	for (i = 0; i < dbx500_dump_size; i++) {
		memcpy_fromio(dbx500_dump[i].data, dbx500_dump[i].io_addr,
			dbx500_dump[i].size);
	}

	dbx500_dump_done = true;
	spin_unlock_irqrestore(&dbx500_dump_lock, flags);

	return NOTIFY_DONE;
}

static void __init init_io_addresses(void)
{
	int i;

	for (i = 0; i < dbx500_dump_size; i++)
		dbx500_dump[i].io_addr = ioremap(dbx500_dump[i].phy_addr,
			dbx500_dump[i].size);
}

static struct notifier_block die_notifier = {
	.notifier_call = crash_notifier,
};

static struct notifier_block panic_notifier = {
	.notifier_call = crash_notifier,
};

int __init dbx500_dump_init(void)
{
	int err, i;

	if (cpu_is_u5500()) {
		dbx500_dump = db5500_dump;
		dbx500_dump_size = ARRAY_SIZE(db5500_dump);
	} else if (cpu_is_u8500()) {
		dbx500_dump = db8500_dump;
		dbx500_dump_size = ARRAY_SIZE(db8500_dump);
	} else if (cpu_is_u9540()) {
		dbx500_dump = db9540_dump;
		dbx500_dump_size = ARRAY_SIZE(db9540_dump);
	}  else {
		ux500_unknown_soc();
	}

	for (i = 0; i < dbx500_dump_size; i++) {
		dbx500_dump[i].data = kmalloc(dbx500_dump[i].size, GFP_KERNEL);
		if (!dbx500_dump[i].data) {
			pr_err("dbx500_dump: Could not allocate memory for "
					"%s\n", dbx500_dump[i].name);
			err = -ENOMEM;
			goto free_mem;
		}
	}

	init_io_addresses();

	err = atomic_notifier_chain_register(&panic_notifier_list,
					     &panic_notifier);
	if (err != 0) {
		pr_err("dbx500_dump: Unable to register a panic notifier %d\n",
			err);
		goto free_mem;
	}

	err = register_die_notifier(&die_notifier);
	if (err != 0) {
		pr_err("dbx500_dump: Unable to register a die notifier %d\n",
			err);
		goto free_panic_notifier;
	}
	pr_info("dbx500_dump: driver initialized\n");
	return err;

free_panic_notifier:
	atomic_notifier_chain_unregister(&panic_notifier_list,
					 &panic_notifier);

free_mem:
	for (i = i - 1; i >= 0; i--)
		kfree(dbx500_dump[i].data);

	return err;
}
arch_initcall(dbx500_dump_init);