From 1939a7914ff48ebf3a02ea8ecb997b97e7a512a8 Mon Sep 17 00:00:00 2001 From: Roberto Pereira Date: Thu, 15 Mar 2018 15:05:57 -0700 Subject: ql-tipc: sysdeps.h: separate memory allocation from getting attributes Obtaining the memory attributes can be done indepentently of the bootloader environment and is now done by the ipc layer. Updated u-boot example to reflect this. Change-Id: I8e649a1367ba02981419c43aac6e55b469dcf651 --- lib/trusty/ql-tipc/ipc_dev.c | 13 +++++++++++-- lib/trusty/ql-tipc/sysdeps/sysdeps_uboot.c | 17 ++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/trusty/ql-tipc/ipc_dev.c b/lib/trusty/ql-tipc/ipc_dev.c index 0f6f5f9090..720acf22be 100644 --- a/lib/trusty/ql-tipc/ipc_dev.c +++ b/lib/trusty/ql-tipc/ipc_dev.c @@ -24,6 +24,7 @@ #include #include +#include #include #define NS_PTE_PHYSADDR(pte) ((pte) & 0xFFFFFFFFF000ULL) @@ -176,13 +177,20 @@ int trusty_ipc_dev_create(struct trusty_ipc_dev **idev, /* allocate shared buffer */ dev->buf_size = shared_buf_size; - dev->buf_vaddr = trusty_alloc_pages(&dev->buf_ns, - shared_buf_size / PAGE_SIZE); + dev->buf_vaddr = trusty_alloc_pages(shared_buf_size / PAGE_SIZE); if (!dev->buf_vaddr) { trusty_error("%s: failed to allocate shared memory\n", __func__); rc = TRUSTY_ERR_NO_MEMORY; goto err_alloc_pages; } + + /* Get memory attributes */ + rc = trusty_encode_page_info(&dev->buf_ns, dev->buf_vaddr); + if (rc != 0) { + trusty_error("%s: failed to get shared memory attributes\n", __func__); + rc = TRUSTY_ERR_GENERIC; + goto err_page_info; + } /* call secure OS to register shared buffer */ rc = trusty_dev_init_ipc(dev->tdev, &dev->buf_ns, dev->buf_size); if (rc != 0) { @@ -197,6 +205,7 @@ int trusty_ipc_dev_create(struct trusty_ipc_dev **idev, *idev = dev; return TRUSTY_ERR_NONE; +err_page_info: err_create_sec_dev: trusty_free_pages(dev->buf_vaddr, dev->buf_size / PAGE_SIZE); err_alloc_pages: diff --git a/lib/trusty/ql-tipc/sysdeps/sysdeps_uboot.c b/lib/trusty/ql-tipc/sysdeps/sysdeps_uboot.c index f0d6c69abd..b42cd20d4f 100644 --- a/lib/trusty/ql-tipc/sysdeps/sysdeps_uboot.c +++ b/lib/trusty/ql-tipc/sysdeps/sysdeps_uboot.c @@ -99,22 +99,9 @@ void trusty_free(void *addr) free(addr); } -void *trusty_alloc_pages(struct ns_mem_page_info *page_info, unsigned count) +void *trusty_alloc_pages(unsigned count) { - void *va = NULL; - int res; - - va = memalign(PAGE_SIZE, count * PAGE_SIZE); - if (!va) - return NULL; - - /* get memory attibutes */ - res = trusty_encode_page_info(page_info, va); - if (res) { - trusty_free_pages(va, count); - return NULL; - } - return va; + return memalign(PAGE_SIZE, count * PAGE_SIZE); } void trusty_free_pages(void *va, unsigned count) -- cgit v1.2.3