From patchwork Wed Mar 5 01:21:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 870543 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp554124wrg; Tue, 4 Mar 2025 17:36:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX7h+A5rc4K7CJsSnXrQmTV3aYdxKbHYzqUiklPOAq2Xm8/Adc7Jm7JcvPfYtpSVC5/OlURaQ==@linaro.org X-Google-Smtp-Source: AGHT+IEa3kwdScpYdCltZsVFkL9Ggot8ydCSiyqt8jvc9fqtTLnTz5WTxmIlqj66KAitgvaPRKs4 X-Received: by 2002:a05:620a:269f:b0:7c3:c88d:18c1 with SMTP id af79cd13be357-7c3d8e66f9bmr212224685a.20.1741138560277; Tue, 04 Mar 2025 17:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741138560; cv=none; d=google.com; s=arc-20240605; b=F8Hh4qK4UuKPIJ8QbfhtBLKd1BBLVESuKMUJ+E6QYxoJoJWO+R2LvUKaO0GMGX+Z4k E++RofzYGqod0TKY8xsWlDQnxWgBkQuRBKLCFlZ3kbLzLq4snfQFjDQUTvCAkmSnlVdc qhsXZa/WuYKE7bBOu3IhvBazD4vk5ek5vSjLmD0U/U1CZQvRB53wXrgyicmBO36QuNzk H0kZ1SvHuFAGOylPRlaAuLQ1gvOO8iQ3SSFENB7x3VQcJH2bQJdbCbyeHiNEed3Wn4NV 09yCrvty9Jxp3/LMo62UFtprwQtWRMrvF/GmNlLcD44dK6b3najNF1VyOYgREDlEsmug txZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jzLF6WZxlhetZaZPRfOe7fKCtkMcxscueckYeAPjn3I=; fh=WFBdicru1D9bSpCyezuvlbmKZ6DpYs++MhPzIQUvDzA=; b=ZqDq0NI786UMJ6CwsmymqzCMfTCyVu8PedyDhPVqJyI1gg0W2cfFXvNaHdRJrwvnxp j4cyi2s6GnHxRH6XHkQ/qwjpCMDApCVw2mGYKi2D6XALtIJjuwIXKu4kleMVNcWa8r7U b/GrGtxjxYSajNUsm5gpbqBttmHvsdxeEd6DITUnAtFEhx07kOgYrC1BfNkd7zY+JezQ HcRsR3XU08m/ofauzvIJM4o7moJhohjnoAmpXXyrCFnSAvkIKNz/rKfyKxa06qB+zRT4 PWhiOQzpAfRZCnSkPEB59A9dcU3OBoDvA3HZ428M2Eo11KURnDSCgi2R4SWReQj2QA2j O1lw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/PeVj4d"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c3cb278097si293602185a.366.2025.03.04.17.36.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Mar 2025 17:36:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/PeVj4d"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpdU7-0001Rl-SF; Tue, 04 Mar 2025 20:23:43 -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 1tpdTB-0008ES-T6 for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:22:53 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tpdT8-0006yg-Bq for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:22:44 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43996e95114so42446825e9.3 for ; Tue, 04 Mar 2025 17:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741137760; x=1741742560; 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=jzLF6WZxlhetZaZPRfOe7fKCtkMcxscueckYeAPjn3I=; b=M/PeVj4dw7tUxqzLOXL2zPIl9u7sLALOThyIPD6D6l8vWR3CLmFFwGQeqUkxOp6rmp 1Cz2KVmkDuMjlHVkK/4f3bdBiYgodIn9VSM4oK4Ldurg4aNTA7f+hTFEuwIlVXKV5SaY KErEz+SEMv+3OSwsteYuHR+PQQhzEA2dsfis57IwK78u2+g4M62c8mUdU0mSYlD/I44y /F2+A9nSHF+RE6Xb2WCQF9Lk5vxaUYXmJ7hTXAP+elh8YxnXOMAzxUjtjGWHOAnlx2H9 ByELEIF3ihDLB2nOHrcA1MSlKXqbF9a0XVhExj8qJNDxuSuONbjMztJu8FANgy1Y0JVT sdLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741137760; x=1741742560; 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=jzLF6WZxlhetZaZPRfOe7fKCtkMcxscueckYeAPjn3I=; b=PJjxcJRQ8b4pjdy/bHU/eblchp5ztsVDUzDuHH554WprZsXEyrPtxf3N+09MFxlm9I IcVUVHQEJRn+kwqFzwFgyWiw8TeTv9Im6exYM/4zyn5kl+pgEbic6ExWcpMOOJ99lgMw 9HZWoIaM0Qu0pC/6cxYwIxC66CJSAOdlIL42oZ0wEYb+pqbdgbnmFqOXo1i42arzHFO/ DhRFEjZbtSLeBEio81Mlpff/gFgN2MYPR4eEdxmJzfdNKrAkPLZr2gTYzwOvNEIhEPjy mVOg+VV5HfK2F+Rjy4xqQLPUhhW3RvHHephEu30e68qOLLtwKe2xoejldeKQGGHbBC0+ s5zg== X-Gm-Message-State: AOJu0Yyqr+hbdG8ICDkh+UPbEXOqEg/mUSjTn+Yrt6BUczjkqs6wsgV8 gJ730FX1gSd0w6oQQO7xSTmFWlBcinaMhSSDftY003VgvHXJHkiNRIh9kV3ixi4h/Dw0ccffu+A n7Mg= X-Gm-Gg: ASbGncsN2imeQRSTvGdyxBx/JFFo/Au+0OFAEJmv1vnsacB0LGNhLYVd/M70RSsxsmg pjvopAqILgSxYQCufkPYKOT7tbYR1yD9g2yu/TZB3MloSEkkMIzUiHwM2t9FbxFaVeS4CnczxIo QsVO4lwqoJQXfUa6Ritl8YGr2/cqpDd5LFrrUBLFNntJXdHYIbjfAh40gNRr2D7hwFChGW2pS6x j/IlzrXBKDvBlIGYa+EXKiT6Ox1ChLufMPV4Eittv9RbE3dcW3nucBisufPfNygraNzkjn6isVt F8DtKbQkaGd6fAqkbeL+k+TfZFATICCCPPuAjBiifV1gH7N41q7x/aLsaDHsquFOx1rUaqyUG6q 6yuUmrnSNPYjoiqfGEz8= X-Received: by 2002:a05:6000:2c6:b0:385:f249:c336 with SMTP id ffacd0b85a97d-3911f7c4703mr616891f8f.45.1741137760367; Tue, 04 Mar 2025 17:22:40 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485dbe7sm19453481f8f.93.2025.03.04.17.22.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 04 Mar 2025 17:22:39 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Phil Dennis-Jordan , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 08/41] hw/usb/hcd-xhci-pci: Adds property for disabling mapping in IRQ mode Date: Wed, 5 Mar 2025 02:21:23 +0100 Message-ID: <20250305012157.96463-9-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250305012157.96463-1-philmd@linaro.org> References: <20250305012157.96463-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Phil Dennis-Jordan 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 Message-ID: <20241227121336.25838-6-phil@philjordan.eu> Signed-off-by: Philippe Mathieu-Daudé --- hw/usb/hcd-xhci-pci.h | 1 + hw/usb/hcd-xhci.h | 5 +++++ hw/usb/hcd-xhci-pci.c | 24 ++++++++++++++++++++++++ hw/usb/hcd-xhci.c | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci-pci.h b/hw/usb/hcd-xhci-pci.h index 08f70ce97cc..5b61ae84555 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.h b/hw/usb/hcd-xhci.h index 9609b835141..9c3974f1489 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 */ diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c index 49642aab58e..d908eb787d3 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.c b/hw/usb/hcd-xhci.c index 00d5bc37792..64c3a23b9b7 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; }