linux/include/linux/highmem.h
<<
>>
Prefs
   1#ifndef _LINUX_HIGHMEM_H
   2#define _LINUX_HIGHMEM_H
   3
   4#include <linux/fs.h>
   5#include <linux/mm.h>
   6
   7#include <asm/cacheflush.h>
   8
   9#ifndef ARCH_HAS_FLUSH_ANON_PAGE
  10static inline void flush_anon_page(struct page *page, unsigned long vmaddr)
  11{
  12}
  13#endif
  14
  15#ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
  16static inline void flush_kernel_dcache_page(struct page *page)
  17{
  18}
  19#endif
  20
  21#ifdef CONFIG_HIGHMEM
  22
  23#include <asm/highmem.h>
  24
  25/* declarations for linux/mm/highmem.c */
  26unsigned int nr_free_highpages(void);
  27extern unsigned long totalhigh_pages;
  28
  29#else /* CONFIG_HIGHMEM */
  30
  31static inline unsigned int nr_free_highpages(void) { return 0; }
  32
  33#define totalhigh_pages 0
  34
  35#ifndef ARCH_HAS_KMAP
  36static inline void *kmap(struct page *page)
  37{
  38        might_sleep();
  39        return page_address(page);
  40}
  41
  42#define kunmap(page) do { (void) (page); } while (0)
  43
  44#define kmap_atomic(page, idx)          page_address(page)
  45#define kunmap_atomic(addr, idx)        do { } while (0)
  46#define kmap_atomic_pfn(pfn, idx)       page_address(pfn_to_page(pfn))
  47#define kmap_atomic_to_page(ptr)        virt_to_page(ptr)
  48#endif
  49
  50#endif /* CONFIG_HIGHMEM */
  51
  52/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
  53static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
  54{
  55        void *addr = kmap_atomic(page, KM_USER0);
  56        clear_user_page(addr, vaddr, page);
  57        kunmap_atomic(addr, KM_USER0);
  58        /* Make sure this page is cleared on other CPU's too before using it */
  59        smp_wmb();
  60}
  61
  62#ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
  63static inline struct page *
  64alloc_zeroed_user_highpage(struct vm_area_struct *vma, unsigned long vaddr)
  65{
  66        struct page *page = alloc_page_vma(GFP_HIGHUSER, vma, vaddr);
  67
  68        if (page)
  69                clear_user_highpage(page, vaddr);
  70
  71        return page;
  72}
  73#endif
  74
  75static inline void clear_highpage(struct page *page)
  76{
  77        void *kaddr = kmap_atomic(page, KM_USER0);
  78        clear_page(kaddr);
  79        kunmap_atomic(kaddr, KM_USER0);
  80}
  81
  82/*
  83 * Same but also flushes aliased cache contents to RAM.
  84 */
  85static inline void memclear_highpage_flush(struct page *page, unsigned int offset, unsigned int size)
  86{
  87        void *kaddr;
  88
  89        BUG_ON(offset + size > PAGE_SIZE);
  90
  91        kaddr = kmap_atomic(page, KM_USER0);
  92        memset((char *)kaddr + offset, 0, size);
  93        flush_dcache_page(page);
  94        kunmap_atomic(kaddr, KM_USER0);
  95}
  96
  97static inline void copy_user_highpage(struct page *to, struct page *from, unsigned long vaddr)
  98{
  99        char *vfrom, *vto;
 100
 101        vfrom = kmap_atomic(from, KM_USER0);
 102        vto = kmap_atomic(to, KM_USER1);
 103        copy_user_page(vto, vfrom, vaddr, to);
 104        kunmap_atomic(vfrom, KM_USER0);
 105        kunmap_atomic(vto, KM_USER1);
 106        /* Make sure this page is cleared on other CPU's too before using it */
 107        smp_wmb();
 108}
 109
 110static inline void copy_highpage(struct page *to, struct page *from)
 111{
 112        char *vfrom, *vto;
 113
 114        vfrom = kmap_atomic(from, KM_USER0);
 115        vto = kmap_atomic(to, KM_USER1);
 116        copy_page(vto, vfrom);
 117        kunmap_atomic(vfrom, KM_USER0);
 118        kunmap_atomic(vto, KM_USER1);
 119}
 120
 121#endif /* _LINUX_HIGHMEM_H */
 122
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.