Commit 5bc7d324 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

test-v2: Update address -> cptr to return offset into memory object.

Updated kliblcd, liblcd, and string example.
parent 5c5c6f88
......@@ -467,6 +467,7 @@ void lcd_unvolunteer_vmalloc_mem(cptr_t vmalloc_mem);
* @paddr: the physical address to search for
* @c_out: out param containing cptr to memory capability that contains @paddr
* @size_out: the memory object is size bytes
* @offset_out: the offset that @paddr is in the memory object, in bytes
*
* If @paddr meets these conditions:
*
......@@ -500,7 +501,8 @@ void lcd_unvolunteer_vmalloc_mem(cptr_t vmalloc_mem);
* (There is no way to get a cptr to a capability to individual pages
* in a chunk, since the microkernel doesn't currently support this.)
*/
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out);
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out);
/**
* lcd_phys_to_resource_node -- Look up the struct lcd_resource_node for the
* memory object that contains guest physical
......@@ -517,10 +519,12 @@ int lcd_phys_to_resource_node(gpa_t paddr, struct lcd_resource_node **n);
* @vaddr: the virtual address to search for
* @c_out: out param containing cptr to memory capability that contains @paddr
* @size_out: the memory object is size bytes
* @offset_out: the offset that @vaddr is in the memory object, in bytes
*
* Similar to lcd_phys_to_cptr. Similar error conditions.
*/
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out);
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out);
/**
* lcd_virt_to_resource_node -- Similar to lcd_phys_to_resource_node,
* but @vaddr is a virtual address
......
......@@ -487,7 +487,7 @@ void lcd_free_pages(struct page *base, unsigned int order)
cptr_t page_cptr;
int ret;
gpa_t gpa;
unsigned long actual_size;
unsigned long actual_size, unused;
/*
* Translate page to physical address.
*
......@@ -498,7 +498,7 @@ void lcd_free_pages(struct page *base, unsigned int order)
/*
* Resolve pages to cptr
*/
ret = lcd_phys_to_cptr(gpa, &page_cptr, &actual_size);
ret = lcd_phys_to_cptr(gpa, &page_cptr, &actual_size, &unused);
if (ret) {
LIBLCD_ERR("warning: pages not found, so not freed");
return;
......@@ -577,12 +577,12 @@ void lcd_vfree(void *vptr)
{
cptr_t vmalloc_mem_cptr;
int ret;
unsigned long unused;
unsigned long unused1, unused2;
/*
* Resolve vptr to cptr
*/
ret = lcd_virt_to_cptr(__gva((unsigned long)vptr),
&vmalloc_mem_cptr, &unused);
&vmalloc_mem_cptr, &unused1, &unused2);
if (ret) {
LIBLCD_ERR("warning: vmaloc mem not found, so not freed");
return;
......@@ -705,14 +705,14 @@ void lcd_unmap_phys(gpa_t base, unsigned int order)
{
int ret;
cptr_t mo_cptr;
unsigned long mo_size;
unsigned long mo_size, unused;
/*
* No real unmapping needs to be done, but we need to
* update the resource tree.
*
* Look up cptr for physical memory
*/
ret = lcd_phys_to_cptr(base, &mo_cptr, &mo_size);
ret = lcd_phys_to_cptr(base, &mo_cptr, &mo_size, &unused);
if (ret) {
LIBLCD_ERR("phys not mapped?");
return;
......@@ -729,14 +729,14 @@ void lcd_unmap_virt(gva_t base, unsigned int order)
{
int ret;
cptr_t mo_cptr;
unsigned long mo_size;
unsigned long mo_size, unused;
/*
* No real unmapping needs to be done, but we need to
* update the resource tree.
*
* Look up cptr for virtual memory
*/
ret = lcd_virt_to_cptr(base, &mo_cptr, &mo_size);
ret = lcd_virt_to_cptr(base, &mo_cptr, &mo_size, &unused);
if (ret) {
LIBLCD_ERR("virt not mapped?");
return;
......@@ -879,7 +879,8 @@ int lcd_phys_to_resource_node(gpa_t paddr, struct lcd_resource_node **n)
n);
}
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out)
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out)
{
int ret;
struct lcd_resource_node *n;
......@@ -896,6 +897,7 @@ int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out)
*/
*c_out = n->cptr;
*size_out = lcd_resource_node_size(n);
*offset_out = gpa_val(paddr) - lcd_resource_node_start(n);
return 0;
......@@ -903,7 +905,8 @@ fail1:
return ret;
}
int lcd_virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n)
int virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n,
int *tree_id)
{
gpa_t gpa;
int ret;
......@@ -922,20 +925,30 @@ int lcd_virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n)
* guest phys = host phys.
*/
gpa = __gpa(hpa_val(hva2hpa(__hva(gva_val(vaddr)))));
*tree_id = LCD_RESOURCE_TREE_CONTIGUOUS;
return lcd_phys_to_resource_node(gpa, n);
}
*tree_id = LCD_RESOURCE_TREE_NON_CONTIGUOUS;
return ret;
}
int lcd_virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n)
{
int unused;
return virt_to_resource_node(vaddr, n, &unused);
}
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out)
{
struct lcd_resource_node *n;
int ret;
int tree_id;
/*
* Resolve to resource node
*/
ret = lcd_virt_to_resource_node(vaddr, &n);
ret = virt_to_resource_node(vaddr, &n, &tree_id);
if (ret) {
LIBLCD_ERR("address not found");
goto fail1;
......@@ -945,6 +958,13 @@ int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out)
*/
*c_out = n->cptr;
*size_out = lcd_resource_node_size(n);
if (tree_id == LCD_RESOURCE_TREE_NON_CONTIGUOUS) {
/* Assumes only virtual addresses in non-contig tree */
*offset_out = gva_val(vaddr) - lcd_resource_node_start(n);
} else {
*offset_out = gpa_val(lcd_gva2gpa(vaddr)) -
lcd_resource_node_start(n);
}
return 0;
......
......@@ -130,7 +130,7 @@ static int dup_module_pages(hva_t pages_base, unsigned long size,
{
int ret;
void *dup_pages;
unsigned long unused;
unsigned long unused1, unused2;
/*
* Alloc dup pages, and memcpy the bits over
*/
......@@ -146,7 +146,7 @@ static int dup_module_pages(hva_t pages_base, unsigned long size,
*/
ret = lcd_virt_to_cptr(__gva((unsigned long)dup_pages),
dup_pages_cap_out,
&unused);
&unused1, &unused2);
if (ret) {
LIBLCD_ERR("vmalloc mem object lookup failed");
goto fail2;
......
......@@ -409,10 +409,10 @@ void lcd_free_memcg_kmem_pages(unsigned long addr, unsigned int order)
int lcd_volunteer_pages(struct page *base, unsigned int order,
cptr_t *slot_out)
{
unsigned long size;
unsigned long size, unused;
return lcd_phys_to_cptr(
lcd_gva2gpa(__gva((unsigned long)lcd_page_address(base))),
slot_out, &size);
slot_out, &size, &unused);
}
void lcd_unvolunteer_pages(cptr_t pages)
......@@ -423,8 +423,8 @@ void lcd_unvolunteer_pages(cptr_t pages)
int lcd_volunteer_dev_mem(gpa_t base, unsigned int order,
cptr_t *slot_out)
{
unsigned long size;
return lcd_phys_to_cptr(base, slot_out, &size);
unsigned long size, unused;
return lcd_phys_to_cptr(base, slot_out, &size, &unused);
}
void lcd_unvolunteer_dev_mem(cptr_t devmem)
......@@ -435,8 +435,8 @@ void lcd_unvolunteer_dev_mem(cptr_t devmem)
int lcd_volunteer_vmalloc_mem(gva_t base, unsigned long nr_pages,
cptr_t *slot_out)
{
unsigned long size;
return lcd_virt_to_cptr(base, slot_out, &size);
unsigned long size, unused;
return lcd_virt_to_cptr(base, slot_out, &size, &unused);
}
void lcd_unvolunteer_vmalloc_mem(cptr_t vmalloc_mem)
......
......@@ -138,7 +138,8 @@ int lcd_virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n)
return lcd_phys_to_resource_node(lcd_gva2gpa(vaddr), n);
}
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out)
int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out)
{
struct lcd_resource_node *n;
int ret;
......@@ -148,6 +149,7 @@ int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out)
return ret;
*c_out = n->cptr;
*size_out = lcd_resource_node_size(n);
*offset_out = gpa_val(paddr) - lcd_resource_node_start(n);
return 0;
}
......
......@@ -62,21 +62,21 @@ fail1:
static int do_send(cptr_t endpoint, char *data, int len)
{
int ret;
struct lcd_resource_node *n;
unsigned long offset;
unsigned long size, offset;
cptr_t page;
/*
* Get the cptr for the page that contains data
*/
ret = lcd_virt_to_resource_node(__gva((unsigned long)data), &n);
ret = lcd_virt_to_cptr(__gva((unsigned long)data), &page,
&size, &offset);
if (ret) {
LIBLCD_ERR("lcd virt addr to page cptr failed");
goto fail1;
}
offset = __pa(data) - lcd_resource_node_start(n);
/*
* Set up message for grant
*/
lcd_set_cr1(n->cptr);
lcd_set_cr1(page);
lcd_set_r0(offset);
ret = lcd_sync_send(endpoint);
if (ret) {
......
......@@ -68,21 +68,21 @@ fail1:
static int do_send(cptr_t endpoint, char *data, int len)
{
int ret;
struct lcd_resource_node *n;
unsigned long offset;
unsigned long offset, size;
cptr_t page;
/*
* Get the cptr for the page that contains data
*/
ret = lcd_virt_to_resource_node(__gva((unsigned long)data), &n);
ret = lcd_virt_to_cptr(__gva((unsigned long)data), &page,
&size, &offset);
if (ret) {
LIBLCD_ERR("lcd virt addr to page cptr failed");
goto fail1;
}
offset = __pa(data) - lcd_resource_node_start(n);
/*
* Set up message for grant
*/
lcd_set_cr1(n->cptr);
lcd_set_cr1(page);
lcd_set_r0(offset);
ret = lcd_sync_send(endpoint);
if (ret) {
......
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