From patchwork Sat Feb 9 06:32:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1039127 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="CUtApYvZ"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="GdXfpj21"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43xMgy4s1dz9sML for ; Sat, 9 Feb 2019 17:33:34 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 43270C21EDC; Sat, 9 Feb 2019 06:32:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=KHOP_BIG_TO_CC, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4AB9DC21F37; Sat, 9 Feb 2019 06:32:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 66339C21F98; Sat, 9 Feb 2019 06:32:12 +0000 (UTC) Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lists.denx.de (Postfix) with ESMTPS id D61DEC21FF7 for ; Sat, 9 Feb 2019 06:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549693930; x=1581229930; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=AmwHm6MLugXWJNntqplRcTB+sRQRl608VcWm5AALqZM=; b=CUtApYvZqo1QHTBF3uS1xTqcSR1o3qDkQtSDZwusIvYrZRyOH2CjxE30 5/RkPeqgcG8urrrEp1hCTXfMcIxAs4boXPLXq72xoatdYXhPkOEUwnbrX ytet7O2938D9TIZ//y2tj8Y+tzr+1q0dxWxI31pTC6DLABfme0La2LUH3 0EDpVDwFctbutDqKe8hs7pk3jkW58RPT0FtYEcrY/zzVbo2ZnWzdtTVu3 2kmnDcyWWBZ9flyExqDpTyuC+Ez6nMTeHzVK+8p14IWSaHpD26nCWxEmC AIMelzdvlBtKp8ewmtoefFVGb9UJoWTcUmP+dmujtJGeu3vELy4y7CAoB A==; X-IronPort-AV: E=Sophos;i="5.56,564,1539619200"; d="scan'208";a="102128420" Received: from mail-co1nam05lp2054.outbound.protection.outlook.com (HELO NAM05-CO1-obe.outbound.protection.outlook.com) ([104.47.48.54]) by ob1.hgst.iphmx.com with ESMTP; 09 Feb 2019 14:32:06 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3aTNfY0lQkSqxLcqBZUihCW7zErFNQCbjMgV2rgvR98=; b=GdXfpj2191F2WaoAnrsN063OgQHvrkebS2qWjnOrAH2lfZTfFBekTYRCA0ojBivB5J7S1yWuFwWKOIals2I8APn1Pnl6xYR/vgQldLq4KiIQxcA7uk3uz2EM2uEp1IQZlsO8vdkZWtX/n31TMwFXWHhsf0oOGYH3FUkBW1KhuIU= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.247.148) by MN2SPR01MB0008.namprd04.prod.outlook.com (20.179.144.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.17; Sat, 9 Feb 2019 06:32:03 +0000 Received: from MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::2cdb:c465:af57:8be1]) by MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::2cdb:c465:af57:8be1%7]) with mapi id 15.20.1601.016; Sat, 9 Feb 2019 06:32:03 +0000 From: Anup Patel To: Rick Chen , Bin Meng , Joe Hershberger , Michal Simek , Michal Simek , Lukas Auer , Masahiro Yamada , Simon Glass Thread-Topic: [PATCH v6 06/16] riscv: generic: Ensure that U-Boot runs within 4GB for 64bit systems Thread-Index: AQHUwEErflbhc+OoKkWCKTKYSZy8jQ== Date: Sat, 9 Feb 2019 06:32:03 +0000 Message-ID: <20190209063052.29092-7-anup.patel@wdc.com> References: <20190209063052.29092-1-anup.patel@wdc.com> In-Reply-To: <20190209063052.29092-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR0101CA0047.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::33) To MN2PR04MB6061.namprd04.prod.outlook.com (2603:10b6:208:de::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anup.Patel@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [49.207.49.10] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MN2SPR01MB0008; 6:AKgfZh1hEo1lUkrVplLJtattSguDyBvnAWarHEvKjPvQQYVi/tiJJm2CiRwoq1KptJbhb5c3anEjdKB8/S361/vT63CVTXEoi13wfvN2ReU+hhffEfRMFOjQddqF4hvr2CeGzVN3UDizwcMhjZh6efsnRpHUJA2HFZhTrE6u2WdR5I+COdVcAEhTwKPilTfY7s3Svu/lwKP4Ad/PeIYhlq2YMzieIP6DALfydej7R0jGIk60Bf/Mf+xoFGe/EFmVKDPwDGsQ/cpciGEvUSzApgbcWAKPedBOny7J6CkIwLWJB9q/HWKwyVFdUDU6ADmICCWRLeQHdSae+Nff3nO+vc0TxPSRu5Tnb8AgS24opcGOa0EaARo7xvP7nhLfaAZP9paT7INxk/CjOMqCdGDoNjhsJmZcKGdpN4Pkp4+oSMs8vvG2N8wxdwSvXWwbDNSlkkisBIcJUBvWfaRThafndA==; 5:ahcnbuf6KctbbEBN8DF4md0qaUUP/pzFWLdaGqXRXls42oJlQaPv4gnYupfOKp5lyNzjdRGIlSodj9ned+nux3Du4sBu2W0stERcNgKz29eQQDjmKp5dyKn3+fKGz2XzB50oelVdQue2qyTYbdfaoKSJoYn+STZI87VSRxWMib5Z0XuBj/r2oF9+pCJq0IONkHya7A4BJzAm/wmW5gTKrg==; 7:bOZBHCIRLk2NY96X7n2fRw340dQntY8Oj3XeshWNkASnVXmCJ8bLg/LAKPujwBlslswfm9aZP32Gba5ir/poeLyx5bnNlm5/CJq1WjhBYr2B5mi1PuuHIAC8fE1czYf5i7j1lCppG/9UzE43XDhnzQ== x-ms-office365-filtering-correlation-id: b58cbc0d-943b-41b7-fdfd-08d68e584ddd x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(4618075)(2017052603328)(7153060)(7193020); SRVR:MN2SPR01MB0008; x-ms-traffictypediagnostic: MN2SPR01MB0008: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-forefront-prvs: 09435FCA72 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(396003)(346002)(39860400002)(136003)(189003)(199004)(99286004)(1076003)(76176011)(55236004)(186003)(102836004)(52116002)(6436002)(72206003)(6506007)(71190400001)(71200400001)(478600001)(26005)(6512007)(68736007)(53936002)(386003)(97736004)(256004)(6116002)(3846002)(105586002)(305945005)(86362001)(2616005)(81156014)(8676002)(50226002)(25786009)(446003)(7736002)(106356001)(476003)(11346002)(2906002)(66066001)(14454004)(6486002)(44832011)(486006)(7416002)(36756003)(316002)(54906003)(4326008)(110136005)(8936002)(81166006)(41533002); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2SPR01MB0008; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: shXh5qdQ0ok7n9AlR7Uq9FT0YbhBivSEW71ZpOAGZEwU+q/Rb7vaJ1TorrurxLGpHrcx556GpEqL0InQjycr2AXzZFVFIq7SpEkmEBtqgDW/JQxLdTtMH5fe8HjkunQQe9ycv/WqRYHBf1k0YaFSE/725cDmrqhfu1gFTrTAUGsoZXl2bhSp0bOcIVzYCdNstUgT8ZOPQblVgKPNsMDELEB0qMJiNWuGf1WXzwpXSGDH1+KIlZjaaSNBDxWb1Rlv5Bf8OiAFMmXlx0ecHVVn95lil9dcwOChF3lbHn1hOoCWkTpKLaxowf24E2X5bJ5bvS136XcvzPqoH7gxFNTrU6Q9h9RL9XJ/pC58NcvUatBdICqD1E16lSWKEud46lOUAOvr57lZykmnG4mZeBNbvZfC9da/afFy2r6YzEna4iM= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: b58cbc0d-943b-41b7-fdfd-08d68e584ddd X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2019 06:31:59.4225 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2SPR01MB0008 Cc: Palmer Dabbelt , Alexander Graf , U-Boot Mailing List Subject: [U-Boot] [PATCH v6 06/16] riscv: generic: Ensure that U-Boot runs within 4GB for 64bit systems X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" On 64bit systems, the DRAM top can be easily beyond 4GB and U-Boot DMA mapping APIs will generate DMA addresses beyond 4GB. This breaks DMA programming in 32bit DMA capable devices (such as Cadence MACB ethernet). For example, If DRAM is more then 2GB on QEMU sifive_u machine then Cadence MACB ethernet stops working for U-Boot because it is a 32bit DMA capable device. To handle 32bit DMA capable devices on 64bit systems, we provide custom implementation of board_get_usable_ram_top() which ensures that usable ram top is not more then 4GB. This in-turn ensures that U-Boot always runs within 4GB hence DMA addresses generated by DMA mapping APIs will be within 4GB too. Signed-off-by: Atish Patra Signed-off-by: Anup Patel Reviewed-by: Alexander Graf Reviewed-by: Lukas Auer Reviewed-by: Bin Meng --- arch/riscv/cpu/generic/dram.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c index 84d87d2a7f..b7b1207235 100644 --- a/arch/riscv/cpu/generic/dram.c +++ b/arch/riscv/cpu/generic/dram.c @@ -5,6 +5,9 @@ #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; int dram_init(void) { @@ -15,3 +18,20 @@ int dram_init_banksize(void) { return fdtdec_setup_memory_banksize(); } + +ulong board_get_usable_ram_top(ulong total_size) +{ +#ifdef CONFIG_64BIT + /* + * Ensure that we run from first 4GB so that all + * addresses used by U-Boot are 32bit addresses. + * + * This in-turn ensures that 32bit DMA capable + * devices work fine because DMA mapping APIs will + * provide 32bit DMA addresses only. + */ + if (gd->ram_top > SZ_4G) + return SZ_4G; +#endif + return gd->ram_top; +}