From patchwork Mon Aug 29 15:50:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 112096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0DD73B6F83 for ; Tue, 30 Aug 2011 01:50:51 +1000 (EST) Received: from localhost ([::1]:56907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy46q-0003mw-6M for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2011 11:50:48 -0400 Received: from eggs.gnu.org ([140.186.70.92]:58326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy46j-0003mK-BH for qemu-devel@nongnu.org; Mon, 29 Aug 2011 11:50:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qy46h-0004mz-9z for qemu-devel@nongnu.org; Mon, 29 Aug 2011 11:50:41 -0400 Received: from goliath.siemens.de ([192.35.17.28]:34274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy46h-0004mk-1S for qemu-devel@nongnu.org; Mon, 29 Aug 2011 11:50:39 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id p7TFoC1D017578; Mon, 29 Aug 2011 17:50:12 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p7TFoAdX027980; Mon, 29 Aug 2011 17:50:11 +0200 Message-ID: <4E5BB532.4010106@siemens.com> Date: Mon, 29 Aug 2011 17:50:10 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: "Kevin O'Connor" , seabios X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.28 Cc: Andrew Theurer , Gleb Natapov , ya su , Alexander Graf , qemu-devel , Avi Kivity Subject: [Qemu-devel] [PATCH] Probe HPET existence X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org QEMU does not provide a HPET block if it was configured with -no-hpet, other machines SeaBIOS runs on may lack a HPET as well. Perform basic checks the ID register for a reasonable vendor ID and a clock period within the valid range, do not build the HPET table if that fails. Signed-off-by: Jan Kiszka --- This allows to postpone the hpet_fw_cfg vs. ACPI discussion until we have >1 HPET blocks and/or put them at non-standard addresses. src/acpi.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index ea7b171..29160f4 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -158,6 +158,9 @@ struct acpi_20_hpet { } PACKED; #define ACPI_HPET_ADDRESS 0xFED00000UL +#define HPET_ID 0x000 +#define HPET_PERIOD 0x004 + /* * SRAT (NUMA topology description) table */ @@ -464,7 +467,16 @@ build_ssdt(void) static void* build_hpet(void) { - struct acpi_20_hpet *hpet = malloc_high(sizeof(*hpet)); + struct acpi_20_hpet *hpet; + const void *hpet_base = (void *)ACPI_HPET_ADDRESS; + u32 hpet_vendor = readl(hpet_base + HPET_ID) >> 16; + u32 hpet_period = readl(hpet_base + HPET_PERIOD); + + if (hpet_vendor == 0 || hpet_vendor == 0xffff || + hpet_period == 0 || hpet_period > 0x05F5E100) + return NULL; + + hpet = malloc_high(sizeof(*hpet)); if (!hpet) { warn_noalloc(); return NULL;