Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 35707C6379F for ; Mon, 20 Feb 2023 19:51:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 87B2985933; Mon, 20 Feb 2023 20:50:33 +0100 (CET) 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="mD2yWjcF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECE64858ED; Mon, 20 Feb 2023 20:49:56 +0100 (CET) Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 B555D85931 for ; Mon, 20 Feb 2023 20:49:43 +0100 (CET) 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-io1-xd32.google.com with SMTP id t6so1250524ioj.8 for ; Mon, 20 Feb 2023 11:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=oc54a8BbgkvFTrUIJMig3YCEoWB+NZ0kNIu5nbNyE/g=; b=mD2yWjcF8I660PFowsU+KwlKxdlNvPZ/09M+7v3jWo6oqqqqFX61NVQbHi8PujDQmf tbccycSzONHsuLCVmYXYv1WI/3YDXqPs9q310zNaJBrfb4oaDCgVZ9vPfRoNPBMEBPdR rgNc4q7CT0JHm00giDg3gExyLyKTX4MS2x9EY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=oc54a8BbgkvFTrUIJMig3YCEoWB+NZ0kNIu5nbNyE/g=; b=dGD3Caiw+BAenWv74BNsYmGtHJ1/BufKBLKtx4T45/jh2jS00LmdPP3cf/z3/FFfWW EACjpHn7nZNq50zKeYczqWQiJwzXwJyuWq5i6Gtc8BSBwMEtlIRW+UgBCsT5LZTyqwkv j1xZFyccetS/DPMEp1cB8+NpCdr0A/AdMZSb1P1CMS4pMk8m6MozUougGxpVzgKrDs3w G7nZnaKyW+RMtnNgch1JvcHWyIAXh/Ndx/NbwY5bqRb40lSCGom7LC1zTTMST85NUJ8s yh2FFzZ9Tn9mWyv2vO7RqZuKuCouodWKk3wXbaF7wa7XYKey3e3NZy4DbSne1nQtwD7F 3fRg== X-Gm-Message-State: AO0yUKXs5TeoCEt7q4ooS6guiPthMOsIffl+ZqUpRowI01YQb88GhMdi ZPHLgulZp1oXjvcqDd6Y/Qij+VKr59S2Lnxk X-Google-Smtp-Source: AK7set9LM1y07/97O1M/s7QRBhWaWdvluHHXcwnEx9Zyy+gDSn/6htE+Wp19LaGaAS9eGEqU9I+YAQ== X-Received: by 2002:a6b:6116:0:b0:745:cc89:f2cf with SMTP id v22-20020a6b6116000000b00745cc89f2cfmr10392563iob.10.1676922582114; Mon, 20 Feb 2023 11:49:42 -0800 (PST) Received: from kea.bld.corp.google.com ([2620:15c:183:200:9f65:93e2:a4c7:ed10]) by smtp.gmail.com with ESMTPSA id e7-20020a056638020700b003c4ec576030sm587521jaq.4.2023.02.20.11.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 11:49:41 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Stefan Roese Subject: [PATCH 06/13] x86: Allow locating UARTs by device ID Date: Mon, 20 Feb 2023 12:49:20 -0700 Message-Id: <20230220194927.476708-7-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230220194927.476708-1-sjg@chromium.org> References: <20230220194927.476708-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean When coreboot does not pass a UART in its sysinfo struct, there is no easy way to find it out. Add a way to specify known UARTs so we can find them without needing help from coreboot. Since coreboot does not actually init the serial device when serial is disabled, it is not possible to make it add this information to the sysinfo table. Also, we cannot use the class information, since we don't know which UART is being used. For example, with Alder Lake there are two: 00.16.00 0x8086 0x51e0 Simple comm. controller 0x80 00.1e.00 0x8086 0x51a8 Simple comm. controller 0x80 In our case the second one is the right one, but thre is no way to distinguish it from the first one without using the device ID. If we have Adler Lake hardware which uses a different UART, we could perhaps look at the ACPI tables, or the machine information passed in the SMBIOS tables. This was discussed previously before: [1] [1] https://patchwork.ozlabs.org/project/uboot/patch/ 20210407163159.3.I967ea8c85e009f870c7aa944372d32c990f1b14a@changeid/ Signed-off-by: Simon Glass --- arch/x86/dts/coreboot.dts | 4 ++ drivers/serial/serial_coreboot.c | 69 ++++++++++++++++++++++++++++---- include/pci_ids.h | 3 ++ 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/arch/x86/dts/coreboot.dts b/arch/x86/dts/coreboot.dts index d21978d6e09..3cd23b797ab 100644 --- a/arch/x86/dts/coreboot.dts +++ b/arch/x86/dts/coreboot.dts @@ -14,6 +14,8 @@ /include/ "rtc.dtsi" #include "tsc_timer.dtsi" +#include +#include / { model = "coreboot x86 payload"; @@ -34,6 +36,8 @@ pci { compatible = "pci-x86"; u-boot,dm-pre-reloc; + u-boot,pci-pre-reloc = < + PCI_VENDEV(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ADP_P_UART0) >; }; serial: serial { diff --git a/drivers/serial/serial_coreboot.c b/drivers/serial/serial_coreboot.c index de09c8681f5..4d960bbe04d 100644 --- a/drivers/serial/serial_coreboot.c +++ b/drivers/serial/serial_coreboot.c @@ -11,19 +11,72 @@ #include #include +static const struct pci_device_id ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL_UART2) }, + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ADP_P_UART0) }, + {}, +}; + +/* + * Coreboot only sets up the UART if it uses it and doesn't bother to put the + * details in sysinfo if it doesn't. Try to guess in that case, using devices + * we know about + * + * @plat: Platform data to fill in + * @return 0 if found, -ve if no UART was found + */ +static int guess_uart(struct ns16550_plat *plat) +{ + struct udevice *bus, *dev; + ulong addr; + int index; + int ret; + + ret = uclass_first_device_err(UCLASS_PCI, &bus); + if (ret) + return ret; + index = 0; + ret = pci_bus_find_devices(bus, ids, &index, &dev); + if (ret) + return ret; + addr = dm_pci_read_bar32(dev, 0); + plat->base = addr; + plat->reg_shift = 2; + plat->reg_width = 4; + plat->clock = 1843200; + plat->fcr = UART_FCR_DEFVAL; + plat->flags = 0; + + return 0; +} + static int coreboot_of_to_plat(struct udevice *dev) { struct ns16550_plat *plat = dev_get_plat(dev); struct cb_serial *cb_info = lib_sysinfo.serial; - plat->base = cb_info->baseaddr; - plat->reg_shift = cb_info->regwidth == 4 ? 2 : 0; - plat->reg_width = cb_info->regwidth; - plat->clock = cb_info->input_hertz; - plat->fcr = UART_FCR_DEFVAL; - plat->flags = 0; - if (cb_info->type == CB_SERIAL_TYPE_IO_MAPPED) - plat->flags |= NS16550_FLAG_IO; + if (cb_info) { + plat->base = cb_info->baseaddr; + plat->reg_shift = cb_info->regwidth == 4 ? 2 : 0; + plat->reg_width = cb_info->regwidth; + plat->clock = cb_info->input_hertz; + plat->fcr = UART_FCR_DEFVAL; + plat->flags = 0; + if (cb_info->type == CB_SERIAL_TYPE_IO_MAPPED) + plat->flags |= NS16550_FLAG_IO; + } else if (CONFIG_IS_ENABLED(PCI)) { + int ret; + + ret = guess_uart(plat); + if (ret) { + /* + * Returning an error will cause U-Boot to complain that + * there is no UART, which may panic. So stay silent and + * pray that the video console will work. + */ + log_debug("Cannot detect UART\n"); + } + } return 0; } diff --git a/include/pci_ids.h b/include/pci_ids.h index 88b0a640458..5ae1b9b7fb6 100644 --- a/include/pci_ids.h +++ b/include/pci_ids.h @@ -2992,6 +2992,9 @@ #define PCI_DEVICE_ID_INTEL_UNC_R3QPI1 0x3c45 #define PCI_DEVICE_ID_INTEL_JAKETOWN_UBOX 0x3ce0 #define PCI_DEVICE_ID_INTEL_IOAT_SNB 0x402f +#define PCI_DEVICE_ID_INTEL_ADP_P_UART0 0x51a8 +#define PCI_DEVICE_ID_INTEL_ADP_P_UART1 0x51a9 +#define PCI_DEVICE_ID_INTEL_APL_UART2 0x5ac0 #define PCI_DEVICE_ID_INTEL_5100_16 0x65f0 #define PCI_DEVICE_ID_INTEL_5100_19 0x65f3 #define PCI_DEVICE_ID_INTEL_5100_21 0x65f5 -- 2.39.2.637.g21b0678d19-goog