Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/memory.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/memory.c 1997/0327
## diff -e /dev/null /n/emeliedump/1997/0327/sys/src/brazil/pc/memory.c
0a
/*
 * Size memory and create the kernel page-tables on the fly while doing so.
 * Called from main(), this code should only be run by the bootstrap processor.
 */
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"

#define PDX(va)		((((ulong)(va))>>22) & 0x03FF)
#define PTX(va)		((((ulong)(va))>>12) & 0x03FF)

enum {
	MemUPA		= 0,		/* unbacked physical address */
	MemRAM		= 1,		/* physical memory */
	MemUMB		= 2,		/* upper memory block (<16MB) */
	NMemType	= 3,

	KB		= 1024,

	MemMinMB	= 4,		/* minimum physical memory (<=4MB) */
	MemMaxMB	= 192,		/* maximum physical memory to check */

	NMemBase	= 10,
};

typedef struct {
	int	size;
	ulong	addr;
} Map;

typedef struct {
	char*	name;
	Map*	map;
	Map*	mapend;

	Lock;
} RMap;

static Map mapupa[8];
static RMap rmapupa = {
	"unallocated unbacked physical memory",
	mapupa,
	&mapupa[7],
};

static Map xmapupa[8];
static RMap xrmapupa = {
	"unbacked physical memory",
	xmapupa,
	&xmapupa[7],
};

static Map mapram[8];
static RMap rmapram = {
	"physical memory",
	mapram,
	&mapram[7],
};

static Map mapumb[64];
static RMap rmapumb = {
	"upper memory block",
	mapumb,
	&mapumb[63],
};

void
mapfree(RMap* rmap, ulong addr, int size)
{
	Map *mp;
	ulong t;

	if(size <= 0)
		return;

	lock(rmap);
	for(mp = rmap->map; mp->addr <= addr && mp->size; mp++)
		;

	if(mp > rmap->map && (mp-1)->addr+(mp-1)->size == addr){
		(mp-1)->size += size;
		if(addr+size == mp->addr){
			(mp-1)->size += mp->size;
			while(mp->size){
				mp++;
				(mp-1)->addr = mp->addr;
				(mp-1)->size = mp->size;
			}
		}
	}
	else{
		if(addr+size == mp->addr && mp->size){
			mp->addr -= size;
			mp->size += size;
		}
		else do{
			if(mp >= rmap->mapend){
				print("mapfree: losing %d, %d\n", addr, size);
				break;
			}
			t = mp->addr;
			mp->addr = addr;
			addr = t;
			t = mp->size;
			mp->size = size;
			mp++;
		}while(size = t);
	}
	unlock(rmap);
}

ulong
mapalloc(RMap* rmap, ulong addr, int size, int align)
{
	Map *mp;
	ulong maddr, oaddr;

	lock(rmap);
	for(mp = rmap->map; mp->size; mp++){
		maddr = mp->addr;

		if(addr){
			if(maddr > addr)
				continue;
			if(addr+size > maddr+mp->size)
				break;
			maddr = addr;
		}

		if(align > 0)
			maddr = ((maddr+align-1)/align)*align;
		if(mp->addr+mp->size-maddr < size)
			continue;

		oaddr = mp->addr;
		mp->addr = maddr+size;
		mp->size -= maddr-oaddr+size;
		if(mp->size == 0){
			do{
				mp++;
				(mp-1)->addr = mp->addr;
			}while((mp-1)->size = mp->size);
		}

		unlock(rmap);
		if(oaddr != maddr)
			mapfree(rmap, oaddr, maddr-oaddr);

		return maddr;
	}
	unlock(rmap);

	return 0;
}

