highmem.c 1.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11
/* highmem.c: arch-specific highmem stuff
 *
 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */
#include <linux/highmem.h>
12
#include <linux/module.h>
L
Linus Torvalds 已提交
13 14 15 16 17 18 19 20 21

void *kmap(struct page *page)
{
	might_sleep();
	if (!PageHighMem(page))
		return page_address(page);
	return kmap_high(page);
}

22 23
EXPORT_SYMBOL(kmap);

L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31 32
void kunmap(struct page *page)
{
	if (in_interrupt())
		BUG();
	if (!PageHighMem(page))
		return;
	kunmap_high(page);
}

33 34
EXPORT_SYMBOL(kunmap);

C
Cong Wang 已提交
35
void *kmap_atomic(struct page *page)
P
Peter Zijlstra 已提交
36 37 38 39
{
	unsigned long paddr;
	int type;

40
	preempt_disable();
P
Peter Zijlstra 已提交
41 42 43 44 45 46 47 48
	pagefault_disable();
	type = kmap_atomic_idx_push();
	paddr = page_to_phys(page);

	switch (type) {
	/*
	 * The first 4 primary maps are reserved for architecture code
	 */
49 50 51 52 53
	case 0:		return __kmap_atomic_primary(0, paddr, 6);
	case 1:		return __kmap_atomic_primary(0, paddr, 7);
	case 2:		return __kmap_atomic_primary(0, paddr, 8);
	case 3:		return __kmap_atomic_primary(0, paddr, 9);
	case 4:		return __kmap_atomic_primary(0, paddr, 10);
P
Peter Zijlstra 已提交
54 55 56 57 58 59 60 61 62

	case 5 ... 5 + NR_TLB_LINES - 1:
		return __kmap_atomic_secondary(type - 5, paddr);

	default:
		BUG();
		return NULL;
	}
}
C
Cong Wang 已提交
63
EXPORT_SYMBOL(kmap_atomic);
P
Peter Zijlstra 已提交
64 65 66

void __kunmap_atomic(void *kvaddr)
{
P
Peter Zijlstra 已提交
67
	int type = kmap_atomic_idx();
P
Peter Zijlstra 已提交
68
	switch (type) {
69 70 71 72 73
	case 0:		__kunmap_atomic_primary(0, 6);	break;
	case 1:		__kunmap_atomic_primary(0, 7);	break;
	case 2:		__kunmap_atomic_primary(0, 8);	break;
	case 3:		__kunmap_atomic_primary(0, 9);	break;
	case 4:		__kunmap_atomic_primary(0, 10);	break;
P
Peter Zijlstra 已提交
74 75 76 77 78 79 80 81

	case 5 ... 5 + NR_TLB_LINES - 1:
		__kunmap_atomic_secondary(type - 5, kvaddr);
		break;

	default:
		BUG();
	}
P
Peter Zijlstra 已提交
82
	kmap_atomic_idx_pop();
P
Peter Zijlstra 已提交
83
	pagefault_enable();
84
	preempt_enable();
P
Peter Zijlstra 已提交
85 86
}
EXPORT_SYMBOL(__kunmap_atomic);