Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / unisys / visorchipset / visorchipset.h
1 /* visorchipset.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 #ifndef __VISORCHIPSET_H__
19 #define __VISORCHIPSET_H__
20
21 #include <linux/uuid.h>
22
23 #include "timskmod.h"
24 #include "channel.h"
25 #include "controlvmchannel.h"
26 #include "parser.h"
27 #include "procobjecttree.h"
28 #include "vbusdeviceinfo.h"
29 #include "vbushelper.h"
30
31 /** Describes the state from the perspective of which controlvm messages have
32  *  been received for a bus or device.
33  */
34 struct visorchipset_state {
35         u32 created:1;
36         u32 attached:1;
37         u32 configured:1;
38         u32 running:1;
39         /* Add new fields above. */
40         /* Remaining bits in this 32-bit word are unused. */
41 };
42
43 enum visorchipset_addresstype {
44         /** address is guest physical, but outside of the physical memory
45          *  region that is controlled by the running OS (this is the normal
46          *  address type for Supervisor channels)
47          */
48         ADDRTYPE_LOCALPHYSICAL,
49
50         /** address is guest physical, and withIN the confines of the
51          *  physical memory controlled by the running OS.
52          */
53         ADDRTYPE_LOCALTEST,
54 };
55
56 enum crash_obj_type {
57         CRASH_DEV,
58         CRASH_BUS,
59 };
60
61 /** Attributes for a particular Supervisor channel.
62  */
63 struct visorchipset_channel_info {
64         enum visorchipset_addresstype addr_type;
65         HOSTADDRESS channel_addr;
66         struct irq_info intr;
67         u64 n_channel_bytes;
68         uuid_le channel_type_uuid;
69         uuid_le channel_inst_uuid;
70
71 };
72
73 /** Attributes for a particular Supervisor device.
74  *  Any visorchipset client can query these attributes using
75  *  visorchipset_get_client_device_info() or
76  *  visorchipset_get_server_device_info().
77  */
78 struct visorchipset_device_info {
79         struct list_head entry;
80         u32 bus_no;
81         u32 dev_no;
82         uuid_le dev_inst_uuid;
83         struct visorchipset_state state;
84         struct visorchipset_channel_info chan_info;
85         u32 reserved1;          /* control_vm_id */
86         u64 reserved2;
87         u32 switch_no;          /* when devState.attached==1 */
88         u32 internal_port_no;   /* when devState.attached==1 */
89         struct controlvm_message_header pending_msg_hdr;/* CONTROLVM_MESSAGE */
90         /** For private use by the bus driver */
91         void *bus_driver_context;
92
93 };
94
95 static inline struct visorchipset_device_info *finddevice(
96                 struct list_head *list, u32 bus_no, u32 dev_no)
97 {
98         struct visorchipset_device_info *p;
99
100         list_for_each_entry(p, list, entry) {
101                 if (p->bus_no == bus_no && p->dev_no == dev_no)
102                         return p;
103         }
104         return NULL;
105 }
106
107 static inline void delbusdevices(struct list_head *list, u32 bus_no)
108 {
109         struct visorchipset_device_info *p, *tmp;
110
111         list_for_each_entry_safe(p, tmp, list, entry) {
112                 if (p->bus_no == bus_no) {
113                         list_del(&p->entry);
114                         kfree(p);
115                 }
116         }
117 }
118
119 /** Attributes for a particular Supervisor bus.
120  *  (For a service partition acting as the server for buses/devices, there
121  *  is a 1-to-1 relationship between busses and guest partitions.)
122  *  Any visorchipset client can query these attributes using
123  *  visorchipset_get_client_bus_info() or visorchipset_get_bus_info().
124  */
125 struct visorchipset_bus_info {
126         struct list_head entry;
127         u32 bus_no;
128         struct visorchipset_state state;
129         struct visorchipset_channel_info chan_info;
130         uuid_le partition_uuid;
131         u64 partition_handle;
132         u8 *name;               /* UTF8 */
133         u8 *description;        /* UTF8 */
134         u64 reserved1;
135         u32 reserved2;
136         struct {
137                 u32 server:1;
138                 /* Add new fields above. */
139                 /* Remaining bits in this 32-bit word are unused. */
140         } flags;
141         struct controlvm_message_header pending_msg_hdr;/* CONTROLVM MsgHdr */
142         /** For private use by the bus driver */
143         void *bus_driver_context;
144         u64 dev_no;
145
146 };
147
148 static inline struct visorchipset_bus_info *
149 findbus(struct list_head *list, u32 bus_no)
150 {
151         struct visorchipset_bus_info *p;
152
153         list_for_each_entry(p, list, entry) {
154                 if (p->bus_no == bus_no)
155                         return p;
156         }
157         return NULL;
158 }
159
160 /*  These functions will be called from within visorchipset when certain
161  *  events happen.  (The implementation of these functions is outside of
162  *  visorchipset.)
163  */
164 struct visorchipset_busdev_notifiers {
165         void (*bus_create)(ulong bus_no);
166         void (*bus_destroy)(ulong bus_no);
167         void (*device_create)(ulong bus_no, ulong dev_no);
168         void (*device_destroy)(ulong bus_no, ulong dev_no);
169         void (*device_pause)(ulong bus_no, ulong dev_no);
170         void (*device_resume)(ulong bus_no, ulong dev_no);
171         int (*get_channel_info)(uuid_le type_uuid, ulong *min_size,
172                                 ulong *max_size);
173 };
174
175 /*  These functions live inside visorchipset, and will be called to indicate
176  *  responses to specific events (by code outside of visorchipset).
177  *  For now, the value for each response is simply either:
178  *       0 = it worked
179  *      -1 = it failed
180  */
181 struct visorchipset_busdev_responders {
182         void (*bus_create)(ulong bus_no, int response);
183         void (*bus_destroy)(ulong bus_no, int response);
184         void (*device_create)(ulong bus_no, ulong dev_no, int response);
185         void (*device_destroy)(ulong bus_no, ulong dev_no, int response);
186         void (*device_pause)(ulong bus_no, ulong dev_no, int response);
187         void (*device_resume)(ulong bus_no, ulong dev_no, int response);
188 };
189
190 /** Register functions (in the bus driver) to get called by visorchipset
191  *  whenever a bus or device appears for which this service partition is
192  *  to be the server for.  visorchipset will fill in <responders>, to
193  *  indicate functions the bus driver should call to indicate message
194  *  responses.
195  */
196 void
197 visorchipset_register_busdev_client(
198                         struct visorchipset_busdev_notifiers *notifiers,
199                         struct visorchipset_busdev_responders *responders,
200                         struct ultra_vbus_deviceinfo *driver_info);
201
202 /** Register functions (in the bus driver) to get called by visorchipset
203  *  whenever a bus or device appears for which this service partition is
204  *  to be the client for.  visorchipset will fill in <responders>, to
205  *  indicate functions the bus driver should call to indicate message
206  *  responses.
207  */
208 void
209 visorchipset_register_busdev_server(
210                         struct visorchipset_busdev_notifiers *notifiers,
211                         struct visorchipset_busdev_responders *responders,
212                         struct ultra_vbus_deviceinfo *driver_info);
213
214 typedef void (*SPARREPORTEVENT_COMPLETE_FUNC) (struct controlvm_message *msg,
215                                                int status);
216
217 void visorchipset_device_pause_response(ulong bus_no, ulong dev_no,
218                                         int response);
219
220 BOOL visorchipset_get_bus_info(ulong bus_no,
221                                struct visorchipset_bus_info *bus_info);
222 BOOL visorchipset_get_device_info(ulong bus_no, ulong dev_no,
223                                   struct visorchipset_device_info *dev_info);
224 BOOL visorchipset_set_bus_context(ulong bus_no, void *context);
225 BOOL visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context);
226 int visorchipset_chipset_ready(void);
227 int visorchipset_chipset_selftest(void);
228 int visorchipset_chipset_notready(void);
229 void visorchipset_save_message(struct controlvm_message *msg,
230                                enum crash_obj_type type);
231 void *visorchipset_cache_alloc(struct kmem_cache *pool,
232                                BOOL ok_to_block, char *fn, int ln);
233 void visorchipset_cache_free(struct kmem_cache *pool, void *p,
234                              char *fn, int ln);
235
236 #endif