From patchwork Mon Feb 3 08:26:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00A5B14B4 for ; Mon, 3 Feb 2020 08:28:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC00820658 for ; Mon, 3 Feb 2020 08:28:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jd86iqOj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC00820658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX5x-0005ok-07 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:28:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34738) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX3q-0002BV-Nw for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX3p-0000yB-6h for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:26 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:45146) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX3o-0000x7-Vw; Mon, 03 Feb 2020 03:26:25 -0500 Received: by mail-wr1-x442.google.com with SMTP id a6so16688034wrx.12; Mon, 03 Feb 2020 00:26:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/a2AvhlrNq+nqNmvP5yTkn3vOLPg6+tDNEhEkfX8xNo=; b=jd86iqOjEh4ckVMErcVFBHrvwO4v2+EOqb+C/zGfcByfiV6HM1svWjV0wTdkHeA1xC cTpZ1NnlUzHsno5CbYV5AxbK0FpfdY12FcU3z7GcmHSnrgU2AcSZDmLneXVq7hL0QPNG B985oTIcD1OvkBSLmexdSPnAIPadR/fMfN9cyeg11lJcNOcnZ/70mhvmvmPsMU/0sOrI SYObl6dPH34RXhFvTdg82tGg6Qsg3a/K8ttsJ4i4rmdrSpojZg7oVvvyE1PGOc2HjrYg 4VJdXN1rq/QC31rVhx9FvN51LEDtdNJUuO8oIKn8xCjHiWwQNS+nRui2hl2AiN3nfr2y jP5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/a2AvhlrNq+nqNmvP5yTkn3vOLPg6+tDNEhEkfX8xNo=; b=SR2GTqiEUSeyaPyC5REHV4bj7CkYzLy1SDcTorq0NKPvxvy9Rt56Iqj9jJrFxcdJum 7qL9ea2UPkTL80iTjeg92i1fYTI1+eFFDKprHDV/t00onnBysZteui8Gbsgde7DnqSrr z6g0/omcj3KKhO6MDstqVWzcv+sW5C1+85vY4f6pZQzPr5aWOfsNAk5gijEwwHmy31SS 3PdOUVTZ1oKqh5izZpnWQb9j7P1g36UTlIGj1GWiDSllR0f5tddfygqThSVECqeIgU57 ypmTP88hWS1NQQ/PVPP4SvWfKnSoN0wwICBJXwIEGNDY1S1V3rhGCS+xf5tlIH/AgrOv wvpA== X-Gm-Message-State: APjAAAVLApKPcGAOKeMLlOV+dvfGmEE+bghX8FnVxA1RQWHt9leCnaBh 3oiS6m/gYPCgJOTg7tko3F4CSIA9 X-Google-Smtp-Source: APXvYqxK3ZRg6AGYyML/L0hk0IdCjLIwUN/ePklV/5mtZWP+9WV/5VGI2bgTGXxiXfxFhr5y8isiDg== X-Received: by 2002:a05:6000:10c:: with SMTP id o12mr10428596wrx.106.1580718383745; Mon, 03 Feb 2020 00:26:23 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:23 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/6] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Date: Mon, 3 Feb 2020 09:26:14 +0100 Message-Id: <20200203082619.7426-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 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 , Stephen Warren , =?utf-8?q?Zolt=C3=A1n_Baldaszti?= , Alistair Francis , Jeremy Linton , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Pete Batard , Igor Mammedov , Michael Chan , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Pekka Enberg , Kshitij Soni Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" When booting without device tree, the Linux kernels uses the $R1 register to determine the machine type. The list of values is registered at [1]. There are two entries for the Raspberry Pi: - https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138 name: MACH_TYPE_BCM2708 value: 0xc42 (3138) status: Active, not mainlined date: 15 Oct 2010 - https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828 name: MACH_TYPE_BCM2835 value: 4828 status: Active, mainlined date: 6 Dec 2013 QEMU always used the non-mainlined type MACH_TYPE_BCM2708. The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and 0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182). The Raspberry Pi foundation bootloader only sets the BCM2708 machine type, see [2] or [3]: 133 9: 134 mov r0, #0 135 ldr r1, =3138 @ BCM2708 machine id 136 ldr r2, atags @ ATAGS 137 bx r4 U-Boot only uses MACH_TYPE_BCM2708 (see [4]): 25 /* 26 * 2835 is a SKU in a series for which the 2708 is the first or primary SoC, 27 * so 2708 has historically been used rather than a dedicated 2835 ID. 28 * 29 * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation 30 * chose to use someone else's previously registered machine ID (3139, MX51_GGC) 31 * rather than obtaining a valid ID:-/ 32 * 33 * For the bcm2837, hopefully a machine type is not needed, since everything 34 * is DT. 35 */ While the definition MACH_BCM2709 with value 0xc43 was introduced in a commit described "Add 2709 platform for Raspberry Pi 2" out of the mainline Linux kernel, it does not seem used, and the platform is introduced with Device Tree support anyway (see [5] and [6]). Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef "raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4 "raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708. [1] https://www.arm.linux.org.uk/developer/machines/ [2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135 [3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64 [4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18 [5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526 [6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- Cc: Zoltán Baldaszti Cc: Pekka Enberg Cc: Stephen Warren Cc: Kshitij Soni Cc: Michael Chan Cc: Andrew Baumann Cc: Jeremy Linton Cc: Pete Batard --- hw/arm/raspi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 3996f6c63a..ef76a27f33 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -29,8 +29,7 @@ #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ -/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44}; +#define MACH_TYPE_BCM2708 3138 /* Linux board IDs */ typedef struct RasPiState { BCM283XState soc; @@ -116,7 +115,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) static struct arm_boot_info binfo; int r; - binfo.board_id = raspi_boardid[version]; + binfo.board_id = MACH_TYPE_BCM2708; binfo.ram_size = ram_size; binfo.nb_cpus = machine->smp.cpus; From patchwork Mon Feb 3 08:26:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E40F112B for ; Mon, 3 Feb 2020 08:27:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1581120658 for ; Mon, 3 Feb 2020 08:27:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tZU2e6MQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1581120658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX4Z-0003Ir-8F for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:27:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34750) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX3s-0002CO-TT for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX3q-0000zj-Kb for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:28 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:33228) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX3q-0000ye-E2; Mon, 03 Feb 2020 03:26:26 -0500 Received: by mail-wm1-x342.google.com with SMTP id m10so13745357wmc.0; Mon, 03 Feb 2020 00:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fH7Pr46rmz5zfbrhebu4o/OiNogYj/7gAgBrUxWpkLo=; b=tZU2e6MQrFAdoCSswO188XhNoZnhzsdTfMcXFl5qLNMbckVT4KJ7mMxkyNI5uMZLXB o+bcTC5CUmyqslqESlHRacNGD/vXBOuQZodvy69AAzOTttHqOd5LvntEHC8XwudG+TKk AOpP6N6hbjBhRFRSYiX4OsqOGybK8Y2KL8yBYEZTuAfatgCCpo1QokI5yur20O3aiC2o wz5NQ/dHiu2Q02ASpu3WxKLlTxAnFBnwh2hPYXQETBz5TulwdWbURjITdoF/bPuw2Vs/ FVeRSPlHADDDVejdHoCyw6wLGtP6+LuU7LZzrSkdOwefw/FcsW9gAxejKNF9MdqOyxjW 68Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=fH7Pr46rmz5zfbrhebu4o/OiNogYj/7gAgBrUxWpkLo=; b=JrLDAcnU2eubOE8DhYUPXGzSbbYDuBS4id41v68FocAoTG72zoxurw25dompfQF3KM Kujis2vvSr7I6qJMOF373A7Y4UojRZv5dZ5y1kCbEynlM91UAiJyyb5B30H1jbXk3Fvl Pcpts+fvYfaXbvMlS/gSQv+aP6jTW5WskGWsIOqQ7rwQdHsNVRh//g+7Xajcrtp9AYQg U6a5z+Rf+rlTkpb95rDSRo3hs6u3uLaZcmZDbgtUoleQlRNNxeW2/S4XMzpQ7J1N1uce yJ1ToP0viXwrPF4c9hmh8W1Je2azzwuacALTv1AeIF9P+y9tZ/Da05rVIX+xoMDjl5dP 2ZCg== X-Gm-Message-State: APjAAAW8IW1YmzlbpTXs9ThYQPP89LLOlmcc+k1fm8nPMduih2HvbGlD AabH5uv9gnqt1ogpQTBhY879Nu43 X-Google-Smtp-Source: APXvYqwM5YhbYRWsW7fFCiDkDhq6m6Eksj9GE04oNvw9Ovg/s/COQ+W0c77BcnEYAxfKkh9TLkB7IQ== X-Received: by 2002:a1c:3b87:: with SMTP id i129mr27019922wma.142.1580718385052; Mon, 03 Feb 2020 00:26:25 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:24 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/6] hw/arm/raspi: Get board version from board revision code Date: Mon, 3 Feb 2020 09:26:15 +0100 Message-Id: <20200203082619.7426-3-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 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 , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Igor Mammedov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The chip ID is encoded in the board revision, and the board version is simply 'chip_id + 1'. We want to support more boards which follow the same scheme. Introduce a new RaspiBoardInfo structure which we'll extend in the following commits. Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/raspi.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index ef76a27f33..eaa8c49009 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -36,6 +36,39 @@ typedef struct RasPiState { MemoryRegion ram; } RasPiState; +typedef struct RaspiBoardInfo { + /* + * Board revision codes: + * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/ + */ + uint32_t board_rev; +} RaspiBoardInfo; + +enum { BOARD_PI2, BOARD_PI3 }; + +static const RaspiBoardInfo raspi_boards[] = { + [BOARD_PI2] = + { + .board_rev = 0xa21041, + }, +#ifdef TARGET_AARCH64 + [BOARD_PI3] = + { + .board_rev = 0xa02082, + }, +#endif +}; + +static int board_chip_id(const RaspiBoardInfo *config) +{ + return extract32(config->board_rev, 12, 4); +} + +static int board_version(const RaspiBoardInfo *config) +{ + return board_chip_id(config) + 1; +} + static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { static const uint32_t smpboot[] = { @@ -163,9 +196,10 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) arm_load_kernel(ARM_CPU(first_cpu), machine, &binfo); } -static void raspi_init(MachineState *machine, int version) +static void raspi_init(MachineState *machine, const RaspiBoardInfo *config) { RasPiState *s = g_new0(RasPiState, 1); + int version = board_version(config); uint32_t vcram_size; DriveInfo *di; BlockBackend *blk; @@ -191,9 +225,8 @@ static void raspi_init(MachineState *machine, int version) /* Setup the SOC */ object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram), &error_abort); - int board_rev = version == 3 ? 0xa02082 : 0xa21041; - object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev", - &error_abort); + object_property_set_int(OBJECT(&s->soc), config->board_rev, + "board-rev", &error_abort); object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort); /* Create and plug in the SD cards */ @@ -215,7 +248,7 @@ static void raspi_init(MachineState *machine, int version) static void raspi2_init(MachineState *machine) { - raspi_init(machine, 2); + raspi_init(machine, &raspi_boards[BOARD_PI2]); } static void raspi2_machine_init(MachineClass *mc) @@ -237,7 +270,7 @@ DEFINE_MACHINE("raspi2", raspi2_machine_init) #ifdef TARGET_AARCH64 static void raspi3_init(MachineState *machine) { - raspi_init(machine, 3); + raspi_init(machine, &raspi_boards[BOARD_PI3]); } static void raspi3_machine_init(MachineClass *mc) From patchwork Mon Feb 3 08:26:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF6E2138D for ; Mon, 3 Feb 2020 08:28:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8630220658 for ; Mon, 3 Feb 2020 08:28:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fywPq+Yh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8630220658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36041 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX5i-0005T3-NF for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:28:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX3u-0002DO-QS for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX3t-00011l-1j for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:30 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:55913) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX3s-00011F-Rs; Mon, 03 Feb 2020 03:26:28 -0500 Received: by mail-wm1-x342.google.com with SMTP id q9so14722384wmj.5; Mon, 03 Feb 2020 00:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EpUTRq0kxtJ0Er2jTMdb5IFTVrAUR3PzkNabxGsF4V8=; b=fywPq+YhIU+m28yFYLG6vh+ESwLEVWNCo/gl2Px9g0Q4TZgCJWnV0kmQVeXAOr1YCg OxjQWaDmn59Ktu19BxXfsCgaMZme9hgS1ECZkle7ZyvbdFgdt+T733EWMznrleXHUzJp 8M9bwZJNoAh1eiec5eREX3kMryrB/4WkrKhm/DNx6G1H3UGspky0jOvdXxOiKHiCEuNK QoauoNjYKzZb1I+s6XEIwAGlk4w/1KWpTpdUFBIGbE6I0gzIGC0hNAEfdc9sGkW1zUS9 6M/60oYaoth0V49RiZX/EZmQ0YeBkTESe+F0qtiK6LfxmbYVsp1VEANdFspNCUjww0AH gbNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EpUTRq0kxtJ0Er2jTMdb5IFTVrAUR3PzkNabxGsF4V8=; b=KzQ5lyEBnWT4lEQ1PRfpEf2z5vXcmlcAWkIorsuCoEjqrdPus76snAQwVaOBipj2Eg cgHyanRvGdB7DQ7+ZbPWXzpt/ebmlQxc7dnryFT3hiJo72K8Dx9bpiKCPmPA+zwM+al6 nJ97tr3yDhTTySxLKH6bjJv+HjBSxG/p93oR5gUn9OxPDjs5zGU0H7q3FX5rsyC7s7rI H4FxhQWkf9YfvUO9jZyDjmt4BQ7ZQCYElylcQmAk21C6HMxjCv1xJJ/mJw8CjL+pT/9z 1tT9/0zC5rUS8+rRWejwrPeY2uKVYGG19ay0IJiCGqiUOD6mfZbMSGwtNuMdIuoPgkYx O8Gw== X-Gm-Message-State: APjAAAVJOwMWFpjMNuEJufZ8+P7FHdv8aWKtVFQGEucuSqE7eN5MGFpS dP1eCiNPv17ZVb05uj+1o/40ryii X-Google-Smtp-Source: APXvYqwnDfQj625IvnQJF4yI5+KpOihczsKwND7QYeXRSIzExO9aXO/o0p3cixT1GJdq3ICNgaKArQ== X-Received: by 2002:a1c:9c87:: with SMTP id f129mr28804653wme.26.1580718386542; Mon, 03 Feb 2020 00:26:26 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:26 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/6] hw/arm/raspi: Get the SoC type name from the revision code Date: Mon, 3 Feb 2020 09:26:16 +0100 Message-Id: <20200203082619.7426-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 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 , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Igor Mammedov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We already know the Chip ID, let's name it with the board_soc_name() helper. Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/raspi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index eaa8c49009..f5e54fe876 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -31,6 +31,18 @@ #define MACH_TYPE_BCM2708 3138 /* Linux board IDs */ +enum BoardIdChip { + C_BCM2836 = 1, + C_BCM2837 = 2, +}; + +static const struct { + const char *soc_name; +} soc_config[] = { + [C_BCM2836] = {TYPE_BCM2836}, + [C_BCM2837] = {TYPE_BCM2837}, +}; + typedef struct RasPiState { BCM283XState soc; MemoryRegion ram; @@ -69,6 +81,11 @@ static int board_version(const RaspiBoardInfo *config) return board_chip_id(config) + 1; } +static const char *board_soc_name(const RaspiBoardInfo *config) +{ + return soc_config[board_chip_id(config)].soc_name; +} + static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { static const uint32_t smpboot[] = { @@ -213,8 +230,7 @@ static void raspi_init(MachineState *machine, const RaspiBoardInfo *config) } object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc), - version == 3 ? TYPE_BCM2837 : TYPE_BCM2836, - &error_abort, NULL); + board_soc_name(config), &error_abort, NULL); /* Allocate and map RAM */ memory_region_allocate_system_memory(&s->ram, OBJECT(machine), "ram", From patchwork Mon Feb 3 08:26:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A37DD138D for ; Mon, 3 Feb 2020 08:28:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79B7C20658 for ; Mon, 3 Feb 2020 08:28:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eV1gR+dJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79B7C20658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX5g-0005Ob-Kg for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:28:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34804) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX41-0002F7-Em for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX3u-00012C-Pp for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:32 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX3t-00011Z-3J; Mon, 03 Feb 2020 03:26:30 -0500 Received: by mail-wm1-x342.google.com with SMTP id c84so15801329wme.4; Mon, 03 Feb 2020 00:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XbrBImsz44K8Xswh3EJyXdM5NyfxQNqxR88yL7gBw4I=; b=eV1gR+dJUN4GCsDBV7J3bxGaEGXZetqOEKg6/n3K+6OJxd15KkmosGax+6f9u+Na0a j82/3wP43NDosSrB7RYBHIy0ncN7Hlt08QuuL51E8W2jKsQTNUGCAQHMX6Ke8frmLB6B qklFQw3GIeSNi3Pk3FYPknKc2QCFuv7bD6xgW6RQiNwZbDXhM+OO1VIf8pxjVabM5GVj ietp0Z0jlVv6AEqCzhKiJYG1+Fvrw0w8pWXG3RybYTPblA6mLNHNJmJWI5mXmWpMWi+W aG9TnFppm54SEWsJJPBBQn+gm9O8v5n/XIFGgUedroDI819/niBufp0P7TCD0iGblTEV di+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=XbrBImsz44K8Xswh3EJyXdM5NyfxQNqxR88yL7gBw4I=; b=A4SP4Zjri/tXxeDDmL+ofJ+Goot7Yrq9cATw/zzMCPJeKALAwnsRhxHtU6qk/IQqBt QCgnK6lU4BiGVW+Hc3w1JxFM97h3+BLZxrOEndabYjsgnAQTrK3dUVd/78YPzmeNKIif qfNqbVpLskIBN7yjEwjP4fHB/xeSoI+K62g/kkMdVVeVl/D4QHfBPNrU308qcrO57R+P VMa04UC1n2kThHVel1OKroPUMq6rvFbyKOKvq/V/H8EPkhAByCZAl2zaFtab6yh3gJh4 eWklQiYRd3U6M+7ITKdP4ctNbtTGk36wMCX32RIOsIIHfljuFSD2Xi++dDWP+bBhxmuq JXXQ== X-Gm-Message-State: APjAAAWjpnGfFMoSku3wJG9DjZ/trpzl3wjrq+qtt8Dqr3+Bq8N7DBPZ UJp1qaOYGmbo6zAzWv4iiJi3NLN+ X-Google-Smtp-Source: APXvYqzAeylC/Aa3zxzliGKQOvFiWGVoaxqJwM7KLUkLdbIN5rwhWtke/jl675bZ4AFzMYTb8cS9ng== X-Received: by 2002:a1c:6246:: with SMTP id w67mr26959693wmb.141.1580718387957; Mon, 03 Feb 2020 00:26:27 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:27 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 4/6] hw/arm/raspi: Get board RAM size from board revision code Date: Mon, 3 Feb 2020 09:26:17 +0100 Message-Id: <20200203082619.7426-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 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 , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Igor Mammedov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The amount of RAM is encoded in the board revision. Add the board_ram_size() helper, it will allow us to quickly support new boards. Signed-off-by: Philippe Mathieu-Daudé Acked-by: Igor Mammedov --- hw/arm/raspi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index f5e54fe876..656d834e07 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "cpu.h" #include "hw/arm/bcm2836.h" @@ -71,6 +72,11 @@ static const RaspiBoardInfo raspi_boards[] = { #endif }; +static uint64_t board_ram_size(const RaspiBoardInfo *config) +{ + return 1 * MiB << extract32(config->board_rev, 20, 4); +} + static int board_chip_id(const RaspiBoardInfo *config) { return extract32(config->board_rev, 12, 4); @@ -222,10 +228,13 @@ static void raspi_init(MachineState *machine, const RaspiBoardInfo *config) BlockBackend *blk; BusState *bus; DeviceState *carddev; + uint64_t ram_size; - if (machine->ram_size > 1 * GiB) { - error_report("Requested ram size is too large for this machine: " - "maximum is 1GB"); + ram_size = board_ram_size(config); + if (machine->ram_size != ram_size) { + char *size_str = size_to_str(ram_size); + error_report("This machine can only be used with %s", size_str); + g_free(size_str); exit(1); } From patchwork Mon Feb 3 08:26:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362205 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9296A138D for ; Mon, 3 Feb 2020 08:29:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 691FA20658 for ; Mon, 3 Feb 2020 08:29:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lUBsX2iA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 691FA20658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX7C-0007mr-J3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:29:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34812) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX41-0002Fs-VZ for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX3u-00012M-Vo for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:34 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:39976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX3u-00011t-Pg; Mon, 03 Feb 2020 03:26:30 -0500 Received: by mail-wr1-x434.google.com with SMTP id j104so16723879wrj.7; Mon, 03 Feb 2020 00:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DFjUzzObXxlhnN9FkJ2W0kMBSKycCnz3WMxnNXs1uCo=; b=lUBsX2iA6rwwz9anYKuoKLRmUhyvGzmAW15ilmBEb6JNn42UCGKG6Wgh32pSu0G+fP PaCxgyxWgKj1umHMcOZi7mMMGDhCZjYm41cRcBl6rnSI84I4P1w04QTQr0B1psx0zpDj TjcMCAijXDKIw1EzEkZwu4lAOISn5pMXLzSujBqqSIY/6KM1vP7QPseMHrVjygHwNXgz vK4QAn6zitvSjr5aizvlGdB6vpq+QLje0vy/mFEVndGrIJ6ycWz++mbT14EnunWS5Ksx 4L4W5hZRp2E8OdjT1GQePjfbLHwBPHyjYeCvQ+KVv0YQFir/ZvQk0OgsOKSCvqfpAPEQ 6piA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DFjUzzObXxlhnN9FkJ2W0kMBSKycCnz3WMxnNXs1uCo=; b=fb7Wcrf0T50rmrHSiqbcfHXSH5bxpsrVdLGT0rREiWqgFrWoKxnxki+tFT1l9mJ9eH x2sCRRzKySU3A+8pdtXB6g0Hscj62FFyfZMknVKucK0R1FKYf2ZmXxtR6qpgV8tDj4ls +ocnH+yzLFxSunCIIWIm9W4PecJEJUQptAblSw/O2tmGbR9oosA9L6IBcFoiHVgAQpOx IimF0oY2NKqjzUTEVb7YEngCmKzlrFBQa+0qryhck1BgFfpnEnzbziPjTCgiSuUUgu6+ SG6pn33+Ga6l7koC3NpAh/UMFR6c52qtu40LYrODVMHg0590rfFQR86DHuIugIMLUlGe ZpAQ== X-Gm-Message-State: APjAAAVn44YMpc+B5rn2qsvgtDcuwcDlkymdfN8enTgq3nqmzDYBJlqe RwqXOHRIE2BMnoUudvH1SOC7c33p X-Google-Smtp-Source: APXvYqxgab2z6B/hzt+gZihlZcO6VApOVZ9hDekjyyX8rGF8x5LRiLei19Rv4yShryD+hN8qm0K2GQ== X-Received: by 2002:adf:f401:: with SMTP id g1mr13596874wro.129.1580718389336; Mon, 03 Feb 2020 00:26:29 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:28 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 5/6] hw/arm/raspi: Dynamically create machines based on the board revision Date: Mon, 3 Feb 2020 09:26:18 +0100 Message-Id: <20200203082619.7426-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 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 , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Igor Mammedov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We added tiny helpers extracting different values from the board revision, we can now create a full board based on its revision. The 'raspi-common' type is common to all raspi boards. Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/raspi.c | 93 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 656d834e07..12dc4d1486 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -44,12 +44,17 @@ static const struct { [C_BCM2837] = {TYPE_BCM2837}, }; -typedef struct RasPiState { +typedef struct RaspiMachineState { + /*< private >*/ + MachineState parent_obj; + /*< public >*/ BCM283XState soc; MemoryRegion ram; -} RasPiState; +} RaspiMachineState; typedef struct RaspiBoardInfo { + const char *name; + const char *desc; /* * Board revision codes: * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/ @@ -57,16 +62,32 @@ typedef struct RaspiBoardInfo { uint32_t board_rev; } RaspiBoardInfo; -enum { BOARD_PI2, BOARD_PI3 }; +typedef struct RaspiMachineClass { + /*< private >*/ + MachineClass parent_obj; + /*< public >*/ + const RaspiBoardInfo *config; +} RaspiMachineClass; + +#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") +#define RASPI_MACHINE(obj) \ + OBJECT_CHECK(RaspiMachineState, (obj), TYPE_RASPI_MACHINE) + +#define RASPI_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(RaspiMachineClass, (klass), TYPE_RASPI_MACHINE) +#define RASPI_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(RaspiMachineClass, (obj), TYPE_RASPI_MACHINE) static const RaspiBoardInfo raspi_boards[] = { - [BOARD_PI2] = { + .name = MACHINE_TYPE_NAME("raspi2"), + .desc = "Raspberry Pi 2B", .board_rev = 0xa21041, }, #ifdef TARGET_AARCH64 - [BOARD_PI3] = { + .name = MACHINE_TYPE_NAME("raspi3"), + .desc = "Raspberry Pi 3B", .board_rev = 0xa02082, }, #endif @@ -221,7 +242,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) static void raspi_init(MachineState *machine, const RaspiBoardInfo *config) { - RasPiState *s = g_new0(RasPiState, 1); + RaspiMachineState *s = RASPI_MACHINE(machine); int version = board_version(config); uint32_t vcram_size; DriveInfo *di; @@ -271,15 +292,22 @@ static void raspi_init(MachineState *machine, const RaspiBoardInfo *config) setup_boot(machine, version, machine->ram_size - vcram_size); } -static void raspi2_init(MachineState *machine) +static void raspi_machine_init(MachineState *machine) { - raspi_init(machine, &raspi_boards[BOARD_PI2]); + RaspiMachineClass *rmc = RASPI_MACHINE_GET_CLASS(machine); + + raspi_init(machine, rmc->config); } -static void raspi2_machine_init(MachineClass *mc) +static void raspi_machine_class_init(ObjectClass *oc, void *data) { - mc->desc = "Raspberry Pi 2"; - mc->init = raspi2_init; + MachineClass *mc = MACHINE_CLASS(oc); + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); + const RaspiBoardInfo *config = data; + + rmc->config = config; + mc->desc = config->desc; + mc->init = raspi_machine_init; mc->block_default_type = IF_SD; mc->no_parallel = 1; mc->no_floppy = 1; @@ -287,29 +315,32 @@ static void raspi2_machine_init(MachineClass *mc) mc->max_cpus = BCM283X_NCPUS; mc->min_cpus = BCM283X_NCPUS; mc->default_cpus = BCM283X_NCPUS; - mc->default_ram_size = 1 * GiB; + mc->default_ram_size = board_ram_size(config); mc->ignore_memory_transaction_failures = true; +} + +static const TypeInfo raspi_machine_type = { + .name = TYPE_RASPI_MACHINE, + .parent = TYPE_MACHINE, + .instance_size = sizeof(RaspiMachineState), + .class_size = sizeof(RaspiMachineClass), + .abstract = true, }; -DEFINE_MACHINE("raspi2", raspi2_machine_init) -#ifdef TARGET_AARCH64 -static void raspi3_init(MachineState *machine) +static void raspi_machine_types(void) { - raspi_init(machine, &raspi_boards[BOARD_PI3]); + int i; + + type_register_static(&raspi_machine_type); + for (i = 0; i < ARRAY_SIZE(raspi_boards); ++i) { + TypeInfo ti = { + .name = raspi_boards[i].name, + .parent = TYPE_RASPI_MACHINE, + .class_init = raspi_machine_class_init, + .class_data = (void *)&raspi_boards[i], + }; + type_register(&ti); + } } -static void raspi3_machine_init(MachineClass *mc) -{ - mc->desc = "Raspberry Pi 3"; - mc->init = raspi3_init; - mc->block_default_type = IF_SD; - mc->no_parallel = 1; - mc->no_floppy = 1; - mc->no_cdrom = 1; - mc->max_cpus = BCM283X_NCPUS; - mc->min_cpus = BCM283X_NCPUS; - mc->default_cpus = BCM283X_NCPUS; - mc->default_ram_size = 1 * GiB; -} -DEFINE_MACHINE("raspi3", raspi3_machine_init) -#endif +type_init(raspi_machine_types) From patchwork Mon Feb 3 08:26:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11362213 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73566138D for ; Mon, 3 Feb 2020 08:31:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4935E20658 for ; Mon, 3 Feb 2020 08:31:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LV0mTo7n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4935E20658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX8G-0000Xn-Mf for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Feb 2020 03:31:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34858) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyX43-0002Io-B2 for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyX42-0001DD-2T for qemu-devel@nongnu.org; Mon, 03 Feb 2020 03:26:39 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iyX40-00012R-8t; Mon, 03 Feb 2020 03:26:37 -0500 Received: by mail-wr1-x442.google.com with SMTP id y11so16727769wrt.6; Mon, 03 Feb 2020 00:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MG6q3ieTomJ3R/kt7cFMdsAQjzJf5NE+35h/33403yM=; b=LV0mTo7n1aOMIP09UJ0OAKahm83O/pyeedX5BLR7LcnczpaVSqeMOVFsf68Cpo1k/s 6n6rLQTAGne0/U2A3bgJ9qS1pNyU6i8GC6KK8x2jryuV3uHeDIpm55rLQizcKV5J6Zs6 wdmUwYXLzUj9fqZJq5C7yGDTeO0mO0UNS7bnJR7VIGmTg1MH/3LDys/2Pi211263wevG G/nRK6JEKC41Gkx4zML+32M0MTuOccw0vGr3ihYWkAGM4VqToTd38J574oBuzEOOR90H 5e0kd3G+Cu2mNRC7ySBMgP6otPG3IrF/vbTVJNTovScAEMecgrQogivdrRoF6jXrJSOh Hs3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MG6q3ieTomJ3R/kt7cFMdsAQjzJf5NE+35h/33403yM=; b=LlhHO92ko+gF2NFgfh1/Bp5zVc2/ekgbRfuhdlkTSDngHsnGcvKoHsyQnKEzMDcu8W XlqAypIoJnOrCnryIDcX+tqTTNH3e0C7o5H5iAqKh8PdDB7Eyxxjrt+MjsYLHklkcSwz IumYt7rbSglIKAavPrPTOHBJJN5v8Kl4Apm+0IDXLA+U/T7P3JyXFzqSX9oIQ+F+qtgm 4jcnNYh/yotLXDmObFn6lZeEGDr1BX0C4NZADR5lTZg6NYZFyqom0/Odeu0rPZa6v5Nf HSG1UmEDN+b9V0pdxFoUd2fAX7n2Mds88yCQtS9X00sO7Jsr/X4R01H0qw9cYXBGwdIp f1Pw== X-Gm-Message-State: APjAAAU3uPQKzT8QT42FYuYOneVZr8rWOv6OXM9e17BI/RB4Vav4CXDQ 3W569UPfZSU2MrV1NcbNDTKPz1q4 X-Google-Smtp-Source: APXvYqyiPMdNtY6zT+Sb5L8dKp1Ls0YJKOy6+avsITHQ7evnIQvu4VKBu2envb2AFuDlTRXbYut7gg== X-Received: by 2002:adf:d4c7:: with SMTP id w7mr14039937wrk.101.1580718390682; Mon, 03 Feb 2020 00:26:30 -0800 (PST) Received: from localhost.localdomain (162.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.162]) by smtp.gmail.com with ESMTPSA id w20sm22396778wmk.34.2020.02.03.00.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 00:26:30 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 6/6] hw/arm/raspi: Get the CPU core count from the revision code Date: Mon, 3 Feb 2020 09:26:19 +0100 Message-Id: <20200203082619.7426-7-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200203082619.7426-1-f4bug@amsat.org> References: <20200203082619.7426-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 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 , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Andrew Baumann , qemu-arm@nongnu.org, Igor Mammedov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The number of cores is tied to the SoC, and we already know how to extract the Chip ID from the revision code. Use it to determine the number of cores. Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/raspi.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 12dc4d1486..aff5d57261 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -39,9 +39,10 @@ enum BoardIdChip { static const struct { const char *soc_name; + int cores_count; } soc_config[] = { - [C_BCM2836] = {TYPE_BCM2836}, - [C_BCM2837] = {TYPE_BCM2837}, + [C_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, + [C_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, }; typedef struct RaspiMachineState { @@ -113,6 +114,11 @@ static const char *board_soc_name(const RaspiBoardInfo *config) return soc_config[board_chip_id(config)].soc_name; } +static int cpu_cores_count(const RaspiBoardInfo *config) +{ + return soc_config[board_chip_id(config)].cores_count; +} + static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { static const uint32_t smpboot[] = { @@ -312,9 +318,7 @@ static void raspi_machine_class_init(ObjectClass *oc, void *data) mc->no_parallel = 1; mc->no_floppy = 1; mc->no_cdrom = 1; - mc->max_cpus = BCM283X_NCPUS; - mc->min_cpus = BCM283X_NCPUS; - mc->default_cpus = BCM283X_NCPUS; + mc->default_cpus = mc->min_cpus = mc->max_cpus = cpu_cores_count(config); mc->default_ram_size = board_ram_size(config); mc->ignore_memory_transaction_failures = true; }