From patchwork Sat Sep 6 11:42:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36927 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 605D9202A1 for ; Sat, 6 Sep 2014 11:42:57 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id x3sf38672905qcv.10 for ; Sat, 06 Sep 2014 04:42:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=xY+4hr+TSh5/VI/LbkNokqhe3RFcz4fbhYajWmt9jUE=; b=W9MVSJSxU7X5Q1P9VvSBqhri7ngAqq0efn0CaeRuKdKrgQ0vW3SSz16n+wD80iTyMj RUBPton/3md5c/gb9Juxd3PM3q5iWuSCdmfwFUcRsYIuFL2wdYv6nDo9HBFDc3Lz564s Pi0X6jWC87arjbRW0Lv6fS59lB5DUY40Ls7ETjJO5jLlvDAScBogFFR6RIbNHXiHaln0 fYzBiSxPo9oUWIZ6TGczHYPADcRNMov6xn7OTg6NdOjYnXE3ytJ+Tfb3F+vYbTDDpp3R ce+A6GUirJ4KPtG9kz1tzMgXEZ4UADp+bbShcgEenghFxzBQnU4vzKi0V+QbWzkRGLAK kNlw== X-Gm-Message-State: ALoCoQkZCrmtksLwH7mJtjQfmmuHHyzeDp1VWxOwqnK7cWyHMf4hARv5aIEa9n0193fLSSZnUy16 X-Received: by 10.52.170.204 with SMTP id ao12mr10518338vdc.2.1410003777173; Sat, 06 Sep 2014 04:42:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.131 with SMTP id m3ls1136157qge.93.gmail; Sat, 06 Sep 2014 04:42:57 -0700 (PDT) X-Received: by 10.220.113.15 with SMTP id y15mr15178860vcp.17.1410003777080; Sat, 06 Sep 2014 04:42:57 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id p4si1983002vcn.54.2014.09.06.04.42.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 06 Sep 2014 04:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so13273336vcb.22 for ; Sat, 06 Sep 2014 04:42:57 -0700 (PDT) X-Received: by 10.221.64.205 with SMTP id xj13mr6686138vcb.18.1410003776951; Sat, 06 Sep 2014 04:42:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp203376vcb; Sat, 6 Sep 2014 04:42:56 -0700 (PDT) X-Received: by 10.42.67.133 with SMTP id t5mr803719ici.62.1410003776345; Sat, 06 Sep 2014 04:42:56 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id m18si4763981igk.49.2014.09.06.04.42.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 06 Sep 2014 04:42:56 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XQEOF-0003vv-H2; Sat, 06 Sep 2014 11:42:47 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XQEOE-0003vq-5P for edk2-devel@lists.sourceforge.net; Sat, 06 Sep 2014 11:42:46 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wi0-f171.google.com; Received: from mail-wi0-f171.google.com ([209.85.212.171]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XQEOD-0000CH-8W for edk2-devel@lists.sourceforge.net; Sat, 06 Sep 2014 11:42:46 +0000 Received: by mail-wi0-f171.google.com with SMTP id hi2so552791wib.16 for ; Sat, 06 Sep 2014 04:42:39 -0700 (PDT) X-Received: by 10.180.12.173 with SMTP id z13mr9689292wib.53.1410003758945; Sat, 06 Sep 2014 04:42:38 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id q3sm4900447wia.14.2014.09.06.04.42.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 06 Sep 2014 04:42:38 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com Date: Sat, 6 Sep 2014 13:42:32 +0200 Message-Id: <1410003752-21176-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1XQEOD-0000CH-8W Subject: [edk2] [RFC PATCH] ArmPlatformPkg: use virtual gRT at runtime X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The cached copy gRT of SystemTable->RuntimeServices is not updated by SetVirtualAddressMap (), which prevent us from using the RTC under the OS, as we call [Get|Set]Variable() through gRT at runtime. Replace gRT with mRT, which we update ourselves on a virtual address change event. Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- This is likely the wrong way to address this, hence the 'RFC' but it is required for the RTC to be usable under Linux after installing the virtual address map. It appears that the cached copy gRT (owned by UefiRuntimeServicesTableLib) is not wired up the virtual address change event, which results in us dereferencing the physical address of the runtime services table. The contents themselves have been converted, just not the value of gRT. If there is a 'proper' way to deal with this (or just a better one), I would love to hear about it. Cheers, Ard. .../PL031RealTimeClockLib/PL031RealTimeClockLib.c | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c index b43d8dc4ba2f..56204881ce86 100644 --- a/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c +++ b/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c @@ -40,11 +40,12 @@ #include -STATIC CONST CHAR16 mTimeZoneVariableName[] = L"PL031RtcTimeZone"; -STATIC CONST CHAR16 mDaylightVariableName[] = L"PL031RtcDaylight"; -STATIC BOOLEAN mPL031Initialized = FALSE; -STATIC EFI_EVENT mRtcVirtualAddrChangeEvent; -STATIC UINTN mPL031RtcBase; +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"PL031RtcTimeZone"; +STATIC CONST CHAR16 mDaylightVariableName[] = L"PL031RtcDaylight"; +STATIC BOOLEAN mPL031Initialized = FALSE; +STATIC EFI_EVENT mRtcVirtualAddrChangeEvent; +STATIC UINTN mPL031RtcBase; +STATIC EFI_RUNTIME_SERVICES *mRT; EFI_STATUS IdentifyPL031 ( @@ -294,7 +295,7 @@ LibGetTime ( // Get the current time zone information from non-volatile storage Size = sizeof (TimeZone); - Status = gRT->GetVariable ( + Status = mRT->GetVariable ( (CHAR16 *)mTimeZoneVariableName, &gEfiCallerIdGuid, NULL, @@ -312,7 +313,7 @@ LibGetTime ( // The time zone variable does not exist in non-volatile storage, so create it. Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; // Store it - Status = gRT->SetVariable ( + Status = mRT->SetVariable ( (CHAR16 *)mTimeZoneVariableName, &gEfiCallerIdGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -346,7 +347,7 @@ LibGetTime ( // Get the current daylight information from non-volatile storage Size = sizeof (Daylight); - Status = gRT->GetVariable ( + Status = mRT->GetVariable ( (CHAR16 *)mDaylightVariableName, &gEfiCallerIdGuid, NULL, @@ -364,7 +365,7 @@ LibGetTime ( // The daylight variable does not exist in non-volatile storage, so create it. Time->Daylight = 0; // Store it - Status = gRT->SetVariable ( + Status = mRT->SetVariable ( (CHAR16 *)mDaylightVariableName, &gEfiCallerIdGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -498,7 +499,7 @@ LibSetTime ( // Do this after having set the RTC. // Save the current time zone information into non-volatile storage - Status = gRT->SetVariable ( + Status = mRT->SetVariable ( (CHAR16 *)mTimeZoneVariableName, &gEfiCallerIdGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -516,7 +517,7 @@ LibSetTime ( } // Save the current daylight information into non-volatile storage - Status = gRT->SetVariable ( + Status = mRT->SetVariable ( (CHAR16 *)mDaylightVariableName, &gEfiCallerIdGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, @@ -609,6 +610,7 @@ LibRtcVirtualNotifyEvent ( // runtime calls will be made in virtual mode. // EfiConvertPointer (0x0, (VOID**)&mPL031RtcBase); + EfiConvertPointer (0x0, (VOID**)&mRT); return; } @@ -656,6 +658,8 @@ LibRtcInitialize ( gRT->GetWakeupTime = LibGetWakeupTime; gRT->SetWakeupTime = LibSetWakeupTime; + mRT = gRT; + // Install the protocol Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces (