app_shmem: delete parallel API for domains

The app shared memory macros for declaring domains provide
no value, despite the stated intentions.

Just declare memory domains using the standard APIs for it.

To support this, symbols declared for app shared memory
partitions now are struct k_mem_partition, which can be
passed to the k_mem_domain APIs as normal, instead of the
app_region structs which are of no interest to the end
user.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-01-28 02:24:44 -08:00 committed by Andrew Boie
commit f278f31da1
4 changed files with 40 additions and 95 deletions

View file

@ -46,19 +46,9 @@ where "part0" is the name then used to refer to that partition.
This macro only creates a function and necessary data structures for This macro only creates a function and necessary data structures for
the later "initialization". the later "initialization".
To create a memory domain for the partition, the macro appmem_domain(dom0) Once the partition is initialized, the standard memory domain APIs may
is called where "dom0" is the name then used for the memory domain. be used to add it to domains; the declared name is a k_mem_partition
To initialize the partition (effectively adding the partition symbol.
to a linked list), appmem_init_part_part0() is called. This is followed
by appmem_init_app_memory(), which walks all partitions in the linked
list and calculates the sizes for each partition.
Once the partition is initialized, the domain can be
initialized with appmem_init_domain_dom0(part0) which initializes the
domain with partition part0.
After the domain has been initialized, the current thread
can be added using appmem_add_thread_dom0(k_current_get()).
Example: Example:
@ -67,17 +57,18 @@ Example:
/* create partition at top of file outside functions */ /* create partition at top of file outside functions */
appmem_partition(part0); appmem_partition(part0);
/* create domain */ /* create domain */
appmem_domain(dom0); struct k_mem_domain dom0;
/* assign variables to the domain */ /* assign variables to the domain */
_app_dmem(dom0) int var1; _app_dmem(part0) int var1;
_app_bmem(dom0) static volatile int var2; _app_bmem(part0) static volatile int var2;
int main() int main()
{ {
appmem_init_part_part0(); appmem_init_part_part0();
appmem_init_app_memory(); appmem_init_app_memory();
appmem_init_domain_dom0(part0); k_mem_domain_init(&dom0, 0, NULL)
appmem_add_thread_dom0(k_current_get()); k_mem_domain_add_partition(&dom0, part0);
k_mem_domain_add_thread(&dom0, k_current_get());
... ...
} }
@ -89,12 +80,6 @@ app_macro_support.h:
FOR_EACH(appmem_partition, part0, part1, part2); FOR_EACH(appmem_partition, part0, part1, part2);
or, for multiple domains, similarly:
.. code-block:: c
FOR_EACH(appmem_domain, dom0, dom1);
Similarly, the appmem_init_part_* can also be used in the macro: Similarly, the appmem_init_part_* can also be used in the macro:
.. code-block:: c .. code-block:: c

View file

