From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oRe8A-0004Tt-KJ for mharc-grub-devel@gnu.org; Fri, 26 Aug 2022 14:32:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRe89-0004TC-A4 for grub-devel@gnu.org; Fri, 26 Aug 2022 14:32:33 -0400 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:40611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRe86-0005LF-Jw for grub-devel@gnu.org; Fri, 26 Aug 2022 14:32:32 -0400 Received: by mail-qv1-xf30.google.com with SMTP id m17so1692553qvv.7 for ; Fri, 26 Aug 2022 11:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc; bh=4PkJGz1uWybWGo8tWXQOjGt7+bgFDMojUeCpE7D+tmM=; b=SwWnSdFmmIqmeXAwUw234zMqGqlbmH2Wuc8JfYGqG3jlnRzC5r5e2lsZyZiyRU8AwV d+NFConDtQ3sToclc5csNql1h/OxeuwYWKQf4XkptXGC9l5+snkqFD+sGN3VBMgwWA3n Enssn1TVJse0e0uRTEV4BOIScs0AJCG/yuK6sHNwC2Y56imAf0pFk98kHMWboU9ufUMg WWyBqlLWue+pLdzH7tDacDB2p+Ohmlp7h3P1K96jx3zHBfGpCsHHwENYYz5ZC13CrsQ0 UXS77dpbT33aL/8N8Gytx+n29jVSVE2k8xDomxRSdcGOLuvDuB3Nc/5mmFw4C0yMyWXm KOxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc; bh=4PkJGz1uWybWGo8tWXQOjGt7+bgFDMojUeCpE7D+tmM=; b=Me17Y+7RICUADPDdncHpU1JpTkqQJMeGl8m38E+rTL+vpqyHpEumDSUEqFJwg09o7h WSVqUqcbgPfrclTDi8xeYdatcvUuJiqwUiDTg0Dw2G7eIswWegbLd+A5bR5oqXJM4r2m mAF9vVmibR83/mjb0E3qHME++Ayu5kjcWanWp+EGpS0lduIIKiTk1qD0Jd5w4TzWrsA+ 1DyUKHCxH6HvmVsb34XOPcziy6IlHW5Up7nrvb3ei400UJG92TqE3OCzCxQZJeE/Wy3J 0uYvqIuY0rcPZmfU4zVhn71XxJHfJP3ieFZ3QSl8Ku94Rr0wtFiuf1fwmDtHQ36V5/yn ekSA== X-Gm-Message-State: ACgBeo1zQ7eB1k8jOlAScormcJFnQQbKVDXbB9ddTSQo6P3SZNkSy/Og AgtxKgxFBQ3w3I3F5dWXk79QCA== X-Google-Smtp-Source: AA6agR79B0TUmaG0Jfxy6U2zzZBv0YZbi47TVXA2JQmmkrbO8tA7a4cMyn3y/zSf47YVh9bYU8Sx0Q== X-Received: by 2002:ad4:5bcd:0:b0:496:e924:5351 with SMTP id t13-20020ad45bcd000000b00496e9245351mr799684qvt.37.1661538749165; Fri, 26 Aug 2022 11:32:29 -0700 (PDT) Received: from crass-HP-ZBook-15-G2 ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id r6-20020a05620a298600b006b98315c6fbsm344153qkp.1.2022.08.26.11.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 11:32:29 -0700 (PDT) Date: Fri, 26 Aug 2022 13:32:25 -0500 From: Glenn Washburn To: peterz@infradead.org Cc: grub-devel@gnu.org, dkiper@net-space.pl Subject: Re: [PATCH v2 2/3] term/serial: Add support for PCI serial devices Message-ID: <20220826133225.2471c2aa@crass-HP-ZBook-15-G2> In-Reply-To: <20220826111358.334758397@alderlake.programming.kicks-ass.net> References: <20220826110142.966628595@alderlake.programming.kicks-ass.net> <20220826111358.334758397@alderlake.programming.kicks-ass.net> Reply-To: development@efficientek.com X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2607:f8b0:4864:20::f30; envelope-from=development@efficientek.com; helo=mail-qv1-xf30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2022 18:32:34 -0000 On Fri, 26 Aug 2022 13:01:44 +0200 peterz@infradead.org wrote: > Loosely based on early_pci_serial_init() from Linux, allow GRUB to make > use of PCI serial devices. > > Specifically, my Alderlake NUC exposes the Intel AMT SoL UART as a PCI > enumerated device but doesn't include it in the EFI tables. > > Tested and confirmed working on a "Lenovo P360 Tiny" with Intel AMT > enabled. This specific machine has (from lspci -vv): > > 00:16.3 Serial controller: Intel Corporation Device 7aeb (rev 11) (prog-if 02 [16550]) > DeviceName: Onboard - Other > Subsystem: Lenovo Device 330e > Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- > Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- SERR- Interrupt: pin D routed to IRQ 19 > Region 0: I/O ports at 40a0 [size=8] > Region 1: Memory at b4224000 (32-bit, non-prefetchable) [size=4K] > Capabilities: [40] MSI: Enable- Count=1/1 Maskable- 64bit+ > Address: 0000000000000000 Data: 0000 > Capabilities: [50] Power Management version 3 > Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0-,D1-,D2-,D3hot-,D3cold-) > Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME- > Kernel driver in use: serial > > >From which the following config (/etc/default/grub) gets a working > serial setup: > > GRUB_CMDLINE_LINUX="console=tty0 earlyprintk=pciserial,00:16.3,115200 console=ttyS0,115200" > GRUB_SERIAL_COMMAND="serial --port=0x40a0 --speed=115200" Forgive my ignorance, I'm a bit confused why the above line does not work without the patch, or does it? Is it because the line "grub_pci_write (cmd_addr, cmdreg | GRUB_PCI_COMMAND_IO_ENABLED);" was needed to enable that IO port? Either way, I think it would be better to example would be something like: GRUB_SERIAL_COMMAND="serial --speed=115200 pci0" Otherwise, LGTM. Reviewed-by: Glenn Washburn Glenn > GRUB_TERMINAL="serial console" > > Signed-off-by: Peter Zijlstra (Intel) > --- > > Index: grub/grub-core/Makefile.core.def > =================================================================== > --- grub.orig/grub-core/Makefile.core.def > +++ grub/grub-core/Makefile.core.def > @@ -2047,6 +2047,7 @@ module = { > ieee1275 = term/ieee1275/serial.c; > mips_arc = term/arc/serial.c; > efi = term/efi/serial.c; > + pci = term/pci/serial.c; > > enable = terminfomodule; > enable = ieee1275; > Index: grub/grub-core/term/pci/serial.c > =================================================================== > --- /dev/null > +++ grub/grub-core/term/pci/serial.c > @@ -0,0 +1,95 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2022 Free Software Foundation, Inc. > + * > + * GRUB is free software: you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation, either version 3 of the License, or > + * (at your option) any later version. > + * > + * GRUB is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with GRUB. If not, see . > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int > +find_pciserial (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) > +{ > + grub_pci_address_t cmd_addr, class_addr, bar_addr; > + struct grub_serial_port *port; > + grub_uint32_t class, bar; > + grub_uint16_t cmdreg; > + int *port_num = data; > + grub_err_t err; > + > + (void)pciid; > + > + cmd_addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); > + cmdreg = grub_pci_read (cmd_addr); > + > + class_addr = grub_pci_make_address (dev, GRUB_PCI_REG_REVISION); > + class = grub_pci_read (class_addr); > + > + bar_addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); > + bar = grub_pci_read (bar_addr); > + > + /* 16550 compattible MODEM or SERIAL */ > + if (((class >> 16) != GRUB_PCI_CLASS_COMMUNICATION_MODEM && > + (class >> 16) != GRUB_PCI_CLASS_COMMUNICATION_SERIAL) || > + ((class >> 8) & 0xff) != GRUB_PCI_SERIAL_16550_COMPATIBLE) > + return 0; > + > + if ((bar & GRUB_PCI_ADDR_SPACE_MASK) != GRUB_PCI_ADDR_SPACE_IO) > + return 0; > + > + port = grub_zalloc (sizeof (*port)); > + if (port == NULL) > + return 0; > + > + port->name = grub_xasprintf ("pci%d", (*port_num)); > + if (port->name == NULL) > + goto error; > + > + grub_pci_write (cmd_addr, cmdreg | GRUB_PCI_COMMAND_IO_ENABLED); > + > + port->driver = &grub_ns8250_driver; > + port->port = bar & GRUB_PCI_ADDR_IO_MASK; > + err = grub_serial_config_defaults (port); > + if (err != GRUB_ERR_NONE) > + { > + grub_print_error (); > + goto error; > + } > + > + err = grub_serial_register (port); > + if (err != GRUB_ERR_NONE) > + goto error; > + > + (*port_num)++; > + > + return 0; > + > +error: > + grub_free (port->name); > + grub_free (port); > + return 0; > +} > + > +void > +grub_pciserial_init (void) > +{ > + int port_num; > + > + grub_pci_iterate (find_pciserial, &port_num); > +} > Index: grub/grub-core/term/serial.c > =================================================================== > --- grub.orig/grub-core/term/serial.c > +++ grub/grub-core/term/serial.c > @@ -448,6 +448,9 @@ GRUB_MOD_INIT(serial) > #ifdef GRUB_MACHINE_ARC > grub_arcserial_init (); > #endif > +#ifdef GRUB_HAS_PCI > + grub_pciserial_init (); > +#endif > } > > GRUB_MOD_FINI(serial) > Index: grub/include/grub/pci.h > =================================================================== > --- grub.orig/include/grub/pci.h > +++ grub/include/grub/pci.h > @@ -80,8 +80,13 @@ > > #define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9 > #define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600 > + > #define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300 > #define GRUB_PCI_CLASS_SUBCLASS_USB 0x0c03 > +#define GRUB_PCI_CLASS_COMMUNICATION_SERIAL 0x0700 > +#define GRUB_PCI_CLASS_COMMUNICATION_MODEM 0x0703 > + > +#define GRUB_PCI_SERIAL_16550_COMPATIBLE 0x02 > > #ifndef ASM_FILE > > Index: grub/include/grub/serial.h > =================================================================== > --- grub.orig/include/grub/serial.h > +++ grub/include/grub/serial.h > @@ -193,6 +193,10 @@ const char * > grub_arcserial_add_port (const char *path); > #endif > > +#ifdef GRUB_HAS_PCI > +void grub_pciserial_init (void); > +#endif > + > struct grub_serial_port *grub_serial_find (const char *name); > extern struct grub_serial_driver grub_ns8250_driver; > void EXPORT_FUNC(grub_serial_unregister_driver) (struct grub_serial_driver *driver); > >