/****************************************************************************** * xenbus_comms.c * * Low level code to talks to Xen Store: ringbuffer and event channel. * * Copyright (C) 2005 Rusty Russell, IBM Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation; or, when distributed * separately from the Linux kernel or incorporated into other * software packages, subject to the following license: * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this source file (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #define pr_fmt(fmt) … #include <linux/wait.h> #include <linux/interrupt.h> #include <linux/kthread.h> #include <linux/sched.h> #include <linux/err.h> #include <xen/xenbus.h> #include <asm/xen/hypervisor.h> #include <xen/events.h> #include <xen/page.h> #include "xenbus.h" /* A list of replies. Currently only one will ever be outstanding. */ LIST_HEAD(…); /* A list of write requests. */ LIST_HEAD(…); DECLARE_WAIT_QUEUE_HEAD(…); DEFINE_MUTEX(…) …; /* Protect xenbus reader thread against save/restore. */ DEFINE_MUTEX(…) …; static int xenbus_irq; static struct task_struct *xenbus_task; static irqreturn_t wake_waiting(int irq, void *unused) { … } static int check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod) { … } static void *get_output_chunk(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod, char *buf, uint32_t *len) { … } static const void *get_input_chunk(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod, const char *buf, uint32_t *len) { … } static int xb_data_to_write(void) { … } /** * xb_write - low level write * @data: buffer to send * @len: length of buffer * * Returns number of bytes written or -err. */ static int xb_write(const void *data, unsigned int len) { … } static int xb_data_to_read(void) { … } static int xb_read(void *data, unsigned int len) { … } static int process_msg(void) { … } static int process_writes(void) { … } static int xb_thread_work(void) { … } static int xenbus_thread(void *unused) { … } /** * xb_init_comms - Set up interrupt handler off store event channel. */ int xb_init_comms(void) { … } void xb_deinit_comms(void) { … }