Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/slab.h>
0003 #include <linux/types.h>
0004 #include <linux/mm.h>
0005 #include <linux/fs.h>
0006 
0007 #include <xen/page.h>
0008 #include <xen/xenbus.h>
0009 
0010 #include "xenfs.h"
0011 
0012 static ssize_t xsd_read(struct file *file, char __user *buf,
0013                 size_t size, loff_t *off)
0014 {
0015     const char *str = (const char *)file->private_data;
0016     return simple_read_from_buffer(buf, size, off, str, strlen(str));
0017 }
0018 
0019 static int xsd_release(struct inode *inode, struct file *file)
0020 {
0021     kfree(file->private_data);
0022     return 0;
0023 }
0024 
0025 static int xsd_kva_open(struct inode *inode, struct file *file)
0026 {
0027     file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
0028                            xen_store_interface);
0029     if (!file->private_data)
0030         return -ENOMEM;
0031     return 0;
0032 }
0033 
0034 static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
0035 {
0036     size_t size = vma->vm_end - vma->vm_start;
0037 
0038     if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
0039         return -EINVAL;
0040 
0041     if (remap_pfn_range(vma, vma->vm_start,
0042                 virt_to_pfn(xen_store_interface),
0043                 size, vma->vm_page_prot))
0044         return -EAGAIN;
0045 
0046     return 0;
0047 }
0048 
0049 const struct file_operations xsd_kva_file_ops = {
0050     .open = xsd_kva_open,
0051     .mmap = xsd_kva_mmap,
0052     .read = xsd_read,
0053     .release = xsd_release,
0054 };
0055 
0056 static int xsd_port_open(struct inode *inode, struct file *file)
0057 {
0058     file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
0059                            xen_store_evtchn);
0060     if (!file->private_data)
0061         return -ENOMEM;
0062     return 0;
0063 }
0064 
0065 const struct file_operations xsd_port_file_ops = {
0066     .open = xsd_port_open,
0067     .read = xsd_read,
0068     .release = xsd_release,
0069 };