From 24c8d4c173dcf9d0212a059eab46616684047e65 Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Thu, 22 Oct 2009 02:51:31 +0000 Subject: [PATCH] Get rid of the hardcoded constants to define cacheable memory: SDRAM_ADDR_START, SDRAM_ADDR_END and SDRAM_MEM_SIZE Instead we now keep a copy of the memory regions enumerated by platform-specific code and use that to determine whether an address is cacheable or not. Approved by: imp (mentor) --- sys/mips/include/md_var.h | 4 ++-- sys/mips/include/pltfm.h | 16 ---------------- sys/mips/include/pmap.h | 16 +++++++++++++++- sys/mips/mips/machdep.c | 18 ++++++++++++++++-- sys/mips/mips/mem.c | 14 ++------------ sys/mips/mips/pmap.c | 9 ++++++++- sys/mips/mips/vm_machdep.c | 29 ----------------------------- 7 files changed, 43 insertions(+), 63 deletions(-) delete mode 100644 sys/mips/include/pltfm.h diff --git a/sys/mips/include/md_var.h b/sys/mips/include/md_var.h index f53074f39bf0..f7210ffa26ce 100644 --- a/sys/mips/include/md_var.h +++ b/sys/mips/include/md_var.h @@ -52,8 +52,8 @@ uintptr_t MipsEmulateBranch(struct trapframe *, uintptr_t, int, uintptr_t); void MipsSwitchFPState(struct thread *, struct trapframe *); u_long kvtop(void *addr); int is_physical_memory(vm_offset_t addr); -int is_cacheable_mem(vm_offset_t pa); -int is_coherent_mem(vm_offset_t pa); + +#define is_cacheable_mem(pa) is_physical_memory((pa)) #define MIPS_DEBUG 0 diff --git a/sys/mips/include/pltfm.h b/sys/mips/include/pltfm.h deleted file mode 100644 index 86d50d964c4f..000000000000 --- a/sys/mips/include/pltfm.h +++ /dev/null @@ -1,16 +0,0 @@ -/*- - * JNPR: pltfm.h,v 1.5.2.1 2007/09/10 05:56:11 girish - * $FreeBSD$ - */ - -#ifndef _MACHINE_PLTFM_H_ -#define _MACHINE_PLTFM_H_ - -/* - * This files contains platform-specific definitions. - */ -#define SDRAM_ADDR_START 0 /* SDRAM addr space */ -#define SDRAM_ADDR_END (SDRAM_ADDR_START + (1024*0x100000)) -#define SDRAM_MEM_SIZE (SDRAM_ADDR_END - SDRAM_ADDR_START) - -#endif /* !_MACHINE_PLTFM_H_ */ diff --git a/sys/mips/include/pmap.h b/sys/mips/include/pmap.h index 3e4231350f61..eedd4f3f801a 100644 --- a/sys/mips/include/pmap.h +++ b/sys/mips/include/pmap.h @@ -145,7 +145,21 @@ typedef struct pv_entry { #define PMAP_DIAGNOSTIC #endif -extern vm_offset_t phys_avail[]; +/* + * physmem_desc[] is a superset of phys_avail[] and describes all the + * memory present in the system. + * + * phys_avail[] is similar but does not include the memory stolen by + * pmap_steal_memory(). + * + * Each memory region is described by a pair of elements in the array + * so we can describe up to (PHYS_AVAIL_ENTRIES / 2) distinct memory + * regions. + */ +#define PHYS_AVAIL_ENTRIES 10 +extern vm_offset_t phys_avail[PHYS_AVAIL_ENTRIES + 2]; +extern vm_offset_t physmem_desc[PHYS_AVAIL_ENTRIES + 2]; + extern char *ptvmmap; /* poor name! */ extern vm_offset_t virtual_avail; extern vm_offset_t virtual_end; diff --git a/sys/mips/mips/machdep.c b/sys/mips/mips/machdep.c index 9a28b2485eab..a746b24c812b 100644 --- a/sys/mips/mips/machdep.c +++ b/sys/mips/mips/machdep.c @@ -79,7 +79,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -120,7 +119,9 @@ struct pcpu pcpu; struct pcpu *pcpup = &pcpu; #endif -vm_offset_t phys_avail[10]; +vm_offset_t phys_avail[PHYS_AVAIL_ENTRIES + 2]; +vm_offset_t physmem_desc[PHYS_AVAIL_ENTRIES + 2]; + #ifdef UNIMPLEMENTED struct platform platform; #endif @@ -426,3 +427,16 @@ cpu_idle_wakeup(int cpu) return (0); } + +int +is_physical_memory(vm_offset_t addr) +{ + int i; + + for (i = 0; physmem_desc[i + 1] != 0; i += 2) { + if (addr >= physmem_desc[i] && addr < physmem_desc[i + 1]) + return (1); + } + + return (0); +} diff --git a/sys/mips/mips/mem.c b/sys/mips/mips/mem.c index 1a03d5b79a77..3a3cbaebb520 100644 --- a/sys/mips/mips/mem.c +++ b/sys/mips/mips/mem.c @@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include @@ -101,17 +100,8 @@ memrw(dev, uio, flags) vm_paddr_t pa; register int o; -#ifdef CPU_SB1 - if (!is_physical_memory(v) || - !is_physical_memory(roundup2(v, PAGE_SIZE) - 1)) { - return (EFAULT); - } -#else - if (v + c > (SDRAM_ADDR_START + ctob(physmem))) - return (EFAULT); -#endif - - if (is_cacheable_mem(v) && is_cacheable_mem(v + c)) { + if (is_cacheable_mem(v) && + is_cacheable_mem(v + c - 1)) { struct fpage *fp; struct sysmaps *sysmaps; diff --git a/sys/mips/mips/pmap.c b/sys/mips/mips/pmap.c index 33b8040c1a54..bfdadb7d4cca 100644 --- a/sys/mips/mips/pmap.c +++ b/sys/mips/mips/pmap.c @@ -96,7 +96,6 @@ __FBSDID("$FreeBSD$"); #endif #include -#include #include #if defined(DIAGNOSTIC) @@ -313,6 +312,14 @@ pmap_bootstrap(void) } } + /* + * Copy the phys_avail[] array before we start stealing memory from it. + */ + for (i = 0; phys_avail[i + 1] != 0; i += 2) { + physmem_desc[i] = phys_avail[i]; + physmem_desc[i + 1] = phys_avail[i + 1]; + } + Maxmem = atop(phys_avail[i - 1]); if (bootverbose) { diff --git a/sys/mips/mips/vm_machdep.c b/sys/mips/mips/vm_machdep.c index 0b51fa1b62d7..9b4829eb9df8 100644 --- a/sys/mips/mips/vm_machdep.c +++ b/sys/mips/mips/vm_machdep.c @@ -57,7 +57,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -399,34 +398,6 @@ kvtop(void *addr) #define ZIDLE_LO(v) ((v) * 2 / 3) #define ZIDLE_HI(v) ((v) * 4 / 5) -/* - * Tell whether this address is in some physical memory region. - * Currently used by the kernel coredump code in order to avoid - * dumping non-memory physical address space. - */ -int -is_physical_memory(vm_offset_t addr) -{ - if (addr >= SDRAM_ADDR_START && addr <= SDRAM_ADDR_END) - return 1; - else - return 0; -} - -int -is_cacheable_mem(vm_offset_t pa) -{ - if ((pa >= SDRAM_ADDR_START && pa <= SDRAM_ADDR_END) || -#ifdef FLASH_ADDR_START - (pa >= FLASH_ADDR_START && pa <= FLASH_ADDR_END)) -#else - 0) -#endif - return 1; - else - return 0; -} - /* * Allocate a pool of sf_bufs (sendfile(2) or "super-fast" if you prefer. :-)) */