From 2627f203874e04500ea80f6e588cd659bec5866b Mon Sep 17 00:00:00 2001 From: Nathan O Date: Fri, 15 Nov 2019 11:19:35 -0500 Subject: 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. --- litmus/uncachedev.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 litmus/uncachedev.c (limited to 'litmus/uncachedev.c') 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 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* device for allocating pages not cached by the CPU */ + +#define UNCACHE_NAME "litmus/uncache" + +void litmus_uncache_vm_open(struct vm_area_struct *vma) +{ +} + +void litmus_uncache_vm_close(struct vm_area_struct *vma) +{ +} + +int litmus_uncache_vm_fault(struct vm_area_struct* vma, + struct vm_fault* vmf) +{ + /* modeled after SG DMA video4linux, but without DMA. */ + /* (see drivers/media/video/videobuf-dma-sg.c) */ + struct page *page; + + page = alloc_page(GFP_USER); + if (!page) + return VM_FAULT_OOM; + + clear_user_highpage(page, (unsigned long)vmf->virtual_address); + vmf->page = page; + + return 0; +} + +static struct vm_operations_struct litmus_uncache_vm_ops = { + .open = litmus_uncache_vm_open, + .close = litmus_uncache_vm_close, + .fault = litmus_uncache_vm_fault, +}; + +static int litmus_uncache_mmap(struct file* filp, struct vm_area_struct* vma) +{ + /* first make sure mapper knows what he's doing */ + + /* you can only map the "first" page */ + if (vma->vm_pgoff != 0) + return -EINVAL; + + /* you can't share it with anyone */ + if (vma->vm_flags & (VM_MAYSHARE | VM_SHARED)) + return -EINVAL; + + /* cannot be expanded, and is not a "normal" page. */ + vma->vm_flags |= VM_DONTEXPAND; + + /* noncached pages are not explicitly locked in memory (for now). */ + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + + vma->vm_ops = &litmus_uncache_vm_ops; + + return 0; +} + +static struct file_operations litmus_uncache_fops = { + .owner = THIS_MODULE, + .mmap = litmus_uncache_mmap, +}; + +static struct miscdevice litmus_uncache_dev = { + .name = UNCACHE_NAME, + .minor = MISC_DYNAMIC_MINOR, + .fops = &litmus_uncache_fops, + /* pages are not locked, so there is no reason why + anyone cannot allocate an uncache pages */ + .mode = (S_IRUGO | S_IWUGO), +}; + +static int __init init_litmus_uncache_dev(void) +{ + int err; + + printk("Initializing LITMUS^RT uncache device.\n"); + err = misc_register(&litmus_uncache_dev); + if (err) + printk("Could not allocate %s device (%d).\n", UNCACHE_NAME, err); + return err; +} + +static void __exit exit_litmus_uncache_dev(void) +{ + misc_deregister(&litmus_uncache_dev); +} + +module_init(init_litmus_uncache_dev); +module_exit(exit_litmus_uncache_dev); -- cgit v1.2.2