diff options
author | Nathan O <otternes@cs.unc.edu> | 2019-11-15 11:19:35 -0500 |
---|---|---|
committer | Nathan O <otternes@cs.unc.edu> | 2019-11-15 11:19:35 -0500 |
commit | 2627f203874e04500ea80f6e588cd659bec5866b (patch) | |
tree | feec07a6a87a24460a19808dcd88ba36ad03201d /litmus/uncachedev.c | |
parent | bf929479893052b1c7bfe23a4e7a903643076350 (diff) |
Re-add LITMUS files, but don't "connect the wires"
- Added the LITMUS^RT source files from the most recent version of
LITMUS (based on the old kernel).
- This change does *not* actually make use of any of the new files,
because I wanted to make sure that any changes for getting LITMUS to
actually work are clearly visible in future commits. If I made any
such changes before committing the files themselves, then it wouldn't
be as easy to see what needed to change in the LITMUS source files,
and the large number of changes would make it more difficult to see
what needed to change in the base Linux sources, too.
Diffstat (limited to 'litmus/uncachedev.c')
-rw-r--r-- | litmus/uncachedev.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/litmus/uncachedev.c b/litmus/uncachedev.c new file mode 100644 index 000000000000..06a6a7c17983 --- /dev/null +++ b/litmus/uncachedev.c | |||
@@ -0,0 +1,102 @@ | |||
1 | #include <linux/sched.h> | ||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/mm.h> | ||
4 | #include <linux/fs.h> | ||
5 | #include <linux/errno.h> | ||
6 | #include <linux/highmem.h> | ||
7 | #include <asm/page.h> | ||
8 | #include <linux/miscdevice.h> | ||
9 | #include <linux/module.h> | ||
10 | |||
11 | #include <litmus/litmus.h> | ||
12 | |||
13 | /* device for allocating pages not cached by the CPU */ | ||
14 | |||
15 | #define UNCACHE_NAME "litmus/uncache" | ||
16 | |||
17 | void litmus_uncache_vm_open(struct vm_area_struct *vma) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | void litmus_uncache_vm_close(struct vm_area_struct *vma) | ||
22 | { | ||
23 | } | ||
24 | |||
25 | int litmus_uncache_vm_fault(struct vm_area_struct* vma, | ||
26 | struct vm_fault* vmf) | ||
27 | { | ||
28 | /* modeled after SG DMA video4linux, but without DMA. */ | ||
29 | /* (see drivers/media/video/videobuf-dma-sg.c) */ | ||
30 | struct page *page; | ||
31 | |||
32 | page = alloc_page(GFP_USER); | ||
33 | if (!page) | ||
34 | return VM_FAULT_OOM; | ||
35 | |||
36 | clear_user_highpage(page, (unsigned long)vmf->virtual_address); | ||
37 | vmf->page = page; | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static struct vm_operations_struct litmus_uncache_vm_ops = { | ||
43 | .open = litmus_uncache_vm_open, | ||
44 | .close = litmus_uncache_vm_close, | ||
45 | .fault = litmus_uncache_vm_fault, | ||
46 | }; | ||
47 | |||
48 | static int litmus_uncache_mmap(struct file* filp, struct vm_area_struct* vma) | ||
49 | { | ||
50 | /* first make sure mapper knows what he's doing */ | ||
51 | |||
52 | /* you can only map the "first" page */ | ||
53 | if (vma->vm_pgoff != 0) | ||
54 | return -EINVAL; | ||
55 | |||
56 | /* you can't share it with anyone */ | ||
57 | if (vma->vm_flags & (VM_MAYSHARE | VM_SHARED)) | ||
58 | return -EINVAL; | ||
59 | |||
60 | /* cannot be expanded, and is not a "normal" page. */ | ||
61 | vma->vm_flags |= VM_DONTEXPAND; | ||
62 | |||
63 | /* noncached pages are not explicitly locked in memory (for now). */ | ||
64 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | ||
65 | |||
66 | vma->vm_ops = &litmus_uncache_vm_ops; | ||
67 | |||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static struct file_operations litmus_uncache_fops = { | ||
72 | .owner = THIS_MODULE, | ||
73 | .mmap = litmus_uncache_mmap, | ||
74 | }; | ||
75 | |||
76 | static struct miscdevice litmus_uncache_dev = { | ||
77 | .name = UNCACHE_NAME, | ||
78 | .minor = MISC_DYNAMIC_MINOR, | ||
79 | .fops = &litmus_uncache_fops, | ||
80 | /* pages are not locked, so there is no reason why | ||
81 | anyone cannot allocate an uncache pages */ | ||
82 | .mode = (S_IRUGO | S_IWUGO), | ||
83 | }; | ||
84 | |||
85 | static int __init init_litmus_uncache_dev(void) | ||
86 | { | ||
87 | int err; | ||
88 | |||
89 | printk("Initializing LITMUS^RT uncache device.\n"); | ||
90 | err = misc_register(&litmus_uncache_dev); | ||
91 | if (err) | ||
92 | printk("Could not allocate %s device (%d).\n", UNCACHE_NAME, err); | ||
93 | return err; | ||
94 | } | ||
95 | |||
96 | static void __exit exit_litmus_uncache_dev(void) | ||
97 | { | ||
98 | misc_deregister(&litmus_uncache_dev); | ||
99 | } | ||
100 | |||
101 | module_init(init_litmus_uncache_dev); | ||
102 | module_exit(exit_litmus_uncache_dev); | ||