From patchwork Fri Dec 27 12:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921783 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 81129E7718F for ; Fri, 27 Dec 2024 12:15:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9ER-0002xc-V3; Fri, 27 Dec 2024 07:14:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v5-Ak for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9Dz-0005FW-P3 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:54 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aa689a37dd4so1047792566b.3 for ; Fri, 27 Dec 2024 04:13:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301625; x=1735906425; darn=nongnu.org; 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=2O+DIEBGhBsth5s6qrd3slMPO7yKFnh06DUjpLZtVho=; b=xzgYhYYkD0yWvLS9xiziyheuQ4Wpw3CiZMunGvBNapb0y/zNJxceUGHri2+CVC54dJ ck5ESvna+qK1GjlNB3SvF5gqrWQcPa4uSAtnz06xtySv1oyF7u4uFaP6vSUdVxrw/Ghx ibjpGHah6wPpgtAiSTnZy976Yr68bwVQ1W1zGHrPHrc7DEiA8j/2UwqPYIEkOu9NCjmy 9mM4Pg5aksBPJsyWdQjoLRbNHJLlwjBqmqJd3WgGmlGWqTykCxDofN8VRa+j+3FKjtCb eCg3fDdimZCFpevumHA68AwHIGn675dlXBjDyHeU7AhlsnkVOOuuy1WxpEGqyFB3oDtT iUFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301625; x=1735906425; 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=2O+DIEBGhBsth5s6qrd3slMPO7yKFnh06DUjpLZtVho=; b=e0x2OValmwt8YOx3Iik4WtQxQVzad6I0rWq/vF6UZo91nwWudFzz9c1+BFqkPq3Oz8 wiRThGfK4It5hRiAiBZ2HnzhCHDfDDLdtSyY4OJaQERoUiFYQdsrW01YMr+ClGSbnrMK DIbKuAMKZdA7SClcuXoGNL6CvVp05+5Ge22N1l7b6FqSwsH0lVIm33wOSX8XhIZmyVcE STBFWOKRKQQRNTGwwCWzoFOebmw5fuRZIlDwADvlazYvXa0N0JsMAR6iABqdMS35AL4C N/bGRoEzecM57rwydafiUUAFjZF2MaQww+3RuVfg1jFwgyv4K3ATFpHChD5B/45sVuMC f3EA== X-Gm-Message-State: AOJu0YwDmy7fHxAkuauUVXDZEUkLHn/AXYPHHxVsNrkmFQmPnEoiEW42 GilEriUEh0RefuA0n7EChxcPv3hLSh3kDd0CCotOJbkr3Y1eyVZ5fgmz8u6I8gLHRveSKRoxa9Q = X-Gm-Gg: ASbGncvhz5ogr752hsZN3sr0lEroP7na4MXB7K3u/3DeS1JdDH4FVlcVmyrvI7mtG/K hDuJb9nyM0/Nre0kohfZtcTabWcb2XV22vIPBKYjDceA+RXwnkPTOrd0jkBjMi9A55jYeId7vJy Jo024fVlTF/YtbD3CkfTa+kV9LQSnaTu7JJ19IreuNWU9mU0RNeM/cZ2pSkE1StJLOo4hsIEVR+ F8is61T++on/lQjIpUzDSrlwDqnoBf/ZKSGsU53KUpdQZYyvo9fqogGDZPIu3PMzcmR/aYfmeY5 HHcQwLYuLR2taOE2/DaZ7c5foO6XjZCR X-Google-Smtp-Source: AGHT+IFhbg2kfNp9SugiGcMQk7FtZYZSin/YtDp1HS7iR9dP5h+WIPD7LKCmOEHFiO1xpZkkX9hjpw== X-Received: by 2002:a17:907:86aa:b0:aa6:5eae:7ece with SMTP id a640c23a62f3a-aac33549659mr2712724566b.43.1735301625196; Fri, 27 Dec 2024 04:13:45 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:44 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 1/6] hw/usb/hcd-xhci-pci: Use modulo to select MSI vector as per spec Date: Fri, 27 Dec 2024 13:13:31 +0100 Message-Id: <20241227121336.25838-2-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::62a; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org QEMU would crash with a failed assertion if the XHCI controller attempted to raise the interrupt on a higher vector than the highest configured for the device by the guest driver. It turns out the XHCI spec (Implementation Note in section 4.17, "Interrupters") requires that the host controller signal the MSI vector with the number computed by taking the interrupter number modulo the number of enabled MSI vectors. This change introduces that modulo calculation, fixing the failed assertion and making the device work correctly in MSI mode with macOS's XHCI driver. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Philippe Mathieu-Daudé --- v2: * Switch to modulo arithmetic for MSI vector number rather than dropping, as per spec. hw/usb/hcd-xhci-pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index e110840c7a..e5e7330387 100644 --- a/hw/usb/hcd-xhci-pci.c +++ b/hw/usb/hcd-xhci-pci.c @@ -74,6 +74,7 @@ static bool xhci_pci_intr_raise(XHCIState *xhci, int n, bool level) } if (msi_enabled(pci_dev) && level) { + n %= msi_nr_vectors_allocated(pci_dev); msi_notify(pci_dev, n); return true; } From patchwork Fri Dec 27 12:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921788 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7962EE77191 for ; Fri, 27 Dec 2024 12:16:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9EZ-000309-Iv; Fri, 27 Dec 2024 07:14:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v7-BJ for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9Dz-0005Fc-P5 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:55 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aaee0b309adso576605966b.3 for ; Fri, 27 Dec 2024 04:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301626; x=1735906426; darn=nongnu.org; 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=4U+f2LVOSjCieG+oVfsElVkg5nzALNjfOKDCd96XFZY=; b=mIfBtrTkp+px4qWvXFmYlqdfsmTKf2ffLPC7reX8iiJa5f1E5QpkPCFWp4iO+o1Li5 z02MQHYoae8Ossu82o2t7L13UrEqowTdTzQIuM1g4GeTtQpbESL1Nhn9/iBakwUqlvUP pjEl7zDYHpMDOXmqZnwAVNI0yjWCRPqcMqhwdkWGwDxMn4AA1cD99d9clnGMhpdJ4keA ya8BbImI5NRzIv7qkKqNqDkVyWi0YACIscvpqokzBzjUgtRZvnMjhSqBHcXQGsYfMBEj sKWz1HZa1UF/xMFdS+FtuqNk111R9BhwrLaVaPyF/l1BiBl3whhmHbhA6PxQGTVfsj9L z/8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301626; x=1735906426; 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=4U+f2LVOSjCieG+oVfsElVkg5nzALNjfOKDCd96XFZY=; b=fpwEaw2OZZ+C0b8p/J5w2CubjORrOkoqo8QmYA5MmryHx6iQ+19PygQdvIYLPv51Ks Y1DlER/g1VAVtUwQ/YqBgnrZ+xDMcE6sZOaYOVLgHcKMYC2U+wo6TUYXKNjbogejHVoz IXPWj91OndEGZUippaNdup02WahRND1flcAeI9oYCGPbsp4K4b8+ga+c7H4Pj2EtP3Mq gVDpnvNG1wurlu1zr9x4UZhv3IiF/J9pTYSrlBsWwfE8WYhJiOuFlV6tbRgaq/vGIT/z 6q83Ti6Zb4PPda7KmZAxLQl2nLIptLawI3m+U30uUY7DUf9WVooLuUpKirxuoiENiBSf 6DOw== X-Gm-Message-State: AOJu0YxAtEh0UCuO1oWAps2OEgfMYtgGWs+JnV6Rov0S7UqoS1N0/fqt w5LXaOWyXBPu/Qq9T3JBzOq7EoKwwgjLCzzahGh1OolqL6ZDY8M2IrARUIxMvFeUX5tYgoltsbQ = X-Gm-Gg: ASbGncuJczPQSqn/HlvVVzhVLtdLnH8SDItkJKZeRGM2INd9TlZ8jNgSWxMKbu5jMrQ b+hMVfa3FBZwDVThXYu6yiMOPhcrgYK9dkVpRjkjDoCBu+YNrcXvDjDOZ19FvgIt9RgYZmPvWcJ xCCj5ZW68Vb4EhPiM3wJFi9C8k9AZGCj1zRj9Su9a3pETP42OZ+zinQ85uteuDmMknjicsY1Vgv 6GlDyE47h5xLCgmCSYMcvWJAd5TFCRgA5Ao5Ewgy/1e2JQpnTybrBTgzlnffn60qkmH2/C4ecEb 9XrD4eQWB46vDMRi2qI7s8I2UxXOTacJ X-Google-Smtp-Source: AGHT+IGTBZTE94nTPwaxzTFbk0znrl3hKxdMssXGV4zjHHxa58vn4O1BDbPoKSJibJo9I2tY1KOr1w== X-Received: by 2002:a17:907:360e:b0:aa6:8d51:8fdc with SMTP id a640c23a62f3a-aac348c4e1bmr2700299566b.58.1735301626121; Fri, 27 Dec 2024 04:13:46 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:45 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 2/6] hw/usb/hcd-xhci-pci: Move msi/msix properties from NEC to superclass Date: Fri, 27 Dec 2024 13:13:32 +0100 Message-Id: <20241227121336.25838-3-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::62a; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The NEC XHCI controller exposes the underlying PCI device's msi and msix properties, but the superclass and thus the qemu-xhci device do not. There does not seem to be any obvious reason for this limitation. This change moves these properties to the superclass so they are exposed by both PCI XHCI device variants. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Philippe Mathieu-Daudé --- v3: * In line with recent upstream changes, the property table is now const and no longer carries an end-of-list marker. hw/usb/hcd-xhci-nec.c | 2 -- hw/usb/hcd-xhci-pci.c | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci-nec.c b/hw/usb/hcd-xhci-nec.c index b1df95b52a..1df518baf5 100644 --- a/hw/usb/hcd-xhci-nec.c +++ b/hw/usb/hcd-xhci-nec.c @@ -37,8 +37,6 @@ struct XHCINecState { }; static const Property nec_xhci_properties[] = { - DEFINE_PROP_ON_OFF_AUTO("msi", XHCIPciState, msi, ON_OFF_AUTO_AUTO), - DEFINE_PROP_ON_OFF_AUTO("msix", XHCIPciState, msix, ON_OFF_AUTO_AUTO), DEFINE_PROP_UINT32("intrs", XHCINecState, intrs, XHCI_MAXINTRS), DEFINE_PROP_UINT32("slots", XHCINecState, slots, XHCI_MAXSLOTS), }; diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index e5e7330387..49642aab58 100644 --- a/hw/usb/hcd-xhci-pci.c +++ b/hw/usb/hcd-xhci-pci.c @@ -198,6 +198,11 @@ static void xhci_instance_init(Object *obj) qdev_alias_all_properties(DEVICE(&s->xhci), obj); } +static const Property xhci_pci_properties[] = { + DEFINE_PROP_ON_OFF_AUTO("msi", XHCIPciState, msi, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("msix", XHCIPciState, msix, ON_OFF_AUTO_AUTO), +}; + static void xhci_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); @@ -209,6 +214,7 @@ static void xhci_class_init(ObjectClass *klass, void *data) k->realize = usb_xhci_pci_realize; k->exit = usb_xhci_pci_exit; k->class_id = PCI_CLASS_SERIAL_USB; + device_class_set_props(dc, xhci_pci_properties); } static const TypeInfo xhci_pci_info = { From patchwork Fri Dec 27 12:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921786 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B458DE7718F for ; Fri, 27 Dec 2024 12:15:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9EP-0002wt-PN; Fri, 27 Dec 2024 07:14:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v4-As for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9Dz-0005Fi-P4 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:55 -0500 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so12823979a12.2 for ; Fri, 27 Dec 2024 04:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301627; x=1735906427; darn=nongnu.org; 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=DvyTgK6t3B/LAOc7k9FPUxri4XHAiPyQyzliFGxQfm4=; b=04RyiATREN7rSFdXDxLc9Ova0iUNMV5MM8+8mhH7MF+3+YQ8/1AmD7Ivzwf121hSiz yJ9Lq8qxDT9vc1rCEHnI0ZjpBFWZvveiWZ0q6PBlbeDeTfFEVKWMC0EAt8rmB59DZgQA wp4f/vKAXPWcBzXun2oe5jxvvvqzB/QOM1/gFpc9DttzJKUyVn6G033U4QTwSkd1QlC7 MNaYkxt8pgPosYzB/gQD7okySyJ8BcyZ9tQqZ0Ys91d9EN2yiCgCQ/j+pAOro3G0OgmK wJR9+Qm8VDwmxoM7ZpCs0Td1BEZwnSDPxBYKfDiubs14H1Gp+5pyU+6b+f+u3IzEyrUM E3Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301627; x=1735906427; 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=DvyTgK6t3B/LAOc7k9FPUxri4XHAiPyQyzliFGxQfm4=; b=UmeAFhjU+/AuGNKhiBPPOA9K/DiiupMy2rvPF3Ri2EqUHz6I7kYtS0b828pVSGV3Xg 85JSlFh4KEFtXCR8k+5u5YpqPDFpfuihcRLW734DLCEe8xmNSyBC3yHrwxh81t3EC/Rx ZTncL7zrsiEDDKfXYaIEype7hddARrWV0LdO0vo3YcFCuefvKGIBZx5fuGLvPI0eEIbu enqW2TTe6r2oH5baBcTS9+7FN5uoCV9zEfxHmAI6ZtQC/x65e8GuYNhqhWLyk1UobcEb VJQ6YT20iNXrV+otCyQ0jf3jOrZuj4q1DNCW6CjihSrhOqOWmmEkU13rQpSUx60eRPS1 1Dtw== X-Gm-Message-State: AOJu0Yy+CnrK0FTRpORMfAG5Vf62MEztpVNEaUwBhnR5H+VTjYv6S6Jq i2GNe4fgEHh2/jx/jriSYni0gEHjjruacaGsmhnPTB8uAKAVLnuNZUwT2DrXNRPrYV4wVT8vtf8 = X-Gm-Gg: ASbGncuZOqlKkK706nWAk2EO96hnthIlTp4Vc2lCA/0htupQ60acCfA6AiQV+rs+Txr x0+PzA1yNLBmNjbSwMoUMDju3YPzKHmwyuB2PROxaBXTvpycnP8tDrbrGVC/b5QD4OkV0ZBIzYP g8z9SrsrTdx8147FuiObQApsdW/RNZ/yu3vAqCGX69YlGB9GtLICjFtjjCioQb5xTUSHignwe36 rND1AUSZyNYIb9zTt77e2jAC6PlNsGCmw/CpWWByQDdLowLZWQoyDej+o4BND+LzBc191BUUFkp Mx7o2xVNy7LNNSIdLIp7FN13T5QpbbHR X-Google-Smtp-Source: AGHT+IECabCWXX5coRCLilR7ADB0xMkJJxQRD3mKaU6vQp/E1ZL62ADfF5ytdkPMoyvmQZvTLRZdzA== X-Received: by 2002:a05:6402:5255:b0:5d3:cfd0:8d4b with SMTP id 4fb4d7f45d1cf-5d81de38c45mr23117436a12.33.1735301627022; Fri, 27 Dec 2024 04:13:47 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:46 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 3/6] hw/usb/hcd-xhci-pci: Use event ring 0 if mapping unsupported Date: Fri, 27 Dec 2024 13:13:33 +0100 Message-Id: <20241227121336.25838-4-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::52f; envelope-from=phil@philjordan.eu; helo=mail-ed1-x52f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The XHCI specification, section 4.17.1 specifies that "If the Number of Interrupters (MaxIntrs) field is greater than 1, then Interrupter Mapping shall be supported." and "If Interrupter Mapping is not supported, the Interrupter Target field shall be ignored by the xHC and all Events targeted at Interrupter 0." QEMU's XHCI device has so far not specially addressed this case, so we add a check to xhci_event() to redirect to event ring and interrupt 0 if mapping is disabled. Signed-off-by: Phil Dennis-Jordan --- hw/usb/hcd-xhci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 3719c0f190..011c445443 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -644,6 +644,10 @@ static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v) dma_addr_t erdp; unsigned int dp_idx; + if (xhci->numintrs == 1) { + v = 0; + } + if (v >= xhci->numintrs) { DPRINTF("intr nr out of range (%d >= %d)\n", v, xhci->numintrs); return; From patchwork Fri Dec 27 12:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921784 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 85884E77191 for ; Fri, 27 Dec 2024 12:15:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9Eb-00030w-Em; Fri, 27 Dec 2024 07:14:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v2-AT for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9Dz-0005Fu-P6 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:55 -0500 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-aaec61d0f65so941578366b.1 for ; Fri, 27 Dec 2024 04:13:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301628; x=1735906428; darn=nongnu.org; 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=/cZzMlorZxepNwBN9OE1rEkxv6kXqEyMS3VAO9/DPjk=; b=YCO8JANzQYkZ1f0Sf05+iATSdesLm4kUkdc7wIf3Tkd2FNfvU30Mewrk29WDbFFDT8 DhGn8rl1+sOhBGrYhRg8ljQsiMWjZNBPjU1ryNKdksoKXqdnbpUDK0JzwPVOkUu0jns1 x3o7kPHU1UHXQiv6H+HYij+HmAzuQIERCMN/IewVVvHo+MXKswQOBNOTza06DvuAYOsv 8H0/jnSrmVcyWYxhINJLSCUvaTsc9S9A/S3P3Dfu21vybe7pqGuiZvzShtnTsV2mF8Uu pUqPRkweNOORdavC/7AZF6Vdm6EDmhPLYH4ZpFG9Nr0b9cFkw3NPbwm50xpq5BLSyLqr ZD0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301628; x=1735906428; 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=/cZzMlorZxepNwBN9OE1rEkxv6kXqEyMS3VAO9/DPjk=; b=hI/hkWf+BVOTZv4b6g7li6WTWv2VjeRSDPZ5apIPVDPcAF1AYkTdI0UopsRt5B3sm4 yr9qLfCePu/Nc7UtaSxhAmQ601qpPf1bJZxDSbokyibkScvO+TYBMtsWHy7eiIqV4wX8 Q8GBMRIbR63Ewkcd/w/L9CoLWfwlJCNnSf0AAGTGLjUKqVsYskEZUCazszKES8L+000f ZpGUB5pgc6+jPFsOk1PMZ0yOlxxx2zVGFZiCI7w4kEddrLtDAnVej3lLgh2Q6hLDHG1C GbARBSzn6jZNIPDLdjdFVTltrOfok+9MaVFqfms292P9u1nMhh7eCUZgVFf+XqqiVcpA 7K1g== X-Gm-Message-State: AOJu0Yw+s9NnMUe1WrOHOb5rKQkZFJV5c9heT7g3Kn91/o/tn6RynSc5 sOUMfz6JB8XLd/a876sanRPoBkqNK9JfbZR3b3chIC7DDjcFbEdINiK5MzrrZ8SfbjQU8+9fSHI = X-Gm-Gg: ASbGncsInHuitNbBr7N65Zq8KZZRDF5kimtyCDgoQhSnLGGA/FFCamJxQ7DzGfwA/9Y +y58xSmetH3bjZkr5p2BNkMV0RafMtPhE0pNUMmIB3QNZ3ValgbVEKqBPU9liRP887ldMdaUV76 bQ262+yQwFbeIQqhrmVvGv+n1SlUB34tVecYKswRDv73BZ8HEz4oiv4NW8EfMEsoIAIBLReDUVc YArHCYExotMdLzG4uDv2VrOOWih4POYo+QNcYqnbktX8x5QbmKQHiBn3BYPnagn4XoZZZiWHuVK ypDmsFeWgtblWWNWHdBcgkLNLcXdGcjo X-Google-Smtp-Source: AGHT+IE5dK31E6/U/uH+HBvl95wXI8KbV1zJZaXpDRO9NAL4sjOO3k6TsmtHXfAhvELhIewyO20jRg== X-Received: by 2002:a17:906:7311:b0:aac:278:98fd with SMTP id a640c23a62f3a-aac2ad80073mr2447233466b.17.1735301627989; Fri, 27 Dec 2024 04:13:47 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:47 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 4/6] hw/usb/hcd-xhci: Unimplemented/guest error logging for port MMIO Date: Fri, 27 Dec 2024 13:13:34 +0100 Message-Id: <20241227121336.25838-5-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::62c; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The XHCI device code uses tracing rather than logging on various code paths that are so far unimplemented. In some cases, these code paths actually indicate faulty guest software. This patch switches instances in the read and write handlers for the port MMIO region to use qemu_log_mask() with LOG_UNIMP or LOG_GUEST_ERROR, as appropriate in each case. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Philippe Mathieu-Daudé --- hw/usb/hcd-xhci.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 011c445443..00d5bc3779 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2814,9 +2814,15 @@ static uint64_t xhci_port_read(void *ptr, hwaddr reg, unsigned size) case 0x08: /* PORTLI */ ret = 0; break; - case 0x0c: /* reserved */ + case 0x0c: /* PORTHLPMC */ + ret = 0; + qemu_log_mask(LOG_UNIMP, "%s: read from port register PORTHLPMC", + __func__); + break; default: - trace_usb_xhci_unimplemented("port read", reg); + qemu_log_mask(LOG_GUEST_ERROR, + "%s: read from port offset 0x%" HWADDR_PRIx, + __func__, reg); ret = 0; } @@ -2885,9 +2891,22 @@ static void xhci_port_write(void *ptr, hwaddr reg, } break; case 0x04: /* PORTPMSC */ + case 0x0c: /* PORTHLPMC */ + qemu_log_mask(LOG_UNIMP, + "%s: write 0x%" PRIx64 + " (%u bytes) to port register at offset 0x%" HWADDR_PRIx, + __func__, val, size, reg); + break; case 0x08: /* PORTLI */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: Write to read-only PORTLI register", + __func__); + break; default: - trace_usb_xhci_unimplemented("port write", reg); + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write 0x%" PRIx64 " (%u bytes) to unknown port " + "register at offset 0x%" HWADDR_PRIx, + __func__, val, size, reg); + break; } } From patchwork Fri Dec 27 12:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921785 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8BABCE7718B for ; Fri, 27 Dec 2024 12:15:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9EQ-0002xJ-Mt; Fri, 27 Dec 2024 07:14:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v8-C1 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9E0-0005G1-10 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:55 -0500 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5d3e9f60bf4so12034050a12.3 for ; Fri, 27 Dec 2024 04:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301629; x=1735906429; darn=nongnu.org; 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=c4OQlrQ2lOwO235fKNtUs/AAw1axl2Gl19Nw0aS3zkY=; b=N+pbC0ywMd7ZmGCjI82UVmoIXOiwB0EYtQ/PpQsbwdU9ayhLNUs0iZLcsmdoD4sSfC fjorJ3QN/9DXoKYsIeyzwSka31zDDl4SNPH6B6zwsAUVDjy9l9szLu/AiLaBPuKD2gHs dPWZs4QNxT5ji1ikFspENQoM8JSEVRhnk82JPMiNfGBXOZ0KFvIYFAf0QzY15Q4M3Sek GE+dt67XSCLwgxufGZiEciYHwYAlaV9etqlORpIzzM9eou1dnktUWrTfnTsoVZBwDgIg MSg4WZ97N+DIZeW4i10zUcaih1LGvdzFKidRkkAg1COdWSCigAZUcC3LG4ssw+NpXFfA OTuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301629; x=1735906429; 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=c4OQlrQ2lOwO235fKNtUs/AAw1axl2Gl19Nw0aS3zkY=; b=ScvGMiKERLD4hyM3AjMA4SL3Ef7/I9J/NalaYfIxjF0D0umWmw0eqgqBR+QO8QN0Qw ox0M7bWVsBo/W/DICJK59DLN/VySw1QaVMuMEJA0jZK8+CPQZnlznIpO5xyOTpYaBPl+ ATOxHWbA/egDdOh63fMGSxtSEz+rtFRaE1tfoYgpjCbZUGFcIglrks+HxTgcSldT4YYy CgAHyYComabU8z8nam1jkCr3FyTMxGa5H0yHDjQj+iZcdWX4UrRxZouTgW1FmIwa0iK9 tyVrmSR4kvc8rnzzw8906hHfEhz3Cv0gGU7QnREJdv+LZZQxQYGqFL0PVSY3RLWVJiI1 Bxkg== X-Gm-Message-State: AOJu0YwX6uX4SLT+iYIrwt/HCeakVrseE97JXLFOY+Da7KC6Rf9TCl47 lVL1fEiJWgIsnB6Eu0uUxVSF9XLiuVRxGz7OxpTmRqFzzaNf+59WupiDBmdQnF6VVgYPmpZ5NAY = X-Gm-Gg: ASbGncvLb4hvJBc1LAA/uuPuvyDca3+ST0YLuP4YJuRHAnuJy4enEAXcoI6RDzZ0mO/ ZDDYKUWGcAG9KCdwNDhS+7SG48/BSWM1XUb45qCwm1MyetrxZuCvoAwmS0W3PNQjXi290YGJL8a 4K5G+t0PKzwfLtZlRmxQXJUnz1ca0tF6OL9VWseIuF7OuX5d0+ui7+DKRPOn+6huHWVN7Rx74zD AdiGL97HQI4lNpexpRx376GkokHCNQkqBX5juQs5LgDMlPtIIqYY98BlTrYLSNQZeQfSI4fWcWa dR1pXAAj+bMO7juKiF+IeM7ftc0rvaBU X-Google-Smtp-Source: AGHT+IG8vK63p3UizcF3rZMBzZCr9ewDDisOQ06UmI3/tJQcU9LohfY9a5821d4rRr6YKB31l45ZTA== X-Received: by 2002:a17:907:1c8c:b0:aa6:3da3:db48 with SMTP id a640c23a62f3a-aac345f5b3amr2299849766b.53.1735301628933; Fri, 27 Dec 2024 04:13:48 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:48 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 5/6] hw/usb/hcd-xhci-pci: Adds property for disabling mapping in IRQ mode Date: Fri, 27 Dec 2024 13:13:35 +0100 Message-Id: <20241227121336.25838-6-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::530; envelope-from=phil@philjordan.eu; helo=mail-ed1-x530.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This change addresses an edge case that trips up macOS guest drivers for PCI based XHCI controllers. The guest driver would attempt to schedule events to XHCI event rings 1 and 2 even when using PCI pin-based interrupts. Interrupts would therefore be dropped, and events only handled on timeout. So, in addition to disabling interrupter mapping if numintrs is 1, a callback is added to xhci to check whether interrupter mapping should be enabled. The PCI XHCI device type now provides an implementation of this callback if the new "conditional-intr-mapping" property is enabled. (default: disabled) When enabled, interrupter mapping is only enabled when MSI-X or MSI is active. This means that when using pin-based interrupts, events are only submitted to interrupter 0 regardless of selected target. This allows the macOS guest drivers to work with the device in those configurations. Signed-off-by: Phil Dennis-Jordan Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2705 --- hw/usb/hcd-xhci-pci.c | 24 ++++++++++++++++++++++++ hw/usb/hcd-xhci-pci.h | 1 + hw/usb/hcd-xhci.c | 3 ++- hw/usb/hcd-xhci.h | 5 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index 49642aab58..d908eb787d 100644 --- a/hw/usb/hcd-xhci-pci.c +++ b/hw/usb/hcd-xhci-pci.c @@ -82,6 +82,21 @@ static bool xhci_pci_intr_raise(XHCIState *xhci, int n, bool level) return false; } +static bool xhci_pci_intr_mapping_conditional(XHCIState *xhci) +{ + XHCIPciState *s = container_of(xhci, XHCIPciState, xhci); + PCIDevice *pci_dev = PCI_DEVICE(s); + + /* + * Implementation of the "conditional-intr-mapping" property, which only + * enables interrupter mapping if MSI or MSI-X is available and active. + * Forces all events onto interrupter/event ring 0 in pin-based IRQ mode. + * Provides compatibility with macOS guests on machine types where MSI(-X) + * is not available. + */ + return msix_enabled(pci_dev) || msi_enabled(pci_dev); +} + static void xhci_pci_reset(DeviceState *dev) { XHCIPciState *s = XHCI_PCI(dev); @@ -119,6 +134,9 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp) object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL); s->xhci.intr_update = xhci_pci_intr_update; s->xhci.intr_raise = xhci_pci_intr_raise; + if (s->conditional_intr_mapping) { + s->xhci.intr_mapping_supported = xhci_pci_intr_mapping_conditional; + } if (!qdev_realize(DEVICE(&s->xhci), NULL, errp)) { return; } @@ -201,6 +219,8 @@ static void xhci_instance_init(Object *obj) static const Property xhci_pci_properties[] = { DEFINE_PROP_ON_OFF_AUTO("msi", XHCIPciState, msi, ON_OFF_AUTO_AUTO), DEFINE_PROP_ON_OFF_AUTO("msix", XHCIPciState, msix, ON_OFF_AUTO_AUTO), + DEFINE_PROP_BOOL("conditional-intr-mapping", XHCIPciState, + conditional_intr_mapping, false), }; static void xhci_class_init(ObjectClass *klass, void *data) @@ -215,6 +235,10 @@ static void xhci_class_init(ObjectClass *klass, void *data) k->exit = usb_xhci_pci_exit; k->class_id = PCI_CLASS_SERIAL_USB; device_class_set_props(dc, xhci_pci_properties); + object_class_property_set_description(klass, "conditional-intr-mapping", + "When true, disables interrupter mapping for pin-based IRQ mode. " + "Intended to be used with guest drivers with questionable behaviour, " + "such as macOS's."); } static const TypeInfo xhci_pci_info = { diff --git a/hw/usb/hcd-xhci-pci.h b/hw/usb/hcd-xhci-pci.h index 08f70ce97c..5b61ae8455 100644 --- a/hw/usb/hcd-xhci-pci.h +++ b/hw/usb/hcd-xhci-pci.h @@ -40,6 +40,7 @@ typedef struct XHCIPciState { XHCIState xhci; OnOffAuto msi; OnOffAuto msix; + bool conditional_intr_mapping; } XHCIPciState; #endif diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 00d5bc3779..64c3a23b9b 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -644,7 +644,8 @@ static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v) dma_addr_t erdp; unsigned int dp_idx; - if (xhci->numintrs == 1) { + if (xhci->numintrs == 1 || + (xhci->intr_mapping_supported && !xhci->intr_mapping_supported(xhci))) { v = 0; } diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h index 9609b83514..9c3974f148 100644 --- a/hw/usb/hcd-xhci.h +++ b/hw/usb/hcd-xhci.h @@ -193,6 +193,11 @@ typedef struct XHCIState { uint32_t max_pstreams_mask; void (*intr_update)(XHCIState *s, int n, bool enable); bool (*intr_raise)(XHCIState *s, int n, bool level); + /* + * Callback for special-casing interrupter mapping support. NULL for most + * implementations, for defaulting to enabled mapping unless numintrs == 1. + */ + bool (*intr_mapping_supported)(XHCIState *s); DeviceState *hostOpaque; /* Operational Registers */ From patchwork Fri Dec 27 12:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13921789 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CEC23E7718B for ; Fri, 27 Dec 2024 12:16:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9Ed-000310-Cs; Fri, 27 Dec 2024 07:14:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9E9-0002v6-Am for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:14:04 -0500 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9E0-0005G8-NP for qemu-devel@nongnu.org; Fri, 27 Dec 2024 07:13:56 -0500 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-aaef00ab172so454429566b.3 for ; Fri, 27 Dec 2024 04:13:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1735301630; x=1735906430; darn=nongnu.org; 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=FcOE8SJ4qU0KcKLjO08qeQlS1Zz6VSXpgWSSMCpxy6c=; b=KDaiK2HYuSeQsv5tuXLWt1LfX+RVar9/WSMV+NiKT5DDIWmRt2Ea2YBEOBtBEAzTNs 6Svwb+nr1XRr2WIzSTiA1Iz+vnHBCOU45450w0WUIEOLDTU52e/c6Pyslo9qTEavnNR8 NeFWIMQ4BTTj805vJQjTVJoogwjDEvAL+LAkpL3Oo8cJw9YwElQce4J5Xiw3X2tSgUbL fH5ugDbVr5cRKSFzGqRl7nFUb+hXUzIIs8kjXNSONLs69e1foqiFuRboWo7dH3O90S94 ZSmzqSjDe5BUNW6bHC0mq7Pk2UkHLL0PWJ9eflR1qPDdPyqwQQB/OWmwD4SDoGHpC3oP KcUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301630; x=1735906430; 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=FcOE8SJ4qU0KcKLjO08qeQlS1Zz6VSXpgWSSMCpxy6c=; b=GAfFGX37oHYc+VC45ssftooX9WroyHTDlSB2uJnXv+X0MukVJGmVI7HkNZValEbbW3 qrhCEi0GYP6jBKhhS4E26aRgDG7wEBOab/C734EWSbOXjM3vlCtwQgFXlqDYHi8HOFfT 2MOfxWjKKrtBgDuX9RJJzWBkEZkePPpb1aJuwpocPwOjts8++S5AOwRfiqMXUHn7/0tc wxIDqh/0Y3kMTvJ9/B+R71xGa4aXxEqwS+jSZPvtt0W1nIkM1DZUiFLfPsdW4EGzY8pu 0rVrwepjxAoBR8l1PxKoEvP38hS8O3mmwVUuPJGLc7ta2hFQ/uQMZN9k7SXy9NzwZbP+ tiqQ== X-Gm-Message-State: AOJu0YzGDPE55IDgcuDgriVoXNjOm6TYxFY/ALyHcIu8xP96Ec1A1Jlz 00patukoFQv19W8PIG+o3uTMRVV3BozpCPjcUcuuX3xaSm5p+BC1gtSf8TYycG/sgzPCqr9nyvQ = X-Gm-Gg: ASbGncujnIFNtzFDm8dUN4LAreLbOgWefrX16wILq/3UtVR+icWr+rxlea7JUkdokhQ 22KEem61h0RWwMwW/Su+BRPR4INc6c4q/E/aO7gHQ19PTwIkQCj5vLJT6927kCqnfhnhV+xR/Mm pUGslIDelbwMoXUNBAZ0KlLYX8wmTbiqCVYO/xCmjGoSJPeLKXgUMFOebg2+pWqMHqIRnzZXjwJ wxaic7apHgQx/MmxL8suYYQndGyEaWIgrZaqpHsqTRZV4TYH+6PIR6Xn00uwH+sd3PBzsXiaR9j ecrb8fiFiwmdCIC7xOJh0PectvfsH6yK X-Google-Smtp-Source: AGHT+IFO2cDv8kiwWI/ExJTIJ/4plwMPy8toObJ9rmldlQKIeM2Kqc0Zy/az6oyWpLUzRF9CQI739Q== X-Received: by 2002:a05:6402:2749:b0:5d0:ed92:cdf6 with SMTP id 4fb4d7f45d1cf-5d81ddc1b64mr58046183a12.19.1735301629910; Fri, 27 Dec 2024 04:13:49 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82ede9sm1098662766b.2.2024.12.27.04.13.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Dec 2024 04:13:49 -0800 (PST) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, thuth@redhat.com, zhao1.liu@intel.com, imammedo@redhat.com, akihiko.odaki@daynix.com, npiggin@gmail.com, Phil Dennis-Jordan Subject: [PATCH v3 6/6] hw/vmapple: XHCI controller's interrupt mapping workaround for macOS Date: Fri, 27 Dec 2024 13:13:36 +0100 Message-Id: <20241227121336.25838-7-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241227121336.25838-1-phil@philjordan.eu> References: <20241227121336.25838-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::62f; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This change enables the new conditional interrupt mapping support property on the vmapple machine type's integrated XHCI controller using compat_props. The macOS guest driver attempts to use event rings 1 and 2 on the XHCI controller, despite there being only one (PCI pin) interrupt channel available. With conditional interrupt mapping enabled, the XHCI controller will only schedule events on interrupter 0 in PCI pin mode. Signed-off-by: Phil Dennis-Jordan --- v2: * Set the "conditional-intr-mapping" property via compat_props, not directly on the created XHCI controller object. v3: * Moved the compat global property table into vmapple patch set -v16, now just add the conditional-intr-mapping property to it. * Set the property on any device implementing the abstract TYPE_XHCI_PCI rather than only the TYPE_QEMU_XHCI device specifically. (So the NEC controller works with the vmapple machine type too.) hw/vmapple/vmapple.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/vmapple/vmapple.c b/hw/vmapple/vmapple.c index 41e3d7d189..ec0896dd32 100644 --- a/hw/vmapple/vmapple.c +++ b/hw/vmapple/vmapple.c @@ -38,7 +38,7 @@ #include "hw/intc/arm_gicv3_common.h" #include "hw/misc/pvpanic.h" #include "hw/pci-host/gpex.h" -#include "hw/usb/xhci.h" +#include "hw/usb/hcd-xhci-pci.h" #include "hw/virtio/virtio-pci.h" #include "hw/vmapple/vmapple.h" #include "net/net.h" @@ -562,6 +562,12 @@ static const CPUArchIdList *vmapple_possible_cpu_arch_ids(MachineState *ms) static GlobalProperty vmapple_compat_defaults[] = { { TYPE_VIRTIO_PCI, "disable-legacy", "on" }, + /* + * macOS XHCI driver attempts to schedule events onto even rings 1 & 2 + * even when (as here) there is no MSI(-X) support. Disabling interrupter + * mapping in the XHCI controller works around the problem. + */ + { TYPE_XHCI_PCI, "conditional-intr-mapping", "on" }, }; static void vmapple_machine_class_init(ObjectClass *oc, void *data)