From nobody Fri Mar 29 11:06:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org ARC-Seal: i=1; a=rsa-sha256; t=1621753727; cv=none; d=zohomail.com; s=zohoarc; b=VfA9ySlw90r9W4knMhpPiBReDAYs2r3g7dWwMIzmomff4EC7xueky0Z1ZG31lzcsAQ8W9LmEdAjoUwyEzuaw1RTWImBq7lGAYyEkNx0ELLCnQi8jgMSWRQb+oUvZ15RlvlcZZCSiUe9Gdj8FWCfRvKY8c2ZS3+lOyT4KX9Anhxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621753727; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=q+J3TfB8msKuFTRA6iKEr8OG0rMA4IhhuphEs+Pvzv8=; b=kpaSQ5pe/ZXMaFOU+j+SReES0y3mggjk7zKGlVMbFxDhHyf82bzuxSOK0IJscltHx/+ea2hKDHEKxKvPTnnCBnSTyoEQjyJ+hAv9dtJIjrOJkoic5nTyTg7z9T3T5U8cP5ug6wmGmTa1++l//A1HshigFSmEJX3Lkft1v0Gge2k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1621753727169751.307253468541; Sun, 23 May 2021 00:08:47 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id BAC6710619FF; Sun, 23 May 2021 07:08:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 9F06A10619F2 for ; Sun, 23 May 2021 07:08:31 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout08.t-online.de (Postfix) with SMTP id C1189BC52E; Sun, 23 May 2021 09:07:49 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lkiDC-0a18Ay0; Sun, 23 May 2021 09:07:46 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 6425A20061C; Sun, 23 May 2021 09:07:46 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Sun, 23 May 2021 09:07:46 +0200 Message-Id: <20210523070746.27398-1-vr_qemu@t-online.de> In-Reply-To: References: MIME-Version: 1.0 X-ID: r31EQcZrYhriuQXLJ9TbcgLDP75jUSOqnfrE72RAxQS3ySwvweRZSlltuUB00l5ZPK X-TOI-EXPURGATEID: 150726::1621753666-0000C8B5-A973C476/0/0 CLEAN NORMAL X-TOI-MSGID: 0adead59-b492-4bc0-b450-30e3b7e5774c Message-ID-Hash: DAC5RWJGEKFCQ5IC4EDIM7E2AVPN2NO4 X-Message-ID-Hash: DAC5RWJGEKFCQ5IC4EDIM7E2AVPN2NO4 X-MailFrom: volker.ruemelin@t-online.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: seabios@seabios.org X-Mailman-Version: 3.3.4 Precedence: list Subject: [SeaBIOS] [PATCH] stacks: call check_irqs() in run_thread() List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- The comment above the yield() function suggests that yield() allows interrupts for a short time. But yield() only briefly enables interrupts if SeaBIOS was built without CONFIG_THREADS or if yield() is called from the main thread. In order to guarantee that interrupts were enabled once before yield() returns in a background thread, the main thread must call check_irqs() before every thread switch. The function run_thread() also switches threads, but the call to check_irqs() was forgotten. Add the missing check_irqs() call. This fixes PS/2 keyboard initialization failures. The code in src/hw/ps2port.c relies on yield() to briefly enable interrupts. There is a comment above the yield() function in __ps2_command(), where the author left a remark why the call to yield() is actually needed. Here is one of the call sequences leading to a PS/2 keyboard initialization failure. ps2_keyboard_setup() | ret =3D i8042_command(I8042_CMD_KBD_DISABLE, NULL); # This command will register an interrupt if the PS/2 device # controller raises interrupts for replies to a controller # command. | ret =3D ps2_kbd_command(ATKBD_CMD_RESET_BAT, param); | ps2_command(0, command, param); | ret =3D __ps2_command(aux, command, param); | // Flush any interrupts already pending. yield(); # yield() doesn't flush interrupts if the main thread # hasn't reached wait_threads(). | ret =3D ps2_sendbyte(aux, command, 1000); # Reset the PS/2 keyboard controller and wait for # PS2_RET_ACK. | ret =3D ps2_recvbyte(aux, 0, 4000); | for (;;) { | status =3D inb(PORT_PS2_STATUS); # I8042_STR_OBF isn't set because the keyboard self # test reply is still on wire. | yield(); # After a few yield()s the keyboard interrupt fires # and clears the I8042_STR_OBF status bit. If the # keyboard self test reply arrives before the # interrupt fires the keyboard reply is lost and # ps2_recvbyte() returns after the timeout. } Suggested-by: Kevin O'Connor Signed-off-by: Volker R=C3=BCmelin --- src/stacks.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stacks.c b/src/stacks.c index 2fe1bfb..641b13f 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -549,7 +549,10 @@ __end_thread(struct thread_info *old) dprintf(1, "All threads complete.\n"); } =20 -// Create a new thread and start executing 'func' in it. +void VISIBLE16 check_irqs(void); + +// Create a new thread. Briefly permit irqs to occur and start +// executing 'func' in the new thread. void run_thread(void (*func)(void*), void *data) { @@ -565,6 +568,10 @@ run_thread(void (*func)(void*), void *data) thread->stackpos =3D (void*)thread + THREADSTACKSIZE; struct thread_info *cur =3D getCurThread(); hlist_add_after(&thread->node, &cur->node); + if (cur =3D=3D &MainThread) + // Permit irqs to fire + check_irqs(); + asm volatile( // Start thread " pushl $1f\n" // store return pc --=20 2.26.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org