10acc7a44SFrançois Revol/*
20acc7a44SFrançois Revol** Copyright 2003, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3b6f76ebeSAugustin Cavalier** Distributed under the terms of the MIT License.
40acc7a44SFrançois Revol*/
50acc7a44SFrançois Revol#ifndef _KERNEL_ARCH_PPC_MMU_AMCC440_H
60acc7a44SFrançois Revol#define _KERNEL_ARCH_PPC_MMU_AMCC440_H
70acc7a44SFrançois Revol
80acc7a44SFrançois Revol
90acc7a44SFrançois Revol#include <SupportDefs.h>
100acc7a44SFrançois Revol#include <string.h>
110acc7a44SFrançois Revol
120acc7a44SFrançois Revol#include <arch_cpu.h>
130acc7a44SFrançois Revol
140acc7a44SFrançois Revol
150acc7a44SFrançois Revol/*** TLB - translation lookaside buffer ***/
160acc7a44SFrançois Revol
170acc7a44SFrançois Revol#define TLB_COUNT	64
180acc7a44SFrançois Revol
190acc7a44SFrançois Revol/** valid tlb length values */
200acc7a44SFrançois Revolenum tlb_length {
210acc7a44SFrançois Revol	TLB_LENGTH_1kB		= 0x0,
220acc7a44SFrançois Revol	TLB_LENGTH_4kB		= 0x1,
230acc7a44SFrançois Revol	TLB_LENGTH_16kB		= 0x2,
240acc7a44SFrançois Revol	TLB_LENGTH_64kB		= 0x3,
250acc7a44SFrançois Revol	TLB_LENGTH_256kB	= 0x4,
260acc7a44SFrançois Revol	TLB_LENGTH_1MB		= 0x5,
270acc7a44SFrançois Revol	TLB_LENGTH_16MB		= 0x7,
280acc7a44SFrançois Revol	TLB_LENGTH_256MB	= 0x9,
290acc7a44SFrançois Revol};
300acc7a44SFrançois Revol
310acc7a44SFrançois Revol#define TLB_V	0x200
320acc7a44SFrançois Revol
330acc7a44SFrançois Revol/** structure of a real TLB entry */
340acc7a44SFrançois Revol//FIXME
350acc7a44SFrançois Revolstruct tlb_entry {
360acc7a44SFrançois Revol	// word 0
370acc7a44SFrançois Revol	uint32	effective_page_number : 22;
380acc7a44SFrançois Revol	uint32	valid : 1;
390acc7a44SFrançois Revol	uint32	translation_address_space : 1;
400acc7a44SFrançois Revol	uint32	page_size : 4;
410acc7a44SFrançois Revol	uint32	parity_1 : 4;
420acc7a44SFrançois Revol	//uint32	translation_id : 8;
430acc7a44SFrançois Revol//FIXME:rest is Classic stuff
440acc7a44SFrançois Revol	// word 0
450acc7a44SFrançois Revol	// upper 32 bit
460acc7a44SFrançois Revol	uint32	page_index : 15;				// BEPI, block effective page index
470acc7a44SFrançois Revol	uint32	_reserved0 : 4;
480acc7a44SFrançois Revol	uint32	length : 11;
490acc7a44SFrançois Revol	uint32	kernel_valid : 1;				// Vs, Supervisor-state valid
500acc7a44SFrançois Revol	uint32	user_valid : 1;					// Vp, User-state valid
510acc7a44SFrançois Revol	// lower 32 bit
520acc7a44SFrançois Revol	uint32	physical_block_number : 15;		// BPRN
530acc7a44SFrançois Revol	uint32	write_through : 1;				// WIMG
540acc7a44SFrançois Revol	uint32	caching_inhibited : 1;
550acc7a44SFrançois Revol	uint32	memory_coherent : 1;
560acc7a44SFrançois Revol	uint32	guarded : 1;
570acc7a44SFrançois Revol	uint32	_reserved1 : 1;
580acc7a44SFrançois Revol	uint32	protection : 2;
590acc7a44SFrançois Revol
600acc7a44SFrançois Revol	tlb_entry()
610acc7a44SFrançois Revol	{
620acc7a44SFrançois Revol		Clear();
630acc7a44SFrançois Revol	}
640acc7a44SFrançois Revol
650acc7a44SFrançois Revol	void SetVirtualAddress(void *address)
660acc7a44SFrançois Revol	{
670acc7a44SFrançois Revol		page_index = uint32(address) >> 17;
680acc7a44SFrançois Revol	}
690acc7a44SFrançois Revol
700acc7a44SFrançois Revol	void SetPhysicalAddress(void *address)
710acc7a44SFrançois Revol	{
720acc7a44SFrançois Revol		physical_block_number = uint32(address) >> 17;
730acc7a44SFrançois Revol	}
740acc7a44SFrançois Revol
750acc7a44SFrançois Revol	void Clear()
760acc7a44SFrançois Revol	{
770acc7a44SFrançois Revol		memset((void *)this, 0, sizeof(tlb_entry));
780acc7a44SFrançois Revol	}
790acc7a44SFrançois Revol};
800acc7a44SFrançois Revol
810acc7a44SFrançois Revol#if 0 // XXX:Classic
820acc7a44SFrançois Revol/*** PTE - page table entry ***/
830acc7a44SFrançois Revol
840acc7a44SFrançois Revolenum pte_protection {
850acc7a44SFrançois Revol	PTE_READ_ONLY	= 3,
860acc7a44SFrançois Revol	PTE_READ_WRITE	= 2,
870acc7a44SFrançois Revol};
880acc7a44SFrançois Revol
890acc7a44SFrançois Revolstruct page_table_entry {
900acc7a44SFrançois Revol	// upper 32 bit
910acc7a44SFrançois Revol	uint32	valid : 1;
920acc7a44SFrançois Revol	uint32	virtual_segment_id : 24;
930acc7a44SFrançois Revol	uint32	secondary_hash : 1;
940acc7a44SFrançois Revol	uint32	abbr_page_index : 6;
950acc7a44SFrançois Revol	// lower 32 bit
960acc7a44SFrançois Revol	uint32	physical_page_number : 20;
970acc7a44SFrançois Revol	uint32	_reserved0 : 3;
980acc7a44SFrançois Revol	uint32	referenced : 1;
990acc7a44SFrançois Revol	uint32	changed : 1;
1000acc7a44SFrançois Revol	uint32	write_through : 1;				// WIMG
1010acc7a44SFrançois Revol	uint32	caching_inhibited : 1;
1020acc7a44SFrançois Revol	uint32	memory_coherent : 1;
1030acc7a44SFrançois Revol	uint32	guarded : 1;
1040acc7a44SFrançois Revol	uint32	_reserved1 : 1;
1050acc7a44SFrançois Revol	uint32	page_protection : 2;
1060acc7a44SFrançois Revol
1070acc7a44SFrançois Revol	static uint32 PrimaryHash(uint32 virtualSegmentID, uint32 virtualAddress);
1080acc7a44SFrançois Revol	static uint32 SecondaryHash(uint32 virtualSegmentID, uint32 virtualAddress);
1090acc7a44SFrançois Revol	static uint32 SecondaryHash(uint32 primaryHash);
1100acc7a44SFrançois Revol};
1110acc7a44SFrançois Revol
1120acc7a44SFrançois Revolstruct page_table_entry_group {
1130acc7a44SFrançois Revol	struct page_table_entry entry[8];
1140acc7a44SFrançois Revol};
1150acc7a44SFrançois Revol
1160acc7a44SFrançois Revolextern void ppc_get_page_table(page_table_entry_group **_pageTable, size_t *_size);
1170acc7a44SFrançois Revolextern void ppc_set_page_table(page_table_entry_group *pageTable, size_t size);
1180acc7a44SFrançois Revol
1190acc7a44SFrançois Revolstatic inline segment_descriptor
1200acc7a44SFrançois Revolppc_get_segment_register(void *virtualAddress)
1210acc7a44SFrançois Revol{
1220acc7a44SFrançois Revol	return (segment_descriptor)get_sr(virtualAddress);
1230acc7a44SFrançois Revol}
1240acc7a44SFrançois Revol
1250acc7a44SFrançois Revol
1260acc7a44SFrançois Revolstatic inline void
1270acc7a44SFrançois Revolppc_set_segment_register(void *virtualAddress, segment_descriptor segment)
1280acc7a44SFrançois Revol{
1290acc7a44SFrançois Revol	set_sr(virtualAddress, *(uint32 *)&segment);
1300acc7a44SFrançois Revol}
1310acc7a44SFrançois Revol
1320acc7a44SFrançois Revol#endif
1330acc7a44SFrançois Revol
1340acc7a44SFrançois Revol#endif	/* _KERNEL_ARCH_PPC_MMU_AMCC440_H */
135