commit e0f9912933cbdeec9b7c5e448902ec916dc93a9a Author: Alexander Larsson Date: Thu Feb 4 16:18:44 2010 +0100 Import all protocol headers from spice/common diff --git a/spice/draw.h b/spice/draw.h new file mode 100644 index 0000000..e277b2d --- /dev/null +++ b/spice/draw.h @@ -0,0 +1,406 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _H_DRAW +#define _H_DRAW + +#ifndef _WIN32 +#include +#endif + +#ifdef __GNUC__ +#define ATTR_PACKED __attribute__ ((__packed__)) +typedef uint64_t UINT64; +typedef uint32_t UINT32; +typedef uint16_t UINT16; +typedef uint8_t UINT8; + +typedef int16_t INT16; +typedef int32_t INT32; +#else +#include +#pragma pack(push) +#pragma pack(1) +#define ATTR_PACKED +#pragma warning(disable:4200) +#endif + +#ifdef _WIN32_WCE +#include +typedef uint64_t UINT64; +typedef uint32_t UINT32; +typedef uint16_t UINT16; +typedef uint8_t UINT8; + +typedef int16_t INT16; +typedef int32_t INT32; +#endif + +#define GET_ADDRESS(addr) ((void *)(unsigned long)(addr)) +#define SET_ADDRESS(addr, val) ((addr) = (unsigned long)(val)) + +typedef INT32 FIXED28_4; +typedef UINT64 ADDRESS; + +enum { + PATH_BEGIN = (1 << 0), + PATH_END = (1 << 1), + PATH_CLOSE = (1 << 3), + PATH_BEZIER = (1 << 4), +}; + +enum { + LINE_ATTR_STARTGAP = (1 << 2), + LINE_ATTR_STYLED = (1 << 3), +}; + +typedef struct ATTR_PACKED PointFix { + FIXED28_4 x; + FIXED28_4 y; +} PointFix; + +typedef struct ATTR_PACKED Point { + INT32 x; + INT32 y; +} Point; + +typedef struct ATTR_PACKED Point16 { + INT16 x; + INT16 y; +} Point16; + +typedef struct ATTR_PACKED Rect { + INT32 top; + INT32 left; + INT32 bottom; + INT32 right; +} Rect; + +typedef struct ATTR_PACKED PathSeg { + UINT32 flags; + UINT32 count; + UINT8 data[0]; +} PathSeg; + +enum ClipType { + CLIP_TYPE_NONE, + CLIP_TYPE_RECTS, + CLIP_TYPE_PATH, +}; + +typedef struct ATTR_PACKED Clip { + UINT32 type; + ADDRESS data; +} Clip; + +enum ROPDescriptor { + ROPD_INVERS_SRC = (1 << 0), + ROPD_INVERS_BRUSH = (1 << 1), + ROPD_INVERS_DEST = (1 << 2), + ROPD_OP_PUT = (1 << 3), + ROPD_OP_OR = (1 << 4), + ROPD_OP_AND = (1 << 5), + ROPD_OP_XOR = (1 << 6), + ROPD_OP_BLACKNESS = (1 << 7), + ROPD_OP_WHITENESS = (1 << 8), + ROPD_OP_INVERS = (1 << 9), + ROPD_INVERS_RES = (1 << 10), +}; + +typedef struct ATTR_PACKED Pattern { + ADDRESS pat; + Point pos; +} Pattern; + +enum { + BRUSH_TYPE_NONE, + BRUSH_TYPE_SOLID, + BRUSH_TYPE_PATTERN, +}; + +typedef struct ATTR_PACKED Brush { + UINT32 type; + union { + UINT32 color; + Pattern pattern; + } u; +} Brush; + +enum { + MASK_INVERS = (1 << 0), +}; + +typedef struct ATTR_PACKED QMask { + UINT8 flags; + Point pos; + ADDRESS bitmap; +} QMask; + +typedef struct ATTR_PACKED Fill { + Brush brush; + UINT16 rop_decriptor; + QMask mask; +} Fill; + +typedef struct ATTR_PACKED Palette { + UINT64 unique; + UINT16 num_ents; + UINT32 ents[0]; +} Palette; + +enum { + IMAGE_TYPE_BITMAP, + IMAGE_TYPE_QUIC, + IMAGE_TYPE_RESERVED, + IMAGE_TYPE_LZ_PLT = 100, + IMAGE_TYPE_LZ_RGB, + IMAGE_TYPE_GLZ_RGB, + IMAGE_TYPE_FROM_CACHE, +}; + +enum { + IMAGE_CACHE_ME = (1 << 0), +}; + +typedef struct ATTR_PACKED ImageDescriptor { + UINT64 id; + UINT8 type; + UINT8 flags; + UINT32 width; + UINT32 height; +} ImageDescriptor; + +enum { + BITMAP_FMT_INVALID, + BITMAP_FMT_1BIT_LE, + BITMAP_FMT_1BIT_BE, + BITMAP_FMT_4BIT_LE, + BITMAP_FMT_4BIT_BE, + BITMAP_FMT_8BIT, + BITMAP_FMT_16BIT, + BITMAP_FMT_24BIT, + BITMAP_FMT_32BIT, + BITMAP_FMT_RGBA, +}; + +enum { + BITMAP_PAL_CACHE_ME = (1 << 0), + BITMAP_PAL_FROM_CACHE = (1 << 1), + BITMAP_TOP_DOWN = (1 << 2), +}; + +typedef struct ATTR_PACKED Bitmap { + UINT8 format; + UINT8 flags; + UINT32 x; + UINT32 y; + UINT32 stride; + ADDRESS palette; + ADDRESS data; //data[0] ? +} Bitmap; + +typedef struct ATTR_PACKED BitmapImage { + ImageDescriptor descriptor; + Bitmap bitmap; +} BitmapImage; + +typedef struct ATTR_PACKED QUICData { + UINT32 data_size; + UINT8 data[0]; +} QUICData, LZ_RGBData; + +typedef struct ATTR_PACKED QUICImage { + ImageDescriptor descriptor; + QUICData quic; +} QUICImage; + +typedef struct ATTR_PACKED LZ_RGBImage { + ImageDescriptor descriptor; + LZ_RGBData lz_rgb; +} LZ_RGBImage; + +typedef struct ATTR_PACKED LZ_PLTData { + UINT8 flags; + UINT32 data_size; + ADDRESS palette; + UINT8 data[0]; +} LZ_PLTData; + +typedef struct ATTR_PACKED LZ_PLTImage { + ImageDescriptor descriptor; + LZ_PLTData lz_plt; +} LZ_PLTImage; + +enum { + IMAGE_SCALE_INTERPOLATE, + IMAGE_SCALE_NEAREST, +}; + +typedef struct ATTR_PACKED Opaque { + ADDRESS src_bitmap; + Rect src_area; + Brush brush; + UINT16 rop_decriptor; + UINT8 scale_mode; + QMask mask; +} Opaque; + +typedef struct ATTR_PACKED Copy { + ADDRESS src_bitmap; + Rect src_area; + UINT16 rop_decriptor; + UINT8 scale_mode; + QMask mask; +} Copy, Blend; + +typedef struct ATTR_PACKED Transparent { + ADDRESS src_bitmap; + Rect src_area; + UINT32 src_color; + UINT32 true_color; +} Transparent; + +typedef struct ATTR_PACKED AlphaBlnd { + UINT8 alpha; + ADDRESS src_bitmap; + Rect src_area; +} AlphaBlnd; + +typedef struct ATTR_PACKED Rop3 { + ADDRESS src_bitmap; + Rect src_area; + Brush brush; + UINT8 rop3; + UINT8 scale_mode; + QMask mask; +} Rop3; + +typedef struct ATTR_PACKED Blackness { + QMask mask; +} Blackness, Invers, Whiteness; + +enum { + LINE_STYLED = (1 << 3), + LINE_START_WITH_GAP = (1 << 2), +}; + +enum { + LINE_CAP_ROUND, + LINE_CAP_SQUARE, + LINE_CAP_BUTT, +}; + +enum { + LINE_JOIN_ROUND, + LINE_JOIN_BEVEL, + LINE_JOIN_MITER, +}; + +typedef struct ATTR_PACKED LineAttr { + UINT8 flags; + UINT8 join_style; + UINT8 end_style; + UINT8 style_nseg; + FIXED28_4 width; + FIXED28_4 miter_limit; + ADDRESS style; //data[0] ? +} LineAttr; + +typedef struct ATTR_PACKED Stroke { + ADDRESS path; + LineAttr attr; + Brush brush; + UINT16 fore_mode; + UINT16 back_mode; +} Stroke; + +typedef struct ATTR_PACKED RasterGlyph { + Point render_pos; + Point glyph_origin; + UINT16 width; + UINT16 height; + UINT8 data[0]; +} RasterGlyph; + +typedef struct ATTR_PACKED VectotGlyph { + Point render_pos; + UINT32 data_size; + UINT8 data[0]; //PathSeg[] +} VectotGlyph; + +enum { + STRING_RASTER_A1 = 1 << 0, + STRING_RASTER_A4 = 1 << 1, + STRING_RASTER_A8 = 1 << 2, + STRING_RASTER_TOP_DOWN = 1 << 3, +}; + +typedef struct ATTR_PACKED String { + UINT16 length; + UINT16 flags; + UINT8 data[0]; +} String; + +typedef struct ATTR_PACKED Text { + ADDRESS str; + Rect back_area; + Brush fore_brush; + Brush back_brush; + UINT16 fore_mode; + UINT16 back_mode; +} Text; + +enum { + CURSOR_TYPE_ALPHA, + CURSOR_TYPE_MONO, + CURSOR_TYPE_COLOR4, + CURSOR_TYPE_COLOR8, + CURSOR_TYPE_COLOR16, + CURSOR_TYPE_COLOR24, + CURSOR_TYPE_COLOR32, +}; + +typedef struct ATTR_PACKED CursorHeader { + UINT64 unique; + UINT16 type; + UINT16 width; + UINT16 height; + UINT16 hot_spot_x; + UINT16 hot_spot_y; +} CursorHeader; + + +#ifndef __GNUC__ +#pragma pack(pop) +#endif + +#undef ATTR_PACKED + +#endif diff --git a/spice/ipc_ring.h b/spice/ipc_ring.h new file mode 100644 index 0000000..1d9b3e1 --- /dev/null +++ b/spice/ipc_ring.h @@ -0,0 +1,135 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _H_RING_ +#define _H_RING_ + + +#define MSB_MASK4(x) \ + (((x) & 0x8) ? 0x8 : \ + ((x) & 0x4) ? 0x4 : \ + ((x) & 0x2) ? 0x2 : \ + ((x) & 0x1) ? 0x1 : 0) + +#define MSB_MASK8(x) \ + (((x) & 0xf0) ? MSB_MASK4((x) >> 4) << 4 : MSB_MASK4(x)) + +#define MSB_MASK16(x) \ + (((x) & 0xff00) ? MSB_MASK8((x) >> 8) << 8 : MSB_MASK8(x)) + +#define MSB_MASK(x) \ + (((x) & 0xffff0000) ? MSB_MASK16((x) >> 16) << 16 : MSB_MASK16(x)) + +#define POWER2_ALIGN(x) MSB_MASK((x) * 2 - 1) + + +#define _TOSHIFT_4(x) \ + (((x) & 0x8) ? 3 : \ + ((x) & 0x4) ? 2 : \ + ((x) & 0x2) ? 1 : 0) + +#define _TOSHIFT_8(x) \ + (((x) & 0xf0) ? _TOSHIFT_4((x) >> 4) + 4 : _TOSHIFT_4(x)) + +#define _TOSHIFT_16(x) \ + (((x) & 0xff00) ? _TOSHIFT_8((x) >> 8) + 8 : _TOSHIFT_8(x)) + +#define PAWER2_TO_SHIFT(x) \ + (((x) & 0xffff0000) ? _TOSHIFT_16((x) >> 16) + 16 : _TOSHIFT_16(x)) + + + +#define RING_DECLARE(name, el_type, size) \ +typedef struct ATTR_PACKED name##_ring_el { \ + union { \ + el_type el; \ + UINT8 data[POWER2_ALIGN(sizeof(el_type))]; \ + } ; \ +} name##_ring_el; \ + \ +typedef struct ATTR_PACKED name { \ + UINT32 num_items; \ + UINT32 prod; \ + UINT32 notify_on_prod; \ + UINT32 cons; \ + UINT32 notify_on_cons; \ + name##_ring_el items[POWER2_ALIGN(size)]; \ +} name; + + +#define RING_INIT(r) \ + (r)->num_items = sizeof((r)->items) >> \ + PAWER2_TO_SHIFT(sizeof((r)->items[0])); \ + (r)->prod = (r)->cons = 0; \ + (r)->notify_on_prod = 1; \ + (r)->notify_on_cons = 0; + + +#define RING_INDEX_MASK(r) ((r)->num_items - 1) + +#define RING_IS_PACKED(r) (sizeof((r)->items[0]) == sizeof((r)->items[0]).el) + +#define RING_IS_EMPTY(r) ((r)->cons == (r)->prod) + +#define RING_IS_FULL(r) (((r)->prod - (r)->cons) == (r)->num_items) + +#define RING_PROD_ITEM(r) (&(r)->items[(r)->prod & RING_INDEX_MASK(r)].el) + +#define RING_PROD_WAIT(r, wait) \ + if (((wait) = RING_IS_FULL(r))) { \ + (r)->notify_on_cons = (r)->cons + 1; \ + mb(); \ + (wait) = RING_IS_FULL(r); \ + } + +#define RING_PUSH(r, notify) \ + (r)->prod++; \ + mb(); \ + (notify) = (r)->prod == (r)->notify_on_prod; + + +#define RING_CONS_ITEM(r) (&(r)->items[(r)->cons & RING_INDEX_MASK(r)].el) + +#define RING_CONS_WAIT(r, wait) \ + if (((wait) = RING_IS_EMPTY(r))) { \ + (r)->notify_on_prod = (r)->prod + 1; \ + mb(); \ + (wait) = RING_IS_EMPTY(r); \ + } + +#define RING_POP(r, notify) \ + (r)->cons++; \ + mb(); \ + (notify) = (r)->cons == (r)->notify_on_cons; + + + +#endif diff --git a/spice/qxl_dev.h b/spice/qxl_dev.h new file mode 100644 index 0000000..048315d --- /dev/null +++ b/spice/qxl_dev.h @@ -0,0 +1,372 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _H_QXL_DEV +#define _H_QXL_DEV + +#include "ipc_ring.h" +#include "draw.h" + +#ifdef __GNUC__ +#ifdef __i386__ +#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") +#else +//mfence +#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%rsp)": : :"memory") +#endif +#define ATTR_PACKED __attribute__ ((__packed__)) +#else +#pragma pack(push) +#pragma pack(1) +#define ATTR_PACKED +#define mb() __asm {lock add [esp], 0} +#endif + +#define REDHAT_PCI_VENDOR_ID 0x1b36 +#define QXL_DEVICE_ID 0x0100 /* 0x100-0x11f reserved for spice */ +#define QXL_REVISION 0x03 + +#define QXL_ROM_MAGIC (*(UINT32*)"QXRO") +#define QXL_RAM_MAGIC (*(UINT32*)"QXRA") + +enum { + QXL_RAM_RANGE_INDEX, + QXL_VRAM_RANGE_INDEX, + QXL_ROM_RANGE_INDEX, + QXL_IO_RANGE_INDEX, + + QXL_PCI_RANGES +}; + +enum { + QXL_IO_NOTIFY_CMD, + QXL_IO_NOTIFY_CURSOR, + QXL_IO_UPDATE_AREA, + QXL_IO_UPDATE_IRQ, + QXL_IO_NOTIFY_OOM, + QXL_IO_RESET, + QXL_IO_LOG, + QXL_IO_MEMSLOT_ADD, + QXL_IO_MEMSLOT_DEL, + QXL_IO_DETACH_PRIMARY, + QXL_IO_ATTACH_PRIMARY, + QXL_IO_CREATE_PRIMARY, + QXL_IO_DESTROY_PRIMARY, + QXL_IO_DESTROY_SURFACE_WAIT, + + QXL_IO_RANGE_SIZE +}; + +typedef struct ATTR_PACKED QXLRom { + UINT32 magic; + UINT32 id; + UINT32 update_id; + UINT32 compression_level; + UINT32 log_level; + UINT32 modes_offset; + UINT32 num_pages; + UINT32 surface0_area_size; + UINT32 ram_header_offset; + UINT32 mm_clock; + UINT64 flags; + UINT8 slots_start; + UINT8 slots_end; + UINT8 slot_gen_bits; + UINT8 slot_id_bits; + UINT8 slot_generation; +} QXLRom; + +typedef struct ATTR_PACKED QXLMode { + UINT32 id; + UINT32 x_res; + UINT32 y_res; + UINT32 bits; + UINT32 stride; + UINT32 x_mili; + UINT32 y_mili; + UINT32 orientation; +} QXLMode; + +typedef struct ATTR_PACKED QXLModes { + UINT32 n_modes; + QXLMode modes[0]; +} QXLModes; + +typedef UINT64 PHYSICAL; +typedef UINT32 QXLFIXED; //fixed 28.4 + +enum QXLCmdType { + QXL_CMD_NOP, + QXL_CMD_DRAW, + QXL_CMD_UPDATE, + QXL_CMD_CURSOR, + QXL_CMD_MESSAGE, +}; + +typedef struct ATTR_PACKED QXLCommand { + PHYSICAL data; + UINT32 type; + UINT32 ped; +} QXLCommand; + +typedef struct ATTR_PACKED QXLCommandExt { + QXLCommand cmd; + UINT32 group_id; +} QXLCommandExt; + +typedef struct ATTR_PACKED QXLMemSlot { + UINT64 mem_start; + UINT64 mem_end; +} QXLMemSlot; + +#define QXL_SURF_TYPE_PRIMARY 0 + +typedef struct ATTR_PACKED QXLSurfaceCreate { + UINT32 width; + UINT32 height; + INT32 stride; + UINT32 depth; + UINT32 position; + UINT32 mouse_mode; + UINT32 flags; + UINT32 type; + PHYSICAL mem; +} QXLSurfaceCreate; + +RING_DECLARE(QXLCommandRing, QXLCommand, 32); +RING_DECLARE(QXLCursorRing, QXLCommand, 32); + +RING_DECLARE(QXLReleaseRing, UINT64, 8); + +#define QXL_LOG_BUF_SIZE 4096 + +#define QXL_INTERRUPT_DISPLAY (1 << 0) +#define QXL_INTERRUPT_CURSOR (1 << 1) + +typedef struct ATTR_PACKED QXLRam { + UINT32 magic; + UINT32 int_pending; + UINT32 int_mask; + UINT8 log_buf[QXL_LOG_BUF_SIZE]; + QXLCommandRing cmd_ring; + QXLCursorRing cursor_ring; + QXLReleaseRing release_ring; + Rect update_area; + QXLMemSlot mem_slot; + QXLSurfaceCreate create_surface; + UINT64 flags; +} QXLRam; + +typedef union QXLReleaseInfo { + UINT64 id; // in + UINT64 next; // out +} QXLReleaseInfo; + +typedef struct QXLReleaseInfoExt { + QXLReleaseInfo *info; + UINT32 group_id; +} QXLReleaseInfoExt; + +typedef struct ATTR_PACKED QXLDataChunk { + UINT32 data_size; + PHYSICAL prev_chunk; + PHYSICAL next_chunk; + UINT8 data[0]; +} QXLDataChunk; + +typedef struct ATTR_PACKED QXLMessage { + QXLReleaseInfo release_info; + UINT8 data[0]; +} QXLMessage; + +typedef struct ATTR_PACKED QXLUpdateCmd { + QXLReleaseInfo release_info; + Rect area; + UINT32 update_id; +} QXLUpdateCmd; + +typedef struct ATTR_PACKED QXLCursor { + CursorHeader header; + UINT32 data_size; + QXLDataChunk chunk; +} QXLCursor; + +enum { + QXL_CURSOR_SET, + QXL_CURSOR_MOVE, + QXL_CURSOR_HIDE, + QXL_CURSOR_TRAIL, +}; + +#define QXL_CURSUR_DEVICE_DATA_SIZE 128 + +typedef struct ATTR_PACKED QXLCursorCmd { + QXLReleaseInfo release_info; + UINT8 type; + union { + struct ATTR_PACKED { + Point16 position; + UINT8 visible; + PHYSICAL shape; + } set; + struct ATTR_PACKED { + UINT16 length; + UINT16 frequency; + } trail; + Point16 position; + } u; + UINT8 device_data[QXL_CURSUR_DEVICE_DATA_SIZE]; //todo: dynamic size from rom +} QXLCursorCmd; + +enum { + QXL_DRAW_NOP, + QXL_DRAW_FILL, + QXL_DRAW_OPAQUE, + QXL_DRAW_COPY, + QXL_COPY_BITS, + QXL_DRAW_BLEND, + QXL_DRAW_BLACKNESS, + QXL_DRAW_WHITENESS, + QXL_DRAW_INVERS, + QXL_DRAW_ROP3, + QXL_DRAW_STROKE, + QXL_DRAW_TEXT, + QXL_DRAW_TRANSPARENT, + QXL_DRAW_ALPHA_BLEND, +}; + +typedef struct ATTR_PACKED QXLString { + UINT32 data_size; + UINT16 length; + UINT16 flags; + QXLDataChunk chunk; +} QXLString; + +typedef struct ATTR_PACKED QXLCopyBits { + Point src_pos; +} QXLCopyBits; + +#define QXL_EFFECT_BLEND 0 +#define QXL_EFFECT_OPAQUE 1 +#define QXL_EFFECT_REVERT_ON_DUP 2 +#define QXL_EFFECT_BLACKNESS_ON_DUP 3 +#define QXL_EFFECT_WHITENESS_ON_DUP 4 +#define QXL_EFFECT_NOP_ON_DUP 5 +#define QXL_EFFECT_NOP 6 +#define QXL_EFFECT_OPAQUE_BRUSH 7 + +typedef struct ATTR_PACKED QXLDrawable { + QXLReleaseInfo release_info; + UINT8 effect; + UINT8 type; + UINT8 self_bitmap; + Rect self_bitmap_area; + Rect bbox; + Clip clip; + UINT32 mm_time; + union { + Fill fill; + Opaque opaque; + Copy copy; + Transparent transparent; + AlphaBlnd alpha_blend; + QXLCopyBits copy_bits; + Blend blend; + Rop3 rop3; + Stroke stroke; + Text text; + Blackness blackness; + Invers invers; + Whiteness whiteness; + } u; +} QXLDrawable; + +typedef struct ATTR_PACKED QXLClipRects { + UINT32 num_rects; + QXLDataChunk chunk; +} QXLClipRects; + +enum { + QXL_PATH_BEGIN = (1 << 0), + QXL_PATH_END = (1 << 1), + QXL_PATH_CLOSE = (1 << 3), + QXL_PATH_BEZIER = (1 << 4), +}; + +typedef struct ATTR_PACKED QXLPath { + UINT32 data_size; + QXLDataChunk chunk; +} QXLPath; + +enum { + QXL_IMAGE_GROUP_DRIVER, + QXL_IMAGE_GROUP_DEVICE, + QXL_IMAGE_GROUP_RED, + QXL_IMAGE_GROUP_DRIVER_DONT_CACHE, +}; + +typedef struct ATTR_PACKED QXLImageID { + UINT32 group; + UINT32 unique; +} QXLImageID; + +enum { + QXL_IMAGE_CACHE = (1 << 0), +}; + +enum { + QXL_BITMAP_DIRECT = (1 << 0), + QXL_BITMAP_UNSTABLE = (1 << 1), + QXL_BITMAP_TOP_DOWN = (1 << 2), // == BITMAP_TOP_DOWN +}; + +#define QXL_SET_IMAGE_ID(image, _group, _unique) { \ + UINT64* id_ptr = &(image)->descriptor.id; \ + QXLImageID *image_id = (QXLImageID *)id_ptr; \ + image_id->group = _group; \ + image_id->unique = _unique; \ +} + +typedef struct ATTR_PACKED QXLImage { + ImageDescriptor descriptor; + union { // variable length + Bitmap bitmap; + QUICData quic; + }; +} QXLImage; + +#ifndef __GNUC__ +#pragma pack(pop) +#endif + +#undef ATTR_PACKED + +#endif diff --git a/spice/red.h b/spice/red.h new file mode 100644 index 0000000..22c0ec6 --- /dev/null +++ b/spice/red.h @@ -0,0 +1,840 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _H_RED +#define _H_RED + +#include +#ifdef _WIN32 +#include +#endif +#include "draw.h" +#ifdef __GNUC__ +#define ATTR_PACKED __attribute__ ((__packed__)) +#else +#pragma pack(push) +#pragma pack(1) +#define ATTR_PACKED +#endif + +#define RED_MAGIC (*(uint32_t*)"REDQ") +#define RED_VERSION_MAJOR (~(uint32_t)0 - 1) +#define RED_VERSION_MINOR 2 + +// Encryption & Ticketing Parameters +#define RED_MAX_PASSWORD_LENGTH 60 +#define RED_TICKET_KEY_PAIR_LENGTH 1024 +#define RED_TICKET_PUBKEY_BYTES (RED_TICKET_KEY_PAIR_LENGTH / 8 + 34) + +enum { + RED_CHANNEL_MAIN = 1, + RED_CHANNEL_DISPLAY, + RED_CHANNEL_INPUTS, + RED_CHANNEL_CURSOR, + RED_CHANNEL_PLAYBACK, + RED_CHANNEL_RECORD, + RED_CHANNEL_TUNNEL, + + RED_CHANNEL_END +}; + +enum { + RED_ERR_OK, + RED_ERR_ERROR, + RED_ERR_INVALID_MAGIC, + RED_ERR_INVALID_DATA, + RED_ERR_VERSION_MISMATCH, + RED_ERR_NEED_SECURED, + RED_ERR_NEED_UNSECURED, + RED_ERR_PERMISSION_DENIED, + RED_ERR_BAD_CONNECTION_ID, + RED_ERR_CHANNEL_NOT_AVAILABLE, +}; + +enum { + RED_WARN_GENERAL, +}; + +enum { + RED_INFO_GENERAL, +}; + +typedef struct ATTR_PACKED RedLinkHeader { + uint32_t magic; + uint32_t major_version; + uint32_t minor_version; + uint32_t size; +} RedLinkHeader; + +typedef struct ATTR_PACKED RedLinkMess { + uint32_t connection_id; + uint8_t channel_type; + uint8_t channel_id; + uint32_t num_common_caps; + uint32_t num_channel_caps; + uint32_t caps_offset; +} RedLinkMess; + +typedef struct ATTR_PACKED RedLinkReply { + uint32_t error; + uint8_t pub_key[RED_TICKET_PUBKEY_BYTES]; + uint32_t num_common_caps; + uint32_t num_channel_caps; + uint32_t caps_offset; +} RedLinkReply; + +typedef struct ATTR_PACKED RedLinkEncryptedTicket { + uint8_t encrypted_data[RED_TICKET_KEY_PAIR_LENGTH / 8]; +} RedLinkEncryptedTicket; + +typedef struct ATTR_PACKED RedDataHeader { + uint64_t serial; + uint16_t type; + uint32_t size; + uint32_t sub_list; //offset to RedSubMessageList[] +} RedDataHeader; + +typedef struct ATTR_PACKED RedSubMessage { + uint16_t type; + uint32_t size; +} RedSubMessage; + +typedef struct ATTR_PACKED RedSubMessageList { + uint16_t size; + uint32_t sub_messages[0]; //offsets to RedSubMessage +} RedSubMessageList; + +enum { + RED_MIGRATE = 1, + RED_MIGRATE_DATA, + RED_SET_ACK, + RED_PING, + RED_WAIT_FOR_CHANNELS, + RED_DISCONNECTING, + RED_NOTIFY, + + RED_FIRST_AVAIL_MESSAGE = 101 +}; + +enum { + REDC_ACK_SYNC = 1, + REDC_ACK, + REDC_PONG, + REDC_MIGRATE_FLUSH_MARK, + REDC_MIGRATE_DATA, + REDC_DISCONNECTING, + + REDC_FIRST_AVAIL_MESSAGE = 101, +}; + +enum { + RED_MIGRATE_BEGIN = RED_FIRST_AVAIL_MESSAGE, + RED_MIGRATE_CANCEL, + RED_INIT, + RED_CHANNELS_LIST, + RED_MOUSE_MODE, + RED_MULTI_MEDIA_TIME, + + RED_AGENT_CONNECTED, + RED_AGENT_DISCONNECTED, + RED_AGENT_DATA, + RED_AGENT_TOKEN, + + RED_MESSAGES_END, +}; + +enum { + REDC_CLIENT_INFO = REDC_FIRST_AVAIL_MESSAGE, + REDC_MIGRATE_CONNECTED, + REDC_MIGRATE_CONNECT_ERROR, + REDC_ATTACH_CHANNELS, + REDC_MOUSE_MODE_REQUEST, + + REDC_AGENT_START, + REDC_AGENT_DATA, + REDC_AGENT_TOKEN, +}; + +#define RED_MOTION_ACK_BUNCH 4 + +enum { + RED_INPUTS_INIT = RED_FIRST_AVAIL_MESSAGE, + RED_INPUTS_KEY_MODIFAIERS, + + RED_INPUTS_MOUSE_MOTION_ACK = RED_FIRST_AVAIL_MESSAGE + 10, + + RED_INPUTS_MESSAGES_END, +}; + +#define RED_SCROLL_LOCK_MODIFIER (1 << 0) +#define RED_NUM_LOCK_MODIFIER (1 << 1) +#define RED_CAPS_LOCK_MODIFIER (1 << 2) + +typedef struct ATTR_PACKED RedInputsInit { + uint32_t keyboard_modifiers; +} RedInputsInit; + +typedef struct ATTR_PACKED RedKeyModifiers { + uint32_t modifiers; +} RedKeyModifiers; + +typedef struct ATTR_PACKED RedMultiMediaTime { + uint32_t time; +} RedMultiMediaTime; + +enum { + RED_PUBKEY_TYPE_INVALID, + RED_PUBKEY_TYPE_RSA, + RED_PUBKEY_TYPE_RSA2, + RED_PUBKEY_TYPE_DSA, + RED_PUBKEY_TYPE_DSA1, + RED_PUBKEY_TYPE_DSA2, + RED_PUBKEY_TYPE_DSA3, + RED_PUBKEY_TYPE_DSA4, + RED_PUBKEY_TYPE_DH, + RED_PUBKEY_TYPE_EC, +}; + +typedef struct ATTR_PACKED RedMigrationBegin { + uint16_t port; + uint16_t sport; + uint32_t host_offset; + uint32_t host_size; + uint16_t pub_key_type; + uint32_t pub_key_offset; + uint32_t pub_key_size; +} RedMigrationBegin; + +enum { + RED_MIGRATE_NEED_FLUSH = (1 << 0), + RED_MIGRATE_NEED_DATA_TRANSFER = (1 << 1), +}; + +typedef struct ATTR_PACKED RedMigrate { + uint32_t flags; +} RedMigrate; + +enum { + RED_RES_TYPE_INVALID, + RED_RES_TYPE_PIXMAP, +}; + +typedef struct ATTR_PACKED RedResorceID { + uint8_t type; + uint64_t id; +} RedResorceID; + +typedef struct ATTR_PACKED RedResorceList { + uint16_t count; + RedResorceID resorces[0]; +} RedResorceList; + +typedef struct ATTR_PACKED RedSetAck { + uint32_t generation; + uint32_t window; +} RedSetAck; + +typedef struct ATTR_PACKED RedWaitForChannel { + uint8_t channel_type; + uint8_t channel_id; + uint64_t message_serial; +} RedWaitForChannel; + +typedef struct ATTR_PACKED RedWaitForChannels { + uint8_t wait_count; + RedWaitForChannel wait_list[0]; +} RedWaitForChannels; + +typedef struct ATTR_PACKED RedChannelInit { + uint8_t type; + uint8_t id; +} RedChannelInit; + +typedef struct ATTR_PACKED RedInit { + uint32_t session_id; + uint32_t display_channels_hint; + uint32_t supported_mouse_modes; + uint32_t current_mouse_mode; + uint32_t agent_connected; + uint32_t agent_tokens; + uint32_t multi_media_time; + uint32_t ram_hint; +} RedInit; + +typedef struct ATTR_PACKED RedDisconnect { + uint64_t time_stamp; + uint32_t reason; // RED_ERR_? +} RedDisconnect; + +enum { + RED_NOTIFY_SEVERITY_INFO, + RED_NOTIFY_SEVERITY_WARN, + RED_NOTIFY_SEVERITY_ERROR, +}; + +enum { + RED_NOTIFY_VISIBILITY_LOW, + RED_NOTIFY_VISIBILITY_MEDIUM, + RED_NOTIFY_VISIBILITY_HIGH, +}; + +typedef struct ATTR_PACKED RedNotify { + uint64_t time_stamp; + uint32_t severty; + uint32_t visibilty; + uint32_t what; + uint32_t message_len; + uint8_t message[0]; +} RedNotify; + +typedef struct ATTR_PACKED RedChannels { + uint32_t num_of_channels; + RedChannelInit channels[0]; +} RedChannels; + +typedef struct ATTR_PACKED RedMouseMode { + uint32_t supported_modes; + uint32_t current_mode; +} RedMouseMode; + +typedef struct ATTR_PACKED RedPing { + uint32_t id; + uint64_t timestamp; +} RedPing; + +typedef struct ATTR_PACKED RedAgentDisconnect { + uint32_t error_code; // RED_ERR_? +} RedAgentDisconnect; + +#define RED_AGENT_MAX_DATA_SIZE 2048 + +typedef struct ATTR_PACKED RedAgentTokens { + uint32_t num_tokens; +} RedAgentTokens, RedcAgentTokens, RedcAgentStart; + +typedef struct ATTR_PACKED RedcClientInfo { + uint64_t cache_size; +} RedcClientInfo; + +typedef struct ATTR_PACKED RedcMouseModeRequest { + uint32_t mode; +} RedcMouseModeRequest; + +enum { + RED_DISPLAY_MODE = RED_FIRST_AVAIL_MESSAGE, + RED_DISPLAY_MARK, + RED_DISPLAY_RESET, + RED_DISPLAY_COPY_BITS, + + RED_DISPLAY_INVAL_LIST, + RED_DISPLAY_INVAL_ALL_PIXMAPS, + RED_DISPLAY_INVAL_PALETTE, + RED_DISPLAY_INVAL_ALL_PALETTES, + + RED_DISPLAY_STREAM_CREATE = RED_FIRST_AVAIL_MESSAGE + 21, + RED_DISPLAY_STREAM_DATA, + RED_DISPLAY_STREAM_CLIP, + RED_DISPLAY_STREAM_DESTROY, + RED_DISPLAY_STREAM_DESTROY_ALL, + + RED_DISPLAY_DRAW_FILL = RED_FIRST_AVAIL_MESSAGE + 201, + RED_DISPLAY_DRAW_OPAQUE, + RED_DISPLAY_DRAW_COPY, + RED_DISPLAY_DRAW_BLEND, + RED_DISPLAY_DRAW_BLACKNESS, + RED_DISPLAY_DRAW_WHITENESS, + RED_DISPLAY_DRAW_INVERS, + RED_DISPLAY_DRAW_ROP3, + RED_DISPLAY_DRAW_STROKE, + RED_DISPLAY_DRAW_TEXT, + RED_DISPLAY_DRAW_TRANSPARENT, + RED_DISPLAY_DRAW_ALPHA_BLEND, + + RED_DISPLAY_MESSAGES_END, +}; + +enum { + RED_CURSOR_NONE = (1 << 0), + RED_CURSOR_CACHE_ME = (1 << 1), + RED_CURSOR_FROM_CACHE = (1 << 2), +}; + +typedef struct ATTR_PACKED RedCursor { + uint32_t flags; + CursorHeader header; + uint8_t data[0]; +} RedCursor; + +typedef struct ATTR_PACKED RedMode { + uint32_t x_res; + uint32_t y_res; + uint32_t bits; +} RedMode; + +typedef struct ATTR_PACKED RedDrawBase { + Rect box; + Clip clip; +} RedDrawBase; + +typedef struct ATTR_PACKED RedFill { + RedDrawBase base; + Fill data; +} RedFill; + +typedef struct ATTR_PACKED RedOpaque { + RedDrawBase base; + Opaque data; +} RedOpaque; + +typedef struct ATTR_PACKED RedCopy { + RedDrawBase base; + Copy data; +} RedCopy; + +typedef struct ATTR_PACKED RedTransparent { + RedDrawBase base; + Transparent data; +} RedTransparent; + +typedef struct ATTR_PACKED RedAlphaBlend { + RedDrawBase base; + AlphaBlnd data; +} RedAlphaBlend; + +typedef struct ATTR_PACKED RedCopyBits { + RedDrawBase base; + Point src_pos; +} RedCopyBits; + +typedef RedCopy RedBlend; + +typedef struct ATTR_PACKED RedRop3 { + RedDrawBase base; + Rop3 data; +} RedRop3; + +typedef struct ATTR_PACKED RedBlackness { + RedDrawBase base; + Blackness data; +} RedBlackness; + +typedef struct ATTR_PACKED RedWhiteness { + RedDrawBase base; + Whiteness data; +} RedWhiteness; + +typedef struct ATTR_PACKED RedInvers { + RedDrawBase base; + Invers data; +} RedInvers; + +typedef struct ATTR_PACKED RedStroke { + RedDrawBase base; + Stroke data; +} RedStroke; + +typedef struct ATTR_PACKED RedText { + RedDrawBase base; + Text data; +} RedText; + +typedef struct ATTR_PACKED RedInvalOne { + uint64_t id; +} RedInvalOne; + +enum { + RED_VIDEO_CODEC_TYPE_MJPEG = 1, +}; + +enum { + STREAM_TOP_DOWN = (1 << 0), +}; + +typedef struct ATTR_PACKED RedStreamCreate { + uint32_t id; + uint32_t flags; + uint32_t codec_type; + uint64_t stamp; + uint32_t stream_width; + uint32_t stream_height; + uint32_t src_width; + uint32_t src_height; + Rect dest; + Clip clip; +} RedStreamCreate; + +typedef struct ATTR_PACKED RedStreamData { + uint32_t id; + uint32_t multi_media_time; + uint32_t data_size; + uint32_t ped_size; + uint8_t data[0]; +} RedStreamData; + +typedef struct ATTR_PACKED RedStreamClip { + uint32_t id; + Clip clip; +} RedStreamClip; + +typedef struct ATTR_PACKED RedStreamDestroy { + uint32_t id; +} RedStreamDestroy; + +enum { + RED_CURSOR_INIT = RED_FIRST_AVAIL_MESSAGE, + RED_CURSOR_RESET, + RED_CURSOR_SET, + RED_CURSOR_MOVE, + RED_CURSOR_HIDE, + RED_CURSOR_TRAIL, + RED_CURSOR_INVAL_ONE, + RED_CURSOR_INVAL_ALL, + + RED_CURSOR_MESSAGES_END, +}; + +typedef struct ATTR_PACKED RedCursorInit { + Point16 position; + uint16_t trail_length; + uint16_t trail_frequency; + uint8_t visible; + RedCursor cursor; +} RedCursorInit; + +typedef struct ATTR_PACKED RedCursorSet { + Point16 postition; + uint8_t visible; + RedCursor cursor; +} RedCursorSet; + +typedef struct ATTR_PACKED RedCursorMove { + Point16 postition; +} RedCursorMove; + +typedef struct ATTR_PACKED RedCursorTrail { + uint16_t length; + uint16_t frequency; +} RedCursorTrail; + +enum { + REDC_DISPLAY_INIT = REDC_FIRST_AVAIL_MESSAGE, + + REDC_DISPLAY_MESSGES_END, +}; + +typedef struct ATTR_PACKED RedcDisplayInit { + uint8_t pixmap_cache_id; + int64_t pixmap_cache_size; //in pixels + uint8_t glz_dictionary_id; + int glz_dictionary_window_size; // in pixels +} RedcDisplayInit; + +enum { + REDC_INPUTS_KEY_DOWN = REDC_FIRST_AVAIL_MESSAGE, + REDC_INPUTS_KEY_UP, + REDC_INPUTS_KEY_MODIFAIERS, + + REDC_INPUTS_MOUSE_MOTION = REDC_FIRST_AVAIL_MESSAGE + 10, + REDC_INPUTS_MOUSE_POSITION, + REDC_INPUTS_MOUSE_PRESS, + REDC_INPUTS_MOUSE_RELEASE, + + REDC_INPUTS_MESSGES_END, +}; + +typedef struct ATTR_PACKED RedcKeyDown { + uint32_t code; +} RedcKeyDown; + +typedef struct ATTR_PACKED RedcKeyUp { + uint32_t code; +} RedcKeyUp; + +enum { + RED_MOUSE_MODE_SERVER = (1 << 0), + RED_MOUSE_MODE_CLIENT = (1 << 1), +}; + +typedef struct ATTR_PACKED RedcKeyModifiers { + uint32_t modifiers; +} RedcKeyModifiers; + +enum RedButton { + REDC_MOUSE_INVALID_BUTTON, + REDC_MOUSE_LBUTTON, + REDC_MOUSE_MBUTTON, + REDC_MOUSE_RBUTTON, + REDC_MOUSE_UBUTTON, + REDC_MOUSE_DBUTTON, +}; + +#define REDC_LBUTTON_MASK (1 << (REDC_MOUSE_LBUTTON - 1)) +#define REDC_MBUTTON_MASK (1 << (REDC_MOUSE_MBUTTON - 1)) +#define REDC_RBUTTON_MASK (1 << (REDC_MOUSE_RBUTTON - 1)) + +typedef struct ATTR_PACKED RedcMouseMotion { + int32_t dx; + int32_t dy; + uint32_t buttons_state; +} RedcMouseMotion; + +typedef struct ATTR_PACKED RedcMousePosition { + uint32_t x; + uint32_t y; + uint32_t buttons_state; + uint8_t display_id; +} RedcMousePosition; + +typedef struct ATTR_PACKED RedcMousePress { + int32_t button; + int32_t buttons_state; +} RedcMousePress; + +typedef struct ATTR_PACKED RedcMouseRelease { + int32_t button; + int32_t buttons_state; +} RedcMouseRelease; + +enum { + RED_AUDIO_FMT_INVALD, + RED_AUDIO_FMT_S16, +}; + +enum { + RED_AUDIO_DATA_MODE_INVALD, + RED_AUDIO_DATA_MODE_RAW, + RED_AUDIO_DATA_MODE_CELT_0_5_1, +}; + +enum { + RED_PLAYBACK_DATA = RED_FIRST_AVAIL_MESSAGE, + RED_PLAYBACK_MODE, + RED_PLAYBACK_START, + RED_PLAYBACK_STOP, + + RED_PLAYBACK_MESSAGES_END, +}; + +enum { + RED_PLAYBACK_CAP_CELT_0_5_1, +}; + +enum { + RED_RECORD_START = RED_FIRST_AVAIL_MESSAGE, + RED_RECORD_STOP, + + RED_RECORD_MESSAGES_END, +}; + +enum { + REDC_RECORD_DATA = RED_FIRST_AVAIL_MESSAGE, + REDC_RECORD_MODE, + REDC_RECORD_START_MARK, + + REDC_RECORD_MESSAGES_END, +}; + +enum { + RED_RECORD_CAP_CELT_0_5_1, +}; + +typedef struct ATTR_PACKED RedPlaybackMode { + uint32_t time; + uint32_t mode; //RED_AUDIO_DATA_MODE_? + uint8_t data[0]; +} RedPlaybackMode, RedcRecordMode; + +typedef struct ATTR_PACKED RedPlaybackStart { + uint32_t channels; + uint32_t format; //RED_AUDIO_FMT_? + uint32_t frequency; + uint32_t time; +} RedPlaybackStart; + +typedef struct ATTR_PACKED RedPlaybackPacket { + uint32_t time; + uint8_t data[0]; +} RedPlaybackPacket, RedcRecordPacket; + +typedef struct ATTR_PACKED RedRecordStart { + uint32_t channels; + uint32_t format; //RED_AUDIO_FMT_? + uint32_t frequency; +} RedRecordStart; + +typedef struct ATTR_PACKED RedcRecordStartMark { + uint32_t time; +} RedcRecordStartMark; + +enum { + RED_TUNNEL_SERVICE_TYPE_INVALID, + RED_TUNNEL_SERVICE_TYPE_GENERIC, + RED_TUNNEL_SERVICE_TYPE_IPP, +}; + +enum { + RED_TUNNEL_INIT = RED_FIRST_AVAIL_MESSAGE, + RED_TUNNEL_SERVICE_IP_MAP, + RED_TUNNEL_SOCKET_OPEN, + RED_TUNNEL_SOCKET_FIN, + RED_TUNNEL_SOCKET_CLOSE, + RED_TUNNEL_SOCKET_DATA, + RED_TUNNEL_SOCKET_CLOSED_ACK, + RED_TUNNEL_SOCKET_TOKEN, + + RED_TUNNEL_MESSAGES_END, +}; + +typedef struct ATTR_PACKED RedTunnelInit { + uint16_t max_num_of_sockets; + uint32_t max_socket_data_size; +} RedTunnelInit; + +enum { + RED_TUNNEL_IP_TYPE_INVALID, + RED_TUNNEL_IP_TYPE_IPv4, +}; + +typedef struct ATTR_PACKED RedTunnelIpInfo { + uint16_t type; + uint8_t data[0]; +} RedTunnelIpInfo; + +typedef uint8_t RedTunnelIPv4[4]; + +typedef struct ATTR_PACKED RedTunnelServiceIpMap { + uint32_t service_id; + RedTunnelIpInfo virtual_ip; +} RedTunnelServiceIpMap; + +typedef struct ATTR_PACKED RedTunnelSocketOpen { + uint16_t connection_id; + uint32_t service_id; + uint32_t tokens; +} RedTunnelSocketOpen; + +/* connection id must be the first field in msgs directed to a specific connection */ + +typedef struct ATTR_PACKED RedTunnelSocketFin { + uint16_t connection_id; +} RedTunnelSocketFin; + +typedef struct ATTR_PACKED RedTunnelSocketClose { + uint16_t connection_id; +} RedTunnelSocketClose; + +typedef struct ATTR_PACKED RedTunnelSocketData { + uint16_t connection_id; + uint8_t data[0]; +} RedTunnelSocketData; + +typedef struct ATTR_PACKED RedTunnelSocketTokens { + uint16_t connection_id; + uint32_t num_tokens; +} RedTunnelSocketTokens; + +typedef struct ATTR_PACKED RedTunnelSocketClosedAck { + uint16_t connection_id; +} RedTunnelSocketClosedAck; + +enum { + REDC_TUNNEL_SERVICE_ADD = REDC_FIRST_AVAIL_MESSAGE, + REDC_TUNNEL_SERVICE_REMOVE, + REDC_TUNNEL_SOCKET_OPEN_ACK, + REDC_TUNNEL_SOCKET_OPEN_NACK, + REDC_TUNNEL_SOCKET_FIN, + REDC_TUNNEL_SOCKET_CLOSED, + REDC_TUNNEL_SOCKET_CLOSED_ACK, + REDC_TUNNEL_SOCKET_DATA, + + REDC_TUNNEL_SOCKET_TOKEN, + + REDC_TUNNEL_MESSGES_END, +}; + +typedef struct ATTR_PACKED RedcTunnelAddGenericService { + uint32_t type; + uint32_t id; + uint32_t group; + uint32_t port; + uint32_t name; + uint32_t description; +} RedcTunnelAddGenericService; + +typedef struct ATTR_PACKED RedcTunnelAddPrintService { + RedcTunnelAddGenericService base; + RedTunnelIpInfo ip; +} RedcTunnelAddPrintService; + +typedef struct ATTR_PACKED RedcTunnelRemoveService { + uint32_t id; +} RedcTunnelRemoveService; + +/* connection id must be the first field in msgs directed to a specific connection */ + +typedef struct ATTR_PACKED RedcTunnelSocketOpenAck { + uint16_t connection_id; + uint32_t tokens; +} RedcTunnelSocketOpenAck; + +typedef struct ATTR_PACKED RedcTunnelSocketOpenNack { + uint16_t connection_id; +} RedcTunnelSocketOpenNack; + +typedef struct ATTR_PACKED RedcTunnelSocketData { + uint16_t connection_id; + uint8_t data[0]; +} RedcTunnelSocketData; + +typedef struct ATTR_PACKED RedcTunnelSocketFin { + uint16_t connection_id; +} RedcTunnelSocketFin; + +typedef struct ATTR_PACKED RedcTunnelSocketClosed { + uint16_t connection_id; +} RedcTunnelSocketClosed; + +typedef struct ATTR_PACKED RedcTunnelSocketClosedAck { + uint16_t connection_id; +} RedcTunnelSocketClosedAck; + +typedef struct ATTR_PACKED RedcTunnelSocketTokens { + uint16_t connection_id; + uint32_t num_tokens; +} RedcTunnelSocketTokens; + +#undef ATTR_PACKED + +#ifndef __GNUC__ +#pragma pack(pop) +#endif + +#endif + diff --git a/spice/red_error_codes.h b/spice/red_error_codes.h new file mode 100644 index 0000000..bff53dd --- /dev/null +++ b/spice/red_error_codes.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef RED_ERROR_CODES_H +#define RED_ERROR_CODES_H + +#define SPICEC_ERROR_CODE_SUCCESS 0 +#define SPICEC_ERROR_CODE_ERROR 1 +#define SPICEC_ERROR_CODE_GETHOSTBYNAME_FAILED 2 +#define SPICEC_ERROR_CODE_CONNECT_FAILED 3 +#define SPICEC_ERROR_CODE_SOCKET_FAILED 4 +#define SPICEC_ERROR_CODE_SEND_FAILED 5 +#define SPICEC_ERROR_CODE_RECV_FAILED 6 +#define SPICEC_ERROR_CODE_SSL_ERROR 7 +#define SPICEC_ERROR_CODE_NOT_ENOUGH_MEMORY 8 +#define SPICEC_ERROR_CODE_AGENT_TIMEOUT 9 +#define SPICEC_ERROR_CODE_AGENT_ERROR 10 +#define SPICEC_ERROR_CODE_VERSION_MISMATCH 11 +#define SPICEC_ERROR_CODE_PERMISSION_DENIED 12 +#define SPICEC_ERROR_CODE_INVALID_ARG 13 +#define SPICEC_ERROR_CODE_CMD_LINE_ERROR 14 + +#endif + diff --git a/spice/reds_stat.h b/spice/reds_stat.h new file mode 100644 index 0000000..0baa13f --- /dev/null +++ b/spice/reds_stat.h @@ -0,0 +1,68 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _H_REDS_STAT +#define _H_REDS_STAT + +#include + +#define REDS_STAT_SHM_NAME "spice.%u" +#define REDS_STAT_NODE_NAME_MAX_LENGTH 20 +#define REDS_STAT_MAGIC (*(uint32_t*)"STAT") +#define REDS_STAT_VERSION 1 + +enum { + STAT_NODE_FLAG_ENABLED = (1 << 0), + STAT_NODE_FLAG_VISIBLE = (1 << 1), + STAT_NODE_FLAG_VALUE = (1 << 2), +}; + +#define STAT_NODE_MASK_SHOW (STAT_NODE_FLAG_ENABLED | STAT_NODE_FLAG_VISIBLE) +#define STAT_NODE_MASK_SHOW_VALUE (STAT_NODE_MASK_SHOW | STAT_NODE_FLAG_VALUE) + +typedef struct StatNode { + uint64_t value; + uint32_t flags; + uint32_t next_sibling_index; + uint32_t first_child_index; + char name[REDS_STAT_NODE_NAME_MAX_LENGTH]; +} StatNode; + +typedef struct RedsStat { + uint32_t magic; + uint32_t version; + uint32_t generation; + uint32_t num_of_nodes; + uint32_t root_index; + StatNode nodes[]; +} RedsStat; + +#endif + diff --git a/spice/vd_agent.h b/spice/vd_agent.h new file mode 100644 index 0000000..7451210 --- /dev/null +++ b/spice/vd_agent.h @@ -0,0 +1,109 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _H_VD_AGENT +#define _H_VD_AGENT + +#include +#ifdef __GNUC__ +#define ATTR_PACKED __attribute__ ((__packed__)) +#else +#pragma pack(push) +#pragma pack(1) +#define ATTR_PACKED +#endif + + +typedef struct ATTR_PACKED VDAgentMessage { + uint32_t protocol; + uint32_t type; + uint64_t opaque; + uint32_t size; + uint8_t data[0]; +} VDAgentMessage; + +#define VD_AGENT_PROTOCOL 1 + +enum { + VD_AGENT_MOUSE_STATE = 1, + VD_AGENT_MONITORS_CONFIG, + VD_AGENT_REPLY, +}; + +typedef struct ATTR_PACKED VDAgentMonConfig { + uint32_t height; + uint32_t width; + uint32_t depth; + int32_t x; + int32_t y; +} VDAgentMonConfig; + +enum { + VD_AGENT_CONFIG_MONITORS_FLAG_USE_POS = (1 << 0), +}; + +typedef struct ATTR_PACKED VDAgentMonitorsConfig { + uint32_t num_of_monitors; + uint32_t flags; + VDAgentMonConfig monitors[0]; +} VDAgentMonitorsConfig; + +#define VD_AGENT_LBUTTON_MASK (1 << 1) +#define VD_AGENT_MBUTTON_MASK (1 << 2) +#define VD_AGENT_RBUTTON_MASK (1 << 3) +#define VD_AGENT_UBUTTON_MASK (1 << 4) +#define VD_AGENT_DBUTTON_MASK (1 << 5) + +typedef struct ATTR_PACKED VDAgentMouseState { + uint32_t x; + uint32_t y; + uint32_t buttons; + uint8_t display_id; +} VDAgentMouseState; + +typedef struct ATTR_PACKED VDAgentReply { + uint32_t type; + uint32_t error; +} VDAgentReply; + +enum { + VD_AGENT_SUCCESS = 1, + VD_AGENT_ERROR, +}; + +#undef ATTR_PACKED + +#ifndef __GNUC__ +#pragma pack(pop) +#endif + +#endif + + diff --git a/spice/vdi_dev.h b/spice/vdi_dev.h new file mode 100644 index 0000000..d8b5add --- /dev/null +++ b/spice/vdi_dev.h @@ -0,0 +1,97 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _H_VDI_DEV +#define _H_VDI_DEV + +#include "ipc_ring.h" + +#ifdef __GNUC__ +#ifdef __i386__ +#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") +#else +//mfence +#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%rsp)": : :"memory") +#endif +#define ATTR_PACKED __attribute__ ((__packed__)) +#else +#pragma pack(push) +#pragma pack(1) +#define ATTR_PACKED +#define mb() __asm {lock add [esp], 0} +#endif + +#define REDHAT_PCI_VENDOR_ID 0x1b36 + +#define VDI_PORT_DEVICE_ID 0x0105 +#define VDI_PORT_REVISION 0x01 + +#define VDI_PORT_INTERRUPT (1 << 0) + +#define VDI_PORT_MAGIC (*(UINT32*)"VDIP") + +typedef struct ATTR_PACKED VDIPortPacket { + UINT32 gen; + UINT32 size; + UINT8 data[512 - 2 * sizeof(UINT32)]; +} VDIPortPacket; + +RING_DECLARE(VDIPortRing, VDIPortPacket, 32); + +enum { + VDI_PORT_IO_RANGE_INDEX, + VDI_PORT_RAM_RANGE_INDEX, +}; + +enum { + VDI_PORT_IO_CONNECTION, + VDI_PORT_IO_NOTIFY = 4, + VDI_PORT_IO_UPDATE_IRQ = 8, + + VDI_PORT_IO_RANGE_SIZE = 12 +}; + +typedef struct ATTR_PACKED VDIPortRam { + UINT32 magic; + UINT32 generation; + UINT32 int_pending; + UINT32 int_mask; + VDIPortRing input; + VDIPortRing output; + UINT32 reserv[32]; +} VDIPortRam; + +#ifndef __GNUC__ +#pragma pack(pop) +#endif + +#undef ATTR_PACKED + +#endif