From patchwork Sat Aug 28 15:02:58 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: 139891 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o7SFDwl6027341 for ; Sat, 28 Aug 2010 15:14:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752115Ab0H1PEx (ORCPT ); Sat, 28 Aug 2010 11:04:53 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:34876 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751224Ab0H1PEo (ORCPT ); Sat, 28 Aug 2010 11:04:44 -0400 Received: by bwz11 with SMTP id 11so2655354bwz.19 for ; Sat, 28 Aug 2010 08:04:43 -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=eKtNuWWz0ZQwAa6cnRqmvbdU2kZxuSCa7+3jJkegMQo=; b=ep6D1G0v/SY0NmLJiujrPGyB9F01PL487859QqHEPtEabV5Xz2MGnvw4IiFw/zvXYo eI7nFAUsF8KJ7X3Hd9nOGhjCNby00LotlaMnb3Oe+MG88j7vBH9465WYEX0nf124Kx9f x7Xjgu4ZAH7A7yUNYptCAGjec++v/bgI/AlFQ= 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=iXMpNeIF18XRQuNgOa+aI999tzZ9ePGzwjzg3dC1gISu4y08sjdELuJ6hyeFpjsqAG v+qDOv6IYnBujTsFWLA1Raq3+4DFrk5J/oNYJQrlDlC5u5QzljISAG1EWIBYo6u2nwqY T9V7cdRl29CMyhxr/xSpRE5ekFFrKVyZght5M= Received: by 10.204.177.79 with SMTP id bh15mr1515708bkb.121.1283007883382; Sat, 28 Aug 2010 08:04:43 -0700 (PDT) Received: from localhost ([188.25.93.165]) by mx.google.com with ESMTPS id y2sm3516665bkx.20.2010.08.28.08.04.42 (version=SSLv3 cipher=RC4-MD5); Sat, 28 Aug 2010 08:04:43 -0700 (PDT) From: Eduard - Gabriel Munteanu To: seabios@seabios.org Cc: mst@redhat.com, kevin@koconnor.net, joro@8bytes.org, blauwirbel@gmail.com, paul@codesourcery.com, avi@redhat.com, anthony@codemonkey.ws, av1474@comtv.ru, yamahata@valinux.co.jp, kvm@vger.kernel.org, qemu-devel@nongnu.org, Eduard - Gabriel Munteanu Subject: [PATCH 4/4] iommu: provide ACPI tables Date: Sat, 28 Aug 2010 18:02:58 +0300 Message-Id: <1283007778-11012-4-git-send-email-eduard.munteanu@linux360.ro> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1283007778-11012-1-git-send-email-eduard.munteanu@linux360.ro> References: <1283007778-11012-1-git-send-email-eduard.munteanu@linux360.ro> 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 (demeter1.kernel.org [140.211.167.41]); Sat, 28 Aug 2010 15:19:59 +0000 (UTC) diff --git a/src/acpi.c b/src/acpi.c index 18830dc..c267c54 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -6,6 +6,7 @@ // This file may be distributed under the terms of the GNU LGPLv3 license. #include "acpi.h" // struct rsdp_descriptor +#include "iommu.h" #include "util.h" // memcpy #include "pci.h" // pci_find_device #include "biosvar.h" // GET_EBDA @@ -196,6 +197,36 @@ struct srat_memory_affinity u32 reserved3[2]; } PACKED; +/* + * IVRS (I/O Virtualization Reporting Structure) table. + * + * Describes the AMD IOMMU, as per: + * "AMD I/O Virtualization Technology (IOMMU) Specification", rev 1.26 + */ + +struct ivrs_ivhd +{ + u8 type; + u8 flags; + u16 length; + u16 devid; + u16 capab_off; + u32 iommu_base_low; + u32 iommu_base_high; + u16 pci_seg_group; + u16 iommu_info; + u32 reserved; + u8 entry[0]; +} PACKED; + +struct ivrs_table +{ + ACPI_TABLE_HEADER_DEF /* ACPI common table header. */ + u32 iv_info; + u32 reserved[2]; + struct ivrs_ivhd ivhd; +} PACKED; + #include "acpi-dsdt.hex" static void @@ -586,6 +617,53 @@ static const struct pci_device_id acpi_find_tbl[] = { PCI_DEVICE_END, }; +#define IVRS_SIGNATURE 0x53525649 // IVRS +#define IVRS_MAX_DEVS 32 +static void * +build_ivrs(void) +{ + int iommu_bdf, bdf, max, i; + struct ivrs_table *ivrs; + struct ivrs_ivhd *ivhd; + + iommu_bdf = pci_find_class(PCI_CLASS_SYSTEM_IOMMU); + if (iommu_bdf < 0) + return NULL; + + ivrs = malloc_high(sizeof(struct ivrs_table) + 4 * IVRS_MAX_DEVS); + ivrs->iv_info = iommu_get_misc() & ~0x000F; + + ivhd = &ivrs->ivhd; + ivhd->type = 0x10; + ivhd->flags = 0; + ivhd->length = sizeof(struct ivrs_ivhd); + ivhd->devid = iommu_get_bdf(); + ivhd->capab_off = iommu_get_cap_offset(); + ivhd->iommu_base_low = iommu_get_base(); + ivhd->iommu_base_high = 0; + ivhd->pci_seg_group = 0; + ivhd->iommu_info = 0; + ivhd->reserved = 0; + + i = 0; + foreachpci(bdf, max) { + if (bdf == ivhd->devid) + continue; + ivhd->entry[4 * i + 0] = 2; + ivhd->entry[4 * i + 1] = bdf & 0xFF; + ivhd->entry[4 * i + 2] = (bdf >> 8) & 0xFF; + ivhd->entry[4 * i + 3] = ~(1 << 3); + ivhd->length += 4; + if (++i >= IVRS_MAX_DEVS) + break; + } + + build_header((void *) ivrs, IVRS_SIGNATURE, + sizeof(struct ivrs_table) + 4 * i, 1); + + return ivrs; +} + struct rsdp_descriptor *RsdpAddr; #define MAX_ACPI_TABLES 20 @@ -625,6 +703,7 @@ acpi_bios_init(void) ACPI_INIT_TABLE(build_madt()); ACPI_INIT_TABLE(build_hpet()); ACPI_INIT_TABLE(build_srat()); + ACPI_INIT_TABLE(build_ivrs()); u16 i, external_tables = qemu_cfg_acpi_additional_tables();