xref: /netbsd-src/sys/arch/xen/include/xenring.h (revision f183eaeed00232c8d8b44a8611d174d9ff1b475b)
1*f183eaeeSriastradh /* $NetBSD: xenring.h,v 1.8 2024/07/16 22:44:38 riastradh Exp $ */
2ac8432e2Scherry 
3ac8432e2Scherry /*
4ac8432e2Scherry  * Glue goop for xbd ring request/response protocol structures.
5ac8432e2Scherry  *
6ac8432e2Scherry  * These are used only from __XEN_INTERFACE_VERSION__ >= 0x00030201
7ac8432e2Scherry  * prior to which they were part of the public XEN api.
8ac8432e2Scherry  */
9ac8432e2Scherry 
10ac8432e2Scherry #ifndef _XEN_RING_H
11ac8432e2Scherry #define _XEN_RING_H
12ac8432e2Scherry 
13dc18d749Scherry #if (__XEN_INTERFACE_VERSION__ >= 0x00030201) && \
148ea97067Scherry 	(__XEN_INTERFACE_VERSION < 0x00030208)
15ac8432e2Scherry 
16ac8432e2Scherry #include <xen/include/public/io/ring.h>
17ac8432e2Scherry 
188ea97067Scherry /*
198ea97067Scherry  * Undo namespace damage from xen/include/public/io/ring.h
208ea97067Scherry  * The proper fix is to get upstream to stop assuming that all OSs use
218ea97067Scherry  * mb(), rmb(), wmb().
228ea97067Scherry  */
238ea97067Scherry #undef xen_mb
248ea97067Scherry #undef xen_rmb
258ea97067Scherry #undef xen_wmb
268ea97067Scherry 
27*f183eaeeSriastradh void xen_mb(void);
28805a95beSriastradh #define xen_rmb() membar_acquire()
29805a95beSriastradh #define xen_wmb() membar_release()
308ea97067Scherry 
318ea97067Scherry /*
328ea97067Scherry  * Define ring types. These were previously part of the public API.
338ea97067Scherry  * Not anymore.
348ea97067Scherry  */
3549e671dcSbouyer /* i386 requests/responses */
3649e671dcSbouyer struct blkif_x86_32_request {
3749e671dcSbouyer     uint8_t        operation;    /* BLKIF_OP_???                         */
3849e671dcSbouyer     uint8_t        nr_segments;  /* number of segments                   */
3949e671dcSbouyer     blkif_vdev_t   handle;       /* only for read/write requests         */
4049e671dcSbouyer     uint64_t       id;           /* private guest value, echoed in resp  */
4149e671dcSbouyer     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
4249e671dcSbouyer     struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
4349e671dcSbouyer } __packed;
4449e671dcSbouyer typedef struct blkif_x86_32_request blkif_x86_32_request_t;
45ac8432e2Scherry 
4649e671dcSbouyer struct blkif_x86_32_response {
4749e671dcSbouyer     uint64_t        id;              /* copied from request */
4849e671dcSbouyer     uint8_t         operation;       /* copied from request */
4949e671dcSbouyer     uint8_t         _pad;
5049e671dcSbouyer     int16_t         status;          /* BLKIF_RSP_???       */
5149e671dcSbouyer } __packed;
5249e671dcSbouyer typedef struct blkif_x86_32_response blkif_x86_32_response_t;
53ac8432e2Scherry 
54e82ca0a1Sjdolecek struct blkif_x86_32_request_indirect {
55e82ca0a1Sjdolecek     uint8_t        operation;    /* BLKIF_OP_INDIRECT                    */
56e82ca0a1Sjdolecek     uint8_t        indirect_op;  /* BLKIF_OP_{READ/WRITE}                */
57e82ca0a1Sjdolecek     uint16_t       nr_segments;  /* number of segments                   */
58e82ca0a1Sjdolecek     uint64_t       id;		 /* private guest value, echoed in resp  */
59e82ca0a1Sjdolecek     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
60e82ca0a1Sjdolecek     blkif_vdev_t   handle;       /* only for read/write requests         */
61e82ca0a1Sjdolecek     uint16_t	   _pad2;
62e82ca0a1Sjdolecek     grant_ref_t    indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
63e82ca0a1Sjdolecek     uint64_t       _pad3;	 /* make it 64 byte aligned */
64e82ca0a1Sjdolecek } __packed;
65e82ca0a1Sjdolecek typedef struct blkif_x86_32_request_indirect blkif_x86_32_request_indirect_t;
66e82ca0a1Sjdolecek 
6749e671dcSbouyer /* amd64-type requests/responses (always used in frontends ) */
6849e671dcSbouyer 
6949e671dcSbouyer struct blkif_x86_64_request {
7049e671dcSbouyer     uint8_t        operation;    /* BLKIF_OP_???                         */
7149e671dcSbouyer     uint8_t        nr_segments;  /* number of segments                   */
7249e671dcSbouyer     blkif_vdev_t   handle;       /* only for read/write requests         */
7349e671dcSbouyer     uint64_t __attribute__((__aligned__(8))) id;/* private guest value, echoed in resp  */
7449e671dcSbouyer     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
7549e671dcSbouyer     struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
7649e671dcSbouyer };
7749e671dcSbouyer typedef struct blkif_x86_64_request blkif_x86_64_request_t;
7849e671dcSbouyer 
7949e671dcSbouyer struct blkif_x86_64_response {
8049e671dcSbouyer     uint64_t __attribute__((__aligned__(8))) id; /* copied from request */
8149e671dcSbouyer     uint8_t         operation;       /* copied from request */
8249e671dcSbouyer     int16_t         status;          /* BLKIF_RSP_???       */
8349e671dcSbouyer };
8449e671dcSbouyer typedef struct blkif_x86_64_response blkif_x86_64_response_t;
8549e671dcSbouyer 
86e82ca0a1Sjdolecek struct blkif_x86_64_request_indirect {
87e82ca0a1Sjdolecek     uint8_t        operation;    /* BLKIF_OP_INDIRECT                    */
88e82ca0a1Sjdolecek     uint8_t        indirect_op;  /* BLKIF_OP_{READ/WRITE}                */
89e82ca0a1Sjdolecek     uint16_t       nr_segments;  /* number of segments                   */
90e82ca0a1Sjdolecek     uint32_t       _pad1;
91e82ca0a1Sjdolecek     uint64_t       id;           /* private guest value, echoed in resp  */
92e82ca0a1Sjdolecek     blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
93e82ca0a1Sjdolecek     blkif_vdev_t   handle;       /* only for read/write requests         */
94e82ca0a1Sjdolecek     uint16_t	   _pad2;
95e82ca0a1Sjdolecek     grant_ref_t    indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
96e82ca0a1Sjdolecek     uint32_t       _pad3;	 /* make it 64 byte aligned */
97e82ca0a1Sjdolecek } __packed;
98e82ca0a1Sjdolecek typedef struct blkif_x86_64_request_indirect blkif_x86_64_request_indirect_t;
99e82ca0a1Sjdolecek 
100e82ca0a1Sjdolecek CTASSERT(sizeof(struct blkif_x86_32_request_indirect)
101e82ca0a1Sjdolecek 	== sizeof(struct blkif_x86_64_request_indirect));
102e82ca0a1Sjdolecek CTASSERT(sizeof(struct blkif_request_indirect)
103e82ca0a1Sjdolecek 	== sizeof(struct blkif_x86_64_request_indirect));
104e82ca0a1Sjdolecek 
10549e671dcSbouyer DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request, struct blkif_x86_32_response);
10649e671dcSbouyer DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request, struct blkif_x86_64_response);
107ac8432e2Scherry 
108ac8432e2Scherry union blkif_back_ring_proto {
109ac8432e2Scherry 	blkif_back_ring_t ring_n; /* native/common members */
110ac8432e2Scherry 	blkif_x86_32_back_ring_t ring_32;
111ac8432e2Scherry 	blkif_x86_64_back_ring_t ring_64;
112ac8432e2Scherry };
113ac8432e2Scherry typedef union blkif_back_ring_proto blkif_back_ring_proto_t;
114ac8432e2Scherry 
1158ea97067Scherry #endif /* __XEN_INTERFACE_VERSION__ */
1168ea97067Scherry 
117ac8432e2Scherry #endif /* _XEN_RING_H_ */
118