]> Git Repo - linux.git/blame - arch/sh/mm/kmap.c
Merge tag 'drm-next-2024-05-25' of https://gitlab.freedesktop.org/drm/kernel
[linux.git] / arch / sh / mm / kmap.c
CommitLineData
c456cfc2 1// SPDX-License-Identifier: GPL-2.0-only
2739742c
PM
2/*
3 * arch/sh/mm/kmap.c
4 *
5 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
6 * Copyright (C) 2002 - 2009 Paul Mundt
2739742c
PM
7 */
8#include <linux/mm.h>
9#include <linux/init.h>
10#include <linux/mutex.h>
11#include <linux/fs.h>
12#include <linux/highmem.h>
13#include <linux/module.h>
14#include <asm/mmu_context.h>
15#include <asm/cacheflush.h>
16
2739742c
PM
17static pte_t *kmap_coherent_pte;
18
19void __init kmap_coherent_init(void)
20{
21 unsigned long vaddr;
22
2739742c
PM
23 /* cache the first coherent kmap pte */
24 vaddr = __fix_to_virt(FIX_CMAP_BEGIN);
e05c7b1f 25 kmap_coherent_pte = virt_to_kpte(vaddr);
2739742c
PM
26}
27
28void *kmap_coherent(struct page *page, unsigned long addr)
29{
157efa29 30 struct folio *folio = page_folio(page);
2739742c 31 enum fixed_addresses idx;
0906a3ad 32 unsigned long vaddr;
2739742c 33
157efa29 34 BUG_ON(!test_bit(PG_dcache_clean, &folio->flags));
2739742c 35
b15d53d0 36 preempt_disable();
0906a3ad 37 pagefault_disable();
2739742c 38
0906a3ad 39 idx = FIX_CMAP_END -
f9e2bdfd
PM
40 (((addr >> PAGE_SHIFT) & (FIX_N_COLOURS - 1)) +
41 (FIX_N_COLOURS * smp_processor_id()));
42
0906a3ad 43 vaddr = __fix_to_virt(idx);
2739742c 44
0906a3ad
PM
45 BUG_ON(!pte_none(*(kmap_coherent_pte - idx)));
46 set_pte(kmap_coherent_pte - idx, mk_pte(page, PAGE_KERNEL));
2739742c
PM
47
48 return (void *)vaddr;
49}
50
0906a3ad 51void kunmap_coherent(void *kvaddr)
2739742c 52{
0906a3ad
PM
53 if (kvaddr >= (void *)FIXADDR_START) {
54 unsigned long vaddr = (unsigned long)kvaddr & PAGE_MASK;
55 enum fixed_addresses idx = __virt_to_fix(vaddr);
56
6e4154d4
PM
57 /* XXX.. Kill this later, here for sanity at the moment.. */
58 __flush_purge_region((void *)vaddr, PAGE_SIZE);
59
0906a3ad
PM
60 pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
61 local_flush_tlb_one(get_asid(), vaddr);
62 }
63
64 pagefault_enable();
b15d53d0 65 preempt_enable();
2739742c 66}
This page took 0.715329 seconds and 4 git commands to generate.