static void
umbscan(void)
{
	uchar *p;

	/*
	 * Scan the Upper Memory Blocks (0xA0000->0xF0000) for pieces
	 * which aren't used; they can be used later for devices which
	 * want to allocate some virtual address space.
	 * Check for two things:
	 * 1) device BIOS ROM. This should start with a two-byte header
	 *    of 0x55 0xAA, followed by a byte giving the size of the ROM
	 *    in 512-byte chunks. These ROM's must start on a 2KB boundary.
	 * 2) device memory. This is read-write.
	 * There are some assumptions: there's VGA memory at 0xA0000 and
	 * the VGA BIOS ROM is at 0xC0000. Also, if there's no ROM signature
	 * at 0xE0000 then the whole 64KB up to 0xF0000 is theoretically up
	 * for grabs; check anyway.
	 */
	p = KADDR(0xC8000);
	while(p < (uchar*)KADDR(0xE0000)){
		p[0] = 0x55;
		p[1] = 0xAA;
		p[2] = 4;
		if(p[0] == 0x55 && p[1] == 0xAA){
			p += p[2]*512;
			continue;
		}
		p[0] = 0xCC;
		p[2*KB-1] = 0xCC;
		if(p[0] != 0xCC && p[2*KB-1] != 0xCC)
			mapfree(&rmapumb, PADDR(p), 2*KB);
		p += 2*KB;
	}

	p = KADDR(0xE0000);
	if(p[0] != 0x55 || p[1] != 0xAA){
		p[0] = 0xCC;
		p[64*KB-1] = 0xCC;
		if(p[0] != 0xCC && p[64*KB-1] != 0xCC)
			mapfree(&rmapumb, PADDR(p), 64*KB);
	}
}

static void
ramscan(void)
{
	ulong *k0, kzero, map, maxpa, pa, *pte, *table, *va, x;
	int nvalid[NMemType];
	uchar *bda;

	/*
	 * The bootstrap code has has created a prototype page
	 * table which maps the first MemMinMB of physical memory to KZERO.
	 * The page directory is at m->pdb and the first page of
	 * free memory is after the per-processor MMU information.
	 */
	/*
	 * Initialise the memory bank information for conventional memory
	 * (i.e. less than 640KB). The base is the first location after the
	 * bootstrap processor MMU information and the limit is obtained from
	 * the BIOS data area.
	 */
	x = PADDR(CPU0MACH+BY2PG);

	bda = (uchar*)(KZERO|0x400);
	mapfree(&rmapram, x, ((bda[0x14]<<8)|bda[0x13])*KB-x);

	/*
	 * Check if the extended memory size can be obtained from the CMOS.
	 * If it's 0 then it's either not known or >= 64MB. Always check
	 * at least 24MB in case there's a memory gap (up to 8MB) below 16MB;
	 * in this case the memory from the gap is remapped to the top of
	 * memory.
	 * The value in CMOS is supposed to be the number of KB minus one.
	 */
	maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
	maxpa = MB+(maxpa+1)*KB;
	if(maxpa == 0 || maxpa >= 64*MB)
		maxpa = MemMaxMB*MB;
	if(maxpa < 24*MB)
		maxpa = 24*MB;

	/*
	 * March up memory from the end of the loaded kernel to maxpa
	 * a page at a time, mapping the page and checking the page can
	 * be written and read correctly. The page tables are created here
	 * on the fly, allocating from low memory as necessary.
	 * Nvalid must be initialised to include some UMB's to prevent the
	 * first 4MB being mapped with a 4MB page extension, it's already
	 * partly mapped.
	 */
	k0 = (ulong*)KZERO;
	kzero = *k0;
	map = 0;
	x = 0x12345678;
	memset(nvalid, 0, sizeof(nvalid));
	nvalid[MemUMB] = (0x100000-0xC8000)/BY2PG;
	nvalid[MemRAM] = PADDR(PGROUND((ulong)end))/BY2PG - nvalid[MemUMB];
	for(pa = PADDR(PGROUND((ulong)end)); pa < maxpa; pa += BY2PG){
		/*
		 * Map the page. Use mapalloc(&rmapram, ...) to make
		 * the page table if necessary, it will be returned to the
		 * pool later if it isn't needed.
		 */
		va = KADDR(pa);
		table = &((ulong*)m->pdb)[PDX(va)];
		if(*table == 0){
			if(map == 0 && (map = mapalloc(&rmapram, 0, BY2PG, BY2PG)) == 0)
				break;
			memset(KADDR(map), 0, BY2PG);
			*table = map|PTEWRITE|PTEVALID;
			memset(nvalid, 0, sizeof(nvalid));
		}
		table = KADDR(PPN(*table));
		pte = &table[PTX(va)];

		*pte = pa|PTEWRITE|PTEUNCACHED|PTEVALID;
		mmuflushtlb(PADDR(m->pdb));

		/*
		 * Write a pattern to the page and write a different
		 * pattern to a possible mirror at KZER0. If the data
		 * reads back correctly the page is some type of RAM (possibly
		 * a linearly-mapped VGA framebuffer, for instance...) and
		 * can be cleared and added to the memory pool. If not, the
		 * page is marked invalid and added to the UMB or NOT pool
		 * depending on whether it is <16MB or not.
		 */
		*va = x;
		*k0 = ~x;
		if(*va == x){
			*pte &= ~PTEUNCACHED;
			nvalid[MemRAM]++;
			mapfree(&rmapram, pa, BY2PG);
			memset(va, 0, BY2PG);
		}
		else{
			if(pa < 16*MB){
				nvalid[MemUMB]++;
				mapfree(&rmapumb, pa, BY2PG);
			}
			else{
				*pte = 0;
				nvalid[MemUPA]++;
				mapfree(&rmapupa, pa, BY2PG);
			}
		}

		/*
		 * Done with this 4MB chunk, review the options:
		 * 1) not physical memory and >=16MB - invalidate the PDB entry;
		 * 2) physical memory - use the 4MB page extension if possible;
		 * 3) not physical memory and <16MB - use the 4MB page extension
		 *    if possible;
		 * 4) mixed or no 4MB page extension - commit the already
		 *    initialised space for the page table.
		 */
		if(((pa+BY2PG) % (4*MB)) == 0){
			table = &((ulong*)m->pdb)[PDX(va)];
			if(nvalid[MemUPA] == 1024)
				*table = 0;
			else if(nvalid[MemRAM] == 1024 && (m->cpuiddx & 0x08))
				*table = (pa & ~(4*MB-1))|PTESIZE|PTEWRITE|PTEVALID;
			else if(nvalid[MemUMB] == 1024 && (m->cpuiddx & 0x08))
				*table = (pa & ~(4*MB-1))|PTESIZE|PTEWRITE|PTEUNCACHED|PTEVALID;
			else
				map = 0;
		}

		mmuflushtlb(PADDR(m->pdb));
		x += 0x3141526;
	}
	if(map)
		mapfree(&rmapram, map, BY2PG);
	if(pa < MemMaxMB*MB)
		mapfree(&rmapupa, pa, MemMaxMB*MB-pa);
	*k0 = kzero;
}

