Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/arch/evbarm/fdt Deduplicate address-range querying...
details: https://anonhg.NetBSD.org/src-all/rev/994bde48d027
branches: trunk
changeset: 932709:994bde48d027
user: Taylor R Campbell <riastradh%NetBSD.org@localhost>
date: Thu May 14 16:33:37 2020 +0000
description:
Deduplicate address-range querying/mapping logic.
diffstat:
sys/arch/evbarm/fdt/fdt_machdep.c | 208 ++++++++++++++-----------------------
1 files changed, 77 insertions(+), 131 deletions(-)
diffs (262 lines):
diff -r 520c1266e804 -r 994bde48d027 sys/arch/evbarm/fdt/fdt_machdep.c
--- a/sys/arch/evbarm/fdt/fdt_machdep.c Thu May 14 16:33:03 2020 +0000
+++ b/sys/arch/evbarm/fdt/fdt_machdep.c Thu May 14 16:33:37 2020 +0000
@@ -330,83 +330,20 @@
}
static void
-fdt_probe_initrd(uint64_t *pstart, uint64_t *pend)
-{
- *pstart = *pend = 0;
-
-#ifdef MEMORY_DISK_DYNAMIC
- const int chosen = OF_finddevice("/chosen");
- if (chosen < 0)
- return;
-
- int len;
- const void *start_data = fdtbus_get_prop(chosen,
- "linux,initrd-start", &len);
- const void *end_data = fdtbus_get_prop(chosen,
- "linux,initrd-end", NULL);
- if (start_data == NULL || end_data == NULL)
- return;
-
- switch (len) {
- case 4:
- *pstart = be32dec(start_data);
- *pend = be32dec(end_data);
- break;
- case 8:
- *pstart = be64dec(start_data);
- *pend = be64dec(end_data);
- break;
- default:
- printf("Unsupported len %d for /chosen/initrd-start\n", len);
- return;
- }
-#endif
-}
-
-static void
-fdt_setup_initrd(void)
-{
-#ifdef MEMORY_DISK_DYNAMIC
- const uint64_t initrd_size = initrd_end - initrd_start;
- paddr_t startpa = trunc_page(initrd_start);
- paddr_t endpa = round_page(initrd_end);
- paddr_t pa;
- vaddr_t va;
- void *md_start;
-
- if (initrd_size == 0)
- return;
-
- va = uvm_km_alloc(kernel_map, initrd_size, 0,
- UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
- if (va == 0) {
- printf("Failed to allocate VA for initrd\n");
- return;
- }
-
- md_start = (void *)va;
-
- for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)
- pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);
- pmap_update(pmap_kernel());
-
- md_root_setconf(md_start, initrd_size);
-#endif
-}
-
-static void
-fdt_probe_rndseed(uint64_t *pstart, uint64_t *pend)
+fdt_probe_range(const char *startname, const char *endname,
+ uint64_t *pstart, uint64_t *pend)
{
int chosen, len;
const void *start_data, *end_data;
*pstart = *pend = 0;
+
chosen = OF_finddevice("/chosen");
if (chosen < 0)
return;
- start_data = fdtbus_get_prop(chosen, "netbsd,rndseed-start", &len);
- end_data = fdtbus_get_prop(chosen, "netbsd,rndseed-end", NULL);
+ start_data = fdtbus_get_prop(chosen, startname, &len);
+ end_data = fdtbus_get_prop(chosen, endname, NULL);
if (start_data == NULL || end_data == NULL)
return;
@@ -420,68 +357,91 @@
*pend = be64dec(end_data);
break;
default:
- printf("Unsupported len %d for /chosen/rndseed-start\n", len);
+ printf("Unsupported len %d for /chosen/%s\n", len, startname);
return;
}
}
+static void *
+fdt_map_range(uint64_t start, uint64_t end, uint64_t *psize,
+ const char *purpose)
+{
+ const paddr_t startpa = trunc_page(start);
+ const paddr_t endpa = round_page(end);
+ paddr_t pa;
+ vaddr_t va;
+ void *ptr;
+
+ *psize = end - start;
+ if (*psize == 0)
+ return NULL;
+
+ va = uvm_km_alloc(kernel_map, *psize, 0, UVM_KMF_VAONLY|UVM_KMF_NOWAIT);
+ if (va == 0) {
+ printf("Failed to allocate VA for %s\n", purpose);
+ return NULL;
+ }
+ ptr = (void *)(va + (start & (PAGE_SIZE-1)));
+
+ for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)
+ pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);
+ pmap_update(pmap_kernel());
+
+ return ptr;
+}
+
+static void
+fdt_probe_initrd(uint64_t *pstart, uint64_t *pend)
+{
+ *pstart = *pend = 0;
+
+#ifdef MEMORY_DISK_DYNAMIC
+ fdt_probe_range("linux,initrd-start", "linux,initrd-end", pstart, pend);
+#endif
+}
+
+static void
+fdt_setup_initrd(void)
+{
+#ifdef MEMORY_DISK_DYNAMIC
+ void *md_start;
+ uint64_t initrd_size;
+
+ md_start = fdt_map_range(initrd_start, initrd_end, &initrd_size,
+ "initrd");
+ if (md_start == NULL)
+ return;
+ md_root_setconf(md_start, initrd_size);
+#endif
+}
+
+static void
+fdt_probe_rndseed(uint64_t *pstart, uint64_t *pend)
+{
+
+ fdt_probe_range("netbsd,rndseed-start", "netbsd,rndseed-end",
+ pstart, pend);
+}
+
static void
fdt_setup_rndseed(void)
{
- const uint64_t rndseed_size = rndseed_end - rndseed_start;
- const paddr_t startpa = trunc_page(rndseed_start);
- const paddr_t endpa = round_page(rndseed_end);
- paddr_t pa;
- vaddr_t va;
+ uint64_t rndseed_size;
void *rndseed;
- if (rndseed_size == 0)
- return;
-
- va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
- UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
- if (va == 0) {
- printf("Failed to allocate VA for rndseed\n");
+ rndseed = fdt_map_range(rndseed_start, rndseed_end, &rndseed_size,
+ "rndseed");
+ if (rndseed == NULL)
return;
- }
- rndseed = (void *)va;
-
- for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)
- pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);
- pmap_update(pmap_kernel());
-
rnd_seed(rndseed, rndseed_size);
}
static void
fdt_probe_efirng(uint64_t *pstart, uint64_t *pend)
{
- int chosen, len;
- const void *start_data, *end_data;
- *pstart = *pend = 0;
- chosen = OF_finddevice("/chosen");
- if (chosen < 0)
- return;
-
- start_data = fdtbus_get_prop(chosen, "netbsd,efirng-start", &len);
- end_data = fdtbus_get_prop(chosen, "netbsd,efirng-end", NULL);
- if (start_data == NULL || end_data == NULL)
- return;
-
- switch (len) {
- case 4:
- *pstart = be32dec(start_data);
- *pend = be32dec(end_data);
- break;
- case 8:
- *pstart = be64dec(start_data);
- *pend = be64dec(end_data);
- break;
- default:
- printf("Unsupported len %d for /chosen/efirng-start\n", len);
- return;
- }
+ fdt_probe_range("netbsd,efirng-start", "netbsd,efirng-end",
+ pstart, pend);
}
static struct krndsource efirng_source;
@@ -489,28 +449,14 @@
static void
fdt_setup_efirng(void)
{
- const uint64_t efirng_size = efirng_end - efirng_start;
- const paddr_t startpa = trunc_page(efirng_start);
- const paddr_t endpa = round_page(efirng_end);
- paddr_t pa;
- vaddr_t va;
+ uint64_t efirng_size;
void *efirng;
- if (efirng_size == 0)
+ efirng = fdt_map_range(efirng_start, efirng_end, &efirng_size,
+ "efirng");
+ if (efirng == NULL)
return;
- va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
- UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
- if (va == 0) {
- printf("Failed to allocate VA for efirng\n");
- return;
- }
- efirng = (void *)va;
-
- for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE)
- pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE, 0);
- pmap_update(pmap_kernel());
-
rnd_attach_source(&efirng_source, "efirng", RND_TYPE_RNG,
RND_FLAG_DEFAULT);
rnd_add_data(&efirng_source, efirng, efirng_size, 0);
Home |
Main Index |
Thread Index |
Old Index