blob: cb808a8aaffc53be6b49f71a630cbaf8bcc21e1f [file] [log] [blame]
Paul Mundt0c7b1df2006-09-27 15:08:07 +09001/*
2 * arch/sh/mm/pmb.c
3 *
4 * Privileged Space Mapping Buffer (PMB) Support.
5 *
Matt Fleming3d467672010-01-18 19:33:10 +09006 * Copyright (C) 2005 - 2010 Paul Mundt
7 * Copyright (C) 2010 Matt Fleming
Paul Mundt0c7b1df2006-09-27 15:08:07 +09008 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13#include <linux/init.h>
14#include <linux/kernel.h>
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +000015#include <linux/sysdev.h>
16#include <linux/cpu.h>
Paul Mundt0c7b1df2006-09-27 15:08:07 +090017#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/bitops.h>
20#include <linux/debugfs.h>
21#include <linux/fs.h>
22#include <linux/seq_file.h>
23#include <linux/err.h>
Paul Mundt51becfd2010-02-17 15:33:30 +090024#include <linux/io.h>
25#include <asm/sizes.h>
Paul Mundt0c7b1df2006-09-27 15:08:07 +090026#include <asm/system.h>
27#include <asm/uaccess.h>
Paul Mundtd7cdc9e2006-09-27 15:16:42 +090028#include <asm/pgtable.h>
Paul Mundt7bdda622010-02-17 13:23:00 +090029#include <asm/page.h>
Paul Mundt0c7b1df2006-09-27 15:08:07 +090030#include <asm/mmu.h>
Stuart Menefyeddeeb32007-11-26 21:32:40 +090031#include <asm/mmu_context.h>
Paul Mundt0c7b1df2006-09-27 15:08:07 +090032
Paul Mundt51becfd2010-02-17 15:33:30 +090033static void pmb_unmap_entry(struct pmb_entry *);
Matt Flemingfc2bdef2009-10-06 21:22:22 +000034
Matt Flemingedd7de82009-10-06 21:22:29 +000035static struct pmb_entry pmb_entry_list[NR_PMB_ENTRIES];
Paul Mundt51becfd2010-02-17 15:33:30 +090036static DECLARE_BITMAP(pmb_map, NR_PMB_ENTRIES);
Paul Mundt0c7b1df2006-09-27 15:08:07 +090037
Paul Mundt51becfd2010-02-17 15:33:30 +090038static __always_inline unsigned long mk_pmb_entry(unsigned int entry)
Paul Mundt0c7b1df2006-09-27 15:08:07 +090039{
40 return (entry & PMB_E_MASK) << PMB_E_SHIFT;
41}
42
Paul Mundt51becfd2010-02-17 15:33:30 +090043static __always_inline unsigned long mk_pmb_addr(unsigned int entry)
Paul Mundt0c7b1df2006-09-27 15:08:07 +090044{
45 return mk_pmb_entry(entry) | PMB_ADDR;
46}
47
Paul Mundt51becfd2010-02-17 15:33:30 +090048static __always_inline unsigned long mk_pmb_data(unsigned int entry)
Paul Mundt0c7b1df2006-09-27 15:08:07 +090049{
50 return mk_pmb_entry(entry) | PMB_DATA;
51}
52
Matt Fleming067784f2009-10-06 21:22:23 +000053static int pmb_alloc_entry(void)
54{
55 unsigned int pos;
56
57repeat:
Paul Mundt51becfd2010-02-17 15:33:30 +090058 pos = find_first_zero_bit(pmb_map, NR_PMB_ENTRIES);
Matt Fleming067784f2009-10-06 21:22:23 +000059
60 if (unlikely(pos > NR_PMB_ENTRIES))
61 return -ENOSPC;
62
Paul Mundt51becfd2010-02-17 15:33:30 +090063 if (test_and_set_bit(pos, pmb_map))
Matt Fleming067784f2009-10-06 21:22:23 +000064 goto repeat;
65
66 return pos;
67}
68
Matt Fleming8386aeb2009-10-06 21:22:28 +000069static struct pmb_entry *pmb_alloc(unsigned long vpn, unsigned long ppn,
Matt Fleming20b50142009-10-06 21:22:33 +000070 unsigned long flags, int entry)
Paul Mundt0c7b1df2006-09-27 15:08:07 +090071{
72 struct pmb_entry *pmbe;
Matt Fleming067784f2009-10-06 21:22:23 +000073 int pos;
74
Matt Fleming20b50142009-10-06 21:22:33 +000075 if (entry == PMB_NO_ENTRY) {
76 pos = pmb_alloc_entry();
77 if (pos < 0)
78 return ERR_PTR(pos);
79 } else {
Paul Mundt51becfd2010-02-17 15:33:30 +090080 if (test_and_set_bit(entry, pmb_map))
Matt Fleming20b50142009-10-06 21:22:33 +000081 return ERR_PTR(-ENOSPC);
82 pos = entry;
83 }
Paul Mundt0c7b1df2006-09-27 15:08:07 +090084
Matt Flemingedd7de82009-10-06 21:22:29 +000085 pmbe = &pmb_entry_list[pos];
Paul Mundt0c7b1df2006-09-27 15:08:07 +090086 if (!pmbe)
87 return ERR_PTR(-ENOMEM);
88
89 pmbe->vpn = vpn;
90 pmbe->ppn = ppn;
91 pmbe->flags = flags;
Matt Fleming067784f2009-10-06 21:22:23 +000092 pmbe->entry = pos;
Paul Mundtd7813bc2010-02-17 17:56:38 +090093 pmbe->size = 0;
Paul Mundt0c7b1df2006-09-27 15:08:07 +090094
95 return pmbe;
96}
97
Matt Fleming8386aeb2009-10-06 21:22:28 +000098static void pmb_free(struct pmb_entry *pmbe)
Paul Mundt0c7b1df2006-09-27 15:08:07 +090099{
Paul Mundtd7813bc2010-02-17 17:56:38 +0900100 clear_bit(pmbe->entry, pmb_map);
101 pmbe->entry = PMB_NO_ENTRY;
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900102}
103
104/*
Paul Mundt0065b962010-02-17 18:05:23 +0900105 * Ensure that the PMB entries match our cache configuration.
106 *
107 * When we are in 32-bit address extended mode, CCR.CB becomes
108 * invalid, so care must be taken to manually adjust cacheable
109 * translations.
110 */
111static __always_inline unsigned long pmb_cache_flags(void)
112{
113 unsigned long flags = 0;
114
115#if defined(CONFIG_CACHE_WRITETHROUGH)
116 flags |= PMB_C | PMB_WT | PMB_UB;
117#elif defined(CONFIG_CACHE_WRITEBACK)
118 flags |= PMB_C;
119#endif
120
121 return flags;
122}
123
124/*
Paul Mundt51becfd2010-02-17 15:33:30 +0900125 * Must be run uncached.
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900126 */
Paul Mundt51becfd2010-02-17 15:33:30 +0900127static void set_pmb_entry(struct pmb_entry *pmbe)
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900128{
Paul Mundt51becfd2010-02-17 15:33:30 +0900129 jump_to_uncached();
130
Paul Mundt0065b962010-02-17 18:05:23 +0900131 pmbe->flags &= ~PMB_CACHE_MASK;
132 pmbe->flags |= pmb_cache_flags();
133
Paul Mundt51becfd2010-02-17 15:33:30 +0900134 __raw_writel(pmbe->vpn | PMB_V, mk_pmb_addr(pmbe->entry));
Paul Mundt51becfd2010-02-17 15:33:30 +0900135 __raw_writel(pmbe->ppn | pmbe->flags | PMB_V, mk_pmb_data(pmbe->entry));
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900136
Stuart Menefycbaa1182007-11-30 17:06:36 +0900137 back_to_cached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900138}
139
Paul Mundt2dc2f8e2010-01-21 16:05:25 +0900140static void clear_pmb_entry(struct pmb_entry *pmbe)
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900141{
142 unsigned int entry = pmbe->entry;
143 unsigned long addr;
144
Stuart Menefycbaa1182007-11-30 17:06:36 +0900145 jump_to_uncached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900146
147 /* Clear V-bit */
148 addr = mk_pmb_addr(entry);
Paul Mundt9d56dd32010-01-26 12:58:40 +0900149 __raw_writel(__raw_readl(addr) & ~PMB_V, addr);
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900150
151 addr = mk_pmb_data(entry);
Paul Mundt9d56dd32010-01-26 12:58:40 +0900152 __raw_writel(__raw_readl(addr) & ~PMB_V, addr);
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900153
Stuart Menefycbaa1182007-11-30 17:06:36 +0900154 back_to_cached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900155}
156
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900157static struct {
158 unsigned long size;
159 int flag;
160} pmb_sizes[] = {
Paul Mundt51becfd2010-02-17 15:33:30 +0900161 { .size = SZ_512M, .flag = PMB_SZ_512M, },
162 { .size = SZ_128M, .flag = PMB_SZ_128M, },
163 { .size = SZ_64M, .flag = PMB_SZ_64M, },
164 { .size = SZ_16M, .flag = PMB_SZ_16M, },
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900165};
166
167long pmb_remap(unsigned long vaddr, unsigned long phys,
Paul Mundt7bdda622010-02-17 13:23:00 +0900168 unsigned long size, pgprot_t prot)
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900169{
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000170 struct pmb_entry *pmbp, *pmbe;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900171 unsigned long wanted;
172 int pmb_flags, i;
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000173 long err;
Paul Mundt7bdda622010-02-17 13:23:00 +0900174 u64 flags;
175
176 flags = pgprot_val(prot);
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900177
Paul Mundt0065b962010-02-17 18:05:23 +0900178 pmb_flags = PMB_WT | PMB_UB;
179
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900180 /* Convert typical pgprot value to the PMB equivalent */
181 if (flags & _PAGE_CACHABLE) {
Paul Mundt0065b962010-02-17 18:05:23 +0900182 pmb_flags |= PMB_C;
183
184 if ((flags & _PAGE_WT) == 0)
185 pmb_flags &= ~(PMB_WT | PMB_UB);
186 }
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900187
188 pmbp = NULL;
189 wanted = size;
190
191again:
192 for (i = 0; i < ARRAY_SIZE(pmb_sizes); i++) {
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900193 if (size < pmb_sizes[i].size)
194 continue;
195
Matt Fleming20b50142009-10-06 21:22:33 +0000196 pmbe = pmb_alloc(vaddr, phys, pmb_flags | pmb_sizes[i].flag,
197 PMB_NO_ENTRY);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000198 if (IS_ERR(pmbe)) {
199 err = PTR_ERR(pmbe);
200 goto out;
201 }
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900202
Matt Fleming067784f2009-10-06 21:22:23 +0000203 set_pmb_entry(pmbe);
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900204
205 phys += pmb_sizes[i].size;
206 vaddr += pmb_sizes[i].size;
207 size -= pmb_sizes[i].size;
208
Paul Mundtd7813bc2010-02-17 17:56:38 +0900209 pmbe->size = pmb_sizes[i].size;
210
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900211 /*
212 * Link adjacent entries that span multiple PMB entries
213 * for easier tear-down.
214 */
215 if (likely(pmbp))
216 pmbp->link = pmbe;
217
218 pmbp = pmbe;
Matt Fleminga2767cf2009-10-06 21:22:34 +0000219
220 /*
221 * Instead of trying smaller sizes on every iteration
222 * (even if we succeed in allocating space), try using
223 * pmb_sizes[i].size again.
224 */
225 i--;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900226 }
227
228 if (size >= 0x1000000)
229 goto again;
230
231 return wanted - size;
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000232
233out:
Paul Mundt51becfd2010-02-17 15:33:30 +0900234 pmb_unmap_entry(pmbp);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000235
236 return err;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900237}
238
239void pmb_unmap(unsigned long addr)
240{
Paul Mundt51becfd2010-02-17 15:33:30 +0900241 struct pmb_entry *pmbe;
Matt Flemingedd7de82009-10-06 21:22:29 +0000242 int i;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900243
Matt Flemingedd7de82009-10-06 21:22:29 +0000244 for (i = 0; i < ARRAY_SIZE(pmb_entry_list); i++) {
Paul Mundt51becfd2010-02-17 15:33:30 +0900245 if (test_bit(i, pmb_map)) {
Matt Flemingedd7de82009-10-06 21:22:29 +0000246 pmbe = &pmb_entry_list[i];
Paul Mundt51becfd2010-02-17 15:33:30 +0900247 if (pmbe->vpn == addr) {
248 pmb_unmap_entry(pmbe);
Matt Flemingedd7de82009-10-06 21:22:29 +0000249 break;
Paul Mundt51becfd2010-02-17 15:33:30 +0900250 }
Matt Flemingedd7de82009-10-06 21:22:29 +0000251 }
252 }
Paul Mundt51becfd2010-02-17 15:33:30 +0900253}
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900254
Paul Mundt51becfd2010-02-17 15:33:30 +0900255static void pmb_unmap_entry(struct pmb_entry *pmbe)
256{
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900257 if (unlikely(!pmbe))
258 return;
259
Paul Mundt51becfd2010-02-17 15:33:30 +0900260 if (!test_bit(pmbe->entry, pmb_map)) {
261 WARN_ON(1);
262 return;
263 }
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900264
265 do {
266 struct pmb_entry *pmblink = pmbe;
267
Matt Fleming067784f2009-10-06 21:22:23 +0000268 /*
269 * We may be called before this pmb_entry has been
270 * entered into the PMB table via set_pmb_entry(), but
271 * that's OK because we've allocated a unique slot for
272 * this entry in pmb_alloc() (even if we haven't filled
273 * it yet).
274 *
275 * Therefore, calling clear_pmb_entry() is safe as no
276 * other mapping can be using that slot.
277 */
278 clear_pmb_entry(pmbe);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000279
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900280 pmbe = pmblink->link;
281
282 pmb_free(pmblink);
283 } while (pmbe);
284}
285
Paul Mundtd7813bc2010-02-17 17:56:38 +0900286static __always_inline unsigned int pmb_ppn_in_range(unsigned long ppn)
Paul Mundtefd54ea2010-02-16 18:39:30 +0900287{
288 return ppn >= __pa(memory_start) && ppn < __pa(memory_end);
289}
290
291static int pmb_synchronize_mappings(void)
Matt Fleming20b50142009-10-06 21:22:33 +0000292{
Matt Fleming3d467672010-01-18 19:33:10 +0900293 unsigned int applied = 0;
Paul Mundtd7813bc2010-02-17 17:56:38 +0900294 struct pmb_entry *pmbp = NULL;
295 int i, j;
Matt Fleming3d467672010-01-18 19:33:10 +0900296
Paul Mundtefd54ea2010-02-16 18:39:30 +0900297 pr_info("PMB: boot mappings:\n");
Matt Fleming3d467672010-01-18 19:33:10 +0900298
299 /*
Paul Mundtefd54ea2010-02-16 18:39:30 +0900300 * Run through the initial boot mappings, log the established
301 * ones, and blow away anything that falls outside of the valid
302 * PPN range. Specifically, we only care about existing mappings
303 * that impact the cached/uncached sections.
Matt Fleming3d467672010-01-18 19:33:10 +0900304 *
Paul Mundtefd54ea2010-02-16 18:39:30 +0900305 * Note that touching these can be a bit of a minefield; the boot
306 * loader can establish multi-page mappings with the same caching
307 * attributes, so we need to ensure that we aren't modifying a
308 * mapping that we're presently executing from, or may execute
309 * from in the case of straddling page boundaries.
Matt Fleming3d467672010-01-18 19:33:10 +0900310 *
Paul Mundtefd54ea2010-02-16 18:39:30 +0900311 * In the future we will have to tidy up after the boot loader by
312 * jumping between the cached and uncached mappings and tearing
313 * down alternating mappings while executing from the other.
Matt Fleming3d467672010-01-18 19:33:10 +0900314 */
Paul Mundt51becfd2010-02-17 15:33:30 +0900315 for (i = 0; i < NR_PMB_ENTRIES; i++) {
Matt Fleming3d467672010-01-18 19:33:10 +0900316 unsigned long addr, data;
317 unsigned long addr_val, data_val;
Paul Mundtefd54ea2010-02-16 18:39:30 +0900318 unsigned long ppn, vpn, flags;
Paul Mundtd7813bc2010-02-17 17:56:38 +0900319 unsigned int size;
Paul Mundtefd54ea2010-02-16 18:39:30 +0900320 struct pmb_entry *pmbe;
Matt Fleming3d467672010-01-18 19:33:10 +0900321
322 addr = mk_pmb_addr(i);
323 data = mk_pmb_data(i);
324
325 addr_val = __raw_readl(addr);
326 data_val = __raw_readl(data);
327
328 /*
329 * Skip over any bogus entries
330 */
331 if (!(data_val & PMB_V) || !(addr_val & PMB_V))
332 continue;
333
334 ppn = data_val & PMB_PFN_MASK;
335 vpn = addr_val & PMB_PFN_MASK;
336
337 /*
338 * Only preserve in-range mappings.
339 */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900340 if (!pmb_ppn_in_range(ppn)) {
Matt Fleming3d467672010-01-18 19:33:10 +0900341 /*
342 * Invalidate anything out of bounds.
343 */
344 __raw_writel(addr_val & ~PMB_V, addr);
345 __raw_writel(data_val & ~PMB_V, data);
Paul Mundtefd54ea2010-02-16 18:39:30 +0900346 continue;
Matt Fleming3d467672010-01-18 19:33:10 +0900347 }
Paul Mundtefd54ea2010-02-16 18:39:30 +0900348
349 /*
350 * Update the caching attributes if necessary
351 */
352 if (data_val & PMB_C) {
Paul Mundt0065b962010-02-17 18:05:23 +0900353 data_val &= ~PMB_CACHE_MASK;
354 data_val |= pmb_cache_flags();
Paul Mundtefd54ea2010-02-16 18:39:30 +0900355 __raw_writel(data_val, data);
356 }
357
Paul Mundtd7813bc2010-02-17 17:56:38 +0900358 size = data_val & PMB_SZ_MASK;
359 flags = size | (data_val & PMB_CACHE_MASK);
Paul Mundtefd54ea2010-02-16 18:39:30 +0900360
361 pmbe = pmb_alloc(vpn, ppn, flags, i);
362 if (IS_ERR(pmbe)) {
363 WARN_ON_ONCE(1);
364 continue;
365 }
366
Paul Mundtd7813bc2010-02-17 17:56:38 +0900367 for (j = 0; j < ARRAY_SIZE(pmb_sizes); j++)
368 if (pmb_sizes[j].flag == size)
369 pmbe->size = pmb_sizes[j].size;
370
371 /*
372 * Compare the previous entry against the current one to
373 * see if the entries span a contiguous mapping. If so,
374 * setup the entry links accordingly.
375 */
376 if (pmbp && ((pmbe->vpn == (pmbp->vpn + pmbp->size)) &&
377 (pmbe->ppn == (pmbp->ppn + pmbp->size))))
378 pmbp->link = pmbe;
379
380 pmbp = pmbe;
381
382 pr_info("\t0x%08lx -> 0x%08lx [ %ldMB %scached ]\n",
383 vpn >> PAGE_SHIFT, ppn >> PAGE_SHIFT, pmbe->size >> 20,
384 (data_val & PMB_C) ? "" : "un");
Paul Mundtefd54ea2010-02-16 18:39:30 +0900385
386 applied++;
Matt Fleming3d467672010-01-18 19:33:10 +0900387 }
388
389 return (applied == 0);
390}
Matt Fleming3d467672010-01-18 19:33:10 +0900391
Paul Mundt2dc2f8e2010-01-21 16:05:25 +0900392int pmb_init(void)
Matt Fleming3d467672010-01-18 19:33:10 +0900393{
Paul Mundtefd54ea2010-02-16 18:39:30 +0900394 int ret;
Matt Fleming20b50142009-10-06 21:22:33 +0000395
Matt Fleming3d467672010-01-18 19:33:10 +0900396 jump_to_uncached();
397
398 /*
Matt Fleming3d467672010-01-18 19:33:10 +0900399 * Sync our software copy of the PMB mappings with those in
400 * hardware. The mappings in the hardware PMB were either set up
401 * by the bootloader or very early on by the kernel.
402 */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900403 ret = pmb_synchronize_mappings();
404 if (unlikely(ret == 0)) {
405 back_to_cached();
406 return 0;
Matt Fleming20b50142009-10-06 21:22:33 +0000407 }
408
Paul Mundt9d56dd32010-01-26 12:58:40 +0900409 __raw_writel(0, PMB_IRMCR);
Paul Mundta0ab3662010-01-13 18:31:48 +0900410
Paul Mundta0ab3662010-01-13 18:31:48 +0900411 /* Flush out the TLB */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900412 __raw_writel(__raw_readl(MMUCR) | MMUCR_TI, MMUCR);
Paul Mundta0ab3662010-01-13 18:31:48 +0900413
Matt Fleming20b50142009-10-06 21:22:33 +0000414 back_to_cached();
415
416 return 0;
417}
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900418
Paul Mundt2efa53b2010-01-20 16:40:48 +0900419bool __in_29bit_mode(void)
420{
421 return (__raw_readl(PMB_PASCR) & PASCR_SE) == 0;
422}
423
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900424static int pmb_seq_show(struct seq_file *file, void *iter)
425{
426 int i;
427
428 seq_printf(file, "V: Valid, C: Cacheable, WT: Write-Through\n"
429 "CB: Copy-Back, B: Buffered, UB: Unbuffered\n");
430 seq_printf(file, "ety vpn ppn size flags\n");
431
432 for (i = 0; i < NR_PMB_ENTRIES; i++) {
433 unsigned long addr, data;
434 unsigned int size;
435 char *sz_str = NULL;
436
Paul Mundt9d56dd32010-01-26 12:58:40 +0900437 addr = __raw_readl(mk_pmb_addr(i));
438 data = __raw_readl(mk_pmb_data(i));
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900439
440 size = data & PMB_SZ_MASK;
441 sz_str = (size == PMB_SZ_16M) ? " 16MB":
442 (size == PMB_SZ_64M) ? " 64MB":
443 (size == PMB_SZ_128M) ? "128MB":
444 "512MB";
445
446 /* 02: V 0x88 0x08 128MB C CB B */
447 seq_printf(file, "%02d: %c 0x%02lx 0x%02lx %s %c %s %s\n",
448 i, ((addr & PMB_V) && (data & PMB_V)) ? 'V' : ' ',
449 (addr >> 24) & 0xff, (data >> 24) & 0xff,
450 sz_str, (data & PMB_C) ? 'C' : ' ',
451 (data & PMB_WT) ? "WT" : "CB",
452 (data & PMB_UB) ? "UB" : " B");
453 }
454
455 return 0;
456}
457
458static int pmb_debugfs_open(struct inode *inode, struct file *file)
459{
460 return single_open(file, pmb_seq_show, NULL);
461}
462
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800463static const struct file_operations pmb_debugfs_fops = {
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900464 .owner = THIS_MODULE,
465 .open = pmb_debugfs_open,
466 .read = seq_read,
467 .llseek = seq_lseek,
Li Zefan45dabf12008-06-24 13:30:23 +0800468 .release = single_release,
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900469};
470
471static int __init pmb_debugfs_init(void)
472{
473 struct dentry *dentry;
474
475 dentry = debugfs_create_file("pmb", S_IFREG | S_IRUGO,
Paul Mundtb9e393c2008-03-07 17:19:58 +0900476 sh_debugfs_root, NULL, &pmb_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800477 if (!dentry)
478 return -ENOMEM;
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900479 if (IS_ERR(dentry))
480 return PTR_ERR(dentry);
481
482 return 0;
483}
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900484postcore_initcall(pmb_debugfs_init);
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000485
486#ifdef CONFIG_PM
487static int pmb_sysdev_suspend(struct sys_device *dev, pm_message_t state)
488{
489 static pm_message_t prev_state;
Matt Flemingedd7de82009-10-06 21:22:29 +0000490 int i;
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000491
492 /* Restore the PMB after a resume from hibernation */
493 if (state.event == PM_EVENT_ON &&
494 prev_state.event == PM_EVENT_FREEZE) {
495 struct pmb_entry *pmbe;
Matt Flemingedd7de82009-10-06 21:22:29 +0000496 for (i = 0; i < ARRAY_SIZE(pmb_entry_list); i++) {
Paul Mundt51becfd2010-02-17 15:33:30 +0900497 if (test_bit(i, pmb_map)) {
Matt Flemingedd7de82009-10-06 21:22:29 +0000498 pmbe = &pmb_entry_list[i];
499 set_pmb_entry(pmbe);
500 }
501 }
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000502 }
503 prev_state = state;
504 return 0;
505}
506
507static int pmb_sysdev_resume(struct sys_device *dev)
508{
509 return pmb_sysdev_suspend(dev, PMSG_ON);
510}
511
512static struct sysdev_driver pmb_sysdev_driver = {
513 .suspend = pmb_sysdev_suspend,
514 .resume = pmb_sysdev_resume,
515};
516
517static int __init pmb_sysdev_init(void)
518{
519 return sysdev_driver_register(&cpu_sysdev_class, &pmb_sysdev_driver);
520}
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000521subsys_initcall(pmb_sysdev_init);
522#endif