summaryrefslogtreecommitdiffstats
path: root/common/memory.c
Commit message (Collapse)AuthorAgeFilesLines
* memory: Fix reserve_sdram_region() return valueSascha Hauer2024-01-101-2/+2
| | | | | | | | | __request_sdram_region() returns NULL on failure, so test for this value and not for an error pointer. Also all callers of reserve_sdram_region() expect NULL on failure, so return that value in case of failure. Link: https://lore.barebox.org/20240109161527.3237581-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: align memory reservation to page boundariesAhmad Fatoum2023-11-101-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | barebox remaps all reserved entries as uncached to avoid speculative access into the described regions using remap_range. The ARM implementation requires buffers to be page aligned, which we can't assume unconditionally. For this reason, reserve_sdram_region will align region start and size before mapping uncached. __mmu_init called later on, will remap everything outside the reserved entries cached, e.g. to cache additional DRAM not known at PBL time. No realignment will happen then though triggering the BUG(!IS_ALIGNED) in ARM's arch_remap_range. By moving the realignment before __request_sdram_region(), we ensure that no misaligned memory regions will be passed to arch_remap_range by core code. This fixes chainloading barebox from an older barebox[1] that reserves the FDT prior to relocation. [1]: anything prior to 0b6b146a5508 ("fdt: Do not reserve device tree blob") Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231109113012.1063774-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: remap immediately in reserve_sdram_region()Sascha Hauer2023-10-231-0/+26
| | | | | | | | | | | | | | | | | | | | | | | reserve_sdram_region() has the purpose of reserving SDRAM regions from being accessed by the CPU. Right now this remaps the reserved region during MMU setup. Instead of doing this, remap the region immediately. The MMU may be enabled already by early code. This means that when reserve_sdram_region() is called with MMU enabled, we can't rely on the region being mapped non-executable right after the call, but only when __mmu_init() is executed. This patch relaxes this constraint. Also, reserve_sdram_region() may now be called after __mmu_init() is executed. So far we silently aligned the remapped region to page boundaries, but really calling reserve_sdram_region() with non page aligned boundaries has undesired effects on the regions between the reserved region and the page boundaries. Stay with this behaviour, but warn the user when the to be reserved region is not page aligned as this really shouldn't happen. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: fix recently broken memory bank fusingAhmad Fatoum2022-10-181-0/+1
| | | | | | | | | | | | | | | | | | barebox will fuse overlapping memory banks to avoid the common issue of the device tree being modified upstream to contain a minimum RAM size that would then conflict with a RAM size barebox determines by querying the memory controller. This was recently broken, because we changed memory banks to have IORESOURCE_MEM in their flags field, but resource_contains() used to compare regions won't return true if memory type differs. Fix this by settings .flags = IORESOURCE_MEM for the new resource as well. Reported-by: Ian Abbott <abbotti@mev.co.uk> Fixes: d0b5f6bde15b ("of: reserved-mem: reserve regions prior to mmu_initcall()") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Tested-by: Ian Abbott <abbotti@mev.co.uk> Link: https://lore.barebox.org/20221017133859.299705-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: reserved-mem: reserve regions prior to mmu_initcall()Ahmad Fatoum2022-08-181-12/+3
| | | | | | | | | | | | Now that we both have a way to mark SDRAM regions requested as reserved and an postmem_initcall() to do this add, change device tree memory reservation parsing code to use them instead of requesting them as normal memory at coredevice_initcall() level. This allows us to reuse this information for MMU setup in the follow-up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220817114244.1810531-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* init: define new postmem_initcall()Ahmad Fatoum2022-08-181-1/+1
| | | | | | | | | | | | | | | | | | | Memory banks are added in mem_initcall() and are used in mmu_initcall() which directly follows it to set caching attributes for the banks. Code that requires memory banks to be registered, thus has to use mmu_initcall(), but this is not possible for code that reliably needs to run before MMU init: We need to give board code and device tree parsing code the chance to reserve_sdram_region parts of SDRAM that contain secure firmware to avoid speculative execution into them once the MMU is turned on. For this reason, define a new postmem_initcall() level and already use it for add_mem_devices, which has nothing to do with mmu_initcall. Another user that can't be mmu_initcall() will follow in a later commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220817114244.1810531-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: allow requesting SDRAM regions with custom flagsAhmad Fatoum2022-08-181-3/+5
| | | | | | | | | | | | Now that __request_region accepts a flag parameter, define __request_sdram_region, which also accepts a flag parameter and passes it through. The default flags for request_sdram_region() will be IORESOURCE_MEM as that ensures resource_contains behaves correctly when comparing against another memory resource. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220817114244.1810531-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: add flags parameter to __request_regionAhmad Fatoum2022-08-181-2/+2
| | | | | | | | | | | | | __request_region allocates a child resource within the parent resource, which so far always had a flags field of zero. Later commits will use the flags field to mark reserved SDRAM regions, so MMU init code can take that into consideration and ensure that CPU doesn't speculate into these regions and risk aborts. Prepare for this by giving __request_region a flags parameter. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220817114244.1810531-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: request reserved memory regions so other code can'tAhmad Fatoum2022-06-151-3/+18
| | | | | | | | | | | Add a new of_reserved_mem_walk that can be used to request reserved memory regions. This avoids e.g. bootm trying to place the kernel into a reserved region. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220609111810.2454588-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: fuse overlapping memory banksAhmad Fatoum2021-06-021-4/+45
| | | | | | | | | | | | | | | | | | | | | | | | | Some ARM subarchitectures read back RAM size from the SDRAM controller and use the info to register memory banks. If an overlapping memory region is already registered, e.g. via device tree /memory, this second registration will fail. This is especially annoying as it can regress after a device tree sync: - Kind soul updates upstream device tree to describe minimal available RAM across hardware variants - barebox PBL has enough info about the board to set up larger RAM size and relocates barebox to the end of the RAM - barebox proper starts with new device tree and is upset to find itself outside of registered memory Account for this by growing the existing bank if a bank to be added happens to overlap it. As a special case, if the existing bank completely contains the new memory bank, the function is a no-op. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210531071239.30653-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: memory: allocate all memory devices at onceAhmad Fatoum2021-06-021-4/+13
| | | | | | | | | | | | | | | | | Follow-up commit will fuse overlapping RAM banks. As all memory is supposed to be registered during mem_initcall or before, we can postpone device creation to mmu_initcall, so we can directly allocate devices spanning the correct region. The mem driver and the devinfo command are the only consumers of these devices, so it's ok to register the devices at mmu_initcall. While at it, drop the struct memory_bank::dev member. It's unused anywhere. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210531071239.30653-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: enable use of iomem command on EFI systemsAhmad Fatoum2021-04-131-1/+1
| | | | | | | | | | | | iomem was so far unimplemented for EFI, because barebox didn't know what to put there as the UEFI implementation does the heavy lifting. Add an initcall that uses the EFI get_memory_map entry point to remedy this. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.pengutronix.de/20210410110355.2105448-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-12/+1
| | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* tlsf: Update to v3.1Sascha Hauer2020-06-161-2/+2
| | | | | | | | This updates the tlsf implementation to v3.1. This is taken from commit deff9ab509341f264addbd3c8ada533678591905 in https://github.com/mattconte/tlsf.git. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: of_fixup: adapt to new memory layoutMarco Felsch2019-02-121-18/+57
| | | | | | | | | | | | | | | Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup won't work correctly anymore, because instead of adapting the extisting one the fixup creates a new node and keeps the old (maybe incorrect) node. To be compatible with the old and new layout delete the found memory node and create a new one. The new node follows the new @<reg> style. The patch also renames the node parameter to make it clearer. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: Add functions to find free RAMSascha Hauer2018-04-041-0/+51
| | | | | | | The bootm code needs to put the Kernel image and initrd into free RAM. Add some functions to find free RAM chunks to help this code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Use of_property_write_string() where appropriateSascha Hauer2017-03-301-1/+1
| | | | | | | Replace users which use of_set_property() to set a property to a string with of_property_write_string(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* efi: move x86 efi boot support to x86 archJean-Christophe PLAGNIOL-VILLARD2017-02-271-1/+1
| | | | | | | prepare to drop the efi arch as efi boot up is not arch sepecific Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* malloc: Add a function to detect if malloc pool is already initializedSascha Hauer2015-01-051-0/+8
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: Let request_iomem_region return an error pointerSascha Hauer2014-09-161-2/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: Let __request_region return an error pointerSascha Hauer2014-09-161-1/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add initial EFI architecture supportSascha Hauer2014-07-161-1/+1
| | | | | | | This adds support for running barebox in an EFI environment on X86 PC hardware. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: Allow for I/O mapped I/OMichel Stam2014-04-081-1/+2
| | | | | | | | Rework the current framework so that I/O mapped I/O resources are also possible. Signed-off-by: Michel Stam <michel@reverze.net> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Add a context pointer to fixup functionsSascha Hauer2013-11-061-2/+2
| | | | | | | If drivers want to fixup their specific instance they need some context to know which instance they have to fixup. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: remove unused libfdtSascha Hauer2013-03-061-1/+0
| | | | | | | Now that we are completely independent of libfdt remove the unused code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: memory: Use of_write_numberSascha Hauer2013-03-061-19/+6
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: fixup unflattened devicetreeSascha Hauer2013-03-061-34/+14
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* barebox-data: add barebox-data sectionsAlexander Aring2013-01-181-0/+4
| | | | | | | | Add barebox-data section in arm branch to get complete barebox regions in sdram regions tree. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: fix size address calculationAlexander Aring2013-01-141-2/+2
| | | | | | | | | | | | | | | | | | | Fix size address calculation. Global variables from <asm/sections.h> which are defined in linker script *.lds files for end addresses has already a +1 calculation. For example: stext = 0x100 with a size about 0x50 will result a etext = 0x150. In this case a correct size calculation is (etext - stext) = 0x50. In function 'request_sdram_region' the end address will be calculated with (start + size - 1) which result a correct end address of 0x149 in this example. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: return error in barebox_add_memory_bankSascha Hauer2012-10-081-3/+5
| | | | | | | | When a memory bank is already registered, return an error code instead of throwing a bug. This can happen if a board has registered a memory bank and the same bank is then probed from the devicetree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-3/+0
| | | | | | | The FSF address has changed in the past. Instead of updating it each time the address changes, just drop it completely treewide. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* resource: store 'end' instead of 'size' in struct resourceSascha Hauer2012-07-011-2/+2
| | | | | | | | | | Storing the size instead of the resource end in struct resource was a mistake. 'size' ranges from 0 to UINT[32|64]_MAX + 1 which obviously leads to problems. 'end' on the other hand will never exceed UINT[32|64]_MAX. Also this way we can express a iomem region covering the whole address space. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: memory: fix off-by-one in tlsf_createMarc Kleine-Budde2012-04-241-1/+1
| | | | | Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add tlsf-based malloc implementationAntony Pavlov2011-12-231-0/+8
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fix "no previous prototype for 'sbrk'" warningAntony Pavlov2011-12-091-0/+1
| | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* memory: do not try to reserve iomem on sandboxSascha Hauer2011-12-071-1/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* register sdram as resourcesSascha Hauer2011-12-041-0/+58
| | | | | | | Also, request the sdram regions used by the barebox binary, bss, malloc space and stack. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* oftree: add fixup for memory nodesSascha Hauer2011-10-191-0/+80
| | | | | | | | Thanks to a common memory handling barebox knows the sdram banks and sizes, so we can add a common fixup functions for the nodes in the devicetree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* introduce generic memory bank handlingSascha Hauer2011-09-231-0/+18
| | | | | | | | | On arm we have the concept of memory banks which can be registered and iterated over. This is useful for other architectures aswell, so add some generic infrastructure for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* malloc: put common memory functions to seperate fileSascha Hauer2011-04-111-0/+71
These functions are needed independently of the specific malloc implementation, so move them out. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>