Received: by 2002:ac2:5978:0:0:0:0:0 with SMTP id h24csp130866lfp; Wed, 22 Sep 2021 05:38:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjj14CThXcqKrxyU+YClwyCHuNjnNQOlmzF2EPQ7NJQiPcnU4PTkFRP2hZ/1OEqgMUivY6 X-Received: by 2002:a67:fd07:: with SMTP id f7mr19221781vsr.43.1632314298514; Wed, 22 Sep 2021 05:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632314298; cv=none; d=google.com; s=arc-20160816; b=irmEEQLarRtUvGuh1T0akUetJnCViXsS892SzIqwlMZFT8MWD45sBs3fmQGgk1I453 r80c+A3O1qFXHcQL71cuoC2OBUK/wfVqNKvHbgqHToTzd2MjUaEsj7dUsoVsAGLo5LES vEJneJkqUf7vG5dDiDlRZ949GZjYU80sSQXPb8z6Gk39meP6iZ7ixuoBVDMCRPOGuFW1 g+jOGqJyWaN0qBxi+bVxeUxo8Q4LXRrm7jK7YD4+wRtLJUZSkw5IrGHqYw4Yfw2/6ujX 0w9G89u31wJ2WqPAG9kgMYGRAvUXggKlSun27fm6Jp8jKwpluLagYMOzWjiNuPKjQHGc 83wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=eDUbBmXbcV2SYybEkn682nVdXBenHfioDrMxUCVgHTU=; b=M2ZLA1eTV0FuX0go2MPLYUiCxywthISFpS42TTwrpDRmdEZpTtU0ySYxPPTtTt+YMe x7LtMRE4CQpsuqzDStsQ4SulYkInMdjUb4MX1mQRVBpFWwmvRN4aW6/C4dm7h/orTcRF +95N/cHhOKrEF5ne+wTccZvaF3ob7QUWyR8QYGkl26nVrWaQMwihc0pz88pPlrlFQy/d o4nYZ+TThnmqr0rpi62oLY6371POSZgilYHh4/3pgzC+jK7FOQ8Aa0EcHTSA7kA4bznD rzPL1IKoJODgcQxOlW5bD1rHwcFFCSS0IjFNQQ/6oGjI06wuURoJ4q5r0JMa4M7tBeGZ VpTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=ZID71ZGq; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q18si1601704vkn.96.2021.09.22.05.38.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Sep 2021 05:38:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=ZID71ZGq; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:34030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT1Vx-00047y-R3 for alex.bennee@linaro.org; Wed, 22 Sep 2021 08:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT1Qf-0006qS-5V for qemu-arm@nongnu.org; Wed, 22 Sep 2021 08:32:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27221) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT1Qb-0000sM-IV for qemu-arm@nongnu.org; Wed, 22 Sep 2021 08:32:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632313964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eDUbBmXbcV2SYybEkn682nVdXBenHfioDrMxUCVgHTU=; b=ZID71ZGq/JeRqY26DOgM31/vfYYlIkNqVPveWq87wod8SIAGyXSngsss/wT0ZSGOdHM0/c 66npZzeonGryomjFg5W7WOzs5AFledMfsmTtZNDEumDEdtgDyk9USj5bp7RPFirwAVKRwU hivf9cfC5FnggiFlRT+PCc/D3u52JpE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-YWVg7xXAOqS__SmgVUQRNw-1; Wed, 22 Sep 2021 08:32:43 -0400 X-MC-Unique: YWVg7xXAOqS__SmgVUQRNw-1 Received: by mail-wr1-f69.google.com with SMTP id f7-20020a5d50c7000000b0015e288741a4so2028054wrt.9 for ; Wed, 22 Sep 2021 05:32:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eDUbBmXbcV2SYybEkn682nVdXBenHfioDrMxUCVgHTU=; b=cvs9V+sRR0NIklEIlpKbhXZbG4atsdDTw9h27WBwRPCPtXnv/nhTKUlI0q9z7p3H9m Pwa3gKNGqFLBZCElOIh2778HFE8B2CFRQSAEe7IpGW5OOU/7ML7z6Pc/18CTOaTUO7nj qpEMGq0fnuuVAlWPi+XvR86VLpQyrYpILO3cbh8QbOtJFMLRuWkDu7m3kO3gPmqxg+/z nFBi7Z9RUNk/2o7qagmO5tVuvgRCCYkHcX83Vlrx1RbvAoz8CzWIeMH44FIUHssMh/1U 4Frssk9z7n7y2CsxjCSYNjFn599hRgF2Vn1ItIQH/cgTsFnW/IbznLfhoOriSLTcinQC FRbA== X-Gm-Message-State: AOAM530UxWOTs02a+qT/jtJ9TkfKhddmiG6edOj05o8k7m1kZxHqgOFU rf/+E+8fsR4MBWl+cvX1bLkgsQv/W6uJmc6qoBar/MPJEpORNiDzU+LYK3VpHiexjsEsha7gQFs 8CX7v/IOGVaKCons/GM9pKL9382tPs8HtXRmiy11hZz8j49JQA2lwM6l0kUewTQ== X-Received: by 2002:a05:600c:4c09:: with SMTP id d9mr10342563wmp.194.1632313962092; Wed, 22 Sep 2021 05:32:42 -0700 (PDT) X-Received: by 2002:a05:600c:4c09:: with SMTP id d9mr10342537wmp.194.1632313961872; Wed, 22 Sep 2021 05:32:41 -0700 (PDT) Received: from ?IPv6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id k17sm2063530wrq.7.2021.09.22.05.32.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Sep 2021 05:32:41 -0700 (PDT) Subject: Re: [PATCH v3 28/35] acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_table_end() instead of build_header() To: Igor Mammedov , qemu-devel@nongnu.org References: <20210907144814.741785-1-imammedo@redhat.com> <20210907144814.741785-29-imammedo@redhat.com> From: Eric Auger Message-ID: <3faf817c-1ea3-559f-2bed-2a04a72b51f2@redhat.com> Date: Wed, 22 Sep 2021 14:32:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210907144814.741785-29-imammedo@redhat.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eauger@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=eauger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, drjones@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, mst@redhat.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: ayq1fGLE+Iay Hi Igor, On 9/7/21 4:48 PM, Igor Mammedov wrote: > it replaces error-prone pointer arithmetic for build_header() API, > with 2 calls to start and finish table creation, > which hides offsets magic from API user. > > Signed-off-by: Igor Mammedov > --- > v3: > * fix conflicts due to > 42e0f050e3a51 'hw/arm/virt-acpi-build: Add IORT support to bypass SMMUv3' > * * s/acpi_init_table|acpi_table_composed/acpi_table_begin|acpi_table_end/ > > CC: drjones@redhat.com > CC: peter.maydell@linaro.org > CC: shannon.zhaosl@gmail.com > CC: qemu-arm@nongnu.org > CC: eauger@redhat.com > --- > include/hw/acpi/acpi-defs.h | 14 ------------ > hw/arm/virt-acpi-build.c | 45 ++++++++++++++++--------------------- > 2 files changed, 19 insertions(+), 40 deletions(-) > > diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h > index bcada37601..195f90caf6 100644 > --- a/include/hw/acpi/acpi-defs.h > +++ b/include/hw/acpi/acpi-defs.h > @@ -188,20 +188,6 @@ struct AcpiGenericTimerTable { > } QEMU_PACKED; > typedef struct AcpiGenericTimerTable AcpiGenericTimerTable; > > -/* > - * Input Output Remapping Table (IORT) > - * Conforms to "IO Remapping Table System Software on ARM Platforms", > - * Document number: ARM DEN 0049B, October 2015 > - */ > - > -struct AcpiIortTable { > - ACPI_TABLE_HEADER_DEF /* ACPI common table header */ > - uint32_t node_count; > - uint32_t node_offset; > - uint32_t reserved; > -} QEMU_PACKED; > -typedef struct AcpiIortTable AcpiIortTable; > - > /* > * IORT node types > */ > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > index 4b9687439d..bceb1b3b7e 100644 > --- a/hw/arm/virt-acpi-build.c > +++ b/hw/arm/virt-acpi-build.c > @@ -273,22 +273,29 @@ static int iort_idmap_compare(gconstpointer a, gconstpointer b) > return idmap_a->input_base - idmap_b->input_base; > } > > +/* > + * Input Output Remapping Table (IORT) > + * Conforms to "IO Remapping Table System Software on ARM Platforms", > + * Document number: ARM DEN 0049B, October 2015 > + */ > static void > build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > { > - int i, nb_nodes, rc_mapping_count, iort_start = table_data->len; > + int i, nb_nodes, rc_mapping_count; > AcpiIortIdMapping *idmap; > AcpiIortItsGroup *its; > - AcpiIortTable *iort; > AcpiIortSmmu3 *smmu; > - size_t node_size, iort_node_offset, iort_length, smmu_offset = 0; > AcpiIortRC *rc; > + const uint32_t iort_node_offset = 48; > + size_t node_size, smmu_offset = 0; > GArray *smmu_idmaps = g_array_new(false, true, sizeof(AcpiIortIdMapping)); > GArray *its_idmaps = g_array_new(false, true, sizeof(AcpiIortIdMapping)); > > - iort = acpi_data_push(table_data, sizeof(*iort)); > + AcpiTable table = { .sig = "IORT", .rev = 0, .oem_id = vms->oem_id, > + .oem_table_id = vms->oem_table_id }; > > if (vms->iommu == VIRT_IOMMU_SMMUV3) { > + forgot this minor comment nit: spurious change Eric > AcpiIortIdMapping next_range = {0}; > > object_child_foreach_recursive(object_get_root(), > @@ -325,18 +332,16 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > rc_mapping_count = 1; > } > > - iort_length = sizeof(*iort); > - iort->node_count = cpu_to_le32(nb_nodes); > - /* > - * Use a copy in case table_data->data moves during acpi_data_push > - * operations. > - */ > - iort_node_offset = sizeof(*iort); > - iort->node_offset = cpu_to_le32(iort_node_offset); > + /* Table 2 The IORT */ > + acpi_table_begin(&table, table_data); > + /* Number of IORT Nodes */ > + build_append_int_noprefix(table_data, nb_nodes, 4); > + /* Offset to Array of IORT Nodes */ > + build_append_int_noprefix(table_data, iort_node_offset, 4); > + build_append_int_noprefix(table_data, 0, 4); /* Reserved */ > > /* ITS group node */ > node_size = sizeof(*its) + sizeof(uint32_t); > - iort_length += node_size; > its = acpi_data_push(table_data, node_size); > > its->type = ACPI_IORT_NODE_ITS_GROUP; > @@ -350,7 +355,6 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > /* SMMUv3 node */ > smmu_offset = iort_node_offset + node_size; > node_size = sizeof(*smmu) + sizeof(*idmap); > - iort_length += node_size; > smmu = acpi_data_push(table_data, node_size); > > smmu->type = ACPI_IORT_NODE_SMMU_V3; > @@ -375,7 +379,6 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > > /* Root Complex Node */ > node_size = sizeof(*rc) + sizeof(*idmap) * rc_mapping_count; > - iort_length += node_size; > rc = acpi_data_push(table_data, node_size); > > rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX; > @@ -424,19 +427,9 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > idmap->output_reference = cpu_to_le32(iort_node_offset); > } > > + acpi_table_end(linker, &table); > g_array_free(smmu_idmaps, true); > g_array_free(its_idmaps, true); > - > - /* > - * Update the pointer address in case table_data->data moves during above > - * acpi_data_push operations. > - */ > - iort = (AcpiIortTable *)(table_data->data + iort_start); > - iort->length = cpu_to_le32(iort_length); > - > - build_header(linker, table_data, (void *)(table_data->data + iort_start), > - "IORT", table_data->len - iort_start, 0, vms->oem_id, > - vms->oem_table_id); > } > > static void >