Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp506622pxf; Wed, 7 Apr 2021 05:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDjdd6ZtTgkm169wDf6Ljve2vnXHreNRCXdqUVyYPEzukq9T7GLOohuN/8SCue2U7TB5RF X-Received: by 2002:a02:c9d0:: with SMTP id c16mr1234065jap.45.1617797463422; Wed, 07 Apr 2021 05:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617797463; cv=none; d=google.com; s=arc-20160816; b=e3tqf5RxjWNpvLT90tdvX3qdGpPDPoUNgGCpwxsGhJcSapBuTDJskZ1WWIzCnkCnBQ elslLCwWgcn+epoMGOl/vLMQr4HEEgMcq479Bpb8yjh4vGGbAIE+l7qCUw5GOtXZVFEH dPFl1Ek2eCOy04rVe1rcIopdb73I5I/ZJbAHE0+1UOeRn2Zu7azrhO+GqHEC2KDybseN BhhIffxKLZyoQdty8EodYXWGxhhV7nmaJIXw7WeOPIQUJsCaoEhqM6YmTgOGNu/Fk/d9 c+smSVyBJvYFKdP53vn1lOXFtusrD8tU1vHo5mTJQi8oFiFCHNMF90XJl8YWTxsq52zJ sgVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=TU4FbfnHAy7CBR07RnBiCzzlUaLRttHuSTUUciXPAWM=; b=pEXeb1lTiPFwnVkLgXAyInQMN/oj7WWLTX/NaFDxGdV9hi5GJvKqZXjSTlf5LnW4cv TftcLXB4eh2d1oQgSGlcWl6EfibvBu0b9SbGuyW2taSroUMWkkDHXRSw+zl5q04JTHYk Dc0oUi0dpD6lHNgXBHOBeNJI8bdEdt5t+duicUH54e2IqMb3iB9cte66Z0QfBiuuAGEo QVRgGe8uH9QyPzEyCaEknRB61KwHJmaCdc0e0+53qLI5UkZAQN3Ryo6TrIvwEiE7AJvk KzHJU4iBcABOImVNNkXaUZERdtu1+ar2pNxf/Z/DfKJc7ADe8rcwYDcwSesFjfXMzVx9 MzcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=marcan.st Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y24si20787448ioj.75.2021.04.07.05.10.50; Wed, 07 Apr 2021 05:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241028AbhDFTWG (ORCPT + 99 others); Tue, 6 Apr 2021 15:22:06 -0400 Received: from marcansoft.com ([212.63.210.85]:49944 "EHLO mail.marcansoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbhDFTWF (ORCPT ); Tue, 6 Apr 2021 15:22:05 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 30DF941E64; Tue, 6 Apr 2021 19:21:48 +0000 (UTC) To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, Rob Herring , Arnd Bergmann , Olof Johansson , Krzysztof Kozlowski , Mark Kettenis , Tony Lindgren , Mohamed Mediouni , Stan Skowronek , Alexander Graf , Will Deacon , Linus Walleij , Mark Rutland , Andy Shevchenko , Jonathan Corbet , Catalin Marinas , Christoph Hellwig , "David S. Miller" , devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210402090542.131194-1-marcan@marcan.st> <20210402090542.131194-16-marcan@marcan.st> <87ft03p9cd.wl-maz@kernel.org> From: Hector Martin Subject: Re: [PATCH v4 15/18] irqchip/apple-aic: Add support for the Apple Interrupt Controller Message-ID: <5a4a0ab4-5a4e-1f1c-f6c6-97439b95e7ee@marcan.st> Date: Wed, 7 Apr 2021 04:21:46 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <87ft03p9cd.wl-maz@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: es-ES Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/04/2021 03.16, Marc Zyngier wrote: > Hi Hector, > > On Fri, 02 Apr 2021 10:05:39 +0100, > Hector Martin wrote: >> + /* >> + * In EL1 the non-redirected registers are the guest's, >> + * not EL2's, so remap the hwirqs to match. >> + */ >> + if (!is_kernel_in_hyp_mode()) { >> + switch (fwspec->param[1]) { >> + case AIC_TMR_GUEST_PHYS: >> + *hwirq = ic->nr_hw + AIC_TMR_HV_PHYS; >> + break; >> + case AIC_TMR_GUEST_VIRT: >> + *hwirq = ic->nr_hw + AIC_TMR_HV_VIRT; >> + break; >> + case AIC_TMR_HV_PHYS: >> + case AIC_TMR_HV_VIRT: >> + return -ENOENT; >> + default: >> + break; >> + } >> + } > > Urgh, this is nasty. You are internally remapping the hwirq from one > timer to another in order to avoid accessing the enable register > which happens to be an EL2 only register? The remapping is to make the IRQs route properly at all. There are EL2 and EL0 timers, and on GIC each timer goes to its own IRQ. But here there are no real IRQs, everything's a FIQ. However, thanks to VHE, the EL2 timer shows up as the EL0 timer, and the EL0 timer is accessed via EL02 registers, when in EL2. So in EL2/VHE mode, "HV" means EL0 and "guest" means EL02, while in EL1, there is no HV and "guest" means EL0. And since we figure out which IRQ fired by reading timer registers, this is what matters. So I map the guest IRQs to the HV hwirqs in EL1 mode, which makes this all work out. Then the timer code goes and ends up undoing all this logic again, so we map to separate fake "IRQs" only to end up right back at using the same timer registers anuway :-) Really, the ugliness here is that the constant meaning is overloaded. In fwspec context they mean what they say on the tin, while in hwirq context "HV" means EL0 and "guest" means EL02 (other FIQs would be passed through unchanged). Perhaps some additional defines might help clarify this? Say, at the top of this file (not in the binding), /* * Pass-through mapping from real timers to the correct registers to * access them in EL2/VHE mode. When running in EL1, this gets * overridden to access the guest timer using EL0 registers. */ #define AIC_TMR_EL0_PHYS AIC_TMR_HV_PHYS #define AIC_TMR_EL0_VIRT AIC_TMR_HV_VIRT #define AIC_TMR_EL02_PHYS AIC_TMR_GUEST_PHYS #define AIC_TMR_EL02_VIRT AIC_TMR_GUEST_VIRT Then the irqchip/FIQ dispatch side can use the EL* constants, the default pass-through mapping is appropriate for VHE/EL2 mode, and translation can adjust it for EL1 mode. -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub