From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16B8AC48BC2 for ; Sun, 27 Jun 2021 23:51:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93F6261C31 for ; Sun, 27 Jun 2021 23:51:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93F6261C31 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3FBE682D78; Mon, 28 Jun 2021 01:51:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="aF2moAiH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F3A882D6F; Mon, 28 Jun 2021 01:51:29 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6807982CE9 for ; Mon, 28 Jun 2021 01:51:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x331.google.com with SMTP id o13-20020a9d404d0000b0290466630039caso1539798oti.6 for ; Sun, 27 Jun 2021 16:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w5XIJ/YT2j6SKy9DYbVLgfyX9CU/arJRD8mKpgO4ghE=; b=aF2moAiH/68pExFfREmkFpIOjVSjV2076d371nynIQ2Cm4f1UdTYlQIYwlxJntx9Q4 jg7hXubWW6B8sDJx4u+YRqwgsn5fOJt0lhdkrG5jvnnQrwwQNsCbjjaZ0jRbkWhzMC2X glpd2rFLyqlrTbcmkbk+IEG2tj6qCH2YpEiLI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w5XIJ/YT2j6SKy9DYbVLgfyX9CU/arJRD8mKpgO4ghE=; b=q0knjHZttcW/vQt9UrUviYt7zdZBeX6tt9kqRRTRllSjJtdovZPSn6PpR06g6X64dQ XHZrnqky3TQ5p+3pAioMn/QnF6mye4aZZ0sG5uYg/a633IFh7RqUKYkp0loKVUd17Jmv Nwa0bQu2Ysq+zQy75y7yIarkcqIi8nQXxubogagWHCzjQGAQj9HZ1vvW3HOOIPoAMEPI YxaXj0mhzFKEuyzr7iDY7MIom49FVqJlNU9Vx/nvEjjvpda2gIy2eEMq6q8T+p31FCLD ASG2PA52oTNBzx+Qjtr/YueJXOcw7Tyf8l4M3gnF3W/lSxIZurv/ch0nYcHVIyB/r0Ed FvWw== X-Gm-Message-State: AOAM532ypo3/H9EJtxLP5F+N/66BgoXxsQF01gKWIHQwYQs7aTGkrtNc XcIYJat5XG/eKNHK0H9kXqY8TxUYSPgBsurk X-Google-Smtp-Source: ABdhPJyB5j9jfz2Z2whyR3nE3U/BsjRyEQsoubzwY/YmWu2nHxxmBWDuM28LUF6EhEgLFPj6kOO4Uw== X-Received: by 2002:a05:6830:314b:: with SMTP id c11mr18537787ots.358.1624837881972; Sun, 27 Jun 2021 16:51:21 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id bb34sm1297928oob.39.2021.06.27.16.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 16:51:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng Subject: [PATCH v3 02/16] x86: pci: Allow binding of some devices before relocation Date: Sun, 27 Jun 2021 17:50:57 -0600 Message-Id: <20210627235111.485507-3-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210627235111.485507-1-sjg@chromium.org> References: <20210627235111.485507-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean At present only bridge devices are bound before relocation, to save space in pre-relocation memory. In some cases we do actually want to bind a device, e.g. because it provides the console UART. Add a devicetree binding to support this. Use the PCI_VENDEV() macro to encode the cell value. This is present in U-Boot but not used, so move it to the binding header-file. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- (no changes since v1) doc/device-tree-bindings/pci/x86-pci.txt | 7 ++++- drivers/pci/pci-uclass.c | 33 +++++++++++++++++++++++- include/dt-bindings/pci/pci.h | 12 +++++++++ include/pci.h | 1 - 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 include/dt-bindings/pci/pci.h diff --git a/doc/device-tree-bindings/pci/x86-pci.txt b/doc/device-tree-bindings/pci/x86-pci.txt index 95e370b3e72..cf4e5ed595a 100644 --- a/doc/device-tree-bindings/pci/x86-pci.txt +++ b/doc/device-tree-bindings/pci/x86-pci.txt @@ -20,6 +20,10 @@ For PCI devices the following optional property is available: output to be lost. This should not generally be used in production code, although it is often harmless. +- u-boot,pci-pre-reloc : List of vendor/device IDs to bind before relocation, even + if they are not bridges. This is useful if the device is needed (e.g. a + UART). The format is 0xvvvvdddd where d is the device ID and v is the + vendor ID. Example: @@ -32,7 +36,8 @@ pci { 0x42000000 0x0 0xb0000000 0xb0000000 0 0x10000000 0x01000000 0x0 0x1000 0x1000 0 0xefff>; u-boot,skip-auto-config-until-reloc; - + u-boot,pci-pre-reloc = < + PCI_VENDEV(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL_UART2)>; serial: serial@18,2 { reg = <0x0200c210 0 0 0 0>; diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index d64fbe0627b..4b52620d6af 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -19,6 +19,7 @@ #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) #include #endif +#include #include #include "pci_internal.h" @@ -676,6 +677,34 @@ static bool pci_match_one_id(const struct pci_device_id *id, return false; } +/** + * pci_need_device_pre_reloc() - Check if a device should be bound + * + * This checks a list of vendor/device-ID values indicating devices that should + * be bound before relocation. + * + * @bus: Bus to check + * @vendor: Vendor ID to check + * @device: Device ID to check + * @return true if the vendor/device is in the list, false if not + */ +static bool pci_need_device_pre_reloc(struct udevice *bus, uint vendor, + uint device) +{ + u32 vendev; + int index; + + for (index = 0; + !dev_read_u32_index(bus, "u-boot,pci-pre-reloc", index, + &vendev); + index++) { + if (vendev == PCI_VENDEV(vendor, device)) + return true; + } + + return false; +} + /** * pci_find_and_bind_driver() - Find and bind the right PCI driver * @@ -764,7 +793,9 @@ static int pci_find_and_bind_driver(struct udevice *parent, * precious memory space as on some platforms as that space is pretty * limited (ie: using Cache As RAM). */ - if (!(gd->flags & GD_FLG_RELOC) && !bridge) + if (!(gd->flags & GD_FLG_RELOC) && !bridge && + !pci_need_device_pre_reloc(parent, find_id->vendor, + find_id->device)) return log_msg_ret("notbr", -EPERM); /* Bind a generic driver so that the device can be used */ diff --git a/include/dt-bindings/pci/pci.h b/include/dt-bindings/pci/pci.h new file mode 100644 index 00000000000..e7290277b90 --- /dev/null +++ b/include/dt-bindings/pci/pci.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * This header provides common constants for PCI bindings. + */ + +#ifndef _DT_BINDINGS_PCI_PCI_H +#define _DT_BINDINGS_PCI_PCI_H + +/* Encode a vendor and device ID into a single cell */ +#define PCI_VENDEV(v, d) (((v) << 16) | (d)) + +#endif /* _DT_BINDINGS_PCI_PCI_H */ diff --git a/include/pci.h b/include/pci.h index 2ee6138324f..9eb28aba049 100644 --- a/include/pci.h +++ b/include/pci.h @@ -578,7 +578,6 @@ typedef int pci_dev_t; #define PCI_MASK_BUS(bdf) ((bdf) & 0xffff) #define PCI_ADD_BUS(bus, devfn) (((bus) << 16) | (devfn)) #define PCI_BDF(b, d, f) ((b) << 16 | PCI_DEVFN(d, f)) -#define PCI_VENDEV(v, d) (((v) << 16) | (d)) #define PCI_ANY_ID (~0) /* Convert from Linux format to U-Boot format */ -- 2.32.0.93.g670b81a890-goog