Skip to contentSkip to conversation

Update reserved memory for simple framebuffer

RFC PATCH New Michael Trimarchi 2 participants 6 messages Feb 19, 2020 – Feb 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Update reserved memory for simple framebuffer

Reserved memory for simple frame buffer should be created in a different way:

+ aliases {
+ display0 = &lcdif;
+ };
+
+ reserved-memory {

+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;

+
+ display_reserved: framebuffer at 86fa2000 {
+ reg = <0x86fa2000 0x80000>;
+ no-map;
+ };
+
+ };

We add a function to change the loaded dts and inject those information. I have added another patch for meson. Right now I'm testing on tinker-s board

Michael Trimarchi (2):
common: fdt: Add a function for reserving memory without kernel linear
mapping
video: meson: Use reserving memory function without kernel linear
mapping

 common/fdt_support.c            | 40 +++++++++++++++++++++++++++++++++
 drivers/video/meson/meson_vpu.c |  6 ++---
 include/fdt_support.h           | 11 +++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH 1/2 common: fdt: Add a function for reserving memory without kernel linear mapping

We need to reserve memory and not put in kernel linear mapping. This avoid problem during memory remapping from the simple frame buffer in linux kernel

---
 common/fdt_support.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h | 11 +++++++++++
 2 files changed, 51 insertions(+)
common/fdt_support.c +40 -0
index 02cf5c6241..a3662f4358 100644
@@ -410,6 +410,46 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size,
 	return p - (char *)buf;
 }
 
+int fdt_fixup_reserved_memory(void *blob, const char *area, u64 start[], u64 size[])
+{
+	int offs, len;
+	const char *subpath;
+	const char *path = "/reserved-memory";
+	fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(blob, 0));
+	fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(blob, 0));
+	u8 temp[16]; /* Up to 64-bit address + 64-bit size */
+
+	offs = fdt_path_offset(blob, path);
+	if (offs < 0) {
+		debug("Node %s not found\n", path);
+		path = "/";
+		subpath = "reserved-memory";
+		offs = fdt_path_offset(blob, path);
+		offs = fdt_add_subnode(blob, offs, subpath);
+		if (offs < 0) {
+			printf("Could not create %s%s node.\n", path, subpath);
+			return -1;
+		}
+		path = "/reserved-memory";
+		offs = fdt_path_offset(blob, path);
+
+		fdt_setprop(blob, offs, "#address-cells", &address_cells, sizeof(address_cells));
+		fdt_setprop(blob, offs, "#size-cells", &size_cells, sizeof(size_cells));
+		fdt_setprop(blob, offs, "ranges", NULL, 0);
+	}
+
+	offs = fdt_add_subnode(blob, offs, area ? : "private");
+	if (offs < 0) {
+		printf("Could not create %s%s node.\n", path, subpath);
+		return -1;
+	}
+
+	fdt_setprop(blob, offs, "no-map", NULL, 0);
+	len = fdt_pack_reg(blob, temp, start, size, 1);
+	fdt_setprop(blob, offs, "reg", temp, len);
+	return 0;
+}
+
 #if CONFIG_NR_DRAM_BANKS > 4
 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS
 #else
include/fdt_support.h +11 -0
index ba14acd7f6..7c8a280f53 100644
@@ -93,6 +93,17 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
  */
 int fdt_fixup_memory(void *blob, u64 start, u64 size);
 
+/**
+ * Setup the memory reserved node in the DT. Creates one if none was existing before.
+ *
+ * @param blob		FDT blob to update
+ * @param area		Reserved area name
+ * @param start		Begin of DRAM mapping in physical memory
+ * @param size		Size of the single memory bank
+ * @return 0 if ok, or -1 or -FDT_ERR_... on error
+ */
+int fdt_fixup_reserved_memory(void *blob, const char *area, u64 start[], u64 size[]);
+
 /**
  * Fill the DT memory node with multiple memory banks.
  * Creates the node if none was existing before.
Signature · 1 line
2.17.1
#3 lore raw

RFC PATCH 2/2 video: meson: Use reserving memory function without kernel linear mapping

In reply to Michael Trimarchi

Memory reserved for the simple framebuffer should not be used and part of memory linear mapping

---
 drivers/video/meson/meson_vpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/meson/meson_vpu.c +3 -3
index 4eb66398d0..134e011b82 100644
@@ -173,9 +173,9 @@ static void meson_vpu_setup_simplefb(void *fdt)
 	 * at the end of the RAM and we strip this portion from the kernel
 	 * allowed region
 	 */
