mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-13 11:25:14 +00:00
We add a configuration option to set the minimum shared memory size (CONFIG_SHAREDMEM_MINIMUM_SIZE), so that the link will fail if there is not enough IRAM left. Also, we add 2 macros around shared_mem_acquire, that check, at build time, that the shared memory size is sufficient for the allocation: - SHARED_MEM_ACQUIRE_CHECK should be used instead of shared_mem_acquire, when size is known in advance. - SHARED_MEM_CHECK_SIZE should be used when only a maximum size is known. This does not account for "jump tags" that boards often add on jump from RO to RW. Luckily, RW usually does not do verification, and does not need as much shared memory. BRANCH=none BUG=chromium:739771 TEST=make buildall -j, no error Change-Id: Ic4c72938affe65fe8f8bc17ee5111c1798fc536f Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1002713 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
89 lines
2.7 KiB
C
89 lines
2.7 KiB
C
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/*
|
|
* Shared memory interface for Chrome EC.
|
|
*
|
|
* This is intended to supply a relatively large block of memory for use by a
|
|
* task for a relatively short amount of time. For example, verified boot may
|
|
* need a buffer to hold signature data during a verification operation. It is
|
|
* NOT intended for allocating long-term buffers; those should in general be
|
|
* static variables allocated at compile-time. It is NOT a full-featured
|
|
* replacement for malloc() / free().
|
|
*/
|
|
|
|
#ifndef __CROS_EC_SHARED_MEM_H
|
|
#define __CROS_EC_SHARED_MEM_H
|
|
|
|
#include "common.h"
|
|
#include <stddef.h>
|
|
|
|
/**
|
|
* Returns the maximum amount of shared memory which can be acquired, in
|
|
* bytes.
|
|
*/
|
|
int shared_mem_size(void);
|
|
|
|
#define SHARED_MEM_CHECK_SIZE(size) \
|
|
BUILD_ASSERT((size) <= CONFIG_SHAREDMEM_MINIMUM_SIZE)
|
|
|
|
/*
|
|
* Acquires a shared memory area of the requested size in bytes.
|
|
*
|
|
* Doing a sysjump between images will corrupt and/or erase shared memory as
|
|
* jump tags are added and .bss is reinitialized. Due to the way jump tags are
|
|
* added to the end of RAM, shared memory must not be allocated, accessed, or
|
|
* freed after the start of a sysjump (for example, in HOOK_SYSJUMP).
|
|
*
|
|
* @param size Number of bytes requested
|
|
* @param dest_ptr If successful, set on return to the start of the
|
|
* granted memory buffer.
|
|
*
|
|
* @return EC_SUCCESS if successful, EC_ERROR_BUSY if buffer in use, or
|
|
* other non-zero error code.
|
|
*/
|
|
int shared_mem_acquire(int size, char **dest_ptr);
|
|
|
|
#define SHARED_MEM_ACQUIRE_CHECK(size, dest_ptr) \
|
|
({ \
|
|
SHARED_MEM_CHECK_SIZE(size); \
|
|
shared_mem_acquire((size), (dest_ptr)); \
|
|
})
|
|
|
|
/**
|
|
* Releases a shared memory area previously allocated via shared_mem_acquire().
|
|
*/
|
|
void shared_mem_release(void *ptr);
|
|
|
|
/*
|
|
* This structure is allocated at the base of the free memory chunk and every
|
|
* allocated buffer.
|
|
*/
|
|
struct shm_buffer {
|
|
struct shm_buffer *next_buffer;
|
|
struct shm_buffer *prev_buffer;
|
|
size_t buffer_size;
|
|
};
|
|
|
|
#ifdef TEST_SHMALLOC
|
|
|
|
/*
|
|
* When in test mode, all possible paths in the allocation/free functions set
|
|
* unique bits in an integer bitmap.
|
|
*
|
|
* The test function generates random allocation and free requests and
|
|
* monitors the bitmap until all bits have been set, which indicates that all
|
|
* possible paths have been executed.
|
|
*/
|
|
|
|
#define MAX_MASK_BIT 24
|
|
#define ALL_PATHS_MASK ((1 << (MAX_MASK_BIT + 1)) - 1)
|
|
void set_map_bit(uint32_t mask);
|
|
extern struct shm_buffer *free_buf_chain;
|
|
extern struct shm_buffer *allocced_buf_chain;
|
|
#endif
|
|
|
|
#endif /* __CROS_EC_SHARED_MEM_H */
|