static void
upainit(void)
{
	ulong addr, pa, pae, *table, *va, x;

	/*
	 * Allocate an 8MB chunk aligned to 16MB. Later can
	 * make the region selectable via conf if necessary.
	 */
	if((addr = mapalloc(&rmapupa, 0, 8*MB, 16*MB)) == 0)
		return;

	pa = addr;
	pae = pa+(16*MB);
	while(pa < pae){
		va = KADDR(pa);
		table = &((ulong*)m->pdb)[PDX(va)];
		if((pa % (4*MB)) == 0 && (m->cpuiddx & 0x08)){
			*table = pa|PTESIZE|PTEWRITE|PTEUNCACHED|PTEVALID;
			pa += (4*MB);
		}
		else{
			if(*table == 0){
				if((x = mapalloc(&rmapram, 0, BY2PG, BY2PG)) == 0)
					break;
				memset(KADDR(x), 0, BY2PG);
				*table = x|PTEWRITE|PTEVALID;
			}
			table = (ulong*)(KZERO|PPN(*table));
			table[PTX(va)] = pa|PTEWRITE|PTEUNCACHED|PTEVALID;
			pa += BY2PG;
		}
	}

	mapfree(&xrmapupa, addr, pa-addr);
}

void
memscan(void)
{
	ulong pa, *pte;

	/*
	 * Set special attributes for memory between 640KB and 1MB:
	 *   VGA memory is writethrough;
	 *   BIOS ROM's/UMB's are uncached;
	 * then scan for useful memory.
	 */
	for(pa = 0xA0000; pa < 0xC0000; pa += BY2PG){
		pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 0);
		*pte |= PTEWT;
	}
	for(pa = 0xC0000; pa < 0x100000; pa += BY2PG){
		pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 0);
		*pte |= PTEUNCACHED;
	}
	mmuflushtlb(PADDR(m->pdb));

	umbscan();
	ramscan();
	upainit();
}

