From nobody Tue Nov 18 10:38:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) client-ip=209.85.128.48; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f48.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609542755; cv=none; d=zohomail.com; s=zohoarc; b=lcAA+NNfDU4/Z3vm8mnJeqAVl2wKFrvnvJ0AAiGw0CP4+Iou1aBns8aRK74lahqWCy0VQ2UQONBKqRnbhWwxvA3cnlgKRTsmazU7fKoFsC1LhEe5rP7TiIEGHGnZfeSAl0R6LEyt75o8kBr/Qa5KTMLMi0J8dGpA+QRn2nRNzJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609542755; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ljyxQOUNZGYTQa01IhKR46X5cyTNgh71UVYnn7BF/T8=; b=fgKb/ueOxwfi1mwTrJFyk6EKoUt0wd9fDaWZxIkrOwekrabMBHHnfg9UmUkECgUZHS/Pty9nMrWeME5TpsMtAadNQ6iRakypJe0RjZ98tCnW/O2EsHCh4KMgBHiq4iIo4iGdA5mQNWZwsxJi80+uRt6h8mbRWyhfQvrrZ4a5jrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.zohomail.com with SMTPS id 1609542755148954.6213871806099; Fri, 1 Jan 2021 15:12:35 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id 190so10274305wmz.0 for ; Fri, 01 Jan 2021 15:12:34 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (239.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.239]) by smtp.gmail.com with ESMTPSA id x17sm76034444wro.40.2021.01.01.15.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jan 2021 15:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ljyxQOUNZGYTQa01IhKR46X5cyTNgh71UVYnn7BF/T8=; b=gj9aAg3lEBFkGyYqrbofjYq+WHyHo97p20dac3t2B96uP7gx03O3DbJSfL06Pw4afl MKvcuJc5BIUJnRGBt8TknJzZLRHJ4ZBZCkyCUiFbPJzwDZhWJFWUW3rjrWUYDn/B+i3F b5ml/yS0rBVKipruBt9vHyoysstW/DlKg5HsomBxyGUmXSvQEJ02pNtUbVshBeDIjCM8 wgKY2L0xufQM3LH5F11hSDb+f0v/7Fg9X6hv3/BWvxJfMvogvZIP4dkTZW5N2MwOxUFf Q5Y5dTuSiuj0rawNaIJRY3b7/jaGQgXkbW6n9xbQhS+3pzi+ioohk7ekWaKxWCcdPFS1 kiZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ljyxQOUNZGYTQa01IhKR46X5cyTNgh71UVYnn7BF/T8=; b=X3wrGhZWuAnzFM/w7Ww+7ZfNBmkoCmLl5uoIoppWDgeDBBRfuxOQPTIu3pG5dt97+V NGq/yXkBO1ahRiwnV7gqJ3BLNRpcTl5+iqtev0YPSnAIP9uZ2TyvXZ+kIGRWZXla6wJy gfA56Z3SY7LJVaI5IFY+tG+RnDJP/kjln0jvKyH6a/JTYeCbchMm24wkaCxzEWv++6OS sq50Ns11XBNQPsRcytPyFXsg3tYnrvAGh6W9zWlaKrIFJT+s6fcmHV0NnfKwQodXMUQ1 gXvosVL4uWqANh05+6sEaa0sYVpXjVUFnaw3JxeCH8zQ6StCgoKFA4TubZoWxVwTw0CY jMbw== X-Gm-Message-State: AOAM533sITD2PEmGg9JIL04cGAdL1Mp262L8vy0AdZjpDXmkCTADAViM vJGT8GvSzQ7+Qi5R5oN+NaU= X-Google-Smtp-Source: ABdhPJzHbswv049B7rC0m2xISqgFQL9fayJbvpZrC9bXRYHh2Z9ZhTl7pJUSHkxPK8VFQWoxe/7oiw== X-Received: by 2002:a1c:24c4:: with SMTP id k187mr17661109wmk.14.1609542753397; Fri, 01 Jan 2021 15:12:33 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aurelien Jarno , Cleber Rosa , Aleksandar Rikalo , Mark Cave-Ayland , qemu-block@nongnu.org, Artyom Tarasenko , Wainer dos Santos Moschetta , John Snow , Huacai Chen , Peter Maydell Subject: [RFC PATCH 3/5] hw/pci-host/bonito: Remap PCI "lo" regions when PCIMAP reg is modified Date: Sat, 2 Jan 2021 00:12:13 +0100 Message-Id: <20210101231215.1870611-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101231215.1870611-1-f4bug@amsat.org> References: <20210101231215.1870611-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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=C3=A9 --- 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) =20 /* 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 */ =20 @@ -237,6 +241,7 @@ struct BonitoState { qemu_irq *pic; PCIBonitoState *pci_dev; MemoryRegion pci_mem; + MemoryRegion pcimem_lo_alias[3]; }; =20 #define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost" @@ -245,6 +250,31 @@ OBJECT_DECLARE_SIMPLE_TYPE(BonitoState, BONITO_PCI_HOS= T_BRIDGE) #define TYPE_PCI_BONITO "Bonito" OBJECT_DECLARE_SIMPLE_TYPE(PCIBonitoState, PCI_BONITO) =20 +static void bonito_remap(PCIBonitoState *s) +{ + static const char *const region_name[3] =3D { + "pci.lomem0", "pci.lomem1", "pci.lomem2" + }; + BonitoState *bs =3D BONITO_PCI_HOST_BRIDGE(s->pcihost); + + for (size_t i =3D 0; i < 3; i++) { + uint32_t offset =3D 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]); + } +} + static void bonito_writel(void *opaque, hwaddr addr, uint64_t val, unsigned size) { @@ -260,7 +290,6 @@ static void bonito_writel(void *opaque, hwaddr addr, case BONITO_BONPONCFG: case BONITO_IODEVCFG: case BONITO_SDCFG: - case BONITO_PCIMAP: case BONITO_PCIMEMBASECFG: case BONITO_PCIMAP_CFG: case BONITO_GPIODATA: @@ -282,6 +311,10 @@ static void bonito_writel(void *opaque, hwaddr addr, case BONITO_MEMSIZE: s->regs[saddr] =3D val; break; + case BONITO_PCIMAP: + s->regs[saddr] =3D val; + bonito_remap(s); + break; case BONITO_BONGENCFG: if (!(s->regs[saddr] & 0x04) && (val & 0x04)) { reset =3D 1; /* bit 2 jump from 0 to 1 cause reset */ @@ -610,6 +643,8 @@ static void bonito_reset(void *opaque) s->regs[BONITO_DQCFG] =3D 0x8; s->regs[BONITO_MEMSIZE] =3D 0x10000000; s->regs[BONITO_PCIMAP] =3D 0x6140; + + bonito_remap(s); } =20 static const VMStateDescription vmstate_bonito =3D { @@ -626,7 +661,6 @@ static void bonito_pcihost_realize(DeviceState *dev, Er= ror **errp) { PCIHostState *phb =3D PCI_HOST_BRIDGE(dev); BonitoState *bs =3D BONITO_PCI_HOST_BRIDGE(dev); - MemoryRegion *pcimem_lo_alias =3D g_new(MemoryRegion, 3); =20 memory_region_init(&bs->pci_mem, OBJECT(dev), "pci.mem", BONITO_PCIHI_= SIZE); phb->bus =3D pci_register_root_bus(dev, "pci", @@ -634,17 +668,6 @@ static void bonito_pcihost_realize(DeviceState *dev, E= rror **errp) dev, &bs->pci_mem, get_system_io(), 0x28, 32, TYPE_PCI_BUS); =20 - for (size_t i =3D 0; i < 3; i++) { - char *name =3D g_strdup_printf("pci.lomem%zu", i); - - memory_region_init_alias(&pcimem_lo_alias[i], NULL, name, - &bs->pci_mem, i * 64 * MiB, 64 * MiB); - memory_region_add_subregion(get_system_memory(), - BONITO_PCILO_BASE + i * 64 * MiB, - &pcimem_lo_alias[i]); - g_free(name); - } - create_unimplemented_device("pci.io", BONITO_PCIIO_BASE, 1 * MiB); } =20 --=20 2.26.2