3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
18 /* This contains the implementation that allows a usermode program to
19 * communicate with the visorchipset driver using a device/file interface.
23 #include "visorchannel.h"
29 #define CURRENT_FILE_PC VISOR_CHIPSET_PC_file_c
31 static struct cdev file_cdev
;
32 static struct visorchannel
**file_controlvm_channel
;
33 static dev_t majordev
= -1; /**< indicates major num for device */
35 static int visorchipset_open(struct inode
*inode
, struct file
*file
);
36 static int visorchipset_release(struct inode
*inode
, struct file
*file
);
37 static int visorchipset_mmap(struct file
*file
, struct vm_area_struct
*vma
);
38 static long visorchipset_ioctl(struct file
*file
, unsigned int cmd
,
41 static const struct file_operations visorchipset_fops
= {
43 .open
= visorchipset_open
,
46 .unlocked_ioctl
= visorchipset_ioctl
,
47 .release
= visorchipset_release
,
48 .mmap
= visorchipset_mmap
,
52 visorchipset_file_init(dev_t major_dev
, struct visorchannel
**controlvm_channel
)
56 file_controlvm_channel
= controlvm_channel
;
58 cdev_init(&file_cdev
, &visorchipset_fops
);
59 file_cdev
.owner
= THIS_MODULE
;
60 if (MAJOR(major_dev
) == 0) {
61 /* dynamic major device number registration required */
62 if (alloc_chrdev_region(&major_dev
, 0, 1, MYDRVNAME
) < 0)
65 /* static major device number registration required */
66 if (register_chrdev_region(major_dev
, 1, MYDRVNAME
) < 0)
69 rc
= cdev_add(&file_cdev
, MKDEV(MAJOR(major_dev
), 0), 1);
76 visorchipset_file_cleanup(dev_t major_dev
)
78 if (file_cdev
.ops
!= NULL
)
81 if (MAJOR(major_dev
) >= 0) {
82 unregister_chrdev_region(major_dev
, 1);
83 majordev
= MKDEV(0, 0);
88 visorchipset_open(struct inode
*inode
, struct file
*file
)
90 unsigned minor_number
= iminor(inode
);
92 if (minor_number
!= 0)
94 file
->private_data
= NULL
;
99 visorchipset_release(struct inode
*inode
, struct file
*file
)
105 visorchipset_mmap(struct file
*file
, struct vm_area_struct
*vma
)
108 ulong offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
109 GUEST_PHYSICAL_ADDRESS addr
= 0;
111 /* sv_enable_dfp(); */
112 if (offset
& (PAGE_SIZE
- 1))
113 return -ENXIO
; /* need aligned offsets */
116 case VISORCHIPSET_MMAP_CONTROLCHANOFFSET
:
117 vma
->vm_flags
|= VM_IO
;
118 if (*file_controlvm_channel
== NULL
) {
121 visorchannel_read(*file_controlvm_channel
,
122 offsetof(struct spar_controlvm_channel_protocol
,
124 &addr
, sizeof(addr
));
128 physaddr
= (ulong
)addr
;
129 if (remap_pfn_range(vma
, vma
->vm_start
,
130 physaddr
>> PAGE_SHIFT
,
131 vma
->vm_end
- vma
->vm_start
,
132 /*pgprot_noncached */
133 (vma
->vm_page_prot
))) {
143 static long visorchipset_ioctl(struct file
*file
, unsigned int cmd
,
150 case VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET
:
151 /* get the physical rtc offset */
152 vrtc_offset
= issue_vmcall_query_guest_virtual_time_offset();
154 ((void __user
*)arg
, &vrtc_offset
, sizeof(vrtc_offset
))) {
158 case VMCALL_UPDATE_PHYSICAL_TIME
:
160 (&adjustment
, (void __user
*)arg
, sizeof(adjustment
))) {
163 return issue_vmcall_update_physical_time(adjustment
);