#ifdef notdef
void
dumpmembank(void)
{
	Map *mp;
	ulong maxpa, maxpa1;

	maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
	maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30);
	print("maxpa = %uX -> %uX, maxpa1 = %uX\n", maxpa, MB+(maxpa+1)*KB, maxpa1);

	for(mp = rmapram.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
	for(mp = rmapumb.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
	for(mp = rmapupa.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
}
#endif /* notdef */

void
meminit(void)
{
	Map *mp, *xmp;

	/*
	 * Set the conf entries describing two banks of allocatable memory.
	 * Grab the first and largest entries in rmapram as left by ramscan().
	 *
	 * It would be nice to have more than 2 memory banks describable in conf.
	 */
	mp = rmapram.map;
	conf.base0 = mp->addr;
	conf.npage0 = mp->size/BY2PG;
	mp++;
	for(xmp = 0; mp->size; mp++){
		if(xmp == 0 || mp->size > xmp->size)
			xmp = mp;
	}

	if(xmp){		
		conf.base1 = xmp->addr;
		conf.npage1 = xmp->size/BY2PG;
	}
}

ulong
umbmalloc(ulong addr, int size, int align)
{
	ulong a;

	if(a = mapalloc(&rmapumb, addr, size, align))
		return KZERO|a;

	return 0;
}

void
umbfree(ulong addr, int size)
{
	mapfree(&rmapumb, addr & ~KZERO, size);
}

ulong
upamalloc(ulong addr, int size, int align)
{
	ulong a;

	if(a = mapalloc(&xrmapupa, addr, size, align))
		return KZERO|a;

	return 0;
}

void
upafree(ulong addr, int size)
{
	mapfree(&xrmapupa, addr & ~KZERO, size);
}
.
## diffname pc/memory.c 1997/0328
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0328/sys/src/brazil/pc/memory.c
24c
	MemMaxMB	= 512,		/* maximum physical memory to check */
.
## diffname pc/memory.c 1997/0329
## diff -e /n/emeliedump/1997/0328/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0329/sys/src/brazil/pc/memory.c
462a
}

ulong
umbrmalloc(ulong addr, int size, int align)
{
	ulong a;

	if(a = mapalloc(&rmapumbr, addr, size, align))
		return KZERO|a;

	return 0;
.
402,426d
400d
398c
dumpmembank();
	ramscan(maxmem);
.
378a
	Map *mp, *xmp;
.
377c
meminit(ulong maxmem)
.
375a

.
334,335c
	if(pa < maxmem)
		mapfree(&rmapupa, pa, maxmem-pa);
.
235,240c
	if(maxmem == 0){
		x = (nvramread(0x18)<<8)|nvramread(0x17);
		if(x == 0 || x >= (63*KB))
			maxpa = MemMaxMB*MB;
		else
			maxpa = MB+x*KB;
		if(maxpa < 24*MB)
			maxpa = 24*MB;
		maxmem = MemMaxMB*MB;
	}
	else
		maxpa = maxmem;
.
233c
	 * The value in CMOS is supposed to be the number of KB above 1MB.
.
223d
204c
ramscan(ulong maxmem)
.
190a
		}
		else
			mapfree(&rmapumbr, PADDR(p), 2*KB);
.
189c
		if(p[0] != 0xCC && p[2*KB-1] != 0xCC){
			p[0] = 0x55;
			p[1] = 0xAA;
			p[2] = 4;
			if(p[0] == 0x55 && p[1] == 0xAA){
				p += p[2]*512;
				continue;
			}
.
180,186d
101c
				print("mapfree: %s: losing 0x%uX, %d\n",
					rmap->name, addr, size);
.
70a
dumpmembank(void)
{
	Map *mp;
	ulong maxpa, maxpa1, maxpa2;

	maxpa = (nvramread(0x18)<<8)|nvramread(0x17);
	maxpa1 = (nvramread(0x31)<<8)|nvramread(0x30);
	maxpa2 = (nvramread(0x16)<<8)|nvramread(0x15);
	print("maxpa = %uX -> %uX, maxpa1 = %uXm maxpa2 = %uX\n",
		maxpa, MB+maxpa*KB, maxpa1, maxpa2);

	for(mp = rmapram.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
	for(mp = rmapumb.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
	for(mp = rmapumbr.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
	for(mp = rmapupa.map; mp->size; mp++)
		print("%8.8uX %8.8uX %8.8uX\n", mp->addr, mp->size, mp->addr+mp->size);
}
#endif /* notdef */

void
.
69a
static Map mapumbr[8];
static RMap rmapumbr = {
	"UMB device memory",
	mapumbr,
	&mapumbr[7],
};

#define notdef
#ifdef notdef
.
## diffname pc/memory.c 1997/0331
## diff -e /n/emeliedump/1997/0329/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0331/sys/src/brazil/pc/memory.c
491a
}

void
umbrwfree(ulong addr, int size)
{
	mapfree(&rmapumbrw, addr & ~KZERO, size);
.
490a
	/*
	 * Perhaps the memory wasn't visible before
	 * the interface is initialised, so try again.
	 */
	if((a = umbmalloc(addr, size, align)) == 0)
		return 0;
	p = (uchar*)a;
	p[0] = 0xCC;
	p[size-1] = 0xCC;
	if(p[0] == 0xCC && p[size-1] == 0xCC)
		return a;
	umbfree(a, size);

.
488c
	if(a = mapalloc(&rmapumbrw, addr, size, align))
.
486a
	uchar *p;
.
484c
umbrwmalloc(ulong addr, int size, int align)
.
226c
			mapfree(&rmapumbrw, PADDR(p), 2*KB);
.
215c
		if(p[0] != 0xCC || p[2*KB-1] != 0xCC){
.
95c
	for(mp = rmapumbrw.map; mp->size; mp++)
.
88c
	print("maxpa = %uX -> %uX, maxpa1 = %uX maxpa2 = %uX\n",
.
73,74c
	mapumbrw,
	&mapumbrw[7],
.
70,71c
static Map mapumbrw[8];
static RMap rmapumbrw = {
.
## diffname pc/memory.c 1997/0401
## diff -e /n/emeliedump/1997/0331/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0401/sys/src/brazil/pc/memory.c
441d
77d
## diffname pc/memory.c 1997/0522
## diff -e /n/emeliedump/1997/0401/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0522/sys/src/brazil/pc/memory.c
361,364c
			else if(nvalid[MemRAM] == (4*MB)/BY2PG && (m->cpuiddx & 0x08))
				*table = (pa - 4*MB)|PTESIZE|PTEWRITE|PTEVALID;
			else if(nvalid[MemUMB] == (4*MB)/BY2PG && (m->cpuiddx & 0x08))
				*table = (pa - 4*MB)|PTESIZE|PTEWRITE|PTEUNCACHED|PTEVALID;
.
359c
			if(nvalid[MemUPA] == (4*MB)/BY2PG)
.
357c
		if((pa % (4*MB)) == 0){
.
337,345c
			nvalid[MemUPA] += MB/BY2PG;
			mapfree(&rmapupa, pa, MB);

			*pte = 0;
			pa += MB;
.
335a
		else if(pa < 16*MB){
			nvalid[MemUMB] += MB/BY2PG;
			mapfree(&rmapumb, pa, MB);

			do{
				*pte++ = pa|PTEWRITE|PTEUNCACHED|PTEVALID;
				pa += BY2PG;
			}while(pa % MB);
		}
.
331,334c
			nvalid[MemRAM] += MB/BY2PG;
			mapfree(&rmapram, pa, MB);

			do{
				*pte++ = pa|PTEWRITE|PTEVALID;
				pa += BY2PG;
			}while(pa % MB);
			mmuflushtlb(PADDR(m->pdb));
			//memset(va, 0, MB);
.
325,326c
		 * chunk is marked uncached and added to the UMB pool if <16MB
		 * or is marked invalid and added to the UPA pool.
.
322c
		 * reads back correctly the chunk is some type of RAM (possibly
.
296,298c
	while(pa < maxpa){
.
287,289d
283,284c
	 * March up memory from MemMinMB to maxpa 1MB at a time,
	 * mapping the first page and checking the page can
.
260a
	x = PADDR(PGROUND((ulong)end));
	pa = MemMinMB*MB;
	mapfree(&rmapram, x, pa-x);

.
237a

.
## diffname pc/memory.c 1997/0612
## diff -e /n/emeliedump/1997/0522/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0612/sys/src/brazil/pc/memory.c
339c
//			memset(va, 0, MB);
.
## diffname pc/memory.c 1997/0717
## diff -e /n/emeliedump/1997/0612/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0717/sys/src/brazil/pc/memory.c
402c
	pae = pa+(64*MB);
.
398c
	if((addr = mapalloc(&rmapupa, 0, 64*MB, 64*MB)) == 0)
.
395c
	 * Allocate an 64MB chunk aligned to 64MB. Later can
.
## diffname pc/memory.c 1997/0805
## diff -e /n/emeliedump/1997/0717/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0805/sys/src/brazil/pc/memory.c
24c
	MemMaxMB	= 768,		/* maximum physical memory to check */
.
## diffname pc/memory.c 1997/0811
## diff -e /n/emeliedump/1997/0805/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0811/sys/src/brazil/pc/memory.c
398c
	if((addr = mapalloc(&rmapupa, 0, 8*MB, 16*MB)) == 0)
.
395c
	 * Allocate an 8MB chunk aligned to 16MB. Later can
.
## diffname pc/memory.c 1997/0823
## diff -e /n/emeliedump/1997/0811/sys/src/brazil/pc/memory.c /n/emeliedump/1997/0823/sys/src/brazil/pc/memory.c
402c
	pae = pa+(8*MB);
.
## diffname pc/memory.c 1997/1011
## diff -e /n/emeliedump/1997/0823/sys/src/brazil/pc/memory.c /n/emeliedump/1997/1011/sys/src/brazil/pc/memory.c
536c
	mapfree(&xrmapupa, addr, size);
.
530c
	if((a = mapalloc(&rmapupa, addr, size, align)) == 0)
		return 0;

	ae = mmukmap(a, 0, size);

	/*
	 * Should check here that it was all delivered
	 * and put it back and barf if not.
	 */
	USED(ae);

	/*
	 * Be very careful this returns a PHYSICAL address.
	 */
	return a;
.
528c
		return (ulong)KADDR(a);
.
525c
	ulong a, ae;
.
519c
	mapfree(&rmapumbrw, PADDR(addr), size);
.
498c
		return(ulong)KADDR(a);
.
488c
	mapfree(&rmapumb, PADDR(addr), size);
.
480c
		return (ulong)KADDR(a);
.
451d
389,426d
385a
	if(maxmem < 0xFEC00000)
		mapfree(&rmapupa, maxmem, 0xFEC00000-maxmem);
.
293c
	k0 = (ulong*)KADDR(0);
.
259c
	bda = (uchar*)KADDR(0x400);
.
102c
mapfree(RMap* rmap, ulong addr, ulong size)
.
## diffname pc/memory.c 1997/1101
## diff -e /n/emeliedump/1997/1011/sys/src/brazil/pc/memory.c /n/emeliedump/1997/1101/sys/src/brazil/pc/memory.c
434a
dumpmembank();
.
408c
		pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 2, 0);
.
404c
		pte = mmuwalk(m->pdb, (ulong)KADDR(pa), 2, 0);
.
386,387c
	if(maxmem < 0xFFE00000)
		mapfree(&rmapupa, maxmem, 0xFFE00000-maxmem);
print("maxmem %uX %uX\n", maxmem, 0xFFE00000-maxmem);
.
368c
			table = &m->pdb[PDX(va)];
.
305c
		table = &m->pdb[PDX(va)];
.
76a
#define notdef
.
## diffname pc/memory.c 1997/1213
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/pc/memory.c /n/emeliedump/1997/1213/sys/src/brazil/pc/memory.c
494c
		return a;
.
437c
	if(MEMDEBUG)
		memdebug();
.
389c
	if(MEMDEBUG)
		print("maxmem %uX %uX\n", maxmem, 0xFFE00000-maxmem);
.
159a
				break;
			if(maddr+mp->size < addr)
.
158a
			/*
			 * A specific address range has been given:
			 *   if the current map entry is greater then
			 *   the address is not in the map;
			 *   if the current map entry does not overlap
			 *   the beginning of the requested range then
			 *   continue on to the next map entry;
			 *   if the current map entry does not entirely
			 *   contain the requested range then the range
			 *   is not in the map.
			 */
.
100d
84a
	if(MEMDEBUG == 0)
		return;

.
80c
memdebug(void)
.
77,78d
11a
#define MEMDEBUG	0

.
## diffname pc/memory.c 1998/0221
## diff -e /n/emeliedump/1997/1213/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0221/sys/src/brazil/pc/memory.c
254d
## diffname pc/memory.c 1998/0312
## diff -e /n/emeliedump/1998/0221/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0312/sys/src/brazil/pc/memory.c
238c
			if(p[0] == 0xFF && p[1] == 0xFF)
				mapfree(&rmapumb, PADDR(p), 2*KB);
.
226c
	p = KADDR(0xC0000);
.
## diffname pc/memory.c 1998/0825
## diff -e /n/emeliedump/1998/0312/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0825/sys/src/brazil/pc/memory.c
405c
		print("maxmem %luX %luX\n", maxmem, 0xFFE00000-maxmem);
.
135c
				print("mapfree: %s: losing 0x%luX, %ld\n",
.
101c
		print("%8.8luX %8.8uX %8.8luX\n", mp->addr, mp->size, mp->addr+mp->size);
.
99c
		print("%8.8luX %8.8uX %8.8luX\n", mp->addr, mp->size, mp->addr+mp->size);
.
97c
		print("%8.8luX %8.8uX %8.8luX\n", mp->addr, mp->size, mp->addr+mp->size);
.
95c
		print("%8.8luX %8.8uX %8.8luX\n", mp->addr, mp->size, mp->addr+mp->size);
.
91c
	print("maxpa = %luX -> %luX, maxpa1 = %luX maxpa2 = %luX\n",
.
## diffname pc/memory.c 1998/0906
## diff -e /n/emeliedump/1998/0825/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0906/sys/src/brazil/pc/memory.c
76c
	&mapumbrw[nelem(mapumbrw)-1],
.
72c
static Map mapumbrw[16];
.
69c
	&mapumb[nelem(mapumb)-1],
.
62c
	&mapram[nelem(mapram)-1],
.
58c
static Map mapram[16];
.
55c
	&xmapupa[nelem(xmapupa)-1],
.
51c
static Map xmapupa[16];
.
48c
	&mapupa[nelem(mapupa)-1],
.
44c
static Map mapupa[16];
.
## diffname pc/memory.c 1998/0924
## diff -e /n/emeliedump/1998/0906/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0924/sys/src/brazil/pc/memory.c
533c
	mapfree(&xrmapupa, pa, size);
.
531c
upafree(ulong pa, int size)
.
516c
	/*
	 * Upamalloc is a request to map a range of physical addresses.
	 * Therefore, if pa is 0 mapalloc will choose the base address.
	 * Note, however, mmukmap is always asked to give a 1-to-1 mapping
	 * of va to pa.
	 */
	ae = mmukmap(a, a, size);
.
514a
	}
.
513c
	if((a = mapalloc(&rmapupa, pa, size, align)) == 0){
		memdebug();
.
510c
	if(a = mapalloc(&xrmapupa, pa, size, align))
.
506c
upamalloc(ulong pa, int size, int align)
.
## diffname pc/memory.c 1998/0926
## diff -e /n/emeliedump/1998/0924/sys/src/brazil/pc/memory.c /n/emeliedump/1998/0926/sys/src/brazil/pc/memory.c
533c
	 * Be very careful this returns a PHYSICAL address
	 * mapped 1-to-1 with the virtual address.
	 * If a < KZERO it's probably not a good idea to
	 * try KADDR(a)...
.
524a
	 * ...but for the moment go back to the old scheme for VLB cards.
	 */
	ae = mmukmap(a, 0, size);
.
523d
## diffname pc/memory.c 1999/0713
## diff -e /n/emeliedump/1998/0926/sys/src/brazil/pc/memory.c /n/emeliedump/1999/0713/sys/src/brazil/pc/memory.c
546a
}


/*
 *  since mapalloc uses 0 to mean no allocation, add one to pa
 *  to shift the whole io range up one in the map.
 */
void
ioinit(void)
{
	mapfree(&rmapiospace, 1, (1<<24)+1);
}

ulong
ioalloc(ulong pa, int size, int align)
{
	ulong a;

	if((a = mapalloc(&rmapiospace, ++pa, size, align)) == 0)
		return 0;

	return --a;
}

void
iofree(ulong pa, int size)
{
	mapfree(&rmapiospace, ++pa, size);
.
78a
static Map mapiospace[256];
static RMap rmapiospace = {
	"x86 IO port space",
	mapiospace,
	&mapiospace[nelem(mapiospace)-1],
};

.
## diffname pc/memory.c 1999/0714
## diff -e /n/emeliedump/1999/0713/sys/src/brazil/pc/memory.c /n/emeliedump/1999/0714/sys/src/brazil/pc/memory.c
556,582d
79,85d
## diffname pc/memory.c 2000/0630
## diff -e /n/emeliedump/1999/0714/sys/src/brazil/pc/memory.c /n/emeliedump/2000/0630/sys/src/9/pc/memory.c
405c
		print("maxmem %luX %luX\n", maxmem, 0x00000000-maxmem);
.
403c
		mapfree(&rmapupa, maxmem, 0x00000000-maxmem);
.
176c
			if(addr - maddr > mp->size - size)	/* addr+size > maddr+mp->size, but no overflow */
.
174c
			if(mp->size < addr - maddr)	/* maddr+mp->size < addr, but no overflow */
.
## diffname pc/memory.c 2001/0523
## diff -e /n/emeliedump/2000/0630/sys/src/9/pc/memory.c /n/emeliedump/2001/0523/sys/src/9/pc/memory.c
227a
		if (p[0] == 0x55 && p[1] == 0xAA) {
			/* Skip p[2] chunks of 512 bytes.  Test for 0x55 AA before
			     poking obtrusively, or else the Thinkpad X20 dies when
			     setting up the cardbus (PB) */
			p += p[2] * 512;
			continue;
		}

.
## diffname pc/memory.c 2001/0527
## diff -e /n/emeliedump/2001/0523/sys/src/9/pc/memory.c /n/emeliedump/2001/0527/sys/src/9/pc/memory.c
228,232c
		/*
		 * Test for 0x55 AA before poking obtrusively,
		 * some machines (e.g. Thinkpad X20) seem to map
		 * something dynamic here (cardbus?) causing weird
		 * problems if it is changed.
		 */
		if(p[0] == 0x55 && p[1] == 0xAA){
			p += p[2]*512;
.
## diffname pc/memory.c 2001/0609
## diff -e /n/emeliedump/2001/0527/sys/src/9/pc/memory.c /n/emeliedump/2001/0609/sys/src/9/pc/memory.c
228,235c
		if (p[0] == 0x55 && p[1] == 0xAA) {
			/* Skip p[2] chunks of 512 bytes.  Test for 0x55 AA before
			     poking obtrusively, or else the Thinkpad X20 dies when
			     setting up the cardbus (PB) */
			p += p[2] * 512;
.
## diffname pc/memory.c 2001/0712
## diff -e /n/emeliedump/2001/0609/sys/src/9/pc/memory.c /n/emeliedump/2001/0712/sys/src/9/pc/memory.c
228,232c
		/*
		 * Test for 0x55 0xAA before poking obtrusively,
		 * some machines (e.g. Thinkpad X20) seem to map
		 * something dynamic here (cardbus?) causing weird
		 * problems if it is changed.
		 */
		if(p[0] == 0x55 && p[1] == 0xAA){
			p += p[2]*512;
.
## diffname pc/memory.c 2002/0109
## diff -e /n/emeliedump/2001/0712/sys/src/9/pc/memory.c /n/emeliedump/2002/0109/sys/src/9/pc/memory.c
424a
	ulong maxmem;
	char *p;

	if(p = getconf("*maxmem"))
		maxmem = strtoul(p, 0, 0);
	else
		maxmem = 0;
.
421c
meminit(void)
.
366c
			/* memset(va, 0, MB); so damn slow to memset all of memory */
.
291a
	memset(KADDR(x), 0, pa-x);		/* keep us honest */
.
287c
	n = ((bda[0x14]<<8)|bda[0x13])*KB-x;
	mapfree(&rmapram, x, n);
	memset(KADDR(x), 0, n);		/* keep us honest */
.
269c
	ulong *k0, kzero, map, maxpa, pa, *pte, *table, *va, x, n;
.
265a
int
touch(uchar *p, int n)
{
	int x;
	int i;

	x = 0;
	for(i=0; i<n; i++)
		x += p[i];
	return x;
}


.
94,101c
	mapprint(&rmapram);
	mapprint(&rmapumb);
	mapprint(&rmapumbrw);
	mapprint(&rmapupa);
.
82a

	print("%s\n", rmap->name);	
	for(mp = rmap->map; mp->size; mp++)
		print("\t%8.8luX %8.8uX %8.8luX\n", mp->addr, mp->size, mp->addr+mp->size);
}


void
memdebug(void)
{
.
80c
mapprint(RMap *rmap)
.
14,16d
## diffname pc/memory.c 2002/0412
## diff -e /n/emeliedump/2002/0109/sys/src/9/pc/memory.c /n/emeliedump/2002/0412/sys/src/9/pc/memory.c
427a

	/*
	 * If we didn't reach the end of the 4MB chunk, that part won't
	 * be mapped.  Commit the already initialised space for the page table.
	 */
	if(pa % (4*MB))
		map = 0;

.
## diffname pc/memory.c 2002/0703
## diff -e /n/emeliedump/2002/0412/sys/src/9/pc/memory.c /n/emeliedump/2002/0703/sys/src/9/pc/memory.c
305c
	memset(KADDR(x), 0, n);			/* keep us honest */
.
269,281d
## diffname pc/memory.c 2002/0918
## diff -e /n/emeliedump/2002/0703/sys/src/9/pc/memory.c /n/emeliedump/2002/0918/sys/src/9/pc/memory.c
229c
	p = KADDR(0xD0000);
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.