a21996c6b15574818428891e68ef2f484a0116a7
[pandora-kernel.git] / include / asm-sparc64 / ldc.h
1 #ifndef _SPARC64_LDC_H
2 #define _SPARC64_LDC_H
3
4 #include <asm/hypervisor.h>
5
6 extern int ldom_domaining_enabled;
7 extern void ldom_set_var(const char *var, const char *value);
8 extern void ldom_reboot(const char *boot_command);
9
10 /* The event handler will be evoked when link state changes
11  * or data becomes available on the receive side.
12  *
13  * For non-RAW links, if the LDC_EVENT_RESET event arrives the
14  * driver should reset all of it's internal state and reinvoke
15  * ldc_connect() to try and bring the link up again.
16  *
17  * For RAW links, ldc_connect() is not used.  Instead the driver
18  * just waits for the LDC_EVENT_UP event.
19  */
20 struct ldc_channel_config {
21         void (*event)(void *arg, int event);
22
23         u32                     mtu;
24         unsigned int            rx_irq;
25         unsigned int            tx_irq;
26         u8                      mode;
27 #define LDC_MODE_RAW            0x00
28 #define LDC_MODE_UNRELIABLE     0x01
29 #define LDC_MODE_RESERVED       0x02
30 #define LDC_MODE_STREAM         0x03
31
32         u8                      debug;
33 #define LDC_DEBUG_HS            0x01
34 #define LDC_DEBUG_STATE         0x02
35 #define LDC_DEBUG_RX            0x04
36 #define LDC_DEBUG_TX            0x08
37 #define LDC_DEBUG_DATA          0x10
38 };
39
40 #define LDC_EVENT_RESET         0x01
41 #define LDC_EVENT_UP            0x02
42 #define LDC_EVENT_DATA_READY    0x04
43
44 #define LDC_STATE_INVALID       0x00
45 #define LDC_STATE_INIT          0x01
46 #define LDC_STATE_BOUND         0x02
47 #define LDC_STATE_READY         0x03
48 #define LDC_STATE_CONNECTED     0x04
49
50 struct ldc_channel;
51
52 /* Allocate state for a channel.  */
53 extern struct ldc_channel *ldc_alloc(unsigned long id,
54                                      const struct ldc_channel_config *cfgp,
55                                      void *event_arg);
56
57 /* Shut down and free state for a channel.  */
58 extern void ldc_free(struct ldc_channel *lp);
59
60 /* Register TX and RX queues of the link with the hypervisor.  */
61 extern int ldc_bind(struct ldc_channel *lp, const char *name);
62
63 /* For non-RAW protocols we need to complete a handshake before
64  * communication can proceed.  ldc_connect() does that, if the
65  * handshake completes successfully, an LDC_EVENT_UP event will
66  * be sent up to the driver.
67  */
68 extern int ldc_connect(struct ldc_channel *lp);
69 extern int ldc_disconnect(struct ldc_channel *lp);
70
71 extern int ldc_state(struct ldc_channel *lp);
72
73 /* Read and write operations.  Only valid when the link is up.  */
74 extern int ldc_write(struct ldc_channel *lp, const void *buf,
75                      unsigned int size);
76 extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
77
78 #define LDC_MAP_SHADOW  0x01
79 #define LDC_MAP_DIRECT  0x02
80 #define LDC_MAP_IO      0x04
81 #define LDC_MAP_R       0x08
82 #define LDC_MAP_W       0x10
83 #define LDC_MAP_X       0x20
84 #define LDC_MAP_RW      (LDC_MAP_R | LDC_MAP_W)
85 #define LDC_MAP_RWX     (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
86 #define LDC_MAP_ALL     0x03f
87
88 struct ldc_trans_cookie {
89         u64                     cookie_addr;
90         u64                     cookie_size;
91 };
92
93 struct scatterlist;
94 extern int ldc_map_sg(struct ldc_channel *lp,
95                       struct scatterlist *sg, int num_sg,
96                       struct ldc_trans_cookie *cookies, int ncookies,
97                       unsigned int map_perm);
98
99 extern int ldc_map_single(struct ldc_channel *lp,
100                           void *buf, unsigned int len,
101                           struct ldc_trans_cookie *cookies, int ncookies,
102                           unsigned int map_perm);
103
104 extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
105                       int ncookies);
106
107 extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
108                     void *buf, unsigned int len, unsigned long offset,
109                     struct ldc_trans_cookie *cookies, int ncookies);
110
111 static inline int ldc_get_dring_entry(struct ldc_channel *lp,
112                                       void *buf, unsigned int len,
113                                       unsigned long offset,
114                                       struct ldc_trans_cookie *cookies,
115                                       int ncookies)
116 {
117         return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
118 }
119
120 static inline int ldc_put_dring_entry(struct ldc_channel *lp,
121                                       void *buf, unsigned int len,
122                                       unsigned long offset,
123                                       struct ldc_trans_cookie *cookies,
124                                       int ncookies)
125 {
126         return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
127 }
128
129 extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
130                                  struct ldc_trans_cookie *cookies,
131                                  int *ncookies, unsigned int map_perm);
132
133 extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
134                                unsigned int len,
135                                struct ldc_trans_cookie *cookies, int ncookies);
136
137 #endif /* _SPARC64_LDC_H */