From nobody Tue Feb 10 03:15:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824628; cv=none; d=zohomail.com; s=zohoarc; b=f8yRHHR9usD57IwtEXWzk7lD6zj0yKIWRRh7HRUz5xAJGj0fn6zQj+teGfmytaY1c9vLleFvHNottmyexYhi4wTWuBPCcps5Ffp4Mfj/gJnXcfaCLZOAHL5sw6YAMBRN1iI2qUEBe+qiKRxoTx8BivOsrC5Xt7N89eK3In059d4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=FIBpiDX4j9bmOfAGrzs/qcReNbLF1JTIooWk6DwGGY0=; b=f49LrgzTg88vphcyqUvpACJIr1T9pkYOZANafg2hGxxZTFCNPz2Uot4XorhKgjZB4Rrj24MnuWGEhN6KwXNMYzSyZwpb/uN+bXTDXGnr4oQ8BvD9muNQhxRtRZzHe+XL3HzqnjByLU1TuxjkqXz8s0/0mrbCygWOF4OnEtzzb1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824628702955.8115095835738; Thu, 14 Jul 2022 11:50:28 -0700 (PDT) Received: from localhost ([::1]:55844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3us-0007Tm-Kt for importer@patchew.org; Thu, 14 Jul 2022 14:50:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aX-0006YQ-PS for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:26 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:51574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aV-0008B9-25 for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:24 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EFs7CB000894; Thu, 14 Jul 2022 18:29:17 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71xrp127-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:16 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrBo022632; Thu, 14 Jul 2022 18:29:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465k0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:16 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAN017868; Thu, 14 Jul 2022 18:29:15 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-9; Thu, 14 Jul 2022 18:29:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=FIBpiDX4j9bmOfAGrzs/qcReNbLF1JTIooWk6DwGGY0=; b=lZ6P1KsTV3bvkFEokAYdk8aUzzMMueWurcfhtJY/RVe9baMI7XJOYuG2BOhdb8M2LofN diD8Ypg2u9qY4NzqLH2hYe8WcN7J8c2lurjVk8NSL787cSd9YO9qP+eq0b6O5ZDuBD+M XOg3+6VfU34svTZfnOZtU6VP3Njxiujz983qN7Nuz9gAAUMC5XePoxYC43iQH9waieoE 3LIBw61uluP0KPyUt1xU51NJILZB+7ggnpFNEOLRdW8DwdBetThXG42tznzRWo0jn4yV HfzegF8hMby3jCKCPFBGoUO7lYBTm35BEqas6uBCC/MQCwvi/dXsTWo//dBrxnSeRHvm uA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins , Jonathan Cameron Subject: [PATCH v7 08/10] i386/pc: factor out device_memory base/size to helper Date: Thu, 14 Jul 2022 19:28:18 +0100 Message-Id: <20220714182820.30970-9-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: MLCcyy9E6NB6jwFB__pUmkJPI0xFGBkH X-Proofpoint-ORIG-GUID: MLCcyy9E6NB6jwFB__pUmkJPI0xFGBkH Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824630370100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move obtaining hole64_start from device_memory memory region base/size into an helper alongside correspondent getters in pc_memory_init() when the hotplug range is unitialized. While doing that remove the memory region based logic from this newly added helper. This is the final step that allows pc_pci_hole64_start() to be callable at the beginning of pc_memory_init() before any memory regions are initialized. Cc: Jonathan Cameron Signed-off-by: Joao Martins --- hw/i386/pc.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c654be6cf0bd..cda435e3baeb 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -825,15 +825,37 @@ static hwaddr pc_above_4g_end(PCMachineState *pcms) return x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; } =20 -static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) +static void pc_get_device_memory_range(PCMachineState *pcms, + hwaddr *base, + ram_addr_t *device_mem_size) { PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); MachineState *machine =3D MACHINE(pcms); + ram_addr_t size; + hwaddr addr; + + size =3D machine->maxram_size - machine->ram_size; + addr =3D ROUND_UP(pc_above_4g_end(pcms), 1 * GiB); + + if (pcmc->enforce_aligned_dimm) { + /* size device region assuming 1G page max alignment per slot */ + size +=3D (1 * GiB) * machine->ram_slots; + } + + *base =3D addr; + *device_mem_size =3D size; +} + + +static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) +{ + PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); hwaddr cxl_base; + ram_addr_t size; =20 - if (pcmc->has_reserved_memory && machine->device_memory->base) { - cxl_base =3D machine->device_memory->base - + memory_region_size(&machine->device_memory->mr); + if (pcmc->has_reserved_memory) { + pc_get_device_memory_range(pcms, &cxl_base, &size); + cxl_base +=3D size; } else { cxl_base =3D pc_above_4g_end(pcms); } @@ -920,7 +942,7 @@ void pc_memory_init(PCMachineState *pcms, /* initialize device memory address space */ if (pcmc->has_reserved_memory && (machine->ram_size < machine->maxram_size)) { - ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + ram_addr_t device_mem_size; =20 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -935,13 +957,7 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - machine->device_memory->base =3D - ROUND_UP(pc_above_4g_end(pcms), 1 * GiB); - - if (pcmc->enforce_aligned_dimm) { - /* size device region assuming 1G page max alignment per slot = */ - device_mem_size +=3D (1 * GiB) * machine->ram_slots; - } + pc_get_device_memory_range(pcms, &machine->device_memory->base, &d= evice_mem_size); =20 if ((machine->device_memory->base + device_mem_size) < device_mem_size) { @@ -1046,13 +1062,14 @@ uint64_t pc_pci_hole64_start(void) PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); MachineState *ms =3D MACHINE(pcms); uint64_t hole64_start =3D 0; + ram_addr_t size =3D 0; =20 if (pcms->cxl_devices_state.is_enabled) { hole64_start =3D pc_get_cxl_range_end(pcms); - } else if (pcmc->has_reserved_memory && ms->device_memory->base) { - hole64_start =3D ms->device_memory->base; + } else if (pcmc->has_reserved_memory && (ms->ram_size < ms->maxram_siz= e)) { + pc_get_device_memory_range(pcms, &hole64_start, &size); if (!pcmc->broken_reserved_end) { - hole64_start +=3D memory_region_size(&ms->device_memory->mr); + hole64_start +=3D size; } } else { hole64_start =3D pc_above_4g_end(pcms); --=20 2.17.2