@ -55,11 +55,7 @@
struct app_region { struct app_region {
char *dmem_start; char *dmem_start;
char *bmem_start; char *bmem_start;
#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
char *smem_size;
#else
u32_t smem_size; u32_t smem_size;
#endif /* CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT */
u32_t dmem_size; u32_t dmem_size;
u32_t bmem_size; u32_t bmem_size;
struct k_mem_partition *partition; struct k_mem_partition *partition;
@ -75,7 +71,7 @@ struct app_region {
* calculate the region sizes. * calculate the region sizes.
*/ */
#define smem_size_declare(name) extern char data_smem_##name##_size[] #define smem_size_declare(name) extern char data_smem_##name##_size[]
#define smem_size_assign(name) name.smem_size = data_smem_##name##_size #define smem_size_assign(name) name##_region.smem_size = (u32_t)&data_smem_##name##_size
#else #else
#define smem_size_declare(name) #define smem_size_declare(name)
#define smem_size_assign(name) #define smem_size_assign(name)
@ -87,48 +83,17 @@ struct app_region {
smem_size_declare(name); \ smem_size_declare(name); \
_app_dmem_pad(name) char name##_dmem_pad; \ _app_dmem_pad(name) char name##_dmem_pad; \
_app_bmem_pad(name) char name##_bmem_pad; \ _app_bmem_pad(name) char name##_bmem_pad; \
__kernel struct k_mem_partition mem_domain_##name; \ __kernel struct k_mem_partition name; \
__kernel struct app_region name; \ __kernel struct app_region name##_region; \
static inline void appmem_init_part_##name(void) \ static inline void appmem_init_part_##name(void) \
{ \ { \
name.dmem_start = (char *)&data_smem_##name; \ name##_region.dmem_start = (char *)&data_smem_##name; \
name.bmem_start = (char *)&data_smem_##name##b; \ name##_region.bmem_start = (char *)&data_smem_##name##b; \
smem_size_assign(name); \ smem_size_assign(name); \
sys_dlist_append(&app_mem_list, &name.lnode); \ sys_dlist_append(&app_mem_list, &name##_region.lnode); \
mem_domain_##name.start = (u32_t) name.dmem_start; \ name.start = (u32_t) name##_region.dmem_start; \
mem_domain_##name.attr = K_MEM_PARTITION_P_RW_U_RW; \ name.attr = K_MEM_PARTITION_P_RW_U_RW; \
name.partition = &mem_domain_##name; \ name##_region.partition = &name; \
}
/*
* A wrapper around the k_mem_domain_* functions. Goal here was
* to a) differentiate these operations from the k_mem_domain*
* functions, and b) to simply the usage and handling of data
* types (i.e. app_region, k_mem_domain, etc).
*/
#define appmem_domain(name) \
__kernel struct k_mem_domain domain_##name; \
static inline void appmem_add_thread_##name(k_tid_t thread) \
{ \
k_mem_domain_add_thread(&domain_##name, thread); \
} \
static inline void appmem_rm_thread_##name(k_tid_t thread) \
{ \
k_mem_domain_remove_thread(thread); \
} \
static inline void appmem_add_part_##name(struct app_region region) \
{ \
k_mem_domain_add_partition(&domain_##name, \
&region.partition[0]); \
} \
static inline void appmem_rm_part_##name(struct app_region region) \
{ \
k_mem_domain_remove_partition(&domain_##name, \
&region.partition[0]); \
} \
static inline void appmem_init_domain_##name(struct app_region region) \
{ \
k_mem_domain_init(&domain_##name, 1, &region.partition); \
} }
/* /*

View file

@ -29,7 +29,7 @@
/* prepare the memory partition structures */ /* prepare the memory partition structures */
FOR_EACH(appmem_partition, part0, part1, part2, part3, part4); FOR_EACH(appmem_partition, part0, part1, part2, part3, part4);
/* prepare the memory domain structures */ /* prepare the memory domain structures */
FOR_EACH(appmem_domain, dom0, dom1, dom2); struct k_mem_domain dom0, dom1, dom2;
/* each variable starts with a name defined in main.h /* each variable starts with a name defined in main.h
* the names are symbolic for the memory partitions * the names are symbolic for the memory partitions
* purpose. * purpose.
@ -99,7 +99,9 @@ _app_ct_d char ctMSG[] = "CT!\n";
void main(void) void main(void)
{ {
struct k_mem_partition *dom1_parts[] = {&part2, &part1, &part3};
struct k_mem_partition *dom2_parts[] = {&part4, &part3};
struct k_mem_partition *dom0_parts[] = {&part0, &part1};
k_tid_t tPT, tENC, tCT; k_tid_t tPT, tENC, tCT;
k_thread_access_grant(k_current_get(), &allforone); k_thread_access_grant(k_current_get(), &allforone);
@ -120,12 +122,9 @@ void main(void)
k_thread_access_grant(tENC, &allforone); k_thread_access_grant(tENC, &allforone);
/* use K_FOREVER followed by k_thread_start*/ /* use K_FOREVER followed by k_thread_start*/
printk("ENC Thread Created %08X\n", (unsigned int) tENC); printk("ENC Thread Created %08X\n", (unsigned int) tENC);
appmem_init_domain_dom1(part2); k_mem_domain_init(&dom1, 3, dom1_parts);
printk("init domain complete\n");
appmem_add_part_dom1(part1);
appmem_add_part_dom1(part3);
printk("Partitions added to dom1\n"); printk("Partitions added to dom1\n");
appmem_add_thread_dom1(tENC); k_mem_domain_add_thread(&dom1, tENC);
printk("dom1 Created\n"); printk("dom1 Created\n");
@ -135,9 +134,8 @@ void main(void)
K_FOREVER); K_FOREVER);
k_thread_access_grant(tPT, &allforone); k_thread_access_grant(tPT, &allforone);
printk("PT Thread Created %08X\n", (unsigned int) tPT); printk("PT Thread Created %08X\n", (unsigned int) tPT);
appmem_init_domain_dom0(part0); k_mem_domain_init(&dom0, 2, dom0_parts);
appmem_add_part_dom0(part1); k_mem_domain_add_thread(&dom0, tPT);
appmem_add_thread_dom0(tPT);
printk("dom0 Created\n"); printk("dom0 Created\n");
tCT = k_thread_create(&ct_thread, ct_stack, STACKSIZE, tCT = k_thread_create(&ct_thread, ct_stack, STACKSIZE,
@ -146,9 +144,8 @@ void main(void)
K_FOREVER); K_FOREVER);
k_thread_access_grant(tCT, &allforone); k_thread_access_grant(tCT, &allforone);
printk("CT Thread Created %08X\n", (unsigned int) tCT); printk("CT Thread Created %08X\n", (unsigned int) tCT);
appmem_init_domain_dom2(part4); k_mem_domain_init(&dom2, 2, dom2_parts);
appmem_add_part_dom2(part3); k_mem_domain_add_thread(&dom2, tCT);
appmem_add_thread_dom2(tCT);
printk("dom2 Created\n"); printk("dom2 Created\n");
k_thread_start(&enc_thread); k_thread_start(&enc_thread);

View file

@ -45,7 +45,8 @@ FOR_EACH(appmem_partition, part0, part1, part2);
* test suite, specifically. dom1 is for a specific test * test suite, specifically. dom1 is for a specific test
* in this test suite. * in this test suite.
*/ */
FOR_EACH(appmem_domain, dom0, dom1); struct k_mem_domain dom0;
struct k_mem_domain dom1;
_app_dmem(part0) static volatile bool give_uthread_end_sem; _app_dmem(part0) static volatile bool give_uthread_end_sem;
_app_dmem(part0) bool mem_access_check; _app_dmem(part0) bool mem_access_check;
@ -656,19 +657,18 @@ static void shared_mem_thread(void)
*/ */
static void access_other_memdomain(void) static void access_other_memdomain(void)
{ {
struct k_mem_partition *parts[] = {&part0, &part2};
/* /*
* Following tests the ability for a thread to access data * Following tests the ability for a thread to access data
* in a domain that it is denied. * in a domain that it is denied.
*/ */
/* initialize domain dom1 with partition part2 */ /* initialize domain dom1 with partition part2 */
appmem_init_domain_dom1(part2); k_mem_domain_init(&dom1, 2, parts);
/* add partition part0 for test globals */
appmem_add_part_dom1(part0); /* remove current thread from domain dom0 and add to dom1 */
/* remove current thread from domain dom0 */ k_mem_domain_remove_thread(k_current_get());
appmem_rm_thread_dom0(k_current_get()); k_mem_domain_add_thread(&dom1, k_current_get());
/* initialize domain with current thread*/
appmem_add_thread_dom1(k_current_get());
/* Create user mode thread */ /* Create user mode thread */
k_thread_create(&uthread_thread, uthread_stack, STACKSIZE, k_thread_create(&uthread_thread, uthread_stack, STACKSIZE,
@ -687,6 +687,8 @@ extern k_thread_stack_t ztest_thread_stack[];
void test_main(void) void test_main(void)
{ {
struct k_mem_partition *parts[] = {&part0, &part1};
/* partitions must be initialized first */ /* partitions must be initialized first */
FOR_EACH(appmem_init_part, part0, part1, part2); FOR_EACH(appmem_init_part, part0, part1, part2);
/* /*
@ -705,12 +707,8 @@ void test_main(void)
#else #else
appmem_init_app_memory(); appmem_init_app_memory();
#endif #endif
/* Domain is initialized with partition part0 */ k_mem_domain_init(&dom0, 2, parts);
appmem_init_domain_dom0(part0); k_mem_domain_add_thread(&dom0, k_current_get());
/* Next, the partition must be added to the domain */
appmem_add_part_dom0(part1);
/* Finally, the current thread is added to domain */
appmem_add_thread_dom0(k_current_get());
#if defined(CONFIG_ARM) #if defined(CONFIG_ARM)
priv_stack_ptr = (int *)_k_priv_stack_find(ztest_thread_stack) - priv_stack_ptr = (int *)_k_priv_stack_find(ztest_thread_stack) -