[PATCH v2 5/6] add handoff-data support

2024-05-16 Thread Ahmad Fatoum
From: Sascha Hauer 

We need to pass data from the PBL to barebox proper. Right now we do
this with passing the data in registers which is quite limited. As the
amount of information that has to be passed increases it's time to
overcome this limitation.

With this patch we introduce handoff-data which is a linked list of
memory blobs that can be passed from PBL to barebox proper.

The data format is done in a way that enables us to compile the list
entries and the data into the binary, so that no memory allocations
are needed in PBL.

Link: https://lore.barebox.org/20240430105310.3149242-3-s.ha...@pengutronix.de
Signed-off-by: Sascha Hauer 
Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - move header into pbl/ subdirectory
  - implement __handoff_data_size with head as argument
  - call new request_barebox_region instead of request_sdram_region
---
 include/pbl/handoff-data.h |  53 ++
 pbl/Makefile   |   1 +
 pbl/handoff-data.c | 194 +
 3 files changed, 248 insertions(+)
 create mode 100644 include/pbl/handoff-data.h
 create mode 100644 pbl/handoff-data.c

diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
new file mode 100644
index ..7f883421df16
--- /dev/null
+++ b/include/pbl/handoff-data.h
@@ -0,0 +1,53 @@
+#ifndef __PBL_HANDOFF_DATA_H
+#define __PBL_HANDOFF_DATA_H
+
+#include 
+
+struct handoff_data {
+   struct list_head entries;
+};
+
+#define HANDOFF_DATA_BAREBOX(n)(0x28061971 + (n))
+#define HANDOFF_DATA_INTERNAL_DT   HANDOFF_DATA_BAREBOX(0)
+#define HANDOFF_DATA_INTERNAL_DT_Z HANDOFF_DATA_BAREBOX(1)
+#define HANDOFF_DATA_EXTERNAL_DT   HANDOFF_DATA_BAREBOX(2)
+#define HANDOFF_DATA_BOARDDATA HANDOFF_DATA_BAREBOX(3)
+
+#define HANDOFF_DATA_BOARD(n)  (0x951726fb + (n))
+
+struct handoff_data_entry {
+   struct list_head list;
+   void *data;
+   size_t size;
+   unsigned int cookie;
+#define HANDOFF_DATA_FLAG_NO_COPY  BIT(0)
+   unsigned int flags;
+};
+
+#define handoff_data_add_flags(_cookie, _data, _size, _flags)  \
+   do {\
+   static struct handoff_data_entry hde;   \
+   hde.cookie = _cookie;   \
+   hde.data = _data;   \
+   hde.size = _size;   \
+   hde.flags = _flags; \
+   \
+   handoff_data_add_entry(&hde);   \
+   } while (0);
+
+#define handoff_data_add(_cookie, _data, _size)\
+   handoff_data_add_flags((_cookie), (_data), (_size), 0)
+
+void handoff_data_add_entry(struct handoff_data_entry *entry);
+void handoff_data_move(void *dest);
+void handoff_data_set(struct handoff_data *handoff);
+void *handoff_data_get_entry(unsigned int cookie, size_t *size);
+int handoff_data_show(void);
+
+size_t __handoff_data_size(const struct handoff_data *hd);
+static inline size_t handoff_data_size(void)
+{
+   return __handoff_data_size(NULL);
+}
+
+#endif /* __PBL_HANDOFF_DATA_H */
diff --git a/pbl/Makefile b/pbl/Makefile
index f6e98e78be3f..79837c56114a 100644
--- a/pbl/Makefile
+++ b/pbl/Makefile
@@ -8,3 +8,4 @@ pbl-y += string.o
 pbl-y += decomp.o
 pbl-$(CONFIG_LIBFDT) += fdt.o
 pbl-$(CONFIG_PBL_CONSOLE) += console.o
+obj-pbl-y += handoff-data.o
diff --git a/pbl/handoff-data.c b/pbl/handoff-data.c
new file mode 100644
index ..e6745797c038
--- /dev/null
+++ b/pbl/handoff-data.c
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static struct handoff_data *handoff_data = (void *)-1;
+
+static struct handoff_data *handoff_data_get(void)
+{
+   static struct handoff_data __handoff_data;
+
+   /*
+* Sometimes the PBL copies itself to some other location and is
+* re-entered at that location. For example on some i.MX SoCs we have
+* to move the PBL out of the SRAM (which will be occupied by the TF-A
+* later). We force the handoff_data variable into the data segment.
+* When moving the PBL somewhere else with handoff_data set we move the
+* content of the variable with it and thus find it to have the correct
+* value in the new PBL.
+*/
+   if (handoff_data == (void *)-1) {
+   handoff_data = &__handoff_data;
+   INIT_LIST_HEAD(&handoff_data->entries);
+   }
+
+   return handoff_data;
+}
+
+/**
+ * handoff_data_set - set the handoff data to be at a specified pointer
+ * @handoff: the place where the handoff data is
+ *
+ * This sets the handoff data to @handoff. To be used by barebox proper
+ * to pass the place where the handoff data has been placed by the PBL.
+ */
+void handoff_data_set(struct handoff_data *hand

[PATCH v2 6/6] ARM: pass handoff data from PBL to proper

2024-05-16 Thread Ahmad Fatoum
From: Sascha Hauer 

Use newly introduced handoff data to pass data from PBL to barebox
proper. This will allow us later to pass more SoC and/or board specific
data from PBL to barebox proper.

Link: https://lore.barebox.org/20240430105310.3149242-4-s.ha...@pengutronix.de
Signed-off-by: Sascha Hauer 
Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - delete no longer used arm_mem_boarddata()
  - in PBL, add board data before computing size, so it's taken into
account
  - in barebox proper, fix arm_mem_barebox_image() to take account of
handoff data size
  - support NULL boarddata passed in by PBL entry point. This is
possibly useful for boards that have board data in ROM that they
want to pass in a custom manner
---
 arch/arm/cpu/start.c   | 74 --
 arch/arm/cpu/uncompress.c  | 36 +--
 arch/arm/include/asm/barebox-arm.h | 24 ++
 3 files changed, 66 insertions(+), 68 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 8461184db467..2158edafa4a9 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,10 +39,9 @@ static unsigned long barebox_boarddata_size;
 
 const struct barebox_boarddata *barebox_get_boarddata(void)
 {
-   if (!barebox_boarddata || !blob_is_arm_boarddata(barebox_boarddata))
-   return NULL;
+   size_t size;
 
-   return barebox_boarddata;
+   return handoff_data_get_entry(HANDOFF_DATA_BOARDDATA, &size);
 }
 
 u32 barebox_arm_machine(void)
@@ -56,19 +56,24 @@ void *barebox_arm_boot_dtb(void)
int ret = 0;
struct barebox_boarddata_compressed_dtb *compressed_dtb;
static void *boot_dtb;
+   void *blob;
+   size_t size;
 
if (boot_dtb)
return boot_dtb;
 
-   if (barebox_boarddata && blob_is_fdt(barebox_boarddata)) {
-   pr_debug("%s: using barebox_boarddata\n", __func__);
-   return barebox_boarddata;
-   }
+   blob = handoff_data_get_entry(HANDOFF_DATA_INTERNAL_DT, &size);
+   if (blob)
+   return blob;
 
-   if (!fdt_blob_can_be_decompressed(barebox_boarddata))
+   blob = handoff_data_get_entry(HANDOFF_DATA_INTERNAL_DT_Z, &size);
+   if (!blob)
return NULL;
 
-   compressed_dtb = barebox_boarddata;
+   if (!fdt_blob_can_be_decompressed(blob))
+   return NULL;
+
+   compressed_dtb = blob;
 
pr_debug("%s: using compressed_dtb\n", __func__);
 
@@ -94,18 +99,6 @@ void *barebox_arm_boot_dtb(void)
return boot_dtb;
 }
 
