From patchwork Thu Oct 19 07:16:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 735519 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1378352wro; Thu, 19 Oct 2023 00:19:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3QTMP8sjtPIZjzRnorS1fIkHkiEQ9oL8s7v6gQuciaAyU9d2qgUWcUzC7+K/rPaBYzdIE X-Received: by 2002:ac8:7d41:0:b0:403:a9aa:571f with SMTP id h1-20020ac87d41000000b00403a9aa571fmr1776249qtb.16.1697699946405; Thu, 19 Oct 2023 00:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697699946; cv=none; d=google.com; s=arc-20160816; b=WlTqJCY5Y/XhTQsq3l05oVc8ciBSUNkx1tJXr/YW9v5hEOqEsr/B0+Op1nqfrJRQrO q0s76FPfnmviHlC1MnlrL0iEThnBt5q9Zx7m4WzpZvUD6VIKwcZ0vjd4xLXsY9G+qzrQ k6EgiRrugmeY3fBjvU2+MuTHRx62LxgQASp6d5aQXZJ+liz8xMPCifqk4fk3Vszc46Ot hW0mzBJQ5pA82GL82h8AaB+Z8lBEgiwk5MV3Tht8rl0+aaHmA9te9AqjtDnTGtk890R2 Tn91YBsMhCd/TNRFQx+8ypzPZln+iOkywjgVO1Gm4c2Pt8JZDhUdg/AJMt62JEJmBQkk Alkg== 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=cFAMYwhnq3nxNfGtfJVokxRT7cRevtvOipnlNAGOBcc=; fh=6jYKO1R8PvzdW4tN+W/XYlQifBf+lht0eG+bQc5OUAg=; b=aNHEdlY6BSx+LXgdY/Ixy8dElLJQsnfL5TQnbiDpzkKrb/dt8lST8ASomeCD9qh7QN sOJftigZNcB2S9FpQPUFBIV67hyIIsOMfvznuAJ97ffcN8Veot9zsGrYiSK9oelKJJZX EQ6pjY81pvKcygdE5GVDEK2Py1to+hzuqTWvL9NDWa/CD2BrvaU2Ps3LFTxlWTO905Sc DVF+6ewJP4SsBtlNfihqGLaleX7nLHorQ/2wFPUdTm57dncwJNE4L4v2WiAEVy+In5tV MCdzUaYwJzyKdCMjf2E10qFBfIWNIDz5MG/pDmFskONu703mJ4pY15FpT9vPT5laWH38 fazQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bjkZDZs7; 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 c19-20020a05622a025300b0041991869095si1122621qtx.330.2023.10.19.00.19.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Oct 2023 00:19:06 -0700 (PDT) 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=bjkZDZs7; 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 1qtNHr-0005vn-Ri; Thu, 19 Oct 2023 03:17:46 -0400 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 1qtNHP-0005Ru-UJ for qemu-devel@nongnu.org; Thu, 19 Oct 2023 03:17:15 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtNHM-0003Ea-7R for qemu-devel@nongnu.org; Thu, 19 Oct 2023 03:17:15 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4079ed65582so21175955e9.1 for ; Thu, 19 Oct 2023 00:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697699829; x=1698304629; 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=cFAMYwhnq3nxNfGtfJVokxRT7cRevtvOipnlNAGOBcc=; b=bjkZDZs70Lg43rIIKd5RgCJWeMkiMo3ANIdC+/B0KaAlclb8eo2s3gec8sksInwrBi YJC78nlu4kzRTiN+D9rVzXfT800qzg0dGG7w5lMIAnihnKsLaMXoKVbvj7+r+lVDK+wS YBewy57shKO+fgPM5ABC+CmWOToL/KAiEov9lk2oV+uHNaSkoHXodnzyzQ1aV+r1uGrn 1uIjP7F1vyoS/On/gTe6tWkX66EkQhFRDYv2H0pJJxWdlgBKZGU8tsW3lrZx7yEFyQxZ IHzslQZRmI0npS5qmVAdRnzUhFqEcx+I1NvHcQVI6Evn+vTVePzCrSVfOHXW0ATWNbd7 lv2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697699829; x=1698304629; 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=cFAMYwhnq3nxNfGtfJVokxRT7cRevtvOipnlNAGOBcc=; b=NwvVf81IUWJHKfSYYMBJaA9tbZ6tygu7cF33aIwonNd5nMo2Nl70nbNF9XgO4lUhlz gLB7crZl/1fYuAvdh0EvmcjW1h46JYmswYlG1BpmP8zxB39Z7Dt9mPzakqddDLxzsErY ZcEbVqPghWhGuzDoLA6OwUxV6uJobBB4Ccyz2JYgV3FJyXCq59KN2vlsWSriUNhNCNXb QZqJW4nkKtlVzkaLO4XvdntvQxr289Ce761xtDAeZKpq7hVGMPBNE993bBu9j4X3Gy/d HsL8E2vn65AJ41nhZHQ/5vOfos0CfCaPEkPkIBYud+r3uCDXVCT8+Po86U/QjzLEppKv QPWg== X-Gm-Message-State: AOJu0Yxot1nLr54GChYNovwBsMe8CzGG+PH0+w4iwAjtHev9v0EDu2P1 pjRIU2yVPeY+rQQwlTtsgGzqdlyoIVSpxqFCJ8VSSg== X-Received: by 2002:adf:e605:0:b0:32d:8401:404a with SMTP id p5-20020adfe605000000b0032d8401404amr986009wrm.10.1697699829535; Thu, 19 Oct 2023 00:17:09 -0700 (PDT) Received: from localhost.localdomain (92.red-88-28-12.dynamicip.rima-tde.net. [88.28.12.92]) by smtp.gmail.com with ESMTPSA id b3-20020adff243000000b003258934a4bcsm3776251wrp.42.2023.10.19.00.17.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 19 Oct 2023 00:17:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Ilya Leoshkevich , Halil Pasic , Huacai Chen , Beniamino Galvani , Thomas Huth , Jiaxun Yang , Marcel Apfelbaum , qemu-arm@nongnu.org, Mark Cave-Ayland , Eric Farman , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-s390x@nongnu.org, Strahinja Jankovic , Richard Henderson , Markus Armbruster , Song Gao , Eduardo Habkost , Peter Xu , Sergio Lopez , Christian Borntraeger , David Hildenbrand , Peter Maydell , "Michael S. Tsirkin" , Jason Wang Subject: [PATCH v2 05/12] hw/pci-host/bonito: Do not use SysBus API to map local MMIO region Date: Thu, 19 Oct 2023 09:16:03 +0200 Message-ID: <20231019071611.98885-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019071611.98885-1-philmd@linaro.org> References: <20231019071611.98885-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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 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 There is no point in exposing an internal MMIO region via SysBus and directly mapping it in the very same device. Just map it without using the SysBus API. Transformation done using the following coccinelle script: @@ expression sbdev; expression index; expression addr; expression subregion; @@ - sysbus_init_mmio(sbdev, subregion); ... when != sbdev - sysbus_mmio_map(sbdev, index, addr); + memory_region_add_subregion(get_system_memory(), addr, subregion); and manually adding the local 'host_mem' variable to avoid multiple calls to get_system_memory(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth --- hw/pci-host/bonito.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c index ee6cb85e97..96bd028671 100644 --- a/hw/pci-host/bonito.c +++ b/hw/pci-host/bonito.c @@ -654,10 +654,10 @@ static void bonito_host_realize(DeviceState *dev, Error **errp) static void bonito_pci_realize(PCIDevice *dev, Error **errp) { PCIBonitoState *s = PCI_BONITO(dev); - SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost); PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost); BonitoState *bs = s->pcihost; MemoryRegion *pcimem_alias = g_new(MemoryRegion, 1); + MemoryRegion *host_mem = get_system_memory(); /* * Bonito North Bridge, built on FPGA, @@ -668,48 +668,48 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp) /* set the north bridge register mapping */ memory_region_init_io(&s->iomem, OBJECT(s), &bonito_ops, s, "north-bridge-register", BONITO_INTERNAL_REG_SIZE); - sysbus_init_mmio(sysbus, &s->iomem); - sysbus_mmio_map(sysbus, 0, BONITO_INTERNAL_REG_BASE); + memory_region_add_subregion(host_mem, BONITO_INTERNAL_REG_BASE, + &s->iomem); /* set the north bridge pci configure mapping */ memory_region_init_io(&phb->conf_mem, OBJECT(s), &bonito_pciconf_ops, s, "north-bridge-pci-config", BONITO_PCICONFIG_SIZE); - sysbus_init_mmio(sysbus, &phb->conf_mem); - sysbus_mmio_map(sysbus, 1, BONITO_PCICONFIG_BASE); + memory_region_add_subregion(host_mem, BONITO_PCICONFIG_BASE, + &phb->conf_mem); /* set the south bridge pci configure mapping */ memory_region_init_io(&phb->data_mem, OBJECT(s), &bonito_spciconf_ops, s, "south-bridge-pci-config", BONITO_SPCICONFIG_SIZE); - sysbus_init_mmio(sysbus, &phb->data_mem); - sysbus_mmio_map(sysbus, 2, BONITO_SPCICONFIG_BASE); + memory_region_add_subregion(host_mem, BONITO_SPCICONFIG_BASE, + &phb->data_mem); create_unimplemented_device("bonito", BONITO_REG_BASE, BONITO_REG_SIZE); memory_region_init_io(&s->iomem_ldma, OBJECT(s), &bonito_ldma_ops, s, "ldma", 0x100); - sysbus_init_mmio(sysbus, &s->iomem_ldma); - sysbus_mmio_map(sysbus, 3, 0x1fe00200); + memory_region_add_subregion(host_mem, 0x1fe00200, + &s->iomem_ldma); /* PCI copier */ memory_region_init_io(&s->iomem_cop, OBJECT(s), &bonito_cop_ops, s, "cop", 0x100); - sysbus_init_mmio(sysbus, &s->iomem_cop); - sysbus_mmio_map(sysbus, 4, 0x1fe00300); + memory_region_add_subregion(host_mem, 0x1fe00300, + &s->iomem_cop); create_unimplemented_device("ROMCS", BONITO_FLASH_BASE, 60 * MiB); /* Map PCI IO Space 0x1fd0 0000 - 0x1fd1 0000 */ memory_region_init_alias(&s->bonito_pciio, OBJECT(s), "isa_mmio", get_system_io(), 0, BONITO_PCIIO_SIZE); - sysbus_init_mmio(sysbus, &s->bonito_pciio); - sysbus_mmio_map(sysbus, 5, BONITO_PCIIO_BASE); + memory_region_add_subregion(host_mem, BONITO_PCIIO_BASE, + &s->bonito_pciio); /* add pci local io mapping */ memory_region_init_alias(&s->bonito_localio, OBJECT(s), "IOCS[0]", get_system_io(), 0, 256 * KiB); - sysbus_init_mmio(sysbus, &s->bonito_localio); - sysbus_mmio_map(sysbus, 6, BONITO_DEV_BASE); + memory_region_add_subregion(host_mem, BONITO_DEV_BASE, + &s->bonito_localio); create_unimplemented_device("IOCS[1]", BONITO_DEV_BASE + 1 * 256 * KiB, 256 * KiB); create_unimplemented_device("IOCS[2]", BONITO_DEV_BASE + 2 * 256 * KiB, @@ -719,7 +719,7 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp) memory_region_init_alias(pcimem_alias, NULL, "pci.mem.alias", &bs->pci_mem, 0, BONITO_PCIHI_SIZE); - memory_region_add_subregion(get_system_memory(), + memory_region_add_subregion(host_mem, BONITO_PCIHI_BASE, pcimem_alias); create_unimplemented_device("PCI_2", (hwaddr)BONITO_PCIHI_BASE + BONITO_PCIHI_SIZE,