From patchwork Sun Jan 1 16:37:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 9492925 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 8B56E60416 for ; Sun, 1 Jan 2017 16:37:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7769A1FF35 for ; Sun, 1 Jan 2017 16:37:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C4D5223B2; Sun, 1 Jan 2017 16:37:58 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A88A1FF35 for ; Sun, 1 Jan 2017 16:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932335AbdAAQhz (ORCPT ); Sun, 1 Jan 2017 11:37:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46636 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932318AbdAAQhl (ORCPT ); Sun, 1 Jan 2017 11:37:41 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3E5D68F22E for ; Sun, 1 Jan 2017 16:37:42 +0000 (UTC) Received: from dhcp-27-118.brq.redhat.com (dhcp-27-122.brq.redhat.com [10.34.27.122]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v01GbZLN019089; Sun, 1 Jan 2017 11:37:41 -0500 From: Alexander Gordeev To: kvm@vger.kernel.org Cc: Alexander Gordeev , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [kvm-unit-tests RFC PATCH 05/10] x86: Find ACPI tables using proper MMIO access Date: Sun, 1 Jan 2017 17:37:27 +0100 Message-Id: <1483288652-18983-6-git-send-email-agordeev@redhat.com> In-Reply-To: <1483288652-18983-1-git-send-email-agordeev@redhat.com> References: <1483288652-18983-1-git-send-email-agordeev@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 01 Jan 2017 16:37:42 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a draft and incomplete implementation Cc: Radim Krčmář Signed-off-by: Alexander Gordeev --- lib/x86/acpi.c | 32 +++++++++++++++++++++++--------- x86/s3.c | 10 ++++++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/x86/acpi.c b/lib/x86/acpi.c index 4373106298d8..6536ff9f988c 100644 --- a/lib/x86/acpi.c +++ b/lib/x86/acpi.c @@ -1,5 +1,6 @@ #include "libcflat.h" #include "acpi.h" +#include "asm/io.h" void* find_acpi_table_addr(u32 sig) { @@ -16,7 +17,7 @@ void* find_acpi_table_addr(u32 sig) if (!fadt) { return NULL; } - return (void*)(ulong)fadt->firmware_ctrl; + return ioremap(fadt->firmware_ctrl, PAGE_SIZE); } for(addr = 0xf0000; addr < 0x100000; addr += 16) { @@ -26,16 +27,22 @@ void* find_acpi_table_addr(u32 sig) } if (addr == 0x100000) { printf("Can't find RSDP\n"); - return 0; + return NULL; } if (sig == RSDP_SIGNATURE) { return rsdp; } - rsdt = (void*)(ulong)rsdp->rsdt_physical_address; - if (!rsdt || rsdt->signature != RSDT_SIGNATURE) - return 0; + if (!rsdp->rsdt_physical_address) { + return NULL; + } + + rsdt = ioremap(rsdp->rsdt_physical_address, sizeof(*rsdt)); + if (rsdt->signature != RSDT_SIGNATURE) { + return NULL; + } + rsdt = ioremap(rsdp->rsdt_physical_address, rsdt->length); if (sig == RSDT_SIGNATURE) { return rsdt; @@ -43,10 +50,17 @@ void* find_acpi_table_addr(u32 sig) end = (void*)rsdt + rsdt->length; for (i=0; (void*)&rsdt->table_offset_entry[i] < end; i++) { - struct acpi_table *t = (void*)(ulong)rsdt->table_offset_entry[i]; - if (t && t->signature == sig) { - return t; + struct acpi_table *table; + + if (!rsdt->table_offset_entry[i]) { + continue; + } + + table = ioremap(rsdt->table_offset_entry[i], sizeof(*table)); + if (table->signature == sig) { + return ioremap(rsdt->table_offset_entry[i], table->length); } } - return NULL; + + return NULL; } diff --git a/x86/s3.c b/x86/s3.c index cef956e0b8a4..255046319925 100644 --- a/x86/s3.c +++ b/x86/s3.c @@ -1,4 +1,5 @@ #include "libcflat.h" +#include "x86/vm.h" #include "x86/acpi.h" #include "asm/io.h" @@ -39,10 +40,15 @@ extern char resume_start, resume_end; int main(int argc, char **argv) { - struct fadt_descriptor_rev1 *fadt = find_acpi_table_addr(FACP_SIGNATURE); - volatile u32 *resume_vector_ptr = find_resume_vector_addr(); + struct fadt_descriptor_rev1 *fadt; + volatile u32 *resume_vector_ptr; char *addr, *resume_vec = (void*)0x1000; + setup_vm(); + + fadt = find_acpi_table_addr(FACP_SIGNATURE); + resume_vector_ptr = find_resume_vector_addr(); + *resume_vector_ptr = (u32)(ulong)resume_vec; printf("resume vector addr is %p\n", resume_vector_ptr);