-static inline unsigned long arm_mem_boarddata(unsigned long membase,
- unsigned long endmem,
- unsigned long size)
-{
-   unsigned long mem;
-
-   mem = arm_mem_barebox_image(membase, endmem, arm_barebox_size);
-   mem -= ALIGN(size, 64);
-
-   return mem;
-}
-
 unsigned long arm_mem_ramoops_get(void)
 {
return arm_mem_ramoops(arm_stack_top);
@@ -143,10 +136,9 @@ __noreturn __prereloc void barebox_non_pbl_start(unsigned 
long membase,
 {
unsigned long endmem = membase + memsize;
unsigned long malloc_start, malloc_end;
-   unsigned long barebox_size = barebox_image_size + MAX_BSS_SIZE;
-   unsigned long barebox_base = arm_mem_barebox_image(membase,
-  endmem,
-  barebox_size);
+   unsigned long barebox_base = arm_mem_barebox_image(membase, endmem,
+  barebox_image_size,
+  boarddata);
 
if (IS_ENABLED(CONFIG_CPU_V7))
armv7_hyp_install();
@@ -164,37 +156,9 @@ __noreturn __prereloc void barebox_non_pbl_start(unsigned 
long membase,
arm_membase = membase;
arm_endmem = endmem;
arm_stack_top = arm_mem_stack_top(endmem);
-   arm_barebox_size = barebox_size;
+   arm_barebox_size = barebox_image_size + MAX_BSS_SIZE;
malloc_end = barebox_base;
 
-   if (boarddata) {
-   uint32_t totalsize = 0;
-   const char *name;
-
-   if (blob_is_fdt(boarddata)) {
-   totalsize = get_unaligned_be32(boarddata + 4);
-   name = "DTB";
-   } else if (blob_is_compressed_fdt(boarddata)) {
-   struct barebox_boarddata_compressed_dtb *bd = boarddata;
-   totalsize = bd->datalen + sizeof(*bd);
-   name = "Compressed DTB";
-   } else if (blob_is_arm_boarddata(boarddata)) {
-   totalsize = sizeof(struct barebox_arm_boarddata);
-   name = "machine type";
-   }
-
-   if

[PATCH v2 3/6] ARM: cpu: start: register barebox memory area

2024-05-16 Thread Ahmad Fatoum
By registering the barebox area, we ensure that functions like
memory_bank_first_find_space() skip over the memory area barebox uses
for itself.

The OS can still reclaim this area once barebox has shutdown.

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - new patch
---
 arch/arm/cpu/start.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index a73224bab930..4f68119d5089 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -219,6 +219,8 @@ __noreturn __prereloc void barebox_non_pbl_start(unsigned 
long membase,
pr_debug("initializing malloc pool at 0x%08lx (size 0x%08lx)\n",
malloc_start, malloc_end - malloc_start);
 
+   register_barebox_area(barebox_base, endmem - barebox_base);
+
kasan_init(membase, memsize, malloc_start - (memsize >> 
KASAN_SHADOW_SCALE_SHIFT));
 
mem_malloc_init((void *)malloc_start, (void *)malloc_end - 1);
-- 
2.39.2




[PATCH v2 1/6] memory: add support for requesting barebox area as a whole

2024-05-16 Thread Ahmad Fatoum
barebox-specific code and data is normally located at the end of
early-known memory. To ensure it's not overwritten, parts of it are
reserved with request_sdram_region at different places.

Gaps in the reservation lead to multiple issues in the past.
So for documentation purposes and to avoid functiosn like
memory_bank_first_find_space finding vacant area where there isn't,
allow architectures call register_barebox_area to do one full
SDRAM request for the area.

Region requests for subsets of this area will be switched in the
follow-up commit to use the new request_barebox_region, which allocates
a subregion if it lies inside a registered barebox area and defers
to request_sdram_region otherwise.

The motivation for this patch is that with the addition of handoff data,
doing separate memory reservation for every accounting structure (cookie
and linked list) in addition to the data could make iomem output a bit
unwieldy, but we really want to avoid anyone else overwriting it.

While at it, we also rename the regions for barebox code and bss to be
more descriptive.

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - new patch
---
 common/memory.c  | 38 --
 include/memory.h |  6 ++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 583843cc34c0..8e68b5e8bb20 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -57,6 +57,40 @@ void mem_malloc_init(void *start, void *end)
mem_malloc_initialized = 1;
 }
 
+static struct resource *barebox_res;
+static resource_size_t barebox_start;
+static resource_size_t barebox_size;
+
+void register_barebox_area(resource_size_t start,
+  resource_size_t size)
+{
+   barebox_start = start,
+   barebox_size = size;
+}
+
+static int mem_register_barebox(void)
+{
+   if (barebox_start && barebox_size)
+   barebox_res = request_sdram_region("barebox", barebox_start,
+  barebox_size);
+   return 0;
+}
+postmem_initcall(mem_register_barebox);
+
+struct resource *request_barebox_region(const char *name,
+   resource_size_t start,
+   resource_size_t size)
+{
+   resource_size_t end = start + size - 1;
+
+   if (barebox_res && barebox_res->start <= start &&
+   end <= barebox_res->end)
+   return __request_region(barebox_res, start, end,
+   name, IORESOURCE_MEM);
+
+   return request_sdram_region(name, start, size);
+}
+
 static int mem_malloc_resource(void)
 {
 #if !defined __SANDBOX__
@@ -69,7 +103,7 @@ static int mem_malloc_resource(void)
request_sdram_region("malloc space",
malloc_start,
malloc_end - malloc_start + 1);
-   request_sdram_region("barebox",
+   request_sdram_region("barebox code",
(unsigned long)&_stext,
(unsigned long)&_etext -
(unsigned long)&_stext);
@@ -77,7 +111,7 @@ static int mem_malloc_resource(void)
(unsigned long)&_sdata,
(unsigned long)&_edata -
(unsigned long)&_sdata);
-   request_sdram_region("bss",
+   request_sdram_region("barebox bss",
(unsigned long)&__bss_start,
(unsigned long)&__bss_stop -
(unsigned long)&__bss_start);
diff --git a/include/memory.h b/include/memory.h
index d8691972ec9b..571effd3b0d6 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -61,4 +61,10 @@ static inline u64 memory_sdram_size(unsigned int cols,
return (u64)banks * width << (rows + cols);
 }
 
+void register_barebox_area(resource_size_t start, resource_size_t size);
+
+struct resource *request_barebox_region(const char *name,
+   resource_size_t start,
+   resource_size_t size);
+
 #endif
-- 
2.39.2




[PATCH v2 2/6] treewide: use request_barebox_region for possible barebox memory regions

2024-05-16 Thread Ahmad Fatoum
This is a prerequisite for allowing architectures to call
register_barebox_area() to register the whole barebox region.

No functional change (yet).

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - new patch
---
 arch/arm/cpu/cpu.c  | 2 +-
 arch/arm/cpu/mmu_32.c   | 8 
 arch/arm/cpu/mmu_64.c   | 4 ++--
 arch/arm/cpu/start.c| 2 +-
 arch/arm/mach-imx/scratch.c | 2 +-
 arch/mips/lib/cpu-probe.c   | 2 +-
 arch/powerpc/mach-mpc5xxx/cpu.c | 2 +-
 arch/powerpc/mach-mpc85xx/cpu.c | 2 +-
 arch/riscv/boot/start.c | 4 ++--
 arch/riscv/cpu/core.c   | 2 +-
 common/memory.c | 6 +++---
 fs/pstore/ram_core.c| 2 +-
 12 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c
index 5f1ffe9a3c76..b00e9e51e5ea 100644
--- a/arch/arm/cpu/cpu.c
+++ b/arch/arm/cpu/cpu.c
@@ -102,7 +102,7 @@ static int arm_request_stack(void)
if (efi_is_payload())
return 0;
 
-   if (!request_sdram_region("stack", arm_stack_top - STACK_SIZE, 
STACK_SIZE))
+   if (!request_barebox_region("stack", arm_stack_top - STACK_SIZE, 
STACK_SIZE))
pr_err("Error: Cannot request SDRAM region for stack\n");
 
return 0;
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 3a8d025ecdee..24d83d933661 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -390,7 +390,7 @@ static void create_vector_table(unsigned long adr)
void *vectors;
u32 *pte;
 
-   vectors_sdram = request_sdram_region("vector table", adr, PAGE_SIZE);
+   vectors_sdram = request_barebox_region("vector table", adr, PAGE_SIZE);
if (vectors_sdram) {
/*
 * The vector table address is inside the SDRAM physical
@@ -486,7 +486,7 @@ static void create_guard_page(void)
return;
 
guard_page = arm_mem_guard_page_get();
-   request_sdram_region("guard page", guard_page, PAGE_SIZE);
+   request_barebox_region("guard page", guard_page, PAGE_SIZE);
remap_range((void *)guard_page, PAGE_SIZE, MAP_FAULT);
 
pr_debug("Created guard page\n");
@@ -535,8 +535,8 @@ void __mmu_init(bool mmu_on)
struct memory_bank *bank;
uint32_t *ttb = get_ttb();
 
-   if (!request_sdram_region("ttb", (unsigned long)ttb,
- ARM_EARLY_PAGETABLE_SIZE))
+   if (!request_barebox_region("ttb", (unsigned long)ttb,
+   ARM_EARLY_PAGETABLE_SIZE))
/*
 * This can mean that:
 * - the early MMU code has put the ttb into a place
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 71c0d8930e63..7c7834201b65 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -219,7 +219,7 @@ static void create_guard_page(void)
return;
 
guard_page = arm_mem_guard_page_get();
-   request_sdram_region("guard page", guard_page, PAGE_SIZE);
+   request_barebox_region("guard page", guard_page, PAGE_SIZE);
remap_range((void *)guard_page, PAGE_SIZE, MAP_FAULT);
 
pr_debug("Created guard page\n");
@@ -233,7 +233,7 @@ void __mmu_init(bool mmu_on)
uint64_t *ttb = get_ttb();
struct memory_bank *bank;
 
-   if (!request_sdram_region("ttb", (unsigned long)ttb,
+   if (!request_barebox_region("ttb", (unsigned long)ttb,
  ARM_EARLY_PAGETABLE_SIZE))
/*
 * This can mean that:
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 2adc60fa8831..a73224bab930 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -134,7 +134,7 @@ EXPORT_SYMBOL_GPL(arm_mem_membase_get);
 static int barebox_memory_areas_init(void)
 {
if(barebox_boarddata)
-   request_sdram_region("board data", (unsigned 
long)barebox_boarddata,
+   request_barebox_region("board data", (unsigned 
long)barebox_boarddata,
 barebox_boarddata_size);
 
if (IS_ENABLED(CONFIG_KASAN))
diff --git a/arch/arm/mach-imx/scratch.c b/arch/arm/mach-imx/scratch.c
index 60d15a4f1a33..002b499fab3a 100644
--- a/arch/arm/mach-imx/scratch.c
+++ b/arch/arm/mach-imx/scratch.c
@@ -95,7 +95,7 @@ const struct optee_header *imx_scratch_get_optee_hdr(void)
 
 static int imx8m_reserve_scratch_area(void)
 {
-   return PTR_ERR_OR_ZERO(request_sdram_region("scratch area",
+   return PTR_ERR_OR_ZERO(request_barebox_region("scratch area",
(ulong)arm_mem_scratch_get(),
sizeof(struct imx_scratch_space)));
 }
diff --git a/arch/mips/lib/cpu-probe.c b/arch/mips/lib/cpu-probe.c
index fc202815973f..ccb27a81497f 100644
--- a/arch/mips/lib/cpu-probe.c
+++ b/arch/mips/lib/cpu-probe.c
@@ -231,7 +231,7 @@ unsigned long mips_stack_top;
 
 static int mips_request_stack(void)
 {
-

[PATCH v2 4/6] ARM: move blob_is_arm_boarddata() to include

2024-05-16 Thread Ahmad Fatoum
From: Sascha Hauer 

Reviewed-by: Ahmad Fatoum 
Link: https://lore.barebox.org/20240430105310.3149242-2-s.ha...@pengutronix.de
Signed-off-by: Sascha Hauer 
Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - no change
---
 arch/arm/cpu/start.c   | 7 ---
 arch/arm/include/asm/barebox-arm.h | 7 +++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 4f68119d5089..8461184db467 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -36,13 +36,6 @@ static unsigned long arm_membase;
 static void *barebox_boarddata;
 static unsigned long barebox_boarddata_size;
 
-static bool blob_is_arm_boarddata(const void *blob)
-{
-   const struct barebox_arm_boarddata *bd = blob;
-
-   return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC;
-}
-
 const struct barebox_boarddata *barebox_get_boarddata(void)
 {
if (!barebox_boarddata || !blob_is_arm_boarddata(barebox_boarddata))
diff --git a/arch/arm/include/asm/barebox-arm.h 
b/arch/arm/include/asm/barebox-arm.h
index c64e74f8f03a..8447ef7ba7fa 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -32,6 +32,13 @@ void __noreturn barebox_arm_entry(unsigned long membase, 
unsigned long memsize,
 #define barebox_arm_boarddata  barebox_boarddata
 #define BAREBOX_ARM_BOARDDATA_MAGICBAREBOX_BOARDDATA_MAGIC
 
+static inline bool blob_is_arm_boarddata(const void *blob)
+{
+   const struct barebox_arm_boarddata *bd = blob;
+
+   return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC;
+}
+
 u32 barebox_arm_machine(void);
 
 unsigned long arm_mem_ramoops_get(void);
-- 
2.39.2




[PATCH v2 0/6] add PBL handoff-data support

2024-05-16 Thread Ahmad Fatoum
This series replaces the 3 patches from v1 that are in next.

The first 3 patches are new: They ensure that the handoff structs
(linked list pointers, cookie, flags, ...) are also reserved in the
SDRAM banks and not only the data.

The three patches after that differ to v1 mainly in that reservation
of space for the handoff data is correctly taken care of. This was
erroneous both in PBL and in barebox proper and led to problems for me
trying to boot a Qemu Virt64 machine that has for some reason a FDT that
describes its size in the header as 1MiB.

Refer to each individual patch's changelog for more information.

Ahmad Fatoum (3):
  memory: add support for requesting barebox area as a whole
  treewide: use request_barebox_region for possible barebox memory
regions
  ARM: cpu: start: register barebox memory area

Sascha Hauer (3):
  ARM: move blob_is_arm_boarddata() to include
  add handoff-data support
  ARM: pass handoff data from PBL to proper

 arch/arm/cpu/cpu.c |   2 +-
 arch/arm/cpu/mmu_32.c  |   8 +-
 arch/arm/cpu/mmu_64.c  |   4 +-
 arch/arm/cpu/start.c   |  85 -
 arch/arm/cpu/uncompress.c  |  36 +-
 arch/arm/include/asm/barebox-arm.h |  31 +++--
 arch/arm/mach-imx/scratch.c|   2 +-
 arch/mips/lib/cpu-probe.c  |   2 +-
 arch/powerpc/mach-mpc5xxx/cpu.c|   2 +-
 arch/powerpc/mach-mpc85xx/cpu.c|   2 +-
 arch/riscv/boot/start.c|   4 +-
 arch/riscv/cpu/core.c  |   2 +-
 common/memory.c|  40 +-
 fs/pstore/ram_core.c   |   2 +-
 include/memory.h   |   6 +
 include/pbl/handoff-data.h |  53 
 pbl/Makefile   |   1 +
 pbl/handoff-data.c | 194 +
 18 files changed, 382 insertions(+), 94 deletions(-)
 create mode 100644 include/pbl/handoff-data.h
 create mode 100644 pbl/handoff-data.c

-- 
2.39.2




[PATCH master 1/2] ARM: cpu: start: align uncompressed DTB size to 4 bytes

2024-05-16 Thread Ahmad Fatoum
KASAN reports that decompression exceeds the bounds of the allocation
and my DT size isn't 4-bytes aligned. Align the allocation size to fix
this.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/cpu/start.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 6d0a7cfc6b04..2adc60fa8831 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -79,7 +79,7 @@ void *barebox_arm_boot_dtb(void)
 
pr_debug("%s: using compressed_dtb\n", __func__);
 
-   dtb = malloc(compressed_dtb->datalen_uncompressed);
+   dtb = malloc(ALIGN(compressed_dtb->datalen_uncompressed, 4));
if (!dtb)
return NULL;
 
-- 
2.39.2




[PATCH master 2/2] RISC-V: start: align uncompressed DTB size to 4 bytes

2024-05-16 Thread Ahmad Fatoum
On ARM, I ran into a KASAN splat, because the uncompressed DT may not
have a 4-byte aligned size. This can affect RISC-V boards too, so import
the fix done there.

Signed-off-by: Ahmad Fatoum 
---
 arch/riscv/boot/start.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/boot/start.c b/arch/riscv/boot/start.c
index 92991d0f6a84..d20526293bac 100644
--- a/arch/riscv/boot/start.c
+++ b/arch/riscv/boot/start.c
@@ -54,7 +54,7 @@ void *barebox_riscv_boot_dtb(void)
 
pr_debug("%s: using compressed_dtb\n", __func__);
 
-   dtb = malloc(compressed_dtb->datalen_uncompressed);
+   dtb = malloc(ALIGN(compressed_dtb->datalen_uncompressed, 4));
if (!dtb)
return NULL;
 
-- 
2.39.2




[PATCH master] ARM: layerscape: fix layerscape multiarch build with DEBUG_LL

2024-05-16 Thread Ahmad Fatoum
Layerscape was added recently into the CONFIG_ARCH_MULTIARCH (really
multiplatform), but the required changes to DBEUG_LL was omitted, which
breaks DEBUG_LL use for other platforms that aren't layerscape.

Fix this, so DEBUG_LL may be used for either layerscape or other enabled
platforms.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/ls1021aiot/lowlevel.c |  2 ++
 arch/arm/boards/ls1028ardb/lowlevel.c |  1 +
 arch/arm/boards/ls1046ardb/lowlevel.c |  1 +
 arch/arm/boards/tqmls1046a/lowlevel.c |  1 +
 arch/arm/include/asm/debug_ll.h   |  6 --
 common/Kconfig.debug_ll   | 10 +-
 include/mach/layerscape/debug_ll.h| 14 ++
 7 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/ls1021aiot/lowlevel.c 
b/arch/arm/boards/ls1021aiot/lowlevel.c
index 6bba528635a8..d2d4237c3d48 100644
--- a/arch/arm/boards/ls1021aiot/lowlevel.c
+++ b/arch/arm/boards/ls1021aiot/lowlevel.c
@@ -8,6 +8,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/boards/ls1028ardb/lowlevel.c 
b/arch/arm/boards/ls1028ardb/lowlevel.c
index e903d9d30196..de6f53d7dc2e 100644
--- a/arch/arm/boards/ls1028ardb/lowlevel.c
+++ b/arch/arm/boards/ls1028ardb/lowlevel.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/boards/ls1046ardb/lowlevel.c 
b/arch/arm/boards/ls1046ardb/lowlevel.c
index 56b8320eddb4..c2d3a526bc06 100644
--- a/arch/arm/boards/ls1046ardb/lowlevel.c
+++ b/arch/arm/boards/ls1046ardb/lowlevel.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/boards/tqmls1046a/lowlevel.c 
b/arch/arm/boards/tqmls1046a/lowlevel.c
index 9fcb52ea3902..2551a18ec634 100644
--- a/arch/arm/boards/tqmls1046a/lowlevel.c
+++ b/arch/arm/boards/tqmls1046a/lowlevel.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/include/asm/debug_ll.h b/arch/arm/include/asm/debug_ll.h
index 0cc3d28662a3..999f1cb831a8 100644
--- a/arch/arm/include/asm/debug_ll.h
+++ b/arch/arm/include/asm/debug_ll.h
@@ -31,6 +31,10 @@
 #include 
 #endif
 
+#ifdef CONFIG_DEBUG_LAYERSCAPE_UART
+#include 
+#endif
+
 #ifdef CONFIG_DEBUG_QEMU_ARM64_VIRT
 #define DEBUG_LL_UART_ADDR 0x900
 #include 
@@ -40,8 +44,6 @@
 #include 
 #elif defined CONFIG_ARCH_VERSATILE
 #include 
-#elif defined CONFIG_ARCH_LAYERSCAPE
-#include 
 #elif defined CONFIG_ARCH_TEGRA
 #include 
 #elif defined CONFIG_ARCH_SOCFPGA
diff --git a/common/Kconfig.debug_ll b/common/Kconfig.debug_ll
index bdc1a7f3a6dc..29265bfad0f5 100644
--- a/common/Kconfig.debug_ll
+++ b/common/Kconfig.debug_ll
@@ -139,6 +139,14 @@ config DEBUG_IMX9_UART
depends on ARCH_IMX93
select DEBUG_IMX_UART
 
+
+config DEBUG_LAYERSCAPE_UART
+   bool "Layerscape Debug UART"
+   depends on ARCH_LAYERSCAPE
+   help
+ Say Y here if you want barebox low-level debugging support
+ on NXP Layerscape SoCs.
+
 config DEBUG_VEXPRESS_UART
bool "Vexpress Debug UART"
depends on ARCH_VEXPRESS
@@ -409,7 +417,7 @@ config DEBUG_SOCFPGA_UART_CLOCK
 
 config DEBUG_LAYERSCAPE_UART_PORT
int "Layerscape UART port selection"
-   depends on ARCH_LAYERSCAPE
+   depends on DEBUG_LAYERSCAPE_UART
default 1
help
  Select the UART port number used for early debugging here. Port
diff --git a/include/mach/layerscape/debug_ll.h 
b/include/mach/layerscape/debug_ll.h
index 22c32243406b..c54a4810a4cb 100644
--- a/include/mach/layerscape/debug_ll.h
+++ b/include/mach/layerscape/debug_ll.h
@@ -13,6 +13,8 @@
 #define __LSCH3_UART_BASE(num) LSCH3_NS16550_COM##num
 #define LSCH3_UART_BASE(num) __LSCH3_UART_BASE(num)
 
+#ifdef CONFIG_DEBUG_LAYERSCAPE_UART
+
 static inline uint8_t debug_ll_read_reg(void __iomem *base, int reg)
 {
return readb(base + reg);
@@ -82,4 +84,16 @@ static inline void layerscape_uart_putc(void *base, int c)
debug_ll_ns16550_putc(base, c);
 }
 
+#else
+
+static inline void ls1046a_uart_setup(void *base) { }
+static inline void ls1046a_debug_ll_init(void) { }
+static inline void ls1028a_uart_setup(void *base) { }
+static inline void ls1028a_debug_ll_init(void) { }
+static inline void ls102xa_uart_setup(void *base) { }
+static inline void ls102xa_debug_ll_init(void) { }
+static inline void layerscape_uart_putc(void *base, int c) { }
+
+#endif
+
 #endif /* __MACH_LAYERSCAPE_DEBUG_LL_H__ */
-- 
2.39.2




[PATCH] common: hide DEFAULT_COMPRESSION menu

2024-05-16 Thread Ahmad Fatoum
CONFIG_DEFAULT_COMPRESSION_* refers to the compression done for
in-barebox binaries and is not useful when barebox proper as a whole is
compressed as in that case, we would have compression applied twice.

For this reason, DEFAULT_COMPRESSION_NONE is the only possible choice in
a PBL-enabled build. Having the choice with only one option is confusing
though, so let's hide the prompt.

Preferably, we'd omit these options in PBL builds completely, but this
seems not easily possible.

Signed-off-by: Ahmad Fatoum 
---
 common/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 67cbbf5197da..366521dadfe1 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -921,8 +921,8 @@ config DEFAULT_ENVIRONMENT
  CONFIG_ENV_HANDLING is not enabled.
 
 choice
-   prompt "default compression for in-barebox binaries"
-   default DEFAULT_COMPRESSION_NONE if PBL_IMAGE
+   prompt "default compression for in-barebox binaries" if PBL_IMAGE
+   default DEFAULT_COMPRESSION_NONE
default DEFAULT_COMPRESSION_LZO if LZO_DECOMPRESS
default DEFAULT_COMPRESSION_XZ if XZ_DECOMPRESS
default DEFAULT_COMPRESSION_GZIP if ZLIB
-- 
2.39.2




[PATCH master 2/2] ARM: fix overlap between ramoops area and early malloc area

2024-05-16 Thread Ahmad Fatoum
ramoops is usually a few megabytes and the early malloc area is just
128K, so the effect of this overlap was likely limited, but depending on
size of the data stored to pstore, this could still lead to problems.

Avoid this by locating the early malloc area before the barebox binary.
That way that space is reclaimed in barebox proper for the non-early
malloc region.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/cpu/uncompress.c  |  4 ++--
 arch/arm/include/asm/barebox-arm.h | 24 +---
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index aa1a49bfc96a..612a5b65ff4c 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -66,8 +66,8 @@ void __noreturn barebox_pbl_start(unsigned long membase, 
unsigned long memsize,
if (IS_ENABLED(CONFIG_MMU))
mmu_early_enable(membase, memsize);
 
-   free_mem_ptr = arm_mem_early_malloc(endmem);
-   free_mem_end_ptr = arm_mem_early_malloc_end(endmem);
+   free_mem_ptr = barebox_base - ARM_MEM_EARLY_MALLOC_SIZE;
+   free_mem_end_ptr = barebox_base;
 
pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx 
(uncompressed size: 0x%08x)\n",
pg_start, pg_len, barebox_base, uncompressed_len);
diff --git a/arch/arm/include/asm/barebox-arm.h 
b/arch/arm/include/asm/barebox-arm.h
index 30834233fb96..c64e74f8f03a 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -73,12 +73,10 @@ void *barebox_arm_boot_dtb(void);
  *   ↑
  *   ARM_EARLY_PAGETABLE_SIZE
  *   ↓
- *   arm_mem_ttb() / arm_mem_early_malloc_end() 
- *   ↑  ↑
- * CONFIG_FS_PSTORE_RAMOOPS_SIZE SZ_128K
- * (depends on FS_PSTORE_RAMOOPS)   |
- *   |  ↓
- *   | -- arm_mem_early_malloc() ---
+ *  --- arm_mem_ttb() -
+ *   ↑
+ * CONFIG_FS_PSTORE_RAMOOPS_SIZE
+ * (depends on FS_PSTORE_RAMOOPS)
  *   ↓
  *  - arm_mem_ramoops() 
  *   ↑
@@ -86,6 +84,10 @@ void *barebox_arm_boot_dtb(void);
  *   + BSS) rounded to SZ_1M
  *   ↓
  *  -- arm_mem_barebox_image() -
+ *   ↑
+ *SZ_128K
+ *   ↓
+ *   arm_mem_early_malloc --
  */
 
 static inline unsigned long arm_mem_optee(unsigned long endmem)
@@ -121,15 +123,7 @@ static inline unsigned long arm_mem_ttb(unsigned long 
endmem)
return endmem;
 }
 
-static inline unsigned long arm_mem_early_malloc(unsigned long endmem)
-{
-   return arm_mem_ttb(endmem) - SZ_128K;
-}
-
-static inline unsigned long arm_mem_early_malloc_end(unsigned long endmem)
-{
-   return arm_mem_ttb(endmem);
-}
+#define ARM_MEM_EARLY_MALLOC_SIZE  SZ_128K
 
 static inline unsigned long arm_mem_ramoops(unsigned long endmem)
 {
-- 
2.39.2




[PATCH master 1/2] ARM: document PBL barebox memory layout

2024-05-16 Thread Ahmad Fatoum
Apparently, we have an overlap between ramoops/barebox proper
and the early malloc area. Before fixing that, let's add a diagram
explaining the current state of affairs.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/include/asm/barebox-arm.h | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm/include/asm/barebox-arm.h 
b/arch/arm/include/asm/barebox-arm.h
index 4d70360b9121..30834233fb96 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -52,6 +52,42 @@ static inline void arm_fixup_vectors(void)
 
 void *barebox_arm_boot_dtb(void);
 
+/*
+ *  - endmem --
+ *   ↑
+ * OPTEE_SIZE (depends on CONFIG_OPTEE_SIZE)
+ *   ↓
+ *  - arm_mem_optee() -
+ *   ↑
+ * SZ_32K
+ *   ↓
+ *   arm_mem_scratch() 
+ *   ↑
+ *   STACK_SIZE
+ *   ↓
+ *  - arm_mem_stack() -
+ *   ↑
+ *PAGE_SIZE (depends on CONFIG_STACK_GUARD_PAGE)
+ *   ↓
+ *  --- arm_mem_guard_page() --
+ *   ↑
+ *   ARM_EARLY_PAGETABLE_SIZE
+ *   ↓
+ *   arm_mem_ttb() / arm_mem_early_malloc_end() 
+ *   ↑  ↑
+ * CONFIG_FS_PSTORE_RAMOOPS_SIZE SZ_128K
+ * (depends on FS_PSTORE_RAMOOPS)   |
+ *   |  ↓
+ *   | -- arm_mem_early_malloc() ---
+ *   ↓
+ *  - arm_mem_ramoops() 
+ *   ↑
+ *   (barebox uncompressed image size
+ *   + BSS) rounded to SZ_1M
+ *   ↓
+ *  -- arm_mem_barebox_image() -
+ */
+
 static inline unsigned long arm_mem_optee(unsigned long endmem)
 {
return endmem - OPTEE_SIZE;
-- 
2.39.2




[PATCH] mci: collect host operation in struct mci_ops

2024-05-16 Thread Ahmad Fatoum
The number of ops implementable by MCI drivers increase due to HS200
support and will increase more for HS400. Collecting them into a common
struct makes it easier to specialize them for drivers that support
multiple variants and makes code more similar to Linux.

No functional change.

Signed-off-by: Ahmad Fatoum 
---
 drivers/mci/am654-sdhci.c| 10 +++---
 drivers/mci/arasan-sdhci.c   | 24 --
 drivers/mci/atmel-sdhci.c| 12 +++
 drivers/mci/atmel_mci.c  | 12 +++
 drivers/mci/bcm2835-sdhost.c | 10 +++---
 drivers/mci/dove-sdhci.c | 10 +++---
 drivers/mci/dw_mmc.c | 12 +++
 drivers/mci/dwcmshc-sdhci.c  | 12 +++
 drivers/mci/imx-esdhc.c  | 12 +++
 drivers/mci/imx.c| 10 +++---
 drivers/mci/mci-bcm2835.c| 10 +++---
 drivers/mci/mci-core.c   | 14 ++---
 drivers/mci/mci_spi.c| 12 +++
 drivers/mci/mmci.c   | 10 +++---
 drivers/mci/mxs.c| 10 +++---
 drivers/mci/omap_hsmmc.c | 10 +++---
 drivers/mci/pxamci.c | 10 +++---
 drivers/mci/rockchip-dwcmshc-sdhci.c | 12 +++
 drivers/mci/sdhci.c  |  2 +-
 drivers/mci/stm32_sdmmc2.c   | 10 +++---
 drivers/mci/tegra-sdmmc.c| 12 +++
 include/mci.h| 30 
 22 files changed, 173 insertions(+), 93 deletions(-)

diff --git a/drivers/mci/am654-sdhci.c b/drivers/mci/am654-sdhci.c
index 391b65591cce..493fa73eeb50 100644
--- a/drivers/mci/am654-sdhci.c
+++ b/drivers/mci/am654-sdhci.c
@@ -539,6 +539,12 @@ static const struct regmap_config regmap_config = {
.max_register   = 0x400,
 };
 
+static const struct mci_ops am654_sdhci_ops = {
+   .send_cmd = am654_sdhci_send_cmd,
+   .set_ios = am654_sdhci_set_ios,
+   .init = am654_sdhci_init,
+};
+
 static int am654_sdhci_probe(struct device *dev)
 {
struct device_node *np = dev->of_node;
@@ -623,9 +629,7 @@ static int am654_sdhci_probe(struct device *dev)
}
}
 
-   mci->send_cmd = am654_sdhci_send_cmd;
-   mci->set_ios = am654_sdhci_set_ios;
-   mci->init = am654_sdhci_init;
+   mci->ops = am654_sdhci_ops;
mci->hw_dev = dev;
 
of_property_read_u32(np, "ti,strobe-sel", &plat->strb_sel);
diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
index be1395454101..37be06dffdfe 100644
--- a/drivers/mci/arasan-sdhci.c
+++ b/drivers/mci/arasan-sdhci.c
@@ -711,6 +711,14 @@ static void arasan_dt_parse_clk_phases(struct device *dev,
 "clk-phase-mmc-hs400");
 }
 
+static const struct mci_ops arasan_sdhci_ops = {
+   .send_cmd = arasan_sdhci_send_cmd,
+   .set_ios = arasan_sdhci_set_ios,
+   .init = arasan_sdhci_init,
+   .card_present = arasan_sdhci_card_present,
+   .card_write_protected = arasan_sdhci_card_write_protected,
+};
+
 static int arasan_sdhci_probe(struct device *dev)
 {
struct device_node *np = dev->of_node;
@@ -728,6 +736,11 @@ static int arasan_sdhci_probe(struct device *dev)
if (IS_ERR(iores))
return PTR_ERR(iores);
 
+   arasan_sdhci->sdhci.base = IOMEM(iores->start);
+   arasan_sdhci->sdhci.mci = mci;
+   mci->ops = arasan_sdhci_ops;
+   mci->hw_dev = dev;
+
clk_ahb = clk_get(dev, "clk_ahb");
if (IS_ERR(clk_ahb)) {
dev_err(dev, "clk_ahb clock not found.\n");
@@ -760,19 +773,10 @@ static int arasan_sdhci_probe(struct device *dev)
 
if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) {
if (IS_ENABLED(CONFIG_MCI_TUNING))
-   mci->execute_tuning = arasan_zynqmp_execute_tuning;
+   mci->ops.execute_tuning = arasan_zynqmp_execute_tuning;
arasan_sdhci->quirks |= SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN;
}
 
-   arasan_sdhci->sdhci.base = IOMEM(iores->start);
-   arasan_sdhci->sdhci.mci = mci;
-   mci->send_cmd = arasan_sdhci_send_cmd;
-   mci->set_ios = arasan_sdhci_set_ios;
-   mci->init = arasan_sdhci_init;
-   mci->card_present = arasan_sdhci_card_present;
-   mci->card_write_protected = arasan_sdhci_card_write_protected;
-   mci->hw_dev = dev;
-
/*
 * clk_rates on ZynqMP are rounded wrong. For HS200 clk_get_rate retunrs
 * 19998 instead of 2
diff --git a/drivers/mci/atmel-sdhci.c b/drivers/mci/atmel-sdhci.c
index c124e736bb7d..a769128942d5 100644
--- a/drivers/mci/atmel-sdhci.c
+++ b/drivers/mci/atmel-sdhci.c
@@ -99,6 +99,13 @@ static int at91_sdhci_card_present(struct mci_host *mci)
return at91_sdhci_is_card_inserted(&to_priv(mci)->host);
 }
 
+static const struct mci_ops at91_sdhci_mci_ops = {
+   .send_cmd = at91_sd

Re: [PATCH master 1/2] list: fix CONFIG_DEBUG_LIST link failure in PBL

2024-05-16 Thread Ahmad Fatoum
On 16.05.24 09:16, Sascha Hauer wrote:
> On Wed, May 15, 2024 at 08:07:57AM +0200, Ahmad Fatoum wrote:
>> With the addition of PBL handoff data, we now use  in PBL.
>> This works fine with CONFIG_DEBUG_LIST disabled, because all functions are
>> inlined, but when building with the option enabled, references to the
>> out-of-line sanity checking functions breaks the build.
>>
>> Fix this by omitting these references when building for PBL.
>>
>> Signed-off-by: Ahmad Fatoum 
>> ---
>>  include/linux/list.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/list.h b/include/linux/list.h
>> index 2b3a39ea81e8..e47a8188e807 100644
>> --- a/include/linux/list.h
>> +++ b/include/linux/list.h
>> @@ -36,7 +36,7 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
>>  list->prev = list;
>>  }
>>  
>> -#ifdef CONFIG_DEBUG_LIST
>> +#if defined(CONFIG_DEBUG_LIST) && !defined(__PBL__)
>>  extern bool __list_add_valid_or_report(struct list_head *new,
>> struct list_head *prev,
>> struct list_head *next);
> 
> What about compiling list_debug.o for PBL as well?

I'd prefer we use singly linked lists instead, but I want to fix the
build error first.

Thanks,
Ahmad

> 
> Sascha
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |




[PATCH] mci: imx-esdhc: retire esdhc_platform_data

2024-05-16 Thread Ahmad Fatoum
We have no board in-tree that doesn't probe the imx-esdhc from DT.
The platform data is thus unused as the PBL usage happens without it,
therefore remove that struct definition and the dead code handling it.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/ls1028ardb/lowlevel.c |  1 -
 arch/arm/boards/ls1046ardb/lowlevel.c |  1 -
 arch/arm/boards/tqmls1046a/lowlevel.c |  1 -
 drivers/mci/imx-esdhc.c   | 34 +--
 include/platform_data/mmc-esdhc-imx.h | 48 ---
 5 files changed, 1 insertion(+), 84 deletions(-)
 delete mode 100644 include/platform_data/mmc-esdhc-imx.h

diff --git a/arch/arm/boards/ls1028ardb/lowlevel.c 
b/arch/arm/boards/ls1028ardb/lowlevel.c
index 00db0b1cf869..e903d9d30196 100644
--- a/arch/arm/boards/ls1028ardb/lowlevel.c
+++ b/arch/arm/boards/ls1028ardb/lowlevel.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/boards/ls1046ardb/lowlevel.c 
b/arch/arm/boards/ls1046ardb/lowlevel.c
index 408e6017f6cc..56b8320eddb4 100644
--- a/arch/arm/boards/ls1046ardb/lowlevel.c
+++ b/arch/arm/boards/ls1046ardb/lowlevel.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/boards/tqmls1046a/lowlevel.c 
b/arch/arm/boards/tqmls1046a/lowlevel.c
index 4a1496078a61..9fcb52ea3902 100644
--- a/arch/arm/boards/tqmls1046a/lowlevel.c
+++ b/arch/arm/boards/tqmls1046a/lowlevel.c
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index b05934a20113..54309aec2f74 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -195,27 +194,7 @@ static void esdhc_set_ios(struct mci_host *mci, struct 
mci_ios *ios)
 
 static int esdhc_card_present(struct mci_host *mci)
 {
-   struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
-   struct esdhc_platform_data *pdata = host->dev->platform_data;
-   int ret;
-
-   if (!pdata)
-   return 1;
-
-   switch (pdata->cd_type) {
-   case ESDHC_CD_NONE:
-   case ESDHC_CD_PERMANENT:
-   return 1;
-   case ESDHC_CD_CONTROLLER:
-   return !(sdhci_read32(&host->sdhci, SDHCI_PRESENT_STATE) & 
SDHCI_WRITE_PROTECT);
-   case ESDHC_CD_GPIO:
-   ret = gpio_direction_input(pdata->cd_gpio);
-   if (ret)
-   return ret;
-   return gpio_get_value(pdata->cd_gpio) ? 0 : 1;
-   }
-
-   return 0;
+   return 1;
 }
 
 static int esdhc_reset(struct fsl_esdhc_host *host)
@@ -302,7 +281,6 @@ static int fsl_esdhc_probe(struct device *dev)
struct mci_host *mci;
int ret;
unsigned long rate;
-   struct esdhc_platform_data *pdata = dev->platform_data;
const struct esdhc_soc_data *socdata;
 
ret = dev_get_drvdata(dev, (const void **)&socdata);
@@ -338,12 +316,6 @@ static int fsl_esdhc_probe(struct device *dev)
 
esdhc_populate_sdhci(host);
 
-   if (pdata) {
-   mci->host_caps = pdata->caps;
-   if (pdata->devname)
-   mci->devname = pdata->devname;
-   }
-
host->mci.ops = fsl_esdhc_ops;
host->mci.hw_dev = dev;
host->sdhci.mci = &host->mci;
@@ -360,10 +332,6 @@ static int fsl_esdhc_probe(struct device *dev)
if (host->mci.f_min < 20)
host->mci.f_min = 20;
host->mci.f_max = rate;
-   if (pdata) {
-   host->mci.use_dsr = pdata->use_dsr;
-   host->mci.dsr_val = pdata->dsr_val;
-   }
 
mci_of_parse(&host->mci);
 
diff --git a/include/platform_data/mmc-esdhc-imx.h 
b/include/platform_data/mmc-esdhc-imx.h
deleted file mode 100644
index fb7380a18201..
--- a/include/platform_data/mmc-esdhc-imx.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2010 Wolfram Sang 
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- */
-
-#ifndef __ASM_ARCH_IMX_ESDHC_H
-#define __ASM_ARCH_IMX_ESDHC_H
-
-enum wp_types {
-   ESDHC_WP_NONE,  /* no WP, neither controller nor gpio */
-   ESDHC_WP_CONTROLLER,/* mmc controller internal WP */
-   ESDHC_WP_GPIO,  /* external gpio pin for WP */
-};
-
-enum cd_types {
-   ESDHC_CD_NONE,  /* no CD, neither controller nor gpio */
-   ESDHC_CD_CONTROLLER,/* mmc controller internal CD */
-   ESDHC_CD_GPIO,  /* external gpio pin for CD */
-   ESDHC_CD_PERMANENT, /* no CD, card permanently wired to host */
-};
-
-/**
- * struct esdhc_platform_data - platform data for esdhc on i.MX
- *
- * ESDHC_WP(CD)_CONTROLLER type i

[PATCH] driver: move some inline getters for struct device into device.h

2024-05-16 Thread Ahmad Fatoum
The purpose of device.h is to contain only the device related
definitions and have as few header dependencies as possible.

dev_of_node() and dev_is_dma_coherent() are accessors for struct device
and have no other dependencies, so move them into this header as well.

Signed-off-by: Ahmad Fatoum 
---
 include/device.h | 21 +
 include/driver.h | 21 -
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/device.h b/include/device.h
index 8c3561e5a2f6..ad1bc7ca1eea 100644
--- a/include/device.h
+++ b/include/device.h
@@ -108,4 +108,25 @@ struct device_alias {
char name[];
 };
 
+static inline struct device_node *dev_of_node(struct device *dev)
+{
+   return IS_ENABLED(CONFIG_OFDEVICE) ? dev->of_node : NULL;
+}
+
+static inline bool dev_is_dma_coherent(struct device *dev)
+{
+   if (dev) {
+   switch (dev->dma_coherent) {
+   case DEV_DMA_NON_COHERENT:
+   return false;
+   case DEV_DMA_COHERENT:
+   return true;
+   case DEV_DMA_COHERENCE_DEFAULT:
+   break;
+   }
+   }
+
+   return IS_ENABLED(CONFIG_ARCH_DMA_DEFAULT_COHERENT);
+}
+
 #endif
diff --git a/include/driver.h b/include/driver.h
index 3401ab4f07f4..100761c7657e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -677,27 +677,6 @@ int device_match_of_modalias(struct device *dev, struct 
driver *drv);
 struct device *device_find_child(struct device *parent, void *data,
 int (*match)(struct device *dev, void *data));
 
-static inline struct device_node *dev_of_node(struct device *dev)
-{
-   return IS_ENABLED(CONFIG_OFDEVICE) ? dev->of_node : NULL;
-}
-
-static inline bool dev_is_dma_coherent(struct device *dev)
-{
-   if (dev) {
-   switch (dev->dma_coherent) {
-   case DEV_DMA_NON_COHERENT:
-   return false;
-   case DEV_DMA_COHERENT:
-   return true;
-   case DEV_DMA_COHERENCE_DEFAULT:
-   break;
-   }
-   }
-
-   return IS_ENABLED(CONFIG_ARCH_DMA_DEFAULT_COHERENT);
-}
-
 static inline void *dev_get_priv(const struct device *dev)
 {
return dev->priv;
-- 
2.39.2




[PATCH 2/3] pinctrl: rename barebox pinctrl_select_state to pinctrl_get_select

2024-05-16 Thread Ahmad Fatoum
Linux pinctrl_select_state() operates on struct pinctrl_state. The
helper that selects a state by name is instead called
pinctrl_get_select.

There's only a single user in-tree for that function, so let's rename
it and adjust the prototype.

Signed-off-by: Ahmad Fatoum 
---
 drivers/i2c/busses/i2c-imx.c | 24 ++--
 drivers/pinctrl/pinctrl.c| 13 +
 include/linux/pinctrl/consumer.h | 10 +++---
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f6a67ec067df..981db015ea34 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -509,21 +509,25 @@ static int i2c_fsl_xfer(struct i2c_adapter *adapter,
return (result < 0) ? result : num;
 }
 
+static void i2c_fsl_pinctrl_select_state(struct i2c_adapter *adapter,
+const char *name)
+{
+   struct pinctrl *pinctrl;
+
+   pinctrl = pinctrl_get_select(adapter->dev.parent, name);
+   if (pinctrl)
+   pinctrl_put(pinctrl);
+   else
+   dev_err(adapter->dev.parent, "pinctrl failed: %pe\n", pinctrl);
+}
+
 static void i2c_fsl_prepare_recovery(struct i2c_adapter *adapter)
 {
-   int ret;
-
-   ret = pinctrl_select_state(adapter->dev.parent, "gpio");
-   if (ret)
-   dev_err(adapter->dev.parent, "pinctrl failed: %s\n", 
strerror(-ret));
+   i2c_fsl_pinctrl_select_state(adapter, "gpio");
 }
 static void i2c_fsl_unprepare_recovery(struct i2c_adapter *adapter)
 {
-   int ret;
-
-   ret = pinctrl_select_state(adapter->dev.parent, "default");
-   if (ret)
-   dev_err(adapter->dev.parent, "pinctrl failed: %s\n", 
strerror(-ret));
+   i2c_fsl_pinctrl_select_state(adapter, "default");
 }
 
 static void i2c_fsl_init_recovery(struct fsl_i2c_struct *i2c_fsl,
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index 95e7b0ea96e1..2d331211f71c 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -161,20 +161,25 @@ int of_pinctrl_select_state_default(struct device_node 
*np)
return of_pinctrl_select_state(np, "default");
 }
 
-int pinctrl_select_state(struct device *dev, const char *name)
+struct pinctrl *pinctrl_get_select(struct device *dev, const char *name)
 {
struct device_node *np;
+   int ret;
 
np = dev->of_node;
if (!np)
-   return 0;
+   return ERR_PTR(-ENODEV);
 
-   return of_pinctrl_select_state(np, name);
+   ret = of_pinctrl_select_state(np, name);
+   if (ret)
+   return ERR_PTR(ret);
+
+   return (struct pinctrl *)np;
 }
 
 int pinctrl_select_state_default(struct device *dev)
 {
-   return pinctrl_select_state(dev, "default");
+   return PTR_ERR_OR_ZERO(pinctrl_get_select(dev, "default"));
 }
 
 int pinctrl_register(struct pinctrl_device *pdev)
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 3028f960deb4..33d5c1b19a89 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -7,8 +7,10 @@
 struct device;
 struct device_node;
 
+struct pinctrl;
+
 #ifdef CONFIG_PINCTRL
-int pinctrl_select_state(struct device *dev, const char *state);
+struct pinctrl *pinctrl_get_select(struct device *dev, const char *state);
 int pinctrl_select_state_default(struct device *dev);
 int of_pinctrl_select_state(struct device_node *np, const char *state);
 int of_pinctrl_select_state_default(struct device_node *np);
@@ -17,9 +19,9 @@ int pinctrl_gpio_direction_output(unsigned int pin);
 int pinctrl_gpio_get_direction(unsigned pin);
 int pinctrl_single_probe(struct device *dev);
 #else
-static inline int pinctrl_select_state(struct device *dev, const char *state)
+static inline struct pinctrl *pinctrl_get_select(struct device *dev, const 
char *state)
 {
-   return -ENODEV;
+   return ERR_PTR(-ENODEV);
 }
 
 static inline int pinctrl_select_state_default(struct device *dev)
@@ -58,4 +60,6 @@ static inline int pinctrl_single_probe(struct device *dev)
 }
 #endif
 
+static inline void pinctrl_put(struct pinctrl *pinctrl) {}
+
 #endif /* LINUX_PINCTRL_CONSUMER_H */
-- 
2.39.2




[PATCH 3/3] pinctrl: implement pinctrl_lookup_state/select_state

2024-05-16 Thread Ahmad Fatoum
Besides pinctrl_get_select, the Linux API provides separate functions to
lookup a state and verify its existence and activating a state.

To make porting code easier that calls the former during probe and the
latter at runtime, define these functions and implement
of_pinctrl_select_state on top of them.

No functional change intended.

Signed-off-by: Ahmad Fatoum 
---
 drivers/pinctrl/pinctrl.c| 98 ++--
 include/linux/pinctrl/consumer.h | 23 
 2 files changed, 90 insertions(+), 31 deletions(-)

diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index 2d331211f71c..dd0ed156ec9e 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -10,6 +10,14 @@
 #include 
 #include 
 
+struct pinctrl {
+   struct device_node consumer_np;
+};
+
+struct pinctrl_state {
+   struct property prop;
+};
+
 static LIST_HEAD(pinctrl_list);
 
 static struct pinctrl_device *pin_to_pinctrl(unsigned int pin)
@@ -90,30 +98,28 @@ static int pinctrl_config_one(struct device_node *for_node, 
struct device_node *
return -ENODEV;
 }
 
-int of_pinctrl_select_state(struct device_node *np, const char *name)
+static inline struct pinctrl_state *
+of_property_pinctrl_get_state(struct property *prop)
 {
+   return container_of(prop, struct pinctrl_state, prop);
+}
+
+struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *pinctrl,
+  const char *name)
+{
+   struct device_node *np = &pinctrl->consumer_np;
int state, ret;
char propname[sizeof("pinctrl-4294967295")];
-   const __be32 *list;
-   int size, config;
-   phandle phandle;
-   struct device_node *np_config;
+   struct property *prop;
const char *statename;
 
-   if (!of_find_property(np, "pinctrl-0", NULL))
-   return 0;
-
/* For each defined state ID */
for (state = 0; ; state++) {
/* Retrieve the pinctrl-* property */
sprintf(propname, "pinctrl-%d", state);
-   list = of_get_property(np, propname, &size);
-   if (!list) {
-   ret = -ENODEV;
-   break;
-   }
-
-   size /= sizeof(*list);
+   prop = of_find_property(np, propname, NULL);
+   if (!prop)
+   return ERR_PTR(-ENODEV);
 
/* Determine whether pinctrl-names property names the state */
ret = of_property_read_string_index(np, "pinctrl-names",
@@ -131,31 +137,61 @@ int of_pinctrl_select_state(struct device_node *np, const 
char *name)
if (strcmp(name, statename))
continue;
 
-   /* For every referenced pin configuration node in it */
-   for (config = 0; config < size; config++) {
-   phandle = be32_to_cpup(list++);
+   return of_property_pinctrl_get_state(prop);
+   }
 
-   /* Look up the pin configuration node */
-   np_config = of_find_node_by_phandle(phandle);
-   if (!np_config) {
-   pr_err("prop %pOF %s index %i invalid 
phandle\n",
-   np, propname, config);
-   ret = -EINVAL;
-   goto err;
-   }
+   return ERR_PTR(ret);
+}
 
-   /* Parse the node */
-   ret = pinctrl_config_one(np, np_config);
-   if (ret < 0)
-   goto err;
+int pinctrl_select_state(struct pinctrl *pinctrl, struct pinctrl_state *state)
+{
+   int ret = -ENODEV;
+   const __be32 *list;
+   int size, config;
+   phandle phandle;
+   struct device_node *np = &pinctrl->consumer_np, *np_config;
+   struct property *prop = &state->prop;
+
+   list = of_property_get_value(prop);
+   size = prop->length / sizeof(*list);
+
+   /* For every referenced pin configuration node in it */
+   for (config = 0; config < size; config++) {
+   phandle = be32_to_cpup(list++);
+
+   /* Look up the pin configuration node */
+   np_config = of_find_node_by_phandle(phandle);
+   if (!np_config) {
+   pr_err("prop %pOF %s index %i invalid phandle\n",
+   np, prop->name, config);
+   ret = -EINVAL;
+   goto err;
}
 
-   return 0;
+   /* Parse the node */
+   ret = pinctrl_config_one(np, np_config);
+   if (ret < 0)
+   goto err;
}
 err:
return ret;
 }
 
+int of_pinctrl_select_state(struct device_node *np, const char *name)
+{
+   struct pinctrl *pinctrl = of_pinctrl_get(np);
+   struct pinctrl_state *st

[PATCH 1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h

2024-05-16 Thread Ahmad Fatoum
Follow-up patches will align the barebox pinctrl consumer API with
Linux'. So it makes sense to have the header called the same as well.
Users of the old pinctrl.h header are unaffected as it will include
the new .

Signed-off-by: Ahmad Fatoum 
---
 include/linux/pinctrl/consumer.h | 61 
 include/pinctrl.h| 55 +++-
 2 files changed, 65 insertions(+), 51 deletions(-)
 create mode 100644 include/linux/pinctrl/consumer.h

diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
new file mode 100644
index ..3028f960deb4
--- /dev/null
+++ b/include/linux/pinctrl/consumer.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LINUX_PINCTRL_CONSUMER_H
+#define LINUX_PINCTRL_CONSUMER_H
+
+#include 
+
+struct device;
+struct device_node;
+
+#ifdef CONFIG_PINCTRL
+int pinctrl_select_state(struct device *dev, const char *state);
+int pinctrl_select_state_default(struct device *dev);
+int of_pinctrl_select_state(struct device_node *np, const char *state);
+int of_pinctrl_select_state_default(struct device_node *np);
+int pinctrl_gpio_direction_input(unsigned pin);
+int pinctrl_gpio_direction_output(unsigned int pin);
+int pinctrl_gpio_get_direction(unsigned pin);
+int pinctrl_single_probe(struct device *dev);
+#else
+static inline int pinctrl_select_state(struct device *dev, const char *state)
+{
+   return -ENODEV;
+}
+
+static inline int pinctrl_select_state_default(struct device *dev)
+{
+   return -ENODEV;
+}
+
+static inline int of_pinctrl_select_state(struct device_node *np, const char 
*state)
+{
+   return -ENODEV;
+}
+
+static inline int of_pinctrl_select_state_default(struct device_node *np)
+{
+   return -ENODEV;
+}
+
+static inline int pinctrl_gpio_direction_input(unsigned pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_gpio_direction_output(unsigned int pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_gpio_get_direction(unsigned pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_single_probe(struct device *dev)
+{
+   return -ENOSYS;
+}
+#endif
+
+#endif /* LINUX_PINCTRL_CONSUMER_H */
diff --git a/include/pinctrl.h b/include/pinctrl.h
index f0f7c2cc8b3e..4ba7b489345b 100644
--- a/include/pinctrl.h
+++ b/include/pinctrl.h
@@ -2,7 +2,11 @@
 #ifndef PINCTRL_H
 #define PINCTRL_H
 
+#include 
+#include 
+
 struct pinctrl_device;
+struct device_node;
 
 struct pinctrl_ops {
int (*set_state)(struct pinctrl_device *, struct device_node *);
@@ -21,55 +25,4 @@ struct pinctrl_device {
 int pinctrl_register(struct pinctrl_device *pdev);
 void pinctrl_unregister(struct pinctrl_device *pdev);
 
-#ifdef CONFIG_PINCTRL
-int pinctrl_select_state(struct device *dev, const char *state);
-int pinctrl_select_state_default(struct device *dev);
-int of_pinctrl_select_state(struct device_node *np, const char *state);
-int of_pinctrl_select_state_default(struct device_node *np);
-int pinctrl_gpio_direction_input(unsigned pin);
-int pinctrl_gpio_direction_output(unsigned int pin);
-int pinctrl_gpio_get_direction(unsigned pin);
-int pinctrl_single_probe(struct device *dev);
-#else
-static inline int pinctrl_select_state(struct device *dev, const char *state)
-{
-   return -ENODEV;
-}
-
-static inline int pinctrl_select_state_default(struct device *dev)
-{
-   return -ENODEV;
-}
-
-static inline int of_pinctrl_select_state(struct device_node *np, const char 
*state)
-{
-   return -ENODEV;
-}
-
-static inline int of_pinctrl_select_state_default(struct device_node *np)
-{
-   return -ENODEV;
-}
-
-static inline int pinctrl_gpio_direction_input(unsigned pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_gpio_direction_output(unsigned int pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_gpio_get_direction(unsigned pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_single_probe(struct device *dev)
-{
-   return -ENOSYS;
-}
-#endif
-
 #endif /* PINCTRL_H */
-- 
2.39.2




Re: [PATCH 0/7] replace cdev_by_name() with cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
On Thu, May 16, 2024 at 04:43:04PM +0200, Marco Felsch wrote:
> Hi Sascha,
> 
> On 24-05-16, Sascha Hauer wrote:
> > As Ahmad noticed cdev_by_name() doesn't increase the reference counting
> > on the returned cdev which causes problems further down the road. This
> > series replaces some of the easier occurences of cdev_by_name() with
> > cdev_open_by_name().
> 
> Can we kindly inform the user with a print_once() or so that
> cdev_by_name should be replaced with cdev_open_by_name()?

Some of the call sites of cdev_by_name() are used frequently on all
boards, so this wouldn't be practical.

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



Re: [PATCH 0/7] replace cdev_by_name() with cdev_open_by_name()

2024-05-16 Thread Marco Felsch
Hi Sascha,

On 24-05-16, Sascha Hauer wrote:
> As Ahmad noticed cdev_by_name() doesn't increase the reference counting
> on the returned cdev which causes problems further down the road. This
> series replaces some of the easier occurences of cdev_by_name() with
> cdev_open_by_name().

Can we kindly inform the user with a print_once() or so that
cdev_by_name should be replaced with cdev_open_by_name()?

Regards,
  Marco

> Sascha Hauer (7):
>   ARM: Freescale i.MX23 evk: use cdev_open_by_name()
>   ARM: tx28: use cdev_open_by_name()
>   ARM: omap: use cdev_open_by_name()
>   ARM: Rockchip: use cdev_open_by_name()
>   commands: devlookup: use cdev_open_by_name()
>   commands: findmnt: use cdev_open_by_name()
>   bootm: use cdev_open_by_name()
> 
>  arch/arm/boards/freescale-mx23-evk/mx23-evk.c | 13 +++--
>  arch/arm/boards/karo-tx28/tx28-stk5.c | 13 -
>  arch/arm/mach-omap/omap_generic.c |  5 -
>  arch/arm/mach-rockchip/bbu.c  |  8 +++-
>  commands/devlookup.c  | 15 ++-
>  commands/findmnt.c|  3 ++-
>  common/bootm.c|  5 -
>  7 files changed, 42 insertions(+), 20 deletions(-)
> 
> -- 
> 2.39.2
> 
> 
> 



Re: [PATCH] ARM: socfpga-xload_*defconfig: merge and disable unused features

2024-05-16 Thread Sascha Hauer


On Thu, 16 May 2024 12:10:52 +0200, Sascha Hauer wrote:
> The socfpga-xload_*defconfig have MC13xxx, AT25 and SPI support enabled.
> Disable these as they are unused. This makes the configs small enough so
> that we can merge the two existing configs into one.
> 
> 

Applied, thanks!

[1/1] ARM: socfpga-xload_*defconfig: merge and disable unused features
  https://git.pengutronix.de/cgit/barebox/commit/?id=d4f47a86f197 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




[PATCH] ARM: socfpga-xload_*defconfig: merge and disable unused features

2024-05-16 Thread Sascha Hauer
The socfpga-xload_*defconfig have MC13xxx, AT25 and SPI support enabled.
Disable these as they are unused. This makes the configs small enough so
that we can merge the two existing configs into one.

Signed-off-by: Sascha Hauer 
---
 arch/arm/configs/socfpga-xload-2_defconfig | 28 --
 arch/arm/configs/socfpga-xload_defconfig   |  9 +++
 2 files changed, 5 insertions(+), 32 deletions(-)
 delete mode 100644 arch/arm/configs/socfpga-xload-2_defconfig

diff --git a/arch/arm/configs/socfpga-xload-2_defconfig 
b/arch/arm/configs/socfpga-xload-2_defconfig
deleted file mode 100644
index 78b07aae5b..00
--- a/arch/arm/configs/socfpga-xload-2_defconfig
+++ /dev/null
@@ -1,28 +0,0 @@
-CONFIG_ARCH_SOCFPGA=y
-CONFIG_ARCH_SOCFPGA_XLOAD=y
-CONFIG_MACH_SOCFPGA_ALTERA_SOCDK=y
-CONFIG_MACH_SOCFPGA_TERASIC_DE0_NANO_SOC=y
-CONFIG_MACH_SOCFPGA_TERASIC_DE10_NANO=y
-CONFIG_THUMB2_BAREBOX=y
-CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
-# CONFIG_ARM_EXCEPTIONS is not set
-# CONFIG_MEMINFO is not set
-CONFIG_MMU=y
-CONFIG_MALLOC_SIZE=0x0
-CONFIG_MALLOC_DUMMY=y
-CONFIG_RELOCATABLE=y
-CONFIG_SHELL_NONE=y
-# CONFIG_ERRNO_MESSAGES is not set
-# CONFIG_TIMESTAMP is not set
-CONFIG_DRIVER_SERIAL_NS16550=y
-CONFIG_MCI=y
-CONFIG_MCI_STARTUP=y
-# CONFIG_MCI_WRITE is not set
-CONFIG_MCI_DW=y
-CONFIG_MFD_MC13XXX=y
-CONFIG_EEPROM_AT25=y
-# CONFIG_FS_RAMFS is not set
-# CONFIG_FS_DEVFS is not set
-CONFIG_FS_FAT=y
-CONFIG_BOOTSTRAP=y
-CONFIG_BOOTSTRAP_DISK=y
diff --git a/arch/arm/configs/socfpga-xload_defconfig 
b/arch/arm/configs/socfpga-xload_defconfig
index 008ba64865..37e9ecec71 100644
--- a/arch/arm/configs/socfpga-xload_defconfig
+++ b/arch/arm/configs/socfpga-xload_defconfig
@@ -1,6 +1,9 @@
 CONFIG_ARCH_SOCFPGA=y
 CONFIG_ARCH_SOCFPGA_XLOAD=y
+CONFIG_MACH_SOCFPGA_ALTERA_SOCDK=y
 CONFIG_MACH_SOCFPGA_EBV_SOCRATES=y
+CONFIG_MACH_SOCFPGA_TERASIC_DE0_NANO_SOC=y
+CONFIG_MACH_SOCFPGA_TERASIC_DE10_NANO=y
 CONFIG_MACH_SOCFPGA_TERASIC_SOCKIT=y
 CONFIG_THUMB2_BAREBOX=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
@@ -9,17 +12,15 @@ CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_MALLOC_SIZE=0x0
 CONFIG_MALLOC_DUMMY=y
-CONFIG_RELOCATABLE=y
 CONFIG_SHELL_NONE=y
 # CONFIG_ERRNO_MESSAGES is not set
-# CONFIG_TIMESTAMP is not set
 CONFIG_DRIVER_SERIAL_NS16550=y
+# CONFIG_SPI is not set
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 # CONFIG_MCI_WRITE is not set
 CONFIG_MCI_DW=y
-CONFIG_MFD_MC13XXX=y
-CONFIG_EEPROM_AT25=y
+# CONFIG_VIRTIO_MENU is not set
 # CONFIG_FS_RAMFS is not set
 # CONFIG_FS_DEVFS is not set
 CONFIG_FS_FAT=y
-- 
2.39.2




Re: [PATCH] common: boards: wolfvision: use state_by_alias instead of opencoding

2024-05-16 Thread Sascha Hauer


On Wed, 15 May 2024 08:07:36 +0200, Ahmad Fatoum wrote:
> This introduces no functional change, but makes code a bit more compact.
> 
> 

Applied, thanks!

[1/1] common: boards: wolfvision: use state_by_alias instead of opencoding
  https://git.pengutronix.de/cgit/barebox/commit/?id=6b1df8b8219d (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH master 1/2] list: fix CONFIG_DEBUG_LIST link failure in PBL

2024-05-16 Thread Sascha Hauer
On Wed, May 15, 2024 at 08:07:57AM +0200, Ahmad Fatoum wrote:
> With the addition of PBL handoff data, we now use  in PBL.
> This works fine with CONFIG_DEBUG_LIST disabled, because all functions are
> inlined, but when building with the option enabled, references to the
> out-of-line sanity checking functions breaks the build.
> 
> Fix this by omitting these references when building for PBL.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  include/linux/list.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/list.h b/include/linux/list.h
> index 2b3a39ea81e8..e47a8188e807 100644
> --- a/include/linux/list.h
> +++ b/include/linux/list.h
> @@ -36,7 +36,7 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
>   list->prev = list;
>  }
>  
> -#ifdef CONFIG_DEBUG_LIST
> +#if defined(CONFIG_DEBUG_LIST) && !defined(__PBL__)
>  extern bool __list_add_valid_or_report(struct list_head *new,
>  struct list_head *prev,
>  struct list_head *next);

What about compiling list_debug.o for PBL as well?

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



Re: [PATCH master 1/3] cdev: return error code from cdev_close

2024-05-16 Thread Sascha Hauer


On Wed, 15 May 2024 10:05:05 +0200, Ahmad Fatoum wrote:
> cdev_operations::close can fail and thus cdev_close should pass along
> the error code to the users instead of discarding it.
> 
> Do that, so users like devfs close() can start propagating this error.
> 
> 

Applied, thanks!

[1/3] cdev: return error code from cdev_close
  https://git.pengutronix.de/cgit/barebox/commit/?id=490dab2db018 (link may 
not be stable)
[2/3] fs: devfs: restore cdev reference count maintenance
  https://git.pengutronix.de/cgit/barebox/commit/?id=dd6ac1612b4b (link may 
not be stable)
[3/3] partition: reparse tables only if CONFIG_PARTITION_MANIPULATION=y
  https://git.pengutronix.de/cgit/barebox/commit/?id=dfdfc732ba6f (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




[PATCH 3/7] ARM: omap: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 arch/arm/mach-omap/omap_generic.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap/omap_generic.c 
b/arch/arm/mach-omap/omap_generic.c
index 99e14fb540..112c806216 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -157,13 +157,16 @@ static int omap_env_init(void)
 
device_detect_by_name(diskdev);
partname = basprintf("%s.0", diskdev);
-   cdev = cdev_by_name(partname);
+   cdev = cdev_open_by_name(partname, O_RDONLY);
if (cdev == NULL) {
pr_err("Failed to get device %s\n", partname);
goto out;
}
 
rootpath = cdev_mount_default(cdev, NULL);
+
+   cdev_close(cdev);
+
if (IS_ERR(rootpath)) {
pr_err("Failed to load environment: mount %s failed (%ld)\n",
cdev->name, PTR_ERR(rootpath));
-- 
2.39.2




[PATCH 0/7] replace cdev_by_name() with cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
As Ahmad noticed cdev_by_name() doesn't increase the reference counting
on the returned cdev which causes problems further down the road. This
series replaces some of the easier occurences of cdev_by_name() with
cdev_open_by_name().

Sascha Hauer (7):
  ARM: Freescale i.MX23 evk: use cdev_open_by_name()
  ARM: tx28: use cdev_open_by_name()
  ARM: omap: use cdev_open_by_name()
  ARM: Rockchip: use cdev_open_by_name()
  commands: devlookup: use cdev_open_by_name()
  commands: findmnt: use cdev_open_by_name()
  bootm: use cdev_open_by_name()

 arch/arm/boards/freescale-mx23-evk/mx23-evk.c | 13 +++--
 arch/arm/boards/karo-tx28/tx28-stk5.c | 13 -
 arch/arm/mach-omap/omap_generic.c |  5 -
 arch/arm/mach-rockchip/bbu.c  |  8 +++-
 commands/devlookup.c  | 15 ++-
 commands/findmnt.c|  3 ++-
 common/bootm.c|  5 -
 7 files changed, 42 insertions(+), 20 deletions(-)

-- 
2.39.2




[PATCH 2/7] ARM: tx28: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 arch/arm/boards/karo-tx28/tx28-stk5.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c 
b/arch/arm/boards/karo-tx28/tx28-stk5.c
index d1fd526c00..01a14a33a3 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -310,20 +310,21 @@ static const uint32_t tx28_starterkit_pad_setup[] = {
  */
 static int register_persistent_environment(void)
 {
-   struct cdev *cdev;
+   struct cdev *cdev, *env;
 
/*
 * The TX28 STK5 has only one usable MCI card socket.
 * So, we expect its name as "disk0".
 */
-   cdev = cdev_by_name("disk0");
+   cdev = cdev_open_by_name("disk0", O_RDONLY);
if (cdev == NULL) {
pr_err("No MCI card preset\n");
return -ENODEV;
}
+   cdev_close(cdev);
 
/* MCI card is present, also a usable partition on it? */
-   cdev = cdev_by_name("disk0.1");
+   cdev = cdev_open_by_name("disk0.1", O_RDONLY);
if (cdev == NULL) {
pr_err("No second partition available\n");
pr_info("Please create at least a second partition with"
@@ -332,9 +333,11 @@ static int register_persistent_environment(void)
}
 
/* use the full partition as our persistent environment storage */
-   cdev = devfs_add_partition("disk0.1", 0, cdev->size,
+   env = devfs_add_partition("disk0.1", 0, cdev->size,
DEVFS_PARTITION_FIXED, "env0");
-   return PTR_ERR_OR_ZERO(cdev);
+   cdev_close(cdev);
+
+   return PTR_ERR_OR_ZERO(env);
 }
 
 static void tx28_get_ethaddr(void)
-- 
2.39.2




[PATCH 6/7] commands: findmnt: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 commands/findmnt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/commands/findmnt.c b/commands/findmnt.c
index da8f58835f..3c9a520b85 100644
--- a/commands/findmnt.c
+++ b/commands/findmnt.c
@@ -71,7 +71,7 @@ static int do_findmnt(int argc, char *argv[])
const char *backingstore;
struct cdev *cdev;
 
-   cdev = cdev_by_name(devpath_to_name(device));
+   cdev = cdev_open_by_name(devpath_to_name(device), 
O_RDONLY);
if (!cdev)
continue;
 
@@ -82,6 +82,7 @@ static int do_findmnt(int argc, char *argv[])
print_header(&header_printed);
report_findmnt(target);
}
+   cdev_close(cdev);
}
}
 
-- 
2.39.2




[PATCH 5/7] commands: devlookup: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 commands/devlookup.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/commands/devlookup.c b/commands/devlookup.c
index ffd6afbaba..bc9bd94614 100644
--- a/commands/devlookup.c
+++ b/commands/devlookup.c
@@ -25,7 +25,7 @@ static int do_devlookup(int argc, char *argv[])
 {
const char *variable = NULL, *devicefile, *paramname;
struct cdev *cdev;
-   int opt;
+   int opt, ret;
 
while ((opt = getopt(argc, argv, "v:")) > 0) {
switch(opt) {
@@ -43,7 +43,7 @@ static int do_devlookup(int argc, char *argv[])
 
devicefile = devpath_to_name(devicefile);
 
-   cdev = cdev_by_name(devicefile);
+   cdev = cdev_open_by_name(devicefile, O_RDONLY);
if (!cdev) {
printf("devlookup: cdev %s not found\n", devicefile);
return -ENOENT;
@@ -51,13 +51,18 @@ static int do_devlookup(int argc, char *argv[])
 
if (!cdev->dev) {
printf("devlookup: cdev %s not associated with a device\n", 
devicefile);
-   return -ENODEV;
+   ret = -ENODEV;
+   goto out;
}
 
if (paramname)
-   return report(variable, dev_get_param(cdev->dev, paramname));
+   ret = report(variable, dev_get_param(cdev->dev, paramname));
+   else
+   ret = report(variable, dev_name(cdev->dev));
+out:
+   cdev_close(cdev);
 
-   return report(variable, dev_name(cdev->dev));
+   return ret;
 }
 
 BAREBOX_CMD_HELP_START(devlookup)
-- 
2.39.2




[PATCH 1/7] ARM: Freescale i.MX23 evk: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c 
b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index d4de99eafb..b10a6e8dcd 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -52,22 +52,21 @@ static struct fsl_usb2_platform_data usb_pdata = {
  */
 static int register_persistent_environment(void)
 {
-   struct cdev *cdev;
+   struct cdev *cdev, *env;
 
/*
 * The imx23-olinuxino only has one MCI card socket.
 * So, we expect its name as "disk0".
 */
-   cdev = cdev_by_name("disk0");
+   cdev = cdev_open_by_name("disk0", O_RDONLY);
if (cdev == NULL) {
pr_err("No MCI card preset\n");
return -ENODEV;
}
-
-
+   cdev_close(cdev);
 
/* MCI card is present, also a useable partition on it? */
-   cdev = cdev_by_name("disk0.1");
+   cdev = cdev_open_by_name("disk0.1", O_RDONLY);
if (cdev == NULL) {
pr_err("No second partition available\n");
pr_info("Please create at least a second partition with"
@@ -76,8 +75,10 @@ static int register_persistent_environment(void)
}
 
/* use the full partition as our persistent environment storage */
-   cdev = devfs_add_partition("disk0.1", 0, cdev->size,
+   env = devfs_add_partition("disk0.1", 0, cdev->size,
DEVFS_PARTITION_FIXED, "env0");
+   cdev_close(cdev);
+
return PTR_ERR_OR_ZERO(cdev);
 }
 
-- 
2.39.2




[PATCH 7/7] bootm: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 common/bootm.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index c851ab0456..357537c54e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -760,7 +760,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 
if (bootm_data->root_dev) {
const char *root_dev_name = 
devpath_to_name(bootm_data->root_dev);
-   const struct cdev *root_cdev = 
cdev_by_name(root_dev_name);
+   struct cdev *root_cdev = 
cdev_open_by_name(root_dev_name, O_RDONLY);
 
rootarg = cdev_get_linux_rootarg(root_cdev);
if (!rootarg) {
@@ -773,6 +773,9 @@ int bootm_boot(struct bootm_data *bootm_data)
pr_err("%s doesn't have a PARTUUID, 
cannot set root= option\n",
root_dev_name);
}
+
+   if (root_cdev)
+   cdev_close(root_cdev);
} else {
rootarg = path_get_linux_rootarg(data->os_file);
}
-- 
2.39.2




[PATCH 4/7] ARM: Rockchip: use cdev_open_by_name()

2024-05-16 Thread Sascha Hauer
cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer 
---
 arch/arm/mach-rockchip/bbu.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/bbu.c b/arch/arm/mach-rockchip/bbu.c
index f15b32937c..7715540863 100644
--- a/arch/arm/mach-rockchip/bbu.c
+++ b/arch/arm/mach-rockchip/bbu.c
@@ -43,6 +43,7 @@ static int rockchip_bbu_mmc_handler(struct bbu_handler 
*handler,
int ret, fd, wr0, wr1;
loff_t space;
const char *cdevname;
+   struct cdev *cdev;
 
filetype = file_detect_type(data->image, data->len);
if (filetype != filetype_rockchip_rkns_image) {
@@ -60,7 +61,12 @@ static int rockchip_bbu_mmc_handler(struct bbu_handler 
*handler,
if (ret)
return ret;
 
-   space = cdev_unallocated_space(cdev_by_name(cdevname));
+   cdev = cdev_open_by_name(cdevname, O_RDONLY);
+   if (!cdev)
+   return -ENOENT;
+
+   space = cdev_unallocated_space(cdev);
+   cdev_close(cdev);
 
if (space < IMG_OFFSET_0 + data->len) {
if (!bbu_force(data, "Unallocated space on %s (%lld) is too 
small for one image\n",
-- 
2.39.2