From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSnns-0004b6-Bm for qemu-devel@nongnu.org; Sat, 04 Jun 2011 06:10:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSnnq-0005VS-Sg for qemu-devel@nongnu.org; Sat, 04 Jun 2011 06:10:00 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:50293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSnnq-0005VN-FF for qemu-devel@nongnu.org; Sat, 04 Jun 2011 06:09:58 -0400 Received: by qwj8 with SMTP id 8so1342530qwj.4 for ; Sat, 04 Jun 2011 03:09:57 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20110531062019.4A610524F@gandalf.tls.msk.ru> References: <20110531062019.4A610524F@gandalf.tls.msk.ru> From: Blue Swirl Date: Sat, 4 Jun 2011 13:09:37 +0300 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5] [resend 2] revamp acpitable parsing and allow to specify complete (headerful) table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev Cc: Isaku Yamahata , qemu-devel@nongnu.org On Thu, May 12, 2011 at 5:44 PM, Michael Tokarev wrote: > Since I've got no comments/replies whatsoever, -- neither > positive nor negative, I assume no one received this email > (sent on Thu, 12 May 2011, and one more time on Fri, 20 > May 2011), so I'am resending it yet again. =C2=A0The patch > still applies to qemu/master. > > This patch almost rewrites acpi_table_add() function > (but still leaves it using old get_param_value() interface). > The result is that it's now possible to specify whole table > (together with a header) in an external file, instead of just > data portion, with a new file=3D parameter, but at the same time > it's still possible to specify header fields as before. > > Now with the checkpatch.pl formatting fixes, thanks to > Stefan Hajnoczi for suggestions, with changes from > Isaku Yamahata, and with my further refinements. > > v5: rediffed against current qemu/master. > > Signed-off-by: Michael Tokarev > --- > =C2=A0hw/acpi.c =C2=A0 =C2=A0 =C2=A0 | =C2=A0292 ++++++++++++++++++++++++= ++++++++----------------------- > =C2=A0qemu-options.hx | =C2=A0 =C2=A07 +- > =C2=A02 files changed, 175 insertions(+), 124 deletions(-) > > diff --git a/hw/acpi.c b/hw/acpi.c > index ad40fb4..4316189 100644 > --- a/hw/acpi.c > +++ b/hw/acpi.c > @@ -22,17 +22,29 @@ > > =C2=A0struct acpi_table_header > =C2=A0{ > - =C2=A0 =C2=A0char signature [4]; =C2=A0 =C2=A0/* ACPI signature (4 ASCI= I characters) */ > + =C2=A0 =C2=A0uint16_t _length; =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* our lengt= h, not actual part of the hdr */ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* XXX why we have 2 length fields here? = */ > + =C2=A0 =C2=A0char sig[4]; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0/* ACPI signature (4 ASCII characters) */ > =C2=A0 =C2=A0 uint32_t length; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Lengt= h of table, in bytes, including header */ > =C2=A0 =C2=A0 uint8_t revision; =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* ACPI Speci= fication minor version # */ > =C2=A0 =C2=A0 uint8_t checksum; =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* To make su= m of entire table =3D=3D 0 */ > - =C2=A0 =C2=A0char oem_id [6]; =C2=A0 =C2=A0 =C2=A0 /* OEM identificatio= n */ > - =C2=A0 =C2=A0char oem_table_id [8]; /* OEM table identification */ > + =C2=A0 =C2=A0char oem_id[6]; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* OEM = identification */ > + =C2=A0 =C2=A0char oem_table_id[8]; =C2=A0 =C2=A0 /* OEM table identific= ation */ > =C2=A0 =C2=A0 uint32_t oem_revision; =C2=A0 =C2=A0/* OEM revision number = */ > - =C2=A0 =C2=A0char asl_compiler_id [4]; /* ASL compiler vendor ID */ > + =C2=A0 =C2=A0char asl_compiler_id[4]; =C2=A0/* ASL compiler vendor ID *= / > =C2=A0 =C2=A0 uint32_t asl_compiler_revision; /* ASL compiler revision nu= mber */ > =C2=A0} __attribute__((packed)); > > +#define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header) > +#define ACPI_TABLE_PFX_SIZE sizeof(uint16_t) =C2=A0/* size of the extra = prefix */ > + > +static const char dfl_hdr[ACPI_TABLE_HDR_SIZE] =3D > + =C2=A0 =C2=A0"\0\0" =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 /* fake _length (2) */ > + =C2=A0 =C2=A0"QEMU\0\0\0\0\1\0" =C2=A0 =C2=A0 =C2=A0 /* sig (4), len(4)= , revno (1), csum (1) */ > + =C2=A0 =C2=A0"QEMUQEQEMUQEMU\1\0\0\0" /* OEM id (6), table (8), revno (= 4) */ > + =C2=A0 =C2=A0"QEMU\1\0\0\0" =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* ASL c= ompiler ID (4), version (4) */ > + =C2=A0 =C2=A0; > + > =C2=A0char *acpi_tables; > =C2=A0size_t acpi_tables_len; > > @@ -45,158 +57,192 @@ static int acpi_checksum(const uint8_t *data, int l= en) > =C2=A0 =C2=A0 return (-sum) & 0xff; > =C2=A0} > > +/* like strncpy() but zero-fills the tail of destination */ > +static void strzcpy(char *dst, const char *src, size_t size) > +{ > + =C2=A0 =C2=A0size_t len =3D strlen(src); > + =C2=A0 =C2=A0if (len >=3D size) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0len =3D size; > + =C2=A0 =C2=A0} else { > + =C2=A0 =C2=A0 =C2=A0memset(dst + len, 0, size - len); > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0memcpy(dst, src, len); > +} > + > +/* XXX fixme: this function uses obsolete argument parsing interface */ > =C2=A0int acpi_table_add(const char *t) > =C2=A0{ > - =C2=A0 =C2=A0static const char *dfl_id =3D "QEMUQEMU"; > =C2=A0 =C2=A0 char buf[1024], *p, *f; > - =C2=A0 =C2=A0struct acpi_table_header acpi_hdr; > =C2=A0 =C2=A0 unsigned long val; > - =C2=A0 =C2=A0uint32_t length; > - =C2=A0 =C2=A0struct acpi_table_header *acpi_hdr_p; > - =C2=A0 =C2=A0size_t off; > + =C2=A0 =C2=A0size_t len, start, allen; > + =C2=A0 =C2=A0bool has_header; > + =C2=A0 =C2=A0int changed; > + =C2=A0 =C2=A0int r; > + =C2=A0 =C2=A0struct acpi_table_header hdr; > + > + =C2=A0 =C2=A0r =3D 0; > + =C2=A0 =C2=A0r |=3D get_param_value(buf, sizeof(buf), "data", t) ? 1 : = 0; > + =C2=A0 =C2=A0r |=3D get_param_value(buf, sizeof(buf), "file", t) ? 2 : = 0; > + =C2=A0 =C2=A0switch (r) { > + =C2=A0 =C2=A0case 0: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0buf[0] =3D '\0'; > + =C2=A0 =C2=A0case 1: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0has_header =3D false; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0case 2: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0has_header =3D true; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > + =C2=A0 =C2=A0default: > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "acpitable: both data and fi= le are specified\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1; > + =C2=A0 =C2=A0} > + > + =C2=A0 =C2=A0if (!acpi_tables) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0allen =3D sizeof(uint16_t); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0acpi_tables =3D qemu_mallocz(allen); > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0else { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0allen =3D acpi_tables_len; > + =C2=A0 =C2=A0} ERROR: else should follow close brace '}' #173: FILE: hw/acpi.c:104: + } + else {