Commit Graph

26 Commits

Author SHA1 Message Date
Joseph Chen 2c655b73ba lib: sysmem: update help of "sysmem_search" command
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Ie747d258fa00301c488f5747cf729c242e4d6033
2020-11-12 13:12:09 +00:00
Joseph Chen 68cca28cd2 sysmem: add cmd "sysmem_search" to find available region
If the user can't make sure where the region is available
and safe for use, this command handles it.

Rename commands with prefix: sysmem_xxx.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I37ea76bf33a3fcb8c16baeecae3980d746775ec7
2020-02-28 11:36:49 +08:00
Joseph Chen 90fca8097f sysmem: fix invisiable region boundary
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I1677891796646cf3e1db3aef836921051386a0e0
2020-02-28 11:22:04 +08:00
Joseph Chen c01d448924 sysmem: simplify the memblk name
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Icfe908ade21d1d8f568db796298f67ba9f013da6
2020-02-28 11:22:04 +08:00
Joseph Chen 64c9242ba7 sysmem: add FIT image memory block
The same feature with AVB memory block.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I1aff5ef703d16852b4bc0a0887b037476464034c
2020-01-16 11:14:13 +08:00
Joseph Chen 1ce69de6f2 lib: sysmem: promise sysmem_alloc_by_name() alloc cacheline align buffer
This function is called to alloc buffer for storage driver
access, make sure the address is cacheline align.

Also better for any module which calls it.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I520d16ea28764671eb566cc96cab744ca6b13fc2
2019-12-24 21:04:55 +08:00
Joseph Chen bcf005ba08 lib: sysmem: no need to increase alloc size when base is 0
Change-Id: Ia716956e1a0e980330d6a7f7eb6c89f91e133ddf
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-04 10:23:52 +08:00
Joseph Chen d65bf0c630 lib: sysmem: fix alloc failed at 0x0 address
The 0x0 address is usually allocated by 32-bit uncompressed kernel
and this alloc action is just a peek. Due to LMB core doesn't support
alloc at 0x0 address, we have to alloc the memblk backword a few bytes.

This patch is mainly to avoid fail message from sysmem/LMB.

Change-Id: I894ae2252a30a7690d10899484266191dfb12d15
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-10-31 16:39:43 +08:00
Joseph Chen acffe33271 lib: sysmem: add sysmem_alloc_by_name() interface
Change-Id: I9e2fd6d99fdc487396dd9619dc54567bcd2ba242
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-22 14:23:50 +08:00
Joseph Chen 50226c8f95 lib: sysmem: optimise alloc policy
- Allow request region alloc within the first invisiable region reserved by
  bidram when request region has flags M_ATTR_IGNORE_INVISIBLE. This is a
  workaround for some firmware memory layout, eg: on RK3308-AArch32, the ATF
  region is 0~1M(same as RK3308-AArch64), but the kernel would like to alloc
  at 0x00058000.

- Always make kernel reserved-memory alloc successfully and check overlap
  with invisible and sysmem allocated regions in sysmem_overflow_check()
  before bootm. This makes alloc policy more easier.

Change-Id: I533c710a6e69bd930befda441b9ec64415e3f408
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-22 14:23:50 +08:00
Joseph Chen 2c66f6f37e lib: sysmem: add sysmem overflow check support
Change-Id: Ifcb6e8cd59656b133f56115d104a1bba017c7c1b
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-26 11:23:12 +08:00
Joseph Chen 556bbbe436 lib: sysmem: add M_ATTR_CACHELINE_ALIGN support
If alloc buffer for storage read/write should be aligned to
cacheline size, please add the M_ATTR_CACHELINE_ALIGN flag
for this region.

Change-Id: I1e5d46405ddacfadd1cdb4670f943996d9b66426
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-26 11:23:03 +08:00
Joseph Chen 598774ec05 lib: sysmem: add optimization for input base and M_ATTR_PEEK
- handle the case: the input base is 0;
- ignore the head region which can't visible for M_ATTR_PEEK;

Change-Id: I2c3609b9457a5e2e429e849228301bfee0e4c9b0
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-28 20:30:36 +08:00
Joseph Chen 661cbb0b92 lib: sysmem: goto out when alloc failed
Change-Id: I8f6fd82f7367c49596475a88bafd19137e2f2f7c
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-15 11:02:14 +08:00
Joseph Chen 3bee194f53 lib: sysmem: add sysmem_can_alloc() interface
Check if the region can be sysmem allocated.

Change-Id: I26a524c1597bee65ab1282da5ec373b9603866ba
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen f6e1530165 lib: sysmem: support avb android memblk sysmem alloc
Because avb android image usually needs a large memory buffer,
always alloc avb android memblk right after U-Boot stack is a
better choice to avoid memblk overlap with others.

Since we have overflow protect magic for U-Boot stack, so we add
a pad(4KB) between them.

Change-Id: I72655d022f7e82f1ed9fbb381424d04bc86ccf6a
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen dcb404a677 lib: sysmem: add sysmem_alloc() interface
Change-Id: I3ae1fe618ba1bb9c7924bb9816884eb26927dc1e
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen efda1f1db3 lib: sysmem: support M_ATTR_PEEK for memblk
- always return successful for M_ATTR_PEEK;
- add code comments;

