Better use of address types in mm.h.
These functions are called to map physical pages in and out of the
address space. It makes more sense for the APIs to use those physical
addresses and avoid mistakes or confusion in the conversions.
Once the physical address has been mapped it will be available as a
virtual address or pointer in the hypervisor and an intermediate
physical address in the VMs. The corresponding type is now returned from
the mapping functions to avoid complication or mistakes in conversion by
the caller and the vast majority of the address type conversions now
happen within mm.
Internally to mm, the stage 1 and stage 2 tables still share the same
management code so that is made generic for the type of input address
being used.
Change-Id: I9201b98b7329ead304903b8b8968c4378eb5a4db
diff --git a/src/fdt_handler.c b/src/fdt_handler.c
index 99ea4d4..06320e4 100644
--- a/src/fdt_handler.c
+++ b/src/fdt_handler.c
@@ -174,24 +174,22 @@
bool ret = false;
/* Map the fdt header in. */
- if (!mm_identity_map(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_header_size()),
- MM_MODE_R)) {
+ fdt = mm_identity_map(fdt_addr, pa_add(fdt_addr, fdt_header_size()),
+ MM_MODE_R);
+ if (!fdt) {
dlog("Unable to map FDT header.\n");
goto err_unmap_fdt_header;
}
- fdt = ptr_from_va(va_from_pa(fdt_addr));
-
if (!fdt_root_node(&n, fdt)) {
dlog("FDT failed validation.\n");
goto err_unmap_fdt_header;
}
/* Map the rest of the fdt in. */
- if (!mm_identity_map(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_total_size(fdt)),
- MM_MODE_R)) {
+ fdt = mm_identity_map(fdt_addr, pa_add(fdt_addr, fdt_total_size(fdt)),
+ MM_MODE_R);
+ if (!fdt) {
dlog("Unable to map full FDT.\n");
goto err_unmap_fdt_header;
}
@@ -213,13 +211,11 @@
ret = true;
out_unmap_fdt:
- mm_unmap(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_total_size(fdt)), 0);
+ mm_unmap(fdt_addr, pa_add(fdt_addr, fdt_total_size(fdt)), 0);
return ret;
err_unmap_fdt_header:
- mm_unmap(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_header_size()), 0);
+ mm_unmap(fdt_addr, pa_add(fdt_addr, fdt_header_size()), 0);
return false;
}
@@ -230,25 +226,23 @@
bool ret = false;
/* Map the fdt header in. */
- if (!mm_identity_map(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_header_size()),
- MM_MODE_R)) {
+ fdt = mm_identity_map(fdt_addr, pa_add(fdt_addr, fdt_header_size()),
+ MM_MODE_R);
+ if (!fdt) {
dlog("Unable to map FDT header.\n");
return false;
}
- fdt = ptr_from_va(va_from_pa(fdt_addr));
-
if (!fdt_root_node(&n, fdt)) {
dlog("FDT failed validation.\n");
goto err_unmap_fdt_header;
}
/* Map the fdt (+ a page) in r/w mode in preparation for updating it. */
- if (!mm_identity_map(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr),
- fdt_total_size(fdt) + PAGE_SIZE),
- MM_MODE_R | MM_MODE_W)) {
+ fdt = mm_identity_map(fdt_addr,
+ pa_add(fdt_addr, fdt_total_size(fdt) + PAGE_SIZE),
+ MM_MODE_R | MM_MODE_W);
+ if (!fdt) {
dlog("Unable to map FDT in r/w mode.\n");
goto err_unmap_fdt_header;
}
@@ -291,17 +285,14 @@
out_unmap_fdt:
/* Unmap FDT. */
- if (!mm_unmap(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr),
- fdt_total_size(fdt) + PAGE_SIZE),
- 0)) {
+ if (!mm_unmap(fdt_addr,
+ pa_add(fdt_addr, fdt_total_size(fdt) + PAGE_SIZE), 0)) {
dlog("Unable to unmap writable FDT.\n");
return false;
}
return ret;
err_unmap_fdt_header:
- mm_unmap(va_from_pa(fdt_addr),
- va_add(va_from_pa(fdt_addr), fdt_header_size()), 0);
+ mm_unmap(fdt_addr, pa_add(fdt_addr, fdt_header_size()), 0);
return false;
}