Commit 528cecbd authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan
Browse files

build-refactor: Incorporate common sources into kliblcd build.

Build bug fixes for resource tree and module create code.
parent 1abb5ae7
*Module.symvers
libcap.build.lcd
libcap.build.microkernel
libcap.out.lcd
libcap.out.microkernel
microkernel_build
......@@ -9,6 +9,8 @@
#include <lcd_config/pre_hook.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <libcap.h>
#include <liblcd/liblcd.h>
......@@ -60,6 +62,7 @@ static int do_kernel_module_grant_map(cptr_t lcd, struct lcd_create_ctx *ctx,
{
unsigned long offset;
cptr_t *c;
int ret;
/*
* Map module init and core at correct offsets
*/
......@@ -102,7 +105,7 @@ static int setup_phys_addr_space(cptr_t lcd, struct lcd_create_ctx *ctx,
if (ret)
goto fail1;
c = &(lcd_to_boot_info(ctx)->lcd_boot_cptrs.gv);
ret = do_grant_and_map_for_mem(lcd, ctx, ctx->pgd,
ret = do_grant_and_map_for_mem(lcd, ctx, ctx->gv_pgd,
LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR, c);
if (ret)
goto fail2;
......@@ -137,8 +140,8 @@ static void setup_lcd_pud(struct lcd_create_ctx *ctx)
*/
unsigned int i;
unsigned int ioremap_offset = LCD_IOREMAP_REGION_OFFSET >> 30;
unsigned int after_ioremap_offset = ioremap_offset +
LCD_IOREMAP_REGION_SIZE >> 30;
unsigned int after_ioremap_offset = (ioremap_offset +
LCD_IOREMAP_REGION_SIZE) >> 30;
pteval_t wb_flags = _PAGE_PRESENT | _PAGE_RW | _PAGE_PSE;
pteval_t uc_flags = _PAGE_PRESENT | _PAGE_RW | _PAGE_PSE | _PAGE_PWT;
pud_t *pud_entry;
......@@ -146,25 +149,25 @@ static void setup_lcd_pud(struct lcd_create_ctx *ctx)
* Map first GBs as write back
*/
for (i = 0; i < ioremap_offset; i++) {
pud_entry = &ctx->pud[i];
pud_entry = &ctx->gv_pud[i];
set_pud(pud_entry,
(LCD_PHYS_BASE + i * (1UL << 30)) | wb_flags)
__pud((LCD_PHYS_BASE + i * (1UL << 30)) | wb_flags));
}
/*
* Map ioremap GBs as uncacheable
*/
for (i = ioremap_offset; i < after_ioremap_offset; i++) {
pud_entry = &ctx->pud[i];
pud_entry = &ctx->gv_pud[i];
set_pud(pud_entry,
(LCD_PHYS_BASE + i * (1UL << 30)) | uc_flags)
__pud((LCD_PHYS_BASE + i * (1UL << 30)) | uc_flags));
}
/*
* Map remaining GBs as write back
*/
for (i = after_ioremap_offset; i < 512; i++) {
pud_entry = &ctx->pud[i];
pud_entry = &ctx->gv_pud[i];
set_pud(pud_entry,
(LCD_PHYS_BASE + i * (1UL << 30)) | wb_flags)
__pud((LCD_PHYS_BASE + i * (1UL << 30)) | wb_flags));
}
}
......@@ -174,7 +177,7 @@ static void setup_lcd_pgd(struct lcd_create_ctx *ctx)
gpa_t pud_gpa;
pteval_t flags = 0;
pgd_entry = &ctx->pgd[511]; /* only map last pud for high 512 GBs */
pgd_entry = &ctx->gv_pgd[511]; /* only map last pud for high 512 GBs */
/* pud comes after pgd */
pud_gpa = gpa_add(LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR, PAGE_SIZE);
......@@ -183,7 +186,7 @@ static void setup_lcd_pgd(struct lcd_create_ctx *ctx)
flags |= _PAGE_RW;
set_pgd(pgd_entry,
__pgd(gpa_val(pud_gpa) | flags))
__pgd(gpa_val(pud_gpa) | flags));
}
static void setup_virt_addr_space(struct lcd_create_ctx *ctx)
......@@ -208,7 +211,7 @@ static int setup_addr_spaces(cptr_t lcd, struct lcd_create_ctx *ctx,
* Set up physical address space (except UTCB - that's done
* via lcd_config)
*/
ret = setup_phys_addr_space(lcd, cxt, m_init_link_addr,
ret = setup_phys_addr_space(lcd, ctx, m_init_link_addr,
m_core_link_addr);
if (ret) {
LIBLCD_ERR("error setting up phys addr space");
......@@ -217,7 +220,7 @@ static int setup_addr_spaces(cptr_t lcd, struct lcd_create_ctx *ctx,
/*
* Set up virtual address space
*/
setup_virt_addr_space(cxt);
setup_virt_addr_space(ctx);
return 0;
......@@ -228,6 +231,7 @@ fail1: /* just return non-zero ret; caller will free mem */
static int init_create_ctx(struct lcd_create_ctx **ctx_out, char *mname)
{
struct lcd_create_ctx *ctx;
int ret;
/*
* Alloc ctx
*/
......@@ -256,15 +260,15 @@ static void destroy_create_ctx(struct lcd_create_ctx *ctx)
* pages will be freed by microkernel.
*/
if (ctx->m_init_bits)
lcd_module_release(ctx->m_init_bits, ctx->m_core_bits);
lcd_release_module(ctx->m_init_bits, ctx->m_core_bits);
if (ctx->stack)
lcd_free_pages(lcd_virt_to_page(ctx->stack),
lcd_free_pages(lcd_virt_to_head_page(ctx->stack),
LCD_STACK_ORDER);
if (ctx->gv_pgd)
lcd_free_pages(lcd_virt_to_page(ctx->gv_pgd),
lcd_free_pages(lcd_virt_to_head_page(ctx->gv_pgd),
LCD_BOOTSTRAP_PAGE_TABLES_ORDER);
if (ctx->lcd_boot_info)
lcd_free_pages(lcd_virt_to_page(ctx->lcd_boot_info),
lcd_free_pages(lcd_virt_to_head_page(ctx->lcd_boot_info),
LCD_BOOTSTRAP_PAGES_ORDER);
/*
* Free the ctx
......@@ -275,6 +279,7 @@ static void destroy_create_ctx(struct lcd_create_ctx *ctx)
static int get_pages_for_lcd(struct lcd_create_ctx *ctx)
{
struct page *p1, *p2, *p3;
int ret;
/*
* We explicity zero things out. If this code is used inside
* an LCD, it may not zero out the alloc'd pages.
......@@ -301,7 +306,7 @@ static int get_pages_for_lcd(struct lcd_create_ctx *ctx)
* Alloc boot page tables
*/
p2 = lcd_alloc_pages(0, LCD_BOOTSTRAP_PAGE_TABLES_ORDER);
if (!p) {
if (!p2) {
LIBLCD_ERR("alloc boot page tables failed");
ret = -ENOMEM;
goto fail3;
......@@ -360,7 +365,7 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd_out,
/*
* Load kernel module into caller's address space
*/
ret = lcd_module_load(mdir, mname,
ret = lcd_load_module(mdir, mname,
&ctx->m_init_bits, &ctx->m_core_bits,
&m_init_cptr, &m_core_cptr,
&m_init_link_addr, &m_core_link_addr);
......@@ -382,7 +387,7 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd_out,
/*
* Set up address spaces
*/
ret = setup_addr_spaces(lcd, cxt, m_init_link_addr,
ret = setup_addr_spaces(lcd, ctx, m_init_link_addr,
m_core_link_addr);
if (ret) {
LIBLCD_ERR("error setting up address spaces");
......@@ -395,7 +400,7 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd_out,
/* implicity put a null return address */
gva_add(LCD_STACK_GV_ADDR,
LCD_STACK_SIZE - sizeof(void *)),
LCD_BOOTSTRAP_PAGE_TABLES_GV_ADDR,
LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR,
LCD_UTCB_GP_ADDR);
if (ret) {
LIBLCD_ERR("error configuring LCDs registers");
......@@ -405,7 +410,7 @@ int lcd_create_module_lcd(char *mdir, char *mname, cptr_t *lcd_out,
/*
* Return context and lcd
*/
*cxt_out = cxt;
*ctx_out = ctx;
*lcd_out = lcd;
return 0;
......
......@@ -11,7 +11,7 @@
#include <linux/slab.h>
#include <linux/interval_tree.h>
#include <linux/rb_tree.h>
#include <linux/rbtree.h>
#include <libcap.h>
#include <liblcd/liblcd.h>
......@@ -48,7 +48,7 @@ int lcd_resource_tree_search(struct lcd_resource_tree *t,
match = interval_tree_iter_first(&t->root, addr, addr);
if (match) {
n_out = container_of(match, struct lcd_resource_node,
*n_out = container_of(match, struct lcd_resource_node,
it_node);
return 0;
} else {
......
......@@ -26,6 +26,9 @@
#define LCD_DEBUG_LVL 1
/* Controls debug msg output for microkernel's libcap */
#define LCD_LIBCAP_DEBUG_LVL 0
#define LCD_ERR(msg...) __lcd_err(__FILE__, __LINE__, msg)
static inline void __lcd_err(char *file, int lineno, char *fmt, ...)
{
......
......@@ -171,11 +171,11 @@ __lcd_build_checks__(void)
/* Orders (for convenience) */
#define LCD_BOOTSTRAP_PAGES_ORDER \
(ilog(LCD_BOOTSTRAP_PAGES_SIZE >> PAGE_SHIFT))
(ilog2(LCD_BOOTSTRAP_PAGES_SIZE >> PAGE_SHIFT))
#define LCD_BOOTSTRAP_PAGE_TABLES_ORDER \
(ilog(LCD_BOOTSTRAP_PAGE_TABLES_SIZE >> PAGE_SHIFT))
(ilog2(LCD_BOOTSTRAP_PAGE_TABLES_SIZE >> PAGE_SHIFT))
#define LCD_STACK_ORDER \
(ilog(LCD_STACK_SIZE >> PAGE_SHIFT))
(ilog2(LCD_STACK_SIZE >> PAGE_SHIFT))
/* Offsets. */
......@@ -217,25 +217,25 @@ __lcd_build_checks__(void)
#define LCD_BOOTSTRAP_PAGES_GP_ADDR \
__gpa(LCD_PHYS_BASE + LCD_BOOTSTRAP_PAGES_OFFSET)
#define LCD_BOOTSTRAP_PAGES_GV_ADDR \
__gpa(LCD_VIRT_BASE + LCD_BOOTSTRAP_PAGES_OFFSET)
__gva(LCD_VIRT_BASE + LCD_BOOTSTRAP_PAGES_OFFSET)
#define LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR \
__gpa(LCD_PHYS_BASE + LCD_BOOTSTRAP_PAGE_TABLES_OFFSET)
#define LCD_BOOTSTRAP_PAGE_TABLES_GV_ADDR \
__gpa(LCD_VIRT_BASE + LCD_BOOTSTRAP_PAGE_TABLES_OFFSET)
__gva(LCD_VIRT_BASE + LCD_BOOTSTRAP_PAGE_TABLES_OFFSET)
#define LCD_STACK_GP_ADDR __gpa(LCD_PHYS_BASE + LCD_STACK_OFFSET)
#define LCD_STACK_GV_ADDR __gpa(LCD_VIRT_BASE + LCD_STACK_OFFSET)
#define LCD_STACK_GV_ADDR __gva(LCD_VIRT_BASE + LCD_STACK_OFFSET)
#define LCD_HEAP_GP_ADDR __gpa(LCD_PHYS_BASE + LCD_HEAP_OFFSET)
#define LCD_HEAP_GV_ADDR __gpa(LCD_VIRT_BASE + LCD_HEAP_OFFSET)
#define LCD_HEAP_GV_ADDR __gva(LCD_VIRT_BASE + LCD_HEAP_OFFSET)
#define LCD_IOREMAP_GP_ADDR __gpa(LCD_PHYS_BASE + LCD_IOREMAP_OFFSET)
#define LCD_IOREMAP_GV_ADDR __gpa(LCD_VIRT_BASE + LCD_IOREMAP_OFFSET)
#define LCD_IOREMAP_GV_ADDR __gva(LCD_VIRT_BASE + LCD_IOREMAP_OFFSET)
#define LCD_KERNEL_MODULE_REGION_GP_ADDR \
__gpa(LCD_PHYS_BASE + LCD_KERNEL_MODULE_REGION_OFFSET)
#define LCD_KERNEL_MODULE_REGION_GV_ADDR \
__gpa(LCD_VIRT_BASE + LCD_KERNEL_MODULE_REGION_OFFSET)
__gva(LCD_VIRT_BASE + LCD_KERNEL_MODULE_REGION_OFFSET)
#endif /* LCD_DOMAINS_ADDRESS_SPACES_H */
......@@ -127,7 +127,7 @@ struct lcd_create_ctx {
*/
struct lcd_boot_info *lcd_boot_info;
pgd_t *gv_pgd;
pgd_t *gv_pud;
pud_t *gv_pud;
void *stack;
void *m_init_bits;
void *m_core_bits;
......
Subproject commit 33e3cc5539a17d170c01191f29547e86cad36cf9
Subproject commit 5cee08d638d9177bdf2a9c6dec523111fb5034f3
......@@ -12,6 +12,10 @@
struct cap_type_system *lcd_libcap_type_system;
/* CAP DEBUGGING -------------------------------------------------- */
int cap_debug_level = LCD_LIBCAP_DEBUG_LVL;
/* ------------------------------------------------------------ */
/* struct for internal use to store all information about a type. */
......
......@@ -42,6 +42,12 @@ lcd_domains-y += $(addprefix kliblcd/, \
sync_ipc.o \
)
# code shared by kliblcd and isolated liblcd
lcd_domains-y += $(addprefix common/, \
resource_tree.o \
module_create.o \
)
# libcap (microkernel and kliblcd share libcap. We get away with this
# because this build of libcap does not use global cap types.)
lcd_domains-y += libcap.install/lib/libcap.a
......
......@@ -194,6 +194,10 @@ obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
obj-$(CONFIG_PERCPU_TEST) += percpu_test.o
# Always include interval tree (for LCD Domains)
obj-y += interval_tree.o
interval_tree_test-objs := interval_tree_test_main.o
obj-$(CONFIG_ASN1) += asn1_decoder.o
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment