Skip to content

Commit 2739742

Browse files
committed
sh: Provide the kmap_coherent() interface generically.
This plugs in kmap_coherent() for the non-SH4 cases to permit the pg-mmu.c bits to be used generically across all CPUs. SH-5 is still in the TODO state, but will move over to fixmap and the generic interface gradually. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 8edcfcb commit 2739742

7 files changed

Lines changed: 99 additions & 55 deletions

File tree

‎arch/sh/include/asm/cacheflush.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ extern void copy_from_user_page(struct vm_area_struct *vma,
7474
#define flush_cache_vmap(start, end) flush_cache_all()
7575
#define flush_cache_vunmap(start, end) flush_cache_all()
7676

77+
void kmap_coherent_init(void);
78+
void *kmap_coherent(struct page *page, unsigned long addr);
79+
void kunmap_coherent(void);
80+
7781
#endif /* __KERNEL__ */
7882
#endif /* __ASM_SH_CACHEFLUSH_H */

‎arch/sh/include/asm/pgtable.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ extern void paging_init(void);
158158
extern void page_table_range_init(unsigned long start, unsigned long end,
159159
pgd_t *pgd);
160160

161-
#if defined(CONFIG_MMU) && !defined(CONFIG_CPU_SH5)
162-
extern void kmap_coherent_init(void);
163-
#else
164-
#define kmap_coherent_init() do { } while (0)
165-
#endif
166-
167161
/* arch/sh/mm/mmap.c */
168162
#define HAVE_ARCH_UNMAPPED_AREA
169163
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN

‎arch/sh/mm/Makefile_32‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif
1515
obj-y += $(cache-y)
1616

1717
mmu-y := tlb-nommu.o pg-nommu.o
18-
mmu-$(CONFIG_MMU) := fault_32.o tlbflush_32.o ioremap_32.o pg-mmu.o
18+
mmu-$(CONFIG_MMU) := fault_32.o kmap.o tlbflush_32.o ioremap_32.o pg-mmu.o
1919

2020
obj-y += $(mmu-y)
2121
obj-$(CONFIG_DEBUG_FS) += asids-debugfs.o

‎arch/sh/mm/cache-sh5.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ void __init p3_cache_init(void)
2929
dtlb_cache_slot = sh64_get_wired_dtlb_entry();
3030
}
3131

32+
void __init kmap_coherent_init(void)
33+
{
34+
/* XXX ... */
35+
}
36+
37+
void *kmap_coherent(struct page *page, unsigned long addr)
38+
{
39+
/* XXX ... */
40+
return NULL;
41+
}
42+
43+
void kunmap_coherent(void)
44+
{
45+
}
46+
3247
#ifdef CONFIG_DCACHE_DISABLED
3348
#define sh64_dcache_purge_all() do { } while (0)
3449
#define sh64_dcache_purge_coloured_phy_page(paddr, eaddr) do { } while (0)

