3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
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.
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
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.
24 * There should be nothing in this file that is private to the visorbus
25 * bus implementation itself.
29 #ifndef __VISORBUS_H__
30 #define __VISORBUS_H__
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>
38 #include "periodic_work.h"
44 typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
47 /** This struct describes a specific Supervisor channel, by providing its
48 * GUID, name, and sizes.
50 struct visor_channeltype_descriptor {
53 unsigned long min_size;
54 unsigned long max_size;
57 /** Information provided by each visor driver when it registers with the
64 const char *build_date;
65 const char *build_time;
68 /** Types of channels handled by this driver, ending with 0 GUID.
69 * Our specialized BUS.match() method knows about this list, and
70 * uses it to determine whether this driver will in fact handle a
71 * new device that it has detected.
73 struct visor_channeltype_descriptor *channel_types;
75 /** Called when a new device comes online, by our probe() function
76 * specified by driver.probe() (triggered ultimately by some call
77 * to driver_register() / bus_add_driver() / driver_attach()).
79 int (*probe)(struct visor_device *dev);
81 /** Called when a new device is removed, by our remove() function
82 * specified by driver.remove() (triggered ultimately by some call
83 * to device_release_driver()).
85 void (*remove)(struct visor_device *dev);
87 /** Called periodically, whenever there is a possibility that
88 * "something interesting" may have happened to the channel state.
90 void (*channel_interrupt)(struct visor_device *dev);
92 /** Called to initiate a change of the device's state. If the return
93 * valu`e is < 0, there was an error and the state transition will NOT
94 * occur. If the return value is >= 0, then the state transition was
95 * INITIATED successfully, and complete_func() will be called (or was
96 * just called) with the final status when either the state transition
97 * fails or completes successfully.
99 int (*pause)(struct visor_device *dev,
100 visorbus_state_complete_func complete_func);
101 int (*resume)(struct visor_device *dev,
102 visorbus_state_complete_func complete_func);
104 /** These fields are for private use by the bus driver only. */
105 struct device_driver driver;
106 struct driver_attribute version_attr;
109 #define to_visor_driver(x) container_of(x, struct visor_driver, driver)
111 /** A device type for things "plugged" into the visorbus bus */
113 struct visor_device {
114 /** visor driver can use the visorchannel member with the functions
115 * defined in visorchannel.h to access the channel
117 struct visorchannel *visorchannel;
118 uuid_le channel_type_guid;
121 /** These fields are for private use by the bus driver only.
122 * A notable exception is that the visor driver can use
123 * visor_get_drvdata() and visor_set_drvdata() to retrieve or stash
124 * private visor driver specific data within the device member.
126 struct device device;
127 struct list_head list_all;
128 struct periodic_work *periodic_work;
130 bool responded_to_device_create;
131 struct kobject kobjdevmajorminor; /* visorbus<x>/dev<y>/devmajorminor/*/
134 void *attr; /* private use by devmajorminor_attr.c you can
135 * change this constant to whatever you
138 /* the code will detect and behave appropriately) */
139 struct semaphore visordriver_callback_lock;
142 unsigned long chipset_bus_no;
143 unsigned long chipset_dev_no;
146 #define to_visor_device(x) container_of(x, struct visor_device, device)
148 #ifndef STANDALONE_CLIENT
149 int visorbus_register_visor_driver(struct visor_driver *);
150 void visorbus_unregister_visor_driver(struct visor_driver *);
151 int visorbus_read_channel(struct visor_device *dev,
152 unsigned long offset, void *dest,
153 unsigned long nbytes);
154 int visorbus_write_channel(struct visor_device *dev,
155 unsigned long offset, void *src,
156 unsigned long nbytes);
157 int visorbus_clear_channel(struct visor_device *dev,
158 unsigned long offset, u8 ch, unsigned long nbytes);
159 int visorbus_registerdevnode(struct visor_device *dev,
160 const char *name, int major, int minor);
161 void visorbus_enable_channel_interrupts(struct visor_device *dev);
162 void visorbus_disable_channel_interrupts(struct visor_device *dev);
165 /* Note that for visorchannel_create()
166 * <channel_bytes> and <guid> arguments may be 0 if we are a channel CLIENT.
167 * In this case, the values can simply be read from the channel header.
169 struct visorchannel *visorchannel_create(u64 physaddr,
170 unsigned long channel_bytes,
171 gfp_t gfp, uuid_le guid);
172 struct visorchannel *visorchannel_create_with_lock(u64 physaddr,
173 unsigned long channel_bytes,
174 gfp_t gfp, uuid_le guid);
175 void visorchannel_destroy(struct visorchannel *channel);
176 int visorchannel_read(struct visorchannel *channel, ulong offset,
177 void *local, ulong nbytes);
178 int visorchannel_write(struct visorchannel *channel, ulong offset,
179 void *local, ulong nbytes);
180 int visorchannel_clear(struct visorchannel *channel, ulong offset,
181 u8 ch, ulong nbytes);
182 bool visorchannel_signalremove(struct visorchannel *channel, u32 queue,
184 bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
186 int visorchannel_signalqueue_slots_avail(struct visorchannel *channel,
188 int visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue);
189 u64 visorchannel_get_physaddr(struct visorchannel *channel);
190 ulong visorchannel_get_nbytes(struct visorchannel *channel);
191 char *visorchannel_id(struct visorchannel *channel, char *s);
192 char *visorchannel_zoneid(struct visorchannel *channel, char *s);
193 u64 visorchannel_get_clientpartition(struct visorchannel *channel);
194 uuid_le visorchannel_get_uuid(struct visorchannel *channel);
195 char *visorchannel_uuid_id(uuid_le *guid, char *s);
196 void visorchannel_debug(struct visorchannel *channel, int num_queues,
197 struct seq_file *seq, u32 off);
198 void __iomem *visorchannel_get_header(struct visorchannel *channel);