ACPI: Introduce acpi_get_pci_dev()
[linux-2.6/linux-acpi-2.6.git] / fs / proc / page.c
blobe9983837d08d4d310701fa774057f1b66848ffb3
1 #include <linux/bootmem.h>
2 #include <linux/compiler.h>
3 #include <linux/fs.h>
4 #include <linux/init.h>
5 #include <linux/mm.h>
6 #include <linux/mmzone.h>
7 #include <linux/proc_fs.h>
8 #include <linux/seq_file.h>
9 #include <asm/uaccess.h>
10 #include "internal.h"
12 #define KPMSIZE sizeof(u64)
13 #define KPMMASK (KPMSIZE - 1)
14 /* /proc/kpagecount - an array exposing page counts
16 * Each entry is a u64 representing the corresponding
17 * physical page count.
19 static ssize_t kpagecount_read(struct file *file, char __user *buf,
20 size_t count, loff_t *ppos)
22 u64 __user *out = (u64 __user *)buf;
23 struct page *ppage;
24 unsigned long src = *ppos;
25 unsigned long pfn;
26 ssize_t ret = 0;
27 u64 pcount;
29 pfn = src / KPMSIZE;
30 count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
31 if (src & KPMMASK || count & KPMMASK)
32 return -EINVAL;
34 while (count > 0) {
35 ppage = NULL;
36 if (pfn_valid(pfn))
37 ppage = pfn_to_page(pfn);
38 pfn++;
39 if (!ppage)
40 pcount = 0;
41 else
42 pcount = page_mapcount(ppage);
44 if (put_user(pcount, out++)) {
45 ret = -EFAULT;
46 break;
49 count -= KPMSIZE;
52 *ppos += (char __user *)out - buf;
53 if (!ret)
54 ret = (char __user *)out - buf;
55 return ret;
58 static const struct file_operations proc_kpagecount_operations = {
59 .llseek = mem_lseek,
60 .read = kpagecount_read,
63 /* /proc/kpageflags - an array exposing page flags
65 * Each entry is a u64 representing the corresponding
66 * physical page flags.
69 /* These macros are used to decouple internal flags from exported ones */
71 #define KPF_LOCKED 0
72 #define KPF_ERROR 1
73 #define KPF_REFERENCED 2
74 #define KPF_UPTODATE 3
75 #define KPF_DIRTY 4
76 #define KPF_LRU 5
77 #define KPF_ACTIVE 6
78 #define KPF_SLAB 7
79 #define KPF_WRITEBACK 8
80 #define KPF_RECLAIM 9
81 #define KPF_BUDDY 10
83 #define kpf_copy_bit(flags, dstpos, srcpos) (((flags >> srcpos) & 1) << dstpos)
85 static ssize_t kpageflags_read(struct file *file, char __user *buf,
86 size_t count, loff_t *ppos)
88 u64 __user *out = (u64 __user *)buf;
89 struct page *ppage;
90 unsigned long src = *ppos;
91 unsigned long pfn;
92 ssize_t ret = 0;
93 u64 kflags, uflags;
95 pfn = src / KPMSIZE;
96 count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
97 if (src & KPMMASK || count & KPMMASK)
98 return -EINVAL;
100 while (count > 0) {
101 ppage = NULL;
102 if (pfn_valid(pfn))
103 ppage = pfn_to_page(pfn);
104 pfn++;
105 if (!ppage)
106 kflags = 0;
107 else
108 kflags = ppage->flags;
110 uflags = kpf_copy_bit(kflags, KPF_LOCKED, PG_locked) |
111 kpf_copy_bit(kflags, KPF_ERROR, PG_error) |
112 kpf_copy_bit(kflags, KPF_REFERENCED, PG_referenced) |
113 kpf_copy_bit(kflags, KPF_UPTODATE, PG_uptodate) |
114 kpf_copy_bit(kflags, KPF_DIRTY, PG_dirty) |
115 kpf_copy_bit(kflags, KPF_LRU, PG_lru) |
116 kpf_copy_bit(kflags, KPF_ACTIVE, PG_active) |
117 kpf_copy_bit(kflags, KPF_SLAB, PG_slab) |
118 kpf_copy_bit(kflags, KPF_WRITEBACK, PG_writeback) |
119 kpf_copy_bit(kflags, KPF_RECLAIM, PG_reclaim) |
120 kpf_copy_bit(kflags, KPF_BUDDY, PG_buddy);
122 if (put_user(uflags, out++)) {
123 ret = -EFAULT;
124 break;
127 count -= KPMSIZE;
130 *ppos += (char __user *)out - buf;
131 if (!ret)
132 ret = (char __user *)out - buf;
133 return ret;
136 static const struct file_operations proc_kpageflags_operations = {
137 .llseek = mem_lseek,
138 .read = kpageflags_read,
141 static int __init proc_page_init(void)
143 proc_create("kpagecount", S_IRUSR, NULL, &proc_kpagecount_operations);
144 proc_create("kpageflags", S_IRUSR, NULL, &proc_kpageflags_operations);
145 return 0;
147 module_init(proc_page_init);