Change-Id: I3c7f939ac61d8da5948978de4e70f17576748c91
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 17:08:36 +08:00
Joseph Chen 305d8903e0 lib: sysmem: improve kernel reserved-memory alloc
- If the region is out of avaiable dram bank, return success;
- region can override allocated memblk with attr M_ATTR_OVERLAP;

Change-Id: I02171cdb51462e9cec3dd955ae3e0aaaa0ee7afd
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-04-03 10:29:03 +08:00
Joseph Chen 2cb995bc2e lib: sysmem: allow alloc subset of an allocated memblk
Change-Id: I171c5978faf6fc1b3e95cc46c55a2adfe6df0176
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-29 18:29:19 +08:00
Joseph Chen a90f2861de lib: sysmem: fix NULL attr.name
Change-Id: I93744c28668d1533ec2bcdaafc9198d8557284a1
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-27 08:59:47 +08:00
Joseph Chen 6e15146eff lib: sysmem: refactor code
- import memblk id to manage memory blocks;
- change "sysmem_property" to generic "memblock";
- use alloc instead of reserve for all memory blocks;
- clean up and fix some logic;
- add U-Boot cmd for sysmem;

Change-Id: I614223ce3bf97a7b3566412a9d1864fb30b68fd8
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +08:00
Joseph Chen 727ebf6de1 lib: sysmem: alloc base and size must be 4-byte aligned
Change-Id: Icf59ee6522f2e0793605b03b0bcf05b58585069f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-04 09:21:58 +08:00
Joseph Chen 2c9d117912 sysmem: fdt: reserve more CONFIG_SYS_FDT_PAD size for fdt
Sometimes, framework or user would call fdt_increase_size() to update
fdt size, it's better reserve more space to avoid sysmem gives the fdt
region overflow report.

The CONFIG_SYS_FDT_PAD default value is sync with bootm framework
in: common/image-fdt.c

Change-Id: I363e9a4182e13b1628a76666acd8272d25db659d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-19 14:37:36 +08:00
Joseph Chen 3befe43d90 lib: sysmem: ignore sysmem reserve warning
Change-Id: I970da1456388f825a351dc26d725bb3ba10d41a4
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-19 09:10:17 +08:00
Joseph Chen ffa8f8b76e lib: introduce sysmem for permanent memory management
U-Boot provides MALLOC for runtime temporary memory management and
LMB for bootm memory management. There is not a mechanism for permanent
memory management. so that the memory blocks are easy to overlap with
each other.

What does permanent memory mean ?
 - The memory can't be touched by U-Boot(ATF/OPTEE/SHM/kernel-reserved, etc);
 - The memory occupied even in kernel, such as some firmware load buffer;

This patch introduces sysmem to do permanent memory management, which
implements base on LMB. It provides memory block (pool):
 - init;
 - add;
 - alloc;
 - free;
 - reserve;
 - stat;
 - overflow check;

Here is an example for RK3399 sysmem boot stat(assume the "fdt" region is Overflow)
called by sysmem_dump_all():

sysmem_dump_all:
    ------------------------------------------------------
    memory.rgn[0].base     = 0x00000000
                 .size     = 0x00000000
    memory.rgn[1].base     = 0x00200000
                 .size     = 0x08200000
    memory.rgn[2].base     = 0x0a200000
                 .size     = 0x75e00000

    memory.total           = 0x7e000000 (2016 MiB. 0 KiB)
    ------------------------------------------------------
    reserved.rgn[0].name   = "ATF"
                   .base   = 0x00000000
                   .size   = 0x00100000
    reserved.rgn[1].name   = "PSTORE/ATAGS/SHM"
                   .base   = 0x00100000
                   .size   = 0x00100000
    reserved.rgn[2].name   = "OP-TEE"
                   .base   = 0x08400000
                   .size   = 0x01e00000
    reserved.rgn[3].name   = "U-Boot"
                   .base   = 0x71be03c0
                   .size   = 0x0e41fc40
    reserved.rgn[4].name   = "secure-memory@20000000"
                   .base   = 0x20000000
                   .size   = 0x10000000

    reserved.total         = 0x2041fc40 (516 MiB. 127 KiB)
    ------------------------------------------------------
    allocated.rgn[0].name  = "fdt"      (Overflow)
                    .base  = 0x01f00000
                    .size  = 0x00009704
    allocated.rgn[1].name  = "kernel"
                    .base  = 0x0027c000
                    .size  = 0x0129da04
    allocated.rgn[2].name  = "ramdisk"
                    .base  = 0x0a200000
                    .size  = 0x001e6c04

    allocated.total        = 0x0148dd0c (20 MiB. 567 KiB)
    ------------------------------------------------------
    LMB.reserved[0].base   = 0x00000000
                   .size   = 0x00200000
    LMB.reserved[1].base   = 0x0027c000
                   .size   = 0x0129da04
    LMB.reserved[2].base   = 0x01f00000
                   .size   = 0x00009704
    LMB.reserved[3].base   = 0x08400000
                   .size   = 0x01fe6c04
    LMB.reserved[4].base   = 0x20000000
                   .size   = 0x10000000
    LMB.reserved[5].base   = 0x71be03c0
                   .size   = 0x0e41fc40

    reserved.core.total    = 0x218ad94c (536 MiB. 694 KiB)
    ------------------------------------------------------

Change-Id: If63b7abed2cdd3c054719511fcceed733ddf606d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-24 15:33:12 +08:00