Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oScPD-0006U9-0f for mharc-grub-devel@gnu.org; Mon, 29 Aug 2022 06:54:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oScPA-0006TO-RG for grub-devel@gnu.org; Mon, 29 Aug 2022 06:54:08 -0400 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]:51238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oScP7-00046t-LI for grub-devel@gnu.org; Mon, 29 Aug 2022 06:54:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=N7XWkb8poY8+2GKBdx74nFtk32BsHCIHa0z+DJATS6g=; b=GzuFzwk83Y+KzRF1ktFWyLCE1x GOiKJUFXBmdJbcY2i8eBQGlJEu1/xHNFiNfy04g1f+DVAtLqlVXx9fOhsmNB+UmIqwYs6KuI+nl9o rHH4yvQrnlsC22tyzFAaNMwX2YAxpHa+CgB36XyUWc1MhKxTUZN34LX7kRoRTdBtjaZNMPPgFTIIN bFQZJwVP6Kxbz3v1Uum5v6QazrYTe5k7M2D3d8U/TiUHYq90nxBZ8OuiHTF+yvV/fMqRZwaEwq4Ho WDsuuB3vyXiJTkPLRobOpohF/9H9nVNO7kAJuk5WuLclMg2ypZg72kBTdXQGRNrVwEKr6IvNKvSZi rL9WUMAw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oScOz-0031dk-6r; Mon, 29 Aug 2022 10:53:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 92CFF300137; Mon, 29 Aug 2022 12:53:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5BF6E2083F6F4; Mon, 29 Aug 2022 12:53:54 +0200 (CEST) Date: Mon, 29 Aug 2022 12:53:54 +0200 From: Peter Zijlstra To: Glenn Washburn 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: References: <20220826110142.966628595@alderlake.programming.kicks-ass.net> <20220826111358.334758397@alderlake.programming.kicks-ass.net> <20220826133225.2471c2aa@crass-HP-ZBook-15-G2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220826133225.2471c2aa@crass-HP-ZBook-15-G2> Received-SPF: none client-ip=2001:8b0:10b:1236::1; envelope-from=peterz@infradead.org; helo=casper.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=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: Mon, 29 Aug 2022 10:54:09 -0000 On Fri, Aug 26, 2022 at 01:32:25PM -0500, Glenn Washburn wrote: > 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? Correct. Without that the IO port doesn't function and life is sad :-) > Either way, I think it would be better to example would be something > like: > > GRUB_SERIAL_COMMAND="serial --speed=115200 pci0" This made me think the below delta might be a better option. Then we could write: GRUB_SERIAL_COMMAND="serial --speed=115200 pci,00:16.3" Hmm? --- Index: grub/grub-core/term/pci/serial.c =================================================================== --- grub.orig/grub-core/term/pci/serial.c +++ grub/grub-core/term/pci/serial.c @@ -30,10 +30,10 @@ find_pciserial (grub_pci_device_t dev, g struct grub_serial_port *port; grub_uint32_t class, bar; grub_uint16_t cmdreg; - int *port_num = data; grub_err_t err; (void)pciid; + (void)data; cmd_addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); cmdreg = grub_pci_read (cmd_addr); @@ -57,7 +57,10 @@ find_pciserial (grub_pci_device_t dev, g if (port == NULL) return 0; - port->name = grub_xasprintf ("pci%d", (*port_num)); + port->name = grub_xasprintf ("pci,%02x:%02x.%x", + grub_pci_get_bus (dev), + grub_pci_get_device (dev), + grub_pci_get_function (dev)); if (port->name == NULL) goto error; @@ -76,8 +79,6 @@ find_pciserial (grub_pci_device_t dev, g if (err != GRUB_ERR_NONE) goto error; - (*port_num)++; - return 0; error: @@ -89,7 +90,5 @@ error: void grub_pciserial_init (void) { - int port_num; - - grub_pci_iterate (find_pciserial, &port_num); + grub_pci_iterate (find_pciserial, NULL); }