linux/drivers/staging/unisys/include/visorbus.h
<<
>>
Prefs
   1/* visorbus.h
   2 *
   3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
   4 * All rights reserved.
   5 *
   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.
  10 *
  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
  15 * details.
  16 */
  17
  18/*
  19 *  This header file is to be included by other kernel mode components that
  20 *  implement a particular kind of visor_device.  Each of these other kernel
  21 *  mode components is called a visor device driver.  Refer to visortemplate
  22 *  for a minimal sample visor device driver.
  23 *
  24 *  There should be nothing in this file that is private to the visorbus
  25 *  bus implementation itself.
  26 *
  27 */
  28
  29#ifndef __VISORBUS_H__
  30#define __VISORBUS_H__
  31
  32#include <linux/device.h>
  33#include <linux/module.h>
  34#include <linux/poll.h>
  35#include <linux/kernel.h>
  36#include <linux/uuid.h>
  37#include <linux/seq_file.h>
  38#include <linux/slab.h>
  39
  40#include "channel.h"
  41
  42struct visor_driver;
  43struct visor_device;
  44extern struct bus_type visorbus_type;
  45
  46typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
  47                                              int status);
  48struct visorchipset_state {
  49        u32 created:1;
  50        u32 attached:1;
  51        u32 configured:1;
  52        u32 running:1;
  53        /* Add new fields above. */
  54        /* Remaining bits in this 32-bit word are unused. */
  55};
  56
  57/** This struct describes a specific Supervisor channel, by providing its
  58 *  GUID, name, and sizes.
  59 */
  60struct visor_channeltype_descriptor {
  61        const uuid_le guid;
  62        const char *name;
  63};
  64
  65/**
  66 * struct visor_driver - Information provided by each visor driver when it
  67 * registers with the visorbus driver.
  68 * @name:               Name of the visor driver.
  69 * @owner:              The module owner.
  70 * @channel_types:      Types of channels handled by this driver, ending with
  71 *                      a zero GUID. Our specialized BUS.match() method knows
  72 *                      about this list, and uses it to determine whether this
  73 *                      driver will in fact handle a new device that it has
  74 *                      detected.
  75 * @probe:              Called when a new device comes online, by our probe()
  76 *                      function specified by driver.probe() (triggered
  77 *                      ultimately by some call to driver_register(),
  78 *                      bus_add_driver(), or driver_attach()).
  79 * @remove:             Called when a new device is removed, by our remove()
  80 *                      function specified by driver.remove() (triggered
  81 *                      ultimately by some call to device_release_driver()).
  82 * @channel_interrupt:  Called periodically, whenever there is a possiblity
  83 *                      that "something interesting" may have happened to the
  84 *                      channel.
  85 * @pause:              Called to initiate a change of the device's state.  If
  86 *                      the return valu`e is < 0, there was an error and the
  87 *                      state transition will NOT occur.  If the return value
  88 *                      is >= 0, then the state transition was INITIATED
  89 *                      successfully, and complete_func() will be called (or
  90 *                      was just called) with the final status when either the
  91 *                      state transition fails or completes successfully.
  92 * @resume:             Behaves similar to pause.
  93 * @driver:             Private reference to the device driver. For use by bus
  94 *                      driver only.
  95 */
  96struct visor_driver {
  97        const char *name;
  98        struct module *owner;
  99        struct visor_channeltype_descriptor *channel_types;
 100        int (*probe)(struct visor_device *dev);
 101        void (*remove)(struct visor_device *dev);
 102        void (*channel_interrupt)(struct visor_device *dev);
 103        int (*pause)(struct visor_device *dev,
 104                     visorbus_state_complete_func complete_func);
 105        int (*resume)(struct visor_device *dev,
 106                      visorbus_state_complete_func complete_func);
 107
 108        /* These fields are for private use by the bus driver only. */
 109        struct device_driver driver;
 110};
 111
 112#define to_visor_driver(x) ((x) ? \
 113        (container_of(x, struct visor_driver, driver)) : (NULL))
 114
 115/**
 116 * struct visor_device - A device type for things "plugged" into the visorbus
 117 * bus
 118 * @visorchannel:               Points to the channel that the device is
 119 *                              associated with.
 120 * @channel_type_guid:          Identifies the channel type to the bus driver.
 121 * @device:                     Device struct meant for use by the bus driver
 122 *                              only.
 123 * @list_all:                   Used by the bus driver to enumerate devices.
 124 * @timer:                      Timer fired periodically to do interrupt-type
 125 *                              activity.
 126 * @being_removed:              Indicates that the device is being removed from
 127 *                              the bus. Private bus driver use only.
 128 * @visordriver_callback_lock:  Used by the bus driver to lock when handling
 129 *                              channel events.
 130 * @pausing:                    Indicates that a change towards a paused state.
 131 *                              is in progress. Only modified by the bus driver.
 132 * @resuming:                   Indicates that a change towards a running state
 133 *                              is in progress. Only modified by the bus driver.
 134 * @chipset_bus_no:             Private field used by the bus driver.
 135 * @chipset_dev_no:             Private field used the bus driver.
 136 * @state:                      Used to indicate the current state of the
 137 *                              device.
 138 * @inst:                       Unique GUID for this instance of the device.
 139 * @name:                       Name of the device.
 140 * @pending_msg_hdr:            For private use by bus driver to respond to
 141 *                              hypervisor requests.
 142 * @vbus_hdr_info:              A pointer to header info. Private use by bus
 143 *                              driver.
 144 * @partition_uuid:             Indicates client partion id. This should be the
 145 *                              same across all visor_devices in the current
 146 *                              guest. Private use by bus driver only.
 147 */
 148
 149struct visor_device {
 150        struct visorchannel *visorchannel;
 151        uuid_le channel_type_guid;
 152        /* These fields are for private use by the bus driver only. */
 153        struct device device;
 154        struct list_head list_all;
 155        struct timer_list timer;
 156        bool timer_active;
 157        bool being_removed;
 158        struct mutex visordriver_callback_lock;
 159        bool pausing;
 160        bool resuming;
 161        u32 chipset_bus_no;
 162        u32 chipset_dev_no;
 163        struct visorchipset_state state;
 164        uuid_le inst;
 165        u8 *name;
 166        struct controlvm_message_header *pending_msg_hdr;
 167        void *vbus_hdr_info;
 168        uuid_le partition_uuid;
 169        struct dentry *debugfs_dir;
 170        struct dentry *debugfs_client_bus_info;
 171};
 172
 173#define to_visor_device(x) container_of(x, struct visor_device, device)
 174
 175int visorbus_register_visor_driver(struct visor_driver *drv);
 176void visorbus_unregister_visor_driver(struct visor_driver *drv);
 177int visorbus_read_channel(struct visor_device *dev,
 178                          unsigned long offset, void *dest,
 179                          unsigned long nbytes);
 180int visorbus_write_channel(struct visor_device *dev,
 181                           unsigned long offset, void *src,
 182                           unsigned long nbytes);
 183int visorbus_enable_channel_interrupts(struct visor_device *dev);
 184void visorbus_disable_channel_interrupts(struct visor_device *dev);
 185
 186/* Levels of severity for diagnostic events, in order from lowest severity to
 187 * highest (i.e. fatal errors are the most severe, and should always be logged,
 188 * but info events rarely need to be logged except during debugging). The
 189 * values DIAG_SEVERITY_ENUM_BEGIN and DIAG_SEVERITY_ENUM_END are not valid
 190 * severity values.  They exist merely to dilineate the list, so that future
 191 * additions won't require changes to the driver (i.e. when checking for
 192 * out-of-range severities in SetSeverity). The values DIAG_SEVERITY_OVERRIDE
 193 * and DIAG_SEVERITY_SHUTOFF are not valid severity values for logging events
 194 * but they are valid for controlling the amount of event data. Changes made
 195 * to the enum, need to be reflected in s-Par.
 196 */
 197enum diag_severity {
 198        DIAG_SEVERITY_VERBOSE = 0,
 199        DIAG_SEVERITY_INFO = 1,
 200        DIAG_SEVERITY_WARNING = 2,
 201        DIAG_SEVERITY_ERR = 3,
 202        DIAG_SEVERITY_PRINT = 4,
 203};
 204
 205int visorchannel_signalremove(struct visorchannel *channel, u32 queue,
 206                              void *msg);
 207int visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
 208                              void *msg);
 209bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
 210uuid_le visorchannel_get_uuid(struct visorchannel *channel);
 211
 212#define BUS_ROOT_DEVICE UINT_MAX
 213struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
 214                                               struct visor_device *from);
 215#endif
 216