public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ramon Fried <ramon.fried@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] snapdragon: Add DRAM detection & FDT fixup
Date: Sun, 22 Jul 2018 21:46:05 +0300	[thread overview]
Message-ID: <20180722184606.12507-1-ramon.fried@gmail.com> (raw)

Fixup the Linux FDT with the detection of onboard DRAM as
provided by SBL (Secondary boot loader) by reading
the shared-memory region.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---
 arch/arm/mach-snapdragon/Makefile            |  1 +
 arch/arm/mach-snapdragon/dram.c              | 97 ++++++++++++++++++++
 arch/arm/mach-snapdragon/include/mach/dram.h | 12 +++
 3 files changed, 110 insertions(+)
 create mode 100644 arch/arm/mach-snapdragon/dram.c
 create mode 100644 arch/arm/mach-snapdragon/include/mach/dram.h

diff --git a/arch/arm/mach-snapdragon/Makefile b/arch/arm/mach-snapdragon/Makefile
index 1d35fea912..f375d07d03 100644
--- a/arch/arm/mach-snapdragon/Makefile
+++ b/arch/arm/mach-snapdragon/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_TARGET_DRAGONBOARD410C) += sysmap-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-snapdragon.o
 obj-y += clock-snapdragon.o
+obj-y += dram.o
diff --git a/arch/arm/mach-snapdragon/dram.c b/arch/arm/mach-snapdragon/dram.c
new file mode 100644
index 0000000000..2aeefa56ca
--- /dev/null
+++ b/arch/arm/mach-snapdragon/dram.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onboard memory detection for Snapdragon boards
+ *
+ * (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com>
+ *
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+#include <asm/arch/dram.h>
+
+#define SMEM_USABLE_RAM_PARTITION_TABLE 402
+#define RAM_PART_NAME_LENGTH            16
+#define RAM_NUM_PART_ENTRIES            32
+#define CATEGORY_SDRAM 0x0E
+#define TYPE_SYSMEM 0x01
+
+struct smem_ram_ptable_hdr {
+	u32 magic[2];
+	u32 version;
+	u32 reserved;
+	u32 len;
+} __attribute__ ((__packed__));
+
+struct smem_ram_ptn {
+	char name[RAM_PART_NAME_LENGTH];
+	u64 start;
+	u64 size;
+	u32 attr;
+	u32 category;
+	u32 domain;
+	u32 type;
+	u32 num_partitions;
+	u32 reserved[3];
+} __attribute__ ((__packed__));
+
+struct smem_ram_ptable {
+	struct smem_ram_ptable_hdr hdr;
+	u32 reserved;     /* Added for 8 bytes alignment of header */
+	struct smem_ram_ptn parts[RAM_NUM_PART_ENTRIES];
+} __attribute__ ((__packed__));
+
+#ifndef MEMORY_BANKS_MAX
+#define MEMORY_BANKS_MAX 4
+#endif
+
+int msm_fixup_memory(void *blob)
+{
+	u64 bank_start[MEMORY_BANKS_MAX];
+	u64 bank_size[MEMORY_BANKS_MAX];
+	size_t size;
+	int i;
+	int count = 0;
+	struct udevice *smem;
+	int ret;
+	struct smem_ram_ptable *ram_ptable;
+	struct smem_ram_ptn *p;
+
+	ret = uclass_get_device_by_name(UCLASS_SMEM, "smem", &smem);
+	if (ret < 0) {
+		printf("Failed to find SMEM node. Check device tree\n");
+		return 0;
+	}
+
+	ram_ptable = smem_get(smem, -1, SMEM_USABLE_RAM_PARTITION_TABLE, &size);
+
+	if (!ram_ptable) {
+		printf("Failed to find SMEM partition.\n");
+		return -ENODEV;
+	}
+
+	/* Check validy of RAM */
+	for (i = 0; i < RAM_NUM_PART_ENTRIES; i++) {
+		p = &ram_ptable->parts[i];
+		if (p->category == CATEGORY_SDRAM && p->type == TYPE_SYSMEM) {
+			bank_start[count] = p->start;
+			bank_size[count] = p->size;
+			debug("Detected memory bank %u: start: 0x%llx size: 0x%llx\n",
+					count, p->start, p->size);
+			count++;
+		}
+	}
+
+	if (!count) {
+		printf("Failed to detect any memory bank\n");
+		return -ENODEV;
+	}
+
+	ret = fdt_fixup_memory_banks(blob, bank_start, bank_size, count);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
diff --git a/arch/arm/mach-snapdragon/include/mach/dram.h b/arch/arm/mach-snapdragon/include/mach/dram.h
new file mode 100644
index 0000000000..0a9eedda41
--- /dev/null
+++ b/arch/arm/mach-snapdragon/include/mach/dram.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Snapdragon DRAM
+ * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#ifndef DRAM_H
+#define DRAM_H
+
+int msm_fixup_memory(void *blob);
+
+#endif
-- 
2.18.0

             reply	other threads:[~2018-07-22 18:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-22 18:46 Ramon Fried [this message]
2018-07-22 18:46 ` [U-Boot] [PATCH 2/2] db410c: Fixup DRAM Ramon Fried
2018-07-30 11:18 ` [U-Boot] [U-Boot, 1/2] snapdragon: Add DRAM detection & FDT fixup Tom Rini
2018-07-30 11:29   ` Ramon Fried
2018-07-31  9:31     ` Ramon Fried

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180722184606.12507-1-ramon.fried@gmail.com \
    --to=ramon.fried@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox