From patchwork Fri Mar 22 18:02:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15556 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 59A0523E2C for ; Fri, 22 Mar 2013 18:03:01 +0000 (UTC) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by fiordland.canonical.com (Postfix) with ESMTP id E58E2A18356 for ; Fri, 22 Mar 2013 18:03:00 +0000 (UTC) Received: by mail-vc0-f174.google.com with SMTP id hx10so3339970vcb.33 for ; Fri, 22 Mar 2013 11:03:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=7dM1QbONJY/kznilBN7st24f22+Ve64Gcls7eJquZis=; b=lGBCza8n3oV7IfKnUIL+4KOZbKW7jm3bZsIXZVd6H0lC5UadpRfvmmIQvktFFLz/Yc TJTDi8NsswIDJT3i5EWphoz6Qr0x/RDAK4/rJf6E3cBVSg6d1+wgsJ7yLVKBonPkMP41 yme+BG7rlQDPtohHVSKZQK3nj3+NK84ZVlA/ZkZNKOBk77mOrVdWd1/Rf3A1CmRr/2+H bb3zxkv8YRCOPmFSxKwNkCCnc6HtbExhiFHGaKBWQVCqm6bh8Ym3y+XIQA9d9PT98lKF 3lY1K23Z6Rnk17xUPH+lG/8EXswPyPff+pmWC/WuoROKEbasHdC2ZJhzm8cxR65Shjw2 IHVw== X-Received: by 10.58.207.163 with SMTP id lx3mr3478503vec.35.1363975380379; Fri, 22 Mar 2013 11:03:00 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.233.198 with SMTP id ty6csp104219vec; Fri, 22 Mar 2013 11:02:59 -0700 (PDT) X-Received: by 10.180.8.4 with SMTP id n4mr4717197wia.13.1363975378838; Fri, 22 Mar 2013 11:02:58 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id fc8si3406814wib.16.2013.03.22.11.02.58 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 22 Mar 2013 11:02:58 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UJ6Ip-0000pX-Eh; Fri, 22 Mar 2013 18:02:55 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Igor Mitsyanko , Gerd Hoffmann Subject: [PATCH v3 1/3] vmstate: Add support for two dimensional arrays Date: Fri, 22 Mar 2013 18:02:53 +0000 Message-Id: <1363975375-3166-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1363975375-3166-1-git-send-email-peter.maydell@linaro.org> References: <1363975375-3166-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQn9BRy1w73d6nRO8eL15wdnGNLRDBeygIGdOHfcCqODHuEIXr+rem0MgD2NDOsBIv2PN1La Add support for migrating two dimensional arrays, by defining a set of new macros VMSTATE_*_2DARRAY paralleling the existing VMSTATE_*_ARRAY macros. 2D arrays are handled the same for actual state serialization; the only difference is that the type check has to change for a 2D array. Signed-off-by: Peter Maydell Reviewed-by: Igor Mitsyanko --- include/migration/vmstate.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 6666d27..24bc537 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -161,6 +161,7 @@ extern const VMStateInfo vmstate_info_buffer; extern const VMStateInfo vmstate_info_unused_buffer; extern const VMStateInfo vmstate_info_bitmap; +#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) @@ -176,6 +177,10 @@ extern const VMStateInfo vmstate_info_bitmap; (offsetof(_state, _field) + \ type_check_array(_type, typeof_field(_state, _field), _num)) +#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2) \ + (offsetof(_state, _field) + \ + type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2)) + #define vmstate_offset_sub_array(_state, _field, _type, _start) \ (offsetof(_state, _field[_start])) @@ -221,6 +226,16 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = vmstate_offset_array(_state, _field, _type, _num), \ } +#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .num = (_n1) * (_n2), \ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_ARRAY, \ + .offset = vmstate_offset_2darray(_state, _field, _type, _n1, _n2), \ +} + #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\ .name = (stringify(_field)), \ .field_exists = (_test), \ @@ -554,15 +569,27 @@ extern const VMStateInfo vmstate_info_bitmap; #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t) +#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v) \ + VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t) + #define VMSTATE_UINT16_ARRAY(_f, _s, _n) \ VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2) \ + VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0) + +#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \ + VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t) + #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t) #define VMSTATE_UINT8_ARRAY(_f, _s, _n) \ VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2) \ + VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0) + #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \ VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)