From patchwork Fri Oct 1 17:42:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 515105 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp1032051jaf; Fri, 1 Oct 2021 10:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXtfnr5NwW48tCxTe2pQuEGPxF2aW2ZsM5XXO/ouQd+0GxSykbvAiI+eA5S4fSztlig0JV X-Received: by 2002:a05:6e02:1d0e:: with SMTP id i14mr9625790ila.205.1633111115165; Fri, 01 Oct 2021 10:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633111115; cv=none; d=google.com; s=arc-20160816; b=snBm89ySYKqsl7TExSnuX0N2XWPXYUPQDSQR14dV1r+VdaWCUTQPG0BBJhTqxEAoVq jMXCk/nIY2ShHLwdTcky4pgtfSbY0OF5oCLwo5JX0fiRsNu+8rSrTSr+MFgahkk1aHXg GBfwKVLpSCqTDpGHmkHvjr/iEMNcABwQm75BAo9d5uhOBpDyBzUquxYIw2s+e5u5hiV5 Lqi1/8GL1ZK6QCDYM2286JIzn6qHYmBxpAoO5Md8xUhZuYCO7hzHnmdZvZ1P8cwQkzdD 77j4tfihLfn7Xf115fx9ArZ1hpNEwvVBlnp7UzvEpnLEpDC7Dbe+HtaihiNzlcMPNbZ7 sIng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=5CS2z1SevkbSoB879G+2NDFjYwoRuePhjlGvIjdncRI=; b=Xd/MfOjD8S3pn1d9Mjc+4CSrJGp9v9j9j2OQ14WcgdJ+OqJYad0liCPo3dBz3GexcB brJo86usxsgysiRbMfsfgaKKQ+8unq7adgcr55UPwlkcyIRqQOjFYyOV3fdKQhFsBN4l lEEBSTE10RD5JG19ssybrkZ9MPXyHsjI383pmycrCiOxS7RXv3yHl3uHYX/SjT9NfELu Zm6NA8m/6x7SDrvMm6Dz/2CqW68LmYrZOoro23nmTyUsG3TQSzRghrG05P9gzSAVqQg2 rTXUgMMWo+79pnh1glWicdNf3TbPjowcMuIJT7C3fVKnJlqPZ3jol/DF4tQeqkweewf3 F7Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j5c3t0N0; 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=fail (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 s11si10744997ilu.95.2021.10.01.10.58.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Oct 2021 10:58:35 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=j5c3t0N0; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWMnq-0006nQ-IG for patch@linaro.org; Fri, 01 Oct 2021 13:58:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWMYo-0004JH-JY for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:43:03 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWMYm-0004ZW-Pc for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:43:02 -0400 Received: by mail-wr1-x42c.google.com with SMTP id v25so6043991wra.2 for ; Fri, 01 Oct 2021 10:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5CS2z1SevkbSoB879G+2NDFjYwoRuePhjlGvIjdncRI=; b=j5c3t0N0VVlZ+Jtb3GxJY+1JMe0ZbMs2cNckTQ3hLmaEJYn6rLWKarcZF37vT6JmqW Dfd4k8f9uRo92c5V6JDIQRZmH3FYq7SqmiiYvIbNEHc0QHLk5tbxN4x4O7yuflg0iwv0 Bbq+9jclWbE6eIeVnQC9J55QQRvAcubMlyhtAb+QwMcgl3fcjbpeKJShoLhKi1MKMfrL YGsOTsycqkdoH/N/rYWLS7jC2yDnE5sZvpeOP6E3shmXx/J9weqcQnIpy4f/I563LePP iJUwIC+/q0IhVJEd0de2SyZmQmM1wHrQRyW/e/F9Ewg7TGoEQY2TPZO5R7F1dW/H6cZ8 SdnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5CS2z1SevkbSoB879G+2NDFjYwoRuePhjlGvIjdncRI=; b=7MtC4hfPsgNeYpAvgxKgXzICQNguZ2G3J+UsLKPmWXe7fukWDdFOcgeXr6YFZIKp3f cyayToFlkV3MHtkoVi5oXrc2sYTxUmzpTCIHpwn0hdvbLRBWKBpLBMVVO/USMDorvJYk jZAs8dlWw6CbCR80e8G+ucVFNekXhcAuY5/1NABYaAdiu60H3rM5wCGjDdLr1AZk5IYq m7vZLSjhIeUjMg1mrGeFLsrAxDr3A+UehywOr9QTiMk5DC40LcdcAduIgqx7w5351PWr gb9D+cOGNpt+8wJmahhtpeD7lFt1yZ27wWNMpGugIwd7GPnHyqHUa7QAhToXy/sNqTY+ XwDw== X-Gm-Message-State: AOAM531ER7KXJViN/LRou9drNIY7Y8pFkjb9Zz4Hi2/GIEAKColMSenW 3saFpKiTTSAJCaLs/R9u0/LmNw== X-Received: by 2002:a5d:6d03:: with SMTP id e3mr13812556wrq.383.1633110178934; Fri, 01 Oct 2021 10:42:58 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v23sm5945882wmj.4.2021.10.01.10.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 10:42:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CB3991FF96; Fri, 1 Oct 2021 18:42:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] hw/arm: fix the position of vcram for raspi Date: Fri, 1 Oct 2021 18:42:42 +0100 Message-Id: <20211001174243.128157-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Michael Bishop , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The previous calculation fell over when I tried to create a 8gb Pi 4 because the values where only 32 bit. However the quirk of the Pi hardware is the vcram can only appear in the first 1gb of address space. This also limits where the initial kernel and DTB can be loaded (notice the DTS for the 8gb Pi4 still only uses 32 bit sizes). Fix this cleaning up setup_boot to directly use vcram_base and documenting what is going on. NB: the aliases are confusing. Signed-off-by: Alex Bennée Cc: Michael Bishop Cc: Philippe Mathieu-Daudé --- hw/arm/bcm2835_peripherals.c | 14 +++++++++++--- hw/arm/bcm2836.c | 2 ++ hw/arm/raspi.c | 19 ++++++++++++------- 3 files changed, 25 insertions(+), 10 deletions(-) -- 2.30.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 1f2f0ad486..3856c7d267 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/module.h" +#include "qemu/units.h" #include "hw/arm/bcm2835_peripherals.h" #include "hw/misc/bcm2835_mbox_defs.h" #include "hw/arm/raspi_platform.h" @@ -74,6 +75,7 @@ static void bcm2835_peripherals_init(Object *obj) /* Framebuffer */ object_initialize_child(obj, "fb", &s->fb, TYPE_BCM2835_FB); object_property_add_alias(obj, "vcram-size", OBJECT(&s->fb), "vcram-size"); + object_property_add_alias(obj, "vcram-base", OBJECT(&s->fb), "vcram-base"); object_property_add_const_link(OBJECT(&s->fb), "dma-mr", OBJECT(&s->gpu_bus_mr)); @@ -138,7 +140,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) Object *obj; MemoryRegion *ram; Error *err = NULL; - uint64_t ram_size, vcram_size; + uint64_t ram_size, vcram_size, vcram_base; int n; obj = object_property_get_link(OBJECT(dev), "ram", &error_abort); @@ -235,15 +237,21 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_ARM_IRQ, INTERRUPT_ARM_MAILBOX)); - /* Framebuffer */ + /* + * The framebuffer has to live in the first 1gb of addressable + * space which is fine for older Pi's with less than 1gb of RAM + * but we need to take care not to put it too high otherwise + */ vcram_size = object_property_get_uint(OBJECT(s), "vcram-size", &err); if (err) { error_propagate(errp, err); return; } + vcram_base = MIN(ram_size, 1 * GiB) - vcram_size; + if (!object_property_set_uint(OBJECT(&s->fb), "vcram-base", - ram_size - vcram_size, errp)) { + vcram_base, errp)) { return; } diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c index 34aaaa77f1..18034c4131 100644 --- a/hw/arm/bcm2836.c +++ b/hw/arm/bcm2836.c @@ -79,6 +79,8 @@ static void bcm2836_init(Object *obj) "board-rev"); object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals), "vcram-size"); + object_property_add_alias(obj, "vcram-base", OBJECT(&s->peripherals), + "vcram-base"); } static bool bcm283x_common_realize(DeviceState *dev, Error **errp) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 50462bc04c..0342aeab03 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -198,14 +198,19 @@ static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) cpu_set_pc(cs, info->smp_loader_start); } +/* + * NB: ram_limit isn't the same as ram_size - it indicates the portion + * of RAM that boot components can live in (up to the first 1gb - the + * vcram_size, aka vcram_base) + */ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, - size_t ram_size) + size_t ram_limit) { RaspiMachineState *s = RASPI_MACHINE(machine); int r; s->binfo.board_id = MACH_TYPE_BCM2708; - s->binfo.ram_size = ram_size; + s->binfo.ram_size = ram_limit; s->binfo.nb_cpus = machine->smp.cpus; if (processor_id <= PROCESSOR_ID_BCM2836) { @@ -241,7 +246,7 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, ? FIRMWARE_ADDR_2 : FIRMWARE_ADDR_3; /* load the firmware image (typically kernel.img) */ r = load_image_targphys(machine->firmware, firmware_addr, - ram_size - firmware_addr); + ram_limit - firmware_addr); if (r < 0) { error_report("Failed to load firmware from %s", machine->firmware); exit(1); @@ -260,7 +265,7 @@ static void raspi_machine_init(MachineState *machine) RaspiMachineState *s = RASPI_MACHINE(machine); uint32_t board_rev = mc->board_rev; uint64_t ram_size = board_ram_size(board_rev); - uint32_t vcram_size; + uint32_t vcram_base; DriveInfo *di; BlockBackend *blk; BusState *bus; @@ -297,10 +302,10 @@ static void raspi_machine_init(MachineState *machine) qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); qdev_realize_and_unref(carddev, bus, &error_fatal); - vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size", + vcram_base = object_property_get_uint(OBJECT(&s->soc), "vcram-base", &error_abort); - setup_boot(machine, board_processor_id(mc->board_rev), - machine->ram_size - vcram_size); + + setup_boot(machine, board_processor_id(mc->board_rev), vcram_base); } static void raspi_machine_class_common_init(MachineClass *mc,