Commit | Line | Data |
---|---|---|
3703987c EA |
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> | |
c0a14641 | 34 | #include <linux/poll.h> |
3703987c EA |
35 | #include <linux/kernel.h> |
36 | #include <linux/uuid.h> | |
37 | ||
38 | #include "periodic_work.h" | |
3703987c | 39 | #include "channel.h" |
f6439218 | 40 | |
3703987c EA |
41 | struct visor_driver; |
42 | struct visor_device; | |
1fb3016e | 43 | extern struct bus_type visorbus_type; |
3703987c EA |
44 | |
45 | typedef void (*visorbus_state_complete_func) (struct visor_device *dev, | |
a298bc0b | 46 | int status); |
1fb3016e DZ |
47 | struct 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 | }; | |
3703987c EA |
55 | |
56 | /** This struct describes a specific Supervisor channel, by providing its | |
57 | * GUID, name, and sizes. | |
58 | */ | |
59 | struct visor_channeltype_descriptor { | |
60 | const uuid_le guid; | |
61 | const char *name; | |
62 | unsigned long min_size; | |
63 | unsigned long max_size; | |
64 | }; | |
65 | ||
66 | /** Information provided by each visor driver when it registers with the | |
67 | * visorbus driver. | |
68 | */ | |
69 | struct visor_driver { | |
70 | const char *name; | |
71 | const char *version; | |
72 | const char *vertag; | |
73 | const char *build_date; | |
74 | const char *build_time; | |
75 | struct module *owner; | |
76 | ||
77 | /** Types of channels handled by this driver, ending with 0 GUID. | |
78 | * Our specialized BUS.match() method knows about this list, and | |
79 | * uses it to determine whether this driver will in fact handle a | |
80 | * new device that it has detected. | |
81 | */ | |
82 | struct visor_channeltype_descriptor *channel_types; | |
83 | ||
84 | /** Called when a new device comes online, by our probe() function | |
85 | * specified by driver.probe() (triggered ultimately by some call | |
86 | * to driver_register() / bus_add_driver() / driver_attach()). | |
87 | */ | |
88 | int (*probe)(struct visor_device *dev); | |
89 | ||
90 | /** Called when a new device is removed, by our remove() function | |
91 | * specified by driver.remove() (triggered ultimately by some call | |
92 | * to device_release_driver()). | |
93 | */ | |
94 | void (*remove)(struct visor_device *dev); | |
95 | ||
96 | /** Called periodically, whenever there is a possibility that | |
97 | * "something interesting" may have happened to the channel state. | |
98 | */ | |
99 | void (*channel_interrupt)(struct visor_device *dev); | |
100 | ||
101 | /** Called to initiate a change of the device's state. If the return | |
102 | * valu`e is < 0, there was an error and the state transition will NOT | |
103 | * occur. If the return value is >= 0, then the state transition was | |
104 | * INITIATED successfully, and complete_func() will be called (or was | |
105 | * just called) with the final status when either the state transition | |
106 | * fails or completes successfully. | |
107 | */ | |
108 | int (*pause)(struct visor_device *dev, | |
a298bc0b | 109 | visorbus_state_complete_func complete_func); |
3703987c | 110 | int (*resume)(struct visor_device *dev, |
a298bc0b | 111 | visorbus_state_complete_func complete_func); |
3703987c EA |
112 | |
113 | /** These fields are for private use by the bus driver only. */ | |
114 | struct device_driver driver; | |
115 | struct driver_attribute version_attr; | |
116 | }; | |
117 | ||
118 | #define to_visor_driver(x) container_of(x, struct visor_driver, driver) | |
119 | ||
120 | /** A device type for things "plugged" into the visorbus bus */ | |
121 | ||
122 | struct visor_device { | |
123 | /** visor driver can use the visorchannel member with the functions | |
124 | * defined in visorchannel.h to access the channel | |
125 | */ | |
126 | struct visorchannel *visorchannel; | |
127 | uuid_le channel_type_guid; | |
128 | u64 channel_bytes; | |
129 | ||
130 | /** These fields are for private use by the bus driver only. | |
131 | * A notable exception is that the visor driver can use | |
132 | * visor_get_drvdata() and visor_set_drvdata() to retrieve or stash | |
133 | * private visor driver specific data within the device member. | |
134 | */ | |
135 | struct device device; | |
136 | struct list_head list_all; | |
137 | struct periodic_work *periodic_work; | |
138 | bool being_removed; | |
139 | bool responded_to_device_create; | |
3703987c EA |
140 | struct kobject kobjdevmajorminor; /* visorbus<x>/dev<y>/devmajorminor/*/ |
141 | struct { | |
142 | int major, minor; | |
143 | void *attr; /* private use by devmajorminor_attr.c you can | |
144 | * change this constant to whatever you | |
145 | * want; */ | |
146 | } devnodes[5]; | |
147 | /* the code will detect and behave appropriately) */ | |
148 | struct semaphore visordriver_callback_lock; | |
149 | bool pausing; | |
150 | bool resuming; | |
65bd6e46 DZ |
151 | u32 chipset_bus_no; |
152 | u32 chipset_dev_no; | |
1fb3016e DZ |
153 | struct visorchipset_state state; |
154 | uuid_le type; | |
155 | uuid_le inst; | |
156 | u8 *name; | |
157 | u8 *description; | |
158 | struct controlvm_message_header *pending_msg_hdr; | |
159 | void *vbus_hdr_info; | |
160 | u32 switch_no; | |
161 | u32 internal_port_no; | |
162 | uuid_le partition_uuid; | |
3703987c EA |
163 | }; |
164 | ||
165 | #define to_visor_device(x) container_of(x, struct visor_device, device) | |
166 | ||
167 | #ifndef STANDALONE_CLIENT | |
168 | int visorbus_register_visor_driver(struct visor_driver *); | |
169 | void visorbus_unregister_visor_driver(struct visor_driver *); | |
170 | int visorbus_read_channel(struct visor_device *dev, | |
171 | unsigned long offset, void *dest, | |
172 | unsigned long nbytes); | |
173 | int visorbus_write_channel(struct visor_device *dev, | |
174 | unsigned long offset, void *src, | |
175 | unsigned long nbytes); | |
176 | int visorbus_clear_channel(struct visor_device *dev, | |
177 | unsigned long offset, u8 ch, unsigned long nbytes); | |
178 | int visorbus_registerdevnode(struct visor_device *dev, | |
179 | const char *name, int major, int minor); | |
180 | void visorbus_enable_channel_interrupts(struct visor_device *dev); | |
181 | void visorbus_disable_channel_interrupts(struct visor_device *dev); | |
182 | #endif | |
183 | ||
dd5f9385 | 184 | /* Note that for visorchannel_create() |
f6439218 DZ |
185 | * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT. |
186 | * In this case, the values can simply be read from the channel header. | |
187 | */ | |
d5b3f1dc | 188 | struct visorchannel *visorchannel_create(u64 physaddr, |
df94247a JS |
189 | unsigned long channel_bytes, |
190 | gfp_t gfp, uuid_le guid); | |
d5b3f1dc | 191 | struct visorchannel *visorchannel_create_with_lock(u64 physaddr, |
df94247a JS |
192 | unsigned long channel_bytes, |
193 | gfp_t gfp, uuid_le guid); | |
f6439218 DZ |
194 | void visorchannel_destroy(struct visorchannel *channel); |
195 | int visorchannel_read(struct visorchannel *channel, ulong offset, | |
196 | void *local, ulong nbytes); | |
197 | int visorchannel_write(struct visorchannel *channel, ulong offset, | |
198 | void *local, ulong nbytes); | |
199 | int visorchannel_clear(struct visorchannel *channel, ulong offset, | |
200 | u8 ch, ulong nbytes); | |
779d0752 | 201 | bool visorchannel_signalremove(struct visorchannel *channel, u32 queue, |
f6439218 | 202 | void *msg); |
779d0752 | 203 | bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue, |
f6439218 DZ |
204 | void *msg); |
205 | int visorchannel_signalqueue_slots_avail(struct visorchannel *channel, | |
206 | u32 queue); | |
207 | int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue); | |
d5b3f1dc | 208 | u64 visorchannel_get_physaddr(struct visorchannel *channel); |
f6439218 DZ |
209 | ulong visorchannel_get_nbytes(struct visorchannel *channel); |
210 | char *visorchannel_id(struct visorchannel *channel, char *s); | |
211 | char *visorchannel_zoneid(struct visorchannel *channel, char *s); | |
212 | u64 visorchannel_get_clientpartition(struct visorchannel *channel); | |
4f6d8a97 DZ |
213 | int visorchannel_set_clientpartition(struct visorchannel *channel, |
214 | u64 partition_handle); | |
f6439218 | 215 | uuid_le visorchannel_get_uuid(struct visorchannel *channel); |
f6439218 DZ |
216 | char *visorchannel_uuid_id(uuid_le *guid, char *s); |
217 | void visorchannel_debug(struct visorchannel *channel, int num_queues, | |
218 | struct seq_file *seq, u32 off); | |
f6439218 DZ |
219 | void __iomem *visorchannel_get_header(struct visorchannel *channel); |
220 | ||
d32517e3 DZ |
221 | #define BUS_ROOT_DEVICE UINT_MAX |
222 | struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, | |
223 | struct visor_device *from); | |
3703987c | 224 | #endif |