From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by mx.groups.io with SMTP id smtpd.web08.1407.1619206804193311748 for ; Fri, 23 Apr 2021 12:40:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sHFj/fTt; spf=pass (domain: gmail.com, ip: 209.85.208.53, mailfrom: adr.her.arc.95@gmail.com) Received: by mail-ed1-f53.google.com with SMTP id h10so58633755edt.13 for ; Fri, 23 Apr 2021 12:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3g7qkdO5wU/IOTnYed3FOyPFgKegcSmYMPjAcaPSGkE=; b=sHFj/fTtyfgS2M+V6+P07/MUi7E7QStFGinwCkbSkta1KY4vnXVBw0JZRLdghRmYaM rHg5Gnsh5DjoOvRcA1mnHUAb6yw7rh6/52hbNtfvZ8A+rz+x4yz0XmQNZtYtb9iG8qhc JSMOHwZh3K5YR6Zl7S93xlwcL+1dLD59/xqSXjxHFpO3nEP/JnATrjCrJ+B+jZs0FlIi jicMlx9FUX5Dh34Ttj6n4Soa9oUVoz1V3DV2k0u/gmjdi4cOhEzMbT/aZN0cGWDPSoAZ 72lur6eE6dAFJC0Xk8IRbyUbAskv6w855o5hg9SvAUrE1XpobMkRLgPr+mrfTmFl5Xrw Y9oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3g7qkdO5wU/IOTnYed3FOyPFgKegcSmYMPjAcaPSGkE=; b=cmUQwawMeSOUrT8NXFc9i3+VMS66Rj240sa9SZaLB+4ITbYr5psYywmnQh1P4kuRxl MpYDZilE2Py1oSAsEr52tKgve96NwvJ+PdRV+CuX/ZpzXShWFiwdYT3zeP6yncQTxIhz NDKSHIIYMhfWqDpZYZqfVIyX2hx9JqeRsdZR0FMrJsMNbu7PMJdlzYd1LhLgYZDag/xP +t67VWp2vnxR0lVwlABsNAzTksVSxW06pCjM+aCbJt6/1f7/dTnBmxr9tMs9kjyhyj/7 fM0Dz+NRjpFXK7NMxrxIQQOp8Pezkp9TT1lmbar1GtFuKqrZppE8FYQPa3TlnwLCvuVz OdAw== X-Gm-Message-State: AOAM532ONGJhPMtCHv5BdgrE7MtfU5q13I2iPC/XrdWEXp69U900D8ii 8pA6Y6uFyVlxZuXX7uxrE6gpuzamOL1r+bGU X-Google-Smtp-Source: ABdhPJwzZo2EHlWh8bSr/OrB8gs2YzY4dBEmXACMWCAtccbzA85eNLjSMtl1QXjd0g0c2dsFNqmpBw== X-Received: by 2002:a05:6402:1103:: with SMTP id u3mr6256181edv.205.1619206802446; Fri, 23 Apr 2021 12:40:02 -0700 (PDT) Return-Path: Received: from C02VH2K5HV2R.vc.cambridge.org (cpc91196-cmbg18-2-0-cust38.5-4.cable.virginm.net. [81.96.232.39]) by smtp.gmail.com with ESMTPSA id 9sm4616464ejv.73.2021.04.23.12.40.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Apr 2021 12:40:02 -0700 (PDT) From: adr.her.arc.95@gmail.com To: devel@edk2.groups.io Cc: =?UTF-8?q?Adri=C3=A1n=20Herrera?= Subject: [PATCH] ArmPkg/ArmGicLib: fix maximum interrupts supported Date: Fri, 23 Apr 2021 20:40:00 +0100 Message-Id: <2a2fef8f58a134336f19e049fbeb2c951bffaa52.1619206373.git.adr.her.arc.95@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable The maximum number of interrupts supported is determined as 32 * (GICD_TYPER.ITLinesNumber + 1). When GICD_TYPER.ITLinesNumber =3D 0b11111, the maximum number of interrupts supported is 1024. However, both GICv2 and GICv3 reserve INTIDs 1020-1023 for special purposes. This results in runtime crashes because: (1) ArmGicLib functions do not guard against special interrupts. (2) ArmGicGetMaxNumInterrupts number includes special interrupts. (2) ArmGicV*Dxe relies on ArmGicGetMaxNumInterrupts, and thus programs special interrupts through ArmGicLib. ArmGicGetMaxNumInterrupts now does not include special interrupts, that is, it reports 1020 instead of 1024 when GICD_TYPER.ITLinesNumber =3D 0b111= 11. This avoids the overhead of guarding ArmGicLib functions while not requiring to modify the drivers code. Signed-off-by: Adri=C3=A1n Herrera --- ArmPkg/Drivers/ArmGic/ArmGicLib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c b/ArmPkg/Drivers/ArmGic/ArmG= icLib.c index 6b01c88206..dff1401e9c 100644 --- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c +++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c @@ -120,7 +120,10 @@ ArmGicGetMaxNumInterrupts ( IN INTN GicDistributorBase=0D )=0D {=0D - return 32 * ((MmioRead32 (GicDistributorBase + ARM_GIC_ICDICTR) & 0x1F) = + 1);=0D + UINT32 ITLinesNumber;=0D +=0D + ITLinesNumber =3D MmioRead32 (GicDistributorBase + ARM_GIC_ICDICTR) & 0x= 1F;=0D + return MIN (32 * (ITLinesNumber+ 1), 1020);=0D }=0D =0D VOID=0D --=20 2.30.0