]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/xen/xenbus/xenbus_comms.h
Import OS interfaces to Xen services.
[FreeBSD/FreeBSD.git] / sys / xen / xenbus / xenbus_comms.h
1 /*
2  * Private include for xenbus communications.
3  * 
4  * Copyright (C) 2005 Rusty Russell, IBM Corporation
5  *
6  * This file may be distributed separately from the Linux kernel, or
7  * incorporated into other software packages, subject to the following license:
8  * 
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this source file (the "Software"), to deal in the Software without
11  * restriction, including without limitation the rights to use, copy, modify,
12  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
13  * and to permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  * 
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  * 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25  * IN THE SOFTWARE.
26  *
27  * $FreeBSD$
28  */
29
30 #ifndef _XENBUS_COMMS_H
31 #define _XENBUS_COMMS_H
32
33 int xs_init(void);
34 int xb_init_comms(void);
35
36 /* Low level routines. */
37 int xb_write(const void *data, unsigned len);
38 int xb_read(void *data, unsigned len);
39 int xs_input_avail(void);
40 extern int xb_waitq;
41
42 #define __wait_event_interruptible(wchan, condition, ret)       \
43 do {                                                            \
44         for (;;) {                                              \
45                 if (condition)                                  \
46                         break;                                  \
47                 if ((ret = !tsleep(wchan, PWAIT | PCATCH, "waitev", hz/10))) \
48                         break;                                                  \
49         }                                                                       \
50 } while (0)
51
52
53 #define wait_event_interruptible(wchan, condition)                      \
54 ({                                                                      \
55         int __ret = 0;                                                  \
56         if (!(condition))                                               \
57                 __wait_event_interruptible(wchan, condition, __ret);    \
58         __ret;                                                          \
59 }) 
60
61           
62           
63 #define DECLARE_MUTEX(lock) struct sema lock
64 #define semaphore     sema
65 #define rw_semaphore  sema
66
67 #define down          sema_wait
68 #define up            sema_post
69 #define down_read     sema_wait
70 #define up_read       sema_post
71 #define down_write    sema_wait
72 #define up_write      sema_post
73
74 /**
75  * container_of - cast a member of a structure out to the containing structure
76  *
77  * @ptr:        the pointer to the member.
78  * @type:       the type of the container struct this is embedded in.
79  * @member:     the name of the member within the struct.
80  *
81  */
82 #define container_of(ptr, type, member) ({                      \
83         __typeof__( ((type *)0)->member ) *__mptr = (ptr);      \
84         (type *)( (char *)__mptr - offsetof(type,member) );})
85  
86
87 /*
88  * XXX 
89  *
90  */
91
92 #define GFP_KERNEL 1
93 #define EXPORT_SYMBOL(x)
94 #define kmalloc(size, unused) malloc(size, M_DEVBUF, M_WAITOK)
95 #define kfree(ptr) free((void *)(uintptr_t)ptr, M_DEVBUF)
96 #define BUG_ON        PANIC_IF
97 #define semaphore     sema
98 #define rw_semaphore  sema
99 typedef struct mtx    spinlock_t;
100 #define spin_lock     mtx_lock
101 #define spin_unlock   mtx_unlock
102 #define DEFINE_SPINLOCK(lock) struct mtx lock
103 #define DECLARE_MUTEX(lock) struct sema lock
104 #define u32           uint32_t
105 #define list_del(head, ent)      TAILQ_REMOVE(head, ent, list) 
106 #define simple_strtoul strtoul
107 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
108 #define list_empty    TAILQ_EMPTY
109 #define wake_up       wakeup
110 #define BUS_ID_SIZE  128
111
112 struct xen_bus_type
113 {
114                 char *root;
115                 unsigned int levels;
116                 int (*get_bus_id)(char bus_id[BUS_ID_SIZE], const char *nodename);
117                 int (*probe)(const char *type, const char *dir);
118                 struct xendev_list_head *bus;
119                 int error;
120 #if 0
121         struct bus_type bus;
122         struct device dev;
123 #endif 
124 };
125
126
127 extern void xenbus_backend_probe_and_watch(void);
128 int xenbus_probe_node(struct xen_bus_type *bus, const char *type,
129                       const char *nodename);
130 int xenbus_probe_devices(struct xen_bus_type *bus);
131
132 int xenbus_register_driver_common(struct xenbus_driver *drv,
133                                   struct xen_bus_type *bus);
134
135 void dev_changed(const char *node, struct xen_bus_type *bus);
136
137 int 
138 read_otherend_details(struct xenbus_device *xendev, char *id_node, 
139                       char *path_node);
140
141 char *kasprintf(const char *fmt, ...);
142
143
144
145
146 #endif /* _XENBUS_COMMS_H */
147
148 /*
149  * Local variables:
150  *  c-file-style: "linux"
151  *  indent-tabs-mode: t
152  *  c-indent-level: 8
153  *  c-basic-offset: 8
154  *  tab-width: 8
155  * End:
156  */