Merge branch 'xseg-refactor' into debian
[archipelago] / xseg / xseg / xseg.h
index ca7846e..208e14b 100644 (file)
@@ -37,9 +37,8 @@ typedef uint32_t xport;
 #define MAX_PATH_LEN 32
 #endif
 
-#ifndef MAX_WAITERS
-#define MAX_WAITERS 32
-#endif
+#define XSEG_NAMESIZE 256
+#define XSEG_TNAMESIZE 32
 
 /* Peers and Segments
  *
@@ -75,9 +74,10 @@ typedef uint32_t xport;
 struct xseg;
 struct xseg_port;
 
-#define MAGIC_OBJH     1
-#define MAGIC_REQ      2
-#define MAGIC_PORT     3
+#define XSEG_MAGIC     (0xcafe0000)
+#define MAGIC_OBJH     (XSEG_MAGIC | 1)
+#define MAGIC_REQ      (XSEG_MAGIC | 2)
+#define MAGIC_PORT     (XSEG_MAGIC | 3)
 
 struct xseg_operations {
        void  (*mfree)(void *mem);
@@ -87,17 +87,21 @@ struct xseg_operations {
        void  (*unmap)(void *xseg, uint64_t size);
 };
 
-#define XSEG_NAMESIZE 256
-#define XSEG_TNAMESIZE 32
-
 struct xseg_type {
        struct xseg_operations ops;
        char name[XSEG_TNAMESIZE];
 };
 
+
 struct xseg_peer_operations {
-       int   (*local_signal_init)(void);
-       void  (*local_signal_quit)(void);
+       int   (*init_signal_desc)(struct xseg *xseg, void *sd);
+       void  (*quit_signal_desc)(struct xseg *xseg, void *sd);
+       void *(*alloc_data)(struct xseg *xseg);
+       void  (*free_data)(struct xseg *xseg, void *data);
+       void *(*alloc_signal_desc)(struct xseg *xseg, void *data);
+       void  (*free_signal_desc)(struct xseg *xseg, void *data, void *sd);
+       int   (*local_signal_init)(struct xseg *xseg, xport portno);
+       void  (*local_signal_quit)(struct xseg *xseg, xport portno);
        int   (*remote_signal_init)(void);
        void  (*remote_signal_quit)(void);
        int   (*signal_join)(struct xseg *xseg);
@@ -137,9 +141,7 @@ struct xseg_port {
        uint64_t max_alloc_reqs;
        uint64_t alloc_reqs;
        struct xlock port_lock;
-       volatile uint64_t waitcue;
-       struct xpool waiters;
-       struct xpool_node bufs[MAX_WAITERS];
+       xptr signal_desc;
 };
 
 struct xseg_request;
@@ -174,6 +176,7 @@ struct xseg_task {
 #define XF_NOSYNC (1 << 0)
 #define XF_FLUSH  (1 << 1)
 #define XF_FUA    (1 << 2)
+#define XF_FORCE  (1 << 3)
 
 /* STATES */
 #define XS_SERVED      (1 << 0)
@@ -187,8 +190,7 @@ struct xseg_task {
 struct xseg_request {
        xserial serial;
        uint64_t offset;
-       uint64_t size; /* FIXME: why are there both size and datalen fields? */
-               /* FIXME: why does filed use ->datalen instead of ->size? */
+       uint64_t size; 
        uint64_t serviced;
        xptr data;
        uint64_t datalen;
@@ -215,6 +217,7 @@ struct xseg_request {
 struct xseg_shared {
        uint64_t flags;
        char (*peer_types)[XSEG_TNAMESIZE]; /* alignment? */
+       xptr *peer_type_data;
        uint32_t nr_peer_types;
 };
 
@@ -222,6 +225,7 @@ struct xseg_private {
        struct xseg_type segment_type;
        struct xseg_peer peer_type;
        struct xseg_peer **peer_types;
+       void **peer_type_data;
        uint32_t max_peer_types;
        void (*wakeup)(uint32_t portno);
        xhash_t *req_data;
@@ -265,7 +269,8 @@ struct xseg {
                                               struct xseg_config  * config    );
 
    struct xseg_port *  xseg_bind_port       ( struct xseg         * xseg,
-                                              uint32_t              portno    );
+                                              uint32_t              portno,
+                                             void                * sd        );
 
     static uint32_t    xseg_portno          ( struct xseg         * xseg,
                                               struct xseg_port    * port      );
@@ -333,13 +338,15 @@ struct xseg_request *  xseg_get_request     ( struct xseg         * xseg,
                                              uint32_t              flags     );
 
 struct xseg_request *  xseg_receive         ( struct xseg         * xseg,
-                                              xport                 portno    );
+                                              xport                 portno,    
+                                             uint32_t              flags     );
 /*                    \___________________/                       \_________/ */
 /*                     ___________________                         _________  */
 /*                    /                   \                       /         \ */
 
 struct xseg_request *  xseg_accept          ( struct xseg         * xseg,
-                                              xport                 portno    );
+                                              xport                 portno,    
+                                             uint32_t              flags     );
 
               xport    xseg_respond         ( struct xseg         * xseg,
                                               struct xseg_request * xreq,
@@ -383,6 +390,14 @@ static inline char* xseg_get_data(struct xseg* xseg, struct xseg_request *req)
        return (char *) XPTR_TAKE(req->data, xseg->segment);
 }
 
+static inline void * xseg_get_signal_desc(struct xseg *xseg, struct xseg_port *port)
+{
+       return (void *) XPTR_TAKE(port->signal_desc, xseg->segment);
+}
+
+struct xobject_h * xseg_get_objh(struct xseg *xseg, uint32_t magic, uint64_t size);
+void xseg_put_objh(struct xseg *xseg, struct xobject_h *objh);
+
 #define xseg_get_queue(__xseg, __port, __queue) \
        ((struct xq *) XPTR_TAKE(__port->__queue, __xseg->segment))