From patchwork Sat Nov 11 01:32:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 743078 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp541329wrw; Fri, 10 Nov 2023 17:33:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKxDQrVZdEFyrjXCnOF/APG8EdS5asWf7Y1YMbrxrp19OwI4kmzg6oRdVUsXxPW2H6GGj5 X-Received: by 2002:ad4:52e9:0:b0:63d:8447:ddd with SMTP id p9-20020ad452e9000000b0063d84470dddmr6111755qvu.20.1699666407423; Fri, 10 Nov 2023 17:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699666407; cv=none; d=google.com; s=arc-20160816; b=w8REpZRnKg3vsxBe+P2kcluvl7HxaSnyFzUYcFDq3zBMMxYKJlB0LQrQvqzzozHB3G Ah6G6sMiPqBmmjAWrKs8FO+6ZR24hJEH3GGCPCEvGX08cZJKQGQbD6O0pajgFge61faL De2dttwRexSvgH7/peTYQ/h1dRgpH26JIOa8FselsejlDRVzIcNn5299H1X99Siv7EI7 XbM6EpoSkb3X85gP1fWQe31QvQkVYGZCj9ifvvUX+HE0gZz5mlGPxmTLqjLjPzhgAp6h rHJGLKr5srW2dpngg8jgLQoU47wqlY4LwULpyPnWHrhJ6t8FSLtCo+huX4pvzmrge0ro 6mAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kKwJoYSEfi9kpha72LByVIQJbXETSVDWcN/f8oG001I=; fh=f2WZoDMBYjCKWIIOoPI+rQtxlv4fmOm4u+dLdQLqpOk=; b=KQo3a+V/XhQo1D72AEwlk48rUTRxUhyoLAyCOXd94WSBzmPukn4QkiacZqXc8dshbe 9dzAdPbag6wviweM65xR5mqxVryjAkFm93SZFoJOnA2I56zf1LmWdmgYlcPYyHDfjjPB mdUrhbSaFTrKafTgMK5TXq5JIn6Jnlbv0cnZvMRrc/93RTd5vgoce51yoCRhqeg8y8ei fyurBR0N2QuaXdqSypYnQm3LT2ucp8IkMNxKhLVeCW3cqZTMXiNCE9HjcaQ7jisJRuG6 UxjF+FS0lE5JO9duyWDMztC2s4nX5K7lmNgK+tj1ZzebZf/BhWURx6PGaZ9pwEOj0w+w AJew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Us1pO4tF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id er4-20020a056214190400b0066d08649238si667496qvb.501.2023.11.10.17.33.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Nov 2023 17:33:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Us1pO4tF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1crU-0002YO-Hx; Fri, 10 Nov 2023 20:32:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1crP-0002Jp-5K for qemu-devel@nongnu.org; Fri, 10 Nov 2023 20:32:31 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1crN-0001cT-7O for qemu-devel@nongnu.org; Fri, 10 Nov 2023 20:32:30 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso2116411b3a.1 for ; Fri, 10 Nov 2023 17:32:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699666346; x=1700271146; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kKwJoYSEfi9kpha72LByVIQJbXETSVDWcN/f8oG001I=; b=Us1pO4tFr1Q4pTHZUzh1UrFuzo/P7bUyALdub2NoZYsoV89sxps6N4/sYKCMfRb5L9 d4y/YwMqvHmHe3YTUe5WbkAeeb9oPMn0IEhTYoOP6eawTWvIGuBAoNueTKhI18PXrtPf vs8anMLIf8UFtnJf8j1wVtJoqc06F0myeWTxSMt4UkJW2OFrv3OnznuHAvE/gPh/QcsR SumHpVhBp3NAXGUgnXriHbQd87p2S/I2FTBKoeDuHMtikYM0jFJHyPHqBeV/9LXf4Yuf 0XyiuLBCbpAqmA3UTLU8oAdtUjtvhRy4LMcfL2J17I40uuD3BJxVs6vk3rSMPa0v59PR WBJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699666346; x=1700271146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kKwJoYSEfi9kpha72LByVIQJbXETSVDWcN/f8oG001I=; b=kcdUczvYoqAuzTSGNgD148WwxW2utU7DPZbZAfCEUVrmDNz/TjTysCJGe2neHVYvqs SpkgKhj5htaqN5+8bhoziJ4gBzP2jg8CKV6PLB6KraktGOJeZXmSmbhu3xzdQ09IuhFl c9IqT70gNa0UGnAkZctvkUgPoODcR+8Cam4ANY384LdIxkATPuPF4F0OQKEqm0iVB08v TlWtvp2ck2wQcfTYB7dj+MHQPlhQOzmbpLq6gbtXtW2XCPxWfNT2gDkT3XW9EMc3ZRUd CdRa902polyG9G3kQWwji8JGkprxA+CxudqIenyKdPz1vVeg8WkJKB48099TsLos2hqG 3GWg== X-Gm-Message-State: AOJu0YwX9NlF2meXB08wHSLMs4yfrPstr2WXYMfa44bxCoZfeZZaNLJU VVj+pKTm65Rdby6FxDyXBGIkn9J+IcZ3aLCP3IE= X-Received: by 2002:aa7:84c7:0:b0:6c3:4bf2:7486 with SMTP id x7-20020aa784c7000000b006c34bf27486mr961801pfn.7.1699666346592; Fri, 10 Nov 2023 17:32:26 -0800 (PST) Received: from stoup.hsd1.or.comcast.net ([2601:1c0:5e02:2a20:a99c:45a6:14e9:ea6]) by smtp.gmail.com with ESMTPSA id m11-20020a62f20b000000b006c1221bc58bsm333502pfh.115.2023.11.10.17.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 17:32:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH 11/11] hw/pci-host/astro: Fix boot for C3700 machine Date: Fri, 10 Nov 2023 17:32:12 -0800 Message-Id: <20231111013212.229673-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231111013212.229673-1-richard.henderson@linaro.org> References: <20231111013212.229673-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller Apply the "32-bit PCI addressing on 40-bit Runway" as the default iommu transformation. This allows PCI devices to dma PDC memory. Signed-off-by: Helge Deller Acked-by: Richard Henderson Signed-off-by: Richard Henderson --- hw/pci-host/astro.c | 73 ++++++++++++++++++----------------------- hw/pci-host/meson.build | 2 +- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/hw/pci-host/astro.c b/hw/pci-host/astro.c index bd226581af..7d68ccee7e 100644 --- a/hw/pci-host/astro.c +++ b/hw/pci-host/astro.c @@ -32,6 +32,7 @@ #include "hw/pci-host/astro.h" #include "hw/hppa/hppa_hardware.h" #include "migration/vmstate.h" +#include "target/hppa/cpu.h" #include "trace.h" #include "qom/object.h" @@ -268,22 +269,6 @@ static const MemoryRegionOps elroy_config_addr_ops = { }; -/* - * A subroutine of astro_translate_iommu that builds an IOMMUTLBEntry using the - * given translated address and mask. - */ -static bool make_iommu_tlbe(hwaddr addr, hwaddr taddr, hwaddr mask, - IOMMUTLBEntry *ret) -{ - hwaddr tce_mask = ~((1ull << 12) - 1); - ret->target_as = &address_space_memory; - ret->iova = addr & tce_mask; - ret->translated_addr = taddr & tce_mask; - ret->addr_mask = ~tce_mask; - ret->perm = IOMMU_RW; - return true; -} - /* Handle PCI-to-system address translation. */ static IOMMUTLBEntry astro_translate_iommu(IOMMUMemoryRegion *iommu, hwaddr addr, @@ -291,53 +276,59 @@ static IOMMUTLBEntry astro_translate_iommu(IOMMUMemoryRegion *iommu, int iommu_idx) { AstroState *s = container_of(iommu, AstroState, iommu); - IOMMUTLBEntry ret = { - .target_as = &address_space_memory, - .iova = addr, - .translated_addr = 0, - .addr_mask = ~(hwaddr)0, - .perm = IOMMU_NONE, - }; - hwaddr pdir_ptr, index, a, ibase; + hwaddr pdir_ptr, index, ibase; hwaddr addr_mask = 0xfff; /* 4k translation */ uint64_t entry; #define IOVP_SHIFT 12 /* equals PAGE_SHIFT */ #define PDIR_INDEX(iovp) ((iovp) >> IOVP_SHIFT) -#define IOVP_MASK PAGE_MASK #define SBA_PDIR_VALID_BIT 0x8000000000000000ULL + addr &= ~addr_mask; + + /* + * Default translation: "32-bit PCI Addressing on 40-bit Runway". + * For addresses in the 32-bit memory address range ... and then + * language which not-coincidentally matches the PSW.W=0 mapping. + */ + if (addr <= UINT32_MAX) { + entry = hppa_abs_to_phys_pa2_w0(addr); + } else { + entry = addr; + } + /* "range enable" flag cleared? */ if ((s->tlb_ibase & 1) == 0) { - make_iommu_tlbe(addr, addr, addr_mask, &ret); - return ret; + goto skip; } - a = addr; ibase = s->tlb_ibase & ~1ULL; - if ((a & s->tlb_imask) != ibase) { + if ((addr & s->tlb_imask) != ibase) { /* do not translate this one! */ - make_iommu_tlbe(addr, addr, addr_mask, &ret); - return ret; + goto skip; } - index = PDIR_INDEX(a); + + index = PDIR_INDEX(addr); pdir_ptr = s->tlb_pdir_base + index * sizeof(entry); entry = ldq_le_phys(&address_space_memory, pdir_ptr); + if (!(entry & SBA_PDIR_VALID_BIT)) { /* I/O PDIR entry valid ? */ - g_assert_not_reached(); - goto failure; + /* failure */ + return (IOMMUTLBEntry) { .perm = IOMMU_NONE }; } + entry &= ~SBA_PDIR_VALID_BIT; entry >>= IOVP_SHIFT; entry <<= 12; - entry |= addr & 0xfff; - make_iommu_tlbe(addr, entry, addr_mask, &ret); - goto success; - failure: - ret = (IOMMUTLBEntry) { .perm = IOMMU_NONE }; - success: - return ret; + skip: + return (IOMMUTLBEntry) { + .target_as = &address_space_memory, + .iova = addr, + .translated_addr = entry, + .addr_mask = addr_mask, + .perm = IOMMU_RW, + }; } static AddressSpace *elroy_pcihost_set_iommu(PCIBus *bus, void *opaque, diff --git a/hw/pci-host/meson.build b/hw/pci-host/meson.build index de7bfb5a62..36d5ab756f 100644 --- a/hw/pci-host/meson.build +++ b/hw/pci-host/meson.build @@ -29,7 +29,7 @@ pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c')) pci_ss.add(when: 'CONFIG_VERSATILE_PCI', if_true: files('versatile.c')) # HPPA devices -pci_ss.add(when: 'CONFIG_ASTRO', if_true: files('astro.c')) +specific_ss.add(when: 'CONFIG_ASTRO', if_true: files('astro.c')) pci_ss.add(when: 'CONFIG_DINO', if_true: files('dino.c')) system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)