From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5B3EC433E0 for ; Sat, 2 Jan 2021 10:46:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2DFD20888 for ; Sat, 2 Jan 2021 10:46:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2DFD20888 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kveQF-0002hC-Qe for qemu-devel@archiver.kernel.org; Sat, 02 Jan 2021 05:46:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kveP2-00020u-9a; Sat, 02 Jan 2021 05:44:56 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:36961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kveP0-0001dB-I0; Sat, 02 Jan 2021 05:44:56 -0500 Received: by mail-wr1-x42c.google.com with SMTP id i9so26183067wrc.4; Sat, 02 Jan 2021 02:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FuH4mbJZdmkw+CX7Wh5KMjGjhGSpx09XpiBCk/lvOz0=; b=X3k1lYZbdMJb+iWQH3BdsSiiIMxAPQKvK0mtjGKa4qLw1IJJBz5QvahRBKyz/CdFj1 /cFNzSpV4WfykPh0tYh5xs2H3OzYzuFNh3KtJ71L2ZOkzhQ5EXXLmAo7N/9RRJWRh77/ 8sB8Kl6sdtHIsE45MYN59F4dL8ptJqYx9Axms1kcmUk1zq8bTDsMlhIDVN+JwXaiT8eQ BFdKQa9vsJSWLurkUt9IrAdT9fzapPLO2ubt3/ljr28HVsZXSFVBqxfezDT0n835Rg6n NP0p28JWRKZala6CLO59pYRKsmZUIY+a86q5NjN7AkTSVpkKSSUVJ1olBmaYZ4VM7UhO h5DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FuH4mbJZdmkw+CX7Wh5KMjGjhGSpx09XpiBCk/lvOz0=; b=duGdqoSr2T+EtUH5dcxr8kkZlfVWQzwl1fwcawL8pckuyOaP1b5lmzuKFwWfa++FCP ekkgbKGn8/b+EJYePi55kE5QO3b8mpdjKZ3e96JgC3INoPSv5+DLTCcD3/wDnSL+BwTA zpx/CgzXKqpbhovNa/4MPVJXXsdPhqU6hxXblsLrpK9a9QCntAXzHWt8qOAZDnD6DztI lr/SWmPgb6v/xunUXGzcdp2d0TY5hOC1tNkWNyQFWUgTnUZAF7aS3NUoUEZlM+QeDxNh gWcZPG4UFjPAEKZFTaB4AyfvoTceT+8HkJSOf5/yd2JgxCdzILktA3JRuJ3F7v8fiC/1 bXIw== X-Gm-Message-State: AOAM531roUpdNV5MOCGNQK/JLe2zxy9lLjeiWvi0iW5dti+S+gJWSHmh OL8IFnaFs9b5PvMFzDrKzk4= X-Google-Smtp-Source: ABdhPJwAZnntZahf51lmCD7RYvVDJ2gJGcG3gY+5ljMRnqqzAL18HKDd7kEwjHYo/iOAIOGA88sXgg== X-Received: by 2002:adf:ea43:: with SMTP id j3mr71661140wrn.393.1609584292602; Sat, 02 Jan 2021 02:44:52 -0800 (PST) Received: from [192.168.1.34] (194.red-83-57-172.dynamicip.rima-tde.net. [83.57.172.194]) by smtp.gmail.com with ESMTPSA id v1sm74784922wrr.48.2021.01.02.02.44.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Jan 2021 02:44:51 -0800 (PST) Subject: Re: [RFC PATCH 3/5] hw/pci-host/bonito: Remap PCI "lo" regions when PCIMAP reg is modified To: Peter Maydell References: <20210101231215.1870611-1-f4bug@amsat.org> <20210101231215.1870611-4-f4bug@amsat.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <2da14074-a4ef-e90c-ea42-74d48ca06afd@amsat.org> Date: Sat, 2 Jan 2021 11:44:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-2.749, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar Rikalo , Qemu-block , Huacai Chen , Mark Cave-Ayland , QEMU Developers , Wainer dos Santos Moschetta , Aurelien Jarno , Cleber Rosa , John Snow , Artyom Tarasenko Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 1/2/21 12:19 AM, Peter Maydell wrote: > On Fri, 1 Jan 2021 at 23:12, Philippe Mathieu-Daudé wrote: >> >> Per the datasheet (Chapter 5.7.1. "PCI address regions"), >> the PCIMAP register: >> >> Map the 64Mbyte regions marked "PCI_Lo" in the CPU's memory map, >> each of which can be assigned to any 64 Mbyte-aligned region of >> PCI memory. The address appearing on the PCI bus consists of the >> low 26 bits of the CPU physical address, with the high 6 bits >> coming from the appropriate base6 field. Each of the three regions >> is an independent window onto PCI memory, and can be positioned on >> any 64Mbyte boundary in PCI space. >> >> Remap the 3 regions on reset and when PCIMAP is updated. >> >> Signed-off-by: Philippe Mathieu-Daudé >> --- >> hw/pci-host/bonito.c | 49 ++++++++++++++++++++++++++++++++------------ >> 1 file changed, 36 insertions(+), 13 deletions(-) >> >> diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c >> index a99eced0657..c58eeaf504c 100644 >> --- a/hw/pci-host/bonito.c >> +++ b/hw/pci-host/bonito.c >> @@ -137,6 +137,10 @@ FIELD(BONGENCFG, PCIQUEUE, 12, 1) >> >> /* 4. PCI address map control */ >> #define BONITO_PCIMAP (0x10 >> 2) /* 0x110 */ >> +FIELD(PCIMAP, LO0, 0, 6) >> +FIELD(PCIMAP, LO1, 6, 6) >> +FIELD(PCIMAP, LO2, 12, 6) >> +FIELD(PCIMAP, 2G, 18, 1) >> #define BONITO_PCIMEMBASECFG (0x14 >> 2) /* 0x114 */ >> #define BONITO_PCIMAP_CFG (0x18 >> 2) /* 0x118 */ >> >> @@ -237,6 +241,7 @@ struct BonitoState { >> qemu_irq *pic; >> PCIBonitoState *pci_dev; >> MemoryRegion pci_mem; >> + MemoryRegion pcimem_lo_alias[3]; >> }; >> >> #define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost" >> @@ -245,6 +250,31 @@ OBJECT_DECLARE_SIMPLE_TYPE(BonitoState, BONITO_PCI_HOST_BRIDGE) >> #define TYPE_PCI_BONITO "Bonito" >> OBJECT_DECLARE_SIMPLE_TYPE(PCIBonitoState, PCI_BONITO) >> >> +static void bonito_remap(PCIBonitoState *s) >> +{ >> + static const char *const region_name[3] = { >> + "pci.lomem0", "pci.lomem1", "pci.lomem2" >> + }; >> + BonitoState *bs = BONITO_PCI_HOST_BRIDGE(s->pcihost); >> + >> + for (size_t i = 0; i < 3; i++) { >> + uint32_t offset = extract32(s->regs[BONITO_PCIMAP], 6 * i, 6) << 26; >> + >> + if (memory_region_is_mapped(&bs->pcimem_lo_alias[i])) { >> + memory_region_del_subregion(get_system_memory(), >> + &bs->pcimem_lo_alias[i]); >> + object_unparent(OBJECT(&bs->pcimem_lo_alias[i])); >> + } >> + >> + memory_region_init_alias(&bs->pcimem_lo_alias[i], OBJECT(s), >> + region_name[i], &bs->pci_mem, >> + offset, 64 * MiB); >> + memory_region_add_subregion(get_system_memory(), >> + BONITO_PCILO_BASE + i * 64 * MiB, >> + &bs->pcimem_lo_alias[i]); >> + } > > Rather than delete-and-reinit-and-add, it's probably better to > just create the subregions once at device startup, and then use > memory_region_set_enabled() and memory_region_set_address() > to manipulate whether the subregion is visible and what address > in the system memory it is mapped at. Great! Thanks Peter :) TIL these functions. >From what I understand from memory_region_readd_subregion (called from memory_region_set_address) using memory_region_set_enabled() directly is enough.