diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/block/block.h | 3 | ||||
-rw-r--r-- | include/block/block_int.h | 7 | ||||
-rw-r--r-- | include/block/nbd.h | 4 | ||||
-rw-r--r-- | include/char/char.h | 19 | ||||
-rw-r--r-- | include/disas/bfd.h | 2 | ||||
-rw-r--r-- | include/glib-compat.h | 27 | ||||
-rw-r--r-- | include/migration/migration.h | 2 | ||||
-rw-r--r-- | include/migration/qemu-file.h | 12 | ||||
-rw-r--r-- | include/migration/vmstate.h | 43 | ||||
-rw-r--r-- | include/net/checksum.h | 26 | ||||
-rw-r--r-- | include/net/eth.h | 347 | ||||
-rw-r--r-- | include/net/net.h | 5 | ||||
-rw-r--r-- | include/qemu-common.h | 39 | ||||
-rw-r--r-- | include/qemu/sockets.h | 3 | ||||
-rw-r--r-- | include/qom/object.h | 2 | ||||
-rw-r--r-- | include/sysemu/arch_init.h | 1 | ||||
-rw-r--r-- | include/ui/console.h | 274 | ||||
-rw-r--r-- | include/ui/spice-display.h | 9 |
18 files changed, 601 insertions, 224 deletions
diff --git a/include/block/block.h b/include/block/block.h index d4f34d6..9dc6aad 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -135,7 +135,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top); void bdrv_delete(BlockDriverState *bs); int bdrv_parse_cache_flags(const char *mode, int *flags); int bdrv_parse_discard_flags(const char *mode, int *flags); -int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); +int bdrv_file_open(BlockDriverState **pbs, const char *filename, + QDict *options, int flags); int bdrv_open_backing_file(BlockDriverState *bs); int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, int flags, BlockDriver *drv); diff --git a/include/block/block_int.h b/include/block/block_int.h index ce0aa26..0986a2d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -76,6 +76,10 @@ struct BlockDriver { int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int (*bdrv_probe_device)(const char *filename); + /* Any driver implementing this callback is expected to be able to handle + * NULL file names in its .bdrv_open() implementation */ + void (*bdrv_parse_filename)(const char *filename, QDict *options, Error **errp); + /* For handling image reopen for split or non-split files */ int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); @@ -83,7 +87,8 @@ struct BlockDriver { void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state); int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags); - int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags); + int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, + QDict *options, int flags); int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, diff --git a/include/block/nbd.h b/include/block/nbd.h index 344f05b..0903d7a 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -22,6 +22,7 @@ #include <sys/types.h> #include "qemu-common.h" +#include "qemu/option.h" struct nbd_request { uint32_t magic; @@ -60,10 +61,9 @@ enum { #define NBD_BUFFER_SIZE (1024*1024) ssize_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read); -int tcp_socket_outgoing(const char *address, uint16_t port); int tcp_socket_incoming(const char *address, uint16_t port); -int tcp_socket_outgoing_spec(const char *address_and_port); int tcp_socket_incoming_spec(const char *address_and_port); +int tcp_socket_outgoing_opts(QemuOpts *opts); int unix_socket_outgoing(const char *path); int unix_socket_incoming(const char *path); diff --git a/include/char/char.h b/include/char/char.h index d6a0351..5c3a7a5 100644 --- a/include/char/char.h +++ b/include/char/char.h @@ -153,8 +153,8 @@ void qemu_chr_fe_close(struct CharDriverState *chr); void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); -guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, - GIOFunc func, void *user_data); +int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data); /** * @qemu_chr_fe_write: @@ -170,6 +170,21 @@ guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); /** + * @qemu_chr_fe_write_all: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. Unlike @qemu_chr_fe_write, + * this function will block if the back end cannot consume all of the data + * attempted to be written. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); + +/** * @qemu_chr_fe_ioctl: * * Issue a device specific ioctl to a backend. diff --git a/include/disas/bfd.h b/include/disas/bfd.h index 3944b3c..803b6ef 100644 --- a/include/disas/bfd.h +++ b/include/disas/bfd.h @@ -218,6 +218,7 @@ enum bfd_architecture #define bfd_mach_cris_v32 32 #define bfd_mach_cris_v10_v32 1032 bfd_arch_microblaze, /* Xilinx MicroBlaze. */ + bfd_arch_moxie, /* The Moxie core. */ bfd_arch_ia64, /* HP/Intel ia64 */ #define bfd_mach_ia64_elf64 64 #define bfd_mach_ia64_elf32 32 @@ -392,6 +393,7 @@ int print_insn_m32r (bfd_vma, disassemble_info*); int print_insn_m88k (bfd_vma, disassemble_info*); int print_insn_mn10200 (bfd_vma, disassemble_info*); int print_insn_mn10300 (bfd_vma, disassemble_info*); +int print_insn_moxie (bfd_vma, disassemble_info*); int print_insn_ns32k (bfd_vma, disassemble_info*); int print_insn_big_powerpc (bfd_vma, disassemble_info*); int print_insn_little_powerpc (bfd_vma, disassemble_info*); diff --git a/include/glib-compat.h b/include/glib-compat.h new file mode 100644 index 0000000..8aa77af --- /dev/null +++ b/include/glib-compat.h @@ -0,0 +1,27 @@ +/* + * GLIB Compatibility Functions + * + * Copyright IBM, Corp. 2013 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_GLIB_COMPAT_H +#define QEMU_GLIB_COMPAT_H + +#include <glib.h> + +#if !GLIB_CHECK_VERSION(2, 14, 0) +static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function, + gpointer data) +{ + return g_timeout_add(interval * 1000, function, data); +} +#endif + +#endif diff --git a/include/migration/migration.h b/include/migration/migration.h index bb617fd..e2acec6 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -96,6 +96,8 @@ extern SaveVMHandlers savevm_ram_handlers; uint64_t dup_mig_bytes_transferred(void); uint64_t dup_mig_pages_transferred(void); +uint64_t skipped_mig_bytes_transferred(void); +uint64_t skipped_mig_pages_transferred(void); uint64_t norm_mig_bytes_transferred(void); uint64_t norm_mig_pages_transferred(void); uint64_t xbzrle_mig_bytes_transferred(void); diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index df81261..623c434 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -51,11 +51,18 @@ typedef int (QEMUFileCloseFunc)(void *opaque); */ typedef int (QEMUFileGetFD)(void *opaque); +/* + * This function writes an iovec to file. + */ +typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov, + int iovcnt); + typedef struct QEMUFileOps { QEMUFilePutBufferFunc *put_buffer; QEMUFileGetBufferFunc *get_buffer; QEMUFileCloseFunc *close; QEMUFileGetFD *get_fd; + QEMUFileWritevBufferFunc *writev_buffer; } QEMUFileOps; QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); @@ -68,6 +75,11 @@ int qemu_fclose(QEMUFile *f); int64_t qemu_ftell(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); +/* + * put_buffer without copying the buffer. + * The buffer should be available till it is sent asynchronously. + */ +void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size); static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) { diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 6666d27..65918a9 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -149,6 +149,7 @@ extern const VMStateInfo vmstate_info_uint8_equal; extern const VMStateInfo vmstate_info_uint16_equal; extern const VMStateInfo vmstate_info_int32_equal; extern const VMStateInfo vmstate_info_uint32_equal; +extern const VMStateInfo vmstate_info_uint64_equal; extern const VMStateInfo vmstate_info_int32_le; extern const VMStateInfo vmstate_info_uint8; @@ -156,6 +157,8 @@ extern const VMStateInfo vmstate_info_uint16; extern const VMStateInfo vmstate_info_uint32; extern const VMStateInfo vmstate_info_uint64; +extern const VMStateInfo vmstate_info_float64; + extern const VMStateInfo vmstate_info_timer; extern const VMStateInfo vmstate_info_buffer; extern const VMStateInfo vmstate_info_unused_buffer; @@ -340,6 +343,16 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .version_id = 0, \ + .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ + .size = sizeof(_type), \ + .vmsd = &(_vmsd), \ + .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .offset = vmstate_offset_pointer(_state, _field, _type), \ +} + #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, _vmsd, _type) { \ .name = (stringify(_field)), \ .version_id = 0, \ @@ -380,14 +393,14 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } -#define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \ +#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, _field_size, _multiply) { \ .name = (stringify(_field)), \ .version_id = (_version), \ .field_exists = (_test), \ .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ .size = (_multiply), \ .info = &vmstate_info_buffer, \ - .flags = VMS_VBUFFER|VMS_MULTIPLY, \ + .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ .offset = offsetof(_state, _field), \ .start = (_start), \ } @@ -518,8 +531,17 @@ extern const VMStateInfo vmstate_info_bitmap; #define VMSTATE_INT32_EQUAL(_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) -#define VMSTATE_UINT32_EQUAL(_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_UINT32_EQUAL_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) + +#define VMSTATE_UINT32_EQUAL(_f, _s) \ + VMSTATE_UINT32_EQUAL_V(_f, _s, 0) + +#define VMSTATE_UINT64_EQUAL_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) + +#define VMSTATE_UINT64_EQUAL(_f, _s) \ + VMSTATE_UINT64_EQUAL_V(_f, _s, 0) #define VMSTATE_INT32_LE(_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) @@ -533,6 +555,13 @@ extern const VMStateInfo vmstate_info_bitmap; #define VMSTATE_UINT32_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) + +#define VMSTATE_FLOAT64_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) + +#define VMSTATE_FLOAT64(_f, _s) \ + VMSTATE_FLOAT64_V(_f, _s, 0) + #define VMSTATE_TIMER_TEST(_f, _s, _test) \ VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *) @@ -599,6 +628,12 @@ extern const VMStateInfo vmstate_info_bitmap; #define VMSTATE_INT64_ARRAY(_f, _s, _n) \ VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v) \ + VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64) + +#define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \ + VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0) + #define VMSTATE_BUFFER_V(_f, _s, _v) \ VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) diff --git a/include/net/checksum.h b/include/net/checksum.h index 1f05298..80203fb 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -20,10 +20,34 @@ #include <stdint.h> -uint32_t net_checksum_add(int len, uint8_t *buf); +uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); uint16_t net_checksum_finish(uint32_t sum); uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, uint8_t *addrs, uint8_t *buf); void net_checksum_calculate(uint8_t *data, int length); +static inline uint32_t +net_checksum_add(int len, uint8_t *buf) +{ + return net_checksum_add_cont(len, buf, 0); +} + +static inline uint16_t +net_raw_checksum(uint8_t *data, int length) +{ + return net_checksum_finish(net_checksum_add(length, data)); +} + +/** + * net_checksum_add_iov: scatter-gather vector checksumming + * + * @iov: input scatter-gather array + * @iov_cnt: number of array elements + * @iov_off: starting iov offset for checksumming + * @size: length of data to be checksummed + */ +uint32_t net_checksum_add_iov(const struct iovec *iov, + const unsigned int iov_cnt, + uint32_t iov_off, uint32_t size); + #endif /* QEMU_NET_CHECKSUM_H */ diff --git a/include/net/eth.h b/include/net/eth.h new file mode 100644 index 0000000..1d48e06 --- /dev/null +++ b/include/net/eth.h @@ -0,0 +1,347 @@ +/* + * QEMU network structures definitions and helper functions + * + * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com) + * + * Developed by Daynix Computing LTD (http://www.daynix.com) + * + * Portions developed by Free Software Foundation, Inc + * Copyright (C) 1991-1997, 2001, 2003, 2006 Free Software Foundation, Inc. + * See netinet/ip6.h and netinet/in.h (GNU C Library) + * + * Portions developed by Igor Kovalenko + * Copyright (c) 2006 Igor Kovalenko + * See hw/rtl8139.c (QEMU) + * + * Authors: + * Dmitry Fleytman <dmitry@daynix.com> + * Tamir Shomer <tamirs@daynix.com> + * Yan Vugenfirer <yan@daynix.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_ETH_H +#define QEMU_ETH_H + +#include <sys/types.h> +#include <string.h> +#include "qemu/bswap.h" +#include "qemu/iov.h" + +#define ETH_ALEN 6 + +struct eth_header { + uint8_t h_dest[ETH_ALEN]; /* destination eth addr */ + uint8_t h_source[ETH_ALEN]; /* source ether addr */ + uint16_t h_proto; /* packet type ID field */ +}; + +struct vlan_header { + uint16_t h_tci; /* priority and VLAN ID */ + uint16_t h_proto; /* encapsulated protocol */ +}; + +struct ip_header { + uint8_t ip_ver_len; /* version and header length */ + uint8_t ip_tos; /* type of service */ + uint16_t ip_len; /* total length */ + uint16_t ip_id; /* identification */ + uint16_t ip_off; /* fragment offset field */ + uint8_t ip_ttl; /* time to live */ + uint8_t ip_p; /* protocol */ + uint16_t ip_sum; /* checksum */ + uint32_t ip_src, ip_dst; /* source and destination address */ +}; + +typedef struct tcp_header { + uint16_t th_sport; /* source port */ + uint16_t th_dport; /* destination port */ + uint32_t th_seq; /* sequence number */ + uint32_t th_ack; /* acknowledgment number */ + uint16_t th_offset_flags; /* data offset, reserved 6 bits, */ + /* TCP protocol flags */ + uint16_t th_win; /* window */ + uint16_t th_sum; /* checksum */ + uint16_t th_urp; /* urgent pointer */ +} tcp_header; + +typedef struct udp_header { + uint16_t uh_sport; /* source port */ + uint16_t uh_dport; /* destination port */ + uint16_t uh_ulen; /* udp length */ + uint16_t uh_sum; /* udp checksum */ +} udp_header; + +typedef struct ip_pseudo_header { + uint32_t ip_src; + uint32_t ip_dst; + uint8_t zeros; + uint8_t ip_proto; + uint16_t ip_payload; +} ip_pseudo_header; + +/* IPv6 address */ +struct in6_addr { + union { + uint8_t __u6_addr8[16]; + } __in6_u; +}; + +struct ip6_header { + union { + struct ip6_hdrctl { + uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC, + 20 bits flow-ID */ + uint16_t ip6_un1_plen; /* payload length */ + uint8_t ip6_un1_nxt; /* next header */ + uint8_t ip6_un1_hlim; /* hop limit */ + } ip6_un1; + uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits tclass */ + struct ip6_ecn_access { + uint8_t ip6_un3_vfc; /* 4 bits version, top 4 bits tclass */ + uint8_t ip6_un3_ecn; /* 2 bits ECN, top 6 bits payload length */ + } ip6_un3; + } ip6_ctlun; + struct in6_addr ip6_src; /* source address */ + struct in6_addr ip6_dst; /* destination address */ +}; + +struct ip6_ext_hdr { + uint8_t ip6r_nxt; /* next header */ + uint8_t ip6r_len; /* length in units of 8 octets */ +}; + +struct udp_hdr { + uint16_t uh_sport; /* source port */ + uint16_t uh_dport; /* destination port */ + uint16_t uh_ulen; /* udp length */ + uint16_t uh_sum; /* udp checksum */ +}; + +struct tcp_hdr { + u_short th_sport; /* source port */ + u_short th_dport; /* destination port */ + uint32_t th_seq; /* sequence number */ + uint32_t th_ack; /* acknowledgment number */ +#ifdef HOST_WORDS_BIGENDIAN + u_char th_off : 4, /* data offset */ + th_x2:4; /* (unused) */ +#else + u_char th_x2 : 4, /* (unused) */ + th_off:4; /* data offset */ +#endif + +#define TH_ELN 0x1 /* explicit loss notification */ +#define TH_ECN 0x2 /* explicit congestion notification */ +#define TH_FS 0x4 /* fast start */ + + u_char th_flags; +#define TH_FIN 0x01 +#define TH_SYN 0x02 +#define TH_RST 0x04 +#define TH_PUSH 0x08 +#define TH_ACK 0x10 +#define TH_URG 0x20 + u_short th_win; /* window */ + u_short th_sum; /* checksum */ + u_short th_urp; /* urgent pointer */ +}; + +#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt +#define ip6_ecn_acc ip6_ctlun.ip6_un3.ip6_un3_ecn + +#define PKT_GET_ETH_HDR(p) \ + ((struct eth_header *)(p)) +#define PKT_GET_VLAN_HDR(p) \ + ((struct vlan_header *) (((uint8_t *)(p)) + sizeof(struct eth_header))) +#define PKT_GET_DVLAN_HDR(p) \ + (PKT_GET_VLAN_HDR(p) + 1) +#define PKT_GET_IP_HDR(p) \ + ((struct ip_header *)(((uint8_t *)(p)) + eth_get_l2_hdr_length(p))) +#define IP_HDR_GET_LEN(p) \ + ((((struct ip_header *)p)->ip_ver_len & 0x0F) << 2) +#define PKT_GET_IP_HDR_LEN(p) \ + (IP_HDR_GET_LEN(PKT_GET_IP_HDR(p))) +#define PKT_GET_IP6_HDR(p) \ + ((struct ip6_header *) (((uint8_t *)(p)) + eth_get_l2_hdr_length(p))) +#define IP_HEADER_VERSION(ip) \ + ((ip->ip_ver_len >> 4)&0xf) + +#define ETH_P_IP (0x0800) +#define ETH_P_IPV6 (0x86dd) +#define ETH_P_VLAN (0x8100) +#define ETH_P_DVLAN (0x88a8) +#define VLAN_VID_MASK 0x0fff +#define IP_HEADER_VERSION_4 (4) +#define IP_HEADER_VERSION_6 (6) +#define IP_PROTO_TCP (6) +#define IP_PROTO_UDP (17) +#define IPTOS_ECN_MASK 0x03 +#define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) +#define IPTOS_ECN_CE 0x03 +#define IP6_ECN_MASK 0xC0 +#define IP6_ECN(x) ((x) & IP6_ECN_MASK) +#define IP6_ECN_CE 0xC0 +#define IP4_DONT_FRAGMENT_FLAG (1 << 14) + +#define IS_SPECIAL_VLAN_ID(x) \ + (((x) == 0) || ((x) == 0xFFF)) + +#define ETH_MAX_L2_HDR_LEN \ + (sizeof(struct eth_header) + 2 * sizeof(struct vlan_header)) + +#define ETH_MAX_IP4_HDR_LEN (60) +#define ETH_MAX_IP_DGRAM_LEN (0xFFFF) + +#define IP_FRAG_UNIT_SIZE (8) +#define IP_FRAG_ALIGN_SIZE(x) ((x) & ~0x7) +#define IP_RF 0x8000 /* reserved fragment flag */ +#define IP_DF 0x4000 /* don't fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + +#define IP6_EXT_GRANULARITY (8) /* Size granularity for + IPv6 extension headers */ + +/* IP6 extension header types */ +#define IP6_HOP_BY_HOP (0) +#define IP6_ROUTING (43) +#define IP6_FRAGMENT (44) +#define IP6_ESP (50) +#define IP6_AUTHENTICATION (51) +#define IP6_NONE (59) +#define IP6_DESTINATON (60) +#define IP6_MOBILITY (135) + +static inline int is_multicast_ether_addr(const uint8_t *addr) +{ + return 0x01 & addr[0]; +} + +static inline int is_broadcast_ether_addr(const uint8_t *addr) +{ + return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; +} + +static inline int is_unicast_ether_addr(const uint8_t *addr) +{ + return !is_multicast_ether_addr(addr); +} + +typedef enum { + ETH_PKT_UCAST = 0xAABBCC00, + ETH_PKT_BCAST, + ETH_PKT_MCAST +} eth_pkt_types_e; + +static inline eth_pkt_types_e +get_eth_packet_type(const struct eth_header *ehdr) +{ + if (is_broadcast_ether_addr(ehdr->h_dest)) { + return ETH_PKT_BCAST; + } else if (is_multicast_ether_addr(ehdr->h_dest)) { + return ETH_PKT_MCAST; + } else { /* unicast */ + return ETH_PKT_UCAST; + } +} + +static inline uint32_t +eth_get_l2_hdr_length(const void *p) +{ + uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto); + struct vlan_header *hvlan = PKT_GET_VLAN_HDR(p); + switch (proto) { + case ETH_P_VLAN: + return sizeof(struct eth_header) + sizeof(struct vlan_header); + case ETH_P_DVLAN: + if (hvlan->h_proto == ETH_P_VLAN) { + return sizeof(struct eth_header) + 2 * sizeof(struct vlan_header); + } else { + return sizeof(struct eth_header) + sizeof(struct vlan_header); + } + default: + return sizeof(struct eth_header); + } +} + +static inline uint16_t +eth_get_pkt_tci(const void *p) +{ + uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto); + struct vlan_header *hvlan = PKT_GET_VLAN_HDR(p); + switch (proto) { + case ETH_P_VLAN: + case ETH_P_DVLAN: + return be16_to_cpu(hvlan->h_tci); + default: + return 0; + } +} + +static inline bool +eth_strip_vlan(const void *p, uint8_t *new_ehdr_buf, + uint16_t *payload_offset, uint16_t *tci) +{ + uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto); + struct vlan_header *hvlan = PKT_GET_VLAN_HDR(p); + struct eth_header *new_ehdr = (struct eth_header *) new_ehdr_buf; + + switch (proto) { + case ETH_P_VLAN: + case ETH_P_DVLAN: + memcpy(new_ehdr->h_source, PKT_GET_ETH_HDR(p)->h_source, ETH_ALEN); + memcpy(new_ehdr->h_dest, PKT_GET_ETH_HDR(p)->h_dest, ETH_ALEN); + new_ehdr->h_proto = hvlan->h_proto; + *tci = be16_to_cpu(hvlan->h_tci); + *payload_offset = + sizeof(struct eth_header) + sizeof(struct vlan_header); + if (be16_to_cpu(new_ehdr->h_proto) == ETH_P_VLAN) { + memcpy(PKT_GET_VLAN_HDR(new_ehdr), + PKT_GET_DVLAN_HDR(p), + sizeof(struct vlan_header)); + *payload_offset += sizeof(struct vlan_header); + } + return true; + default: + return false; + } +} + +static inline uint16_t +eth_get_l3_proto(const void *l2hdr, size_t l2hdr_len) +{ + uint8_t *proto_ptr = (uint8_t *) l2hdr + l2hdr_len - sizeof(uint16_t); + return be16_to_cpup((uint16_t *)proto_ptr); +} + +void eth_setup_vlan_headers(struct eth_header *ehdr, uint16_t vlan_tag, + bool *is_new); + +uint8_t eth_get_gso_type(uint16_t l3_proto, uint8_t *l3_hdr, uint8_t l4proto); + +void eth_get_protocols(const uint8_t *headers, + uint32_t hdr_length, + bool *isip4, bool *isip6, + bool *isudp, bool *istcp); + +void eth_setup_ip4_fragmentation(const void *l2hdr, size_t l2hdr_len, + void *l3hdr, size_t l3hdr_len, + size_t l3payload_len, + size_t frag_offset, bool more_frags); + +void +eth_fix_ip4_checksum(void *l3hdr, size_t l3hdr_len); + +uint32_t +eth_calc_pseudo_hdr_csum(struct ip_header *iphdr, uint16_t csl); + +bool +eth_parse_ipv6_hdr(struct iovec *pkt, int pkt_frags, + size_t ip6hdr_off, uint8_t *l4proto, + size_t *full_hdr_len); + +#endif diff --git a/include/net/net.h b/include/net/net.h index cb049a1..43d85a1 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -11,6 +11,11 @@ #define MAX_QUEUE_NUM 1024 +/* Maximum GSO packet size (64k) plus plenty of room for + * the ethernet and virtio_net headers + */ +#define NET_BUFSIZE (4096 + 65536) + struct MACAddr { uint8_t a[6]; }; diff --git a/include/qemu-common.h b/include/qemu-common.h index 5e13708..31fff22 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -40,7 +40,7 @@ #include <sys/time.h> #include <assert.h> #include <signal.h> -#include <glib.h> +#include "glib-compat.h" #ifdef _WIN32 #include "sysemu/os-win32.h" @@ -442,4 +442,41 @@ int64_t pow2floor(int64_t value); int uleb128_encode_small(uint8_t *out, uint32_t n); int uleb128_decode_small(const uint8_t *in, uint32_t *n); +/* + * Hexdump a buffer to a file. An optional string prefix is added to every line + */ + +void hexdump(const char *buf, FILE *fp, const char *prefix, size_t size); + +/* vector definitions */ +#ifdef __ALTIVEC__ +#include <altivec.h> +#define VECTYPE vector unsigned char +#define SPLAT(p) vec_splat(vec_ld(0, p), 0) +#define ALL_EQ(v1, v2) vec_all_eq(v1, v2) +/* altivec.h may redefine the bool macro as vector type. + * Reset it to POSIX semantics. */ +#undef bool +#define bool _Bool +#elif defined __SSE2__ +#include <emmintrin.h> +#define VECTYPE __m128i +#define SPLAT(p) _mm_set1_epi8(*(p)) +#define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF) +#else +#define VECTYPE unsigned long +#define SPLAT(p) (*(p) * (~0UL / 255)) +#define ALL_EQ(v1, v2) ((v1) == (v2)) +#endif + +#define BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR 8 +static inline bool +can_use_buffer_find_nonzero_offset(const void *buf, size_t len) +{ + return (len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR + * sizeof(VECTYPE)) == 0 + && ((uintptr_t) buf) % sizeof(VECTYPE) == 0); +} +size_t buffer_find_nonzero_offset(const void *buf, size_t len); + #endif diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index ae5c21c..d225f6d 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -30,6 +30,8 @@ int inet_aton(const char *cp, struct in_addr *ia); #include "qapi/error.h" #include "qapi/qmp/qerror.h" +extern QemuOptsList socket_optslist; + /* misc helpers */ int qemu_socket(int domain, int type, int protocol); int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); @@ -45,6 +47,7 @@ int recv_all(int fd, void *buf, int len1, bool single_read); */ typedef void NonBlockingConnectHandler(int fd, void *opaque); +InetSocketAddress *inet_parse(const char *str, Error **errp); int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp); int inet_listen(const char *str, char *ostr, int olen, int socktype, int port_offset, Error **errp); diff --git a/include/qom/object.h b/include/qom/object.h index cf094e7..d0f99c5 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -202,7 +202,7 @@ typedef struct InterfaceInfo InterfaceInfo; * Methods are always <emphasis>virtual</emphasis>. Overriding a method in * #TypeInfo.class_init of a subclass leads to any user of the class obtained * via OBJECT_GET_CLASS() accessing the overridden function. - * The original function is not automatically invoked. It is the responsability + * The original function is not automatically invoked. It is the responsibility * of the overriding class to determine whether and when to invoke the method * being overridden. * diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 5fc780c..8c8d78e 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -20,6 +20,7 @@ enum { QEMU_ARCH_XTENSA = 4096, QEMU_ARCH_OPENRISC = 8192, QEMU_ARCH_UNICORE32 = 0x4000, + QEMU_ARCH_MOXIE = 0x8000, }; extern const uint32_t arch_type; diff --git a/include/ui/console.h b/include/ui/console.h index a37cf65..a234c72 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -147,31 +147,43 @@ void cursor_set_mono(QEMUCursor *c, void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask); void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask); -struct DisplayChangeListener { - int idle; - uint64_t gui_timer_interval; +typedef struct DisplayChangeListenerOps { + const char *dpy_name; - void (*dpy_refresh)(struct DisplayState *s); + void (*dpy_refresh)(DisplayChangeListener *dcl); - void (*dpy_gfx_update)(struct DisplayState *s, int x, int y, int w, int h); - void (*dpy_gfx_resize)(struct DisplayState *s); - void (*dpy_gfx_setdata)(struct DisplayState *s); - void (*dpy_gfx_copy)(struct DisplayState *s, int src_x, int src_y, + void (*dpy_gfx_update)(DisplayChangeListener *dcl, + int x, int y, int w, int h); + void (*dpy_gfx_switch)(DisplayChangeListener *dcl, + struct DisplaySurface *new_surface); + void (*dpy_gfx_copy)(DisplayChangeListener *dcl, + int src_x, int src_y, int dst_x, int dst_y, int w, int h); - void (*dpy_text_cursor)(struct DisplayState *s, int x, int y); - void (*dpy_text_resize)(struct DisplayState *s, int w, int h); - void (*dpy_text_update)(struct DisplayState *s, int x, int y, int w, int h); + void (*dpy_text_cursor)(DisplayChangeListener *dcl, + int x, int y); + void (*dpy_text_resize)(DisplayChangeListener *dcl, + int w, int h); + void (*dpy_text_update)(DisplayChangeListener *dcl, + int x, int y, int w, int h); - void (*dpy_mouse_set)(struct DisplayState *s, int x, int y, int on); - void (*dpy_cursor_define)(struct DisplayState *s, QEMUCursor *cursor); + void (*dpy_mouse_set)(DisplayChangeListener *dcl, + int x, int y, int on); + void (*dpy_cursor_define)(DisplayChangeListener *dcl, + QEMUCursor *cursor); +} DisplayChangeListenerOps; + +struct DisplayChangeListener { + int idle; + uint64_t gui_timer_interval; + const DisplayChangeListenerOps *ops; + DisplayState *ds; QLIST_ENTRY(DisplayChangeListener) next; }; struct DisplayState { struct DisplaySurface *surface; - void *opaque; struct QEMUTimer *gui_timer; bool have_gfx; bool have_text; @@ -189,11 +201,8 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, PixelFormat qemu_different_endianness_pixelformat(int bpp); PixelFormat qemu_default_pixelformat(int bpp); -DisplaySurface *qemu_create_displaysurface(DisplayState *ds, - int width, int height); -DisplaySurface *qemu_resize_displaysurface(DisplayState *ds, - int width, int height); -void qemu_free_displaysurface(DisplayState *ds); +DisplaySurface *qemu_create_displaysurface(int width, int height); +void qemu_free_displaysurface(DisplaySurface *surface); static inline int is_surface_bgr(DisplaySurface *surface) { @@ -210,208 +219,55 @@ static inline int is_buffer_shared(DisplaySurface *surface) void gui_setup_refresh(DisplayState *ds); -static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl) -{ - QLIST_INSERT_HEAD(&ds->listeners, dcl, next); - gui_setup_refresh(ds); - if (dcl->dpy_gfx_resize) { - dcl->dpy_gfx_resize(ds); - } -} - -static inline void unregister_displaychangelistener(DisplayState *ds, - DisplayChangeListener *dcl) -{ - QLIST_REMOVE(dcl, next); - gui_setup_refresh(ds); -} - -static inline void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h) -{ - struct DisplayChangeListener *dcl; - int width = pixman_image_get_width(s->surface->image); - int height = pixman_image_get_height(s->surface->image); - - x = MAX(x, 0); - y = MAX(y, 0); - x = MIN(x, width); - y = MIN(y, height); - w = MIN(w, width - x); - h = MIN(h, height - y); - - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_gfx_update) { - dcl->dpy_gfx_update(s, x, y, w, h); - } - } -} - -static inline void dpy_gfx_resize(DisplayState *s) +void register_displaychangelistener(DisplayState *ds, + DisplayChangeListener *dcl); +void unregister_displaychangelistener(DisplayChangeListener *dcl); + +void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h); +void dpy_gfx_replace_surface(QemuConsole *con, + DisplaySurface *surface); +void dpy_refresh(DisplayState *s); +void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y, + int dst_x, int dst_y, int w, int h); +void dpy_text_cursor(QemuConsole *con, int x, int y); +void dpy_text_update(QemuConsole *con, int x, int y, int w, int h); +void dpy_text_resize(QemuConsole *con, int w, int h); +void dpy_mouse_set(QemuConsole *con, int x, int y, int on); +void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor); +bool dpy_cursor_define_supported(QemuConsole *con); + +static inline int surface_stride(DisplaySurface *s) { - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_gfx_resize) { - dcl->dpy_gfx_resize(s); - } - } + return pixman_image_get_stride(s->image); } -static inline void dpy_gfx_setdata(DisplayState *s) +static inline void *surface_data(DisplaySurface *s) { - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_gfx_setdata) { - dcl->dpy_gfx_setdata(s); - } - } + return pixman_image_get_data(s->image); } -static inline void dpy_refresh(DisplayState *s) +static inline int surface_width(DisplaySurface *s) { - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_refresh) { - dcl->dpy_refresh(s); - } - } + return pixman_image_get_width(s->image); } -static inline void dpy_gfx_copy(struct DisplayState *s, int src_x, int src_y, - int dst_x, int dst_y, int w, int h) +static inline int surface_height(DisplaySurface *s) { - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_gfx_copy) { - dcl->dpy_gfx_copy(s, src_x, src_y, dst_x, dst_y, w, h); - } else { /* TODO */ - dcl->dpy_gfx_update(s, dst_x, dst_y, w, h); - } - } + return pixman_image_get_height(s->image); } -static inline void dpy_text_cursor(struct DisplayState *s, int x, int y) +static inline int surface_bits_per_pixel(DisplaySurface *s) { - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_text_cursor) { - dcl->dpy_text_cursor(s, x, y); - } - } -} - -static inline void dpy_text_update(DisplayState *s, int x, int y, int w, int h) -{ - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_text_update) { - dcl->dpy_text_update(s, x, y, w, h); - } - } -} - -static inline void dpy_text_resize(DisplayState *s, int w, int h) -{ - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_text_resize) { - dcl->dpy_text_resize(s, w, h); - } - } -} - -static inline void dpy_mouse_set(struct DisplayState *s, int x, int y, int on) -{ - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_mouse_set) { - dcl->dpy_mouse_set(s, x, y, on); - } - } -} - -static inline void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor) -{ - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_cursor_define) { - dcl->dpy_cursor_define(s, cursor); - } - } -} - -static inline bool dpy_cursor_define_supported(struct DisplayState *s) -{ - struct DisplayChangeListener *dcl; - QLIST_FOREACH(dcl, &s->listeners, next) { - if (dcl->dpy_cursor_define) { - return true; - } - } - return false; -} - -static inline int ds_get_linesize(DisplayState *ds) -{ - return pixman_image_get_stride(ds->surface->image); -} - -static inline uint8_t* ds_get_data(DisplayState *ds) -{ - return (void *)pixman_image_get_data(ds->surface->image); -} - -static inline int ds_get_width(DisplayState *ds) -{ - return pixman_image_get_width(ds->surface->image); -} - -static inline int ds_get_height(DisplayState *ds) -{ - return pixman_image_get_height(ds->surface->image); -} - -static inline int ds_get_bits_per_pixel(DisplayState *ds) -{ - int bits = PIXMAN_FORMAT_BPP(ds->surface->format); + int bits = PIXMAN_FORMAT_BPP(s->format); return bits; } -static inline int ds_get_bytes_per_pixel(DisplayState *ds) +static inline int surface_bytes_per_pixel(DisplaySurface *s) { - int bits = PIXMAN_FORMAT_BPP(ds->surface->format); + int bits = PIXMAN_FORMAT_BPP(s->format); return (bits + 7) / 8; } -static inline pixman_format_code_t ds_get_format(DisplayState *ds) -{ - return ds->surface->format; -} - -static inline pixman_image_t *ds_get_image(DisplayState *ds) -{ - return ds->surface->image; -} - -static inline int ds_get_depth(DisplayState *ds) -{ - return ds->surface->pf.depth; -} - -static inline int ds_get_rmask(DisplayState *ds) -{ - return ds->surface->pf.rmask; -} - -static inline int ds_get_gmask(DisplayState *ds) -{ - return ds->surface->pf.gmask; -} - -static inline int ds_get_bmask(DisplayState *ds) -{ - return ds->surface->pf.bmask; -} - #ifdef CONFIG_CURSES #include <curses.h> typedef chtype console_ch_t; @@ -431,11 +287,11 @@ typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch, Error **errp); typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *); -DisplayState *graphic_console_init(vga_hw_update_ptr update, - vga_hw_invalidate_ptr invalidate, - vga_hw_screen_dump_ptr screen_dump, - vga_hw_text_update_ptr text_update, - void *opaque); +QemuConsole *graphic_console_init(vga_hw_update_ptr update, + vga_hw_invalidate_ptr invalidate, + vga_hw_screen_dump_ptr screen_dump, + vga_hw_text_update_ptr text_update, + void *opaque); void vga_hw_update(void); void vga_hw_invalidate(void); @@ -446,9 +302,11 @@ int is_fixedsize_console(void); void text_consoles_set_display(DisplayState *ds); void console_select(unsigned int index); void console_color_init(DisplayState *ds); -void qemu_console_resize(DisplayState *ds, int width, int height); -void qemu_console_copy(DisplayState *ds, int src_x, int src_y, +void qemu_console_resize(QemuConsole *con, int width, int height); +void qemu_console_copy(QemuConsole *con, int src_x, int src_y, int dst_x, int dst_y, int w, int h); +DisplaySurface *qemu_console_surface(QemuConsole *con); +DisplayState *qemu_console_displaystate(QemuConsole *console); typedef CharDriverState *(VcHandler)(ChardevVC *vc); diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h index 46f9530..7a20fc4 100644 --- a/include/ui/spice-display.h +++ b/include/ui/spice-display.h @@ -71,7 +71,9 @@ typedef struct SimpleSpiceDisplay SimpleSpiceDisplay; typedef struct SimpleSpiceUpdate SimpleSpiceUpdate; struct SimpleSpiceDisplay { - DisplayState *ds; + QemuConsole *con; + DisplaySurface *ds; + DisplayChangeListener dcl; void *buf; int bufsize; QXLWorker *worker; @@ -112,11 +114,12 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd); void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd); void qemu_spice_vm_change_state_handler(void *opaque, int running, RunState state); -void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds); +void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd); void qemu_spice_display_update(SimpleSpiceDisplay *ssd, int x, int y, int w, int h); -void qemu_spice_display_resize(SimpleSpiceDisplay *ssd); +void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, + DisplaySurface *surface); void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd); void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd); |