From patchwork Tue Mar 7 23:47:04 2023 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: 659891 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp37878wrb; Tue, 7 Mar 2023 15:50:05 -0800 (PST) X-Google-Smtp-Source: AK7set/3z2Y9+NrWwENasQX1hPch1z7uEIOpEOws9ri9yIbW5EVwy45HHlMTYd7QuaTrwRPo5TL+ X-Received: by 2002:a05:6214:19ec:b0:56e:9a34:4eaf with SMTP id q12-20020a05621419ec00b0056e9a344eafmr30668044qvc.36.1678233005298; Tue, 07 Mar 2023 15:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678233005; cv=none; d=google.com; s=arc-20160816; b=B6Nkis1RYiCMeOzjyGyCB+nVpVCB0xOqR22gNMQPk5XOCzw4eFPtdZflDtxSaBvTHm pLpe8bf3KxEe/J8sdv8amaNTTYMSU6bxYQyPmWkomex1fGEDcXySXb1dUz9MaZUSav1j UTbymYhm5BYbD0fSbAKA66sHIuMEghZHxoKP76YwQ2ZdSlV47d8omVhgf1zIA4g5rM8y +pKNk9Z4SOXTo/nQ4PTPvF1SgoZunNTuMZ5O98nPUkYHNk942Wcsq7Dyz/zgEOePpP5H PuMM7+WRAmZ4fb5TcIwX+Hg5gCoXC8qzuRm2P0crjVjjwDgsq/wpTRrdQB5bJHsXrEBK wCjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=9irWQw02oFu2/D4ty32J7zQYkGSYrUOUK9Or1m5BKRM=; b=aK8N7HUeg61hORcWtWdVmFTfLoJUco25sBYhmmtzocq2TtUmv2HaYf6E8IjrmNbg5i yItIj/QrlSJDOuhu86AgwLFGJ6rct0Gh+7vTBeiaJjMcLMyrJPzraHRV4pmTK17LG0Rf HS4is1HSIOV7pm4wS5CyZg1s82GpHmvxE8acOE3+sz7dkOebC3yQ8bkekIBnNv55lSHA LPfRe+gyX0mS49z/8ptIv2VZho0YLHMT8EYx5R0R3znOfXycGErHU9H2m8bfSn9hkYkZ gbVVjxJD6UKGUA3gICAEGov7tWEwSz60jNZeNxDMr1P7XlYM6ZJ8ESviH0jTJtFSviPs e/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gwSjzS98; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z17-20020a0cf011000000b0056e95808bb9si9891581qvk.295.2023.03.07.15.50.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Mar 2023 15:50:05 -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=gwSjzS98; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZh2t-0003wV-FG; Tue, 07 Mar 2023 18:48:39 -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 1pZh2s-0003hS-Ad for qemu-devel@nongnu.org; Tue, 07 Mar 2023 18:48:38 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZh2m-0002rs-FM for qemu-devel@nongnu.org; Tue, 07 Mar 2023 18:48:37 -0500 Received: by mail-wr1-x42f.google.com with SMTP id h14so13790413wru.4 for ; Tue, 07 Mar 2023 15:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678232910; 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=9irWQw02oFu2/D4ty32J7zQYkGSYrUOUK9Or1m5BKRM=; b=gwSjzS98wh68Fu2g62z1JKcKVOswblHKob2VT9JjOtYDq22LbtmKNaDA1fJtv2W1AT EV4PEnfHsvXV9fkZFHjfFey4bEm7elIRc/4o+ejCRKE9e7IICyYX2gxAIqVWa3nsR/6t jceI8fB1gGrP9Fot83WgeMN7M/DOrivjLLFqZ+87zq6cwjwgNW3E/X2hgLDIA3fluhRL 7rnXMz4v8wm1FMnhnQV2aMwxGVEcglLmU8y+nw1+eDeflXOJqADkJJV3KA1On/JMN0M/ vE9v2XBsHflvT4892HG+KM8JRDa5iTt/w1i7yYIAtrm5djlTqFbe2aCgvLVt6L2qDtJP 3HXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678232910; 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=9irWQw02oFu2/D4ty32J7zQYkGSYrUOUK9Or1m5BKRM=; b=hn8AT+FRxbWjSXLQVW+ZZcpens+KvnOPo8QYWWdDDb4ZNrYUlHyDT2MyGDYoE74eU/ yAFNLX+80iDFjA2YAYbn5FItuEH0siMXetKfobDA7AgVJwofAKD98K+wDrDo2xnb/+7p LiZWuwqSeHBvvzRsvxtbTrdjb3XLxzvAqJU+7OYQiNgzvOG00DwhbvN4YQTKAK+FhDh+ cP/0iJF9MnsH4bVvPvp2MP8Ceb5jCzUUgpskMYjKOlCfP+vv5WuNVMs6wMYaup/bfjMx uv/mpXm/jtS4H+Ky7kyydPRrX/LUSlmmtGEjfVZwyx2KafnvY48IlvKNA5xy1ZNcQiaQ bW1w== X-Gm-Message-State: AO0yUKVWREodBLC/duBYcNN6RExy80hVz5RV4OZ++twrqJivuKCGWo5p cdLb+7v27Eid2lLubrJAF0VwXYShqGV8ANmhEPw= X-Received: by 2002:a05:6000:1041:b0:2c6:e91d:1359 with SMTP id c1-20020a056000104100b002c6e91d1359mr9832855wrx.61.1678232910583; Tue, 07 Mar 2023 15:48:30 -0800 (PST) Received: from localhost.localdomain (57.red-88-29-179.dynamicip.rima-tde.net. [88.29.179.57]) by smtp.gmail.com with ESMTPSA id o13-20020a5d670d000000b002c8476dde7asm13706104wru.114.2023.03.07.15.48.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Mar 2023 15:48:30 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, BALATON Zoltan , Bernhard Beschow , Rene Engel , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Huacai Chen , Jiaxun Yang Subject: [PULL 13/20] hw/isa/vt82c686: Implement PCI IRQ routing Date: Wed, 8 Mar 2023 00:47:04 +0100 Message-Id: <20230307234711.55375-14-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230307234711.55375-1-philmd@linaro.org> References: <20230307234711.55375-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-x42f.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=unavailable 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: BALATON Zoltan The real VIA south bridges implement a PCI IRQ router which is configured by the BIOS or the OS. In order to respect these configurations, QEMU needs to implement it as well. The real chip may allow routing IRQs from internal functions independently of PCI interrupts but since guests usually configute it to a single shared interrupt we don't model that here for simplicity. Note: The implementation was taken from piix4_set_irq() in hw/isa/piix4. Suggested-by: Bernhard Beschow Signed-off-by: BALATON Zoltan Reviewed-by: Bernhard Beschow Tested-by: Rene Engel Message-Id: Signed-off-by: Philippe Mathieu-Daudé --- hw/isa/vt82c686.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 01e0148967..71da316052 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -604,6 +604,46 @@ static void via_isa_request_i8259_irq(void *opaque, int irq, int level) qemu_set_irq(s->cpu_intr, level); } +static int via_isa_get_pci_irq(const ViaISAState *s, int irq_num) +{ + switch (irq_num) { + case 0: + return s->dev.config[0x55] >> 4; + case 1: + return s->dev.config[0x56] & 0xf; + case 2: + return s->dev.config[0x56] >> 4; + case 3: + return s->dev.config[0x57] >> 4; + } + return 0; +} + +static void via_isa_set_pci_irq(void *opaque, int irq_num, int level) +{ + ViaISAState *s = opaque; + PCIBus *bus = pci_get_bus(&s->dev); + int i, pic_level, pic_irq = via_isa_get_pci_irq(s, irq_num); + + /* IRQ 0: disabled, IRQ 2,8,13: reserved */ + if (!pic_irq) { + return; + } + if (unlikely(pic_irq == 2 || pic_irq == 8 || pic_irq == 13)) { + qemu_log_mask(LOG_GUEST_ERROR, "Invalid ISA IRQ routing"); + } + + /* The pic level is the logical OR of all the PCI irqs mapped to it. */ + pic_level = 0; + for (i = 0; i < PCI_NUM_PINS; i++) { + if (pic_irq == via_isa_get_pci_irq(s, i)) { + pic_level |= pci_bus_get_irq_level(bus, i); + } + } + /* Now we change the pic irq level according to the via irq mappings. */ + qemu_set_irq(s->isa_irqs_in[pic_irq], pic_level); +} + static void via_isa_realize(PCIDevice *d, Error **errp) { ViaISAState *s = VIA_ISA(d); @@ -627,6 +667,8 @@ static void via_isa_realize(PCIDevice *d, Error **errp) i8254_pit_init(isa_bus, 0x40, 0, NULL); i8257_dma_init(isa_bus, 0); + qdev_init_gpio_in_named(dev, via_isa_set_pci_irq, "pirq", PCI_NUM_PINS); + /* RTC */ qdev_prop_set_int32(DEVICE(&s->rtc), "base_year", 2000); if (!qdev_realize(DEVICE(&s->rtc), BUS(isa_bus), errp)) {