Logical memory blocks

enum lmb_flags

definition of memory region attributes

Constants

LMB_NONE

no special request

LMB_NOMAP

don’t add to mmu configuration

LMB_NOOVERWRITE

the memory region cannot be overwritten/re-reserved

LMB_NONOTIFY

do not notify other modules of changes to this memory region

struct lmb_region

Description of one region.

Definition

struct lmb_region {
  phys_addr_t base;
  phys_size_t size;
  enum lmb_flags flags;
};

Members

base

Base address of the region.

size

Size of the region

flags

memory region attributes

struct lmb

The LMB structure

Definition

struct lmb {
  struct alist free_mem;
  struct alist used_mem;
  bool test;
};

Members

free_mem

List of free memory regions

used_mem

List of used/reserved memory regions

test

Is structure being used for LMB tests

int lmb_init(void)

Initialise the LMB module

Parameters

void

no arguments

Description

Initialise the LMB lists needed for keeping the memory map. There are two lists, in form of alloced list data structure. One for the available memory, and one for the used memory. Initialise the two lists as part of board init. Add memory to the available memory list and reserve common areas by adding them to the used memory list.

Return

0 on success, -ve on error

void lmb_add_memory(void)

Add memory range for LMB allocations

Parameters

void

no arguments

Description

Add the entire available memory range to the pool of memory that can be used by the LMB module for allocations.

Return

None

long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags)

Reserve one region with a specific flags bitfield.

Parameters

phys_addr_t base

base address of the memory region

phys_size_t size

size of the memory region

enum lmb_flags flags

flags for the memory region

Return

0 if OK, > 0 for coalesced region or a negative error code.

phys_addr_t lmb_alloc_addr_flags(phys_addr_t base, phys_size_t size, uint flags)

Allocate specified memory address with specified attributes

Parameters

phys_addr_t base

Base Address requested

phys_size_t size

Size of the region requested

uint flags

Memory region attributes to be set

Description

Allocate a region of memory with the attributes specified through the parameter. The base parameter is used to specify the base address of the requested region.

Return

base address on success, 0 on error

int lmb_is_reserved_flags(phys_addr_t addr, int flags)

test if address is in reserved region with flag bits set

Parameters

phys_addr_t addr

address to be tested

int flags

bitmap with bits to be tested

Description

The function checks if a reserved region comprising addr exists which has all flag bits set which are set in flags.

Return

1 if matching reservation exists, 0 otherwise

long lmb_free_flags(phys_addr_t base, phys_size_t size, uint flags)

Free up a region of memory

Parameters

phys_addr_t base

Base Address of region to be freed

phys_size_t size

Size of the region to be freed

uint flags

Memory region attributes

Description

Free up a region of memory.

Return

0 if successful, -1 on failure

int io_lmb_setup(struct lmb *io_lmb)

Initialize LMB struct

Parameters

struct lmb *io_lmb

IO LMB to initialize

Return

0 on success, negative error code on failure

void io_lmb_teardown(struct lmb *io_lmb)

Tear LMB struct down

Parameters

struct lmb *io_lmb

IO LMB to teardown

long io_lmb_add(struct lmb *io_lmb, phys_addr_t base, phys_size_t size)

Add an IOVA range for allocations

Parameters

struct lmb *io_lmb

LMB to add the space to

phys_addr_t base

Base Address of region to add

phys_size_t size

Size of the region to add

Description

Add the IOVA space [base, base + size] to be managed by io_lmb.

Return

0 if the region addition was successful, -1 on failure

phys_addr_t io_lmb_alloc(struct lmb *io_lmb, phys_size_t size, ulong align)

Allocate specified IO memory address with specified alignment

Parameters

struct lmb *io_lmb

LMB to alloc from

phys_size_t size

Size of the region requested

ulong align

Required address and size alignment

Description

Allocate a region of IO memory. The base parameter is used to specify the base address of the requested region.

Return

base IO address on success, 0 on error

long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size)

Free up a region of IOVA space

Parameters

struct lmb *io_lmb

LMB to return the IO address space to

phys_addr_t base

Base Address of region to be freed

phys_size_t size

Size of the region to be freed

Description

Free up a region of IOVA space.

Return

0 if successful, -1 on failure