From patchwork Tue Mar 30 08:20:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard - Gabriel Munteanu X-Patchwork-Id: 89248 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2U8Kagd006165 for ; Tue, 30 Mar 2010 08:20:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755907Ab0C3IUb (ORCPT ); Tue, 30 Mar 2010 04:20:31 -0400 Received: from mail-bw0-f209.google.com ([209.85.218.209]:33744 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755351Ab0C3IU0 (ORCPT ); Tue, 30 Mar 2010 04:20:26 -0400 Received: by bwz1 with SMTP id 1so4153677bwz.21 for ; Tue, 30 Mar 2010 01:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=ewhAw7CfxrRYOx4IhCjnfwTV+neFcAdRLzLA3v4Suv4=; b=G8WfChRx6BJvoKxClrgQ3UWqFwoGUO1Oc+boc76Mei3ZknwE+nmjSyGLIzO5NBhLwG g8IHaX7G/u30yo9fzA6Vg5lNtrEcSOYmhZo9oZAdnNbtYu2ixuNwA3ZMK/UM39SQCKNm OxPs2kY5Uit2nXwgdsMi7WWu0T7ZA3pi5aafo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=N+jOXcHMjzdx3e2mCY5tjfqjOF4HrXlXTjFG13BJd7nDBeXEAQarWUOzpI9LMO7/+4 N1mLm/MufhskV+QxDLunZkvx18hTImw/LOw1ZsgUEw8j9X3DMfaKUycTgYmvYPWyHSYM sH9Tiy3HZTZ8k/owuKyg+VTonz0fiZT29ZfO0= Received: by 10.204.151.71 with SMTP id b7mr4307470bkw.104.1269937224897; Tue, 30 Mar 2010 01:20:24 -0700 (PDT) Received: from localhost.localdomain ([188.25.93.130]) by mx.google.com with ESMTPS id 16sm2589620bwz.9.2010.03.30.01.20.24 (version=SSLv3 cipher=RC4-MD5); Tue, 30 Mar 2010 01:20:24 -0700 (PDT) From: Eduard - Gabriel Munteanu To: joro@8bytes.org Cc: aliguori@us.ibm.com, avi@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, Eduard - Gabriel Munteanu Subject: [RFC PATCH 2/7] acpi: split and rename acpi_table_add() Date: Tue, 30 Mar 2010 11:20:03 +0300 Message-Id: <972d931f99c27de91d043b1332eb564e6b4260db.1269936879.git.eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.6.4.4 In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 30 Mar 2010 08:20:36 +0000 (UTC) diff --git a/hw/acpi.c b/hw/acpi.c index 7c4e8d3..8eb53da 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -840,7 +840,7 @@ struct acpi_table_header } __attribute__((packed)); char *acpi_tables; -size_t acpi_tables_len; +size_t acpi_tables_len, acpi_tables_prev_len; static int acpi_checksum(const uint8_t *data, int len) { @@ -851,13 +851,44 @@ static int acpi_checksum(const uint8_t *data, int len) return (-sum) & 0xff; } -int acpi_table_add(const char *t) +void *acpi_alloc_table(size_t size) +{ + void *ptr; + + if (!acpi_tables) { + acpi_tables_len = sizeof(uint16_t); + acpi_tables = qemu_mallocz(acpi_tables_len); + } + acpi_tables_prev_len = acpi_tables_len; + acpi_tables_len += sizeof(uint16_t) + size; + acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len); + ptr = acpi_tables + acpi_tables_prev_len; + + *(uint16_t *) ptr = size; + + return ptr + sizeof(uint16_t); +} + +void acpi_commit_table(void *buf) +{ + struct acpi_table_header *acpi_hdr = buf; + size_t size = acpi_tables_len - acpi_tables_prev_len - sizeof(uint16_t); + + acpi_hdr->length = cpu_to_le32(size); + acpi_hdr->checksum = acpi_checksum(buf, size); + + /* increase number of tables */ + (*(uint16_t *) acpi_tables) = + cpu_to_le32(le32_to_cpu(*(uint16_t *) acpi_tables) + 1); +} + +int acpi_table_cmdline_add(const char *t) { static const char *dfl_id = "QEMUQEMU"; char buf[1024], *p, *f; struct acpi_table_header acpi_hdr; unsigned long val; - size_t newlen, off; + size_t size, off; memset(&acpi_hdr, 0, sizeof(acpi_hdr)); @@ -915,7 +946,7 @@ int acpi_table_add(const char *t) buf[0] = '\0'; } - acpi_hdr.length = sizeof(acpi_hdr); + size = sizeof(acpi_hdr); f = buf; while (buf[0]) { @@ -927,27 +958,17 @@ int acpi_table_add(const char *t) fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno)); goto out; } - acpi_hdr.length += s.st_size; + size += s.st_size; if (!n) break; *n = ':'; f = n + 1; } - if (!acpi_tables) { - acpi_tables_len = sizeof(uint16_t); - acpi_tables = qemu_mallocz(acpi_tables_len); - } - newlen = acpi_tables_len + sizeof(uint16_t) + acpi_hdr.length; - acpi_tables = qemu_realloc(acpi_tables, newlen); - p = acpi_tables + acpi_tables_len; - acpi_tables_len = newlen; + p = acpi_alloc_table(size); + off = sizeof(struct acpi_table_header); - acpi_hdr.length = cpu_to_le32(acpi_hdr.length); - *(uint16_t*)p = acpi_hdr.length; - p += sizeof(uint16_t); - memcpy(p, &acpi_hdr, sizeof(acpi_hdr)); - off = sizeof(acpi_hdr); + memcpy(p, &acpi_hdr, off); f = buf; while (buf[0]) { @@ -983,10 +1004,8 @@ int acpi_table_add(const char *t) f = n + 1; } - ((struct acpi_table_header*)p)->checksum = acpi_checksum((uint8_t*)p, off); - /* increase number of tables */ - (*(uint16_t*)acpi_tables) = - cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1); + acpi_commit_table(p); + return 0; out: if (acpi_tables) { @@ -995,3 +1014,4 @@ out: } return -1; } + diff --git a/hw/pc.h b/hw/pc.h index b599564..0cef140 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -108,7 +108,9 @@ extern char *acpi_tables; extern size_t acpi_tables_len; void acpi_bios_init(void); -int acpi_table_add(const char *table_desc); +void *acpi_alloc_table(size_t size); +void acpi_commit_table(void *buf); +int acpi_table_cmdline_add(const char *table_desc); /* acpi_piix.c */ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, diff --git a/vl.c b/vl.c index d959fdb..0efba90 100644 --- a/vl.c +++ b/vl.c @@ -5492,7 +5492,7 @@ int main(int argc, char **argv, char **envp) rtc_td_hack = 1; break; case QEMU_OPTION_acpitable: - if(acpi_table_add(optarg) < 0) { + if(acpi_table_cmdline_add(optarg) < 0) { fprintf(stderr, "Wrong acpi table provided\n"); exit(1); }