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)
This commit is contained in:
Neel Natu 2009-10-22 02:51:31 +00:00
parent 1a71736fb1
commit 24c8d4c173
7 changed files with 43 additions and 63 deletions

View File

@ -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

View File

@ -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_ */

View File

@ -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;

View File

@ -79,7 +79,6 @@ __FBSDID("$FreeBSD$");
#include <sys/syslog.h>
#include <machine/cache.h>
#include <machine/cpu.h>
#include <machine/pltfm.h>
#include <net/netisr.h>
#include <machine/md_var.h>
#include <machine/clock.h>
@ -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);
}

View File

@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$");
#include <machine/cpu.h>
#include <machine/md_var.h>
#include <machine/atomic.h>
#include <machine/pltfm.h>
#include <machine/memdev.h>
@ -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;

View File

@ -96,7 +96,6 @@ __FBSDID("$FreeBSD$");
#endif
#include <machine/cache.h>
#include <machine/pltfm.h>
#include <machine/md_var.h>
#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) {

View File

@ -57,7 +57,6 @@ __FBSDID("$FreeBSD$");
#include <machine/cpu.h>
#include <machine/md_var.h>
#include <machine/pcb.h>
#include <machine/pltfm.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@ -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. :-))
*/