-	mem_start = gd->bd->bi_dram[0].start;
-	mem_size = gd->bd->bi_dram[0].size - meson_fb.fb_size;
-	ret = fdt_fixup_memory_banks(fdt, &mem_start, &mem_size, 1);
+	mem_start = meson_fb.base;
+	mem_size = meson_fb.fb_size;
+	ret = fdt_fixup_reserved_memory(blob, "display_reserved", &mem_start, &mem_size);
 	if (ret) {
 		eprintf("Cannot setup simplefb: Error reserving memory\n");
 		return;
Signature · 1 line
2.17.1
#2 lore raw

RFC PATCH 1/2 common: fdt: Add a function for reserving memory without kernel linear mapping

In reply to Michael Trimarchi

Hi Michael,

Quoted 10 lines · Michael Trimarchi

We need to reserve memory and not put in kernel linear mapping. This avoid problem during memory remapping from the simple frame buffer in linux kernel

---
 common/fdt_support.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h | 11 +++++++++++
 2 files changed, 51 insertions(+)

nits below

Quoted 14 lines
common/fdt_support.c +5 -0
index 02cf5c6241..a3662f4358 100644
@@ -410,6 +410,46 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size,
        return p - (char *)buf;
 }
 
+int fdt_fixup_reserved_memory(void *blob, const char *area, u64 start[], u64 size[])
+{
+       int offs, len;
+       const char *subpath;
+       const char *path = "/reserved-memory";

common/fdt_support.c static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, · line 427

Quoted 10 lines
common/fdt_support.c +10 -0
+       fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(blob, 0));
+       fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(blob, 0));
+       u8 temp[16]; /* Up to 64-bit address + 64-bit size */
+
+       offs = fdt_path_offset(blob, path);
+       if (offs < 0) {
+               debug("Node %s not found\n", path);
+               path = "/";
+               subpath = "reserved-memory";
+               offs = fdt_path_offset(blob, path);

This is always 0 by definition.

common/fdt_support.c static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, · line 431

Quoted 4 lines
common/fdt_support.c +4 -0
+               offs = fdt_add_subnode(blob, offs, subpath);
+               if (offs < 0) {
+                       printf("Could not create %s%s node.\n", path, subpath);
+                       return -1;

This is -EPERM. I think it would be better to return ofs.

common/fdt_support.c static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, · line 444

Quoted 13 lines
common/fdt_support.c +13 -0
+               }
+               path = "/reserved-memory";
+               offs = fdt_path_offset(blob, path);
+
+               fdt_setprop(blob, offs, "#address-cells", &address_cells, sizeof(address_cells));
+               fdt_setprop(blob, offs, "#size-cells", &size_cells, sizeof(size_cells));
+               fdt_setprop(blob, offs, "ranges", NULL, 0);
+       }
+
+       offs = fdt_add_subnode(blob, offs, area ? : "private");
+       if (offs < 0) {
+               printf("Could not create %s%s node.\n", path, subpath);
+               return -1;

and here

common/fdt_support.c static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, · line 449

Quoted 5 lines
common/fdt_support.c +5 -0
+       }
+
+       fdt_setprop(blob, offs, "no-map", NULL, 0);
+       len = fdt_pack_reg(blob, temp, start, size, 1);
+       fdt_setprop(blob, offs, "reg", temp, len);

blank line before return

Quoted 12 lines
common/fdt_support.c +3 -0
+       return 0;
+}
+
 #if CONFIG_NR_DRAM_BANKS > 4
 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS
 #else
include/fdt_support.h +0 -0
index ba14acd7f6..7c8a280f53 100644
@@ -93,6 +93,17 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat,
  */

