GNU Linux-libre 4.14.332-gnu1
[releases.git] / drivers / staging / unisys / include / visorbus.h
1 /*
2  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13  * NON INFRINGEMENT.  See the GNU General Public License for more
14  * details.
15  */
16
17 /*
18  *  This header file is to be included by other kernel mode components that
19  *  implement a particular kind of visor_device.  Each of these other kernel
20  *  mode components is called a visor device driver.  Refer to visortemplate
21  *  for a minimal sample visor device driver.
22  *
23  *  There should be nothing in this file that is private to the visorbus
24  *  bus implementation itself.
25  */
26
27 #ifndef __VISORBUS_H__
28 #define __VISORBUS_H__
29
30 #include <linux/device.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33
34 #include "channel.h"
35
36 struct visor_device;
37 extern struct bus_type visorbus_type;
38
39 typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
40                                               int status);
41
42 struct visorchipset_state {
43         u32 created:1;
44         u32 attached:1;
45         u32 configured:1;
46         u32 running:1;
47         /* Add new fields above. */
48         /* Remaining bits in this 32-bit word are unused. */
49 };
50
51 /*
52  * This struct describes a specific Supervisor channel, by providing its
53  * GUID, name, and sizes.
54  */
55 struct visor_channeltype_descriptor {
56         const guid_t guid;
57         const char *name;
58 };
59
60 /**
61  * struct visor_driver - Information provided by each visor driver when it
62  * registers with the visorbus driver.
63  * @name:               Name of the visor driver.
64  * @owner:              The module owner.
65  * @channel_types:      Types of channels handled by this driver, ending with
66  *                      a zero GUID. Our specialized BUS.match() method knows
67  *                      about this list, and uses it to determine whether this
68  *                      driver will in fact handle a new device that it has
69  *                      detected.
70  * @probe:              Called when a new device comes online, by our probe()
71  *                      function specified by driver.probe() (triggered
72  *                      ultimately by some call to driver_register(),
73  *                      bus_add_driver(), or driver_attach()).
74  * @remove:             Called when a new device is removed, by our remove()
75  *                      function specified by driver.remove() (triggered
76  *                      ultimately by some call to device_release_driver()).
77  * @channel_interrupt:  Called periodically, whenever there is a possiblity
78  *                      that "something interesting" may have happened to the
79  *                      channel.
80  * @pause:              Called to initiate a change of the device's state.  If
81  *                      the return valu`e is < 0, there was an error and the
82  *                      state transition will NOT occur.  If the return value
83  *                      is >= 0, then the state transition was INITIATED
84  *                      successfully, and complete_func() will be called (or
85  *                      was just called) with the final status when either the
86  *                      state transition fails or completes successfully.
87  * @resume:             Behaves similar to pause.
88  * @driver:             Private reference to the device driver. For use by bus
89  *                      driver only.
90  */
91 struct visor_driver {
92         const char *name;
93         struct module *owner;
94         struct visor_channeltype_descriptor *channel_types;
95         int (*probe)(struct visor_device *dev);
96         void (*remove)(struct visor_device *dev);
97         void (*channel_interrupt)(struct visor_device *dev);
98         int (*pause)(struct visor_device *dev,
99                      visorbus_state_complete_func complete_func);
100         int (*resume)(struct visor_device *dev,
101                       visorbus_state_complete_func complete_func);
102
103         /* These fields are for private use by the bus driver only. */
104         struct device_driver driver;
105 };
106
107 #define to_visor_driver(x) (container_of(x, struct visor_driver, driver))
108
109 /**
110  * struct visor_device - A device type for things "plugged" into the visorbus
111  * bus
112  * @visorchannel:               Points to the channel that the device is
113  *                              associated with.
114  * @channel_type_guid:          Identifies the channel type to the bus driver.
115  * @device:                     Device struct meant for use by the bus driver
116  *                              only.
117  * @list_all:                   Used by the bus driver to enumerate devices.
118  * @timer:                      Timer fired periodically to do interrupt-type
119  *                              activity.
120  * @being_removed:              Indicates that the device is being removed from
121  *                              the bus. Private bus driver use only.
122  * @visordriver_callback_lock:  Used by the bus driver to lock when adding and
123  *                              removing devices.
124  * @pausing:                    Indicates that a change towards a paused state.
125  *                              is in progress. Only modified by the bus driver.
126  * @resuming:                   Indicates that a change towards a running state
127  *                              is in progress. Only modified by the bus driver.
128  * @chipset_bus_no:             Private field used by the bus driver.
129  * @chipset_dev_no:             Private field used the bus driver.
130  * @state:                      Used to indicate the current state of the
131  *                              device.
132  * @inst:                       Unique GUID for this instance of the device.
133  * @name:                       Name of the device.
134  * @pending_msg_hdr:            For private use by bus driver to respond to
135  *                              hypervisor requests.
136  * @vbus_hdr_info:              A pointer to header info. Private use by bus
137  *                              driver.
138  * @partition_guid:             Indicates client partion id. This should be the
139  *                              same across all visor_devices in the current
140  *                              guest. Private use by bus driver only.
141  */
142
143 struct visor_device {
144         struct visorchannel *visorchannel;
145         guid_t channel_type_guid;
146         /* These fields are for private use by the bus driver only. */
147         struct device device;
148         struct list_head list_all;
149         struct timer_list timer;
150         bool timer_active;
151         bool being_removed;
152         struct mutex visordriver_callback_lock; /* synchronize probe/remove */
153         bool pausing;
154         bool resuming;
155         u32 chipset_bus_no;
156         u32 chipset_dev_no;
157         struct visorchipset_state state;
158         guid_t inst;
159         u8 *name;
160         struct controlvm_message_header *pending_msg_hdr;
161         void *vbus_hdr_info;
162         guid_t partition_guid;
163         struct dentry *debugfs_dir;
164         struct dentry *debugfs_client_bus_info;
165 };
166
167 #define to_visor_device(x) container_of(x, struct visor_device, device)
168
169 int visor_check_channel(struct channel_header *ch, struct device *dev,
170                         const guid_t *expected_uuid, char *chname,
171                         u64 expected_min_bytes, u32 expected_version,
172                         u64 expected_signature);
173
174 int visorbus_register_visor_driver(struct visor_driver *drv);
175 void visorbus_unregister_visor_driver(struct visor_driver *drv);
176 int visorbus_read_channel(struct visor_device *dev,
177                           unsigned long offset, void *dest,
178                           unsigned long nbytes);
179 int visorbus_write_channel(struct visor_device *dev,
180                            unsigned long offset, void *src,
181                            unsigned long nbytes);
182 int visorbus_enable_channel_interrupts(struct visor_device *dev);
183 void visorbus_disable_channel_interrupts(struct visor_device *dev);
184
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  */
197 enum 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
205 int visorchannel_signalremove(struct visorchannel *channel, u32 queue,
206                               void *msg);
207 int visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
208                               void *msg);
209 bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
210 const guid_t *visorchannel_get_guid(struct visorchannel *channel);
211
212 #define BUS_ROOT_DEVICE UINT_MAX
213 struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no,
214                                                struct visor_device *from);
215 #endif