From patchwork Wed Oct 26 11:42:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 9396661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9266C60231 for ; Wed, 26 Oct 2016 11:58:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D69429AF5 for ; Wed, 26 Oct 2016 11:58:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51D5A29AF9; Wed, 26 Oct 2016 11:58:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3EF2829AF5 for ; Wed, 26 Oct 2016 11:58:15 +0000 (UTC) Received: from localhost ([::1]:33517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzMqU-0001wK-F9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Oct 2016 07:58:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzMcU-0007Gs-QI for qemu-devel@nongnu.org; Wed, 26 Oct 2016 07:43:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzMcS-0004X1-P9 for qemu-devel@nongnu.org; Wed, 26 Oct 2016 07:43:46 -0400 Received: from ozlabs.org ([103.22.144.67]:43819) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzMcS-0004VM-50; Wed, 26 Oct 2016 07:43:44 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3t3p6z5s5Dz9t1Y; Wed, 26 Oct 2016 22:43:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1477482187; bh=paiyvvYB+27Nq8P293pWlO1lGtIIqyQhYg9ho4GI2DQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PkxOmflKqtEEkugKVAJcGetdEzYeJVM7d24TabJuBNIndy88nMreISPS7Ueed5mZq L1lMFweH7ocqrQvgDtKymaarr765xQ0t9xkghWjjfUGf+3x3yaLHto76pO+G/S/6/b 2v7I3FNO5nbg/KcXdSxKxgMs4SPfdvTir1jWgiec= From: David Gibson To: peter.maydell@linaro.org Date: Wed, 26 Oct 2016 22:42:16 +1100 Message-Id: <1477482173-8761-13-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477482173-8761-1-git-send-email-david@gibson.dropbear.id.au> References: <1477482173-8761-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 12/49] nvram: Move the remaining CHRP NVRAM related code to chrp_nvram.[ch] X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, thuth@redhat.com, aik@ozlabs.ru, mark.cave-ayland@ilande.co.uk, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thomas Huth Everything that is related to CHRP NVRAM should rather reside in chrp_nvram.c / chrp_nvram.h instead of openbios_firmware_abi.h. Signed-off-by: Thomas Huth Tested-by: Mark Cave-Ayland Signed-off-by: David Gibson --- hw/nvram/chrp_nvram.c | 31 +++++++++++++++--------- hw/nvram/mac_nvram.c | 7 +++--- include/hw/nvram/chrp_nvram.h | 30 +++++++++++++++++++++++ include/hw/nvram/openbios_firmware_abi.h | 41 -------------------------------- tests/postcopy-test.c | 8 +++---- 5 files changed, 57 insertions(+), 60 deletions(-) diff --git a/hw/nvram/chrp_nvram.c b/hw/nvram/chrp_nvram.c index f6183ed..3837510 100644 --- a/hw/nvram/chrp_nvram.c +++ b/hw/nvram/chrp_nvram.c @@ -23,26 +23,35 @@ #include "qemu/cutils.h" #include "hw/hw.h" #include "hw/nvram/chrp_nvram.h" -#include "hw/nvram/openbios_firmware_abi.h" #include "sysemu/sysemu.h" +static int chrp_nvram_set_var(uint8_t *nvram, int addr, const char *str) +{ + int len; + + len = strlen(str) + 1; + memcpy(&nvram[addr], str, len); + + return addr + len; +} + /** * Create a "system partition", used for the Open Firmware * environment variables. */ int chrp_nvram_create_system_partition(uint8_t *data, int min_len) { - struct OpenBIOS_nvpart_v1 *part_header; + ChrpNvramPartHdr *part_header; unsigned int i; int end; - part_header = (struct OpenBIOS_nvpart_v1 *)data; - part_header->signature = OPENBIOS_PART_SYSTEM; + part_header = (ChrpNvramPartHdr *)data; + part_header->signature = CHRP_NVPART_SYSTEM; pstrcpy(part_header->name, sizeof(part_header->name), "system"); - end = sizeof(struct OpenBIOS_nvpart_v1); + end = sizeof(ChrpNvramPartHdr); for (i = 0; i < nb_prom_envs; i++) { - end = OpenBIOS_set_var(data, end, prom_envs[i]); + end = chrp_nvram_set_var(data, end, prom_envs[i]); } /* End marker */ @@ -54,7 +63,7 @@ int chrp_nvram_create_system_partition(uint8_t *data, int min_len) if (end < min_len) { end = min_len; } - OpenBIOS_finish_partition(part_header, end); + chrp_nvram_finish_partition(part_header, end); return end; } @@ -64,13 +73,13 @@ int chrp_nvram_create_system_partition(uint8_t *data, int min_len) */ int chrp_nvram_create_free_partition(uint8_t *data, int len) { - struct OpenBIOS_nvpart_v1 *part_header; + ChrpNvramPartHdr *part_header; - part_header = (struct OpenBIOS_nvpart_v1 *)data; - part_header->signature = OPENBIOS_PART_FREE; + part_header = (ChrpNvramPartHdr *)data; + part_header->signature = CHRP_NVPART_FREE; pstrcpy(part_header->name, sizeof(part_header->name), "free"); - OpenBIOS_finish_partition(part_header, len); + chrp_nvram_finish_partition(part_header, len); return len; } diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c index c0e62a5..63f9ed1 100644 --- a/hw/nvram/mac_nvram.c +++ b/hw/nvram/mac_nvram.c @@ -24,7 +24,6 @@ */ #include "qemu/osdep.h" #include "hw/hw.h" -#include "hw/nvram/openbios_firmware_abi.h" #include "hw/nvram/chrp_nvram.h" #include "hw/ppc/mac.h" #include "qemu/cutils.h" @@ -163,15 +162,15 @@ static void pmac_format_nvram_partition_osx(MacIONVRAMState *nvr, int off, int len) { uint32_t start = off; - struct OpenBIOS_nvpart_v1 *part_header; + ChrpNvramPartHdr *part_header; unsigned char *data = &nvr->data[start]; /* empty partition */ - part_header = (struct OpenBIOS_nvpart_v1 *)data; + part_header = (ChrpNvramPartHdr *)data; part_header->signature = OSX_NVRAM_SIGNATURE; pstrcpy(part_header->name, sizeof(part_header->name), "wwwwwwwwwwww"); - OpenBIOS_finish_partition(part_header, len); + chrp_nvram_finish_partition(part_header, len); /* Generation */ stl_be_p(&data[20], 2); diff --git a/include/hw/nvram/chrp_nvram.h b/include/hw/nvram/chrp_nvram.h index 18d1976..b4f5b2b 100644 --- a/include/hw/nvram/chrp_nvram.h +++ b/include/hw/nvram/chrp_nvram.h @@ -18,6 +18,36 @@ #ifndef CHRP_NVRAM_H #define CHRP_NVRAM_H +/* OpenBIOS NVRAM partition */ +typedef struct { + uint8_t signature; + uint8_t checksum; + uint16_t len; /* Big endian, length divided by 16 */ + char name[12]; +} ChrpNvramPartHdr; + +#define CHRP_NVPART_SYSTEM 0x70 +#define CHRP_NVPART_FREE 0x7f + +static inline void +chrp_nvram_finish_partition(ChrpNvramPartHdr *header, uint32_t size) +{ + unsigned int i, sum; + uint8_t *tmpptr; + + /* Length divided by 16 */ + header->len = cpu_to_be16(size >> 4); + + /* Checksum */ + tmpptr = (uint8_t *)header; + sum = *tmpptr; + for (i = 0; i < 14; i++) { + sum += tmpptr[2 + i]; + sum = (sum + ((sum & 0xff00) >> 8)) & 0xff; + } + header->checksum = sum & 0xff; +} + int chrp_nvram_create_system_partition(uint8_t *data, int min_len); int chrp_nvram_create_free_partition(uint8_t *data, int len); diff --git a/include/hw/nvram/openbios_firmware_abi.h b/include/hw/nvram/openbios_firmware_abi.h index 74cfd56..27ce9f4 100644 --- a/include/hw/nvram/openbios_firmware_abi.h +++ b/include/hw/nvram/openbios_firmware_abi.h @@ -1,47 +1,6 @@ #ifndef OPENBIOS_FIRMWARE_ABI_H #define OPENBIOS_FIRMWARE_ABI_H -/* OpenBIOS NVRAM partition */ -struct OpenBIOS_nvpart_v1 { - uint8_t signature; - uint8_t checksum; - uint16_t len; // BE, length divided by 16 - char name[12]; -}; - -#define OPENBIOS_PART_SYSTEM 0x70 -#define OPENBIOS_PART_FREE 0x7f - -static inline void -OpenBIOS_finish_partition(struct OpenBIOS_nvpart_v1 *header, uint32_t size) -{ - unsigned int i, sum; - uint8_t *tmpptr; - - // Length divided by 16 - header->len = cpu_to_be16(size >> 4); - - // Checksum - tmpptr = (uint8_t *)header; - sum = *tmpptr; - for (i = 0; i < 14; i++) { - sum += tmpptr[2 + i]; - sum = (sum + ((sum & 0xff00) >> 8)) & 0xff; - } - header->checksum = sum & 0xff; -} - -static inline uint32_t -OpenBIOS_set_var(uint8_t *nvram, uint32_t addr, const char *str) -{ - uint32_t len; - - len = strlen(str) + 1; - memcpy(&nvram[addr], str, len); - - return addr + len; -} - /* Sun IDPROM structure at the end of NVRAM */ /* from http://www.squirrel.com/squirrel/sun-nvram-hostid.faq.html */ struct Sun_nvram { diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 41ed1a9..d6613c5 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -18,7 +18,7 @@ #include "qemu/sockets.h" #include "sysemu/char.h" #include "sysemu/sysemu.h" -#include "hw/nvram/openbios_firmware_abi.h" +#include "hw/nvram/chrp_nvram.h" #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ @@ -137,15 +137,15 @@ static void init_bootfile_ppc(const char *bootpath) { FILE *bootfile; char buf[MIN_NVRAM_SIZE]; - struct OpenBIOS_nvpart_v1 *header = (struct OpenBIOS_nvpart_v1 *)buf; + ChrpNvramPartHdr *header = (ChrpNvramPartHdr *)buf; memset(buf, 0, MIN_NVRAM_SIZE); /* Create a "common" partition in nvram to store boot-command property */ - header->signature = OPENBIOS_PART_SYSTEM; + header->signature = CHRP_NVPART_SYSTEM; memcpy(header->name, "common", 6); - OpenBIOS_finish_partition(header, MIN_NVRAM_SIZE); + chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE); /* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB, * so let's modify memory between 1MB and 100MB