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