From 23e52c351253c7260d6757e98af0854e074ad60f Mon Sep 17 00:00:00 2001 From: jhibbits Date: Tue, 1 Mar 2016 02:59:06 +0000 Subject: [PATCH] Correct the memory rman ranges to be to BUS_SPACE_MAXADDR Summary: As part of the migration of rman_res_t to be typed to uintmax_t, memory ranges must be clamped appropriately for the bus, to prevent completely bogus addresses from being used. This is extracted from D4544. Reviewed By: cem Sponsored by: Alex Perez/Inertial Computing Differential Revision: https://reviews.freebsd.org/D5134 --- sys/arm/arm/nexus.c | 5 +++-- sys/arm64/arm64/nexus.c | 7 ++++--- sys/mips/mips/nexus.c | 4 ++-- sys/riscv/riscv/nexus.c | 7 ++++--- sys/sparc64/sparc64/nexus.c | 2 +- sys/x86/x86/nexus.c | 8 ++++++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index b1c6b089e6bc..035e81f4fa7f 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -161,10 +161,11 @@ nexus_attach(device_t dev) { mem_rman.rm_start = 0; - mem_rman.rm_end = ~0ul; + mem_rman.rm_end = BUS_SPACE_MAXADDR; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; - if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0)) + if (rman_init(&mem_rman) || + rman_manage_region(&mem_rman, 0, BUS_SPACE_MAXADDR)) panic("nexus_probe mem_rman"); /* diff --git a/sys/arm64/arm64/nexus.c b/sys/arm64/arm64/nexus.c index 94b904873409..cdc5fc88847a 100644 --- a/sys/arm64/arm64/nexus.c +++ b/sys/arm64/arm64/nexus.c @@ -153,13 +153,14 @@ nexus_attach(device_t dev) { mem_rman.rm_start = 0; - mem_rman.rm_end = ~0ul; + mem_rman.rm_end = BUS_SPACE_MAXADDR; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; - if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0)) + if (rman_init(&mem_rman) || + rman_manage_region(&mem_rman, 0, BUS_SPACE_MAXADDR)) panic("nexus_attach mem_rman"); irq_rman.rm_start = 0; - irq_rman.rm_end = ~0ul; + irq_rman.rm_end = ~0; irq_rman.rm_type = RMAN_ARRAY; irq_rman.rm_descr = "Interrupts"; if (rman_init(&irq_rman) || rman_manage_region(&irq_rman, 0, ~0)) diff --git a/sys/mips/mips/nexus.c b/sys/mips/mips/nexus.c index 88a1c20b4c1a..617d842db28f 100644 --- a/sys/mips/mips/nexus.c +++ b/sys/mips/mips/nexus.c @@ -185,11 +185,11 @@ nexus_probe(device_t dev) } mem_rman.rm_start = 0; - mem_rman.rm_end = ~0ul; + mem_rman.rm_end = BUS_SPACE_MAXADDR; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "Memory addresses"; if (rman_init(&mem_rman) != 0 || - rman_manage_region(&mem_rman, 0, ~0) != 0) { + rman_manage_region(&mem_rman, 0, BUS_SPACE_MAXADDR) != 0) { panic("%s: mem_rman", __func__); } diff --git a/sys/riscv/riscv/nexus.c b/sys/riscv/riscv/nexus.c index 8d862a1481dc..a4ced760eeaa 100644 --- a/sys/riscv/riscv/nexus.c +++ b/sys/riscv/riscv/nexus.c @@ -143,13 +143,14 @@ nexus_attach(device_t dev) { mem_rman.rm_start = 0; - mem_rman.rm_end = ~0ul; + mem_rman.rm_end = BUS_SPACE_MAXADDR; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; - if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0)) + if (rman_init(&mem_rman) || + rman_manage_region(&mem_rman, 0, BUS_SPACE_MAXADDR)) panic("nexus_attach mem_rman"); irq_rman.rm_start = 0; - irq_rman.rm_end = ~0ul; + irq_rman.rm_end = ~0; irq_rman.rm_type = RMAN_ARRAY; irq_rman.rm_descr = "Interrupts"; if (rman_init(&irq_rman) || rman_manage_region(&irq_rman, 0, ~0)) diff --git a/sys/sparc64/sparc64/nexus.c b/sys/sparc64/sparc64/nexus.c index 8115f07433ab..3e099bdf6643 100644 --- a/sys/sparc64/sparc64/nexus.c +++ b/sys/sparc64/sparc64/nexus.c @@ -233,7 +233,7 @@ nexus_attach(device_t dev) rman_init(&sc->sc_mem_rman) != 0 || rman_manage_region(&sc->sc_intr_rman, 0, IV_MAX - 1) != 0 || - rman_manage_region(&sc->sc_mem_rman, 0ULL, ~0ULL) != 0) + rman_manage_region(&sc->sc_mem_rman, 0, BUS_SPACE_MAXADDR) != 0) panic("%s: failed to set up rmans.", __func__); } else node = ofw_bus_get_node(dev); diff --git a/sys/x86/x86/nexus.c b/sys/x86/x86/nexus.c index ab006136791d..39eeb82e603a 100644 --- a/sys/x86/x86/nexus.c +++ b/sys/x86/x86/nexus.c @@ -261,11 +261,15 @@ nexus_init_resources(void) panic("nexus_init_resources port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0ul; +#ifndef PAE + mem_rman.rm_end = BUS_SPACE_MAXADDR; +#else + mem_rman.rm_end = ((1ULL << cpu_maxphyaddr) - 1); +#endif mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; if (rman_init(&mem_rman) - || rman_manage_region(&mem_rman, 0, ~0)) + || rman_manage_region(&mem_rman, 0, mem_rman.rm_end)) panic("nexus_init_resources mem_rman"); }