‎arch/sh/mm/kmap.c‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* arch/sh/mm/kmap.c
3+
*
4+
* Copyright (C) 1999, 2000, 2002 Niibe Yutaka
5+
* Copyright (C) 2002 - 2009 Paul Mundt
6+
*
7+
* Released under the terms of the GNU GPL v2.0.
8+
*/
9+
#include <linux/mm.h>
10+
#include <linux/init.h>
11+
#include <linux/mutex.h>
12+
#include <linux/fs.h>
13+
#include <linux/highmem.h>
14+
#include <linux/module.h>
15+
#include <asm/mmu_context.h>
16+
#include <asm/cacheflush.h>
17+
18+
#define kmap_get_fixmap_pte(vaddr) \
19+
pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr)), (vaddr))
20+
21+
static pte_t *kmap_coherent_pte;
22+
23+
void __init kmap_coherent_init(void)
24+
{
25+
unsigned long vaddr;
26+
27+
if (!boot_cpu_data.dcache.n_aliases)
28+
return;
29+
30+
/* cache the first coherent kmap pte */
31+
vaddr = __fix_to_virt(FIX_CMAP_BEGIN);
32+
kmap_coherent_pte = kmap_get_fixmap_pte(vaddr);
33+
}
34+
35+
void *kmap_coherent(struct page *page, unsigned long addr)
36+
{
37+
enum fixed_addresses idx;
38+
unsigned long vaddr, flags;
39+
pte_t pte;
40+
41+
BUG_ON(test_bit(PG_dcache_dirty, &page->flags));
42+
43+
inc_preempt_count();
44+
45+
idx = (addr & current_cpu_data.dcache.alias_mask) >> PAGE_SHIFT;
46+
vaddr = __fix_to_virt(FIX_CMAP_END - idx);
47+
pte = mk_pte(page, PAGE_KERNEL);
48+
49+
local_irq_save(flags);
50+
flush_tlb_one(get_asid(), vaddr);
51+
local_irq_restore(flags);
52+
53+
update_mmu_cache(NULL, vaddr, pte);
54+
55+
set_pte(kmap_coherent_pte - (FIX_CMAP_END - idx), pte);
56+
57+
return (void *)vaddr;
58+
}
59+
60+
void kunmap_coherent(void)
61+
{
62+
dec_preempt_count();
63+
preempt_check_resched();
64+
}

‎arch/sh/mm/pg-mmu.c‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,6 @@
1515
#include <asm/mmu_context.h>
1616
#include <asm/cacheflush.h>
1717

18-
#define kmap_get_fixmap_pte(vaddr) \
19-
pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr)), (vaddr))
20-
21-
static pte_t *kmap_coherent_pte;
22-
23-
void __init kmap_coherent_init(void)
24-
{
25-
unsigned long vaddr;
26-
27-
if (!boot_cpu_data.dcache.n_aliases)
28-
return;
29-
30-
/* cache the first coherent kmap pte */
31-
vaddr = __fix_to_virt(FIX_CMAP_BEGIN);
32-
kmap_coherent_pte = kmap_get_fixmap_pte(vaddr);
33-
}
34-
35-
static void *kmap_coherent(struct page *page, unsigned long addr)
36-
{
37-
enum fixed_addresses idx;
38-
unsigned long vaddr, flags;
39-
pte_t pte;
40-
41-
BUG_ON(test_bit(PG_dcache_dirty, &page->flags));
42-
43-
inc_preempt_count();
44-
45-
idx = (addr & current_cpu_data.dcache.alias_mask) >> PAGE_SHIFT;
46-
vaddr = __fix_to_virt(FIX_CMAP_END - idx);
47-
pte = mk_pte(page, PAGE_KERNEL);
48-
49-
local_irq_save(flags);
50-
flush_tlb_one(get_asid(), vaddr);
51-
local_irq_restore(flags);
52-
53-
update_mmu_cache(NULL, vaddr, pte);
54-
55-
set_pte(kmap_coherent_pte - (FIX_CMAP_END - idx), pte);
56-
57-
return (void *)vaddr;
58-
}
59-
60-
static inline void kunmap_coherent(void)
61-
{
62-
dec_preempt_count();
63-
preempt_check_resched();
64-
}
65-
6618
void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
6719
unsigned long vaddr, void *dst, const void *src,
6820
unsigned long len)

‎arch/sh/mm/tlb-nommu.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ void __update_cache(struct vm_area_struct *vma,
5555
{
5656
}
5757

58+
void __init kmap_coherent_init(void)
59+
{
60+
}
61+
62+
void *kmap_coherent(struct page *page, unsigned long addr)
63+
{
64+
BUG();
65+
return NULL;
66+
}
67+
68+
void kunmap_coherent(void)
69+
{
70+
BUG();
71+
}
72+
5873
void __init page_table_range_init(unsigned long start, unsigned long end,
5974
pgd_t *pgd_base)
6075
{

0 commit comments

Comments
 (0)