blob: f2ad6e374b648eaec2d3a9f329078add82396a12 [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 Mundt51becfd2010-02-17 15:33:30 +0900105 * Must be run uncached.
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900106 */
Paul Mundt51becfd2010-02-17 15:33:30 +0900107static void set_pmb_entry(struct pmb_entry *pmbe)
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900108{
Paul Mundt51becfd2010-02-17 15:33:30 +0900109 jump_to_uncached();
110
111 __raw_writel(pmbe->vpn | PMB_V, mk_pmb_addr(pmbe->entry));
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900112
Paul Mundte7bd34a2007-07-31 17:07:28 +0900113#ifdef CONFIG_CACHE_WRITETHROUGH
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900114 /*
115 * When we are in 32-bit address extended mode, CCR.CB becomes
116 * invalid, so care must be taken to manually adjust cacheable
117 * translations.
118 */
Paul Mundt51becfd2010-02-17 15:33:30 +0900119 if (likely(pmbe->flags & PMB_C))
120 pmbe->flags |= PMB_WT;
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900121#endif
122
Paul Mundt51becfd2010-02-17 15:33:30 +0900123 __raw_writel(pmbe->ppn | pmbe->flags | PMB_V, mk_pmb_data(pmbe->entry));
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900124
Stuart Menefycbaa1182007-11-30 17:06:36 +0900125 back_to_cached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900126}
127
Paul Mundt2dc2f8e2010-01-21 16:05:25 +0900128static void clear_pmb_entry(struct pmb_entry *pmbe)
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900129{
130 unsigned int entry = pmbe->entry;
131 unsigned long addr;
132
Stuart Menefycbaa1182007-11-30 17:06:36 +0900133 jump_to_uncached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900134
135 /* Clear V-bit */
136 addr = mk_pmb_addr(entry);
Paul Mundt9d56dd32010-01-26 12:58:40 +0900137 __raw_writel(__raw_readl(addr) & ~PMB_V, addr);
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900138
139 addr = mk_pmb_data(entry);
Paul Mundt9d56dd32010-01-26 12:58:40 +0900140 __raw_writel(__raw_readl(addr) & ~PMB_V, addr);
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900141
Stuart Menefycbaa1182007-11-30 17:06:36 +0900142 back_to_cached();
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900143}
144
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900145static struct {
146 unsigned long size;
147 int flag;
148} pmb_sizes[] = {
Paul Mundt51becfd2010-02-17 15:33:30 +0900149 { .size = SZ_512M, .flag = PMB_SZ_512M, },
150 { .size = SZ_128M, .flag = PMB_SZ_128M, },
151 { .size = SZ_64M, .flag = PMB_SZ_64M, },
152 { .size = SZ_16M, .flag = PMB_SZ_16M, },
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900153};
154
155long pmb_remap(unsigned long vaddr, unsigned long phys,
Paul Mundt7bdda622010-02-17 13:23:00 +0900156 unsigned long size, pgprot_t prot)
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900157{
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000158 struct pmb_entry *pmbp, *pmbe;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900159 unsigned long wanted;
160 int pmb_flags, i;
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000161 long err;
Paul Mundt7bdda622010-02-17 13:23:00 +0900162 u64 flags;
163
164 flags = pgprot_val(prot);
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900165
166 /* Convert typical pgprot value to the PMB equivalent */
167 if (flags & _PAGE_CACHABLE) {
168 if (flags & _PAGE_WT)
169 pmb_flags = PMB_WT;
170 else
171 pmb_flags = PMB_C;
172 } else
173 pmb_flags = PMB_WT | PMB_UB;
174
175 pmbp = NULL;
176 wanted = size;
177
178again:
179 for (i = 0; i < ARRAY_SIZE(pmb_sizes); i++) {
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900180 if (size < pmb_sizes[i].size)
181 continue;
182
Matt Fleming20b50142009-10-06 21:22:33 +0000183 pmbe = pmb_alloc(vaddr, phys, pmb_flags | pmb_sizes[i].flag,
184 PMB_NO_ENTRY);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000185 if (IS_ERR(pmbe)) {
186 err = PTR_ERR(pmbe);
187 goto out;
188 }
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900189
Matt Fleming067784f2009-10-06 21:22:23 +0000190 set_pmb_entry(pmbe);
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900191
192 phys += pmb_sizes[i].size;
193 vaddr += pmb_sizes[i].size;
194 size -= pmb_sizes[i].size;
195
Paul Mundtd7813bc2010-02-17 17:56:38 +0900196 pmbe->size = pmb_sizes[i].size;
197
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900198 /*
199 * Link adjacent entries that span multiple PMB entries
200 * for easier tear-down.
201 */
202 if (likely(pmbp))
203 pmbp->link = pmbe;
204
205 pmbp = pmbe;
Matt Fleminga2767cf2009-10-06 21:22:34 +0000206
207 /*
208 * Instead of trying smaller sizes on every iteration
209 * (even if we succeed in allocating space), try using
210 * pmb_sizes[i].size again.
211 */
212 i--;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900213 }
214
215 if (size >= 0x1000000)
216 goto again;
217
218 return wanted - size;
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000219
220out:
Paul Mundt51becfd2010-02-17 15:33:30 +0900221 pmb_unmap_entry(pmbp);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000222
223 return err;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900224}
225
226void pmb_unmap(unsigned long addr)
227{
Paul Mundt51becfd2010-02-17 15:33:30 +0900228 struct pmb_entry *pmbe;
Matt Flemingedd7de82009-10-06 21:22:29 +0000229 int i;
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900230
Matt Flemingedd7de82009-10-06 21:22:29 +0000231 for (i = 0; i < ARRAY_SIZE(pmb_entry_list); i++) {
Paul Mundt51becfd2010-02-17 15:33:30 +0900232 if (test_bit(i, pmb_map)) {
Matt Flemingedd7de82009-10-06 21:22:29 +0000233 pmbe = &pmb_entry_list[i];
Paul Mundt51becfd2010-02-17 15:33:30 +0900234 if (pmbe->vpn == addr) {
235 pmb_unmap_entry(pmbe);
Matt Flemingedd7de82009-10-06 21:22:29 +0000236 break;
Paul Mundt51becfd2010-02-17 15:33:30 +0900237 }
Matt Flemingedd7de82009-10-06 21:22:29 +0000238 }
239 }
Paul Mundt51becfd2010-02-17 15:33:30 +0900240}
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900241
Paul Mundt51becfd2010-02-17 15:33:30 +0900242static void pmb_unmap_entry(struct pmb_entry *pmbe)
243{
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900244 if (unlikely(!pmbe))
245 return;
246
Paul Mundt51becfd2010-02-17 15:33:30 +0900247 if (!test_bit(pmbe->entry, pmb_map)) {
248 WARN_ON(1);
249 return;
250 }
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900251
252 do {
253 struct pmb_entry *pmblink = pmbe;
254
Matt Fleming067784f2009-10-06 21:22:23 +0000255 /*
256 * We may be called before this pmb_entry has been
257 * entered into the PMB table via set_pmb_entry(), but
258 * that's OK because we've allocated a unique slot for
259 * this entry in pmb_alloc() (even if we haven't filled
260 * it yet).
261 *
262 * Therefore, calling clear_pmb_entry() is safe as no
263 * other mapping can be using that slot.
264 */
265 clear_pmb_entry(pmbe);
Matt Flemingfc2bdef2009-10-06 21:22:22 +0000266
Paul Mundtd7cdc9e2006-09-27 15:16:42 +0900267 pmbe = pmblink->link;
268
269 pmb_free(pmblink);
270 } while (pmbe);
271}
272
Paul Mundtd7813bc2010-02-17 17:56:38 +0900273static __always_inline unsigned int pmb_ppn_in_range(unsigned long ppn)
Paul Mundtefd54ea2010-02-16 18:39:30 +0900274{
275 return ppn >= __pa(memory_start) && ppn < __pa(memory_end);
276}
277
278static int pmb_synchronize_mappings(void)
Matt Fleming20b50142009-10-06 21:22:33 +0000279{
Matt Fleming3d467672010-01-18 19:33:10 +0900280 unsigned int applied = 0;
Paul Mundtd7813bc2010-02-17 17:56:38 +0900281 struct pmb_entry *pmbp = NULL;
282 int i, j;
Matt Fleming3d467672010-01-18 19:33:10 +0900283
Paul Mundtefd54ea2010-02-16 18:39:30 +0900284 pr_info("PMB: boot mappings:\n");
Matt Fleming3d467672010-01-18 19:33:10 +0900285
286 /*
Paul Mundtefd54ea2010-02-16 18:39:30 +0900287 * Run through the initial boot mappings, log the established
288 * ones, and blow away anything that falls outside of the valid
289 * PPN range. Specifically, we only care about existing mappings
290 * that impact the cached/uncached sections.
Matt Fleming3d467672010-01-18 19:33:10 +0900291 *
Paul Mundtefd54ea2010-02-16 18:39:30 +0900292 * Note that touching these can be a bit of a minefield; the boot
293 * loader can establish multi-page mappings with the same caching
294 * attributes, so we need to ensure that we aren't modifying a
295 * mapping that we're presently executing from, or may execute
296 * from in the case of straddling page boundaries.
Matt Fleming3d467672010-01-18 19:33:10 +0900297 *
Paul Mundtefd54ea2010-02-16 18:39:30 +0900298 * In the future we will have to tidy up after the boot loader by
299 * jumping between the cached and uncached mappings and tearing
300 * down alternating mappings while executing from the other.
Matt Fleming3d467672010-01-18 19:33:10 +0900301 */
Paul Mundt51becfd2010-02-17 15:33:30 +0900302 for (i = 0; i < NR_PMB_ENTRIES; i++) {
Matt Fleming3d467672010-01-18 19:33:10 +0900303 unsigned long addr, data;
304 unsigned long addr_val, data_val;
Paul Mundtefd54ea2010-02-16 18:39:30 +0900305 unsigned long ppn, vpn, flags;
Paul Mundtd7813bc2010-02-17 17:56:38 +0900306 unsigned int size;
Paul Mundtefd54ea2010-02-16 18:39:30 +0900307 struct pmb_entry *pmbe;
Matt Fleming3d467672010-01-18 19:33:10 +0900308
309 addr = mk_pmb_addr(i);
310 data = mk_pmb_data(i);
311
312 addr_val = __raw_readl(addr);
313 data_val = __raw_readl(data);
314
315 /*
316 * Skip over any bogus entries
317 */
318 if (!(data_val & PMB_V) || !(addr_val & PMB_V))
319 continue;
320
321 ppn = data_val & PMB_PFN_MASK;
322 vpn = addr_val & PMB_PFN_MASK;
323
324 /*
325 * Only preserve in-range mappings.
326 */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900327 if (!pmb_ppn_in_range(ppn)) {
Matt Fleming3d467672010-01-18 19:33:10 +0900328 /*
329 * Invalidate anything out of bounds.
330 */
331 __raw_writel(addr_val & ~PMB_V, addr);
332 __raw_writel(data_val & ~PMB_V, data);
Paul Mundtefd54ea2010-02-16 18:39:30 +0900333 continue;
Matt Fleming3d467672010-01-18 19:33:10 +0900334 }
Paul Mundtefd54ea2010-02-16 18:39:30 +0900335
336 /*
337 * Update the caching attributes if necessary
338 */
339 if (data_val & PMB_C) {
340#if defined(CONFIG_CACHE_WRITETHROUGH)
341 data_val |= PMB_WT;
342#elif defined(CONFIG_CACHE_WRITEBACK)
343 data_val &= ~PMB_WT;
344#else
345 data_val &= ~(PMB_C | PMB_WT);
346#endif
347 __raw_writel(data_val, data);
348 }
349
Paul Mundtd7813bc2010-02-17 17:56:38 +0900350 size = data_val & PMB_SZ_MASK;
351 flags = size | (data_val & PMB_CACHE_MASK);
Paul Mundtefd54ea2010-02-16 18:39:30 +0900352
353 pmbe = pmb_alloc(vpn, ppn, flags, i);
354 if (IS_ERR(pmbe)) {
355 WARN_ON_ONCE(1);
356 continue;
357 }
358
Paul Mundtd7813bc2010-02-17 17:56:38 +0900359 for (j = 0; j < ARRAY_SIZE(pmb_sizes); j++)
360 if (pmb_sizes[j].flag == size)
361 pmbe->size = pmb_sizes[j].size;
362
363 /*
364 * Compare the previous entry against the current one to
365 * see if the entries span a contiguous mapping. If so,
366 * setup the entry links accordingly.
367 */
368 if (pmbp && ((pmbe->vpn == (pmbp->vpn + pmbp->size)) &&
369 (pmbe->ppn == (pmbp->ppn + pmbp->size))))
370 pmbp->link = pmbe;
371
372 pmbp = pmbe;
373
374 pr_info("\t0x%08lx -> 0x%08lx [ %ldMB %scached ]\n",
375 vpn >> PAGE_SHIFT, ppn >> PAGE_SHIFT, pmbe->size >> 20,
376 (data_val & PMB_C) ? "" : "un");
Paul Mundtefd54ea2010-02-16 18:39:30 +0900377
378 applied++;
Matt Fleming3d467672010-01-18 19:33:10 +0900379 }
380
381 return (applied == 0);
382}
Matt Fleming3d467672010-01-18 19:33:10 +0900383
Paul Mundt2dc2f8e2010-01-21 16:05:25 +0900384int pmb_init(void)
Matt Fleming3d467672010-01-18 19:33:10 +0900385{
Paul Mundtefd54ea2010-02-16 18:39:30 +0900386 int ret;
Matt Fleming20b50142009-10-06 21:22:33 +0000387
Matt Fleming3d467672010-01-18 19:33:10 +0900388 jump_to_uncached();
389
390 /*
Matt Fleming3d467672010-01-18 19:33:10 +0900391 * Sync our software copy of the PMB mappings with those in
392 * hardware. The mappings in the hardware PMB were either set up
393 * by the bootloader or very early on by the kernel.
394 */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900395 ret = pmb_synchronize_mappings();
396 if (unlikely(ret == 0)) {
397 back_to_cached();
398 return 0;
Matt Fleming20b50142009-10-06 21:22:33 +0000399 }
400
Paul Mundt9d56dd32010-01-26 12:58:40 +0900401 __raw_writel(0, PMB_IRMCR);
Paul Mundta0ab3662010-01-13 18:31:48 +0900402
Paul Mundta0ab3662010-01-13 18:31:48 +0900403 /* Flush out the TLB */
Paul Mundtefd54ea2010-02-16 18:39:30 +0900404 __raw_writel(__raw_readl(MMUCR) | MMUCR_TI, MMUCR);
Paul Mundta0ab3662010-01-13 18:31:48 +0900405
Matt Fleming20b50142009-10-06 21:22:33 +0000406 back_to_cached();
407
408 return 0;
409}
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900410
Paul Mundt2efa53b2010-01-20 16:40:48 +0900411bool __in_29bit_mode(void)
412{
413 return (__raw_readl(PMB_PASCR) & PASCR_SE) == 0;
414}
415
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900416static int pmb_seq_show(struct seq_file *file, void *iter)
417{
418 int i;
419
420 seq_printf(file, "V: Valid, C: Cacheable, WT: Write-Through\n"
421 "CB: Copy-Back, B: Buffered, UB: Unbuffered\n");
422 seq_printf(file, "ety vpn ppn size flags\n");
423
424 for (i = 0; i < NR_PMB_ENTRIES; i++) {
425 unsigned long addr, data;
426 unsigned int size;
427 char *sz_str = NULL;
428
Paul Mundt9d56dd32010-01-26 12:58:40 +0900429 addr = __raw_readl(mk_pmb_addr(i));
430 data = __raw_readl(mk_pmb_data(i));
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900431
432 size = data & PMB_SZ_MASK;
433 sz_str = (size == PMB_SZ_16M) ? " 16MB":
434 (size == PMB_SZ_64M) ? " 64MB":
435 (size == PMB_SZ_128M) ? "128MB":
436 "512MB";
437
438 /* 02: V 0x88 0x08 128MB C CB B */
439 seq_printf(file, "%02d: %c 0x%02lx 0x%02lx %s %c %s %s\n",
440 i, ((addr & PMB_V) && (data & PMB_V)) ? 'V' : ' ',
441 (addr >> 24) & 0xff, (data >> 24) & 0xff,
442 sz_str, (data & PMB_C) ? 'C' : ' ',
443 (data & PMB_WT) ? "WT" : "CB",
444 (data & PMB_UB) ? "UB" : " B");
445 }
446
447 return 0;
448}
449
450static int pmb_debugfs_open(struct inode *inode, struct file *file)
451{
452 return single_open(file, pmb_seq_show, NULL);
453}
454
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800455static const struct file_operations pmb_debugfs_fops = {
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900456 .owner = THIS_MODULE,
457 .open = pmb_debugfs_open,
458 .read = seq_read,
459 .llseek = seq_lseek,
Li Zefan45dabf12008-06-24 13:30:23 +0800460 .release = single_release,
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900461};
462
463static int __init pmb_debugfs_init(void)
464{
465 struct dentry *dentry;
466
467 dentry = debugfs_create_file("pmb", S_IFREG | S_IRUGO,
Paul Mundtb9e393c2008-03-07 17:19:58 +0900468 sh_debugfs_root, NULL, &pmb_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800469 if (!dentry)
470 return -ENOMEM;
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900471 if (IS_ERR(dentry))
472 return PTR_ERR(dentry);
473
474 return 0;
475}
Paul Mundt0c7b1df2006-09-27 15:08:07 +0900476postcore_initcall(pmb_debugfs_init);
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000477
478#ifdef CONFIG_PM
479static int pmb_sysdev_suspend(struct sys_device *dev, pm_message_t state)
480{
481 static pm_message_t prev_state;
Matt Flemingedd7de82009-10-06 21:22:29 +0000482 int i;
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000483
484 /* Restore the PMB after a resume from hibernation */
485 if (state.event == PM_EVENT_ON &&
486 prev_state.event == PM_EVENT_FREEZE) {
487 struct pmb_entry *pmbe;
Matt Flemingedd7de82009-10-06 21:22:29 +0000488 for (i = 0; i < ARRAY_SIZE(pmb_entry_list); i++) {
Paul Mundt51becfd2010-02-17 15:33:30 +0900489 if (test_bit(i, pmb_map)) {
Matt Flemingedd7de82009-10-06 21:22:29 +0000490 pmbe = &pmb_entry_list[i];
491 set_pmb_entry(pmbe);
492 }
493 }
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000494 }
495 prev_state = state;
496 return 0;
497}
498
499static int pmb_sysdev_resume(struct sys_device *dev)
500{
501 return pmb_sysdev_suspend(dev, PMSG_ON);
502}
503
504static struct sysdev_driver pmb_sysdev_driver = {
505 .suspend = pmb_sysdev_suspend,
506 .resume = pmb_sysdev_resume,
507};
508
509static int __init pmb_sysdev_init(void)
510{
511 return sysdev_driver_register(&cpu_sysdev_class, &pmb_sysdev_driver);
512}
Francesco VIRLINZIa83c0b72009-03-11 10:39:02 +0000513subsys_initcall(pmb_sysdev_init);
514#endif