kernel/eka/memmodel/epoc/multiple/arm/xmmu.cpp
changeset 286 48e57fb1237e
parent 132 e4a7b1cbe40c
equal deleted inserted replaced
285:ff5437e4337c 286:48e57fb1237e
  1935 
  1935 
  1936 
  1936 
  1937 #if defined(__CPU_MEMORY_TYPE_REMAPPING) //arm1176, arm11mcore, armv7
  1937 #if defined(__CPU_MEMORY_TYPE_REMAPPING) //arm1176, arm11mcore, armv7
  1938 /**
  1938 /**
  1939 Calculates page directory/table entries for memory type described in aMapAttr.
  1939 Calculates page directory/table entries for memory type described in aMapAttr.
  1940 Global, small page (4KB) mapping is assumed.
  1940 Small page (4KB) mapping is assumed.
  1941 (All magic numbers come from ARM page table descriptions.)
  1941 (All magic numbers come from ARM page table descriptions.)
  1942 @param aMapAttr On entry, holds description(memory type, access permisions,...) of the memory.
  1942 @param aMapAttr On entry, holds description(memory type, access permisions,...) of the memory.
  1943 				It is made up of TMappingAttributes constants or TMappingAttributes2 object. If TMappingAttributes,
  1943 				It is made up of TMappingAttributes constants or TMappingAttributes2 object. If TMappingAttributes,
  1944 				may be altered 	on exit to hold the actual cache attributes & access permissions.
  1944 				may be altered 	on exit to hold the actual cache attributes & access permissions.
  1945 @param aPde		On exit, holds page-table-entry for the 1st level descriptor
  1945 @param aPde		On exit, holds page-table-entry for the 1st level descriptor
  1946 				for given type of memory, with base address set to 0.
  1946 				for given type of memory, with base address set to 0.
  1947 @param aPte		On exit, holds small-page-entry (4K) for the 2nd level descriptor
  1947 @param aPte		On exit, holds small-page-entry (4K) for the 2nd level descriptor
  1948 				for given type of memory, with base address set to 0.
  1948 				for given type of memory, with base address set to 0.
       
  1949 @param aGlobal	Set to ETrue when the mapping should be global.
  1949 @return KErrNotSupported 	If memory described in aMapAttr is not supported
  1950 @return KErrNotSupported 	If memory described in aMapAttr is not supported
  1950 		KErrNone			Otherwise
  1951 		KErrNone			Otherwise
  1951 */
  1952 */
  1952 TInt ArmMmu::PdePtePermissions(TUint& aMapAttr, TPde& aPde, TPte& aPte)
  1953 TInt ArmMmu::PdePtePermissions(TUint& aMapAttr, TPde& aPde, TPte& aPte, TBool aGlobal)
  1953 	{
  1954 	{
  1954 	__KTRACE_OPT(KMMU,Kern::Printf(">ArmMmu::PdePtePermissions, mapattr=%08x",aMapAttr));
  1955 	__KTRACE_OPT(KMMU,Kern::Printf(">ArmMmu::PdePtePermissions, mapattr=%08x",aMapAttr));
  1955 
  1956 
  1956 	TMappingAttributes2& memory = (TMappingAttributes2&)aMapAttr;
  1957 	TMappingAttributes2& memory = (TMappingAttributes2&)aMapAttr;
  1957 
  1958 
  1975 				((memory.Type()&3)<<2) | ((memory.Type()&4)<<4)			|	// memory type
  1976 				((memory.Type()&3)<<2) | ((memory.Type()&4)<<4)			|	// memory type
  1976 				(memory.Executable() ? 0			: KArmV6PteSmallXN)	|	// eXecuteNever bit
  1977 				(memory.Executable() ? 0			: KArmV6PteSmallXN)	|	// eXecuteNever bit
  1977 #if defined	(__CPU_USE_SHARED_MEMORY)
  1978 #if defined	(__CPU_USE_SHARED_MEMORY)
  1978 				KArmV6PteS 												|	// Memory is always shared.
  1979 				KArmV6PteS 												|	// Memory is always shared.
  1979 #else
  1980 #else
  1980 				(memory.Shared()	  ? KArmV6PteS	: 0) 				|	// Shared bit
  1981 				(memory.Shared()	? KArmV6PteS	: 0)				|	// Shared bit
  1981 #endif				
  1982 #endif
  1982 				(memory.Writable()	  ? 0			: KArmV6PteAPX)		|	// APX = !Writable
  1983 				(memory.Writable()	? 0				: KArmV6PteAPX)		|	// APX = !Writable
  1983 				(memory.UserAccess() ? KArmV6PteAP1: 0);					// AP1 = UserAccess
  1984 				(memory.UserAccess()? KArmV6PteAP1	: 0)				|	// AP1 = UserAccess
       
  1985 				(aGlobal			? 0 			: KArmV6PteNG);			// Not Global bit
  1984 		// aMapAttr remains the same
  1986 		// aMapAttr remains the same
  1985 		}
  1987 		}
  1986 	else
  1988 	else
  1987 		{
  1989 		{
  1988 //---------Memory described by TMappingAttributes bitmask-----------------
  1990 //---------Memory described by TMappingAttributes bitmask-----------------
  2058 	
  2060 	
  2059 		//	4.	Calculate page-table-entry for the 1st level (aka page directory) descriptor 
  2061 		//	4.	Calculate page-table-entry for the 1st level (aka page directory) descriptor 
  2060 		aPde=((aMapAttr&EMapAttrUseECC)>>8)|KArmV6PdePageTable;
  2062 		aPde=((aMapAttr&EMapAttrUseECC)>>8)|KArmV6PdePageTable;
  2061 
  2063 
  2062 		//	5.	Calculate small-page-entry for the 2nd level (aka page table) descriptor 
  2064 		//	5.	Calculate small-page-entry for the 2nd level (aka page table) descriptor 
  2063 		aPte=SP_PTE(apxap, tex0_c_b, exec, 1);	// always global
  2065 		aPte=SP_PTE(apxap, tex0_c_b, exec, aGlobal);
  2064 		if (aMapAttr&EMapAttrShared)
  2066 		if (aMapAttr&EMapAttrShared)
  2065 			aPte |= KArmV6PteS;
  2067 			aPte |= KArmV6PteS;
  2066 	
  2068 	
  2067 		//	6.	Fix aMapAttr to hold the actual values for access permission & cache attributes
  2069 		//	6.	Fix aMapAttr to hold the actual values for access permission & cache attributes
  2068 		TUint xnapxap=((aPte<<3)&8)|((aPte>>7)&4)|((aPte>>4)&3);
  2070 		TUint xnapxap=((aPte<<3)&8)|((aPte>>7)&4)|((aPte>>4)&3);
  2148 	WBWA,	WBWA,	WBWA,	WBWA,	//101
  2150 	WBWA,	WBWA,	WBWA,	WBWA,	//101
  2149 	WTRA,	WTRA,	WTRA,	WTRA,	//110
  2151 	WTRA,	WTRA,	WTRA,	WTRA,	//110
  2150 	WBRA,	WBRA,	WBRA,	WBRA	//111
  2152 	WBRA,	WBRA,	WBRA,	WBRA	//111
  2151 	};
  2153 	};
  2152 
  2154 
  2153 TInt ArmMmu::PdePtePermissions(TUint& aMapAttr, TPde& aPde, TPte& aPte)
  2155 TInt ArmMmu::PdePtePermissions(TUint& aMapAttr, TPde& aPde, TPte& aPte, TBool aGlobal)
  2154 	{
  2156 	{
  2155 	__KTRACE_OPT(KMMU,Kern::Printf(">ArmMmu::PdePtePermissions, mapattr=%08x",aMapAttr));
  2157 	__KTRACE_OPT(KMMU,Kern::Printf(">ArmMmu::PdePtePermissions, mapattr=%08x",aMapAttr));
  2156 
  2158 
  2157 	TUint read=aMapAttr & EMapAttrReadMask;
  2159 	TUint read=aMapAttr & EMapAttrReadMask;
  2158 	TUint write=(aMapAttr & EMapAttrWriteMask)>>4;
  2160 	TUint write=(aMapAttr & EMapAttrWriteMask)>>4;
  2189 		apxap=(read>=4)?KArmV6PermRORO:(read?KArmV6PermRONO:KArmV6PermNONO);
  2191 		apxap=(read>=4)?KArmV6PermRORO:(read?KArmV6PermRONO:KArmV6PermNONO);
  2190 	else if (write<4)
  2192 	else if (write<4)
  2191 		apxap=(read>=4)?KArmV6PermRWRO:KArmV6PermRWNO;
  2193 		apxap=(read>=4)?KArmV6PermRWRO:KArmV6PermRWNO;
  2192 	else
  2194 	else
  2193 		apxap=KArmV6PermRWRW;
  2195 		apxap=KArmV6PermRWRW;
  2194 	TPte pte=SP_PTE(apxap, cbtex, exec, 1);	// always global
  2196 	TPte pte=SP_PTE(apxap, cbtex, exec, aGlobal);
  2195 	if (aMapAttr&EMapAttrShared)
  2197 	if (aMapAttr&EMapAttrShared)
  2196 		pte |= KArmV6PteS;
  2198 		pte |= KArmV6PteS;
  2197 
  2199 
  2198 	// Translate back to get actual map attributes
  2200 	// Translate back to get actual map attributes
  2199 	TUint xnapxap=((pte<<3)&8)|((pte>>7)&4)|((pte>>4)&3);
  2201 	TUint xnapxap=((pte<<3)&8)|((pte>>7)&4)|((pte>>4)&3);