include/fdt_support.h void do_fixup_by_compat_u32(void *fdt, const char *compat, · line 103

Quoted 10 lines
include/fdt_support.h +8 -0
 int fdt_fixup_memory(void *blob, u64 start, u64 size);
 
+/**
+ * Setup the memory reserved node in the DT. Creates one if none was existing before.
+ *
+ * @param blob         FDT blob to update
+ * @param area         Reserved area name
+ * @param start                Begin of DRAM mapping in physical memory
+ * @param size         Size of the single memory bank
+ * @return 0 if ok, or -1 or -FDT_ERR_... on error

check this

Quoted 9 lines
include/fdt_support.h +3 -1
+ */
+int fdt_fixup_reserved_memory(void *blob, const char *area, u64 start[], u64 size[]);
+
 /**
  * Fill the DT memory node with multiple memory banks.
  * Creates the node if none was existing before.
--

2.17.1

Regards,
Simon

#4 lore raw

RFC PATCH 2/2 video: meson: Use reserving memory function without kernel linear mapping

In reply to Michael Trimarchi

Hi Michael,

Quoted 8 lines · Michael Trimarchi

Memory reserved for the simple framebuffer should not be used and part of memory linear mapping

---
 drivers/video/meson/meson_vpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Is there a binding file for this? Please add it to a patch.

Quoted 6 lines
drivers/video/meson/meson_vpu.c +0 -0
index 4eb66398d0..134e011b82 100644

drivers/video/meson/meson_vpu.c static void meson_vpu_setup_simplefb(void *fdt) · line 178

Quoted 9 lines
drivers/video/meson/meson_vpu.c +3 -3
@@ -173,9 +173,9 @@ static void meson_vpu_setup_simplefb(void *fdt)
         * at the end of the RAM and we strip this portion from the kernel
         * allowed region
         */
-       mem_start = gd->bd->bi_dram[0].start;
-       mem_size = gd->bd->bi_dram[0].size - meson_fb.fb_size;
-       ret = fdt_fixup_memory_banks(fdt, &mem_start, &mem_size, 1);
+       mem_start = meson_fb.base;
+       mem_size = meson_fb.fb_size;
+       ret = fdt_fixup_reserved_memory(blob, "display_reserved", &mem_start, &mem_size);

Odd that this uses underscore...normally bindings use hyphen.

Quoted 6 lines
drivers/video/meson/meson_vpu.c +0 -1
        if (ret) {
                eprintf("Cannot setup simplefb: Error reserving memory\n");
                return;
--

2.17.1

Regards,
Simon

#5 lore raw

RFC PATCH 2/2 video: meson: Use reserving memory function without kernel linear mapping

Hi

Quoted 9 lines · Simon Glass

Hi Michael,

Quoted 4 lines · Michael Trimarchi

Memory reserved for the simple framebuffer should not be used and part of memory linear mapping

Quoted 7 lines
Quoted 4 lines
---
 drivers/video/meson/meson_vpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Is there a binding file for this? Please add it to a patch.

This is an example how to use it. I need to repost it. There is a compilation issue
later. I need only to have some feedback from Neil because I can not test this board

Quoted 18 lines
Quoted 6 lines
drivers/video/meson/meson_vpu.c +0 -0
index 4eb66398d0..134e011b82 100644

drivers/video/meson/meson_vpu.c static void meson_vpu_setup_simplefb(void *fdt) · line 178

Quoted 9 lines
drivers/video/meson/meson_vpu.c +3 -3
@@ -173,9 +173,9 @@ static void meson_vpu_setup_simplefb(void *fdt)
         * at the end of the RAM and we strip this portion from the kernel
         * allowed region
         */
-       mem_start = gd->bd->bi_dram[0].start;
-       mem_size = gd->bd->bi_dram[0].size - meson_fb.fb_size;
-       ret = fdt_fixup_memory_banks(fdt, &mem_start, &mem_size, 1);
+       mem_start = meson_fb.base;
+       mem_size = meson_fb.fb_size;
+       ret = fdt_fixup_reserved_memory(blob, "display_reserved", &mem_start, &mem_size);

Odd that this uses underscore...normally bindings use hyphen.

Will fix. There are few things that I need to change here because sunxi, meson use simpleframe buffer
but they have some code duplication

Micheal

Quoted 9 lines
Quoted 6 lines
drivers/video/meson/meson_vpu.c +0 -1
        if (ret) {
                eprintf("Cannot setup simplefb: Error reserving memory\n");
                return;
--

2.17.1

Regards,
Simon