2 ** Stolen mostly from arch/parisc/kernel/pci-dma.c
5 #include <linux/types.h>
7 #include <linux/string.h>
10 #include <linux/malloc.h>
11 #include <linux/vmalloc.h>
13 #include <asm/uaccess.h>
14 #include <asm/pgalloc.h>
17 #include <asm/page.h> /* get_order */
19 #undef flush_cache_all
20 #define flush_cache_all flush_all_caches
22 typedef void (*pte_iterator_t
) (pte_t
* pte
, unsigned long arg
);
25 /* XXX This routine could be used with iterate_page() to replace
26 * unmap_uncached_page() and save a little code space but I didn't
27 * do that since I'm not certain whether this is the right path. -PB
29 static void unmap_cached_pte(pte_t
* pte
, unsigned long arg
)
33 if (!pte_none(page
)) {
34 if (pte_present(page
)) {
35 unsigned long map_nr
= pte_pagenr(page
);
36 if (map_nr
< max_mapnr
)
37 __free_page(mem_map
+ map_nr
);
40 "Whee.. Swapped out page in kernel page table\n");
46 /* These two routines should probably check a few things... */
47 static void set_uncached(pte_t
* pte
, unsigned long arg
)
49 pte_val(*pte
) |= _PAGE_NO_CACHE
;
52 static void set_cached(pte_t
* pte
, unsigned long arg
)
54 pte_val(*pte
) &= ~_PAGE_NO_CACHE
;
57 static inline void iterate_pte(pmd_t
* pmd
, unsigned long address
,
58 unsigned long size
, pte_iterator_t op
,
71 pte
= pte_offset(pmd
, address
);
80 } while (address
< end
);
83 static inline void iterate_pmd(pgd_t
* dir
, unsigned long address
,
84 unsigned long size
, pte_iterator_t op
,
97 pmd
= pmd_offset(dir
, address
);
98 address
&= ~PGDIR_MASK
;
100 if (end
> PGDIR_SIZE
)
103 iterate_pte(pmd
, address
, end
- address
, op
, arg
);
104 address
= (address
+ PMD_SIZE
) & PMD_MASK
;
106 } while (address
< end
);
109 static void iterate_pages(unsigned long address
, unsigned long size
,
110 pte_iterator_t op
, unsigned long arg
)
113 unsigned long end
= address
+ size
;
115 dir
= pgd_offset_k(address
);
118 iterate_pmd(dir
, address
, end
- address
, op
, arg
);
119 address
= (address
+ PGDIR_SIZE
) & PGDIR_MASK
;
121 } while (address
&& (address
< end
));
126 kernel_set_cachemode(unsigned long vaddr
, unsigned long size
, int what
)
129 case IOMAP_FULL_CACHING
:
130 iterate_pages(vaddr
, size
, set_cached
, 0);
131 flush_tlb_range(&init_mm
, vaddr
, size
);
133 case IOMAP_NOCACHE_SER
:
134 iterate_pages(vaddr
, size
, set_uncached
, 0);
135 flush_tlb_range(&init_mm
, vaddr
, size
);
139 "kernel_set_cachemode mode %d not understood\n",