From patchwork Tue Mar 16 21:16:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RBZ0mbhz9sRR for ; Wed, 17 Mar 2021 08:24:36 +1100 (AEDT) Received: from localhost ([::1]:36248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHB4-0000RG-1t for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:24:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3U-0006gb-AZ for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:44 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:54871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3Q-0003xE-Kg for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:44 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N17gy-1lpbbT0agk-012WBt; Tue, 16 Mar 2021 22:16:37 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/7] mac_via: switch rtc pram trace-events to use hex rather than decimal for addresses Date: Tue, 16 Mar 2021 22:16:25 +0100 Message-Id: <20210316211631.107417-2-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:YMs8kFXOEqihu3tIhuovcKcubK+hXhvAUJLE0WKcevNhpGcxCiG OWE5wd/CZWUxfqn7CdpjyWn0To5E1Y03GoDsydBEsvy04NCiNfRcbZblbESSqhOAfYHwDmq DCy0gSmwkSFOPmEONozBvN5o+AA4UY2V/2UTBSCTCHeeJ/8lPsHh0tS6OJPlxFvCxfIaU3W 7zAbuOORwt5nzxRgrRYWQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:nFRosDrV5tU=:CSBZwbxkn+rOQLQEQdLYHy RhR39D7shdyJF7R7KoFMpB73kF9CMpqTUMchDP46q3QICjR4m2ioHHITTjOHKzfgQ1Wnxhuvc BusmuTOELZHlfyQV09Zla5S4Kzh9DLcQiQgnUg16tG1zTUrsktwoUOvot1WFes+6XwVPN1/9a 4vFNd005jm4LyEpBt2jeIhtfiRa20npYBKtP+ECJaLeli+cXg4PYJUrlQHuVVKC1TYdFhvANU sThdLutibkwK7oQADHJRT7qCl7XABW+LM9UNqPWi3ODN/IHFHY6/kQnIwFpNQcbQJYXdG0rbv YQOG1nKqb8hFwzLvvK4GMqn++AUicHUN29lgMDcIKv/kxJhxOoEKz+yVCJL6nY9WJrfGHSTos WgFNCCWcbIuoaoHA6W09ZThNe3FJs/5QrJAOCAkC3qVTLKaQTGyZKk7G+3qcVpqq2wdgwSiR8 +pmQBtfm5A== Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland Since all the documentation uses the hex offsets, this makes it much easier to see what is going on. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-Id: <20210311100505.22596-2-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/trace-events | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index b87d0b4c906a..fa422727aeb7 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -233,8 +233,8 @@ via1_rtc_cmd_test_write(int value) "value=0x%02x" via1_rtc_cmd_wprotect_write(int value) "value=0x%02x" via1_rtc_cmd_pram_read(int addr, int value) "addr=%u value=0x%02x" via1_rtc_cmd_pram_write(int addr, int value) "addr=%u value=0x%02x" -via1_rtc_cmd_pram_sect_read(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=%d value=0x%02x" -via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=%d value=0x%02x" +via1_rtc_cmd_pram_sect_read(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=0x%x value=0x%02x" +via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=0x%x value=0x%02x" via1_adb_send(const char *state, uint8_t data, const char *vadbint) "state %s data=0x%02x vADBInt=%s" via1_adb_receive(const char *state, uint8_t data, const char *vadbint, int status, int index, int size) "state %s data=0x%02x vADBInt=%s status=0x%x index=%d size=%d" via1_adb_poll(uint8_t data, const char *vadbint, int status, int index, int size) "data=0x%02x vADBInt=%s status=0x%x index=%d size=%d" From patchwork Tue Mar 16 21:16:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RLX2qsFz9sRR for ; Wed, 17 Mar 2021 08:31:32 +1100 (AEDT) Received: from localhost ([::1]:55754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHHm-0000Fm-E8 for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:31:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3U-0006hu-Rw for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:44 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:60999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3Q-0003xG-EW for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:44 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MDhpZ-1lWQBl08Gd-00Aq8y; Tue, 16 Mar 2021 22:16:38 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/7] mac_via: fix up adb_via_receive() trace events Date: Tue, 16 Mar 2021 22:16:26 +0100 Message-Id: <20210316211631.107417-3-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:RqkzY2UO+eeyo6LUXWcwef52WykYXSf3e8jajeY8v+hw/SXfDhv CpKUiwC5WSXS+A96hnJN7thwpOCM9uJ9T8tQWAGaKXaQ8+qm8BmPvzSlMRPTOBaigm0/M0V MG4wPUkSsypgFuVtlGBkfpqreTnmmPjEDMYIuMqVkJIJg6ObgHi17aQdLmC+j9X76kStGJ4 +TEAmKWNhyZllosVoruQQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:hd5sFF52uR8=:5Dc+ie6UxHtUmtNWlkgGe4 X3Z/DntkKWCHa4/Pby/ol2r0+8tA32dtfbri8q6nIFtLOANuq0C0P1OLSjfl6z8hPzqbzVQxS I2ToHdW8ZOnlnCMTesKPYX8xLHiiEWU0w1mfZQ0sHjhYp8QyZ4UUCAPQMZpM/ct0CUPtfecV/ IxFEMaf5t8FVTGvdwoO9mC3Ujzjsp1BkkZ/BXLz+jNYWn6UUW/GSYBHQLmog7/q36l4K1LrSN XHROH+dldd958MkmOHk7pCF0Na5mfMzVAPvlosEfxitwQsZJK1DBCVtNRnW1Pzxg7FzYqfT6a L38QxbDxBdDbOUiP2miuz+UtcHjZcLZzvLdOa4u4nL6qE21loCoNlKjgL9tDjpStv7TXNDbKx vnJZVPaxIAigegTOnldOVaZMMUZAJqTZvfvzPag2D006znUobC5QbYPA8j5+t665XoGjR6mjH WIPefpO/uw== Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The use of the post-increment operator on adb_data_in_index meant that the trace-event was accidentally displaying the next byte in the incoming ADB data buffer rather than the current byte. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-Id: <20210311100505.22596-3-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/mac_via.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index ca2f939dd588..0a25de577cf9 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -816,33 +816,37 @@ static void adb_via_receive(MacVIAState *s, int state, uint8_t *data) switch (s->adb_data_in_index) { case 0: /* First EVEN byte: vADBInt indicates bus timeout */ - trace_via1_adb_receive(state == ADB_STATE_EVEN ? "EVEN" : " ODD", - *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", - adb_bus->status, s->adb_data_in_index, - s->adb_data_in_size); - - *data = s->adb_data_in[s->adb_data_in_index++]; + *data = s->adb_data_in[s->adb_data_in_index]; if (adb_bus->status & ADB_STATUS_BUSTIMEOUT) { ms->b &= ~VIA1B_vADBInt; } else { ms->b |= VIA1B_vADBInt; } - break; - case 1: - /* First ODD byte: vADBInt indicates SRQ */ trace_via1_adb_receive(state == ADB_STATE_EVEN ? "EVEN" : " ODD", *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", adb_bus->status, s->adb_data_in_index, s->adb_data_in_size); - *data = s->adb_data_in[s->adb_data_in_index++]; + s->adb_data_in_index++; + break; + + case 1: + /* First ODD byte: vADBInt indicates SRQ */ + *data = s->adb_data_in[s->adb_data_in_index]; pending = adb_bus->pending & ~(1 << (s->adb_autopoll_cmd >> 4)); if (pending) { ms->b &= ~VIA1B_vADBInt; } else { ms->b |= VIA1B_vADBInt; } + + trace_via1_adb_receive(state == ADB_STATE_EVEN ? "EVEN" : " ODD", + *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", + adb_bus->status, s->adb_data_in_index, + s->adb_data_in_size); + + s->adb_data_in_index++; break; default: @@ -852,14 +856,9 @@ static void adb_via_receive(MacVIAState *s, int state, uint8_t *data) * end of the poll reply, so provide these extra bytes below to * keep it happy */ - trace_via1_adb_receive(state == ADB_STATE_EVEN ? "EVEN" : " ODD", - *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", - adb_bus->status, s->adb_data_in_index, - s->adb_data_in_size); - if (s->adb_data_in_index < s->adb_data_in_size) { /* Next data byte */ - *data = s->adb_data_in[s->adb_data_in_index++]; + *data = s->adb_data_in[s->adb_data_in_index]; ms->b |= VIA1B_vADBInt; } else if (s->adb_data_in_index == s->adb_data_in_size) { if (adb_bus->status & ADB_STATUS_BUSTIMEOUT) { @@ -869,7 +868,6 @@ static void adb_via_receive(MacVIAState *s, int state, uint8_t *data) /* Return 0x0 after reply */ *data = 0; } - s->adb_data_in_index++; ms->b &= ~VIA1B_vADBInt; } else { /* Bus timeout (no more data) */ @@ -878,6 +876,15 @@ static void adb_via_receive(MacVIAState *s, int state, uint8_t *data) adb_bus->status = 0; adb_autopoll_unblock(adb_bus); } + + trace_via1_adb_receive(state == ADB_STATE_EVEN ? "EVEN" : " ODD", + *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", + adb_bus->status, s->adb_data_in_index, + s->adb_data_in_size); + + if (s->adb_data_in_index <= s->adb_data_in_size) { + s->adb_data_in_index++; + } break; } From patchwork Tue Mar 16 21:16:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RQh3qJrz9sW1 for ; Wed, 17 Mar 2021 08:35:08 +1100 (AEDT) Received: from localhost ([::1]:34636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHLF-0003Fk-Fq for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:35:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3X-0006oJ-Fl for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:47 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:58183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3Q-0003xe-Ql for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:47 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mq2vU-1m0Xo50cny-00nDIn; Tue, 16 Mar 2021 22:16:39 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/7] mac_via: allow long accesses to VIA registers Date: Tue, 16 Mar 2021 22:16:27 +0100 Message-Id: <20210316211631.107417-4-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:UeqSUK+xGf941NCWE3ZYcaOibw4lGD8AwgGdxU+eErOYHKbiSBM 9oBKrjqqpOm7JVSvAY0dIhIimirVNiw4BtzUFDTa9siJaY1pSMvgatRoTvsTwym0i/HO9af W+WnZK18TNLVhlFg/SagqVEPkc++iicosPuHgE9Py+Z9R6C25OZzCVrDIOBsgWJw7eLcnbD v07o755fYqJnMfUJDkbBQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:CqQ+QiX23uI=:DibJsKiCSofcvT3zE0yhGt nrZZkL/qRmMw3a6/6rxW/ujBVbo1JGKP4tEbTt7ZkFYKaenWB4MqG5VvhXdRe+Of9wWQvLOMq /HLnnaCHhwhOmcI4O9YEMxwf928y0p61qYWizg/zt/r7Jf9Zlqbdz0caADGWV3PJkPoHFF8DJ SdsHCzA1/UnT1Pl2KQ+7CM2ry5Pn4CaTGLJdAvMy+jMIf1qKf/AotzsEqYIoywuSocL3x0Mr9 mTmgbMCXw+NVcT2YdrbVCmBKYuVIPeNMN2HkVDO4ooJWiOsMr2oolcFQbKWPa7mxPHbUmeISm kcNmhM/Hb9uBzdnLQw/DHHVEonFThzYMpsR2Fi+h2ZgmzqdUsJhJzcmsnFc9slyuR4jfREKE/ BaC+Lipw/q1dZO7QGCTDWqwmAHpAvR2h7BatOD2DGtBgBQwPTYCtJuO/LCE3pE92lVKlbDEWX ZeexvW38zQ== Received-SPF: none client-ip=212.227.17.24; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The MacOS SCSI driver uses a long access to read the VIA registers rather than just a single byte during the message out phase. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-Id: <20210311100505.22596-4-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/mac_via.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 0a25de577cf9..8810eb97ccb7 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -966,7 +966,7 @@ static const MemoryRegionOps mos6522_q800_via1_ops = { .endianness = DEVICE_BIG_ENDIAN, .valid = { .min_access_size = 1, - .max_access_size = 1, + .max_access_size = 4, }, }; @@ -995,7 +995,7 @@ static const MemoryRegionOps mos6522_q800_via2_ops = { .endianness = DEVICE_BIG_ENDIAN, .valid = { .min_access_size = 1, - .max_access_size = 1, + .max_access_size = 4, }, }; From patchwork Tue Mar 16 21:16:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RMb4475z9sW1 for ; Wed, 17 Mar 2021 08:32:27 +1100 (AEDT) Received: from localhost ([::1]:57936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHIf-0001BG-Ic for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:32:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3V-0006iL-43 for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:45 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:42199) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3S-0003yK-MJ for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:44 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N4R4i-1loV8b2kwo-011QnV; Tue, 16 Mar 2021 22:16:39 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/7] mac_via: don't re-inject ADB response when switching to IDLE state Date: Tue, 16 Mar 2021 22:16:28 +0100 Message-Id: <20210316211631.107417-5-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:/lkjfQERd3Eyr1mqs0sqKbMkf8eK5GxYgZCy3NR6VopDqkyA1nM tdAd0yphShqz/EmNYm9RuTfWMI7sdTM1XoIEZ3cp85Dv80lZ4NtcuXRDfXaur8rcf23N7Wj JVtgImRCiZRgBKuvCtj4rk8jY9VNXJerEwZjGvBbH/mp+XTeNSpft+1l1FBPB1E2jqeI6AZ qNM0kT5FnS3UQaBKZ1g8w== X-UI-Out-Filterresults: notjunk:1;V03:K0:5andyBZZ80A=:InoVrh9lZ148KSh5ZtBopt oDxpxcMGY/5NMW+ZHBVKPo3015vHXYKVNjEKZ5tP6JLl/Il4W2fH3WykqiTHadIyeBc99VvTN +c5MdcsfWZOl1aG2q0PvU8OXs7xYKtoCufRBQNDvTD01J06Y5LkPQIUh/gV54b5og6+C4fjxm 3tl4I1Ou41pSfG8OmcIEOrEm+SDbSmvc88YG5qQXZhgEoXsr1J3NsvykZ91zi0jy0Lx9Ipcw1 mdbFW47aDXHxdntoRXkffTwUZTYlRzpSC1nhEvzIkmUNy4lI36SXAeidU0g8Rs8hqec3VGOZX tFbgiWtAUxOvtpDcoLafFA/PHncKJH8pRVi7qFXpPAPBZDQniN1w9YUHQdd+wtu2HLsG6dPf2 qWwBNdJOhJz9PDW8Tp6gIfc+pnq7Qgtq3qn3SYgpARlkvHFIS0a0NemWXVb/23mdrQvC98Scu IR05g2IzPA== Received-SPF: none client-ip=212.227.17.10; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The current workaround for the Linux ADB state machine in kernels < 5.6 switching the VIA back to IDLE state between send and receive modes is to re-inject the first byte of the response in the IDLE state, and then force the state machine into generating an autopoll reply. In fact what is happening is much simpler: analysis of traces from a real Quadra suggest that the existing data is returned as the first autopoll response rather than generating an immediate response starting whilst still in IDLE state. Update the ADB receive code to work in the same way, which allows the re-injection code to be completely removed from adb_via_receive() and for adb_via_poll() to be simplified accordingly. Signed-off-by: Mark Cave-Ayland Message-Id: <20210311100505.22596-5-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/mac_via.c | 78 ++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 51 deletions(-) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 8810eb97ccb7..4914cb809860 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -609,7 +609,6 @@ static void adb_via_poll(void *opaque) uint8_t obuf[9]; uint8_t *data = &s->sr; int olen; - uint16_t pending; /* * Setting vADBInt below indicates that an autopoll reply has been @@ -618,36 +617,36 @@ static void adb_via_poll(void *opaque) */ adb_autopoll_block(adb_bus); - m->adb_data_in_index = 0; - m->adb_data_out_index = 0; - olen = adb_poll(adb_bus, obuf, adb_bus->autopoll_mask); - - if (olen > 0) { - /* Autopoll response */ - *data = obuf[0]; - olen--; - memcpy(m->adb_data_in, &obuf[1], olen); - m->adb_data_in_size = olen; + if (m->adb_data_in_size > 0 && m->adb_data_in_index == 0) { + /* + * For older Linux kernels that switch to IDLE mode after sending the + * ADB command, detect if there is an existing response and return that + * as a a "fake" autopoll reply or bus timeout accordingly + */ + *data = m->adb_data_out[0]; + olen = m->adb_data_in_size; s->b &= ~VIA1B_vADBInt; qemu_irq_raise(m->adb_data_ready); - } else if (olen < 0) { - /* Bus timeout (device does not exist) */ - *data = 0xff; - s->b |= VIA1B_vADBInt; - adb_autopoll_unblock(adb_bus); } else { - pending = adb_bus->pending & ~(1 << (m->adb_autopoll_cmd >> 4)); + /* + * Otherwise poll as normal + */ + m->adb_data_in_index = 0; + m->adb_data_out_index = 0; + olen = adb_poll(adb_bus, obuf, adb_bus->autopoll_mask); + + if (olen > 0) { + /* Autopoll response */ + *data = obuf[0]; + olen--; + memcpy(m->adb_data_in, &obuf[1], olen); + m->adb_data_in_size = olen; - if (pending) { - /* - * Bus timeout (device exists but another device has data). Block - * autopoll so the OS can read out the first EVEN and first ODD - * byte to determine bus timeout and SRQ status - */ - *data = m->adb_autopoll_cmd; s->b &= ~VIA1B_vADBInt; - + qemu_irq_raise(m->adb_data_ready); + } else { + *data = m->adb_autopoll_cmd; obuf[0] = 0xff; obuf[1] = 0xff; olen = 2; @@ -655,12 +654,8 @@ static void adb_via_poll(void *opaque) memcpy(m->adb_data_in, obuf, olen); m->adb_data_in_size = olen; + s->b &= ~VIA1B_vADBInt; qemu_irq_raise(m->adb_data_ready); - } else { - /* Bus timeout (device exists but no other device has data) */ - *data = 0; - s->b |= VIA1B_vADBInt; - adb_autopoll_unblock(adb_bus); } } @@ -783,27 +778,8 @@ static void adb_via_receive(MacVIAState *s, int state, uint8_t *data) return; case ADB_STATE_IDLE: - /* - * Since adb_request() will have already consumed the data from the - * device, we must detect this extra state change and re-inject the - * reponse as either a "fake" autopoll reply or bus timeout - * accordingly - */ - if (s->adb_data_in_index == 0) { - if (adb_bus->status & ADB_STATUS_BUSTIMEOUT) { - *data = 0xff; - ms->b |= VIA1B_vADBInt; - qemu_irq_raise(s->adb_data_ready); - } else if (s->adb_data_in_size > 0) { - adb_bus->status = ADB_STATUS_POLLREPLY; - *data = s->adb_autopoll_cmd; - ms->b &= ~VIA1B_vADBInt; - qemu_irq_raise(s->adb_data_ready); - } - } else { - ms->b |= VIA1B_vADBInt; - adb_autopoll_unblock(adb_bus); - } + ms->b |= VIA1B_vADBInt; + adb_autopoll_unblock(adb_bus); trace_via1_adb_receive("IDLE", *data, (ms->b & VIA1B_vADBInt) ? "+" : "-", adb_bus->status, From patchwork Tue Mar 16 21:16:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RGm6C3Xz9sRR for ; Wed, 17 Mar 2021 08:28:16 +1100 (AEDT) Received: from localhost ([::1]:46858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHEc-0004xV-SF for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:28:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3a-0006vW-MG for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:50 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:49629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3Y-00041H-Hu for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:50 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MmDAc-1m4NIW1RHU-00iFUB; Tue, 16 Mar 2021 22:16:40 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/7] mac_via: rename VBL timer to 60Hz timer Date: Tue, 16 Mar 2021 22:16:29 +0100 Message-Id: <20210316211631.107417-6-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:R1UaaEEbJtMOkT2Zoa3AxJRv8CBfFvcbHFKse1gu7Yt2oUmZL3f 4v0YB5M7dfIZz8GlkLswTiwYK74wlol8dY/rxAEOD8pQgc3JXIlQv5NQJHbnFRV4BmPLFOs PJUY44r0TOBk3MgPofs0GEPDnn2FY8TWHJdZTvVELsWtZ3LWpSqDqkZEE2+ljhtWVsTzoKc DiFzZaL9gXJQa9vb1Bldw== X-UI-Out-Filterresults: notjunk:1;V03:K0:WzPqQCZVQSs=:IJEQH3VUmfMx1EPyG7C5vi 6Hu5PLD4SSPNTdTdYR5BG9GRQazs9O+6yNK3Yzg77lnPD12vAZDsKuVeYLrSUadKtD75PXid5 +6Yx3OlUu5VKt/+wl4QFPK+VYM4PAZVg2lTfLP5dHPaJE3YPuNcabU7zALhED64fyrhvXc/Mj myheLGErdbw8eCx/i3wEdAMmQQgShrUk61y9V3LX5b3hdneKZlVn3cHU6EukeSoAwLwIx8K/F tugrPynxxev15PDexSr4aoJVQOVE0d8xHHJ6q3LVBDBkS/AW6keecl43U5YLrtlHc9ESIaiNr EHc44NdwDaFpJbfq0OdGhGUI3h9oIBTu8JDntCBY1vxkxjOQlBwwj7Ert9sh5L3+tkPdVQkjL KWSW0H08o8Vfr+53o8/pbinY87xyNw/pynpUteSk/DQYrNQe1UfeeQJlLo1yfw8aCMF1ukshN vQiDEbwKqA== Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland According to the "Guide To The Macintosh Family Hardware", the 60Hz VIA1 timer on newer Macs such as the Quadra only exists for compatibility with old software and is no longer synced to the VBL interval. Rename the VBL timer to 60Hz timer to emphasise this and to prevent confusion when the real VBL interrupt (now handled as a NuBus slot interrupt) is added in future. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Reviewed-by: BALATON Zoltan Message-Id: <20210311100505.22596-6-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- include/hw/misc/mac_via.h | 8 ++++---- hw/misc/mac_via.c | 41 ++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/hw/misc/mac_via.h b/include/hw/misc/mac_via.h index a59f0bd42235..3058b30685ae 100644 --- a/include/hw/misc/mac_via.h +++ b/include/hw/misc/mac_via.h @@ -17,7 +17,7 @@ /* VIA 1 */ #define VIA1_IRQ_ONE_SECOND_BIT 0 -#define VIA1_IRQ_VBLANK_BIT 1 +#define VIA1_IRQ_60HZ_BIT 1 #define VIA1_IRQ_ADB_READY_BIT 2 #define VIA1_IRQ_ADB_DATA_BIT 3 #define VIA1_IRQ_ADB_CLOCK_BIT 4 @@ -25,7 +25,7 @@ #define VIA1_IRQ_NB 8 #define VIA1_IRQ_ONE_SECOND (1 << VIA1_IRQ_ONE_SECOND_BIT) -#define VIA1_IRQ_VBLANK (1 << VIA1_IRQ_VBLANK_BIT) +#define VIA1_IRQ_60HZ (1 << VIA1_IRQ_60HZ_BIT) #define VIA1_IRQ_ADB_READY (1 << VIA1_IRQ_ADB_READY_BIT) #define VIA1_IRQ_ADB_DATA (1 << VIA1_IRQ_ADB_DATA_BIT) #define VIA1_IRQ_ADB_CLOCK (1 << VIA1_IRQ_ADB_CLOCK_BIT) @@ -45,8 +45,8 @@ struct MOS6522Q800VIA1State { /* external timers */ QEMUTimer *one_second_timer; int64_t next_second; - QEMUTimer *VBL_timer; - int64_t next_VBL; + QEMUTimer *sixty_hz_timer; + int64_t next_sixty_hz; }; diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 4914cb809860..9617e04f02ef 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -297,18 +297,18 @@ enum { REG_EMPTY = 0xff, }; -static void via1_VBL_update(MOS6522Q800VIA1State *v1s) +static void via1_sixty_hz_update(MOS6522Q800VIA1State *v1s) { MOS6522State *s = MOS6522(v1s); /* 60 Hz irq */ - v1s->next_VBL = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630) / - 16630 * 16630; + v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630) / + 16630 * 16630; - if (s->ier & VIA1_IRQ_VBLANK) { - timer_mod(v1s->VBL_timer, v1s->next_VBL); + if (s->ier & VIA1_IRQ_60HZ) { + timer_mod(v1s->sixty_hz_timer, v1s->next_sixty_hz); } else { - timer_del(v1s->VBL_timer); + timer_del(v1s->sixty_hz_timer); } } @@ -325,16 +325,16 @@ static void via1_one_second_update(MOS6522Q800VIA1State *v1s) } } -static void via1_VBL(void *opaque) +static void via1_sixty_hz(void *opaque) { MOS6522Q800VIA1State *v1s = opaque; MOS6522State *s = MOS6522(v1s); MOS6522DeviceClass *mdc = MOS6522_GET_CLASS(s); - s->ifr |= VIA1_IRQ_VBLANK; + s->ifr |= VIA1_IRQ_60HZ; mdc->update_irq(s); - via1_VBL_update(v1s); + via1_sixty_hz_update(v1s); } static void via1_one_second(void *opaque) @@ -897,12 +897,12 @@ static uint64_t mos6522_q800_via1_read(void *opaque, hwaddr addr, unsigned size) /* * If IRQs are disabled, timers are disabled, but we need to update - * VIA1_IRQ_VBLANK and VIA1_IRQ_ONE_SECOND bits in the IFR + * VIA1_IRQ_60HZ and VIA1_IRQ_ONE_SECOND bits in the IFR */ - if (now >= s->next_VBL) { - ms->ifr |= VIA1_IRQ_VBLANK; - via1_VBL_update(s); + if (now >= s->next_sixty_hz) { + ms->ifr |= VIA1_IRQ_60HZ; + via1_sixty_hz_update(s); } if (now >= s->next_second) { ms->ifr |= VIA1_IRQ_ONE_SECOND; @@ -933,7 +933,7 @@ static void mos6522_q800_via1_write(void *opaque, hwaddr addr, uint64_t val, } via1_one_second_update(v1s); - via1_VBL_update(v1s); + via1_sixty_hz_update(v1s); } static const MemoryRegionOps mos6522_q800_via1_ops = { @@ -983,8 +983,8 @@ static void mac_via_reset(DeviceState *dev) adb_set_autopoll_enabled(adb_bus, true); - timer_del(v1s->VBL_timer); - v1s->next_VBL = 0; + timer_del(v1s->sixty_hz_timer); + v1s->next_sixty_hz = 0; timer_del(v1s->one_second_timer); v1s->next_second = 0; @@ -1026,8 +1026,9 @@ static void mac_via_realize(DeviceState *dev, Error **errp) m->mos6522_via1.one_second_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, via1_one_second, &m->mos6522_via1); - m->mos6522_via1.VBL_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, via1_VBL, - &m->mos6522_via1); + m->mos6522_via1.sixty_hz_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + via1_sixty_hz, + &m->mos6522_via1); qemu_get_timedate(&tm, 0); m->tick_offset = (uint32_t)mktimegm(&tm) + RTC_OFFSET; @@ -1116,8 +1117,8 @@ static const VMStateDescription vmstate_mac_via = { VMSTATE_BUFFER(mos6522_via1.PRAM, MacVIAState), VMSTATE_TIMER_PTR(mos6522_via1.one_second_timer, MacVIAState), VMSTATE_INT64(mos6522_via1.next_second, MacVIAState), - VMSTATE_TIMER_PTR(mos6522_via1.VBL_timer, MacVIAState), - VMSTATE_INT64(mos6522_via1.next_VBL, MacVIAState), + VMSTATE_TIMER_PTR(mos6522_via1.sixty_hz_timer, MacVIAState), + VMSTATE_INT64(mos6522_via1.next_sixty_hz, MacVIAState), VMSTATE_STRUCT(mos6522_via2.parent_obj, MacVIAState, 0, vmstate_mos6522, MOS6522State), /* RTC */ From patchwork Tue Mar 16 21:16:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RFN1Nhwz9sW1 for ; Wed, 17 Mar 2021 08:27:04 +1100 (AEDT) Received: from localhost ([::1]:42602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHDS-00038o-5i for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:27:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3W-0006ko-66 for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:46 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:54465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3U-0003yy-87 for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:45 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MrQMz-1m1NHy2Jxn-00oakO; Tue, 16 Mar 2021 22:16:41 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 6/7] mac_via: fix 60Hz VIA1 timer interval Date: Tue, 16 Mar 2021 22:16:30 +0100 Message-Id: <20210316211631.107417-7-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:HbgICZv4D4bZYNo8jh+W+S1quxJqTIpWeJOrIqOpy0cfr97a6iB 5nuWinov0fEo7uVWqSSe3Nwb1SfpORMzLqyIw9fVufK1uQGvHZr8b5292x8jRvtZxvmwPeh FLMdzu3Pj5TTymN1QWw6F2Rr71KtQ70JZCsgd6gSgqd0+7MgIlv5b4p0SUqrO7aSefleZTf FpcPQpqjPCjbFd+xGyHKA== X-UI-Out-Filterresults: notjunk:1;V03:K0:uEgqoFJwNXI=:OZewy82OK+oMF4izKo1Nqo 4jPEjdDMlp6SsgHZvf3h0Lw/eht/dsW7eCEGod+COR9caK1tPWyh11faHWjWt9xUe4FwYmyr7 STFmbLnJjLlCzkABvdUkJgMXQyfKqHBFUbvFAe3k1o0fUiNXJrAsh/UVYYBl712k+xJrg+hOd +xmxDHt+u62KSnlZTxxd6I5sw8mUHmjxo0s2IA7PlSz8ehSK4TdwMP2pCTvX+L40G9XTjZ3Za fDbQE7RFUaoPMZrVqmcVUU90+bmPulCDUYSZXL+9QV3Mif/IaS6f77bZtrlFHNRZq6gw1ql73 1bFj9yCUMjDSnr3mdCfnoygU8hxkuZL0GMtQfylAjeDJi2ba+AJlDZ/QVOImuJT56W19dIiOF 9x7wtmel/T9IrqeEvhG8AiK2BAOG3xfmIpY0rOkf5PBymAJTmfNi+0QXhHwnZmihKk7XYKvoB 3luoS/fkrg== Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The 60Hz timer is initialised using timer_new_ns() meaning that the timer interval should be measured in ns, and therefore its period is a thousand times too short. Use a define for the 60Hz timer period taking the more precise value as documented in the Guide To The Macintosh Family Hardware. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Reviewed-by: BALATON Zoltan Message-Id: <20210311100505.22596-7-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/mac_via.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 9617e04f02ef..36e70674feda 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -279,6 +279,12 @@ #define VIA_TIMER_FREQ (783360) #define VIA_ADB_POLL_FREQ 50 /* XXX: not real */ +/* + * Guide to the Macintosh Family Hardware ch. 12 "Displays" p. 401 gives the + * precise 60Hz interrupt frequency as ~60.15Hz with a period of 16625.8 us + */ +#define VIA_60HZ_TIMER_PERIOD_NS 16625800 + /* VIA returns time offset from Jan 1, 1904, not 1970 */ #define RTC_OFFSET 2082844800 @@ -302,8 +308,9 @@ static void via1_sixty_hz_update(MOS6522Q800VIA1State *v1s) MOS6522State *s = MOS6522(v1s); /* 60 Hz irq */ - v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630) / - 16630 * 16630; + v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + VIA_60HZ_TIMER_PERIOD_NS) / + VIA_60HZ_TIMER_PERIOD_NS * VIA_60HZ_TIMER_PERIOD_NS; if (s->ier & VIA1_IRQ_60HZ) { timer_mod(v1s->sixty_hz_timer, v1s->next_sixty_hz); From patchwork Tue Mar 16 21:16:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1454300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F0RPC2dTfz9sRR for ; Wed, 17 Mar 2021 08:33:51 +1100 (AEDT) Received: from localhost ([::1]:60584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHK1-0002IU-51 for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2021 17:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3V-0006kH-TK for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:45 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:49487) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMH3T-0003yr-Q4 for qemu-devel@nongnu.org; Tue, 16 Mar 2021 17:16:45 -0400 Received: from localhost.localdomain ([82.142.20.38]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MV6G0-1lFAK40HsE-00S62v; Tue, 16 Mar 2021 22:16:42 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 7/7] mac_via: remove VIA1 timer optimisations Date: Tue, 16 Mar 2021 22:16:31 +0100 Message-Id: <20210316211631.107417-8-laurent@vivier.eu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu> References: <20210316211631.107417-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:S/r5LIf4Ot8NttTzssD2oP9kzbyOVUfmDdAUTwwuRVip+tlCRtC k/NvEWQbSH6F+JYYzrVygN84H5ia+jWUQPUAMxSssnr8Tp3oOCwCsaOZkIDI+5QOl13N4xS Bh08cmm9+ZGmIXXsbE5yCrgcECRUQuFLi6+Bq/NoODktr7UZJdUvJqjj8r4kbSVK81rzpwU 4hgdqZrq75y3ETOQwy2lA== X-UI-Out-Filterresults: notjunk:1;V03:K0:M3Q7F/IxJd4=:eI+F055F3LAJq+vKS7Hgj/ UAwvPucwka2g7PCm+er1IKr0IV7VH+aoJmorUaSh5bS1Nh5np3b36m69kQ6wvPfGH6KWSpLjZ B+pQCDg8BknQiFh2WwMLT5U1CmWwzwAaNqY8WeEYudTqdWc/n0ljzdIv+wk215Fvl4HfC4OdU ck52XcvOf53uRzQS2cxkdhkKvGqjrg9dkPITRKVLCQH8KkkN7dTFOhx7pq63eQU2MEEfMj6m6 lsKhi8SkxklP2YXIW4j5z0OdR1n9OtHG4SrGQeZUEi3VmfFpzjJujoCYfKY6fuUqd1COnL1Nh CA1H0ZFn9/WfLCtZ0LwJsAfzW+oARAPiGyEpChYnmHG5YnIv4lEZ6MqzIVcxiwFPdSIqzO+zU vQoePzyDPwE4OfCF0cl/gmJ1dJcmjBlyut3ShpNxPINCs8Im8XZPNas9E3890dMxCoJvwqt7r hj/4I4klGw== Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The original implementation of the Macintosh VIA devices in commit 6dca62a000 "hw/m68k: add VIA support" used timer optimisations to reduce high CPU usage on the host when booting Linux. These optimisations worked by waiting until VIA1 port B was accessed before re-arming the timers. The MacOS toolbox ROM constantly writes to VIA1 port B which calls via1_one_second_update() and via1_sixty_hz_update() to calculate the new expiry time, causing the timers to constantly reset and never fire. The effect of this is that the Ticks (0x16a) global variable holding the number of 60Hz timer ticks since reset is never incremented by the interrupt causing time to stand still. Whilst the code was introduced as a performance optimisation, it is likely that the high CPU usage was actually caused by the incorrect 60Hz timer interval fixed in the previous patch. Remove the optimisation to keep everything simple and enable the MacOS toolbox ROM to start keeping time. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-Id: <20210311100505.22596-8-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/misc/mac_via.c | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 36e70674feda..ff0156db76f2 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -305,31 +305,18 @@ enum { static void via1_sixty_hz_update(MOS6522Q800VIA1State *v1s) { - MOS6522State *s = MOS6522(v1s); - /* 60 Hz irq */ v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + VIA_60HZ_TIMER_PERIOD_NS) / VIA_60HZ_TIMER_PERIOD_NS * VIA_60HZ_TIMER_PERIOD_NS; - - if (s->ier & VIA1_IRQ_60HZ) { - timer_mod(v1s->sixty_hz_timer, v1s->next_sixty_hz); - } else { - timer_del(v1s->sixty_hz_timer); - } + timer_mod(v1s->sixty_hz_timer, v1s->next_sixty_hz); } static void via1_one_second_update(MOS6522Q800VIA1State *v1s) { - MOS6522State *s = MOS6522(v1s); - v1s->next_second = (qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 1000) / 1000 * 1000; - if (s->ier & VIA1_IRQ_ONE_SECOND) { - timer_mod(v1s->one_second_timer, v1s->next_second); - } else { - timer_del(v1s->one_second_timer); - } + timer_mod(v1s->one_second_timer, v1s->next_second); } static void via1_sixty_hz(void *opaque) @@ -900,21 +887,6 @@ static uint64_t mos6522_q800_via1_read(void *opaque, hwaddr addr, unsigned size) { MOS6522Q800VIA1State *s = MOS6522_Q800_VIA1(opaque); MOS6522State *ms = MOS6522(s); - int64_t now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); - - /* - * If IRQs are disabled, timers are disabled, but we need to update - * VIA1_IRQ_60HZ and VIA1_IRQ_ONE_SECOND bits in the IFR - */ - - if (now >= s->next_sixty_hz) { - ms->ifr |= VIA1_IRQ_60HZ; - via1_sixty_hz_update(s); - } - if (now >= s->next_second) { - ms->ifr |= VIA1_IRQ_ONE_SECOND; - via1_one_second_update(s); - } addr = (addr >> 9) & 0xf; return mos6522_read(ms, addr, size); @@ -938,9 +910,6 @@ static void mos6522_q800_via1_write(void *opaque, hwaddr addr, uint64_t val, v1s->last_b = ms->b; break; } - - via1_one_second_update(v1s); - via1_sixty_hz_update(v1s); } static const MemoryRegionOps mos6522_q800_via1_ops = { @@ -985,16 +954,10 @@ static const MemoryRegionOps mos6522_q800_via2_ops = { static void mac_via_reset(DeviceState *dev) { MacVIAState *m = MAC_VIA(dev); - MOS6522Q800VIA1State *v1s = &m->mos6522_via1; ADBBusState *adb_bus = &m->adb_bus; adb_set_autopoll_enabled(adb_bus, true); - timer_del(v1s->sixty_hz_timer); - v1s->next_sixty_hz = 0; - timer_del(v1s->one_second_timer); - v1s->next_second = 0; - m->cmd = REG_EMPTY; m->alt = REG_EMPTY; } @@ -1033,9 +996,11 @@ static void mac_via_realize(DeviceState *dev, Error **errp) m->mos6522_via1.one_second_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, via1_one_second, &m->mos6522_via1); + via1_one_second_update(&m->mos6522_via1); m->mos6522_via1.sixty_hz_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, via1_sixty_hz, &m->mos6522_via1); + via1_sixty_hz_update(&m->mos6522_via1); qemu_get_timedate(&tm, 0); m->tick_offset = (uint32_t)mktimegm(&tm) + RTC_OFFSET;