staging: unisys: Clean up device sysfs attributes
[linux-2.6-block.git] / drivers / staging / unisys / include / visorbus.h
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>
34 #include <linux/poll.h>
35 #include <linux/kernel.h>
36 #include <linux/uuid.h>
37
38 #include "periodic_work.h"
39 #include "channel.h"
40
41 struct visor_driver;
42 struct visor_device;
43
44 typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
45                                               int status);
46
47 /** This struct describes a specific Supervisor channel, by providing its
48  *  GUID, name, and sizes.
49  */
50 struct visor_channeltype_descriptor {
51         const uuid_le guid;
52         const char *name;
53         unsigned long min_size;
54         unsigned long max_size;
55 };
56
57 /** Information provided by each visor driver when it registers with the
58  *  visorbus driver.
59  */
60 struct visor_driver {
61         const char *name;
62         const char *version;
63         const char *vertag;
64         const char *build_date;
65         const char *build_time;
66         struct module *owner;
67
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.
72          */
73         struct visor_channeltype_descriptor *channel_types;
74
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()).
78          */
79         int (*probe)(struct visor_device *dev);
80
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()).
84          */
85         void (*remove)(struct visor_device *dev);
86
87         /** Called periodically, whenever there is a possibility that
88          *  "something interesting" may have happened to the channel state.
89          */
90         void (*channel_interrupt)(struct visor_device *dev);
91
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.
98          */
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);
103
104         /** These fields are for private use by the bus driver only. */
105         struct device_driver driver;
106         struct driver_attribute version_attr;
107 };
108
109 #define to_visor_driver(x) container_of(x, struct visor_driver, driver)
110
111 /** A device type for things "plugged" into the visorbus bus */
112
113 struct visor_device {
114         /** visor driver can use the visorchannel member with the functions
115          *  defined in visorchannel.h to access the channel
116          */
117         struct visorchannel *visorchannel;
118         uuid_le channel_type_guid;
119         u64 channel_bytes;
120
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.
125          */
126         struct device device;
127         struct list_head list_all;
128         struct periodic_work *periodic_work;
129         bool being_removed;
130         bool responded_to_device_create;
131         struct kobject kobjdevmajorminor; /* visorbus<x>/dev<y>/devmajorminor/*/
132         struct {
133                 int major, minor;
134                 void *attr;     /* private use by devmajorminor_attr.c you can
135                                    * change this constant to whatever you
136                                    * want; */
137         } devnodes[5];
138         /* the code will detect and behave appropriately) */
139         struct semaphore visordriver_callback_lock;
140         bool pausing;
141         bool resuming;
142         unsigned long chipset_bus_no;
143         unsigned long chipset_dev_no;
144 };
145
146 #define to_visor_device(x) container_of(x, struct visor_device, device)
147
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);
163 #endif
164
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.
168  */
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,
183                                void *msg);
184 bool visorchannel_signalinsert(struct visorchannel *channel, u32 queue,
185                                void *msg);
186 int visorchannel_signalqueue_slots_avail(struct visorchannel *channel,
187                                          u32 queue);
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);
199
200 #endif