From patchwork Thu Oct 12 12:18:52 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: 732472 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp917617wrv; Thu, 12 Oct 2023 05:21:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuScAmb8RDO7VZsLFHpTYz3yFVPApVImMAr0YNbwC7M1cvfV+NcW3MeXau5VHgrHQabD8l X-Received: by 2002:a05:6808:18:b0:3a8:ccf0:103f with SMTP id u24-20020a056808001800b003a8ccf0103fmr24513216oic.3.1697113319537; Thu, 12 Oct 2023 05:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697113319; cv=none; d=google.com; s=arc-20160816; b=Gip9w9JfaE1dvhFjW5uslkyv2+Kd5oqQwVPxTyX2eWlhm8OhdYvLWymAUWmSl9cbEf D/HYjhygmFSXvqXAUMVlqB/WBIXbamwlMFPOq06VztoLARbFAHKukeiP6sO+zJwJabFz bvrpqal1cZYy3LRXtlBRRmRrONlc+zyZ1LSJVjCXsovKN/4oHkgBWodV39JuNq0N7gR6 TH9P+pMhNldIovJl/yOd+9a9TnWFcVYZrQ0C4cOcTuPWAjK7Qcj87i+TsAchObZWpM3f 8kevJeTbfcjBJyqe7bYF+VTRKPBh9uC/DehauflFy52++u6BLmtsm97YWWvh/fTzdZpH 47+g== 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=xa2WXsDwKflmWK2k8quohK6TTrUH1twZfhC/r4NA1UE=; fh=uMYo3jOuXUsDthaXCE4/M6n3+voY5rtHQA7Grzg1cYU=; b=cYOKM+fvUQ90GV28WNkPYWmwjF1ezM6sIzKPVx+H+jU+z7qAQX1RF/07dpuHQrsufb KCtOri1erGwfTQj7/enEhaJCC9KbO8hGu+BMik1XProFOphZ7MSyH3lGRpvYo5f0yhAb AGqhmwh/HlvWCKRFJtEWIKEYwwixayChbtlpT/xqCTtsIaytq8qa+4BrUiXCCvEFjQX+ hSacsE45ZOY6fo1oBZxeQvfkP0J18Dc04fAhq1UaWlUEJ8qCL9bHv8BhCt+VZ7gyqGGi satt5SS9k0mkWwKAfK/Ukli9DXlUPXHxPvyPDk2JZV/LgFx5gJwx/lu4Ys3Yhpj3dyqM xo1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nLvXAOTh; 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 t1-20020a0ce2c1000000b0066d0656ef0esi2405719qvl.615.2023.10.12.05.21.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Oct 2023 05:21:59 -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=nLvXAOTh; 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 1qquf6-0003Dz-Fd; Thu, 12 Oct 2023 08:19:32 -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 1qquf4-0003Cz-Lj for qemu-devel@nongnu.org; Thu, 12 Oct 2023 08:19:30 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qquf2-0001pi-CX for qemu-devel@nongnu.org; Thu, 12 Oct 2023 08:19:30 -0400 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-53db1fbee70so1579933a12.2 for ; Thu, 12 Oct 2023 05:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697113166; x=1697717966; 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=xa2WXsDwKflmWK2k8quohK6TTrUH1twZfhC/r4NA1UE=; b=nLvXAOThsr3uR2a97tQKtPvjWU5llPjrq1nzOnGCKl7KH7fwtOhSdT94qupGpCjG0y 8c+v1cI7n38tjYOxCocAEHgf/k6EW0aT3oRM4Yn2STewLs9hXQ/lZFe3ioSlx9mW1I4R up6QG8M8zCaqmlyZkMllUtAbR6MG4HWD5m/WBA9ooygZ02Tuh9wAKMpXZGw/etkTByoV 71R5RMsRUWembW/3ou+a//5CntVsJuvcocvtbErCFJuNPrF85ul0C1K/3wG+QKxUDSob ObF7BNgLK5UrJXzIfGrBjplEbekqf/rOx7WsHoE1O5B91no482mHkob/YgGyAGPU9w0n UJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697113166; x=1697717966; 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=xa2WXsDwKflmWK2k8quohK6TTrUH1twZfhC/r4NA1UE=; b=uPyPLwu411Qtb2ySiuQG/eFNQyDLVMLut6oPsfWHGuGaROUX9wduGvTWrWbJ8eKoak tb1m17x28P9Sey8in6JxBRok5RhEqU5hFupovYDRNbp40OtSNkqQzpc/b3m0XqE/sQJ7 SO+Oqsh6v7vACeyZQqJbqrwwGh6qCKpqY//wI+jbrAPts0+WCZaj0hClsrbifsinKoSJ FHXk0goVPPpzAQWe8u3opvXUKAgA8J1m6vVLeku1GTtnMK54na9rUVAUX6XVwxMxoz+d Q1fiL/bwro3ov4H0lMJvl0rhkgXAShsS7RDtXjGJG9xd6a+uYjb0V8+6gpH3WPxXdFOH TJBA== X-Gm-Message-State: AOJu0YxmDaLCUWhVTTDYK11HggoxT82XzA+OnEhGazYSOAgWyhqU6cfe irRlay0F280bd/pBs6mPyzknh/X5vupvkAYLQYOIeA== X-Received: by 2002:a05:6402:1250:b0:533:e314:20dd with SMTP id l16-20020a056402125000b00533e31420ddmr20275891edw.13.1697113166626; Thu, 12 Oct 2023 05:19:26 -0700 (PDT) Received: from m1x-phil.lan (176-131-211-232.abo.bbox.fr. [176.131.211.232]) by smtp.gmail.com with ESMTPSA id a23-20020a50ff17000000b005342fa19070sm10081874edu.89.2023.10.12.05.19.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 12 Oct 2023 05:19:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrey Smirnov , qemu-arm@nongnu.org, Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 4/8] hw/pci-host/designware: Hoist host controller in root function #0 Date: Thu, 12 Oct 2023 14:18:52 +0200 Message-ID: <20231012121857.31873-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012121857.31873-1-philmd@linaro.org> References: <20231012121857.31873-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=philmd@linaro.org; helo=mail-ed1-x52e.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=unavailable 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 always an unique root function for the host bridge controller. We create this function when the controller is realized, in designware_pcie_host_realize(). No need to call qdev_get_parent_bus() each time the root function want to resolve its host part. Hoist a pointer in its state. Set the pointer once when the function is realized. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Gustavo Romero --- include/hw/pci-host/designware.h | 1 + hw/pci-host/designware.c | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/hw/pci-host/designware.h b/include/hw/pci-host/designware.h index c484e377a8..9e2caa04e9 100644 --- a/include/hw/pci-host/designware.h +++ b/include/hw/pci-host/designware.h @@ -71,6 +71,7 @@ struct DesignwarePCIERoot { DesignwarePCIEViewport viewports[2][DESIGNWARE_PCIE_NUM_VIEWPORTS]; DesignwarePCIEMSI msi; + DesignwarePCIEHost *host; }; struct DesignwarePCIEHost { diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c index bacb2bdb2d..fb46493a05 100644 --- a/hw/pci-host/designware.c +++ b/hw/pci-host/designware.c @@ -57,13 +57,6 @@ #define DESIGNWARE_PCIE_IRQ_MSI 3 -static DesignwarePCIEHost * -designware_pcie_root_to_host(DesignwarePCIERoot *root) -{ - BusState *bus = qdev_get_parent_bus(DEVICE(root)); - return DESIGNWARE_PCIE_HOST(bus->parent); -} - static uint64_t designware_pcie_root_msi_read(void *opaque, hwaddr addr, unsigned size) { @@ -85,7 +78,7 @@ static void designware_pcie_root_msi_write(void *opaque, hwaddr addr, uint64_t val, unsigned len) { DesignwarePCIERoot *root = DESIGNWARE_PCIE_ROOT(opaque); - DesignwarePCIEHost *host = designware_pcie_root_to_host(root); + DesignwarePCIEHost *host = root->host; root->msi.intr[0].status |= BIT(val) & root->msi.intr[0].enable; @@ -300,7 +293,7 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address, uint32_t val, int len) { DesignwarePCIERoot *root = DESIGNWARE_PCIE_ROOT(d); - DesignwarePCIEHost *host = designware_pcie_root_to_host(root); + DesignwarePCIEHost *host = root->host; DesignwarePCIEViewport *viewport = designware_pcie_root_get_current_viewport(root); @@ -392,7 +385,8 @@ static char *designware_pcie_viewport_name(const char *direction, static void designware_pcie_root_realize(PCIDevice *dev, Error **errp) { DesignwarePCIERoot *root = DESIGNWARE_PCIE_ROOT(dev); - DesignwarePCIEHost *host = designware_pcie_root_to_host(root); + DesignwarePCIEHost *host = DESIGNWARE_PCIE_HOST( + qdev_get_parent_bus(DEVICE(dev))->parent); MemoryRegion *host_mem = get_system_memory(); MemoryRegion *address_space = &host->pci.memory; PCIBridge *br = PCI_BRIDGE(dev); @@ -406,6 +400,7 @@ static void designware_pcie_root_realize(PCIDevice *dev, Error **errp) size_t i; br->bus_name = "dw-pcie"; + root->host = host; pci_set_word(dev->config + PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);