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
  38#include "periodic_work.h"
  39#include "channel.h"
  40
  41struct visor_driver;
  42struct visor_device;
  43extern struct bus_type visorbus_type;
  44
  45typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
  46                                              int status);
  47struct visorchipset_state {
  48        u32 created:1;
  49        u32 attached:1;
  50        u32 configured:1;
  51        u32 running:1;
  52        /* Add new fields above. */
  53        /* Remaining bits in this 32-bit word are unused. */
  54};
  55
  56/** This struct describes a specific Supervisor channel, by providing its
  57 *  GUID, name, and sizes.
  58 */
  59struct visor_channeltype_descriptor {
  60        const uuid_le guid;
  61        const char *name;
  62};
  63
  64/**
  65 * struct visor_driver - Information provided by each visor driver when it
  66 * registers with the visorbus driver.
  67 * @name:               Name of the visor driver.
  68 * @version:            The numbered version of the driver (x.x.xxx).
  69 * @vertag:             A human readable version string.
  70 * @owner:              The module owner.
  71 * @channel_types:      Types of channels handled by this driver, ending with
  72 *                      a zero GUID. Our specialized BUS.match() method knows
  73 *                      about this list, and uses it to determine whether this
  74 *                      driver will in fact handle a new device that it has
  75 *                      detected.
  76 * @probe:              Called when a new device comes online, by our probe()
  77 *                      function specified by driver.probe() (triggered
  78 *                      ultimately by some call to driver_register(),
  79 *                      bus_add_driver(), or driver_attach()).
  80 * @remove:             Called when a new device is removed, by our remove()
  81 *                      function specified by driver.remove() (triggered
  82 *                      ultimately by some call to device_release_driver()).
  83 * @channel_interrupt:  Called periodically, whenever there is a possiblity
  84 *                      that "something interesting" may have happened to the
  85 *                      channel.
  86 * @pause:              Called to initiate a change of the device's state.  If
  87 *                      the return valu`e is < 0, there was an error and the
  88 *                      state transition will NOT occur.  If the return value
  89 *                      is >= 0, then the state transition was INITIATED
  90 *                      successfully, and complete_func() will be called (or
  91 *                      was just called) with the final status when either the
  92 *                      state transition fails or completes successfully.
  93 * @resume:             Behaves similar to pause.
  94 * @driver:             Private reference to the device driver. For use by bus
  95 *                      driver only.
  96 * @version_attr:       Private version field. For use by bus driver only.
  97 */
  98struct visor_driver {
  99        const char *name;
 100        const char *version;
 101        const char *vertag;
 102        struct module *owner;
 103        struct visor_channeltype_descriptor *channel_types;
 104        int (*probe)(struct visor_device *dev);
 105        void (*remove)(struct visor_device *dev);
 106        void (*channel_interrupt)(struct visor_device *dev);
 107        int (*pause)(struct visor_device *dev,
 108                     visorbus_state_complete_func complete_func);
 109        int (*resume)(struct visor_device *dev,
 110                      visorbus_state_complete_func complete_func);
 111
 112        /* These fields are for private use by the bus driver only. */
 113        struct device_driver driver;
 114        struct driver_attribute version_attr;
 115};
 116
 117#define to_visor_driver(x) ((x) ? \
 118        (container_of(x, struct visor_driver, driver)) : (NULL))
 119
 120/**
 121 * struct visor_device - A device type for things "plugged" into the visorbus
 122 * bus
 123 * visorchannel:                Points to the channel that the device is
 124 *                              associated with.
 125 * channel_type_guid:           Identifies the channel type to the bus driver.
 126 * device:                      Device struct meant for use by the bus driver
 127 *                              only.
 128 * list_all:                    Used by the bus driver to enumerate devices.
 129 * periodic_work:               Device work queue. Private use by bus driver
 130 *                              only.
 131 * being_removed:               Indicates that the device is being removed from
 132 *                              the bus. Private bus driver use only.
 133 * visordriver_callback_lock:   Used by the bus driver to lock when handling
 134 *                              channel events.
 135 * pausing:                     Indicates that a change towards a paused state.
 136 *                              is in progress. Only modified by the bus driver.
 137 * resuming:                    Indicates that a change towards a running state
 138 *                              is in progress. Only modified by the bus driver.
 139 * chipset_bus_no:              Private field used by the bus driver.
 140 * chipset_dev_no:              Private field used the bus driver.
 141 * state:                       Used to indicate the current state of the
 142 *                              device.
 143 * inst:                        Unique GUID for this instance of the device.
 144 * name:                        Name of the device.
 145 * pending_msg_hdr:             For private use by bus driver to respond to
 146 *                              hypervisor requests.
 147 * vbus_hdr_info:               A pointer to header info. Private use by bus
 148 *                              driver.
 149 * partition_uuid:              Indicates client partion id. This should be the
 150 *                              same across all visor_devices in the current
 151 *                              guest. Private use by bus driver only.
 152 */
 153
 154struct visor_device {
 155        struct visorchannel *visorchannel;
 156        uuid_le channel_type_guid;
 157        /* These fields are for private use by the bus driver only. */
 158        struct device device;
 159        struct list_head list_all;
 160        struct periodic_work *periodic_work;
 161        bool being_removed;
 162        struct semaphore visordriver_callback_lock;
 163        bool pausing;
 164        bool resuming;
 165        u32 chipset_bus_no;
 166        u32 chipset_dev_no;
 167        struct visorchipset_state state;
 168        uuid_le inst;
 169        u8 *name;
 170        struct controlvm_message_header *pending_msg_hdr;
 171        void *vbus_hdr_info;
 172        uuid_le partition_uuid;
 173};
 174
 175#define to_visor_device(x) container_of(x, struct visor_device, device)
 176
 177#ifndef STANDALONE_CLIENT
 178int visorbus_register_visor_driver(struct visor_driver *);
 179void visorbus_unregister_visor_driver(struct visor_driver *);
 180int visorbus_read_channel(struct visor_device *dev,
 181                          unsigned long offset, void *dest,
 182                          unsigned long nbytes);
 183int visorbus_write_channel(struct visor_device *dev,
 184                           unsigned long offset, void *src,
 185                           unsigned long nbytes);
 186int visorbus_clear_channel(struct visor_device *dev,
 187                           unsigned long offset, u8 ch, unsigned long nbytes);
 188void visorbus_enable_channel_interrupts(struct visor_device *dev);
 189void visorbus_disable_channel_interrupts(struct visor_device *dev);
 190#endif
 191
 192/* Note that for visorchannel_create()
 193 * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT.
 194 * In this case, the values can simply be read from the channel header.
 195 */
 196struct visorchannel *visorchannel_create(u64 physaddr,
 197                                         unsigned long channel_bytes,
 198                                         gfp_t gfp, uuid_le guid);
 199struct visorchannel *visorchannel_create_with_lock(u64 physaddr,
 200                                                   unsigned long channel_bytes,
 201                                                   gfp_t gfp, uuid_le guid);
 202void visorchannel_destroy(struct visorchannel *channel);
 203int visorchannel_read(struct visorchannel *channel, ulong offset,
 204                      void *local, ulong nbytes);
 205int visorchannel_write(struct visorchannel *channel, ulong offset,
 206                       void *local, ulong nbytes);
 207int visorchannel_clear(struct visorchannel *channel, ulong offset,
 208                       u8 ch, ulong nbytes);
 209bool visorchannel_signalremove(struct visorchannel *channel, u32 queue,
 210                               void *msg);
 211bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
 212                               void *msg);
 213bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
 214
 215int visorchannel_signalqueue_slots_avail(struct visorchannel *channel,
 216                                         u32 queue);
 217int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue);
 218u64 visorchannel_get_physaddr(struct visorchannel *channel);
 219ulong visorchannel_get_nbytes(struct visorchannel *channel);
 220char *visorchannel_id(struct visorchannel *channel, char *s);
 221char *visorchannel_zoneid(struct visorchannel *channel, char *s);
 222u64 visorchannel_get_clientpartition(struct visorchannel *channel);
 223int visorchannel_set_clientpartition(struct visorchannel *channel,
 224                                     u64 partition_handle);
 225uuid_le visorchannel_get_uuid(struct visorchannel *channel);
 226char *visorchannel_uuid_id(uuid_le *guid, char *s);
 227void visorchannel_debug(struct visorchannel *channel, int num_queues,
 228                        struct seq_file *seq, u32 off);
 229void __iomem *visorchannel_get_header(struct visorchannel *channel);
 230
 231#define BUS_ROOT_DEVICE         UINT_MAX
 232struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
 233                                               struct visor_device *from);
 234#endif
 235