Linux Audio

Check our new training course

Loading...
v3.1
 
 1#include <linux/slab.h>
 2#include <linux/types.h>
 3#include <linux/mm.h>
 4#include <linux/fs.h>
 5
 6#include <xen/page.h>
 
 7
 8#include "xenfs.h"
 9#include "../xenbus/xenbus_comms.h"
10
11static ssize_t xsd_read(struct file *file, char __user *buf,
12			    size_t size, loff_t *off)
13{
14	const char *str = (const char *)file->private_data;
15	return simple_read_from_buffer(buf, size, off, str, strlen(str));
16}
17
18static int xsd_release(struct inode *inode, struct file *file)
19{
20	kfree(file->private_data);
21	return 0;
22}
23
24static int xsd_kva_open(struct inode *inode, struct file *file)
25{
26	file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
27					       xen_store_interface);
28	if (!file->private_data)
29		return -ENOMEM;
30	return 0;
31}
32
33static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
34{
35	size_t size = vma->vm_end - vma->vm_start;
36
37	if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
38		return -EINVAL;
39
40	if (remap_pfn_range(vma, vma->vm_start,
41			    virt_to_pfn(xen_store_interface),
42			    size, vma->vm_page_prot))
43		return -EAGAIN;
44
45	return 0;
46}
47
48const struct file_operations xsd_kva_file_ops = {
49	.open = xsd_kva_open,
50	.mmap = xsd_kva_mmap,
51	.read = xsd_read,
52	.release = xsd_release,
53};
54
55static int xsd_port_open(struct inode *inode, struct file *file)
56{
57	file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
58					       xen_store_evtchn);
59	if (!file->private_data)
60		return -ENOMEM;
61	return 0;
62}
63
64const struct file_operations xsd_port_file_ops = {
65	.open = xsd_port_open,
66	.read = xsd_read,
67	.release = xsd_release,
68};
v6.2
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/slab.h>
 3#include <linux/types.h>
 4#include <linux/mm.h>
 5#include <linux/fs.h>
 6
 7#include <xen/page.h>
 8#include <xen/xenbus.h>
 9
10#include "xenfs.h"
 
11
12static ssize_t xsd_read(struct file *file, char __user *buf,
13			    size_t size, loff_t *off)
14{
15	const char *str = (const char *)file->private_data;
16	return simple_read_from_buffer(buf, size, off, str, strlen(str));
17}
18
19static int xsd_release(struct inode *inode, struct file *file)
20{
21	kfree(file->private_data);
22	return 0;
23}
24
25static int xsd_kva_open(struct inode *inode, struct file *file)
26{
27	file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
28					       xen_store_interface);
29	if (!file->private_data)
30		return -ENOMEM;
31	return 0;
32}
33
34static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
35{
36	size_t size = vma->vm_end - vma->vm_start;
37
38	if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
39		return -EINVAL;
40
41	if (remap_pfn_range(vma, vma->vm_start,
42			    virt_to_pfn(xen_store_interface),
43			    size, vma->vm_page_prot))
44		return -EAGAIN;
45
46	return 0;
47}
48
49const struct file_operations xsd_kva_file_ops = {
50	.open = xsd_kva_open,
51	.mmap = xsd_kva_mmap,
52	.read = xsd_read,
53	.release = xsd_release,
54};
55
56static int xsd_port_open(struct inode *inode, struct file *file)
57{
58	file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
59					       xen_store_evtchn);
60	if (!file->private_data)
61		return -ENOMEM;
62	return 0;
63}
64
65const struct file_operations xsd_port_file_ops = {
66	.open = xsd_port_open,
67	.read = xsd_read,
68	.release = xsd_release,
69};