^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright IBM Corp. 2004, 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Interface implementation for communication with the z/VM control program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * z/VMs CP offers the possibility to issue commands via the diagnose code 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * this driver implements a character device that issues these commands and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * returns the answer of CP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * The idea of this driver is based on cpint from Neale Ferguson and #CP in CMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/cma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/cpcmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/vmcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct vmcp_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) char *response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int bufsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int cma_alloc : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int resp_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int resp_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static debug_info_t *vmcp_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static unsigned long vmcp_cma_size __initdata = CONFIG_VMCP_CMA_SIZE * 1024 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct cma *vmcp_cma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int __init early_parse_vmcp_cma(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) vmcp_cma_size = ALIGN(memparse(p, NULL), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) early_param("vmcp_cma", early_parse_vmcp_cma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void __init vmcp_cma_reserve(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) cma_declare_contiguous(0, vmcp_cma_size, 0, 0, 0, false, "vmcp", &vmcp_cma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static void vmcp_response_alloc(struct vmcp_session *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int nr_pages, order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) order = get_order(session->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) nr_pages = ALIGN(session->bufsize, PAGE_SIZE) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * For anything below order 3 allocations rely on the buddy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * allocator. If such low-order allocations can't be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * anymore the system won't work anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (order > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) page = cma_alloc(vmcp_cma, nr_pages, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) session->response = (char *)page_to_phys(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) session->cma_alloc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) session->response = (char *)__get_free_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void vmcp_response_free(struct vmcp_session *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int nr_pages, order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!session->response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) order = get_order(session->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) nr_pages = ALIGN(session->bufsize, PAGE_SIZE) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (session->cma_alloc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) page = phys_to_page((unsigned long)session->response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) cma_release(vmcp_cma, page, nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) session->cma_alloc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) free_pages((unsigned long)session->response, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) session->response = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int vmcp_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct vmcp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) session = kmalloc(sizeof(*session), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) session->bufsize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) session->response = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) session->resp_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) mutex_init(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) file->private_data = session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return nonseekable_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int vmcp_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct vmcp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) session = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) vmcp_response_free(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) kfree(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) vmcp_read(struct file *file, char __user *buff, size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct vmcp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) session = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (mutex_lock_interruptible(&session->mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!session->response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) mutex_unlock(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) size = min_t(size_t, session->resp_size, session->bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = simple_read_from_buffer(buff, count, ppos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) session->response, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) mutex_unlock(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) vmcp_write(struct file *file, const char __user *buff, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) char *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct vmcp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (count > 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cmd = memdup_user_nul(buff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (IS_ERR(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return PTR_ERR(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) session = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (mutex_lock_interruptible(&session->mutex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (!session->response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) vmcp_response_alloc(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!session->response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) mutex_unlock(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) debug_text_event(vmcp_debug, 1, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) session->resp_size = cpcmd(cmd, session->response, session->bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) &session->resp_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) mutex_unlock(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) *ppos = 0; /* reset the file pointer after a command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * These ioctls are available, as the semantics of the diagnose 8 call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * does not fit very well into a Linux call. Diagnose X'08' is described in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * CP Programming Services SC24-6084-00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * VMCP_GETCODE: gives the CP return code back to user space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * VMCP_SETBUF: sets the response buffer for the next write call. diagnose 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * expects adjacent pages in real storage and to make matters worse, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * dont know the size of the response. Therefore we default to PAGESIZE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * let userspace to change the response size, if userspace expects a bigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static long vmcp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct vmcp_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int ret = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int __user *argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) session = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (is_compat_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) argp = (int __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (mutex_lock_interruptible(&session->mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case VMCP_GETCODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ret = put_user(session->resp_code, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) case VMCP_SETBUF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) vmcp_response_free(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ret = get_user(session->bufsize, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) session->bufsize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (!session->bufsize || get_order(session->bufsize) > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) session->bufsize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) case VMCP_GETSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ret = put_user(session->resp_size, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) mutex_unlock(&session->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static const struct file_operations vmcp_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .open = vmcp_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .release = vmcp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .read = vmcp_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .write = vmcp_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .unlocked_ioctl = vmcp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .compat_ioctl = vmcp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static struct miscdevice vmcp_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .name = "vmcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .minor = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .fops = &vmcp_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int __init vmcp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) vmcp_debug = debug_register("vmcp", 1, 1, 240);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!vmcp_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ret = debug_register_view(vmcp_debug, &debug_hex_ascii_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) debug_unregister(vmcp_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ret = misc_register(&vmcp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) debug_unregister(vmcp_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) device_initcall(vmcp_init);