blob: 9baf1ec70d0132eab09b751cc21eafbcf6ab43d4 [file] [log] [blame]
Erik Arfvidson37039872015-05-05 18:36:00 -04001/* 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>
Erik Arfvidsonc0a14642015-05-05 18:37:06 -040034#include <linux/poll.h>
Erik Arfvidson37039872015-05-05 18:36:00 -040035#include <linux/kernel.h>
36#include <linux/uuid.h>
37
38#include "periodic_work.h"
Erik Arfvidson37039872015-05-05 18:36:00 -040039#include "channel.h"
Don Zickusf6439212015-05-05 18:36:02 -040040
Erik Arfvidson37039872015-05-05 18:36:00 -040041struct visor_driver;
42struct visor_device;
Don Zickus1fb30162015-05-13 13:22:18 -040043extern struct bus_type visorbus_type;
Erik Arfvidson37039872015-05-05 18:36:00 -040044
45typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
Don Zickusa298bc02015-06-04 09:22:42 -040046 int status);
Don Zickus1fb30162015-05-13 13:22:18 -040047struct 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};
Erik Arfvidson37039872015-05-05 18:36:00 -040055
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;
Erik Arfvidson37039872015-05-05 18:36:00 -040062};
63
Alexander Curtinb9edaf72016-04-18 23:22:01 -040064/**
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.
Erik Arfvidson37039872015-05-05 18:36:00 -040097 */
98struct visor_driver {
99 const char *name;
100 const char *version;
101 const char *vertag;
Erik Arfvidson37039872015-05-05 18:36:00 -0400102 struct module *owner;
Erik Arfvidson37039872015-05-05 18:36:00 -0400103 struct visor_channeltype_descriptor *channel_types;
Erik Arfvidson37039872015-05-05 18:36:00 -0400104 int (*probe)(struct visor_device *dev);
Erik Arfvidson37039872015-05-05 18:36:00 -0400105 void (*remove)(struct visor_device *dev);
Erik Arfvidson37039872015-05-05 18:36:00 -0400106 void (*channel_interrupt)(struct visor_device *dev);
Erik Arfvidson37039872015-05-05 18:36:00 -0400107 int (*pause)(struct visor_device *dev,
Don Zickusa298bc02015-06-04 09:22:42 -0400108 visorbus_state_complete_func complete_func);
Erik Arfvidson37039872015-05-05 18:36:00 -0400109 int (*resume)(struct visor_device *dev,
Don Zickusa298bc02015-06-04 09:22:42 -0400110 visorbus_state_complete_func complete_func);
Erik Arfvidson37039872015-05-05 18:36:00 -0400111
Alexander Curtinb9edaf72016-04-18 23:22:01 -0400112 /* These fields are for private use by the bus driver only. */
Erik Arfvidson37039872015-05-05 18:36:00 -0400113 struct device_driver driver;
114 struct driver_attribute version_attr;
115};
116
Tim Selld15a65b2015-07-09 13:27:42 -0400117#define to_visor_driver(x) ((x) ? \
118 (container_of(x, struct visor_driver, driver)) : (NULL))
Erik Arfvidson37039872015-05-05 18:36:00 -0400119
Alexander Curtin39b92802016-04-18 23:22:02 -0400120/**
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 */
Erik Arfvidson37039872015-05-05 18:36:00 -0400153
154struct visor_device {
Erik Arfvidson37039872015-05-05 18:36:00 -0400155 struct visorchannel *visorchannel;
156 uuid_le channel_type_guid;
Alexander Curtin39b92802016-04-18 23:22:02 -0400157 /* These fields are for private use by the bus driver only. */
Erik Arfvidson37039872015-05-05 18:36:00 -0400158 struct device device;
159 struct list_head list_all;
160 struct periodic_work *periodic_work;
161 bool being_removed;
Erik Arfvidson37039872015-05-05 18:36:00 -0400162 struct semaphore visordriver_callback_lock;
163 bool pausing;
164 bool resuming;
Don Zickus65bd6e42015-06-04 09:22:40 -0400165 u32 chipset_bus_no;
166 u32 chipset_dev_no;
Don Zickus1fb30162015-05-13 13:22:18 -0400167 struct visorchipset_state state;
Don Zickus1fb30162015-05-13 13:22:18 -0400168 uuid_le inst;
169 u8 *name;
Don Zickus1fb30162015-05-13 13:22:18 -0400170 struct controlvm_message_header *pending_msg_hdr;
171 void *vbus_hdr_info;
Don Zickus1fb30162015-05-13 13:22:18 -0400172 uuid_le partition_uuid;
Erik Arfvidson37039872015-05-05 18:36:00 -0400173};
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);
Erik Arfvidson37039872015-05-05 18:36:00 -0400188void visorbus_enable_channel_interrupts(struct visor_device *dev);
189void visorbus_disable_channel_interrupts(struct visor_device *dev);
190#endif
191
Jes Sorensendd5f9382015-05-05 18:36:20 -0400192/* Note that for visorchannel_create()
Don Zickusf6439212015-05-05 18:36:02 -0400193 * <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 */
Erik Arfvidsond5b3f1d2015-05-05 18:37:04 -0400196struct visorchannel *visorchannel_create(u64 physaddr,
Jes Sorensendf942472015-05-05 18:37:10 -0400197 unsigned long channel_bytes,
198 gfp_t gfp, uuid_le guid);
Erik Arfvidsond5b3f1d2015-05-05 18:37:04 -0400199struct visorchannel *visorchannel_create_with_lock(u64 physaddr,
Jes Sorensendf942472015-05-05 18:37:10 -0400200 unsigned long channel_bytes,
201 gfp_t gfp, uuid_le guid);
Don Zickusf6439212015-05-05 18:36:02 -0400202void 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);
Prarit Bhargava779d0752015-05-05 18:37:01 -0400209bool visorchannel_signalremove(struct visorchannel *channel, u32 queue,
Don Zickusf6439212015-05-05 18:36:02 -0400210 void *msg);
Prarit Bhargava779d0752015-05-05 18:37:01 -0400211bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
Don Zickusf6439212015-05-05 18:36:02 -0400212 void *msg);
Neil Hormanfdc792c2015-07-31 18:56:32 -0400213bool visorchannel_signalempty(struct visorchannel *channel, u32 queue);
214
Don Zickusf6439212015-05-05 18:36:02 -0400215int visorchannel_signalqueue_slots_avail(struct visorchannel *channel,
216 u32 queue);
217int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue);
Erik Arfvidsond5b3f1d2015-05-05 18:37:04 -0400218u64 visorchannel_get_physaddr(struct visorchannel *channel);
Don Zickusf6439212015-05-05 18:36:02 -0400219ulong 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);
Don Zickus4f6d8a92015-05-13 13:22:20 -0400223int visorchannel_set_clientpartition(struct visorchannel *channel,
224 u64 partition_handle);
Don Zickusf6439212015-05-05 18:36:02 -0400225uuid_le visorchannel_get_uuid(struct visorchannel *channel);
Don Zickusf6439212015-05-05 18:36:02 -0400226char *visorchannel_uuid_id(uuid_le *guid, char *s);
227void visorchannel_debug(struct visorchannel *channel, int num_queues,
228 struct seq_file *seq, u32 off);
Don Zickusf6439212015-05-05 18:36:02 -0400229void __iomem *visorchannel_get_header(struct visorchannel *channel);
230
Don Zickusd32517e2015-06-04 09:22:41 -0400231#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);
Erik Arfvidson37039872015-05-05 18:36:00 -0400234#endif