11/*
2- * Copyright (C) 2014-2019 Daniel Rossier <daniel.rossier@heig-vd.ch>
2+ * Copyright (C) 2014-2026 Daniel Rossier <daniel.rossier@heig-vd.ch>
33 *
44 *
55 * This program is free software; you can redistribute it and/or modify
@@ -55,7 +55,13 @@ static void init_dev_info(dev_t *dev)
5555 dev -> fdt = 0 ;
5656}
5757
58- /* Get memory informations from a device tree */
58+ /**
59+ * @brief Get memory informations from a device tree
60+ *
61+ * @param fdt Virtual address of the device tree
62+ * @param info Memory info structure which will be filled up by this function
63+ * @return int Offset of the memory node in the device tree
64+ */
5965int get_mem_info (const void * fdt , mem_info_t * info )
6066{
6167 int offset ;
@@ -81,14 +87,17 @@ int get_mem_info(const void *fdt, mem_info_t *info)
8187
8288 /* For some platform, address-cells and size-cells are set to 2 (64-bit)
8389 * even for a 32-bit platform, probably to support LPAE.
90+ * Additionally, on Raspberry Pi 4, the device tree has its memory node
91+ * with a 64-bit address cell and a 32-bit size cell. That's why we need
92+ * to consider a 12 bytes <reg> property.
8493 */
8594
8695 if (prop ) {
8796 if (prop_len == 8 ) {
8897 info -> phys_base = fdt32_to_cpu (((const fdt32_t * ) prop -> data )[0 ]);
8998 info -> size = fdt32_to_cpu (((const fdt32_t * ) prop -> data )[1 ]);
9099 } else {
91- BUG_ON (prop_len != 16 );
100+ BUG_ON (( prop_len != 16 ) && ( prop_len != 12 ) );
92101
93102 /* Keep a possible conversion from 64-bit to 32-bit if the address & size are
94103 * on 64-bit for aarch32 platforms.
@@ -110,10 +119,15 @@ int get_mem_info(const void *fdt, mem_info_t *info)
110119
111120 info -> phys_base = fdt64_to_cpu (val );
112121
113- for (i = 0 ; i < 8 ; i ++ )
114- * (((char * ) & val ) + i ) = * ptr ++ ;
115-
116- info -> size = fdt64_to_cpu (val );
122+ if (prop_len == 16 ) {
123+ for (i = 0 ; i < 8 ; i ++ )
124+ * (((char * ) & val ) + i ) = * ptr ++ ;
125+ info -> size = fdt64_to_cpu (val );
126+ } else {
127+ for (i = 0 ; i < 4 ; i ++ )
128+ * (((char * ) & val ) + i ) = * ptr ++ ;
129+ info -> size = fdt32_to_cpu (val );
130+ }
117131
118132#endif /* !CONFIG_ARCH_ARM32 */
119133 }
0 commit comments